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

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