All of lore.kernel.org
 help / color / mirror / Atom feed
From: Maxim Levitsky <mlevitsk@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Kevin Wolf" <kwolf@redhat.com>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	qemu-block@nongnu.org, "John Snow" <jsnow@redhat.com>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Max Reitz" <mreitz@redhat.com>,
	"Maxim Levitsky" <mlevitsk@redhat.com>
Subject: [PATCH v6 13/14] block/qcow2: implement blockdev-amend
Date: Sun, 10 May 2020 16:40:36 +0300	[thread overview]
Message-ID: <20200510134037.18487-14-mlevitsk@redhat.com> (raw)
In-Reply-To: <20200510134037.18487-1-mlevitsk@redhat.com>

Currently the implementation only supports amending the encryption
options, unlike the qemu-img version

Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
---
 block/qcow2.c        | 39 +++++++++++++++++++++++++++++++++++++++
 qapi/block-core.json | 16 +++++++++++++++-
 2 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/block/qcow2.c b/block/qcow2.c
index 4bb6e3fc8f..90fe43918f 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -5473,6 +5473,44 @@ static int qcow2_amend_options(BlockDriverState *bs, QemuOpts *opts,
     return 0;
 }
 
+static int coroutine_fn qcow2_co_amend(BlockDriverState *bs,
+                                       BlockdevAmendOptions *opts,
+                                       bool force,
+                                       Error **errp)
+{
+    BlockdevAmendOptionsQcow2 *qopts = &opts->u.qcow2;
+    BDRVQcow2State *s = bs->opaque;
+    int ret = 0;
+
+    if (qopts->has_encrypt) {
+        if (!s->crypto) {
+            error_setg(errp, "image is not encrypted, can't amend");
+            return -EOPNOTSUPP;
+        }
+
+        if (qopts->encrypt->format != Q_CRYPTO_BLOCK_FORMAT_LUKS) {
+            error_setg(errp,
+                       "Amend can't be used to change the qcow2 encryption format");
+            return -EOPNOTSUPP;
+        }
+
+        if (s->crypt_method_header != QCOW_CRYPT_LUKS) {
+            error_setg(errp,
+                       "Only LUKS encryption options can be amended for qcow2 with blockdev-amend");
+            return -EOPNOTSUPP;
+        }
+
+        ret = qcrypto_block_amend_options(s->crypto,
+                                          qcow2_crypto_hdr_read_func,
+                                          qcow2_crypto_hdr_write_func,
+                                          bs,
+                                          qopts->encrypt,
+                                          force,
+                                          errp);
+    }
+    return ret;
+}
+
 /*
  * If offset or size are negative, respectively, they will not be included in
  * the BLOCK_IMAGE_CORRUPTED event emitted.
@@ -5682,6 +5720,7 @@ BlockDriver bdrv_qcow2 = {
     .mutable_opts        = mutable_opts,
     .bdrv_co_check       = qcow2_co_check,
     .bdrv_amend_options  = qcow2_amend_options,
+    .bdrv_co_amend       = qcow2_co_amend,
 
     .bdrv_detach_aio_context  = qcow2_detach_aio_context,
     .bdrv_attach_aio_context  = qcow2_attach_aio_context,
diff --git a/qapi/block-core.json b/qapi/block-core.json
index df710fa597..0faff6c675 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -4661,6 +4661,19 @@
   'data': { }
 }
 
+##
+# @BlockdevAmendOptionsQcow2:
+#
+# Driver specific image amend options for qcow2.
+# For now, only encryption options can be amended
+#
+# @encrypt          Encryption options to be amended
+#
+# Since: 5.1
+##
+{ 'struct': 'BlockdevAmendOptionsQcow2',
+  'data': { '*encrypt':         'QCryptoBlockAmendOptions' } }
+
 ##
 # @BlockdevAmendOptions:
 #
@@ -4675,7 +4688,8 @@
       'driver':         'BlockdevDriver' },
   'discriminator': 'driver',
   'data': {
-      'luks':           'BlockdevAmendOptionsLUKS' } }
+      'luks':           'BlockdevAmendOptionsLUKS',
+      'qcow2':          'BlockdevAmendOptionsQcow2' } }
 
 ##
 # @x-blockdev-amend:
-- 
2.17.2



  parent reply	other threads:[~2020-05-10 13:43 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-10 13:40 [PATCH v6 00/14] LUKS: encryption slot management using amend interface Maxim Levitsky
2020-05-10 13:40 ` [PATCH v6 01/14] qcrypto/core: add generic infrastructure for crypto options amendment Maxim Levitsky
2020-05-10 13:40 ` [PATCH v6 02/14] qcrypto/luks: implement encryption key management Maxim Levitsky
2020-05-14 11:56   ` Max Reitz
2020-05-17  8:13     ` Maxim Levitsky
2020-05-10 13:40 ` [PATCH v6 03/14] block/amend: add 'force' option Maxim Levitsky
2020-05-14 12:18   ` Max Reitz
2020-05-17  8:15     ` Maxim Levitsky
2020-05-10 13:40 ` [PATCH v6 04/14] block/amend: separate amend and create options for qemu-img Maxim Levitsky
2020-05-14 12:28   ` Max Reitz
2020-05-14 16:10     ` Eric Blake
2020-05-15  6:22       ` Max Reitz
2020-05-15 17:24         ` Eric Blake
2020-05-17  8:47           ` Maxim Levitsky
2020-05-17  8:54     ` Maxim Levitsky
2020-05-10 13:40 ` [PATCH v6 05/14] block/amend: refactor qcow2 amend options Maxim Levitsky
2020-05-14 13:36   ` Max Reitz
2020-05-17 17:52     ` Maxim Levitsky
2020-05-10 13:40 ` [PATCH v6 06/14] block/crypto: rename two functions Maxim Levitsky
2020-05-10 13:40 ` [PATCH v6 07/14] block/crypto: implement the encryption key management Maxim Levitsky
2020-05-14 14:09   ` Max Reitz
2020-05-14 14:14     ` Daniel P. Berrangé
2020-05-14 14:32       ` Max Reitz
2020-05-17 17:56         ` Maxim Levitsky
2020-05-10 13:40 ` [PATCH v6 08/14] block/qcow2: extend qemu-img amend interface with crypto options Maxim Levitsky
2020-05-14 14:30   ` Max Reitz
2020-05-17 18:03     ` Maxim Levitsky
2020-05-10 13:40 ` [PATCH v6 09/14] iotests: filter few more luks specific create options Maxim Levitsky
2020-05-14 14:49   ` Max Reitz
2020-05-17 18:50     ` Maxim Levitsky
2020-05-10 13:40 ` [PATCH v6 10/14] iotests: qemu-img tests for luks key management Maxim Levitsky
2020-05-10 13:40 ` [PATCH v6 11/14] block/core: add generic infrastructure for x-blockdev-amend qmp command Maxim Levitsky
2020-05-14 15:47   ` Max Reitz
2020-05-18 10:48     ` Maxim Levitsky
2020-05-10 13:40 ` [PATCH v6 12/14] block/crypto: implement blockdev-amend Maxim Levitsky
2020-05-14 16:05   ` Max Reitz
2020-05-10 13:40 ` Maxim Levitsky [this message]
2020-05-14 16:05   ` [PATCH v6 13/14] block/qcow2: " Max Reitz
2020-05-10 13:40 ` [PATCH v6 14/14] iotests: add tests for blockdev-amend Maxim Levitsky
2020-05-10 14:37 ` [PATCH v6 00/14] LUKS: encryption slot management using amend interface no-reply
2020-05-10 15:14 ` 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=20200510134037.18487-14-mlevitsk@redhat.com \
    --to=mlevitsk@redhat.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=jsnow@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.