Blame SOURCES/libvirt-qemu-copy-Accept-format-parameter-when-copying-to-a-non-existing-img.patch

44539d
From bdc1f6bf79de43824f36bfba548b523765b24fb6 Mon Sep 17 00:00:00 2001
44539d
Message-Id: <bdc1f6bf79de43824f36bfba548b523765b24fb6@dist-git>
44539d
From: Peter Krempa <pkrempa@redhat.com>
44539d
Date: Wed, 1 Oct 2014 17:41:59 -0600
44539d
Subject: [PATCH] qemu: copy: Accept 'format' parameter when copying to a
44539d
 non-existing img
44539d
44539d
RHEL 7.0.z: https://bugzilla.redhat.com/show_bug.cgi?id=1149078
44539d
RHEL 7.1: https://bugzilla.redhat.com/show_bug.cgi?id=1113751
44539d
44539d
We have the following matrix of possible arguments handled by the logic
44539d
statement touched by this patch:
44539d
       | flags & _REUSE_EXT | !(flags & _REUSE_EXT)
44539d
-------+--------------------+----------------------
44539d
 format| (1)                | (2)
44539d
-------+--------------------+----------------------
44539d
!format| (3)                | (4)
44539d
-------+--------------------+----------------------
44539d
44539d
In cases 1 and 2 the user provided a format, in cases 3 and 4 not. The
44539d
user requests to use a pre-existing image in 1 and 3 and libvirt will
44539d
create a new image in 2 and 4.
44539d
44539d
The difference between cases 3 and 4 is that for 3 the format is probed
44539d
from the user-provided image, whereas in 4 we just use the existing disk
44539d
format.
44539d
44539d
The current code would treat cases 1,3 and 4 correctly but in case 2 the
44539d
format provided by the user would be ignored.
44539d
44539d
The particular piece of code was broken in commit 35c7701c64508f975dfeb8
44539d
but since it was introduced a few commits before that it was never
44539d
released as working.
44539d
44539d
(cherry picked from commit 42619ed05d7924978f3e6e2399522fc6f30607de)
44539d
Signed-off-by: Eric Blake <eblake@redhat.com>
44539d
44539d
Conflicts:
44539d
	src/qemu/qemu_driver.c - no refactoring of commits 7b7bf001, 4f20226
44539d
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
44539d
---
44539d
 src/qemu/qemu_driver.c | 37 +++++++++++++++++++++----------------
44539d
 1 file changed, 21 insertions(+), 16 deletions(-)
44539d
44539d
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
44539d
index ea87d50..72d03b5 100644
44539d
--- a/src/qemu/qemu_driver.c
44539d
+++ b/src/qemu/qemu_driver.c
44539d
@@ -15118,29 +15118,34 @@ qemuDomainBlockCopy(virDomainObjPtr vm,
44539d
         goto endjob;
44539d
     }
44539d
 
44539d
+    if (format) {
44539d
+        if ((mirrorFormat = virStorageFileFormatTypeFromString(format)) <= 0) {
44539d
+            virReportError(VIR_ERR_INVALID_ARG, _("unrecognized format '%s'"),
44539d
+                           format);
44539d
+            goto endjob;
44539d
+        }
44539d
+    } else {
44539d
+        if (!(flags & VIR_DOMAIN_BLOCK_REBASE_REUSE_EXT)) {
44539d
+            mirrorFormat = disk->format;
44539d
+        } else {
44539d
+            /* If the user passed the REUSE_EXT flag, then either they
44539d
+             * also passed the RAW flag (and format is non-NULL), or it is
44539d
+             * safe for us to probe the format from the file that we will
44539d
+             * be using.  */
44539d
+            mirrorFormat = virStorageFileProbeFormat(dest, cfg->user,
44539d
+                                                     cfg->group);
44539d
+        }
44539d
+    }
44539d
+
44539d
+    /* pre-create the image file */
44539d
     if (!(flags & VIR_DOMAIN_BLOCK_REBASE_REUSE_EXT)) {
44539d
         int fd = qemuOpenFile(driver, vm, dest, O_WRONLY | O_TRUNC | O_CREAT,
44539d
                               &need_unlink, NULL);
44539d
         if (fd < 0)
44539d
             goto endjob;
44539d
         VIR_FORCE_CLOSE(fd);
44539d
-        if (!format)
44539d
-            mirrorFormat = disk->format;
44539d
-    } else if (format) {
44539d
-        mirrorFormat = virStorageFileFormatTypeFromString(format);
44539d
-        if (mirrorFormat <= 0) {
44539d
-            virReportError(VIR_ERR_INVALID_ARG, _("unrecognized format '%s'"),
44539d
-                           format);
44539d
-            goto endjob;
44539d
-        }
44539d
-    } else {
44539d
-        /* If the user passed the REUSE_EXT flag, then either they
44539d
-         * also passed the RAW flag (and format is non-NULL), or it is
44539d
-         * safe for us to probe the format from the file that we will
44539d
-         * be using.  */
44539d
-        mirrorFormat = virStorageFileProbeFormat(dest, cfg->user,
44539d
-                                                 cfg->group);
44539d
     }
44539d
+
44539d
     if (!format && mirrorFormat > 0)
44539d
         format = virStorageFileFormatTypeToString(mirrorFormat);
44539d
     if (VIR_STRDUP(mirror, dest) < 0)
44539d
-- 
44539d
2.2.0
44539d