]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: checkpoint: tolerate missing disks on checkpoint deletion
authorPeter Krempa <pkrempa@redhat.com>
Wed, 8 Jan 2020 07:18:51 +0000 (08:18 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 27 Jan 2020 14:28:49 +0000 (15:28 +0100)
If a disk is unplugged and then the user tries to delete a checkpoint
the code would try to use NULL node name as it was not checked.

Fix this by fetching the whole disk definition object and verifying it
was found.

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

index 03a8321135ae38cda5adb0b1e025802446d208c2..326707e09880fd57bbb6f354d6241d170e44d4c8 100644 (file)
@@ -125,12 +125,15 @@ qemuCheckpointDiscardBitmaps(virDomainObjPtr vm,
 
     for (i = 0; i < chkdef->ndisks; i++) {
         virDomainCheckpointDiskDef *chkdisk = &chkdef->disks[i];
-        const char *node;
+        virDomainDiskDefPtr domdisk = virDomainDiskByTarget(vm->def, chkdisk->name);
+
+        /* domdisk can be missing e.g. when it was unplugged */
+        if (!domdisk)
+            continue;
 
         if (chkdisk->type != VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP)
             continue;
 
-        node = qemuDomainDiskNodeFormatLookup(vm, chkdisk->name);
         /* If any ancestor checkpoint has a bitmap for the same
          * disk, then this bitmap must be merged to the
          * ancestor. */
@@ -153,20 +156,28 @@ qemuCheckpointDiscardBitmaps(virDomainObjPtr vm,
                 if (!(arr = virJSONValueNewArray()))
                     return -1;
 
-                if (qemuMonitorTransactionBitmapMergeSourceAddBitmap(arr, node, chkdisk->bitmap) < 0)
+                if (qemuMonitorTransactionBitmapMergeSourceAddBitmap(arr,
+                                                                     domdisk->src->nodeformat,
+                                                                     chkdisk->bitmap) < 0)
                     return -1;
 
                 if (chkcurrent) {
-                    if (qemuMonitorTransactionBitmapEnable(actions, node, disk2->bitmap) < 0)
+                    if (qemuMonitorTransactionBitmapEnable(actions,
+                                                           domdisk->src->nodeformat,
+                                                           disk2->bitmap) < 0)
                         return -1;
                 }
 
-                if (qemuMonitorTransactionBitmapMerge(actions, node, disk2->bitmap, &arr) < 0)
+                if (qemuMonitorTransactionBitmapMerge(actions,
+                                                      domdisk->src->nodeformat,
+                                                      disk2->bitmap, &arr) < 0)
                     return -1;
             }
         }
 
-        if (qemuMonitorTransactionBitmapRemove(actions, node, chkdisk->bitmap) < 0)
+        if (qemuMonitorTransactionBitmapRemove(actions,
+                                               domdisk->src->nodeformat,
+                                               chkdisk->bitmap) < 0)
             return -1;
     }