block: Add blk_remove_bs()
authorMax Reitz <mreitz@redhat.com>
Mon, 26 Oct 2015 20:39:05 +0000 (21:39 +0100)
committerKevin Wolf <kwolf@redhat.com>
Wed, 11 Nov 2015 15:22:46 +0000 (16:22 +0100)
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 <mreitz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block/block-backend.c
include/sysemu/block-backend.h

index 19fdaaec1a06e4b830e6e9ee0fa881a795ef6a6d..878c448855f5bbde6c1d135d06ea69d69f36aa0f 100644 (file)
@@ -333,6 +333,18 @@ void blk_hide_on_behalf_of_hmp_drive_del(BlockBackend *blk)
     }
 }
 
+/*
+ * Disassociates the currently associated BlockDriverState from @blk.
+ */
+void blk_remove_bs(BlockBackend *blk)
+{
+    blk_update_root_state(blk);
+
+    blk->bs->blk = NULL;
+    bdrv_unref(blk->bs);
+    blk->bs = NULL;
+}
+
 /*
  * Associates a new BlockDriverState with @blk.
  */
index 9306a527bb259df7a5bb7135b7666667a6631fed..14a6d32bb2ce58d88edd168896f13aedf19c81e8 100644 (file)
@@ -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);