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

214 lines
7.7 KiB
Diff
Raw Normal View History

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