Add missing error messages for the drivers I am comfortable to do this in. Signed-off-by: Max Reitz <mre...@redhat.com> --- block/file-posix.c | 8 +++++++- block/qcow2.c | 2 ++ block/qed.c | 4 +++- block/raw-format.c | 2 ++ 4 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/block/file-posix.c b/block/file-posix.c index 9d2bea730d..553213221c 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1341,20 +1341,26 @@ static int raw_truncate(BlockDriverState *bs, int64_t offset, Error **errp) { BDRVRawState *s = bs->opaque; struct stat st; + int ret; if (fstat(s->fd, &st)) { - return -errno; + ret = -errno; + error_setg_errno(errp, -ret, "Failed to fstat() the file"); + return ret; } if (S_ISREG(st.st_mode)) { if (ftruncate(s->fd, offset) < 0) { + /* The generic error message will be fine */ return -errno; } } else if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) { if (offset > raw_getlength(bs)) { + error_setg(errp, "Cannot grow device files"); return -EINVAL; } } else { + error_setg(errp, "Resizing this file is not supported"); return -ENOTSUP; } diff --git a/block/qcow2.c b/block/qcow2.c index 17585fbb89..53b0bd61a7 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2550,6 +2550,7 @@ static int qcow2_truncate(BlockDriverState *bs, int64_t offset, Error **errp) new_l1_size = size_to_l1(s, offset); ret = qcow2_grow_l1_table(bs, new_l1_size, true); if (ret < 0) { + error_setg(errp, "Failed to grow the L1 table"); return ret; } @@ -2558,6 +2559,7 @@ static int qcow2_truncate(BlockDriverState *bs, int64_t offset, Error **errp) ret = bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, size), &offset, sizeof(uint64_t)); if (ret < 0) { + error_setg(errp, "Failed to update the image size"); return ret; } diff --git a/block/qed.c b/block/qed.c index fa2aeee471..eb346d645b 100644 --- a/block/qed.c +++ b/block/qed.c @@ -1526,11 +1526,12 @@ static int bdrv_qed_truncate(BlockDriverState *bs, int64_t offset, Error **errp) if (!qed_is_image_size_valid(offset, s->header.cluster_size, s->header.table_size)) { + error_setg(errp, "Invalid image size specified"); return -EINVAL; } - /* Shrinking is currently not supported */ if ((uint64_t)offset < s->header.image_size) { + error_setg(errp, "Shrinking images is currently not supported"); return -ENOTSUP; } @@ -1539,6 +1540,7 @@ static int bdrv_qed_truncate(BlockDriverState *bs, int64_t offset, Error **errp) ret = qed_write_header_sync(s); if (ret < 0) { s->header.image_size = old_image_size; + error_setg(errp, "Failed to update the image size"); } return ret; } diff --git a/block/raw-format.c b/block/raw-format.c index 9761bdaff8..36e65036f0 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -332,10 +332,12 @@ static int raw_truncate(BlockDriverState *bs, int64_t offset, Error **errp) BDRVRawState *s = bs->opaque; if (s->has_size) { + error_setg(errp, "Cannot resize fixed-size raw disks"); return -ENOTSUP; } if (INT64_MAX - offset < s->offset) { + error_setg(errp, "Disk size too large for the chosen offset"); return -EINVAL; } -- 2.12.0