render / rpms / libvirt

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