aboutsummaryrefslogtreecommitdiff
path: root/blockdev.c
diff options
context:
space:
mode:
authorStefan Hajnoczi <stefanha@linux.vnet.ibm.com>2012-01-04 22:23:34 +0000
committerLuiz Capitulino <lcapitulino@redhat.com>2012-01-18 10:23:39 -0200
commit939a1cc399adb92640d156097d528b6471c136ae (patch)
treee459b5524103a382b7a271ab992c6fad7ac6298b /blockdev.c
parentc1303596a196613f1a765f8a536319577b2bb844 (diff)
block: use proper qerrors in qmp_block_resize
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 <stefanha@linux.vnet.ibm.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Diffstat (limited to 'blockdev.c')
-rw-r--r--blockdev.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/blockdev.c b/blockdev.c
index 5d16137878..1f83c888e7 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;
}
}