Blame SOURCES/libvirt-qemu-backup-Fix-handling-of-backing-store-for-backup-target-images.patch

a41c76
From 14b1e4fc93ba1a87854aa1afaf519cc3accff4c6 Mon Sep 17 00:00:00 2001
a41c76
Message-Id: <14b1e4fc93ba1a87854aa1afaf519cc3accff4c6@dist-git>
a41c76
From: Peter Krempa <pkrempa@redhat.com>
a41c76
Date: Tue, 23 Jun 2020 12:23:34 +0200
a41c76
Subject: [PATCH] qemu: backup: Fix handling of backing store for backup target
a41c76
 images
a41c76
MIME-Version: 1.0
a41c76
Content-Type: text/plain; charset=UTF-8
a41c76
Content-Transfer-Encoding: 8bit
a41c76
a41c76
We always tried to install backing store for the image even if it didn't
a41c76
make sense, e.g. for a full backup into a raw image. Additionally we
a41c76
didn't record the backing file into the qcow2 metadata so the image
a41c76
itself contained the diff of data but reading from it would be
a41c76
incomplete as it depends on the backing image.
a41c76
a41c76
This patch fixes both issues by carefully installing the correct backing
a41c76
file when appropriate and also recording it into the metadata when
a41c76
creating the image.
a41c76
a41c76
https://bugzilla.redhat.com/show_bug.cgi?id=1813310
a41c76
a41c76
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
a41c76
Reviewed-by: Ján Tomko <jtomko@redhat.com>
a41c76
(cherry picked from commit 4aea6f42fe32175ce0cb9015913db536097130e4)
a41c76
https://bugzilla.redhat.com/show_bug.cgi?id=1804593
a41c76
Message-Id: <8c4ebc06863aac1f75532b6633772944a6b0bd2a.1592906423.git.pkrempa@redhat.com>
a41c76
Reviewed-by: Ján Tomko <jtomko@redhat.com>
a41c76
---
a41c76
 src/qemu/qemu_backup.c | 26 ++++++++++++++++++++++----
a41c76
 1 file changed, 22 insertions(+), 4 deletions(-)
a41c76
a41c76
diff --git a/src/qemu/qemu_backup.c b/src/qemu/qemu_backup.c
a41c76
index 9a056fa407..5d18720f53 100644
a41c76
--- a/src/qemu/qemu_backup.c
a41c76
+++ b/src/qemu/qemu_backup.c
a41c76
@@ -105,6 +105,8 @@ struct qemuBackupDiskData {
a41c76
     virDomainDiskDefPtr domdisk;
a41c76
     qemuBlockJobDataPtr blockjob;
a41c76
     virStorageSourcePtr store;
a41c76
+    virStorageSourcePtr terminator;
a41c76
+    virStorageSourcePtr backingStore;
a41c76
     char *incrementalBitmap;
a41c76
     qemuBlockStorageSourceChainDataPtr crdata;
a41c76
     bool labelled;
a41c76
@@ -146,6 +148,7 @@ qemuBackupDiskDataCleanupOne(virDomainObjPtr vm,
a41c76
         qemuBlockJobStartupFinalize(vm, dd->blockjob);
a41c76
 
a41c76
     qemuBlockStorageSourceChainDataFree(dd->crdata);
a41c76
+    virObjectUnref(dd->terminator);
a41c76
 }
a41c76
 
a41c76
 
a41c76
@@ -295,6 +298,7 @@ qemuBackupDiskPrepareDataOne(virDomainObjPtr vm,
a41c76
                              virDomainBackupDiskDefPtr backupdisk,
a41c76
                              struct qemuBackupDiskData *dd,
a41c76
                              virJSONValuePtr actions,
a41c76
+                             bool pull,
a41c76
                              virDomainMomentDefPtr *incremental,
a41c76
                              virHashTablePtr blockNamedNodeData,
a41c76
                              virQEMUDriverConfigPtr cfg)
a41c76
@@ -314,6 +318,19 @@ qemuBackupDiskPrepareDataOne(virDomainObjPtr vm,
a41c76
     if (!dd->store->format)
a41c76
         dd->store->format = VIR_STORAGE_FILE_QCOW2;
a41c76
 
a41c76
+    /* calculate backing store to use:
a41c76
+     * push mode:
a41c76
+     *   full backups: no backing store
a41c76
+     *   incremental: original disk if format supports backing store
a41c76
+     * pull mode:
a41c76
+     *   both: original disk
a41c76
+     */
a41c76
+    if (pull || (incremental && dd->store->format >= VIR_STORAGE_FILE_BACKING)) {
a41c76
+        dd->backingStore = dd->domdisk->src;
a41c76
+    } else {
a41c76
+        dd->backingStore = dd->terminator = virStorageSourceNew();
a41c76
+    }
a41c76
+
a41c76
     if (qemuDomainStorageFileInit(priv->driver, vm, dd->store, dd->domdisk->src) < 0)
a41c76
         return -1;
a41c76
 
a41c76
@@ -337,7 +354,7 @@ qemuBackupDiskPrepareDataOne(virDomainObjPtr vm,
a41c76
 
a41c76
     /* use original disk as backing to prevent opening the backing chain */
a41c76
     if (!(dd->crdata = qemuBuildStorageSourceChainAttachPrepareBlockdevTop(dd->store,
a41c76
-                                                                           dd->domdisk->src,
a41c76
+                                                                           dd->backingStore,
a41c76
                                                                            priv->qemuCaps)))
a41c76
         return -1;
a41c76
 
a41c76
@@ -398,6 +415,7 @@ qemuBackupDiskPrepareData(virDomainObjPtr vm,
a41c76
     struct qemuBackupDiskData *disks = NULL;
a41c76
     ssize_t ndisks = 0;
a41c76
     size_t i;
a41c76
+    bool pull = def->type == VIR_DOMAIN_BACKUP_TYPE_PULL;
a41c76
 
a41c76
     disks = g_new0(struct qemuBackupDiskData, def->ndisks);
a41c76
 
a41c76
@@ -410,12 +428,12 @@ qemuBackupDiskPrepareData(virDomainObjPtr vm,
a41c76
 
a41c76
         ndisks++;
a41c76
 
a41c76
-        if (qemuBackupDiskPrepareDataOne(vm, backupdisk, dd, actions,
a41c76
+        if (qemuBackupDiskPrepareDataOne(vm, backupdisk, dd, actions, pull,
a41c76
                                          incremental, blockNamedNodeData,
a41c76
                                          cfg) < 0)
a41c76
             goto error;
a41c76
 
a41c76
-        if (def->type == VIR_DOMAIN_BACKUP_TYPE_PULL) {
a41c76
+        if (pull) {
a41c76
             if (qemuBackupDiskPrepareDataOnePull(actions, dd) < 0)
a41c76
                 goto error;
a41c76
         } else {
a41c76
@@ -480,7 +498,7 @@ qemuBackupDiskPrepareOneStorage(virDomainObjPtr vm,
a41c76
                                                    dd->store, dd->domdisk->src) < 0)
a41c76
             return -1;
a41c76
 
a41c76
-        if (qemuBlockStorageSourceCreate(vm, dd->store, NULL, NULL,
a41c76
+        if (qemuBlockStorageSourceCreate(vm, dd->store, dd->backingStore, NULL,
a41c76
                                          dd->crdata->srcdata[0],
a41c76
                                          QEMU_ASYNC_JOB_BACKUP) < 0)
a41c76
             return -1;
a41c76
-- 
a41c76
2.27.0
a41c76