[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 28/58] block-backend: implement .change_aio_ctx in child_root
From: |
Kevin Wolf |
Subject: |
[PULL 28/58] block-backend: implement .change_aio_ctx in child_root |
Date: |
Thu, 27 Oct 2022 20:31:16 +0200 |
From: Emanuele Giuseppe Esposito <eesposit@redhat.com>
blk_root_change_aio_ctx() is very similar to blk_root_can_set_aio_ctx(),
but implements a new transaction so that if all check pass, the new
transaction's .commit will take care of changing the BlockBackend
AioContext. blk_root_set_aio_ctx_commit() is the same as
blk_root_set_aio_ctx().
Note: bdrv_child_try_change_aio_context() is not called by
anyone at this point.
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20221025084952.2139888-7-eesposit@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block/block-backend.c | 52 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 52 insertions(+)
diff --git a/block/block-backend.c b/block/block-backend.c
index aa4adf06ae..d87ae435a7 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -138,6 +138,9 @@ 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 bool blk_root_change_aio_ctx(BdrvChild *child, AioContext *ctx,
+ GHashTable *visited, Transaction *tran,
+ Error **errp);
static char *blk_root_get_parent_desc(BdrvChild *child)
{
@@ -336,6 +339,7 @@ static const BdrvChildClass child_root = {
.can_set_aio_ctx = blk_root_can_set_aio_ctx,
.set_aio_ctx = blk_root_set_aio_ctx,
+ .change_aio_ctx = blk_root_change_aio_ctx,
.get_parent_aio_context = blk_root_get_parent_aio_context,
};
@@ -2177,6 +2181,54 @@ int blk_set_aio_context(BlockBackend *blk, AioContext
*new_context,
return blk_do_set_aio_context(blk, new_context, true, errp);
}
+typedef struct BdrvStateBlkRootContext {
+ AioContext *new_ctx;
+ BlockBackend *blk;
+} BdrvStateBlkRootContext;
+
+static void blk_root_set_aio_ctx_commit(void *opaque)
+{
+ BdrvStateBlkRootContext *s = opaque;
+ BlockBackend *blk = s->blk;
+
+ blk_do_set_aio_context(blk, s->new_ctx, false, &error_abort);
+}
+
+static TransactionActionDrv set_blk_root_context = {
+ .commit = blk_root_set_aio_ctx_commit,
+ .clean = g_free,
+};
+
+static bool blk_root_change_aio_ctx(BdrvChild *child, AioContext *ctx,
+ GHashTable *visited, Transaction *tran,
+ Error **errp)
+{
+ BlockBackend *blk = child->opaque;
+ BdrvStateBlkRootContext *s;
+
+ if (!blk->allow_aio_context_change) {
+ /*
+ * Manually created BlockBackends (those with a name) that are not
+ * attached to anything can change their AioContext without updating
+ * their user; return an error for others.
+ */
+ if (!blk->name || blk->dev) {
+ /* TODO Add BB name/QOM path */
+ error_setg(errp, "Cannot change iothread of active block backend");
+ return false;
+ }
+ }
+
+ s = g_new(BdrvStateBlkRootContext, 1);
+ *s = (BdrvStateBlkRootContext) {
+ .new_ctx = ctx,
+ .blk = blk,
+ };
+
+ tran_add(tran, &set_blk_root_context, s);
+ return true;
+}
+
static bool blk_root_can_set_aio_ctx(BdrvChild *child, AioContext *ctx,
GSList **ignore, Error **errp)
{
--
2.37.3
- [PULL 32/58] block: remove bdrv_try_set_aio_context and replace it with bdrv_try_change_aio_context, (continued)
- [PULL 32/58] block: remove bdrv_try_set_aio_context and replace it with bdrv_try_change_aio_context, Kevin Wolf, 2022/10/27
- [PULL 53/58] qed: switch to *_co_* functions, Kevin Wolf, 2022/10/27
- [PULL 44/58] qcow: manually add more coroutine_fn annotations, Kevin Wolf, 2022/10/27
- [PULL 22/58] block: refactor bdrv_remove_file_or_backing_child to bdrv_remove_child, Kevin Wolf, 2022/10/27
- [PULL 23/58] block.c: assert bs->aio_context is written under BQL and drains, Kevin Wolf, 2022/10/27
- [PULL 24/58] block: use transactions as a replacement of ->{can_}set_aio_context(), Kevin Wolf, 2022/10/27
- [PULL 21/58] block/snapshot: drop indirection around bdrv_snapshot_fallback_ptr, Kevin Wolf, 2022/10/27
- [PULL 39/58] coroutine-lock: add missing coroutine_fn annotation to prototypes, Kevin Wolf, 2022/10/27
- [PULL 58/58] block/block-backend: blk_set_enable_write_cache is IO_CODE, Kevin Wolf, 2022/10/27
- [PULL 57/58] monitor: switch to *_co_* functions, Kevin Wolf, 2022/10/27
- [PULL 28/58] block-backend: implement .change_aio_ctx in child_root,
Kevin Wolf <=
- [PULL 34/58] backup: remove incorrect coroutine_fn annotation, Kevin Wolf, 2022/10/27
- [PULL 38/58] block: add missing coroutine_fn annotation to prototypes, Kevin Wolf, 2022/10/27
- [PULL 49/58] mirror: switch to *_co_* functions, Kevin Wolf, 2022/10/27
- [PULL 27/58] block: implement .change_aio_ctx in child_of_bds, Kevin Wolf, 2022/10/27
- [PULL 51/58] qcow: switch to *_co_* functions, Kevin Wolf, 2022/10/27
- [PULL 43/58] blkdebug: add missing coroutine_fn annotation for indirect-called functions, Kevin Wolf, 2022/10/27
- [PULL 50/58] parallels: switch to *_co_* functions, Kevin Wolf, 2022/10/27
- [PULL 52/58] qcow2: switch to *_co_* functions, Kevin Wolf, 2022/10/27
- [PULL 56/58] vmdk: switch to *_co_* functions, Kevin Wolf, 2022/10/27
- [PULL 54/58] vdi: switch to *_co_* functions, Kevin Wolf, 2022/10/27