[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 14/14] block: use proper qerrors in qmp_block_resize
From: |
Luiz Capitulino |
Subject: |
[Qemu-devel] [PATCH 14/14] block: use proper qerrors in qmp_block_resize |
Date: |
Wed, 18 Jan 2012 15:41:24 -0200 |
From: Stefan Hajnoczi <address@hidden>
Let's report specific errors so that management tools and users can
identify the problem.
Two new qerrors are needed:
* QERR_DEVICE_HAS_NO_MEDIUM for ENOMEDIUM
* QERR_DEVICE_IS_READ_ONLY for EACCES
Signed-off-by: Stefan Hajnoczi <address@hidden>
Signed-off-by: Luiz Capitulino <address@hidden>
---
blockdev.c | 26 ++++++++++++++++++--------
qapi-schema.json | 7 +++++--
qerror.c | 8 ++++++++
qerror.h | 6 ++++++
4 files changed, 37 insertions(+), 10 deletions(-)
diff --git a/blockdev.c b/blockdev.c
index 5d16137..1f83c88 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -848,11 +848,6 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject
**ret_data)
return 0;
}
-/*
- * XXX: replace the QERR_UNDEFINED_ERROR errors with real values once the
- * existing QERR_ macro mess is cleaned up. A good example for better
- * error reports can be found in the qemu-img resize code.
- */
void qmp_block_resize(const char *device, int64_t size, Error **errp)
{
BlockDriverState *bs;
@@ -864,12 +859,27 @@ void qmp_block_resize(const char *device, int64_t size,
Error **errp)
}
if (size < 0) {
- error_set(errp, QERR_UNDEFINED_ERROR);
+ error_set(errp, QERR_INVALID_PARAMETER_VALUE, "size", "a >0 size");
return;
}
- if (bdrv_truncate(bs, size)) {
+ switch (bdrv_truncate(bs, size)) {
+ case 0:
+ break;
+ case -ENOMEDIUM:
+ error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device);
+ break;
+ case -ENOTSUP:
+ error_set(errp, QERR_UNSUPPORTED);
+ break;
+ case -EACCES:
+ error_set(errp, QERR_DEVICE_IS_READ_ONLY, device);
+ break;
+ case -EBUSY:
+ error_set(errp, QERR_DEVICE_IN_USE, device);
+ break;
+ default:
error_set(errp, QERR_UNDEFINED_ERROR);
- return;
+ break;
}
}
diff --git a/qapi-schema.json b/qapi-schema.json
index 9b154cc..735eb35 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -1064,8 +1064,11 @@
#
# Returns: nothing on success
# If @device is not a valid block device, DeviceNotFound
-#
-# Notes: This command returns UndefinedError in a number of error conditions.
+# If @size is negative, InvalidParameterValue
+# If the block device has no medium inserted, DeviceHasNoMedium
+# If the block device does not support resize, Unsupported
+# If the block device is read-only, DeviceIsReadOnly
+# If a long-running operation is using the device, DeviceInUse
#
# Since: 0.14.0
##
diff --git a/qerror.c b/qerror.c
index 2979b3e..3d95383 100644
--- a/qerror.c
+++ b/qerror.c
@@ -80,6 +80,10 @@ static const QErrorStringTable qerror_table[] = {
.desc = "Migration is disabled when using feature '%(feature)' in
device '%(device)'",
},
{
+ .error_fmt = QERR_DEVICE_HAS_NO_MEDIUM,
+ .desc = "Device '%(device)' has no medium",
+ },
+ {
.error_fmt = QERR_DEVICE_INIT_FAILED,
.desc = "Device '%(device)' could not be initialized",
},
@@ -88,6 +92,10 @@ static const QErrorStringTable qerror_table[] = {
.desc = "Device '%(device)' is in use",
},
{
+ .error_fmt = QERR_DEVICE_IS_READ_ONLY,
+ .desc = "Device '%(device)' is read only",
+ },
+ {
.error_fmt = QERR_DEVICE_LOCKED,
.desc = "Device '%(device)' is locked",
},
diff --git a/qerror.h b/qerror.h
index be4e865..89160dd 100644
--- a/qerror.h
+++ b/qerror.h
@@ -81,12 +81,18 @@ QError *qobject_to_qerror(const QObject *obj);
#define QERR_DEVICE_FEATURE_BLOCKS_MIGRATION \
"{ 'class': 'DeviceFeatureBlocksMigration', 'data': { 'device': %s,
'feature': %s } }"
+#define QERR_DEVICE_HAS_NO_MEDIUM \
+ "{ 'class': 'DeviceHasNoMedium', 'data': { 'device': %s } }"
+
#define QERR_DEVICE_INIT_FAILED \
"{ 'class': 'DeviceInitFailed', 'data': { 'device': %s } }"
#define QERR_DEVICE_IN_USE \
"{ 'class': 'DeviceInUse', 'data': { 'device': %s } }"
+#define QERR_DEVICE_IS_READ_ONLY \
+ "{ 'class': 'DeviceIsReadOnly', 'data': { 'device': %s } }"
+
#define QERR_DEVICE_LOCKED \
"{ 'class': 'DeviceLocked', 'data': { 'device': %s } }"
--
1.7.9.rc0.dirty
- [Qemu-devel] [PATCH 01/14] vnc: Simplify vnc_display_password(), (continued)
- [Qemu-devel] [PATCH 01/14] vnc: Simplify vnc_display_password(), Luiz Capitulino, 2012/01/18
- [Qemu-devel] [PATCH 03/14] qapi: Convert expire_password, Luiz Capitulino, 2012/01/18
- [Qemu-devel] [PATCH 05/14] qapi: Convert eject, Luiz Capitulino, 2012/01/18
- [Qemu-devel] [PATCH 04/14] block: eject_device(): Use error_set(), Luiz Capitulino, 2012/01/18
- [Qemu-devel] [PATCH 06/14] monitor: expose readline state, Luiz Capitulino, 2012/01/18
- [Qemu-devel] [PATCH 07/14] qapi: Introduce change-vnc-password, Luiz Capitulino, 2012/01/18
- [Qemu-devel] [PATCH 08/14] qerror: Extend QERR_DEVICE_ENCRYPTED, Luiz Capitulino, 2012/01/18
- [Qemu-devel] [PATCH 09/14] qapi: Convert change, Luiz Capitulino, 2012/01/18
- [Qemu-devel] [PATCH 10/14] qapi: Convert block_set_io_throttle, Luiz Capitulino, 2012/01/18
- [Qemu-devel] [PATCH 13/14] qerror: restore alphabetical order over qerrors, Luiz Capitulino, 2012/01/18
- [Qemu-devel] [PATCH 14/14] block: use proper qerrors in qmp_block_resize,
Luiz Capitulino <=
- [Qemu-devel] [PATCH 12/14] qerror: add check-qerror.sh to verify alphabetical order, Luiz Capitulino, 2012/01/18
- [Qemu-devel] [PATCH 11/14] qmp: Add missing gcc format attribute and fix format string, Luiz Capitulino, 2012/01/18
- Re: [Qemu-devel] [PULL 00/14]: QMP queue, Anthony Liguori, 2012/01/19