Skip to content

Commit

Permalink
block: Inquire tray state before tray-moved events
Browse files Browse the repository at this point in the history
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 <mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
  • Loading branch information
XanClic authored and kevmw committed Nov 11, 2015
1 parent de2c6c0 commit f1f5706
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions block/block-backend.c
Expand Up @@ -429,18 +429,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);
}
}
}
Expand Down

0 comments on commit f1f5706

Please sign in to comment.