diff options
Diffstat (limited to 'block.c')
-rw-r--r-- | block.c | 16 |
1 files changed, 12 insertions, 4 deletions
@@ -3307,7 +3307,7 @@ exit: /** * Truncate file to 'offset' bytes (needed only for file protocols) */ -int bdrv_truncate(BdrvChild *child, int64_t offset) +int bdrv_truncate(BdrvChild *child, int64_t offset, Error **errp) { BlockDriverState *bs = child->bs; BlockDriver *drv = bs->drv; @@ -3315,12 +3315,18 @@ int bdrv_truncate(BdrvChild *child, int64_t offset) assert(child->perm & BLK_PERM_RESIZE); - if (!drv) + if (!drv) { + error_setg(errp, "No medium inserted"); return -ENOMEDIUM; - if (!drv->bdrv_truncate) + } + if (!drv->bdrv_truncate) { + error_setg(errp, "Image format driver does not support resize"); return -ENOTSUP; - if (bs->read_only) + } + if (bs->read_only) { + error_setg(errp, "Image is read-only"); return -EACCES; + } ret = drv->bdrv_truncate(bs, offset); if (ret == 0) { @@ -3328,6 +3334,8 @@ int bdrv_truncate(BdrvChild *child, int64_t offset) bdrv_dirty_bitmap_truncate(bs); bdrv_parent_cb_resize(bs); ++bs->write_gen; + } else { + error_setg_errno(errp, -ret, "Failed to resize image"); } return ret; } |