qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: qemu-block@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	Peter Maydell <peter.maydell@linaro.org>,
	qemu-devel@nongnu.org, Max Reitz <mreitz@redhat.com>
Subject: [PULL 02/19] luks: implement .bdrv_measure()
Date: Wed, 11 Mar 2020 14:51:56 +0100	[thread overview]
Message-ID: <20200311135213.1242028-3-mreitz@redhat.com> (raw)
In-Reply-To: <20200311135213.1242028-1-mreitz@redhat.com>

From: Stefan Hajnoczi <stefanha@redhat.com>

Add qemu-img measure support in the "luks" block driver.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Message-Id: <20200221112522.1497712-3-stefanha@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 block/crypto.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)

diff --git a/block/crypto.c b/block/crypto.c
index 24823835c1..23e9c74d6f 100644
--- a/block/crypto.c
+++ b/block/crypto.c
@@ -484,6 +484,67 @@ static int64_t block_crypto_getlength(BlockDriverState *bs)
 }
 
 
+static BlockMeasureInfo *block_crypto_measure(QemuOpts *opts,
+                                              BlockDriverState *in_bs,
+                                              Error **errp)
+{
+    g_autoptr(QCryptoBlockCreateOptions) create_opts = NULL;
+    Error *local_err = NULL;
+    BlockMeasureInfo *info;
+    uint64_t size;
+    size_t luks_payload_size;
+    QDict *cryptoopts;
+
+    /*
+     * Preallocation mode doesn't affect size requirements but we must consume
+     * the option.
+     */
+    g_free(qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC));
+
+    size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0);
+
+    if (in_bs) {
+        int64_t ssize = bdrv_getlength(in_bs);
+
+        if (ssize < 0) {
+            error_setg_errno(&local_err, -ssize,
+                             "Unable to get image virtual_size");
+            goto err;
+        }
+
+        size = ssize;
+    }
+
+    cryptoopts = qemu_opts_to_qdict_filtered(opts, NULL,
+            &block_crypto_create_opts_luks, true);
+    qdict_put_str(cryptoopts, "format", "luks");
+    create_opts = block_crypto_create_opts_init(cryptoopts, &local_err);
+    qobject_unref(cryptoopts);
+    if (!create_opts) {
+        goto err;
+    }
+
+    if (!qcrypto_block_calculate_payload_offset(create_opts, NULL,
+                                                &luks_payload_size,
+                                                &local_err)) {
+        goto err;
+    }
+
+    /*
+     * Unallocated blocks are still encrypted so allocation status makes no
+     * difference to the file size.
+     */
+    info = g_new(BlockMeasureInfo, 1);
+    info->fully_allocated = luks_payload_size + size;
+    info->required = luks_payload_size + size;
+    return info;
+
+err:
+    error_propagate(errp, local_err);
+    return NULL;
+}
+
+
 static int block_crypto_probe_luks(const uint8_t *buf,
                                    int buf_size,
                                    const char *filename) {
@@ -670,6 +731,7 @@ static BlockDriver bdrv_crypto_luks = {
     .bdrv_co_preadv     = block_crypto_co_preadv,
     .bdrv_co_pwritev    = block_crypto_co_pwritev,
     .bdrv_getlength     = block_crypto_getlength,
+    .bdrv_measure       = block_crypto_measure,
     .bdrv_get_info      = block_crypto_get_info_luks,
     .bdrv_get_specific_info = block_crypto_get_specific_info_luks,
 
-- 
2.24.1



  parent reply	other threads:[~2020-03-11 13:58 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-11 13:51 [PULL 00/19] Block patches Max Reitz
2020-03-11 13:51 ` [PULL 01/19] luks: extract qcrypto_block_calculate_payload_offset() Max Reitz
2020-03-11 13:51 ` Max Reitz [this message]
2020-03-11 13:51 ` [PULL 03/19] qemu-img: allow qemu-img measure --object without a filename Max Reitz
2020-03-11 13:51 ` [PULL 04/19] iotests: add 288 luks qemu-img measure test Max Reitz
2020-03-11 13:51 ` [PULL 05/19] block/curl: HTTP header fields allow whitespace around values Max Reitz
2020-03-11 13:52 ` [PULL 06/19] block/curl: HTTP header field names are case insensitive Max Reitz
2020-03-11 13:52 ` [PULL 07/19] iotests: Fix nonportable use of od --endian Max Reitz
2020-03-11 13:52 ` [PULL 08/19] block/qcow2: do free crypto_opts in qcow2_close() Max Reitz
2020-03-11 13:52 ` [PULL 09/19] qemu-img: free memory before re-assign Max Reitz
2020-03-11 13:52 ` [PULL 10/19] block/qcow2-threads: fix qcow2_decompress Max Reitz
2020-03-11 13:52 ` [PULL 11/19] job: refactor progress to separate object Max Reitz
2020-03-11 13:52 ` [PULL 12/19] block/block-copy: fix progress calculation Max Reitz
2020-03-11 13:52 ` [PULL 13/19] block/block-copy: specialcase first copy_range request Max Reitz
2020-03-11 13:52 ` [PULL 14/19] block/block-copy: use block_status Max Reitz
2020-03-11 13:52 ` [PULL 15/19] block/block-copy: factor out find_conflicting_inflight_req Max Reitz
2020-03-11 13:52 ` [PULL 16/19] block/block-copy: refactor interfaces to use bytes instead of end Max Reitz
2020-03-11 13:52 ` [PULL 17/19] block/block-copy: rename start to offset in interfaces Max Reitz
2020-03-11 13:52 ` [PULL 18/19] block/block-copy: reduce intersecting request lock Max Reitz
2020-03-11 13:52 ` [PULL 19/19] block/block-copy: hide structure definitions Max Reitz
2020-03-12 11:02 ` [PULL 00/19] Block patches Peter Maydell

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=20200311135213.1242028-3-mreitz@redhat.com \
    --to=mreitz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=peter.maydell@linaro.org \
    --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).