[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v5 30/31] crypto: delegate permission functions to JobDriver .pre
From: |
Emanuele Giuseppe Esposito |
Subject: |
[PATCH v5 30/31] crypto: delegate permission functions to JobDriver .pre_run |
Date: |
Wed, 24 Nov 2021 01:44:17 -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 ib 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 1) change block_crypto_amend_options_generic_luks
to use the permission API only when the BQL is held, and
2) use the .pre_run JobDriver callback to check for
permissions before switching to the job aiocontext. This has also
the benefit of applying the same permission operation to all
amend implementations, not only luks.
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
block/amend.c | 20 ++++++++++++++++++++
block/crypto.c | 18 ++++++++++++------
2 files changed, 32 insertions(+), 6 deletions(-)
diff --git a/block/amend.c b/block/amend.c
index 392df9ef83..fba6add51a 100644
--- a/block/amend.c
+++ b/block/amend.c
@@ -53,10 +53,30 @@ static int coroutine_fn blockdev_amend_run(Job *job, Error
**errp)
return ret;
}
+static int blockdev_amend_refresh_perms(Job *job, Error **errp)
+{
+ BlockdevAmendJob *s = container_of(job, BlockdevAmendJob, common);
+
+ return bdrv_child_refresh_perms(s->bs, s->bs->file, errp);
+}
+
+static int blockdev_amend_pre_run(Job *job, Error **errp)
+{
+ return blockdev_amend_refresh_perms(job, errp);
+}
+
+static void blockdev_amend_clean(Job *job)
+{
+ Error *errp;
+ blockdev_amend_refresh_perms(job, &errp);
+}
+
static const JobDriver blockdev_amend_job_driver = {
.instance_size = sizeof(BlockdevAmendJob),
.job_type = JOB_TYPE_AMEND,
.run = blockdev_amend_run,
+ .pre_run = blockdev_amend_pre_run,
+ .clean = blockdev_amend_clean,
};
void qmp_x_blockdev_amend(const char *job_id,
diff --git a/block/crypto.c b/block/crypto.c
index c8ba4681e2..82f154516c 100644
--- a/block/crypto.c
+++ b/block/crypto.c
@@ -780,6 +780,7 @@ block_crypto_get_specific_info_luks(BlockDriverState *bs,
Error **errp)
static int
block_crypto_amend_options_generic_luks(BlockDriverState *bs,
QCryptoBlockAmendOptions
*amend_options,
+ bool under_bql,
bool force,
Error **errp)
{
@@ -791,9 +792,12 @@ block_crypto_amend_options_generic_luks(BlockDriverState
*bs,
/* 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;
+
+ if (under_bql) {
+ ret = bdrv_child_refresh_perms(bs, bs->file, errp);
+ if (ret) {
+ goto cleanup;
+ }
}
ret = qcrypto_block_amend_options(crypto->block,
@@ -806,7 +810,9 @@ block_crypto_amend_options_generic_luks(BlockDriverState
*bs,
cleanup:
/* release exclusive read/write permissions to the underlying file*/
crypto->updating_keys = false;
- bdrv_child_refresh_perms(bs, bs->file, errp);
+ if (under_bql) {
+ bdrv_child_refresh_perms(bs, bs->file, errp);
+ }
return ret;
}
@@ -834,7 +840,7 @@ block_crypto_amend_options_luks(BlockDriverState *bs,
goto cleanup;
}
ret = block_crypto_amend_options_generic_luks(bs, amend_options,
- force, errp);
+ true, force, errp);
cleanup:
qapi_free_QCryptoBlockAmendOptions(amend_options);
return ret;
@@ -853,7 +859,7 @@ coroutine_fn block_crypto_co_amend_luks(BlockDriverState
*bs,
.u.luks = *qapi_BlockdevAmendOptionsLUKS_base(&opts->u.luks),
};
return block_crypto_amend_options_generic_luks(bs, &amend_opts,
- force, errp);
+ false, force, errp);
}
static void
--
2.27.0
- [PATCH v5 18/31] include/block/snapshot: global state API + assertions, (continued)
- [PATCH v5 18/31] include/block/snapshot: global state API + assertions, Emanuele Giuseppe Esposito, 2021/11/24
- [PATCH v5 22/31] block_int-common.h: assertion in the callers of BlockDriver function pointers, Emanuele Giuseppe Esposito, 2021/11/24
- [PATCH v5 24/31] block_int-common.h: assertions in the callers of BdrvChildClass function pointers, Emanuele Giuseppe Esposito, 2021/11/24
- [PATCH v5 23/31] block_int-common.h: split function pointers in BdrvChildClass, Emanuele Giuseppe Esposito, 2021/11/24
- [PATCH v5 20/31] block/coroutines: I/O API, Emanuele Giuseppe Esposito, 2021/11/24
- [PATCH v5 26/31] job.h: split function pointers in JobDriver, Emanuele Giuseppe Esposito, 2021/11/24
- [PATCH v5 21/31] block_int-common.h: split function pointers in BlockDriver, Emanuele Giuseppe Esposito, 2021/11/24
- [PATCH v5 25/31] block-backend-common.h: split function pointers in BlockDevOps, Emanuele Giuseppe Esposito, 2021/11/24
- [PATCH v5 27/31] job.h: assertions in the callers of JobDriver funcion pointers, Emanuele Giuseppe Esposito, 2021/11/24
- [PATCH v5 28/31] block.c: assert BQL lock held in bdrv_co_invalidate_cache, Emanuele Giuseppe Esposito, 2021/11/24
- [PATCH v5 30/31] crypto: delegate permission functions to JobDriver .pre_run,
Emanuele Giuseppe Esposito <=
- [PATCH v5 31/31] block.c: assertions to the block layer permissions API, Emanuele Giuseppe Esposito, 2021/11/24
- [PATCH v5 29/31] jobs: introduce pre_run function in JobDriver, Emanuele Giuseppe Esposito, 2021/11/24
- Re: [PATCH v5 00/31] block layer: split block APIs in global state and I/O, Stefan Hajnoczi, 2021/11/29