qemu-devel.nongnu.org archive mirror
 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 v8 13/14] block/qcow2: implement blockdev-amend
Date: Mon,  8 Jun 2020 12:40:29 +0300	[thread overview]
Message-ID: <20200608094030.670121-14-mlevitsk@redhat.com> (raw)
In-Reply-To: <20200608094030.670121-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>
Reviewed-by: Max Reitz <mreitz@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 0e72e8fc39..0d2d05d1f7 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -5585,6 +5585,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.
@@ -5802,6 +5840,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 cd679ad435..b20332e592 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -4686,6 +4686,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:
 #
@@ -4700,7 +4713,8 @@
       'driver':         'BlockdevDriver' },
   'discriminator': 'driver',
   'data': {
-      'luks':           'BlockdevAmendOptionsLUKS' } }
+      'luks':           'BlockdevAmendOptionsLUKS',
+      'qcow2':          'BlockdevAmendOptionsQcow2' } }
 
 ##
 # @x-blockdev-amend:
-- 
2.25.4



  parent reply	other threads:[~2020-06-08  9:50 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-08  9:40 [PATCH v8 00/14] LUKS: encryption slot management using amend interface Maxim Levitsky
2020-06-08  9:40 ` [PATCH v8 01/14] qcrypto/core: add generic infrastructure for crypto options amendment Maxim Levitsky
2020-06-08  9:40 ` [PATCH v8 02/14] qcrypto/luks: implement encryption key management Maxim Levitsky
2020-06-08  9:40 ` [PATCH v8 03/14] block/amend: add 'force' option Maxim Levitsky
2020-06-08  9:40 ` [PATCH v8 04/14] block/amend: separate amend and create options for qemu-img Maxim Levitsky
2020-06-08  9:40 ` [PATCH v8 05/14] block/amend: refactor qcow2 amend options Maxim Levitsky
2020-06-16 13:23   ` Max Reitz
2020-06-08  9:40 ` [PATCH v8 06/14] block/crypto: rename two functions Maxim Levitsky
2020-06-08  9:40 ` [PATCH v8 07/14] block/crypto: implement the encryption key management Maxim Levitsky
2020-06-08 12:14   ` Max Reitz
2020-06-16 13:57     ` Maxim Levitsky
2020-06-08  9:40 ` [PATCH v8 08/14] block/qcow2: extend qemu-img amend interface with crypto options Maxim Levitsky
2020-06-08  9:40 ` [PATCH v8 09/14] iotests: filter few more luks specific create options Maxim Levitsky
2020-06-08  9:40 ` [PATCH v8 10/14] iotests: qemu-img tests for luks key management Maxim Levitsky
2020-06-08  9:40 ` [PATCH v8 11/14] block/core: add generic infrastructure for x-blockdev-amend qmp command Maxim Levitsky
2020-07-08 12:33   ` Gerd Hoffmann
2020-07-08 13:06     ` Maxim Levitsky
2020-07-08 13:47       ` Gerd Hoffmann
2020-07-08 14:23       ` Gerd Hoffmann
2020-07-08 16:11         ` Maxim Levitsky
2020-06-08  9:40 ` [PATCH v8 12/14] block/crypto: implement blockdev-amend Maxim Levitsky
2020-06-08  9:40 ` Maxim Levitsky [this message]
2020-06-08  9:40 ` [PATCH v8 14/14] iotests: add tests for blockdev-amend Maxim Levitsky
2020-06-08 11:54 ` [PATCH v8 00/14] LUKS: encryption slot management using amend interface no-reply
2020-06-08 12:15 ` 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=20200608094030.670121-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 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).