yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-qemu-img-Resolve-relative-backing-paths-in-rebase.patch

ae23c9
From 68af7bd1c3085fb25f50a7ad8cada0c33dbba748 Mon Sep 17 00:00:00 2001
ae23c9
From: Max Reitz <mreitz@redhat.com>
ae23c9
Date: Mon, 18 Jun 2018 17:48:32 +0200
ae23c9
Subject: [PATCH 071/268] qemu-img: Resolve relative backing paths in rebase
ae23c9
ae23c9
RH-Author: Max Reitz <mreitz@redhat.com>
ae23c9
Message-id: <20180618174833.19439-2-mreitz@redhat.com>
ae23c9
Patchwork-id: 80790
ae23c9
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH 1/2] qemu-img: Resolve relative backing paths in rebase
ae23c9
Bugzilla: 1569835
ae23c9
RH-Acked-by: John Snow <jsnow@redhat.com>
ae23c9
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
ae23c9
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
ae23c9
ae23c9
Currently, rebase interprets a relative path for the new backing image
ae23c9
as follows:
ae23c9
(1) Open the new backing image with the given relative path (thus relative to
ae23c9
    qemu-img's working directory).
ae23c9
(2) Write it directly into the overlay's backing path field (thus
ae23c9
    relative to the overlay).
ae23c9
ae23c9
If the overlay is not in qemu-img's working directory, both will be
ae23c9
different interpretations, which may either lead to an error somewhere
ae23c9
(either rebase fails because it cannot open the new backing image, or
ae23c9
your overlay becomes unusable because its backing path does not point to
ae23c9
a file), or, even worse, it may result in your rebase being performed
ae23c9
for a different backing file than what your overlay will point to after
ae23c9
the rebase.
ae23c9
ae23c9
Fix this by interpreting the target backing path as relative to the
ae23c9
overlay, like qemu-img does everywhere else.
ae23c9
ae23c9
Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=1569835
ae23c9
Cc: qemu-stable@nongnu.org
ae23c9
Signed-off-by: Max Reitz <mreitz@redhat.com>
ae23c9
Message-id: 20180509182002.8044-2-mreitz@redhat.com
ae23c9
Reviewed-by: Eric Blake <eblake@redhat.com>
ae23c9
Signed-off-by: Max Reitz <mreitz@redhat.com>
ae23c9
(cherry picked from commit d16699b64671466b42079c45b89127aeea1ca565)
ae23c9
Signed-off-by: Max Reitz <mreitz@redhat.com>
ae23c9
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
ae23c9
---
ae23c9
 qemu-img.c | 23 ++++++++++++++++++++++-
ae23c9
 1 file changed, 22 insertions(+), 1 deletion(-)
ae23c9
ae23c9
diff --git a/qemu-img.c b/qemu-img.c
ae23c9
index 4bcf157..76d6e47 100644
ae23c9
--- a/qemu-img.c
ae23c9
+++ b/qemu-img.c
ae23c9
@@ -3202,6 +3202,9 @@ static int img_rebase(int argc, char **argv)
ae23c9
         }
ae23c9
 
ae23c9
         if (out_baseimg[0]) {
ae23c9
+            const char *overlay_filename;
ae23c9
+            char *out_real_path;
ae23c9
+
ae23c9
             options = qdict_new();
ae23c9
             if (out_basefmt) {
ae23c9
                 qdict_put_str(options, "driver", out_basefmt);
ae23c9
@@ -3210,8 +3213,26 @@ static int img_rebase(int argc, char **argv)
ae23c9
                 qdict_put_bool(options, BDRV_OPT_FORCE_SHARE, true);
ae23c9
             }
ae23c9
 
ae23c9
-            blk_new_backing = blk_new_open(out_baseimg, NULL,
ae23c9
+            overlay_filename = bs->exact_filename[0] ? bs->exact_filename
ae23c9
+                                                     : bs->filename;
ae23c9
+            out_real_path = g_malloc(PATH_MAX);
ae23c9
+
ae23c9
+            bdrv_get_full_backing_filename_from_filename(overlay_filename,
ae23c9
+                                                         out_baseimg,
ae23c9
+                                                         out_real_path,
ae23c9
+                                                         PATH_MAX,
ae23c9
+                                                         &local_err);
ae23c9
+            if (local_err) {
ae23c9
+                error_reportf_err(local_err,
ae23c9
+                                  "Could not resolve backing filename: ");
ae23c9
+                ret = -1;
ae23c9
+                g_free(out_real_path);
ae23c9
+                goto out;
ae23c9
+            }
ae23c9
+
ae23c9
+            blk_new_backing = blk_new_open(out_real_path, NULL,
ae23c9
                                            options, src_flags, &local_err);
ae23c9
+            g_free(out_real_path);
ae23c9
             if (!blk_new_backing) {
ae23c9
                 error_reportf_err(local_err,
ae23c9
                                   "Could not open new backing file '%s': ",
ae23c9
-- 
ae23c9
1.8.3.1
ae23c9