[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 02/50] crypto: distinguish between main loop and I/O in block_cryp
From: |
Kevin Wolf |
Subject: |
[PULL 02/50] crypto: distinguish between main loop and I/O in block_crypto_amend_options_generic_luks |
Date: |
Fri, 4 Mar 2022 17:46:23 +0100 |
From: Emanuele Giuseppe Esposito <eesposit@redhat.com>
block_crypto_amend_options_generic_luks uses the block layer
permission API, therefore it should be called with the BQL held.
However, the same function is being called by two BlockDriver
callbacks: bdrv_amend_options (under BQL) and bdrv_co_amend (I/O).
The latter is I/O because it is invoked by block/amend.c's
blockdev_amend_run(), a .run callback of the amend JobDriver.
Therefore we want to change this function to still perform
the permission check, but making sure it is done under BQL regardless
of the caller context.
Remove the permission check in block_crypto_amend_options_generic_luks()
and:
- in block_crypto_amend_options_luks() (BQL case, called by
.bdrv_amend_options()), reuse helper functions
block_crypto_amend_{prepare/cleanup} that take care of checking
permissions.
- for block_crypto_co_amend_luks() (I/O case, called by
.bdrv_co_amend()), don't check for permissions but delegate
.bdrv_amend_pre_run() and .bdrv_amend_clean() to do it,
performing these checks before and after the job runs in its aiocontext.
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Message-Id: <20220209105452.1694545-3-eesposit@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block/crypto.c | 35 +++++++++++++++--------------------
1 file changed, 15 insertions(+), 20 deletions(-)
diff --git a/block/crypto.c b/block/crypto.c
index 70b2f07351..9d5fecbef8 100644
--- a/block/crypto.c
+++ b/block/crypto.c
@@ -815,30 +815,17 @@ block_crypto_amend_options_generic_luks(BlockDriverState
*bs,
Error **errp)
{
BlockCrypto *crypto = bs->opaque;
- int ret;
assert(crypto);
assert(crypto->block);
- /* apply for exclusive read/write permissions to the underlying file*/
- crypto->updating_keys = true;
- ret = bdrv_child_refresh_perms(bs, bs->file, errp);
- if (ret) {
- goto cleanup;
- }
-
- ret = qcrypto_block_amend_options(crypto->block,
- block_crypto_read_func,
- block_crypto_write_func,
- bs,
- amend_options,
- force,
- errp);
-cleanup:
- /* release exclusive read/write permissions to the underlying file*/
- crypto->updating_keys = false;
- bdrv_child_refresh_perms(bs, bs->file, errp);
- return ret;
+ return qcrypto_block_amend_options(crypto->block,
+ block_crypto_read_func,
+ block_crypto_write_func,
+ bs,
+ amend_options,
+ force,
+ errp);
}
static int
@@ -864,8 +851,16 @@ block_crypto_amend_options_luks(BlockDriverState *bs,
if (!amend_options) {
goto cleanup;
}
+
+ ret = block_crypto_amend_prepare(bs, errp);
+ if (ret) {
+ goto perm_cleanup;
+ }
ret = block_crypto_amend_options_generic_luks(bs, amend_options,
force, errp);
+
+perm_cleanup:
+ block_crypto_amend_cleanup(bs);
cleanup:
qapi_free_QCryptoBlockAmendOptions(amend_options);
return ret;
--
2.35.1
- [PULL 10/50] os-posix: Add os_set_daemonize(), (continued)
- [PULL 10/50] os-posix: Add os_set_daemonize(), Kevin Wolf, 2022/03/04
- [PULL 12/50] qsd: Add --daemonize, Kevin Wolf, 2022/03/04
- [PULL 11/50] qsd: Add pre-init argument parsing pass, Kevin Wolf, 2022/03/04
- [PULL 07/50] util/async: replace __thread with QEMU TLS macros, Kevin Wolf, 2022/03/04
- [PULL 16/50] include/block/block: split header into I/O and global state API, Kevin Wolf, 2022/03/04
- [PULL 13/50] iotests/185: Add post-READY quit tests, Kevin Wolf, 2022/03/04
- [PULL 14/50] main-loop.h: introduce qemu_in_main_thread(), Kevin Wolf, 2022/03/04
- [PULL 15/50] main loop: macros to mark GS and I/O functions, Kevin Wolf, 2022/03/04
- [PULL 03/50] block: introduce bdrv_activate, Kevin Wolf, 2022/03/04
- [PULL 17/50] assertions for block global state API, Kevin Wolf, 2022/03/04
- [PULL 02/50] crypto: distinguish between main loop and I/O in block_crypto_amend_options_generic_luks,
Kevin Wolf <=
- [PULL 19/50] block/export/fuse.c: allow writable exports to take RESIZE permission, Kevin Wolf, 2022/03/04
- [PULL 27/50] block: introduce assert_bdrv_graph_writable, Kevin Wolf, 2022/03/04
- [PULL 20/50] include/sysemu/block-backend: split header into I/O and global state (GS) API, Kevin Wolf, 2022/03/04
- [PULL 32/50] assertions for blockjob.h global state API, Kevin Wolf, 2022/03/04
- [PULL 18/50] IO_CODE and IO_OR_GS_CODE for block I/O API, Kevin Wolf, 2022/03/04
- [PULL 35/50] include/block/snapshot: global state API + assertions, Kevin Wolf, 2022/03/04
- [PULL 33/50] include/sysemu/blockdev.h: global state API, Kevin Wolf, 2022/03/04
- [PULL 34/50] assertions for blockdev.h global state API, Kevin Wolf, 2022/03/04
- [PULL 21/50] block/block-backend.c: assertions for block-backend, Kevin Wolf, 2022/03/04