render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
fbe740
From 2de41b514449c5ab85a7a0943456a44909122874 Mon Sep 17 00:00:00 2001
fbe740
Message-Id: <2de41b514449c5ab85a7a0943456a44909122874@dist-git>
fbe740
From: Peter Krempa <pkrempa@redhat.com>
fbe740
Date: Tue, 4 Feb 2020 15:07:57 +0100
fbe740
Subject: [PATCH] qemu: checkpoint: Extract calculation of bitmap merging for
fbe740
 checkpoint deletion
fbe740
MIME-Version: 1.0
fbe740
Content-Type: text/plain; charset=UTF-8
fbe740
Content-Transfer-Encoding: 8bit
fbe740
fbe740
This will allow some testing before refactoring.
fbe740
fbe740
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
fbe740
Reviewed-by: Eric Blake <eblake@redhat.com>
fbe740
(cherry picked from commit d9dfc1f7de2e54c015504e0a0370e8a89b5e971a)
fbe740
fbe740
https://bugzilla.redhat.com/show_bug.cgi?id=1207659
fbe740
Message-Id: <2b3c69597aa8f99af55e30f71d4496b6ae620d31.1580824112.git.pkrempa@redhat.com>
fbe740
Reviewed-by: Ján Tomko <jtomko@redhat.com>
fbe740
---
fbe740
 src/qemu/qemu_checkpoint.c | 72 ++++++++++++++++++++++++--------------
fbe740
 src/qemu/qemu_checkpoint.h |  7 ++++
fbe740
 2 files changed, 53 insertions(+), 26 deletions(-)
fbe740
fbe740
diff --git a/src/qemu/qemu_checkpoint.c b/src/qemu/qemu_checkpoint.c
fbe740
index 1100f6e744..e75cdd0458 100644
fbe740
--- a/src/qemu/qemu_checkpoint.c
fbe740
+++ b/src/qemu/qemu_checkpoint.c
fbe740
@@ -148,6 +148,46 @@ qemuCheckpointFindActiveDiskInParent(virDomainObjPtr vm,
fbe740
 }
fbe740
 
fbe740
 
fbe740
+int
fbe740
+qemuCheckpointDiscardDiskBitmaps(virStorageSourcePtr src,
fbe740
+                                 const char *delbitmap,
fbe740
+                                 const char *parentbitmap,
fbe740
+                                 bool chkcurrent,
fbe740
+                                 virJSONValuePtr actions)
fbe740
+{
fbe740
+    if (parentbitmap) {
fbe740
+        g_autoptr(virJSONValue) arr = NULL;
fbe740
+
fbe740
+        if (!(arr = virJSONValueNewArray()))
fbe740
+            return -1;
fbe740
+
fbe740
+        if (qemuMonitorTransactionBitmapMergeSourceAddBitmap(arr,
fbe740
+                                                             src->nodeformat,
fbe740
+                                                             delbitmap) < 0)
fbe740
+            return -1;
fbe740
+
fbe740
+        if (chkcurrent) {
fbe740
+            if (qemuMonitorTransactionBitmapEnable(actions,
fbe740
+                                                   src->nodeformat,
fbe740
+                                                   parentbitmap) < 0)
fbe740
+                return -1;
fbe740
+        }
fbe740
+
fbe740
+        if (qemuMonitorTransactionBitmapMerge(actions,
fbe740
+                                              src->nodeformat,
fbe740
+                                              parentbitmap, &arr) < 0)
fbe740
+            return -1;
fbe740
+    }
fbe740
+
fbe740
+    if (qemuMonitorTransactionBitmapRemove(actions,
fbe740
+                                           src->nodeformat,
fbe740
+                                           delbitmap) < 0)
fbe740
+        return -1;
fbe740
+
fbe740
+    return 0;
fbe740
+}
fbe740
+
fbe740
+
fbe740
 static int
fbe740
 qemuCheckpointDiscardBitmaps(virDomainObjPtr vm,
fbe740
                              virDomainCheckpointDefPtr chkdef,
fbe740
@@ -167,6 +207,7 @@ qemuCheckpointDiscardBitmaps(virDomainObjPtr vm,
fbe740
         virDomainCheckpointDiskDef *chkdisk = &chkdef->disks[i];
fbe740
         virDomainDiskDefPtr domdisk = virDomainDiskByTarget(vm->def, chkdisk->name);
fbe740
         virDomainCheckpointDiskDef *parentchkdisk = NULL;
fbe740
+        const char *parentbitmap = NULL;
fbe740
 
fbe740
         /* domdisk can be missing e.g. when it was unplugged */
fbe740
         if (!domdisk)
fbe740
@@ -178,33 +219,12 @@ qemuCheckpointDiscardBitmaps(virDomainObjPtr vm,
fbe740
         /* If any ancestor checkpoint has a bitmap for the same
fbe740
          * disk, then this bitmap must be merged to the
fbe740
          * ancestor. */
fbe740
-        if ((parentchkdisk = qemuCheckpointFindActiveDiskInParent(vm, parent, chkdisk->name))) {
fbe740
-            g_autoptr(virJSONValue) arr = NULL;
fbe740
+        if ((parentchkdisk = qemuCheckpointFindActiveDiskInParent(vm, parent,
fbe740
+                                                                  chkdisk->name)))
fbe740
+            parentbitmap = parentchkdisk->name;
fbe740
 
fbe740
-            if (!(arr = virJSONValueNewArray()))
fbe740
-                return -1;
fbe740
-
fbe740
-            if (qemuMonitorTransactionBitmapMergeSourceAddBitmap(arr,
fbe740
-                                                                 domdisk->src->nodeformat,
fbe740
-                                                                 chkdisk->bitmap) < 0)
fbe740
-                return -1;
fbe740
-
fbe740
-            if (chkcurrent) {
fbe740
-                if (qemuMonitorTransactionBitmapEnable(actions,
fbe740
-                                                       domdisk->src->nodeformat,
fbe740
-                                                       parentchkdisk->bitmap) < 0)
fbe740
-                    return -1;
fbe740
-            }
fbe740
-
fbe740
-            if (qemuMonitorTransactionBitmapMerge(actions,
fbe740
-                                                  domdisk->src->nodeformat,
fbe740
-                                                  parentchkdisk->bitmap, &arr) < 0)
fbe740
-                return -1;
fbe740
-        }
fbe740
-
fbe740
-        if (qemuMonitorTransactionBitmapRemove(actions,
fbe740
-                                               domdisk->src->nodeformat,
fbe740
-                                               chkdisk->bitmap) < 0)
fbe740
+        if (qemuCheckpointDiscardDiskBitmaps(domdisk->src, chkdisk->bitmap,
fbe740
+                                             parentbitmap, chkcurrent, actions) < 0)
fbe740
             return -1;
fbe740
     }
fbe740
 
fbe740
diff --git a/src/qemu/qemu_checkpoint.h b/src/qemu/qemu_checkpoint.h
fbe740
index eb85611ea6..85fd453d50 100644
fbe740
--- a/src/qemu/qemu_checkpoint.h
fbe740
+++ b/src/qemu/qemu_checkpoint.h
fbe740
@@ -71,3 +71,10 @@ qemuCheckpointCreateFinalize(virQEMUDriverPtr driver,
fbe740
 void
fbe740
 qemuCheckpointRollbackMetadata(virDomainObjPtr vm,
fbe740
                                virDomainMomentObjPtr chk);
fbe740
+
fbe740
+int
fbe740
+qemuCheckpointDiscardDiskBitmaps(virStorageSourcePtr src,
fbe740
+                                 const char *delbitmap,
fbe740
+                                 const char *parentbitmap,
fbe740
+                                 bool chkcurrent,
fbe740
+                                 virJSONValuePtr actions);
fbe740
-- 
fbe740
2.25.0
fbe740