render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
fbe740
From d0dc4217142fda8ce8850a30b7d89a344bb55d5e Mon Sep 17 00:00:00 2001
fbe740
Message-Id: <d0dc4217142fda8ce8850a30b7d89a344bb55d5e@dist-git>
fbe740
From: Peter Krempa <pkrempa@redhat.com>
fbe740
Date: Tue, 23 Jun 2020 12:23:35 +0200
fbe740
Subject: [PATCH] qemu: backup: Split up code traversing checkpoint list
fbe740
 looking for bitmaps
fbe740
MIME-Version: 1.0
fbe740
Content-Type: text/plain; charset=UTF-8
fbe740
Content-Transfer-Encoding: 8bit
fbe740
fbe740
The algorithm is getting quite complex. Split out the lookup of range of
fbe740
backing chain storage sources and bitmaps contained in them which
fbe740
correspond to one checkpoint.
fbe740
fbe740
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
fbe740
Reviewed-by: Eric Blake <eblake@redhat.com>
fbe740
(cherry picked from commit 562511afa6cef5948e6339596ba5954cb5ed0565)
fbe740
https://bugzilla.redhat.com/show_bug.cgi?id=1804593
fbe740
Message-Id: <b3a1485033a5bb425f261caeb299973b2f39bbff.1592906423.git.pkrempa@redhat.com>
fbe740
Reviewed-by: Ján Tomko <jtomko@redhat.com>
fbe740
---
fbe740
 src/qemu/qemu_backup.c | 111 ++++++++++++++++++++++-------------------
fbe740
 1 file changed, 61 insertions(+), 50 deletions(-)
fbe740
fbe740
diff --git a/src/qemu/qemu_backup.c b/src/qemu/qemu_backup.c
fbe740
index 5d18720f53..400b711f79 100644
fbe740
--- a/src/qemu/qemu_backup.c
fbe740
+++ b/src/qemu/qemu_backup.c
fbe740
@@ -173,72 +173,83 @@ qemuBackupDiskDataCleanup(virDomainObjPtr vm,
fbe740
 }
fbe740
 
fbe740
 
fbe740
+static int
fbe740
+qemuBackupGetBitmapMergeRange(virStorageSourcePtr from,
fbe740
+                              const char *bitmapname,
fbe740
+                              virJSONValuePtr *actions,
fbe740
+                              virStorageSourcePtr *to,
fbe740
+                              const char *diskdst,
fbe740
+                              virHashTablePtr blockNamedNodeData)
fbe740
+{
fbe740
+    g_autoptr(virJSONValue) act = virJSONValueNewArray();
fbe740
+    virStorageSourcePtr tmpsrc = NULL;
fbe740
+    virStorageSourcePtr n;
fbe740
+    bool foundbitmap = false;
fbe740
+
fbe740
+    for (n = from; virStorageSourceIsBacking(n); n = n->backingStore) {
fbe740
+        qemuBlockNamedNodeDataBitmapPtr bitmap = NULL;
fbe740
+
fbe740
+        if (!(bitmap = qemuBlockNamedNodeDataGetBitmapByName(blockNamedNodeData,
fbe740
+                                                             n,
fbe740
+                                                             bitmapname)))
fbe740
+            break;
fbe740
+
fbe740
+        foundbitmap = true;
fbe740
+
fbe740
+        if (bitmap->inconsistent) {
fbe740
+            virReportError(VIR_ERR_INVALID_ARG,
fbe740
+                           _("bitmap '%s' for image '%s%u' is inconsistent"),
fbe740
+                           bitmap->name, diskdst, n->id);
fbe740
+            return -1;
fbe740
+        }
fbe740
+
fbe740
+        if (qemuMonitorTransactionBitmapMergeSourceAddBitmap(act,
fbe740
+                                                             n->nodeformat,
fbe740
+                                                             bitmapname) < 0)
fbe740
+            return -1;
fbe740
+
fbe740
+        tmpsrc = n;
fbe740
+    }
fbe740
+
fbe740
+    if (!foundbitmap) {
fbe740
+        virReportError(VIR_ERR_INVALID_ARG,
fbe740
+                       _("failed to find bitmap '%s' in image '%s%u'"),
fbe740
+                       bitmapname, diskdst, from->id);
fbe740
+        return -1;
fbe740
+    }
fbe740
+
fbe740
+    *actions = g_steal_pointer(&act;;
fbe740
+    *to = tmpsrc;
fbe740
+
fbe740
+    return 0;
fbe740
+}
fbe740
+
fbe740
+
fbe740
 virJSONValuePtr
fbe740
 qemuBackupDiskPrepareOneBitmapsChain(virDomainMomentDefPtr *incremental,
fbe740
                                      virStorageSourcePtr backingChain,
fbe740
                                      virHashTablePtr blockNamedNodeData,
fbe740
                                      const char *diskdst)
fbe740
 {
fbe740
-    qemuBlockNamedNodeDataBitmapPtr bitmap;
fbe740
     g_autoptr(virJSONValue) ret = NULL;
fbe740
     size_t incridx = 0;
fbe740
+    virStorageSourcePtr n = backingChain;
fbe740
 
fbe740
     ret = virJSONValueNewArray();
fbe740
 
fbe740
-    if (!(bitmap = qemuBlockNamedNodeDataGetBitmapByName(blockNamedNodeData,
fbe740
-                                                         backingChain,
fbe740
-                                                         incremental[0]->name))) {
fbe740
-        virReportError(VIR_ERR_INVALID_ARG,
fbe740
-                       _("failed to find bitmap '%s' in image '%s%u'"),
fbe740
-                       incremental[0]->name, diskdst, backingChain->id);
fbe740
-        return NULL;
fbe740
-    }
fbe740
+    for (incridx = 0; incremental[incridx]; incridx++) {
fbe740
+        g_autoptr(virJSONValue) tmp = virJSONValueNewArray();
fbe740
+        virStorageSourcePtr tmpsrc = NULL;
fbe740
 
fbe740
-    while (bitmap) {
fbe740
-        if (bitmap->inconsistent) {
fbe740
-            virReportError(VIR_ERR_INVALID_ARG,
fbe740
-                           _("bitmap '%s' for image '%s%u' is inconsistent"),
fbe740
-                           bitmap->name, diskdst, backingChain->id);
fbe740
+        if (qemuBackupGetBitmapMergeRange(n, incremental[incridx]->name,
fbe740
+                                          &tmp, &tmpsrc, diskdst,
fbe740
+                                          blockNamedNodeData) < 0)
fbe740
             return NULL;
fbe740
-        }
fbe740
 
fbe740
-        if (qemuMonitorTransactionBitmapMergeSourceAddBitmap(ret,
fbe740
-                                                             backingChain->nodeformat,
fbe740
-                                                             bitmap->name) < 0)
fbe740
+        if (virJSONValueArrayConcat(ret, tmp) < 0)
fbe740
             return NULL;
fbe740
 
fbe740
-        if (backingChain->backingStore &&
fbe740
-            (bitmap = qemuBlockNamedNodeDataGetBitmapByName(blockNamedNodeData,
fbe740
-                                                            backingChain->backingStore,
fbe740
-                                                            incremental[incridx]->name))) {
fbe740
-            backingChain = backingChain->backingStore;
fbe740
-            continue;
fbe740
-        }
fbe740
-
fbe740
-        if (incremental[incridx + 1]) {
fbe740
-            if ((bitmap = qemuBlockNamedNodeDataGetBitmapByName(blockNamedNodeData,
fbe740
-                                                                backingChain,
fbe740
-                                                                incremental[incridx + 1]->name))) {
fbe740
-                incridx++;
fbe740
-                continue;
fbe740
-            }
fbe740
-
fbe740
-            if (backingChain->backingStore &&
fbe740
-                (bitmap = qemuBlockNamedNodeDataGetBitmapByName(blockNamedNodeData,
fbe740
-                                                                backingChain->backingStore,
fbe740
-                                                                incremental[incridx + 1]->name))) {
fbe740
-                incridx++;
fbe740
-                backingChain = backingChain->backingStore;
fbe740
-                continue;
fbe740
-            }
fbe740
-
fbe740
-            virReportError(VIR_ERR_INVALID_ARG,
fbe740
-                           _("failed to find bitmap '%s' in image '%s%u'"),
fbe740
-                           incremental[incridx]->name, diskdst, backingChain->id);
fbe740
-            return NULL;
fbe740
-        } else {
fbe740
-            break;
fbe740
-        }
fbe740
+        n = tmpsrc;
fbe740
     }
fbe740
 
fbe740
     return g_steal_pointer(&ret;;
fbe740
-- 
fbe740
2.27.0
fbe740