[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 12/24] block: Implement .(can_)set_aio_ctx for BlockB
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 12/24] block: Implement .(can_)set_aio_ctx for BlockBackend |
Date: |
Mon, 20 May 2019 18:14:41 +0200 |
bdrv_try_set_aio_context() currently fails if a BlockBackend is attached
to a node because it doesn't implement the BdrvChildRole callbacks for
AioContext management.
We can allow changing the AioContext of monitor-owned BlockBackends as
long as no device is attached to them.
When setting the AioContext of the root node of a BlockBackend, we now
need to pass blk->root as an ignored child because we don't want the
root node to recursively call back into BlockBackend and execute
blk_do_set_aio_context() a second time.
Signed-off-by: Kevin Wolf <address@hidden>
---
block/block-backend.c | 45 +++++++++++++++++++++++++++++++++++++++++--
1 file changed, 43 insertions(+), 2 deletions(-)
diff --git a/block/block-backend.c b/block/block-backend.c
index f78e82a707..0e75fc8849 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -124,6 +124,11 @@ static void blk_root_drained_end(BdrvChild *child);
static void blk_root_change_media(BdrvChild *child, bool load);
static void blk_root_resize(BdrvChild *child);
+static bool blk_root_can_set_aio_ctx(BdrvChild *child, AioContext *ctx,
+ GSList **ignore, Error **errp);
+static void blk_root_set_aio_ctx(BdrvChild *child, AioContext *ctx,
+ GSList **ignore);
+
static char *blk_root_get_parent_desc(BdrvChild *child)
{
BlockBackend *blk = child->opaque;
@@ -300,6 +305,9 @@ static const BdrvChildRole child_root = {
.attach = blk_root_attach,
.detach = blk_root_detach,
+
+ .can_set_aio_ctx = blk_root_can_set_aio_ctx,
+ .set_aio_ctx = blk_root_set_aio_ctx,
};
/*
@@ -1852,7 +1860,8 @@ static AioContext *blk_aiocb_get_aio_context(BlockAIOCB
*acb)
return blk_get_aio_context(blk_acb->blk);
}
-void blk_set_aio_context(BlockBackend *blk, AioContext *new_context)
+static void blk_do_set_aio_context(BlockBackend *blk, AioContext *new_context,
+ bool update_root_node)
{
BlockDriverState *bs = blk_bs(blk);
ThrottleGroupMember *tgm = &blk->public.throttle_group_member;
@@ -1864,10 +1873,42 @@ void blk_set_aio_context(BlockBackend *blk, AioContext
*new_context)
throttle_group_attach_aio_context(tgm, new_context);
bdrv_drained_end(bs);
}
- bdrv_set_aio_context(bs, new_context);
+ if (update_root_node) {
+ GSList *ignore = g_slist_prepend(NULL, blk->root);
+ bdrv_set_aio_context_ignore(bs, new_context, &ignore);
+ g_slist_free(ignore);
+ }
}
}
+void blk_set_aio_context(BlockBackend *blk, AioContext *new_context)
+{
+ blk_do_set_aio_context(blk, new_context, true);
+}
+
+static bool blk_root_can_set_aio_ctx(BdrvChild *child, AioContext *ctx,
+ GSList **ignore, Error **errp)
+{
+ BlockBackend *blk = child->opaque;
+
+ /* Only manually created BlockBackends that are not attached to anything
+ * can change their AioContext without updating their user. */
+ if (!blk->name || blk->dev) {
+ /* TODO Add BB name/QOM path */
+ error_setg(errp, "Cannot change iothread of active block backend");
+ return false;
+ }
+
+ return true;
+}
+
+static void blk_root_set_aio_ctx(BdrvChild *child, AioContext *ctx,
+ GSList **ignore)
+{
+ BlockBackend *blk = child->opaque;
+ blk_do_set_aio_context(blk, ctx, false);
+}
+
void blk_add_aio_context_notifier(BlockBackend *blk,
void (*attached_aio_context)(AioContext *new_context, void *opaque),
void (*detach_aio_context)(void *opaque), void *opaque)
--
2.20.1
- [Qemu-block] [PULL 00/24] Block layer patches, Kevin Wolf, 2019/05/20
- [Qemu-block] [PULL 06/24] nvme: fix copy direction in DMA reads going to CMB, Kevin Wolf, 2019/05/20
- [Qemu-block] [PULL 04/24] qmp: forbid qmp_cont in RUN_STATE_FINISH_MIGRATE, Kevin Wolf, 2019/05/20
- [Qemu-block] [PULL 03/24] block: Use BDRV_REQUEST_MAX_BYTES instead of BDRV_REQUEST_MAX_SECTORS, Kevin Wolf, 2019/05/20
- [Qemu-block] [PULL 01/24] block/file-posix: Truncate in xfs_write_zeroes(), Kevin Wolf, 2019/05/20
- [Qemu-block] [PULL 02/24] qcow2: Define and use QCOW2_COMPRESSED_SECTOR_SIZE, Kevin Wolf, 2019/05/20
- [Qemu-block] [PULL 09/24] block: Move recursion to bdrv_set_aio_context(), Kevin Wolf, 2019/05/20
- [Qemu-block] [PULL 12/24] block: Implement .(can_)set_aio_ctx for BlockBackend,
Kevin Wolf <=
- [Qemu-block] [PULL 07/24] block: Add bdrv_try_set_aio_context(), Kevin Wolf, 2019/05/20
- [Qemu-block] [PULL 05/24] iotest: fix 169: do not run qmp_cont in RUN_STATE_FINISH_MIGRATE, Kevin Wolf, 2019/05/20
- [Qemu-block] [PULL 10/24] block: Propagate AioContext change to parents, Kevin Wolf, 2019/05/20
- [Qemu-block] [PULL 11/24] test-block-iothread: Test AioContext propagation through the tree, Kevin Wolf, 2019/05/20
- [Qemu-block] [PULL 16/24] test-block-iothread: Test AioContext propagation for block jobs, Kevin Wolf, 2019/05/20
- [Qemu-block] [PULL 13/24] block: Add blk_set_allow_aio_context_change(), Kevin Wolf, 2019/05/20
- [Qemu-block] [PULL 08/24] block: Make bdrv_attach/detach_aio_context() static, Kevin Wolf, 2019/05/20
- [Qemu-block] [PULL 15/24] blockjob: Remove AioContext notifiers, Kevin Wolf, 2019/05/20
- [Qemu-block] [PULL 14/24] blockjob: Propagate AioContext change to all job nodes, Kevin Wolf, 2019/05/20
- [Qemu-block] [PULL 17/24] block/file-posix: Unaligned O_DIRECT block-status, Kevin Wolf, 2019/05/20