qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 33/50] blockdev: Respect NULL BDS in do_drive_del()


From: Max Reitz
Subject: [Qemu-devel] [PATCH 33/50] blockdev: Respect NULL BDS in do_drive_del()
Date: Mon, 26 Jan 2015 11:03:07 -0500

Signed-off-by: Max Reitz <address@hidden>
---
 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]