[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 18/48] block: Add BB-BDS remove/insert notifiers
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 18/48] block: Add BB-BDS remove/insert notifiers |
Date: |
Fri, 29 Jan 2016 18:37:24 +0100 |
From: Max Reitz <address@hidden>
bdrv_close() no longer signifies ejection of a medium, this is now done
by removing the BDS from the BB. Therefore, we want to have a notifier
for that in the BB instead of a close notifier in the BDS. The former is
added now, the latter is removed later.
Symmetrically, another notifier list is added that is invoked whenever a
BDS is inserted. We will need that for virtio-blk and virtio-scsi, which
can then remove their op blockers on BDS ejection and set them up on
insertion.
Signed-off-by: Max Reitz <address@hidden>
Reviewed-by: Kevin Wolf <address@hidden>
Reviewed-by: Fam Zheng <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/block-backend.c | 20 ++++++++++++++++++++
include/sysemu/block-backend.h | 2 ++
2 files changed, 22 insertions(+)
diff --git a/block/block-backend.c b/block/block-backend.c
index a4208f1..1872191 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -49,6 +49,8 @@ struct BlockBackend {
BlockdevOnError on_read_error, on_write_error;
bool iostatus_enabled;
BlockDeviceIoStatus iostatus;
+
+ NotifierList remove_bs_notifiers, insert_bs_notifiers;
};
typedef struct BlockBackendAIOCB {
@@ -99,6 +101,8 @@ BlockBackend *blk_new(const char *name, Error **errp)
blk = g_new0(BlockBackend, 1);
blk->name = g_strdup(name);
blk->refcnt = 1;
+ notifier_list_init(&blk->remove_bs_notifiers);
+ notifier_list_init(&blk->insert_bs_notifiers);
QTAILQ_INSERT_TAIL(&blk_backends, blk, link);
return blk;
}
@@ -167,6 +171,8 @@ static void blk_delete(BlockBackend *blk)
bdrv_unref(blk->bs);
blk->bs = NULL;
}
+ assert(QLIST_EMPTY(&blk->remove_bs_notifiers.notifiers));
+ assert(QLIST_EMPTY(&blk->insert_bs_notifiers.notifiers));
if (blk->root_state.throttle_state) {
g_free(blk->root_state.throttle_group);
throttle_group_unref(blk->root_state.throttle_state);
@@ -345,6 +351,8 @@ void blk_hide_on_behalf_of_hmp_drive_del(BlockBackend *blk)
*/
void blk_remove_bs(BlockBackend *blk)
{
+ notifier_list_notify(&blk->remove_bs_notifiers, blk);
+
blk_update_root_state(blk);
blk->bs->blk = NULL;
@@ -361,6 +369,8 @@ void blk_insert_bs(BlockBackend *blk, BlockDriverState *bs)
bdrv_ref(bs);
blk->bs = bs;
bs->blk = blk;
+
+ notifier_list_notify(&blk->insert_bs_notifiers, blk);
}
/*
@@ -1126,6 +1136,16 @@ void blk_remove_aio_context_notifier(BlockBackend *blk,
}
}
+void blk_add_remove_bs_notifier(BlockBackend *blk, Notifier *notify)
+{
+ notifier_list_add(&blk->remove_bs_notifiers, notify);
+}
+
+void blk_add_insert_bs_notifier(BlockBackend *blk, Notifier *notify)
+{
+ notifier_list_add(&blk->insert_bs_notifiers, notify);
+}
+
void blk_add_close_notifier(BlockBackend *blk, Notifier *notify)
{
if (blk->bs) {
diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h
index 1568554..e12be67 100644
--- a/include/sysemu/block-backend.h
+++ b/include/sysemu/block-backend.h
@@ -164,6 +164,8 @@ void blk_remove_aio_context_notifier(BlockBackend *blk,
void *),
void (*detach_aio_context)(void *),
void *opaque);
+void blk_add_remove_bs_notifier(BlockBackend *blk, Notifier *notify);
+void blk_add_insert_bs_notifier(BlockBackend *blk, Notifier *notify);
void blk_add_close_notifier(BlockBackend *blk, Notifier *notify);
void blk_io_plug(BlockBackend *blk);
void blk_io_unplug(BlockBackend *blk);
--
1.8.3.1
- [Qemu-devel] [PULL 16/48] block: Release named dirty bitmaps in bdrv_close(), (continued)
- [Qemu-devel] [PULL 16/48] block: Release named dirty bitmaps in bdrv_close(), Kevin Wolf, 2016/01/29
- [Qemu-devel] [PULL 10/48] iotests: Move _filter_nbd into common.filter, Kevin Wolf, 2016/01/29
- [Qemu-devel] [PULL 15/48] block: Remove unused struct definition BlockFinishData, Kevin Wolf, 2016/01/29
- [Qemu-devel] [PULL 11/48] iotests: Make _filter_nbd drop log lines, Kevin Wolf, 2016/01/29
- [Qemu-devel] [PULL 17/48] iotests: Add test for eject under NBD server, Kevin Wolf, 2016/01/29
- [Qemu-devel] [PULL 08/48] iotests: Rename filter_nbd to _filter_nbd in 083, Kevin Wolf, 2016/01/29
- [Qemu-devel] [PULL 21/48] nbd: Switch from close to eject notifier, Kevin Wolf, 2016/01/29
- [Qemu-devel] [PULL 22/48] block: Remove BDS close notifier, Kevin Wolf, 2016/01/29
- [Qemu-devel] [PULL 24/48] blockdev: Use blk_remove_bs() in do_drive_del(), Kevin Wolf, 2016/01/29
- [Qemu-devel] [PULL 23/48] block: Use blk_remove_bs() in blk_delete(), Kevin Wolf, 2016/01/29
- [Qemu-devel] [PULL 18/48] block: Add BB-BDS remove/insert notifiers,
Kevin Wolf <=
- [Qemu-devel] [PULL 19/48] virtio-blk: Functions for op blocker management, Kevin Wolf, 2016/01/29
- [Qemu-devel] [PULL 20/48] virtio-scsi: Catch BDS-BB removal/insertion, Kevin Wolf, 2016/01/29
- [Qemu-devel] [PULL 25/48] block: Make bdrv_close() static, Kevin Wolf, 2016/01/29
- [Qemu-devel] [PULL 30/48] iotests: Add test for multiple BB on BDS tree, Kevin Wolf, 2016/01/29
- [Qemu-devel] [PULL 26/48] block: Add list of all BlockDriverStates, Kevin Wolf, 2016/01/29
- [Qemu-devel] [PULL 34/48] qcow: Assign bs->file->bs to file in qcow_co_get_block_status, Kevin Wolf, 2016/01/29
- [Qemu-devel] [PULL 37/48] iscsi: Assign bs to file in iscsi_co_get_block_status, Kevin Wolf, 2016/01/29
- [Qemu-devel] [PULL 39/48] qed: Assign bs->file->bs to file in bdrv_qed_co_get_block_status, Kevin Wolf, 2016/01/29
- [Qemu-devel] [PULL 32/48] block: acquire in bdrv_query_image_info, Kevin Wolf, 2016/01/29
- [Qemu-devel] [PULL 35/48] qcow2: Assign bs->file->bs to file in qcow2_co_get_block_status, Kevin Wolf, 2016/01/29