From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37830) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aJ1BA-0006IG-Dq for qemu-devel@nongnu.org; Tue, 12 Jan 2016 10:48:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aJ1B9-0006lr-91 for qemu-devel@nongnu.org; Tue, 12 Jan 2016 10:48:16 -0500 From: Max Reitz Date: Tue, 12 Jan 2016 16:47:52 +0100 Message-Id: <1452613674-12248-3-git-send-email-mreitz@redhat.com> In-Reply-To: <1452613674-12248-1-git-send-email-mreitz@redhat.com> References: <1452613674-12248-1-git-send-email-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH 2/4] blockdev: Fix 'change' for slot devices List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-block@nongnu.org Cc: Kevin Wolf , Peter Maydell , qemu-stable , Markus Armbruster , qemu-devel@nongnu.org, Max Reitz , John Snow 'change' and related operations did not work when used on guest devices featuring removable media but no actual tray, because blk_dev_is_tray_open() always returned false for them and the blockdev-{insert,remove}-medium commands required it to return true. Fix this by making blockdev-{insert,remove}-medium work on tray-less devices. Also, blockdev-{open,close}-tray are now explicitly no-ops when invoked on such devices, and blk_dev_change_media_cb() is instead called by blockdev-{insert,remove}-medium (for tray-less devices only). Reported-by: Peter Maydell Cc: qemu-stable Signed-off-by: Max Reitz --- blockdev.c | 27 +++++++++++++++++++++++++-- qapi/block-core.json | 3 +-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/blockdev.c b/blockdev.c index 2df0c6d..f053be6 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2305,6 +2305,11 @@ void qmp_blockdev_open_tray(const char *device, bool has_force, bool force, return; } + if (!blk_dev_has_tray(blk)) { + /* Ignore this command on tray-less devices */ + return; + } + if (blk_dev_is_tray_open(blk)) { return; } @@ -2335,6 +2340,11 @@ void qmp_blockdev_close_tray(const char *device, Error **errp) return; } + if (!blk_dev_has_tray(blk)) { + /* Ignore this command on tray-less devices */ + return; + } + if (!blk_dev_is_tray_open(blk)) { return; } @@ -2364,7 +2374,7 @@ void qmp_x_blockdev_remove_medium(const char *device, Error **errp) return; } - if (has_device && !blk_dev_is_tray_open(blk)) { + if (has_device && blk_dev_has_tray(blk) && !blk_dev_is_tray_open(blk)) { error_setg(errp, "Tray of device '%s' is not open", device); return; } @@ -2381,6 +2391,12 @@ void qmp_x_blockdev_remove_medium(const char *device, Error **errp) goto out; } + if (!blk_dev_has_tray(blk)) { + /* For tray-less devices, blockdev-open-tray is a no-op (or may not be + * called at all); therefore, the medium needs to be ejected here */ + blk_dev_change_media_cb(blk, false); + } + /* This follows the convention established by bdrv_make_anon() */ if (bs->device_list.tqe_prev) { QTAILQ_REMOVE(&bdrv_states, bs, device_list); @@ -2414,7 +2430,7 @@ static void qmp_blockdev_insert_anon_medium(const char *device, return; } - if (has_device && !blk_dev_is_tray_open(blk)) { + if (has_device && blk_dev_has_tray(blk) && !blk_dev_is_tray_open(blk)) { error_setg(errp, "Tray of device '%s' is not open", device); return; } @@ -2424,6 +2440,13 @@ static void qmp_blockdev_insert_anon_medium(const char *device, return; } + if (!blk_dev_has_tray(blk)) { + /* For tray-less devices, blockdev-close-tray is a no-op (or may not be + * called at all); therefore, the medium needs to be pushed into the + * slot here */ + blk_dev_change_media_cb(blk, true); + } + blk_insert_bs(blk, bs); QTAILQ_INSERT_TAIL(&bdrv_states, bs, device_list); diff --git a/qapi/block-core.json b/qapi/block-core.json index 0a915ed..40239bf 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2098,8 +2098,7 @@ # respond to the eject request # - if the BlockBackend denoted by @device does not have a guest device attached # to it -# - if the guest device does not have an actual tray and is empty, for instance -# for floppy disk drives +# - if the guest device does not have an actual tray # # @device: block device name # -- 2.7.0