[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 25/31] blockdev: clean up error handling in do_open_t
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 25/31] blockdev: clean up error handling in do_open_tray |
Date: |
Wed, 8 Jun 2016 11:16:51 +0200 |
From: Colin Lord <address@hidden>
Returns negative error codes and accompanying error messages in cases where
the device has no tray or the tray is locked and isn't forced open. This
extra information should result in better flexibility in functions that
call do_open_tray.
Suggested by: Markus Armbruster <address@hidden>
Signed-off-by: Colin Lord <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
blockdev.c | 46 ++++++++++++++++++++++++++++------------------
1 file changed, 28 insertions(+), 18 deletions(-)
diff --git a/blockdev.c b/blockdev.c
index 6ccb8e1..7fd515a 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -56,6 +56,8 @@
static QTAILQ_HEAD(, BlockDriverState) monitor_bdrv_states =
QTAILQ_HEAD_INITIALIZER(monitor_bdrv_states);
+static int do_open_tray(const char *device, bool force, Error **errp);
+
static const char *const if_name[IF_COUNT] = {
[IF_NONE] = "none",
[IF_IDE] = "ide",
@@ -2274,8 +2276,6 @@ exit:
block_job_txn_unref(block_job_txn);
}
-static int do_open_tray(const char *device, bool force, Error **errp);
-
void qmp_eject(const char *device, bool has_force, bool force, Error **errp)
{
Error *local_err = NULL;
@@ -2286,16 +2286,11 @@ void qmp_eject(const char *device, bool has_force, bool
force, Error **errp)
}
rc = do_open_tray(device, force, &local_err);
- if (local_err) {
+ if (rc && rc != -ENOSYS) {
error_propagate(errp, local_err);
return;
}
-
- if (rc == EINPROGRESS) {
- error_setg(errp, "Device '%s' is locked and force was not specified, "
- "wait for tray to open and try again", device);
- return;
- }
+ error_free(local_err);
qmp_x_blockdev_remove_medium(device, errp);
}
@@ -2324,11 +2319,16 @@ void qmp_block_passwd(bool has_device, const char
*device,
aio_context_release(aio_context);
}
-/**
- * returns -errno on fatal error, +errno for non-fatal situations.
- * errp will always be set when the return code is negative.
- * May return +ENOSYS if the device has no tray,
- * or +EINPROGRESS if the tray is locked and the guest has been notified.
+/*
+ * Attempt to open the tray of @device.
+ * If @force, ignore its tray lock.
+ * Else, if the tray is locked, don't open it, but ask the guest to open it.
+ * On error, store an error through @errp and return -errno.
+ * If @device does not exist, return -ENODEV.
+ * If it has no removable media, return -ENOTSUP.
+ * If it has no tray, return -ENOSYS.
+ * If the guest was asked to open the tray, return -EINPROGRESS.
+ * Else, return 0.
*/
static int do_open_tray(const char *device, bool force, Error **errp)
{
@@ -2348,8 +2348,8 @@ static int do_open_tray(const char *device, bool force,
Error **errp)
}
if (!blk_dev_has_tray(blk)) {
- /* Ignore this command on tray-less devices */
- return ENOSYS;
+ error_setg(errp, "Device '%s' does not have a tray", device);
+ return -ENOSYS;
}
if (blk_dev_is_tray_open(blk)) {
@@ -2366,7 +2366,9 @@ static int do_open_tray(const char *device, bool force,
Error **errp)
}
if (locked && !force) {
- return EINPROGRESS;
+ error_setg(errp, "Device '%s' is locked and force was not specified, "
+ "wait for tray to open and try again", device);
+ return -EINPROGRESS;
}
return 0;
@@ -2375,10 +2377,18 @@ static int do_open_tray(const char *device, bool force,
Error **errp)
void qmp_blockdev_open_tray(const char *device, bool has_force, bool force,
Error **errp)
{
+ Error *local_err = NULL;
+ int rc;
+
if (!has_force) {
force = false;
}
- do_open_tray(device, force, errp);
+ rc = do_open_tray(device, force, &local_err);
+ if (rc && rc != -ENOSYS && rc != -EINPROGRESS) {
+ error_propagate(errp, local_err);
+ return;
+ }
+ error_free(local_err);
}
void qmp_blockdev_close_tray(const char *device, Error **errp)
--
1.8.3.1
- [Qemu-devel] [PULL 18/31] block: Kill bdrv_co_write_zeroes(), (continued)
- [Qemu-devel] [PULL 18/31] block: Kill bdrv_co_write_zeroes(), Kevin Wolf, 2016/06/08
- [Qemu-devel] [PULL 04/31] qemu-iotests: Test one more spot for optimizing write_zeroes, Kevin Wolf, 2016/06/08
- [Qemu-devel] [PULL 13/31] gluster: Convert to bdrv_co_pwrite_zeroes(), Kevin Wolf, 2016/06/08
- [Qemu-devel] [PULL 12/31] blkreplay: Convert to bdrv_co_pwrite_zeroes(), Kevin Wolf, 2016/06/08
- [Qemu-devel] [PULL 16/31] raw_bsd: Convert to bdrv_co_pwrite_zeroes(), Kevin Wolf, 2016/06/08
- [Qemu-devel] [PULL 14/31] qed: Convert to bdrv_co_pwrite_zeroes(), Kevin Wolf, 2016/06/08
- [Qemu-devel] [PULL 28/31] qemu-img bench: Sequential writes, Kevin Wolf, 2016/06/08
- [Qemu-devel] [PULL 23/31] qcow2: avoid extra flushes in qcow2, Kevin Wolf, 2016/06/08
- [Qemu-devel] [PULL 27/31] qemu-img bench, Kevin Wolf, 2016/06/08
- [Qemu-devel] [PULL 24/31] block: Fix bdrv_all_delete_snapshot() error handling, Kevin Wolf, 2016/06/08
- [Qemu-devel] [PULL 25/31] blockdev: clean up error handling in do_open_tray,
Kevin Wolf <=
- [Qemu-devel] [PULL 20/31] migration/block: Convert saving to BlockBackend, Kevin Wolf, 2016/06/08
- [Qemu-devel] [PULL 29/31] qemu-img bench: Make start offset configurable, Kevin Wolf, 2016/06/08
- [Qemu-devel] [PULL 22/31] raw-posix: Fetch max sectors for host block device, Kevin Wolf, 2016/06/08
- [Qemu-devel] [PULL 26/31] block: Don't emulate natively supported pwritev flags, Kevin Wolf, 2016/06/08
- [Qemu-devel] [PULL 31/31] qemu-img bench: Add --flush-interval, Kevin Wolf, 2016/06/08
- [Qemu-devel] [PULL 30/31] qemu-img bench: Implement -S (step size), Kevin Wolf, 2016/06/08
- Re: [Qemu-devel] [PULL 00/31] Block layer patches, Peter Maydell, 2016/06/08