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

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