From: Emanuele Giuseppe Esposito <eesposit@redhat.com>
To: qemu-block@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>, John Snow <jsnow@redhat.com>,
Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
Markus Armbruster <armbru@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
qemu-devel@nongnu.org,
Emanuele Giuseppe Esposito <eesposit@redhat.com>
Subject: [PATCH v3 04/10] blockjob: implement .change_aio_ctx in child_job
Date: Tue, 25 Oct 2022 04:49:46 -0400 [thread overview]
Message-ID: <20221025084952.2139888-5-eesposit@redhat.com> (raw)
In-Reply-To: <20221025084952.2139888-1-eesposit@redhat.com>
child_job_change_aio_ctx() is very similar to
child_job_can_set_aio_ctx(), but it implements a new transaction
so that if all check pass, the new transaction's .commit()
will take care of changin the BlockJob AioContext.
child_job_set_aio_ctx_commit() is similar to child_job_set_aio_ctx(),
but it doesn't need to invoke the recursion, as this is already
taken care by child_job_change_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: Hanna Reitz <hreitz@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
---
blockjob.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/blockjob.c b/blockjob.c
index bdf20a0e35..5a783b75c6 100644
--- a/blockjob.c
+++ b/blockjob.c
@@ -126,6 +126,50 @@ static void child_job_drained_end(BdrvChild *c, int *drained_end_counter)
job_resume(&job->job);
}
+typedef struct BdrvStateChildJobContext {
+ AioContext *new_ctx;
+ BlockJob *job;
+} BdrvStateChildJobContext;
+
+static void child_job_set_aio_ctx_commit(void *opaque)
+{
+ BdrvStateChildJobContext *s = opaque;
+ BlockJob *job = s->job;
+
+ job_set_aio_context(&job->job, s->new_ctx);
+}
+
+static TransactionActionDrv change_child_job_context = {
+ .commit = child_job_set_aio_ctx_commit,
+ .clean = g_free,
+};
+
+static bool child_job_change_aio_ctx(BdrvChild *c, AioContext *ctx,
+ GHashTable *visited, Transaction *tran,
+ Error **errp)
+{
+ BlockJob *job = c->opaque;
+ BdrvStateChildJobContext *s;
+ GSList *l;
+
+ for (l = job->nodes; l; l = l->next) {
+ BdrvChild *sibling = l->data;
+ if (!bdrv_child_change_aio_context(sibling, ctx, visited,
+ tran, errp)) {
+ return false;
+ }
+ }
+
+ s = g_new(BdrvStateChildJobContext, 1);
+ *s = (BdrvStateChildJobContext) {
+ .new_ctx = ctx,
+ .job = job,
+ };
+
+ tran_add(tran, &change_child_job_context, s);
+ return true;
+}
+
static bool child_job_can_set_aio_ctx(BdrvChild *c, AioContext *ctx,
GSList **ignore, Error **errp)
{
@@ -174,6 +218,7 @@ static const BdrvChildClass child_job = {
.drained_end = child_job_drained_end,
.can_set_aio_ctx = child_job_can_set_aio_ctx,
.set_aio_ctx = child_job_set_aio_ctx,
+ .change_aio_ctx = child_job_change_aio_ctx,
.stay_at_node = true,
.get_parent_aio_context = child_job_get_parent_aio_context,
};
--
2.31.1
next prev parent reply other threads:[~2022-10-25 9:13 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-25 8:49 [PATCH v3 00/10] Refactor bdrv_try_set_aio_context using transactions Emanuele Giuseppe Esposito
2022-10-25 8:49 ` [PATCH v3 01/10] block.c: assert bs->aio_context is written under BQL and drains Emanuele Giuseppe Esposito
2022-10-25 8:49 ` [PATCH v3 02/10] block: use transactions as a replacement of ->{can_}set_aio_context() Emanuele Giuseppe Esposito
2022-10-25 8:49 ` [PATCH v3 03/10] bdrv_change_aio_context: use hash table instead of list of visited nodes Emanuele Giuseppe Esposito
2022-10-25 8:49 ` Emanuele Giuseppe Esposito [this message]
2022-10-25 8:49 ` [PATCH v3 05/10] block: implement .change_aio_ctx in child_of_bds Emanuele Giuseppe Esposito
2022-10-25 8:49 ` [PATCH v3 06/10] block-backend: implement .change_aio_ctx in child_root Emanuele Giuseppe Esposito
2022-10-25 8:49 ` [PATCH v3 07/10] block: use the new _change_ API instead of _can_set_ and _set_ Emanuele Giuseppe Esposito
2022-10-25 8:49 ` [PATCH v3 08/10] block: remove all unused ->can_set_aio_ctx and ->set_aio_ctx callbacks Emanuele Giuseppe Esposito
2022-10-25 8:49 ` [PATCH v3 09/10] block: rename bdrv_child_try_change_aio_context in bdrv_try_change_aio_context Emanuele Giuseppe Esposito
2022-10-25 8:49 ` [PATCH v3 10/10] block: remove bdrv_try_set_aio_context and replace it with bdrv_try_change_aio_context Emanuele Giuseppe Esposito
2022-10-25 10:18 ` [PATCH v3 00/10] Refactor bdrv_try_set_aio_context using transactions Kevin Wolf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221025084952.2139888-5-eesposit@redhat.com \
--to=eesposit@redhat.com \
--cc=armbru@redhat.com \
--cc=hreitz@redhat.com \
--cc=jsnow@redhat.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=vsementsov@virtuozzo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).