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>,
	Maxim Levitsky <mlevitsk@redhat.com>,
	qemu-devel@nongnu.org, Max Reitz <mreitz@redhat.com>
Subject: [PATCH 17/19] block/crypto: implement blockdev-amend
Date: Thu, 25 Jun 2020 14:55:46 +0200	[thread overview]
Message-ID: <20200625125548.870061-18-mreitz@redhat.com> (raw)
In-Reply-To: <20200625125548.870061-1-mreitz@redhat.com>

From: Maxim Levitsky <mlevitsk@redhat.com>

Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Message-Id: <20200608094030.670121-13-mlevitsk@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 qapi/block-core.json | 14 ++++++++-
 block/crypto.c       | 72 ++++++++++++++++++++++++++++++++------------
 2 files changed, 66 insertions(+), 20 deletions(-)

diff --git a/qapi/block-core.json b/qapi/block-core.json
index c22996282f..cd679ad435 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -4674,6 +4674,18 @@
   'data': { 'job-id': 'str',
             'options': 'BlockdevCreateOptions' } }
 
+##
+# @BlockdevAmendOptionsLUKS:
+#
+# Driver specific image amend options for LUKS.
+#
+# Since: 5.1
+##
+{ 'struct': 'BlockdevAmendOptionsLUKS',
+  'base': 'QCryptoBlockAmendOptionsLUKS',
+  'data': { }
+}
+
 ##
 # @BlockdevAmendOptions:
 #
@@ -4688,7 +4700,7 @@
       'driver':         'BlockdevDriver' },
   'discriminator': 'driver',
   'data': {
-  } }
+      'luks':           'BlockdevAmendOptionsLUKS' } }
 
 ##
 # @x-blockdev-amend:
diff --git a/block/crypto.c b/block/crypto.c
index b9c40e6922..3fbd68832b 100644
--- a/block/crypto.c
+++ b/block/crypto.c
@@ -791,32 +791,21 @@ block_crypto_get_specific_info_luks(BlockDriverState *bs, Error **errp)
 }
 
 static int
-block_crypto_amend_options_luks(BlockDriverState *bs,
-                                QemuOpts *opts,
-                                BlockDriverAmendStatusCB *status_cb,
-                                void *cb_opaque,
-                                bool force,
-                                Error **errp)
+block_crypto_amend_options_generic_luks(BlockDriverState *bs,
+                                        QCryptoBlockAmendOptions *amend_options,
+                                        bool force,
+                                        Error **errp)
 {
     BlockCrypto *crypto = bs->opaque;
-    QDict *cryptoopts = NULL;
-    QCryptoBlockAmendOptions *amend_options = NULL;
     int ret;
 
     assert(crypto);
     assert(crypto->block);
-    crypto->updating_keys = true;
 
+    /* apply for exclusive read/write permissions to the underlying file*/
+    crypto->updating_keys = true;
     ret = bdrv_child_refresh_perms(bs, bs->file, errp);
-    if (ret < 0) {
-        goto cleanup;
-    }
-
-    cryptoopts = qemu_opts_to_qdict(opts, NULL);
-    qdict_put_str(cryptoopts, "format", "luks");
-    amend_options = block_crypto_amend_opts_init(cryptoopts, errp);
-    if (!amend_options) {
-        ret = -EINVAL;
+    if (ret) {
         goto cleanup;
     }
 
@@ -828,13 +817,57 @@ block_crypto_amend_options_luks(BlockDriverState *bs,
                                       force,
                                       errp);
 cleanup:
+    /* release exclusive read/write permissions to the underlying file*/
     crypto->updating_keys = false;
     bdrv_child_refresh_perms(bs, bs->file, errp);
-    qapi_free_QCryptoBlockAmendOptions(amend_options);
+    return ret;
+}
+
+static int
+block_crypto_amend_options_luks(BlockDriverState *bs,
+                                QemuOpts *opts,
+                                BlockDriverAmendStatusCB *status_cb,
+                                void *cb_opaque,
+                                bool force,
+                                Error **errp)
+{
+    BlockCrypto *crypto = bs->opaque;
+    QDict *cryptoopts = NULL;
+    QCryptoBlockAmendOptions *amend_options = NULL;
+    int ret = -EINVAL;
+
+    assert(crypto);
+    assert(crypto->block);
+
+    cryptoopts = qemu_opts_to_qdict(opts, NULL);
+    qdict_put_str(cryptoopts, "format", "luks");
+    amend_options = block_crypto_amend_opts_init(cryptoopts, errp);
     qobject_unref(cryptoopts);
+    if (!amend_options) {
+        goto cleanup;
+    }
+    ret = block_crypto_amend_options_generic_luks(bs, amend_options,
+                                                  force, errp);
+cleanup:
+    qapi_free_QCryptoBlockAmendOptions(amend_options);
     return ret;
 }
 
+static int
+coroutine_fn block_crypto_co_amend_luks(BlockDriverState *bs,
+                                        BlockdevAmendOptions *opts,
+                                        bool force,
+                                        Error **errp)
+{
+    QCryptoBlockAmendOptions amend_opts;
+
+    amend_opts = (QCryptoBlockAmendOptions) {
+        .format = Q_CRYPTO_BLOCK_FORMAT_LUKS,
+        .u.luks = *qapi_BlockdevAmendOptionsLUKS_base(&opts->u.luks),
+    };
+    return block_crypto_amend_options_generic_luks(bs, &amend_opts,
+                                                   force, errp);
+}
 
 static void
 block_crypto_child_perms(BlockDriverState *bs, BdrvChild *c,
@@ -910,6 +943,7 @@ static BlockDriver bdrv_crypto_luks = {
     .bdrv_get_info      = block_crypto_get_info_luks,
     .bdrv_get_specific_info = block_crypto_get_specific_info_luks,
     .bdrv_amend_options = block_crypto_amend_options_luks,
+    .bdrv_co_amend      = block_crypto_co_amend_luks,
 
     .is_format          = true,
 
-- 
2.26.2



  parent reply	other threads:[~2020-06-25 13:06 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-25 12:55 [PATCH 00/19] block: LUKS encryption slot management + iotest tweaks Max Reitz
2020-06-25 12:55 ` [PATCH 01/19] iotests: Make _filter_img_create more active Max Reitz
2020-06-28 15:12   ` Maxim Levitsky
2020-06-25 12:55 ` [PATCH 02/19] iotests: filter few more luks specific create options Max Reitz
2020-06-25 12:55 ` [PATCH 03/19] iotests/common.rc: Add _require_working_luks Max Reitz
2020-06-28 19:02   ` Maxim Levitsky
2020-06-25 12:55 ` [PATCH 04/19] iotests.py: Add qemu_img_pipe_and_status() Max Reitz
2020-06-29  8:45   ` Maxim Levitsky
2020-06-25 12:55 ` [PATCH 05/19] iotests.py: Add (verify|has)_working_luks() Max Reitz
2020-06-29 10:12   ` Maxim Levitsky
2020-06-30  8:52     ` Max Reitz
2020-06-25 12:55 ` [PATCH 06/19] iotests: Check whether luks works Max Reitz
2020-06-29 12:03   ` Maxim Levitsky
2020-06-30  8:53     ` Max Reitz
2020-06-25 12:55 ` [PATCH 07/19] qcrypto/core: add generic infrastructure for crypto options amendment Max Reitz
2020-06-25 12:55 ` [PATCH 08/19] qcrypto/luks: implement encryption key management Max Reitz
2020-06-25 12:55 ` [PATCH 09/19] block/amend: add 'force' option Max Reitz
2020-06-25 12:55 ` [PATCH 10/19] block/amend: separate amend and create options for qemu-img Max Reitz
2020-06-25 12:55 ` [PATCH 11/19] block/amend: refactor qcow2 amend options Max Reitz
2020-06-25 12:55 ` [PATCH 12/19] block/crypto: rename two functions Max Reitz
2020-06-25 12:55 ` [PATCH 13/19] block/crypto: implement the encryption key management Max Reitz
2020-06-25 12:55 ` [PATCH 14/19] block/qcow2: extend qemu-img amend interface with crypto options Max Reitz
2020-06-25 12:55 ` [PATCH 15/19] iotests: qemu-img tests for luks key management Max Reitz
2020-06-29 12:05   ` Maxim Levitsky
2020-06-30  8:56     ` Max Reitz
2020-06-30  9:23       ` Maxim Levitsky
2020-06-25 12:55 ` [PATCH 16/19] block/core: add generic infrastructure for x-blockdev-amend qmp command Max Reitz
2020-06-25 12:55 ` Max Reitz [this message]
2020-06-25 12:55 ` [PATCH 18/19] block/qcow2: implement blockdev-amend Max Reitz
2020-06-25 12:55 ` [PATCH 19/19] iotests: add tests for blockdev-amend Max Reitz
2020-06-29 12:06   ` Maxim Levitsky
2020-06-25 13:22 ` [PATCH 00/19] block: LUKS encryption slot management + iotest tweaks no-reply
2020-07-03 11:57 ` Max Reitz

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=20200625125548.870061-18-mreitz@redhat.com \
    --to=mreitz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mlevitsk@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).