[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-stable] [PATCH 13/35] blockdev: Fix 'change' for slot devices
From: |
Michael Roth |
Subject: |
[Qemu-stable] [PATCH 13/35] blockdev: Fix 'change' for slot devices |
Date: |
Mon, 21 Mar 2016 12:28:11 -0500 |
From: Max Reitz <address@hidden>
'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 <address@hidden>
Cc: qemu-stable <address@hidden>
Signed-off-by: Max Reitz <address@hidden>
Reviewed-by: Alberto Garcia <address@hidden>
Message-id: address@hidden
Reviewed-by: Eric Blake <address@hidden>
(cherry picked from commit 12c7ec87a7d88919b23736176eba3118d1521372)
Signed-off-by: Michael Roth <address@hidden>
---
blockdev.c | 31 +++++++++++++++++++++++++++++--
qapi/block-core.json | 3 +--
2 files changed, 30 insertions(+), 4 deletions(-)
diff --git a/blockdev.c b/blockdev.c
index 80932e8..7c81f48 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -2306,6 +2306,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;
}
@@ -2336,6 +2341,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;
}
@@ -2365,7 +2375,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;
}
@@ -2390,6 +2400,14 @@ void qmp_x_blockdev_remove_medium(const char *device,
Error **errp)
blk_remove_bs(blk);
+ 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.
+ * Do it after blk_remove_bs() so blk_is_inserted(blk) returns the
@load
+ * value passed here (i.e. false). */
+ blk_dev_change_media_cb(blk, false);
+ }
+
out:
aio_context_release(aio_context);
}
@@ -2415,7 +2433,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;
}
@@ -2428,6 +2446,15 @@ static void qmp_blockdev_insert_anon_medium(const char
*device,
blk_insert_bs(blk, bs);
QTAILQ_INSERT_TAIL(&bdrv_states, bs, device_list);
+
+ 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.
+ * Do it after blk_insert_bs() so blk_is_inserted(blk) returns the
@load
+ * value passed here (i.e. true). */
+ blk_dev_change_media_cb(blk, true);
+ }
}
void qmp_x_blockdev_insert_medium(const char *device, const char *node_name,
diff --git a/qapi/block-core.json b/qapi/block-core.json
index 5a23165..419f112 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -2048,8 +2048,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
#
--
1.9.1
- [Qemu-stable] [PATCH 00/35] Patch Round-up for stable 2.5.1, freeze on 2016-03-25, Michael Roth, 2016/03/21
- [Qemu-stable] [PATCH 09/35] ivshmem: no need for opaque argument, Michael Roth, 2016/03/21
- [Qemu-stable] [PATCH 12/35] block: Add blk_dev_has_tray(), Michael Roth, 2016/03/21
- [Qemu-stable] [PATCH 18/35] ehci: update irq on reset, Michael Roth, 2016/03/21
- [Qemu-stable] [PATCH 15/35] net/filter: fix nf->netdev_id leak, Michael Roth, 2016/03/21
- [Qemu-stable] [PATCH 11/35] net: rocker: fix an incorrect array bounds check, Michael Roth, 2016/03/21
- [Qemu-stable] [PATCH 17/35] net: set endianness on all backend devices, Michael Roth, 2016/03/21
- [Qemu-stable] [PATCH 13/35] blockdev: Fix 'change' for slot devices,
Michael Roth <=
- [Qemu-stable] [PATCH 01/35] ehci: make idt processing more robust, Michael Roth, 2016/03/21
- [Qemu-stable] [PATCH 14/35] net/dump: fix nfds->filename leak, Michael Roth, 2016/03/21
- [Qemu-stable] [PATCH 21/35] s390x/css: fix control flags during csch, Michael Roth, 2016/03/21
- [Qemu-stable] [PATCH 19/35] block/raw-posix: avoid bogus fixup for cylinders on DASD disks, Michael Roth, 2016/03/21
- [Qemu-stable] [PATCH 16/35] net: ne2000: check ring buffer control registers, Michael Roth, 2016/03/21
- [Qemu-stable] [PATCH 20/35] s390x/ioinst: set type and len for SEI response, Michael Roth, 2016/03/21
- [Qemu-stable] [PATCH 24/35] qmp: Fix reference-counting of qnull on empty output visit, Michael Roth, 2016/03/21
- [Qemu-stable] [PATCH 23/35] cpus: use broadcast on qemu_pause_cond, Michael Roth, 2016/03/21
- [Qemu-stable] [PATCH 25/35] block: set device_list.tqe_prev to NULL on BDS removal, Michael Roth, 2016/03/21
- [Qemu-stable] [PATCH 10/35] ivshmem: remove redundant assignment, fix crash with msi=off, Michael Roth, 2016/03/21