[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 28/31] block: clarify error message for qmp-eject
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 28/31] block: clarify error message for qmp-eject |
Date: |
Thu, 19 May 2016 17:22:06 +0200 |
From: John Snow <address@hidden>
If you use HMP's eject but the CDROM tray is locked, you may get a
confusing error message informing you that the "tray isn't open."
As this is the point of eject, we can do a little better and help
clarify that the tray was locked and that it (might) open up later,
so try again.
It's not ideal, but it makes the semantics of the (legacy) eject
command more understandable to end users when they try to use it.
Signed-off-by: John Snow <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Reviewed-by: Fam Zheng <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
blockdev.c | 51 ++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 40 insertions(+), 11 deletions(-)
diff --git a/blockdev.c b/blockdev.c
index b6fa210..40e4e6f 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -2281,16 +2281,29 @@ 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;
+ int rc;
+
+ if (!has_force) {
+ force = false;
+ }
- qmp_blockdev_open_tray(device, has_force, force, &local_err);
+ rc = do_open_tray(device, force, &local_err);
if (local_err) {
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;
+ }
+
qmp_x_blockdev_remove_medium(device, errp);
}
@@ -2318,35 +2331,36 @@ void qmp_block_passwd(bool has_device, const char
*device,
aio_context_release(aio_context);
}
-void qmp_blockdev_open_tray(const char *device, bool has_force, bool force,
- Error **errp)
+/**
+ * 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.
+ */
+static int do_open_tray(const char *device, bool force, Error **errp)
{
BlockBackend *blk;
bool locked;
- if (!has_force) {
- force = false;
- }
-
blk = blk_by_name(device);
if (!blk) {
error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
"Device '%s' not found", device);
- return;
+ return -ENODEV;
}
if (!blk_dev_has_removable_media(blk)) {
error_setg(errp, "Device '%s' is not removable", device);
- return;
+ return -ENOTSUP;
}
if (!blk_dev_has_tray(blk)) {
/* Ignore this command on tray-less devices */
- return;
+ return ENOSYS;
}
if (blk_dev_is_tray_open(blk)) {
- return;
+ return 0;
}
locked = blk_dev_is_medium_locked(blk);
@@ -2357,6 +2371,21 @@ void qmp_blockdev_open_tray(const char *device, bool
has_force, bool force,
if (!locked || force) {
blk_dev_change_media_cb(blk, false);
}
+
+ if (locked && !force) {
+ return EINPROGRESS;
+ }
+
+ return 0;
+}
+
+void qmp_blockdev_open_tray(const char *device, bool has_force, bool force,
+ Error **errp)
+{
+ if (!has_force) {
+ force = false;
+ }
+ do_open_tray(device, force, errp);
}
void qmp_blockdev_close_tray(const char *device, Error **errp)
--
1.8.3.1
- [Qemu-block] [PULL 26/31] qcow2: Fix write_zeroes with partially allocated backing file cluster, (continued)
- [Qemu-block] [PULL 26/31] qcow2: Fix write_zeroes with partially allocated backing file cluster, Kevin Wolf, 2016/05/19
- [Qemu-block] [PULL 20/31] block: Add bdrv_has_blk(), Kevin Wolf, 2016/05/19
- [Qemu-block] [PULL 21/31] block: Avoid bs->blk in bdrv_next(), Kevin Wolf, 2016/05/19
- Re: [Qemu-block] [PULL 21/31] block: Avoid bs->blk in bdrv_next(), Paolo Bonzini, 2016/05/20
- Re: [Qemu-block] [PULL 21/31] block: Avoid bs->blk in bdrv_next(), Kevin Wolf, 2016/05/20
- Re: [Qemu-block] [PULL 21/31] block: Avoid bs->blk in bdrv_next(), Kevin Wolf, 2016/05/20
- Re: [Qemu-block] [PULL 21/31] block: Avoid bs->blk in bdrv_next(), Paolo Bonzini, 2016/05/20
- Re: [Qemu-block] [PULL 21/31] block: Avoid bs->blk in bdrv_next(), Kevin Wolf, 2016/05/20
- Re: [Qemu-block] [PULL 21/31] block: Avoid bs->blk in bdrv_next(), Paolo Bonzini, 2016/05/20
[Qemu-block] [PULL 25/31] qcow2: fix condition in is_zero_cluster, Kevin Wolf, 2016/05/19
[Qemu-block] [PULL 28/31] block: clarify error message for qmp-eject,
Kevin Wolf <=
[Qemu-block] [PULL 22/31] block: Don't return throttling info in query-named-block-nodes, Kevin Wolf, 2016/05/19
[Qemu-block] [PULL 29/31] qemu-io: Fix recent UI updates, Kevin Wolf, 2016/05/19
[Qemu-block] [PULL 23/31] block: Remove BlockDriverState.blk, Kevin Wolf, 2016/05/19
[Qemu-block] [PULL 24/31] block: Propagate AioContext change to all children, Kevin Wolf, 2016/05/19
[Qemu-block] [PULL 27/31] qemu-iotests: Some more write_zeroes tests, Kevin Wolf, 2016/05/19
[Qemu-block] [PULL 30/31] qemu-iotests: Simplify 109 with unaligned qemu-img compare, Kevin Wolf, 2016/05/19
[Qemu-block] [PULL 31/31] qemu-iotests: Fix regression in 136 on aio_read invalid, Kevin Wolf, 2016/05/19
Re: [Qemu-block] [Qemu-devel] [PULL 00/31] Block layer patches, Peter Maydell, 2016/05/19
[Qemu-block] [PULL 00/31] Block layer patches, Kevin Wolf, 2016/05/25