[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH RESEND 44/50] block: Inquire tray state before tray-
From: |
Max Reitz |
Subject: |
[Qemu-devel] [PATCH RESEND 44/50] block: Inquire tray state before tray-moved events |
Date: |
Tue, 27 Jan 2015 14:46:17 -0500 |
blk_dev_change_media_cb() is called for all potential tray movements;
however, it is possible to request closing the tray but nothing actually
happening (on a floppy disk drive without a medium).
Thus, the actual tray status should be inquired before sending a
tray-moved event (and an event should be sent whenever the status
changed).
Checking @load is now superfluous; it was necessary because it was
possible to change a medium without having explicitly opened the tray
and closed it again (or it might have been possible, at least). This is
no longer possible, though.
Signed-off-by: Max Reitz <address@hidden>
---
block/block-backend.c | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/block/block-backend.c b/block/block-backend.c
index d2c1bff..7c18f8d 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -420,18 +420,15 @@ void blk_set_dev_ops(BlockBackend *blk, const BlockDevOps
*ops,
void blk_dev_change_media_cb(BlockBackend *blk, bool load)
{
if (blk->dev_ops && blk->dev_ops->change_media_cb) {
- bool tray_was_closed = !blk_dev_is_tray_open(blk);
+ bool tray_was_open, tray_is_open;
+ tray_was_open = blk_dev_is_tray_open(blk);
blk->dev_ops->change_media_cb(blk->dev_opaque, load);
- if (tray_was_closed) {
- /* tray open */
- qapi_event_send_device_tray_moved(blk_name(blk),
- true, &error_abort);
- }
- if (load) {
- /* tray close */
- qapi_event_send_device_tray_moved(blk_name(blk),
- false, &error_abort);
+ tray_is_open = blk_dev_is_tray_open(blk);
+
+ if (tray_was_open != tray_is_open) {
+ qapi_event_send_device_tray_moved(blk_name(blk), tray_is_open,
+ &error_abort);
}
}
}
--
2.1.0
- [Qemu-devel] [PATCH RESEND 45/50] qmp: Introduce blockdev-change-medium, (continued)
- [Qemu-devel] [PATCH RESEND 45/50] qmp: Introduce blockdev-change-medium, Max Reitz, 2015/01/27
- [Qemu-devel] [PATCH RESEND 42/50] blockdev: Implement eject with basic operations, Max Reitz, 2015/01/27
- [Qemu-devel] [PATCH RESEND 43/50] blockdev: Implement change with basic operations, Max Reitz, 2015/01/27
- [Qemu-devel] [PATCH RESEND 47/50] blockdev: Add read-only option to blockdev-change-medium, Max Reitz, 2015/01/27
- [Qemu-devel] [PATCH RESEND 44/50] block: Inquire tray state before tray-moved events,
Max Reitz <=
- [Qemu-devel] [PATCH RESEND 49/50] iotests: More options for VM.add_drive(), Max Reitz, 2015/01/27
- [Qemu-devel] [PATCH RESEND 50/50] iotests: Add test for change-related QMP commands, Max Reitz, 2015/01/27
- [Qemu-devel] [PATCH RESEND 48/50] hmp: Add read-only option to change command, Max Reitz, 2015/01/27