From: Hanna Reitz <hreitz@redhat.com>
To: Emanuele Giuseppe Esposito <eesposit@redhat.com>, qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, John Snow <jsnow@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Vladimir Sementsov-Ogievskiy <v.sementsov-og@mail.ru>,
qemu-block@nongnu.org
Subject: Re: [RFC PATCH 7/8] block: use the new _change_ API instead of _can_set_ and _set_
Date: Fri, 15 Jul 2022 15:32:53 +0200 [thread overview]
Message-ID: <b4146d6b-3879-f6f9-d573-5c5289afb593@redhat.com> (raw)
In-Reply-To: <20220712211911.1302836-8-eesposit@redhat.com>
On 12.07.22 23:19, Emanuele Giuseppe Esposito wrote:
> 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);
As far as I understand, the transaction is supposed to always succeed;
that’s why we pass `&error_abort`, I thought.
If so, `ret` should always be true. More importantly, though, I think
the `ret ? ret : -1` is wrong because it’ll always evaluate to either 1
or -1, but never to 0, which would indicate success. I think it should
be `ret == true ? 0 : -1`, or even better `assert(ret == true);
tran_finalize(tran, 0);`.
> }
>
> 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) {
To be honest, due to the mix of return value styles we have, perhaps a
`ret_child == true` would help to signal that this is a success path.
> 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);
This too should probably be `ret_child == true ? 0 : -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);
Why not remove this function and adjust all callers?
Hanna
> }
>
> void bdrv_add_aio_context_notifier(BlockDriverState *bs,
next prev parent reply other threads:[~2022-07-15 13:34 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-12 21:19 [RFC PATCH 0/8] Refactor bdrv_try_set_aio_context using transactions Emanuele Giuseppe Esposito
2022-07-12 21:19 ` [RFC PATCH 1/8] block.c: assert bs->aio_context is written under BQL and drains Emanuele Giuseppe Esposito
2022-07-14 14:03 ` Hanna Reitz
2022-07-12 21:19 ` [RFC PATCH 2/8] transactions: add tran_add_back Emanuele Giuseppe Esposito
2022-07-14 15:13 ` Hanna Reitz
2022-07-18 16:20 ` Paolo Bonzini
2022-07-20 13:36 ` Vladimir Sementsov-Ogievskiy
2022-07-12 21:19 ` [RFC PATCH 3/8] RFC: block: use transactions as a replacement of ->{can_}set_aio_context() Emanuele Giuseppe Esposito
2022-07-14 16:45 ` Hanna Reitz
2022-07-18 8:45 ` Emanuele Giuseppe Esposito
2022-07-18 9:09 ` Emanuele Giuseppe Esposito
2022-07-20 14:09 ` Vladimir Sementsov-Ogievskiy
2022-07-25 8:35 ` Emanuele Giuseppe Esposito
2022-07-12 21:19 ` [RFC PATCH 4/8] blockjob: implement .change_aio_ctx in child_job Emanuele Giuseppe Esposito
2022-07-15 11:14 ` Hanna Reitz
2022-07-12 21:19 ` [RFC PATCH 5/8] block: implement .change_aio_ctx in child_of_bds Emanuele Giuseppe Esposito
2022-07-15 11:17 ` Hanna Reitz
2022-07-12 21:19 ` [RFC PATCH 6/8] block-backend: implement .change_aio_ctx in child_root Emanuele Giuseppe Esposito
2022-07-15 11:34 ` Hanna Reitz
2022-07-12 21:19 ` [RFC PATCH 7/8] block: use the new _change_ API instead of _can_set_ and _set_ Emanuele Giuseppe Esposito
2022-07-15 13:32 ` Hanna Reitz [this message]
2022-07-18 16:30 ` Paolo Bonzini
2022-07-18 16:39 ` Paolo Bonzini
2022-07-19 9:57 ` Emanuele Giuseppe Esposito
2022-07-19 18:07 ` Paolo Bonzini
2022-07-20 11:47 ` Emanuele Giuseppe Esposito
2022-07-12 21:19 ` [RFC PATCH 8/8] block: remove all unused ->can_set_aio_ctx and ->set_aio_ctx callbacks Emanuele Giuseppe Esposito
2022-07-15 14:34 ` Hanna Reitz
2022-07-18 8:45 ` Emanuele Giuseppe Esposito
2022-07-18 14:39 ` Emanuele Giuseppe Esposito
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=b4146d6b-3879-f6f9-d573-5c5289afb593@redhat.com \
--to=hreitz@redhat.com \
--cc=eesposit@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=v.sementsov-og@mail.ru \
/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).