[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH v3 25/38] block: Add blk_remove_bs()
From: |
Max Reitz |
Subject: |
[Qemu-block] [PATCH v3 25/38] block: Add blk_remove_bs() |
Date: |
Wed, 3 Jun 2015 21:44:06 +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 4d6532f..93c14f9 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -312,6 +312,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)
@@ -321,9 +337,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 8561380..eba3130 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.4.1
- Re: [Qemu-block] [PATCH v3 18/38] block: Fail requests to empty BlockBackend, (continued)
- [Qemu-block] [PATCH v3 20/38] block: Add blk_insert_bs(), Max Reitz, 2015/06/03
- [Qemu-block] [PATCH v3 19/38] block: Prepare remaining BB functions for NULL BDS, Max Reitz, 2015/06/03
- [Qemu-block] [PATCH v3 21/38] block: Prepare for NULL BDS, Max Reitz, 2015/06/03
- [Qemu-block] [PATCH v3 22/38] blockdev: Do not create BDS for empty drive, Max Reitz, 2015/06/03
- [Qemu-block] [PATCH v3 23/38] blockdev: Pull out blockdev option extraction, Max Reitz, 2015/06/03
- [Qemu-block] [PATCH v3 25/38] block: Add blk_remove_bs(),
Max Reitz <=
- [Qemu-block] [PATCH v3 26/38] blockdev: Add blockdev-open-tray, Max Reitz, 2015/06/03
- [Qemu-block] [PATCH v3 24/38] blockdev: Allow more options for BB-less BDS tree, Max Reitz, 2015/06/03
- [Qemu-block] [PATCH v3 27/38] blockdev: Add blockdev-close-tray, Max Reitz, 2015/06/03
- [Qemu-block] [PATCH v3 28/38] blockdev: Add blockdev-remove-medium, Max Reitz, 2015/06/03
- [Qemu-block] [PATCH v3 29/38] blockdev: Add blockdev-insert-medium, Max Reitz, 2015/06/03
- [Qemu-block] [PATCH v3 30/38] blockdev: Implement eject with basic operations, Max Reitz, 2015/06/03
- [Qemu-block] [PATCH v3 31/38] blockdev: Implement change with basic operations, Max Reitz, 2015/06/03