|
|
357786 |
From c8b73d0f85b2435aabbdec92452cb7a0446b1d36 Mon Sep 17 00:00:00 2001
|
|
|
357786 |
From: Kevin Wolf <kwolf@redhat.com>
|
|
|
357786 |
Date: Mon, 3 Sep 2018 09:41:40 +0200
|
|
|
357786 |
Subject: [PATCH 27/29] qemu-img: fix regression copying secrets during convert
|
|
|
357786 |
MIME-Version: 1.0
|
|
|
357786 |
Content-Type: text/plain; charset=UTF-8
|
|
|
357786 |
Content-Transfer-Encoding: 8bit
|
|
|
357786 |
|
|
|
357786 |
RH-Author: Kevin Wolf <kwolf@redhat.com>
|
|
|
357786 |
Message-id: <20180903094140.12988-2-kwolf@redhat.com>
|
|
|
357786 |
Patchwork-id: 82031
|
|
|
357786 |
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH 1/1] qemu-img: fix regression copying secrets during convert
|
|
|
357786 |
Bugzilla: 1575578
|
|
|
357786 |
RH-Acked-by: Max Reitz <mreitz@redhat.com>
|
|
|
357786 |
RH-Acked-by: Daniel P. Berrange <berrange@redhat.com>
|
|
|
357786 |
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
357786 |
|
|
|
357786 |
From: Daniel P. Berrangé <berrange@redhat.com>
|
|
|
357786 |
|
|
|
357786 |
When the convert command is creating an output file that needs
|
|
|
357786 |
secrets, we need to ensure those secrets are passed to both the
|
|
|
357786 |
blk_new_open and bdrv_create API calls.
|
|
|
357786 |
|
|
|
357786 |
This is done by qemu-img extracting all opts matching the name
|
|
|
357786 |
suffix "key-secret". Unfortunately the code doing this was run after the
|
|
|
357786 |
call to bdrv_create(), which meant the QemuOpts it was extracting
|
|
|
357786 |
secrets from was now empty.
|
|
|
357786 |
|
|
|
357786 |
Previously this worked by luks as a bug meant the "key-secret"
|
|
|
357786 |
parameters were not purged from the QemuOpts. This bug was fixed in
|
|
|
357786 |
|
|
|
357786 |
commit b76b4f604521e59f857d6177bc55f6f2e41fd392
|
|
|
357786 |
Author: Kevin Wolf <kwolf@redhat.com>
|
|
|
357786 |
Date: Thu Jan 11 16:18:08 2018 +0100
|
|
|
357786 |
|
|
|
357786 |
qcow2: Use visitor for options in qcow2_create()
|
|
|
357786 |
|
|
|
357786 |
Exposing the latent bug in qemu-img. This fix simply moves the copying
|
|
|
357786 |
of secrets to before the bdrv_create() call.
|
|
|
357786 |
|
|
|
357786 |
Cc: qemu-stable@nongnu.org
|
|
|
357786 |
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
|
|
|
357786 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
357786 |
(cherry picked from commit 8d65a3ccfd5db7f0436e095cd952f5d0c3a873ba)
|
|
|
357786 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
357786 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
357786 |
---
|
|
|
357786 |
qemu-img.c | 32 +++++++++++++++-----------------
|
|
|
357786 |
1 file changed, 15 insertions(+), 17 deletions(-)
|
|
|
357786 |
|
|
|
357786 |
diff --git a/qemu-img.c b/qemu-img.c
|
|
|
357786 |
index f42750a..fa0cbd7 100644
|
|
|
357786 |
--- a/qemu-img.c
|
|
|
357786 |
+++ b/qemu-img.c
|
|
|
357786 |
@@ -348,21 +348,6 @@ static int img_add_key_secrets(void *opaque,
|
|
|
357786 |
return 0;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
-static BlockBackend *img_open_new_file(const char *filename,
|
|
|
357786 |
- QemuOpts *create_opts,
|
|
|
357786 |
- const char *fmt, int flags,
|
|
|
357786 |
- bool writethrough, bool quiet,
|
|
|
357786 |
- bool force_share)
|
|
|
357786 |
-{
|
|
|
357786 |
- QDict *options = NULL;
|
|
|
357786 |
-
|
|
|
357786 |
- options = qdict_new();
|
|
|
357786 |
- qemu_opt_foreach(create_opts, img_add_key_secrets, options, &error_abort);
|
|
|
357786 |
-
|
|
|
357786 |
- return img_open_file(filename, options, fmt, flags, writethrough, quiet,
|
|
|
357786 |
- force_share);
|
|
|
357786 |
-}
|
|
|
357786 |
-
|
|
|
357786 |
|
|
|
357786 |
static BlockBackend *img_open(bool image_opts,
|
|
|
357786 |
const char *filename,
|
|
|
357786 |
@@ -1994,6 +1979,7 @@ static int img_convert(int argc, char **argv)
|
|
|
357786 |
BlockDriverState *out_bs;
|
|
|
357786 |
QemuOpts *opts = NULL, *sn_opts = NULL;
|
|
|
357786 |
QemuOptsList *create_opts = NULL;
|
|
|
357786 |
+ QDict *open_opts = NULL;
|
|
|
357786 |
char *options = NULL;
|
|
|
357786 |
Error *local_err = NULL;
|
|
|
357786 |
bool writethrough, src_writethrough, quiet = false, image_opts = false,
|
|
|
357786 |
@@ -2342,6 +2328,16 @@ static int img_convert(int argc, char **argv)
|
|
|
357786 |
}
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
+ /*
|
|
|
357786 |
+ * The later open call will need any decryption secrets, and
|
|
|
357786 |
+ * bdrv_create() will purge "opts", so extract them now before
|
|
|
357786 |
+ * they are lost.
|
|
|
357786 |
+ */
|
|
|
357786 |
+ if (!skip_create) {
|
|
|
357786 |
+ open_opts = qdict_new();
|
|
|
357786 |
+ qemu_opt_foreach(opts, img_add_key_secrets, open_opts, &error_abort);
|
|
|
357786 |
+ }
|
|
|
357786 |
+
|
|
|
357786 |
if (!skip_create) {
|
|
|
357786 |
/* Create the new image */
|
|
|
357786 |
ret = bdrv_create(drv, out_filename, opts, &local_err);
|
|
|
357786 |
@@ -2368,8 +2364,9 @@ static int img_convert(int argc, char **argv)
|
|
|
357786 |
* That has to wait for bdrv_create to be improved
|
|
|
357786 |
* to allow filenames in option syntax
|
|
|
357786 |
*/
|
|
|
357786 |
- s.target = img_open_new_file(out_filename, opts, out_fmt,
|
|
|
357786 |
- flags, writethrough, quiet, false);
|
|
|
357786 |
+ s.target = img_open_file(out_filename, open_opts, out_fmt,
|
|
|
357786 |
+ flags, writethrough, quiet, false);
|
|
|
357786 |
+ open_opts = NULL; /* blk_new_open will have freed it */
|
|
|
357786 |
}
|
|
|
357786 |
if (!s.target) {
|
|
|
357786 |
ret = -1;
|
|
|
357786 |
@@ -2437,6 +2434,7 @@ out:
|
|
|
357786 |
qemu_opts_del(opts);
|
|
|
357786 |
qemu_opts_free(create_opts);
|
|
|
357786 |
qemu_opts_del(sn_opts);
|
|
|
357786 |
+ qobject_unref(open_opts);
|
|
|
357786 |
blk_unref(s.target);
|
|
|
357786 |
if (s.src) {
|
|
|
357786 |
for (bs_i = 0; bs_i < s.src_num; bs_i++) {
|
|
|
357786 |
--
|
|
|
357786 |
1.8.3.1
|
|
|
357786 |
|