[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/5] crypto: distinguish between main loop and I/O in block_crypt
From: |
Emanuele Giuseppe Esposito |
Subject: |
[PATCH 2/5] crypto: distinguish between main loop and I/O in block_crypto_amend_options_generic_luks |
Date: |
Wed, 9 Feb 2022 05:54:49 -0500 |
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>
---
block/crypto.c | 35 +++++++++++++++--------------------
1 file changed, 15 insertions(+), 20 deletions(-)
diff --git a/block/crypto.c b/block/crypto.c
index 59f768ea8d..c546b96dbd 100644
--- a/block/crypto.c
+++ b/block/crypto.c
@@ -809,30 +809,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
@@ -858,8 +845,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.31.1
- [PATCH 0/5] block layer: permission API refactoring in preparation, Emanuele Giuseppe Esposito, 2022/02/09
- [PATCH 2/5] crypto: distinguish between main loop and I/O in block_crypto_amend_options_generic_luks,
Emanuele Giuseppe Esposito <=
- [PATCH 5/5] block: move BQL logic of bdrv_co_invalidate_cache in bdrv_activate, Emanuele Giuseppe Esposito, 2022/02/09
- [PATCH 3/5] block: introduce bdrv_activate, Emanuele Giuseppe Esposito, 2022/02/09
- [PATCH 1/5] crypto: perform permission checks under BQL, Emanuele Giuseppe Esposito, 2022/02/09
- [PATCH 4/5] block: rename bdrv_invalidate_cache_all, blk_invalidate_cache and test_sync_op_invalidate_cache, Emanuele Giuseppe Esposito, 2022/02/09