From: Kevin Wolf <kwolf@redhat.com>
To: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Cc: "Fam Zheng" <fam@euphon.net>,
"Vladimir Sementsov-Ogievskiy" <vsementsov@virtuozzo.com>,
qemu-block@nongnu.org, "Juan Quintela" <quintela@redhat.com>,
qemu-devel@nongnu.org, "Markus Armbruster" <armbru@redhat.com>,
"Daniel Henrique Barboza" <danielhb413@gmail.com>,
"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
"Greg Kurz" <groug@kaod.org>, "Hanna Reitz" <hreitz@redhat.com>,
qemu-ppc@nongnu.org, "Cédric Le Goater" <clg@kaod.org>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Denis V. Lunev" <den@openvz.org>,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
"David Gibson" <david@gibson.dropbear.id.au>
Subject: Re: [PATCH 1/5] crypto: perform permission checks under BQL
Date: Tue, 1 Mar 2022 10:32:14 +0100 [thread overview]
Message-ID: <Yh3oHumQVSIOjdhk@redhat.com> (raw)
In-Reply-To: <20220209105452.1694545-2-eesposit@redhat.com>
Am 09.02.2022 um 11:54 hat Emanuele Giuseppe Esposito geschrieben:
> Move the permission API calls into driver-specific callbacks
> that always run under BQL. In this case, bdrv_crypto_luks
> needs to perform permission checks before and after
> qcrypto_block_amend_options(). The problem is that the caller,
> block_crypto_amend_options_generic_luks(), can also run in I/O
> from .bdrv_co_amend(). This does not comply with Global State-I/O API split,
> as permissions API must always run under BQL.
>
> Firstly, introduce .bdrv_amend_pre_run() and .bdrv_amend_clean()
> callbacks. These two callbacks are guaranteed to be invoked under
> BQL, respectively before and after .bdrv_co_amend().
> They take care of performing the permission checks
> in the same way as they are currently done before and after
> qcrypto_block_amend_options().
> These callbacks are in preparation for next patch, where we
> delete the original permission check. Right now they just add redundant
> control.
>
> Then, call .bdrv_amend_pre_run() before job_start in
> qmp_x_blockdev_amend(), so that it will be run before the job coroutine
> is created and stay in the main loop.
> As a cleanup, use JobDriver's .clean() callback to call
> .bdrv_amend_clean(), and run amend-specific cleanup callbacks under BQL.
>
> Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
> ---
> block/amend.c | 24 ++++++++++++++++++++++++
> block/crypto.c | 27 +++++++++++++++++++++++++++
> include/block/block_int.h | 14 ++++++++++++++
> 3 files changed, 65 insertions(+)
>
> diff --git a/block/amend.c b/block/amend.c
> index 392df9ef83..329bca53dc 100644
> --- a/block/amend.c
> +++ b/block/amend.c
> @@ -53,10 +53,29 @@ static int coroutine_fn blockdev_amend_run(Job *job, Error **errp)
> return ret;
> }
>
> +static int blockdev_amend_pre_run(BlockdevAmendJob *s, Error **errp)
> +{
> + if (s->bs->drv->bdrv_amend_pre_run) {
> + return s->bs->drv->bdrv_amend_pre_run(s->bs, errp);
> + }
> +
> + return 0;
> +}
> +
> +static void blockdev_amend_clean(Job *job)
> +{
> + BlockdevAmendJob *s = container_of(job, BlockdevAmendJob, common);
> +
> + if (s->bs->drv->bdrv_amend_clean) {
> + s->bs->drv->bdrv_amend_clean(s->bs);
> + }
> +}
> +
> static const JobDriver blockdev_amend_job_driver = {
> .instance_size = sizeof(BlockdevAmendJob),
> .job_type = JOB_TYPE_AMEND,
> .run = blockdev_amend_run,
> + .clean = blockdev_amend_clean,
> };
>
> void qmp_x_blockdev_amend(const char *job_id,
> @@ -113,5 +132,10 @@ void qmp_x_blockdev_amend(const char *job_id,
> s->bs = bs,
> s->opts = QAPI_CLONE(BlockdevAmendOptions, options),
> s->force = has_force ? force : false;
> +
> + if (blockdev_amend_pre_run(s, errp)) {
> + return;
> + }
> +
> job_start(&s->common);
> }
> diff --git a/block/crypto.c b/block/crypto.c
> index c8ba4681e2..59f768ea8d 100644
> --- a/block/crypto.c
> +++ b/block/crypto.c
> @@ -777,6 +777,31 @@ block_crypto_get_specific_info_luks(BlockDriverState *bs, Error **errp)
> return spec_info;
> }
>
> +static int
> +block_crypto_amend_prepare(BlockDriverState *bs, Error **errp)
> +{
> + BlockCrypto *crypto = bs->opaque;
> +
> + /* apply for exclusive read/write permissions to the underlying file*/
Missing space before the end of the comment.
> + crypto->updating_keys = true;
> + return bdrv_child_refresh_perms(bs, bs->file, errp);
> +}
> +
> +static void
> +block_crypto_amend_cleanup(BlockDriverState *bs)
> +{
> + BlockCrypto *crypto = bs->opaque;
> + Error *errp = NULL;
> +
> + /* release exclusive read/write permissions to the underlying file*/
And here.
I can fix this up while applying.
Kevin
next prev parent reply other threads:[~2022-03-01 9:41 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-09 10:54 [PATCH 0/5] block layer: permission API refactoring in preparation Emanuele Giuseppe Esposito
2022-02-09 10:54 ` [PATCH 1/5] crypto: perform permission checks under BQL Emanuele Giuseppe Esposito
2022-03-01 9:32 ` Kevin Wolf [this message]
2022-02-09 10:54 ` [PATCH 2/5] crypto: distinguish between main loop and I/O in block_crypto_amend_options_generic_luks Emanuele Giuseppe Esposito
2022-02-09 10:54 ` [PATCH 3/5] block: introduce bdrv_activate Emanuele Giuseppe Esposito
2022-02-09 10:54 ` [PATCH 4/5] block: rename bdrv_invalidate_cache_all, blk_invalidate_cache and test_sync_op_invalidate_cache Emanuele Giuseppe Esposito
2022-02-09 10:54 ` [PATCH 5/5] block: move BQL logic of bdrv_co_invalidate_cache in bdrv_activate Emanuele Giuseppe Esposito
2022-03-01 10:34 ` [PATCH 0/5] block layer: permission API refactoring in preparation 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=Yh3oHumQVSIOjdhk@redhat.com \
--to=kwolf@redhat.com \
--cc=armbru@redhat.com \
--cc=clg@kaod.org \
--cc=danielhb413@gmail.com \
--cc=david@gibson.dropbear.id.au \
--cc=den@openvz.org \
--cc=dgilbert@redhat.com \
--cc=eesposit@redhat.com \
--cc=f4bug@amsat.org \
--cc=fam@euphon.net \
--cc=groug@kaod.org \
--cc=hreitz@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=quintela@redhat.com \
--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).