From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, mreitz@redhat.com, berrange@redhat.com,
eblake@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 1/6] luks: Separate image file creation from formatting
Date: Fri, 9 Mar 2018 18:27:08 +0100 [thread overview]
Message-ID: <20180309172713.26318-2-kwolf@redhat.com> (raw)
In-Reply-To: <20180309172713.26318-1-kwolf@redhat.com>
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 <kwolf@redhat.com>
---
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
next prev parent reply other threads:[~2018-03-09 17:27 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-09 17:27 [Qemu-devel] [PATCH 0/6] luks: Implement .bdrv_co_create Kevin Wolf
2018-03-09 17:27 ` Kevin Wolf [this message]
2018-03-09 19:40 ` [Qemu-devel] [PATCH 1/6] luks: Separate image file creation from formatting Eric Blake
2018-03-12 11:35 ` Daniel P. Berrangé
2018-03-12 11:43 ` Kevin Wolf
2018-03-12 11:46 ` Daniel P. Berrangé
2018-03-09 17:27 ` [Qemu-devel] [PATCH 2/6] luks: Create block_crypto_co_create_generic() Kevin Wolf
2018-03-09 20:06 ` Eric Blake
2018-03-12 11:48 ` Daniel P. Berrangé
2018-03-09 17:27 ` [Qemu-devel] [PATCH 3/6] luks: Support .bdrv_co_create Kevin Wolf
2018-03-09 20:15 ` Eric Blake
2018-03-12 11:40 ` Daniel P. Berrangé
2018-03-12 11:47 ` Kevin Wolf
2018-03-12 11:50 ` Daniel P. Berrangé
2018-03-12 12:14 ` Kevin Wolf
2018-03-12 13:07 ` Eric Blake
2018-03-09 17:27 ` [Qemu-devel] [PATCH 4/6] luks: Turn invalid assertion into check Kevin Wolf
2018-03-09 20:19 ` Eric Blake
2018-03-09 21:55 ` Kevin Wolf
2018-03-12 11:41 ` Daniel P. Berrangé
2018-03-09 17:27 ` [Qemu-devel] [PATCH 5/6] luks: Catch integer overflow for huge sizes Kevin Wolf
2018-03-09 20:21 ` Eric Blake
2018-03-12 11:42 ` Daniel P. Berrangé
2018-03-09 17:27 ` [Qemu-devel] [PATCH 6/6] qemu-iotests: Test luks QMP image creation Kevin Wolf
2018-03-09 20:26 ` Eric Blake
2018-03-12 11:45 ` Daniel P. Berrangé
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180309172713.26318-2-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=berrange@redhat.com \
--cc=eblake@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).