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