render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
b971b8
From 97a6adcb3ac735ff135469aa602c798fbc0b1491 Mon Sep 17 00:00:00 2001
b971b8
Message-Id: <97a6adcb3ac735ff135469aa602c798fbc0b1491@dist-git>
b971b8
From: Peter Krempa <pkrempa@redhat.com>
b971b8
Date: Tue, 23 Jun 2020 12:23:36 +0200
b971b8
Subject: [PATCH] qemu: backup: Fix backup of disk skipped in an intermediate
b971b8
 checkpoint
b971b8
MIME-Version: 1.0
b971b8
Content-Type: text/plain; charset=UTF-8
b971b8
Content-Transfer-Encoding: 8bit
b971b8
b971b8
If a disk is not captured by one of the intermediate checkpoints the
b971b8
code would fail, but we can easily calculate the bitmaps to merge
b971b8
correctly by skipping over checkpoints which don't describe the disk.
b971b8
b971b8
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
b971b8
Reviewed-by: Eric Blake <eblake@redhat.com>
b971b8
(cherry picked from commit c89a44777fdf89b400878adcb03a3557bcec3f4e)
b971b8
b971b8
https://bugzilla.redhat.com/show_bug.cgi?id=1804593
b971b8
Message-Id: <d0efe760e9f8049758691b7f66a7de41fce5c264.1592906423.git.pkrempa@redhat.com>
b971b8
Reviewed-by: Ján Tomko <jtomko@redhat.com>
b971b8
---
b971b8
 src/qemu/qemu_backup.c | 24 ++++++++++++++++++++++++
b971b8
 tests/qemublocktest.c  |  6 ++++++
b971b8
 2 files changed, 30 insertions(+)
b971b8
b971b8
diff --git a/src/qemu/qemu_backup.c b/src/qemu/qemu_backup.c
b971b8
index 400b711f79..adbf696de6 100644
b971b8
--- a/src/qemu/qemu_backup.c
b971b8
+++ b/src/qemu/qemu_backup.c
b971b8
@@ -240,6 +240,30 @@ qemuBackupDiskPrepareOneBitmapsChain(virDomainMomentDefPtr *incremental,
b971b8
     for (incridx = 0; incremental[incridx]; incridx++) {
b971b8
         g_autoptr(virJSONValue) tmp = virJSONValueNewArray();
b971b8
         virStorageSourcePtr tmpsrc = NULL;
b971b8
+        virDomainCheckpointDefPtr chkdef = (virDomainCheckpointDefPtr) incremental[incridx];
b971b8
+        bool checkpoint_has_disk = false;
b971b8
+        size_t i;
b971b8
+
b971b8
+        for (i = 0; i < chkdef->ndisks; i++) {
b971b8
+            if (STRNEQ_NULLABLE(diskdst, chkdef->disks[i].name))
b971b8
+                continue;
b971b8
+
b971b8
+            if (chkdef->disks[i].type == VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP)
b971b8
+                checkpoint_has_disk = true;
b971b8
+
b971b8
+            break;
b971b8
+        }
b971b8
+
b971b8
+        if (!checkpoint_has_disk) {
b971b8
+            if (!incremental[incridx + 1]) {
b971b8
+                virReportError(VIR_ERR_INVALID_ARG,
b971b8
+                               _("disk '%s' not found in checkpoint '%s'"),
b971b8
+                               diskdst, incremental[incridx]->name);
b971b8
+                return NULL;
b971b8
+            }
b971b8
+
b971b8
+            continue;
b971b8
+        }
b971b8
 
b971b8
         if (qemuBackupGetBitmapMergeRange(n, incremental[incridx]->name,
b971b8
                                           &tmp, &tmpsrc, diskdst,
b971b8
diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c
b971b8
index e461b3a23d..d15965d9eb 100644
b971b8
--- a/tests/qemublocktest.c
b971b8
+++ b/tests/qemublocktest.c
b971b8
@@ -727,6 +727,12 @@ testQemuBackupGetIncrementalMoment(const char *name)
b971b8
     if (!(checkpoint = virDomainCheckpointDefNew()))
b971b8
         abort();
b971b8
 
b971b8
+    checkpoint->disks = g_new0(virDomainCheckpointDiskDef, 1);
b971b8
+    checkpoint->ndisks = 1;
b971b8
+
b971b8
+    checkpoint->disks[0].name = g_strdup("testdisk");
b971b8
+    checkpoint->disks[0].type = VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP;
b971b8
+
b971b8
     checkpoint->parent.name = g_strdup(name);
b971b8
 
b971b8
     return (virDomainMomentDefPtr) checkpoint;
b971b8
-- 
b971b8
2.27.0
b971b8