Blame SOURCES/libvirt-qemu-backup-Move-fetching-of-checkpoint-list-for-incremental-backup.patch

b971b8
From 7dae651c45df86ce74b304535baf62013d7f527d Mon Sep 17 00:00:00 2001
b971b8
Message-Id: <7dae651c45df86ce74b304535baf62013d7f527d@dist-git>
b971b8
From: Peter Krempa <pkrempa@redhat.com>
b971b8
Date: Tue, 23 Jun 2020 12:23:38 +0200
b971b8
Subject: [PATCH] qemu: backup: Move fetching of checkpoint list for
b971b8
 incremental backup
b971b8
MIME-Version: 1.0
b971b8
Content-Type: text/plain; charset=UTF-8
b971b8
Content-Transfer-Encoding: 8bit
b971b8
b971b8
Fetch the checkpoint list for every disk specifically based on the new
b971b8
per-disk 'incremental' field.
b971b8
b971b8
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
b971b8
Reviewed-by: Eric Blake <eblake@redhat.com>
b971b8
(cherry picked from commit 15c5ed8ba64e26090174d296486eacfa240af53e)
b971b8
https://bugzilla.redhat.com/show_bug.cgi?id=1804593
b971b8
Message-Id: <485f9933893a9890f018889a76fc48654de2c58a.1592906423.git.pkrempa@redhat.com>
b971b8
Reviewed-by: Ján Tomko <jtomko@redhat.com>
b971b8
---
b971b8
 src/qemu/qemu_backup.c | 109 ++++++++++++++++++++---------------------
b971b8
 1 file changed, 53 insertions(+), 56 deletions(-)
b971b8
b971b8
diff --git a/src/qemu/qemu_backup.c b/src/qemu/qemu_backup.c
b971b8
index adbf696de6..13e2a7412b 100644
b971b8
--- a/src/qemu/qemu_backup.c
b971b8
+++ b/src/qemu/qemu_backup.c
b971b8
@@ -173,6 +173,50 @@ qemuBackupDiskDataCleanup(virDomainObjPtr vm,
b971b8
 }
b971b8
 
b971b8
 
b971b8
+/**
b971b8
+ * qemuBackupBeginCollectIncrementalCheckpoints:
b971b8
+ * @vm: domain object
b971b8
+ * @incrFrom: name of checkpoint representing starting point of incremental backup
b971b8
+ *
b971b8
+ * Returns a NULL terminated list of pointers to checkpoint definitions in
b971b8
+ * chronological order starting from the 'current' checkpoint until reaching
b971b8
+ * @incrFrom.
b971b8
+ */
b971b8
+static virDomainMomentDefPtr *
b971b8
+qemuBackupBeginCollectIncrementalCheckpoints(virDomainObjPtr vm,
b971b8
+                                             const char *incrFrom)
b971b8
+{
b971b8
+    virDomainMomentObjPtr n = virDomainCheckpointGetCurrent(vm->checkpoints);
b971b8
+    g_autofree virDomainMomentDefPtr *incr = NULL;
b971b8
+    size_t nincr = 0;
b971b8
+
b971b8
+    while (n) {
b971b8
+        virDomainMomentDefPtr def = n->def;
b971b8
+
b971b8
+        if (VIR_APPEND_ELEMENT_COPY(incr, nincr, def) < 0)
b971b8
+            return NULL;
b971b8
+
b971b8
+        if (STREQ(def->name, incrFrom)) {
b971b8
+            def = NULL;
b971b8
+            if (VIR_APPEND_ELEMENT_COPY(incr, nincr, def) < 0)
b971b8
+                return NULL;
b971b8
+
b971b8
+            return g_steal_pointer(&incr;;
b971b8
+        }
b971b8
+
b971b8
+        if (!n->def->parent_name)
b971b8
+            break;
b971b8
+
b971b8
+        n = virDomainCheckpointFindByName(vm->checkpoints, n->def->parent_name);
b971b8
+    }
b971b8
+
b971b8
+    virReportError(VIR_ERR_OPERATION_INVALID,
b971b8
+                   _("could not locate checkpoint '%s' for incremental backup"),
b971b8
+                   incrFrom);
b971b8
+    return NULL;
b971b8
+}
b971b8
+
b971b8
+
b971b8
 static int
b971b8
 qemuBackupGetBitmapMergeRange(virStorageSourcePtr from,
b971b8
                               const char *bitmapname,
b971b8
@@ -334,11 +378,11 @@ qemuBackupDiskPrepareDataOne(virDomainObjPtr vm,
b971b8
                              struct qemuBackupDiskData *dd,
b971b8
                              virJSONValuePtr actions,
b971b8
                              bool pull,
b971b8
-                             virDomainMomentDefPtr *incremental,
b971b8
                              virHashTablePtr blockNamedNodeData,
b971b8
                              virQEMUDriverConfigPtr cfg)
b971b8
 {
b971b8
     qemuDomainObjPrivatePtr priv = vm->privateData;
b971b8
+    g_autofree virDomainMomentDefPtr *incremental = NULL;
b971b8
 
b971b8
     /* set data structure */
b971b8
     dd->backupdisk = backupdisk;
b971b8
@@ -360,7 +404,8 @@ qemuBackupDiskPrepareDataOne(virDomainObjPtr vm,
b971b8
      * pull mode:
b971b8
      *   both: original disk
b971b8
      */
b971b8
-    if (pull || (incremental && dd->store->format >= VIR_STORAGE_FILE_BACKING)) {
b971b8
+    if (pull || (dd->backupdisk->incremental &&
b971b8
+                 dd->store->format >= VIR_STORAGE_FILE_BACKING)) {
b971b8
         dd->backingStore = dd->domdisk->src;
b971b8
     } else {
b971b8
         dd->backingStore = dd->terminator = virStorageSourceNew();
b971b8
@@ -372,7 +417,10 @@ qemuBackupDiskPrepareDataOne(virDomainObjPtr vm,
b971b8
     if (qemuDomainPrepareStorageSourceBlockdev(NULL, dd->store, priv, cfg) < 0)
b971b8
         return -1;
b971b8
 
b971b8
-    if (incremental) {
b971b8
+    if (dd->backupdisk->incremental) {
b971b8
+        if (!(incremental = qemuBackupBeginCollectIncrementalCheckpoints(vm, dd->backupdisk->incremental)))
b971b8
+            return -1;
b971b8
+
b971b8
         if (dd->backupdisk->exportbitmap)
b971b8
             dd->incrementalBitmap = g_strdup(dd->backupdisk->exportbitmap);
b971b8
         else
b971b8
@@ -441,7 +489,6 @@ qemuBackupDiskPrepareDataOnePull(virJSONValuePtr actions,
b971b8
 static ssize_t
b971b8
 qemuBackupDiskPrepareData(virDomainObjPtr vm,
b971b8
                           virDomainBackupDefPtr def,
b971b8
-                          virDomainMomentDefPtr *incremental,
b971b8
                           virHashTablePtr blockNamedNodeData,
b971b8
                           virJSONValuePtr actions,
b971b8
                           virQEMUDriverConfigPtr cfg,
b971b8
@@ -464,8 +511,7 @@ qemuBackupDiskPrepareData(virDomainObjPtr vm,
b971b8
         ndisks++;
b971b8
 
b971b8
         if (qemuBackupDiskPrepareDataOne(vm, backupdisk, dd, actions, pull,
b971b8
-                                         incremental, blockNamedNodeData,
b971b8
-                                         cfg) < 0)
b971b8
+                                         blockNamedNodeData, cfg) < 0)
b971b8
             goto error;
b971b8
 
b971b8
         if (pull) {
b971b8
@@ -622,50 +668,6 @@ qemuBackupBeginPullExportDisks(virDomainObjPtr vm,
b971b8
 }
b971b8
 
b971b8
 
b971b8
-/**
b971b8
- * qemuBackupBeginCollectIncrementalCheckpoints:
b971b8
- * @vm: domain object
b971b8
- * @incrFrom: name of checkpoint representing starting point of incremental backup
b971b8
- *
b971b8
- * Returns a NULL terminated list of pointers to checkpoint definitions in
b971b8
- * chronological order starting from the 'current' checkpoint until reaching
b971b8
- * @incrFrom.
b971b8
- */
b971b8
-static virDomainMomentDefPtr *
b971b8
-qemuBackupBeginCollectIncrementalCheckpoints(virDomainObjPtr vm,
b971b8
-                                             const char *incrFrom)
b971b8
-{
b971b8
-    virDomainMomentObjPtr n = virDomainCheckpointGetCurrent(vm->checkpoints);
b971b8
-    g_autofree virDomainMomentDefPtr *incr = NULL;
b971b8
-    size_t nincr = 0;
b971b8
-
b971b8
-    while (n) {
b971b8
-        virDomainMomentDefPtr def = n->def;
b971b8
-
b971b8
-        if (VIR_APPEND_ELEMENT_COPY(incr, nincr, def) < 0)
b971b8
-            return NULL;
b971b8
-
b971b8
-        if (STREQ(def->name, incrFrom)) {
b971b8
-            def = NULL;
b971b8
-            if (VIR_APPEND_ELEMENT_COPY(incr, nincr, def) < 0)
b971b8
-                return NULL;
b971b8
-
b971b8
-            return g_steal_pointer(&incr;;
b971b8
-        }
b971b8
-
b971b8
-        if (!n->def->parent_name)
b971b8
-            break;
b971b8
-
b971b8
-        n = virDomainCheckpointFindByName(vm->checkpoints, n->def->parent_name);
b971b8
-    }
b971b8
-
b971b8
-    virReportError(VIR_ERR_OPERATION_INVALID,
b971b8
-                   _("could not locate checkpoint '%s' for incremental backup"),
b971b8
-                   incrFrom);
b971b8
-    return NULL;
b971b8
-}
b971b8
-
b971b8
-
b971b8
 void
b971b8
 qemuBackupJobTerminate(virDomainObjPtr vm,
b971b8
                        qemuDomainJobStatus jobstatus)
b971b8
@@ -799,7 +801,6 @@ qemuBackupBegin(virDomainObjPtr vm,
b971b8
     bool pull = false;
b971b8
     virDomainMomentObjPtr chk = NULL;
b971b8
     g_autoptr(virDomainCheckpointDef) chkdef = NULL;
b971b8
-    g_autofree virDomainMomentDefPtr *incremental = NULL;
b971b8
     g_autoptr(virJSONValue) actions = NULL;
b971b8
     struct qemuBackupDiskData *dd = NULL;
b971b8
     ssize_t ndd = 0;
b971b8
@@ -867,10 +868,6 @@ qemuBackupBegin(virDomainObjPtr vm,
b971b8
     if (virDomainBackupAlignDisks(def, vm->def, suffix) < 0)
b971b8
         goto endjob;
b971b8
 
b971b8
-    if (def->incremental &&
b971b8
-        !(incremental = qemuBackupBeginCollectIncrementalCheckpoints(vm, def->incremental)))
b971b8
-        goto endjob;
b971b8
-
b971b8
     actions = virJSONValueNewArray();
b971b8
 
b971b8
     /* The 'chk' checkpoint must be rolled back if the transaction command
b971b8
@@ -884,7 +881,7 @@ qemuBackupBegin(virDomainObjPtr vm,
b971b8
     if (!(blockNamedNodeData = qemuBlockGetNamedNodeData(vm, QEMU_ASYNC_JOB_BACKUP)))
b971b8
         goto endjob;
b971b8
 
b971b8
-    if ((ndd = qemuBackupDiskPrepareData(vm, def, incremental, blockNamedNodeData,
b971b8
+    if ((ndd = qemuBackupDiskPrepareData(vm, def, blockNamedNodeData,
b971b8
                                          actions, cfg, &dd)) <= 0) {
b971b8
         if (ndd == 0) {
b971b8
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
b971b8
-- 
b971b8
2.27.0
b971b8