qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v6 30/33] include/block/block_int-common.h: introduce bdrv_amend_


From: Emanuele Giuseppe Esposito
Subject: [PATCH v6 30/33] include/block/block_int-common.h: introduce bdrv_amend_pre_run and bdrv_amend_clean
Date: Fri, 21 Jan 2022 12:05:41 -0500

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;
+}
+
+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.
+     */
+    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.
+     */
+    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,
-- 
2.31.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]