[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 22/41] luks: Separate image file creation from format
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 22/41] luks: Separate image file creation from formatting |
Date: |
Tue, 13 Mar 2018 17:17:44 +0100 |
The crypto driver used to create the image file in a callback from the
crypto subsystem. If we want to implement .bdrv_co_create, this needs to
go away because that callback will get a reference to an already
existing block node.
Move the image file creation to block_crypto_create_generic().
Signed-off-by: Kevin Wolf <address@hidden>
Reviewed-by: Daniel P. Berrangé <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
---
block/crypto.c | 37 +++++++++++++++++--------------------
1 file changed, 17 insertions(+), 20 deletions(-)
diff --git a/block/crypto.c b/block/crypto.c
index e6095e7807..77871640cc 100644
--- a/block/crypto.c
+++ b/block/crypto.c
@@ -71,8 +71,6 @@ static ssize_t block_crypto_read_func(QCryptoBlock *block,
struct BlockCryptoCreateData {
- const char *filename;
- QemuOpts *opts;
BlockBackend *blk;
uint64_t size;
};
@@ -103,27 +101,13 @@ static ssize_t block_crypto_init_func(QCryptoBlock *block,
Error **errp)
{
struct BlockCryptoCreateData *data = opaque;
- int ret;
/* User provided size should reflect amount of space made
* available to the guest, so we must take account of that
* which will be used by the crypto header
*/
- data->size += headerlen;
-
- qemu_opt_set_number(data->opts, BLOCK_OPT_SIZE, data->size, &error_abort);
- ret = bdrv_create_file(data->filename, data->opts, errp);
- if (ret < 0) {
- return -1;
- }
-
- data->blk = blk_new_open(data->filename, NULL, NULL,
- BDRV_O_RDWR | BDRV_O_PROTOCOL, errp);
- if (!data->blk) {
- return -1;
- }
-
- return 0;
+ return blk_truncate(data->blk, data->size + headerlen, PREALLOC_MODE_OFF,
+ errp);
}
@@ -333,11 +317,10 @@ static int block_crypto_create_generic(QCryptoBlockFormat
format,
struct BlockCryptoCreateData data = {
.size = ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0),
BDRV_SECTOR_SIZE),
- .opts = opts,
- .filename = filename,
};
QDict *cryptoopts;
+ /* Parse options */
cryptoopts = qemu_opts_to_qdict(opts, NULL);
create_opts = block_crypto_create_opts_init(format, cryptoopts, errp);
@@ -345,6 +328,20 @@ static int block_crypto_create_generic(QCryptoBlockFormat
format,
return -1;
}
+ /* Create protocol layer */
+ ret = bdrv_create_file(filename, opts, errp);
+ if (ret < 0) {
+ return ret;
+ }
+
+ data.blk = blk_new_open(filename, NULL, NULL,
+ BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_PROTOCOL,
+ errp);
+ if (!data.blk) {
+ return -EINVAL;
+ }
+
+ /* Create format layer */
crypto = qcrypto_block_create(create_opts, NULL,
block_crypto_init_func,
block_crypto_write_func,
--
2.13.6
- Re: [Qemu-block] [Qemu-devel] [PULL 18/41] blockjobs: add block-job-finalize, (continued)
- [Qemu-block] [PULL 13/41] blockjobs: add commit, abort, clean helpers, Kevin Wolf, 2018/03/13
- [Qemu-block] [PULL 09/41] blockjobs: add CONCLUDED state, Kevin Wolf, 2018/03/13
- [Qemu-block] [PULL 17/41] blockjobs: add PENDING status and event, Kevin Wolf, 2018/03/13
- [Qemu-block] [PULL 23/41] luks: Create block_crypto_co_create_generic(), Kevin Wolf, 2018/03/13
- [Qemu-block] [PULL 24/41] luks: Support .bdrv_co_create, Kevin Wolf, 2018/03/13
- [Qemu-block] [PULL 20/41] iotests: test manual job dismissal, Kevin Wolf, 2018/03/13
- [Qemu-block] [PULL 12/41] blockjobs: ensure abort is called for cancelled jobs, Kevin Wolf, 2018/03/13
- [Qemu-block] [PULL 15/41] blockjobs: add prepare callback, Kevin Wolf, 2018/03/13
- [Qemu-block] [PULL 22/41] luks: Separate image file creation from formatting,
Kevin Wolf <=
- [Qemu-block] [PULL 29/41] vdi: Move file creation to vdi_co_create_opts, Kevin Wolf, 2018/03/13
- [Qemu-block] [PULL 27/41] qemu-iotests: Test luks QMP image creation, Kevin Wolf, 2018/03/13
- [Qemu-block] [PULL 26/41] luks: Catch integer overflow for huge sizes, Kevin Wolf, 2018/03/13
- [Qemu-block] [PULL 19/41] blockjobs: Expose manual property, Kevin Wolf, 2018/03/13
- [Qemu-block] [PULL 21/41] tests/test-blockjob: test cancellations, Kevin Wolf, 2018/03/13
- [Qemu-block] [PULL 25/41] luks: Turn invalid assertion into check, Kevin Wolf, 2018/03/13
- [Qemu-block] [PULL 34/41] qemu-iotests: Enable write tests for parallels, Kevin Wolf, 2018/03/13
- [Qemu-block] [PULL 28/41] vdi: Pull option parsing from vdi_co_create, Kevin Wolf, 2018/03/13
- [Qemu-block] [PULL 38/41] vhdx: Support .bdrv_co_create, Kevin Wolf, 2018/03/13
- [Qemu-block] [PULL 30/41] vdi: Implement .bdrv_co_create, Kevin Wolf, 2018/03/13