Signed-off-by: Max Reitz <mre...@redhat.com> --- blockdev.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/blockdev.c b/blockdev.c index f3091df..f82b20c 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2019,7 +2019,6 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data) error_report("Device '%s' not found", id); return -1; } - bs = blk_bs(blk); if (!blk_legacy_dinfo(blk)) { error_report("Deleting device added with blockdev-add" @@ -2027,10 +2026,11 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data) return -1; } - aio_context = bdrv_get_aio_context(bs); + aio_context = blk_get_aio_context(blk); aio_context_acquire(aio_context); - if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_DRIVE_DEL, &local_err)) { + bs = blk_bs(blk); + if (bs && bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_DRIVE_DEL, &local_err)) { error_report("%s", error_get_pretty(local_err)); error_free(local_err); aio_context_release(aio_context); @@ -2039,8 +2039,10 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data) /* quiesce block driver; prevent further io */ bdrv_drain_all(); - bdrv_flush(bs); - bdrv_close(bs); + if (bs) { + bdrv_flush(bs); + bdrv_close(bs); + } /* if we have a device attached to this BlockDriverState * then we need to make the drive anonymous until the device -- 2.1.0