]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: backup: Fix backup of disk skipped in an intermediate checkpoint
authorPeter Krempa <pkrempa@redhat.com>
Thu, 21 May 2020 11:23:40 +0000 (13:23 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 22 Jun 2020 14:04:29 +0000 (16:04 +0200)
If a disk is not captured by one of the intermediate checkpoints the
code would fail, but we can easily calculate the bitmaps to merge
correctly by skipping over checkpoints which don't describe the disk.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
src/qemu/qemu_backup.c
tests/qemublocktest.c

index 8d75b59db2898659c40b5f8f8fd88ff8e98aa6dd..d56794af1f02f148ec82a4ce85f99fbafd8baa9e 100644 (file)
@@ -240,6 +240,30 @@ qemuBackupDiskPrepareOneBitmapsChain(virDomainMomentDefPtr *incremental,
     for (incridx = 0; incremental[incridx]; incridx++) {
         g_autoptr(virJSONValue) tmp = virJSONValueNewArray();
         virStorageSourcePtr tmpsrc = NULL;
+        virDomainCheckpointDefPtr chkdef = (virDomainCheckpointDefPtr) incremental[incridx];
+        bool checkpoint_has_disk = false;
+        size_t i;
+
+        for (i = 0; i < chkdef->ndisks; i++) {
+            if (STRNEQ_NULLABLE(diskdst, chkdef->disks[i].name))
+                continue;
+
+            if (chkdef->disks[i].type == VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP)
+                checkpoint_has_disk = true;
+
+            break;
+        }
+
+        if (!checkpoint_has_disk) {
+            if (!incremental[incridx + 1]) {
+                virReportError(VIR_ERR_INVALID_ARG,
+                               _("disk '%s' not found in checkpoint '%s'"),
+                               diskdst, incremental[incridx]->name);
+                return NULL;
+            }
+
+            continue;
+        }
 
         if (qemuBackupGetBitmapMergeRange(n, incremental[incridx]->name,
                                           &tmp, &tmpsrc, diskdst,
index 0cdedb9ad40db6938b28ad3ed510db40e99804ec..f00d2ff129010209b08839ea7abda2bbf04373a8 100644 (file)
@@ -727,6 +727,12 @@ testQemuBackupGetIncrementalMoment(const char *name)
     if (!(checkpoint = virDomainCheckpointDefNew()))
         abort();
 
+    checkpoint->disks = g_new0(virDomainCheckpointDiskDef, 1);
+    checkpoint->ndisks = 1;
+
+    checkpoint->disks[0].name = g_strdup("testdisk");
+    checkpoint->disks[0].type = VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP;
+
     checkpoint->parent.name = g_strdup(name);
 
     return (virDomainMomentDefPtr) checkpoint;