Commit b4d02820 authored by Max Reitz's avatar Max Reitz Committed by Kevin Wolf
Browse files

block: Invoke change media CB before NULLing drv



In order to handle host device passthrough, some guest device models
may call blk_is_inserted() to check whether the medium is inserted on
the host, when checking the guest tray status.

This tray status is inquired by blk_dev_change_media_cb(); because
bdrv_is_inserted() (invoked by blk_is_inserted()) always returns false
for BDS with drv set to NULL, blk_dev_change_media_cb() should therefore
be called before drv is set to NULL.

Signed-off-by: default avatarMax Reitz <mreitz@redhat.com>
Reviewed-by: default avatarEric Blake <eblake@redhat.com>
Reviewed-by: default avatarAlberto Garcia <berto@igalia.com>
Reviewed-by: default avatarKevin Wolf <kwolf@redhat.com>
Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
parent 1354c473
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -1912,6 +1912,10 @@ void bdrv_close(BlockDriverState *bs)
    bdrv_drain(bs); /* in case flush left pending I/O */
    notifier_list_notify(&bs->close_notifiers, bs);

    if (bs->blk) {
        blk_dev_change_media_cb(bs->blk, false);
    }

    if (bs->drv) {
        BdrvChild *child, *next;

@@ -1950,10 +1954,6 @@ void bdrv_close(BlockDriverState *bs)
        bs->full_open_options = NULL;
    }

    if (bs->blk) {
        blk_dev_change_media_cb(bs->blk, false);
    }

    QLIST_FOREACH_SAFE(ban, &bs->aio_notifiers, list, ban_next) {
        g_free(ban);
    }