[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH RESEND 37/50] block: Add blk_remove_bs()
From: |
Max Reitz |
Subject: |
[Qemu-devel] [PATCH RESEND 37/50] block: Add blk_remove_bs() |
Date: |
Tue, 27 Jan 2015 14:46:10 -0500 |
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>
---
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 656ebfc..d2c1bff 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -312,6 +312,22 @@ void blk_hide_on_behalf_of_do_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 b6cf5bf..c8b47f7 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_do_drive_del(BlockBackend *blk);
--
2.1.0
- [Qemu-devel] [PATCH RESEND 47/50] blockdev: Add read-only option to blockdev-change-medium, (continued)
- [Qemu-devel] [PATCH RESEND 47/50] blockdev: Add read-only option to blockdev-change-medium, Max Reitz, 2015/01/27
- [Qemu-devel] [PATCH RESEND 44/50] block: Inquire tray state before tray-moved events, Max Reitz, 2015/01/27
- [Qemu-devel] [PATCH RESEND 49/50] iotests: More options for VM.add_drive(), Max Reitz, 2015/01/27
- [Qemu-devel] [PATCH RESEND 50/50] iotests: Add test for change-related QMP commands, Max Reitz, 2015/01/27
- [Qemu-devel] [PATCH RESEND 48/50] hmp: Add read-only option to change command, Max Reitz, 2015/01/27
- [Qemu-devel] [PATCH RESEND 03/50] hw/block/fdc: Implement tray status, Max Reitz, 2015/01/27
- [Qemu-devel] [PATCH RESEND 17/50] block: Respect empty BB in bdrv_lookup_bs(), Max Reitz, 2015/01/27
- [Qemu-devel] [PATCH RESEND 37/50] block: Add blk_remove_bs(),
Max Reitz <=
- [Qemu-devel] [PATCH RESEND 20/50] blockdev: Check blk_is_available() in sn-del-int-sync, Max Reitz, 2015/01/27
- [Qemu-devel] [PATCH RESEND 14/50] block: Make some BB functions fall back to BBRS, Max Reitz, 2015/01/27
- [Qemu-devel] [PATCH RESEND 01/50] blockdev: Allow creation of BDS trees without BB, Max Reitz, 2015/01/27
- [Qemu-devel] [PATCH RESEND 22/50] blockdev: Check BB validity in drive-backup TA, Max Reitz, 2015/01/27
- [Qemu-devel] [PATCH RESEND 13/50] block: Add BlockBackendRootState, Max Reitz, 2015/01/27