Blob Blame History Raw
From 2de41b514449c5ab85a7a0943456a44909122874 Mon Sep 17 00:00:00 2001
Message-Id: <2de41b514449c5ab85a7a0943456a44909122874@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Tue, 4 Feb 2020 15:07:57 +0100
Subject: [PATCH] qemu: checkpoint: Extract calculation of bitmap merging for
 checkpoint deletion
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This will allow some testing before refactoring.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
(cherry picked from commit d9dfc1f7de2e54c015504e0a0370e8a89b5e971a)

https://bugzilla.redhat.com/show_bug.cgi?id=1207659
Message-Id: <2b3c69597aa8f99af55e30f71d4496b6ae620d31.1580824112.git.pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/qemu/qemu_checkpoint.c | 72 ++++++++++++++++++++++++--------------
 src/qemu/qemu_checkpoint.h |  7 ++++
 2 files changed, 53 insertions(+), 26 deletions(-)

diff --git a/src/qemu/qemu_checkpoint.c b/src/qemu/qemu_checkpoint.c
index 1100f6e744..e75cdd0458 100644
--- a/src/qemu/qemu_checkpoint.c
+++ b/src/qemu/qemu_checkpoint.c
@@ -148,6 +148,46 @@ qemuCheckpointFindActiveDiskInParent(virDomainObjPtr vm,
 }
 
 
+int
+qemuCheckpointDiscardDiskBitmaps(virStorageSourcePtr src,
+                                 const char *delbitmap,
+                                 const char *parentbitmap,
+                                 bool chkcurrent,
+                                 virJSONValuePtr actions)
+{
+    if (parentbitmap) {
+        g_autoptr(virJSONValue) arr = NULL;
+
+        if (!(arr = virJSONValueNewArray()))
+            return -1;
+
+        if (qemuMonitorTransactionBitmapMergeSourceAddBitmap(arr,
+                                                             src->nodeformat,
+                                                             delbitmap) < 0)
+            return -1;
+
+        if (chkcurrent) {
+            if (qemuMonitorTransactionBitmapEnable(actions,
+                                                   src->nodeformat,
+                                                   parentbitmap) < 0)
+                return -1;
+        }
+
+        if (qemuMonitorTransactionBitmapMerge(actions,
+                                              src->nodeformat,
+                                              parentbitmap, &arr) < 0)
+            return -1;
+    }
+
+    if (qemuMonitorTransactionBitmapRemove(actions,
+                                           src->nodeformat,
+                                           delbitmap) < 0)
+        return -1;
+
+    return 0;
+}
+
+
 static int
 qemuCheckpointDiscardBitmaps(virDomainObjPtr vm,
                              virDomainCheckpointDefPtr chkdef,
@@ -167,6 +207,7 @@ qemuCheckpointDiscardBitmaps(virDomainObjPtr vm,
         virDomainCheckpointDiskDef *chkdisk = &chkdef->disks[i];
         virDomainDiskDefPtr domdisk = virDomainDiskByTarget(vm->def, chkdisk->name);
         virDomainCheckpointDiskDef *parentchkdisk = NULL;
+        const char *parentbitmap = NULL;
 
         /* domdisk can be missing e.g. when it was unplugged */
         if (!domdisk)
@@ -178,33 +219,12 @@ qemuCheckpointDiscardBitmaps(virDomainObjPtr vm,
         /* If any ancestor checkpoint has a bitmap for the same
          * disk, then this bitmap must be merged to the
          * ancestor. */
-        if ((parentchkdisk = qemuCheckpointFindActiveDiskInParent(vm, parent, chkdisk->name))) {
-            g_autoptr(virJSONValue) arr = NULL;
+        if ((parentchkdisk = qemuCheckpointFindActiveDiskInParent(vm, parent,
+                                                                  chkdisk->name)))
+            parentbitmap = parentchkdisk->name;
 
-            if (!(arr = virJSONValueNewArray()))
-                return -1;
-
-            if (qemuMonitorTransactionBitmapMergeSourceAddBitmap(arr,
-                                                                 domdisk->src->nodeformat,
-                                                                 chkdisk->bitmap) < 0)
-                return -1;
-
-            if (chkcurrent) {
-                if (qemuMonitorTransactionBitmapEnable(actions,
-                                                       domdisk->src->nodeformat,
-                                                       parentchkdisk->bitmap) < 0)
-                    return -1;
-            }
-
-            if (qemuMonitorTransactionBitmapMerge(actions,
-                                                  domdisk->src->nodeformat,
-                                                  parentchkdisk->bitmap, &arr) < 0)
-                return -1;
-        }
-
-        if (qemuMonitorTransactionBitmapRemove(actions,
-                                               domdisk->src->nodeformat,
-                                               chkdisk->bitmap) < 0)
+        if (qemuCheckpointDiscardDiskBitmaps(domdisk->src, chkdisk->bitmap,
+                                             parentbitmap, chkcurrent, actions) < 0)
             return -1;
     }
 
diff --git a/src/qemu/qemu_checkpoint.h b/src/qemu/qemu_checkpoint.h
index eb85611ea6..85fd453d50 100644
--- a/src/qemu/qemu_checkpoint.h
+++ b/src/qemu/qemu_checkpoint.h
@@ -71,3 +71,10 @@ qemuCheckpointCreateFinalize(virQEMUDriverPtr driver,
 void
 qemuCheckpointRollbackMetadata(virDomainObjPtr vm,
                                virDomainMomentObjPtr chk);
+
+int
+qemuCheckpointDiscardDiskBitmaps(virStorageSourcePtr src,
+                                 const char *delbitmap,
+                                 const char *parentbitmap,
+                                 bool chkcurrent,
+                                 virJSONValuePtr actions);
-- 
2.25.0