render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
9119d9
From 61fbb57d74cc44594b5bcb184c350ab18b963291 Mon Sep 17 00:00:00 2001
9119d9
Message-Id: <61fbb57d74cc44594b5bcb184c350ab18b963291@dist-git>
9119d9
From: Eric Blake <eblake@redhat.com>
9119d9
Date: Tue, 24 Feb 2015 11:59:51 +0100
9119d9
Subject: [PATCH] blockjob: shuffle block rebase code
9119d9
9119d9
https://bugzilla.redhat.com/show_bug.cgi?id=1196066
9119d9
9119d9
The existing virDomainBlockRebase code rejected the combination of
9119d9
_RELATIVE and _COPY flags, but only by accident.  It makes sense
9119d9
to add support for the combination someday, at least for the case
9119d9
of _SHALLOW and not _REUSE_EXT; but to implement it, libvirt would
9119d9
have to pre-create the file with a relative backing name, and I'm
9119d9
not ready to code that in yet.
9119d9
9119d9
Meanwhile, the code to forward on to the block copy code is getting
9119d9
longer, and reorganizing the function to have the block pull done
9119d9
early makes it easier to add even more block copy prep code.
9119d9
9119d9
This patch should have no semantic difference other than the quality
9119d9
of the error message on the unsupported flag combination.  Pre-patch:
9119d9
9119d9
error: unsupported flags (0x10) in function qemuDomainBlockCopy
9119d9
9119d9
Post-patch:
9119d9
9119d9
error: argument unsupported: Relative backing during copy not supported yet
9119d9
9119d9
* src/qemu/qemu_driver.c (qemuDomainBlockRebase): Reorder code,
9119d9
and improve error message of relative copy.
9119d9
9119d9
Signed-off-by: Eric Blake <eblake@redhat.com>
9119d9
(cherry picked from commit 02d2bd7d91c200d1ea1a5b3f78c8b41720cea832)
9119d9
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
9119d9
---
9119d9
 src/qemu/qemu_driver.c | 47 ++++++++++++++++++++++++++++++++---------------
9119d9
 1 file changed, 32 insertions(+), 15 deletions(-)
9119d9
9119d9
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
9119d9
index f3b909f..162e039 100644
9119d9
--- a/src/qemu/qemu_driver.c
9119d9
+++ b/src/qemu/qemu_driver.c
9119d9
@@ -15947,6 +15947,8 @@ qemuDomainBlockRebase(virDomainPtr dom, const char *path, const char *base,
9119d9
                       unsigned long bandwidth, unsigned int flags)
9119d9
 {
9119d9
     virDomainObjPtr vm;
9119d9
+    const char *format = NULL;
9119d9
+    int ret = -1;
9119d9
 
9119d9
     virCheckFlags(VIR_DOMAIN_BLOCK_REBASE_SHALLOW |
9119d9
                   VIR_DOMAIN_BLOCK_REBASE_REUSE_EXT |
9119d9
@@ -15957,22 +15959,37 @@ qemuDomainBlockRebase(virDomainPtr dom, const char *path, const char *base,
9119d9
     if (!(vm = qemuDomObjFromDomain(dom)))
9119d9
         return -1;
9119d9
 
9119d9
-    if (virDomainBlockRebaseEnsureACL(dom->conn, vm->def) < 0) {
9119d9
+    if (virDomainBlockRebaseEnsureACL(dom->conn, vm->def) < 0)
9119d9
+        goto cleanup;
9119d9
+
9119d9
+    /* For normal rebase (enhanced blockpull), the common code handles
9119d9
+     * everything, including vm cleanup. */
9119d9
+    if (!(flags & VIR_DOMAIN_BLOCK_REBASE_COPY))
9119d9
+        return qemuDomainBlockJobImpl(vm, dom->conn, path, base, bandwidth,
9119d9
+                                      NULL, BLOCK_JOB_PULL, flags);
9119d9
+
9119d9
+    /* If we got here, we are doing a block copy rebase. */
9119d9
+    if (flags & VIR_DOMAIN_BLOCK_REBASE_COPY_RAW)
9119d9
+        format = "raw";
9119d9
+
9119d9
+    /* XXX: If we are doing a shallow copy but not reusing an external
9119d9
+     * file, we should attempt to pre-create the destination with a
9119d9
+     * relative backing chain instead of qemu's default of absolute */
9119d9
+    if (flags & VIR_DOMAIN_BLOCK_REBASE_RELATIVE) {
9119d9
+        virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
9119d9
+                       _("Relative backing during copy not supported yet"));
9119d9
+        goto cleanup;
9119d9
+    }
9119d9
+
9119d9
+    flags &= (VIR_DOMAIN_BLOCK_REBASE_SHALLOW |
9119d9
+              VIR_DOMAIN_BLOCK_REBASE_REUSE_EXT);
9119d9
+    ret = qemuDomainBlockCopy(vm, dom->conn, path, base, format,
9119d9
+                              bandwidth, flags);
9119d9
+    vm = NULL;
9119d9
+ cleanup:
9119d9
+    if (vm)
9119d9
         virObjectUnlock(vm);
9119d9
-        return -1;
9119d9
-    }
9119d9
-
9119d9
-    if (flags & VIR_DOMAIN_BLOCK_REBASE_COPY) {
9119d9
-        const char *format = NULL;
9119d9
-        if (flags & VIR_DOMAIN_BLOCK_REBASE_COPY_RAW)
9119d9
-            format = "raw";
9119d9
-        flags &= ~(VIR_DOMAIN_BLOCK_REBASE_COPY |
9119d9
-                   VIR_DOMAIN_BLOCK_REBASE_COPY_RAW);
9119d9
-        return qemuDomainBlockCopy(vm, dom->conn, path, base, format, bandwidth, flags);
9119d9
-    }
9119d9
-
9119d9
-    return qemuDomainBlockJobImpl(vm, dom->conn, path, base, bandwidth, NULL,
9119d9
-                                  BLOCK_JOB_PULL, flags);
9119d9
+    return ret;
9119d9
 }
9119d9
 
9119d9
 static int
9119d9
-- 
9119d9
2.3.0
9119d9