qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH v5 26/38] block: Add blk_remove_bs()


From: Max Reitz
Subject: [Qemu-devel] [PATCH v5 26/38] block: Add blk_remove_bs()
Date: Fri, 18 Sep 2015 17:23:01 +0200

This function removes the BlockDriverState associated with the given
BlockBackend from that BB and sets the BDS pointer in the BB to NULL.

Signed-off-by: Max Reitz <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
---
 block/block-backend.c          | 22 +++++++++++++++++++++-
 include/sysemu/block-backend.h |  1 +
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/block/block-backend.c b/block/block-backend.c
index 652385e..66ecc07 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -314,6 +314,22 @@ void blk_hide_on_behalf_of_hmp_drive_del(BlockBackend *blk)
 }
 
 /*
+ * Disassociates the currently associated BlockDriverState from @blk.
+ */
+void blk_remove_bs(BlockBackend *blk)
+{
+    if (!blk->bs) {
+        return;
+    }
+
+    blk_update_root_state(blk);
+
+    bdrv_unref(blk->bs);
+    blk->bs->blk = NULL;
+    blk->bs = NULL;
+}
+
+/*
  * Associates a new BlockDriverState with @blk.
  */
 void blk_insert_bs(BlockBackend *blk, BlockDriverState *bs)
@@ -323,9 +339,13 @@ void blk_insert_bs(BlockBackend *blk, BlockDriverState *bs)
     }
 
     assert(!blk->bs);
-    assert(!bs->blk);
     bdrv_ref(bs);
     blk->bs = bs;
+
+    if (bs->blk) {
+        blk_remove_bs(bs->blk);
+    }
+
     bs->blk = blk;
 }
 
diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h
index 9306a52..14a6d32 100644
--- a/include/sysemu/block-backend.h
+++ b/include/sysemu/block-backend.h
@@ -72,6 +72,7 @@ BlockBackend *blk_by_name(const char *name);
 BlockBackend *blk_next(BlockBackend *blk);
 
 BlockDriverState *blk_bs(BlockBackend *blk);
+void blk_remove_bs(BlockBackend *blk);
 void blk_insert_bs(BlockBackend *blk, BlockDriverState *bs);
 
 void blk_hide_on_behalf_of_hmp_drive_del(BlockBackend *blk);
-- 
2.5.2




reply via email to

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