[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH for-2.10 3/3] block: Add some bdrv_truncate() error
From: |
Max Reitz |
Subject: |
[Qemu-block] [PATCH for-2.10 3/3] block: Add some bdrv_truncate() error messages |
Date: |
Mon, 6 Mar 2017 20:54:34 +0100 |
Add missing error messages for the drivers I am comfortable to do this
in.
Signed-off-by: Max Reitz <address@hidden>
---
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
- [Qemu-block] [PATCH for-2.10 0/3] block: Add errp to b{lk, drv}_turncate(), Max Reitz, 2017/03/06
- [Qemu-block] [PATCH for-2.10 2/3] block: Add errp to BD.bdrv_truncate(), Max Reitz, 2017/03/06
- [Qemu-block] [PATCH for-2.10 1/3] block: Add errp to b{lk, drv}_truncate(), Max Reitz, 2017/03/06
- [Qemu-block] [PATCH for-2.10 3/3] block: Add some bdrv_truncate() error messages,
Max Reitz <=
- Re: [Qemu-block] [Qemu-devel] [PATCH for-2.10 3/3] block: Add some bdrv_truncate() error messages, Eric Blake, 2017/03/06
- Re: [Qemu-block] [Qemu-devel] [PATCH for-2.10 3/3] block: Add some bdrv_truncate() error messages, Max Reitz, 2017/03/06
- Re: [Qemu-block] [Qemu-devel] [PATCH for-2.10 3/3] block: Add some bdrv_truncate() error messages, Eric Blake, 2017/03/06
- Re: [Qemu-block] [Qemu-devel] [PATCH for-2.10 3/3] block: Add some bdrv_truncate() error messages, Max Reitz, 2017/03/06
- Re: [Qemu-block] [Qemu-devel] [PATCH for-2.10 3/3] block: Add some bdrv_truncate() error messages, Eric Blake, 2017/03/06
- Re: [Qemu-block] [Qemu-devel] [PATCH for-2.10 3/3] block: Add some bdrv_truncate() error messages, Kevin Wolf, 2017/03/07
Re: [Qemu-block] [Qemu-devel] [PATCH for-2.10 0/3] block: Add errp to b{lk, drv}_turncate(), no-reply, 2017/03/06