qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Hanna Reitz <hreitz@redhat.com>
To: Emanuele Giuseppe Esposito <eesposit@redhat.com>, qemu-block@nongnu.org
Cc: "Kevin Wolf" <kwolf@redhat.com>, "Fam Zheng" <fam@euphon.net>,
	"Vladimir Sementsov-Ogievskiy" <vsementsov@virtuozzo.com>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Juan Quintela" <quintela@redhat.com>,
	qemu-devel@nongnu.org, "John Snow" <jsnow@redhat.com>,
	"Daniel Henrique Barboza" <danielhb413@gmail.com>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	"Eduardo Habkost" <eduardo@habkost.net>,
	"Greg Kurz" <groug@kaod.org>,
	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>,
	"Eric Blake" <eblake@redhat.com>,
	"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
	"David Gibson" <david@gibson.dropbear.id.au>
Subject: Re: [PATCH v6 30/33] include/block/block_int-common.h: introduce bdrv_amend_pre_run and bdrv_amend_clean
Date: Wed, 26 Jan 2022 15:54:53 +0100	[thread overview]
Message-ID: <3271c5a7-937b-cf3c-be5a-544c6e32e501@redhat.com> (raw)
In-Reply-To: <20220121170544.2049944-31-eesposit@redhat.com>

On 21.01.22 18:05, Emanuele Giuseppe Esposito wrote:
> These two callbacks will be invoked by job callbacks to execute
> driver-specific code while still being in BQL.
> In this example, we want the amend JobDriver to execute the
> permission check (bdrv_child_refresh_perms) currently only
> done in block/crypto.c block_crypto_amend_options_generic_luks()
> to all its bdrv.
> This is achieved by introducing callbacks in the JobDriver, but
> we also need to make sure that crypto->updating_keys is true
> before refreshing the permissions the first time, so that
> WRITE perm is temporarly given to qcrypto_block_amend_options(),
> and set it to false when permissions are restored.
>
> Therefore bdrv_amend_pre_run() and bdrv_amend_clean() will take care of
> just temporarly setting the crypto-specific updating_keys flag.
>
> Note that at this stage, they are not yet invoked.
>
> Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
> ---
>   block/crypto.c                   | 16 ++++++++++++++++
>   include/block/block_int-common.h | 13 +++++++++++++
>   2 files changed, 29 insertions(+)
>
> diff --git a/block/crypto.c b/block/crypto.c
> index c8ba4681e2..f5e0c7b7c0 100644
> --- a/block/crypto.c
> +++ b/block/crypto.c
> @@ -777,6 +777,20 @@ block_crypto_get_specific_info_luks(BlockDriverState *bs, Error **errp)
>       return spec_info;
>   }
>   
> +static void
> +block_crypto_amend_pre_run(BlockDriverState *bs)
> +{
> +    BlockCrypto *crypto = bs->opaque;
> +    crypto->updating_keys = true;
> +}

So I see you decided to leave actually updating the permissions to the 
caller, i.e. blockdev_amend_pre_run().  Why?

I’m asking because:

(1) If the .bdrv_amend_pre_run() isn’t implemented, I don’t think 
refreshing the permissions in blockdev_amend_pre_run() is necessary.  So 
if it is implemented, the implementation might as well do it itself.

(2) The way you implemented it, it’s actually kind of hard to see why 
this is even necessary.  Both of these functions 
(block_crypto_amend_{pre_run,cleanup}()) don’t require the BQL, so the 
explanation for .bdrv_amend_pre_run() (“useful to perform 
driver-specific initialization code under BQL”) doesn’t really apply.  
If you want to explain (and we should) why this is necessary, then the 
.bdrv_amend_pre_run() documentation needs to state that we will refresh 
the permissions after this function has run and before .bdrv_co_amend() 
will run, and so it’s also useful to put code here that will change the 
permissions on permission update, but that just really gets complicated 
to explain.  Naively, I find it simpler to just say “Put BQL code here, 
this will run before .bdrv_co_amend()” and have every implementation 
that needs it refresh the permissions itself.

(3) In patch 32, you add 
block_crypto_amend_options_{prepare,cleanup}().  If the functions added 
here (block_crypto_amend_{pre_run,cleanup}()) would refresh the 
permissions by themselves, they’d be exactly the same functions, so you 
could reuse the ones from here in patch 32.

> +
> +static void
> +block_crypto_amend_cleanup(BlockDriverState *bs)
> +{
> +    BlockCrypto *crypto = bs->opaque;
> +    crypto->updating_keys = false;
> +}
> +
>   static int
>   block_crypto_amend_options_generic_luks(BlockDriverState *bs,
>                                           QCryptoBlockAmendOptions *amend_options,
> @@ -931,6 +945,8 @@ static BlockDriver bdrv_crypto_luks = {
>       .bdrv_get_specific_info = block_crypto_get_specific_info_luks,
>       .bdrv_amend_options = block_crypto_amend_options_luks,
>       .bdrv_co_amend      = block_crypto_co_amend_luks,
> +    .bdrv_amend_pre_run       = block_crypto_amend_pre_run,
> +    .bdrv_amend_clean         = block_crypto_amend_cleanup,
>   
>       .is_format          = true,
>   
> diff --git a/include/block/block_int-common.h b/include/block/block_int-common.h
> index cc8c8835ba..9d28396978 100644
> --- a/include/block/block_int-common.h
> +++ b/include/block/block_int-common.h
> @@ -189,6 +189,19 @@ struct BlockDriver {
>        * the GS API.
>        */
>   
> +    /*
> +     * Called inside job->pre_run() callback, it is useful
> +     * to perform driver-specific initialization code under
> +     * BQL, like setting up specific permission flags.

I wouldn’t necessarily state that this function is called by 
`job->pre_run()`, but rather paint the picture of how it’s used together 
with `.bdrv_co_amend()`, e.g. something like:

“This function is invoked under the BQL before .bdrv_co_amend() (which 
in contrast does not necessarily run under the BQL) to allow 
driver-specific initialization code that requires the BQL, like setting 
up specific permission flags.”

(Though this comment should be much more specific if we keep updating 
the permissions in the caller, because then the comment also needs to 
explain that we do that.)

> +     */
> +    void (*bdrv_amend_pre_run)(BlockDriverState *bs);
> +    /*
> +     * Called inside job->clean() callback, it undoes
> +     * the driver-specific initialization code done in amend_pre_run.
> +     * Also this function is under BQL.

Here too I’d omit the job reference and just say that (e.g.)

“This function is invoked under the BQL after .bdrv_co_amend() to allow 
cleaning up what was done in .bdrv_amend_pre_run().”

Hanna

> +     */
> +    void (*bdrv_amend_clean)(BlockDriverState *bs);
> +
>       /*
>        * Return true if @to_replace can be replaced by a BDS with the
>        * same data as @bs without it affecting @bs's behavior (that is,



  reply	other threads:[~2022-01-26 15:02 UTC|newest]

Thread overview: 85+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-21 17:05 [PATCH v6 00/33] block layer: split block APIs in global state and I/O Emanuele Giuseppe Esposito
2022-01-21 17:05 ` [PATCH v6 01/33] main-loop.h: introduce qemu_in_main_thread() Emanuele Giuseppe Esposito
2022-01-27 10:56   ` Kevin Wolf
2022-01-31 11:25     ` Emanuele Giuseppe Esposito
2022-01-31 14:33       ` Kevin Wolf
2022-01-31 15:49         ` Paolo Bonzini
2022-02-01  9:08           ` Emanuele Giuseppe Esposito
2022-02-01 10:41             ` Paolo Bonzini
2022-02-01 11:55           ` Kevin Wolf
2022-02-01 12:10             ` Kevin Wolf
2022-01-21 17:05 ` [PATCH v6 02/33] include/block/block: split header into I/O and global state API Emanuele Giuseppe Esposito
2022-01-27 11:01   ` Kevin Wolf
2022-01-31 13:40     ` Emanuele Giuseppe Esposito
2022-01-31 14:54       ` Kevin Wolf
2022-01-31 15:58         ` Paolo Bonzini
2022-02-01  9:45           ` Emanuele Giuseppe Esposito
2022-02-01 10:30             ` Paolo Bonzini
2022-02-07 16:53               ` Kevin Wolf
2022-02-08 10:50                 ` Emanuele Giuseppe Esposito
2022-01-21 17:05 ` [PATCH v6 03/33] assertions for block " Emanuele Giuseppe Esposito
2022-01-21 17:05 ` [PATCH v6 04/33] block/export/fuse.c: allow writable exports to take RESIZE permission Emanuele Giuseppe Esposito
2022-01-25 16:51   ` Hanna Reitz
2022-01-28 14:44     ` Emanuele Giuseppe Esposito
2022-01-21 17:05 ` [PATCH v6 05/33] include/sysemu/block-backend: split header into I/O and global state (GS) API Emanuele Giuseppe Esposito
2022-02-07 17:04   ` Kevin Wolf
2022-01-21 17:05 ` [PATCH v6 06/33] block/block-backend.c: assertions for block-backend Emanuele Giuseppe Esposito
2022-01-26  9:02   ` Hanna Reitz
2022-01-21 17:05 ` [PATCH v6 07/33] include/block/block_int: split header into I/O and global state API Emanuele Giuseppe Esposito
2022-01-21 17:05 ` [PATCH v6 08/33] assertions for block_int " Emanuele Giuseppe Esposito
2022-01-21 17:05 ` [PATCH v6 09/33] block: introduce assert_bdrv_graph_writable Emanuele Giuseppe Esposito
2022-02-07 17:14   ` Kevin Wolf
2022-01-21 17:05 ` [PATCH v6 10/33] include/block/blockjob_int.h: split header into I/O and GS API Emanuele Giuseppe Esposito
2022-01-21 17:05 ` [PATCH v6 11/33] assertions for blockjob_int.h Emanuele Giuseppe Esposito
2022-01-21 17:05 ` [PATCH v6 12/33] block.c: add assertions to static functions Emanuele Giuseppe Esposito
2022-01-21 17:05 ` [PATCH v6 13/33] include/block/blockjob.h: global state API Emanuele Giuseppe Esposito
2022-02-07 17:26   ` Kevin Wolf
2022-02-08 10:50     ` Emanuele Giuseppe Esposito
2022-01-21 17:05 ` [PATCH v6 14/33] assertions for blockjob.h " Emanuele Giuseppe Esposito
2022-01-21 17:05 ` [PATCH v6 15/33] include/sysemu/blockdev.h: " Emanuele Giuseppe Esposito
2022-01-21 17:05 ` [PATCH v6 16/33] assertions for blockdev.h " Emanuele Giuseppe Esposito
2022-01-21 17:05 ` [PATCH v6 17/33] include/block/snapshot: global state API + assertions Emanuele Giuseppe Esposito
2022-01-21 17:05 ` [PATCH v6 18/33] block/copy-before-write.h: " Emanuele Giuseppe Esposito
2022-01-21 17:05 ` [PATCH v6 19/33] block: introduce bdrv_activate Emanuele Giuseppe Esposito
2022-01-26 11:49   ` Hanna Reitz
2022-01-21 17:05 ` [PATCH v6 20/33] block: rename bdrv_invalidate_cache_all, blk_invalidate_cache and test_sync_op_invalidate_cache Emanuele Giuseppe Esposito
2022-01-24 10:44   ` Juan Quintela
2022-01-27  9:18     ` Emanuele Giuseppe Esposito
2022-01-31 15:59       ` Paolo Bonzini
2022-01-26 11:57   ` Hanna Reitz
2022-01-21 17:05 ` [PATCH v6 21/33] block: move BQL logic of bdrv_co_invalidate_cache in bdrv_activate Emanuele Giuseppe Esposito
2022-01-26 12:20   ` Hanna Reitz
2022-01-27 11:03   ` Kevin Wolf
2022-02-02 17:27     ` Paolo Bonzini
2022-02-02 18:27       ` Kevin Wolf
2022-01-21 17:05 ` [PATCH v6 22/33] block/coroutines: I/O API Emanuele Giuseppe Esposito
2022-02-07 17:36   ` Kevin Wolf
2022-01-21 17:05 ` [PATCH v6 23/33] block_int-common.h: split function pointers in BlockDriver Emanuele Giuseppe Esposito
2022-01-26 12:29   ` Hanna Reitz
2022-01-21 17:05 ` [PATCH v6 24/33] block_int-common.h: assertions in the callers of BlockDriver function pointers Emanuele Giuseppe Esposito
2022-01-21 17:05 ` [PATCH v6 25/33] block_int-common.h: split function pointers in BdrvChildClass Emanuele Giuseppe Esposito
2022-01-26 12:42   ` Hanna Reitz
2022-01-28 15:08     ` Emanuele Giuseppe Esposito
2022-01-21 17:05 ` [PATCH v6 26/33] block_int-common.h: assertions in the callers of BdrvChildClass function pointers Emanuele Giuseppe Esposito
2022-01-26 12:46   ` Hanna Reitz
2022-01-21 17:05 ` [PATCH v6 27/33] block-backend-common.h: split function pointers in BlockDevOps Emanuele Giuseppe Esposito
2022-01-21 17:05 ` [PATCH v6 28/33] job.h: split function pointers in JobDriver Emanuele Giuseppe Esposito
2022-01-21 17:05 ` [PATCH v6 29/33] job.h: assertions in the callers of JobDriver funcion pointers Emanuele Giuseppe Esposito
2022-01-26 14:13   ` Hanna Reitz
2022-01-28 15:19     ` Emanuele Giuseppe Esposito
2022-01-31  8:49       ` Hanna Reitz
2022-01-21 17:05 ` [PATCH v6 30/33] include/block/block_int-common.h: introduce bdrv_amend_pre_run and bdrv_amend_clean Emanuele Giuseppe Esposito
2022-01-26 14:54   ` Hanna Reitz [this message]
2022-01-21 17:05 ` [PATCH v6 31/33] include/qemu/job.h: introduce job->pre_run() and use it in amend Emanuele Giuseppe Esposito
2022-01-26 15:57   ` Hanna Reitz
2022-02-07 18:14   ` Kevin Wolf
2022-02-08 11:05     ` Emanuele Giuseppe Esposito
2022-01-21 17:05 ` [PATCH v6 32/33] crypto: delegate permission functions to JobDriver .pre_run Emanuele Giuseppe Esposito
2022-01-24 14:41   ` Paolo Bonzini
2022-01-26 16:10   ` Hanna Reitz
2022-01-28 16:57     ` Emanuele Giuseppe Esposito
2022-01-21 17:05 ` [PATCH v6 33/33] block.c: assertions to the block layer permissions API Emanuele Giuseppe Esposito
2022-02-07 18:30 ` [PATCH v6 00/33] block layer: split block APIs in global state and I/O Kevin Wolf
2022-02-08 11:42   ` Emanuele Giuseppe Esposito
2022-02-08 13:08     ` Kevin Wolf
2022-02-10 16:19       ` 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=3271c5a7-937b-cf3c-be5a-544c6e32e501@redhat.com \
    --to=hreitz@redhat.com \
    --cc=armbru@redhat.com \
    --cc=berrange@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=eblake@redhat.com \
    --cc=eduardo@habkost.net \
    --cc=eesposit@redhat.com \
    --cc=f4bug@amsat.org \
    --cc=fam@euphon.net \
    --cc=groug@kaod.org \
    --cc=jsnow@redhat.com \
    --cc=kwolf@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=richard.henderson@linaro.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).