render / rpms / libvirt

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