[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 7/8] block: use the new _change_ API instead of _can_set_ and
From: |
Emanuele Giuseppe Esposito |
Subject: |
[RFC PATCH 7/8] block: use the new _change_ API instead of _can_set_ and _set_ |
Date: |
Tue, 12 Jul 2022 17:19:10 -0400 |
Replace all direct usage of ->can_set_aio_ctx and ->set_aio_ctx,
and call bdrv_child_try_change_aio_context() in
bdrv_try_set_aio_context(), the main function called through
the whole block layer.
>From this point onwards, ->can_set_aio_ctx and ->set_aio_ctx
won't be used anymore.
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
block.c | 30 ++++++++++++++++--------------
block/block-backend.c | 8 ++++++--
2 files changed, 22 insertions(+), 16 deletions(-)
diff --git a/block.c b/block.c
index a7ba590dfa..101188a2d4 100644
--- a/block.c
+++ b/block.c
@@ -2966,17 +2966,18 @@ static void bdrv_attach_child_common_abort(void *opaque)
}
if (bdrv_child_get_parent_aio_context(child) != s->old_parent_ctx) {
+ Transaction *tran;
GSList *ignore;
+ bool ret;
- /* No need to ignore `child`, because it has been detached already */
- ignore = NULL;
- child->klass->can_set_aio_ctx(child, s->old_parent_ctx, &ignore,
- &error_abort);
- g_slist_free(ignore);
+ tran = tran_new();
+ /* No need to ignore `child`, because it has been detached already */
ignore = NULL;
- child->klass->set_aio_ctx(child, s->old_parent_ctx, &ignore);
+ ret = child->klass->change_aio_ctx(child, s->old_parent_ctx, &ignore,
+ tran, &error_abort);
g_slist_free(ignore);
+ tran_finalize(tran, ret ? ret : -1);
}
bdrv_unref(bs);
@@ -3037,17 +3038,18 @@ static int bdrv_attach_child_common(BlockDriverState
*child_bs,
Error *local_err = NULL;
int ret = bdrv_try_set_aio_context(child_bs, parent_ctx, &local_err);
- if (ret < 0 && child_class->can_set_aio_ctx) {
+ if (ret < 0 && child_class->change_aio_ctx) {
+ Transaction *tran = tran_new();
GSList *ignore = g_slist_prepend(NULL, new_child);
- if (child_class->can_set_aio_ctx(new_child, child_ctx, &ignore,
- NULL))
- {
+ bool ret_child;
+
+ ret_child = child_class->change_aio_ctx(new_child, child_ctx,
+ &ignore, tran, NULL);
+ if (ret_child) {
error_free(local_err);
ret = 0;
- g_slist_free(ignore);
- ignore = g_slist_prepend(NULL, new_child);
- child_class->set_aio_ctx(new_child, child_ctx, &ignore);
}
+ tran_finalize(tran, ret_child ? ret_child : -1);
g_slist_free(ignore);
}
@@ -7708,7 +7710,7 @@ int bdrv_try_set_aio_context(BlockDriverState *bs,
AioContext *ctx,
Error **errp)
{
GLOBAL_STATE_CODE();
- return bdrv_child_try_set_aio_context(bs, ctx, NULL, errp);
+ return bdrv_child_try_change_aio_context(bs, ctx, NULL, errp);
}
void bdrv_add_aio_context_notifier(BlockDriverState *bs,
diff --git a/block/block-backend.c b/block/block-backend.c
index 674eaaa2bf..6e90ac3a6a 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -2184,8 +2184,12 @@ static int blk_do_set_aio_context(BlockBackend *blk,
AioContext *new_context,
bdrv_ref(bs);
if (update_root_node) {
- ret = bdrv_child_try_set_aio_context(bs, new_context, blk->root,
- errp);
+ /*
+ * update_root_node MUST be false for
blk_root_set_aio_ctx_commit(),
+ * as we are already in the commit function of a transaction.
+ */
+ ret = bdrv_child_try_change_aio_context(bs, new_context, blk->root,
+ errp);
if (ret < 0) {
bdrv_unref(bs);
return ret;
--
2.31.1
[RFC PATCH 8/8] block: remove all unused ->can_set_aio_ctx and ->set_aio_ctx callbacks, Emanuele Giuseppe Esposito, 2022/07/12