[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 23/41] luks: Create block_crypto_co_create_generic()
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 23/41] luks: Create block_crypto_co_create_generic() |
Date: |
Tue, 13 Mar 2018 17:17:45 +0100 |
Everything that refers to the protocol layer or QemuOpts is moved out of
block_crypto_create_generic(), so that the remaining function is
suitable to be called by a .bdrv_co_create implementation.
LUKS is the only driver that actually implements the old interface, and
we don't intend to use it in any new drivers, so put the moved out code
directly into a LUKS function rather than creating a generic
intermediate one.
Signed-off-by: Kevin Wolf <address@hidden>
Reviewed-by: Daniel P. Berrangé <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
---
block/crypto.c | 95 +++++++++++++++++++++++++++++++++++++---------------------
1 file changed, 61 insertions(+), 34 deletions(-)
diff --git a/block/crypto.c b/block/crypto.c
index 77871640cc..b0a4cb3388 100644
--- a/block/crypto.c
+++ b/block/crypto.c
@@ -306,43 +306,29 @@ static int block_crypto_open_generic(QCryptoBlockFormat
format,
}
-static int block_crypto_create_generic(QCryptoBlockFormat format,
- const char *filename,
- QemuOpts *opts,
- Error **errp)
+static int block_crypto_co_create_generic(BlockDriverState *bs,
+ int64_t size,
+ QCryptoBlockCreateOptions *opts,
+ Error **errp)
{
- int ret = -EINVAL;
- QCryptoBlockCreateOptions *create_opts = NULL;
+ int ret;
+ BlockBackend *blk;
QCryptoBlock *crypto = NULL;
- struct BlockCryptoCreateData data = {
- .size = ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0),
- BDRV_SECTOR_SIZE),
- };
- QDict *cryptoopts;
-
- /* Parse options */
- cryptoopts = qemu_opts_to_qdict(opts, NULL);
+ struct BlockCryptoCreateData data;
- create_opts = block_crypto_create_opts_init(format, cryptoopts, errp);
- if (!create_opts) {
- return -1;
- }
+ blk = blk_new(BLK_PERM_WRITE | BLK_PERM_RESIZE, BLK_PERM_ALL);
- /* Create protocol layer */
- ret = bdrv_create_file(filename, opts, errp);
+ ret = blk_insert_bs(blk, bs, errp);
if (ret < 0) {
- return ret;
+ goto cleanup;
}
- data.blk = blk_new_open(filename, NULL, NULL,
- BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_PROTOCOL,
- errp);
- if (!data.blk) {
- return -EINVAL;
- }
+ data = (struct BlockCryptoCreateData) {
+ .blk = blk,
+ .size = size,
+ };
- /* Create format layer */
- crypto = qcrypto_block_create(create_opts, NULL,
+ crypto = qcrypto_block_create(opts, NULL,
block_crypto_init_func,
block_crypto_write_func,
&data,
@@ -355,10 +341,8 @@ static int block_crypto_create_generic(QCryptoBlockFormat
format,
ret = 0;
cleanup:
- QDECREF(cryptoopts);
qcrypto_block_free(crypto);
- blk_unref(data.blk);
- qapi_free_QCryptoBlockCreateOptions(create_opts);
+ blk_unref(blk);
return ret;
}
@@ -563,8 +547,51 @@ static int coroutine_fn
block_crypto_co_create_opts_luks(const char *filename,
QemuOpts *opts,
Error **errp)
{
- return block_crypto_create_generic(Q_CRYPTO_BLOCK_FORMAT_LUKS,
- filename, opts, errp);
+ QCryptoBlockCreateOptions *create_opts = NULL;
+ BlockDriverState *bs = NULL;
+ QDict *cryptoopts;
+ int64_t size;
+ int ret;
+
+ /* Parse options */
+ size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0);
+
+ cryptoopts = qemu_opts_to_qdict_filtered(opts, NULL,
+ &block_crypto_create_opts_luks,
+ true);
+
+ create_opts = block_crypto_create_opts_init(Q_CRYPTO_BLOCK_FORMAT_LUKS,
+ cryptoopts, errp);
+ if (!create_opts) {
+ ret = -EINVAL;
+ goto fail;
+ }
+
+ /* Create protocol layer */
+ ret = bdrv_create_file(filename, opts, errp);
+ if (ret < 0) {
+ return ret;
+ }
+
+ bs = bdrv_open(filename, NULL, NULL,
+ BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_PROTOCOL, errp);
+ if (!bs) {
+ ret = -EINVAL;
+ goto fail;
+ }
+
+ /* Create format layer */
+ ret = block_crypto_co_create_generic(bs, size, create_opts, errp);
+ if (ret < 0) {
+ goto fail;
+ }
+
+ ret = 0;
+fail:
+ bdrv_unref(bs);
+ qapi_free_QCryptoBlockCreateOptions(create_opts);
+ QDECREF(cryptoopts);
+ return ret;
}
static int block_crypto_get_info_luks(BlockDriverState *bs,
--
2.13.6
- [Qemu-devel] [PULL 07/41] blockjobs: add block_job_verb permission table, (continued)
- [Qemu-devel] [PULL 07/41] blockjobs: add block_job_verb permission table, Kevin Wolf, 2018/03/13
- [Qemu-devel] [PULL 08/41] blockjobs: add ABORTING state, Kevin Wolf, 2018/03/13
- [Qemu-devel] [PULL 15/41] blockjobs: add prepare callback, Kevin Wolf, 2018/03/13
- [Qemu-devel] [PULL 12/41] blockjobs: ensure abort is called for cancelled jobs, Kevin Wolf, 2018/03/13
- [Qemu-devel] [PULL 16/41] blockjobs: add waiting status, Kevin Wolf, 2018/03/13
- [Qemu-devel] [PULL 18/41] blockjobs: add block-job-finalize, Kevin Wolf, 2018/03/13
- [Qemu-devel] [PULL 04/41] blockjobs: add status enum, Kevin Wolf, 2018/03/13
- [Qemu-devel] [PULL 10/41] blockjobs: add NULL state, Kevin Wolf, 2018/03/13
- [Qemu-devel] [PULL 11/41] blockjobs: add block_job_dismiss, Kevin Wolf, 2018/03/13
- [Qemu-devel] [PULL 06/41] iotests: add pause_wait, Kevin Wolf, 2018/03/13
- [Qemu-devel] [PULL 23/41] luks: Create block_crypto_co_create_generic(),
Kevin Wolf <=
- [Qemu-devel] [PULL 17/41] blockjobs: add PENDING status and event, Kevin Wolf, 2018/03/13
- [Qemu-devel] [PULL 25/41] luks: Turn invalid assertion into check, Kevin Wolf, 2018/03/13
- [Qemu-devel] [PULL 20/41] iotests: test manual job dismissal, Kevin Wolf, 2018/03/13
- [Qemu-devel] [PULL 05/41] blockjobs: add state transition table, Kevin Wolf, 2018/03/13
- [Qemu-devel] [PULL 09/41] blockjobs: add CONCLUDED state, Kevin Wolf, 2018/03/13
- [Qemu-devel] [PULL 14/41] blockjobs: add block_job_txn_apply function, Kevin Wolf, 2018/03/13
- [Qemu-devel] [PULL 32/41] iotests: Add regression test for commit base locking, Kevin Wolf, 2018/03/13
- [Qemu-devel] [PULL 21/41] tests/test-blockjob: test cancellations, Kevin Wolf, 2018/03/13
- [Qemu-devel] [PULL 19/41] blockjobs: Expose manual property, Kevin Wolf, 2018/03/13
- [Qemu-devel] [PULL 24/41] luks: Support .bdrv_co_create, Kevin Wolf, 2018/03/13