From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Kevin Wolf <kwolf@redhat.com>
Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, mreitz@redhat.com
Subject: Re: [Qemu-devel] [PATCH v2 2/6] luks: Create block_crypto_co_create_generic()
Date: Tue, 14 May 2019 12:13:30 +0100 [thread overview]
Message-ID: <20190514111330.GA8548@redhat.com> (raw)
In-Reply-To: <20180312150218.1314-3-kwolf@redhat.com>
On Mon, Mar 12, 2018 at 04:02:14PM +0100, Kevin Wolf wrote:
> 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 <kwolf@redhat.com>
> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
> Reviewed-by: Eric Blake <eblake@redhat.com>
> ---
> block/crypto.c | 95 +++++++++++++++++++++++++++++++++++++---------------------
> 1 file changed, 61 insertions(+), 34 deletions(-)
Reviving a year old commit...
The LUKS driver doesn't implement preallocation during create.
Before this commit this would be reported
$ qemu-img create -f luks --object secret,id=sec0,data=base -o key-secret=sec0 base.luks 1G -o preallocation=full
Formatting 'base.luks', fmt=luks size=1073741824 key-secret=sec0 preallocation=full
qemu-img: base.luks: Parameter 'preallocation' is unexpected
After this commit, there is no error reported - it just silently
ignores the preallocation=full option.
I'm a bit lost in block layer understanding where is the right
place to fix the error reporting in this case.
>
> 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
>
Regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
next prev parent reply other threads:[~2019-05-14 11:14 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-12 15:02 [Qemu-devel] [PATCH v2 0/6] luks: Implement .bdrv_co_create Kevin Wolf
2018-03-12 15:02 ` [Qemu-devel] [PATCH v2 1/6] luks: Separate image file creation from formatting Kevin Wolf
2018-03-12 15:02 ` [Qemu-devel] [PATCH v2 2/6] luks: Create block_crypto_co_create_generic() Kevin Wolf
2019-05-14 11:13 ` Daniel P. Berrangé [this message]
2019-05-14 17:53 ` Kevin Wolf
2018-03-12 15:02 ` [Qemu-devel] [PATCH v2 3/6] luks: Support .bdrv_co_create Kevin Wolf
2018-03-12 16:03 ` Daniel P. Berrangé
2018-03-12 15:02 ` [Qemu-devel] [PATCH v2 4/6] luks: Turn invalid assertion into check Kevin Wolf
2018-03-12 16:03 ` Daniel P. Berrangé
2018-03-12 15:02 ` [Qemu-devel] [PATCH v2 5/6] luks: Catch integer overflow for huge sizes Kevin Wolf
2018-03-12 15:02 ` [Qemu-devel] [PATCH v2 6/6] qemu-iotests: Test luks QMP image creation Kevin Wolf
2018-03-12 16:06 ` Daniel P. Berrangé
2018-03-12 16:34 ` [Qemu-devel] [PATCH v2 0/6] luks: Implement .bdrv_co_create Kevin Wolf
2018-03-12 17:59 ` no-reply
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=20190514111330.GA8548@redhat.com \
--to=berrange@redhat.com \
--cc=kwolf@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.