d76c62
From 628b1f392c5fb2e3a492640a9069edd244a7b150 Mon Sep 17 00:00:00 2001
d76c62
Message-Id: <628b1f392c5fb2e3a492640a9069edd244a7b150@dist-git>
d76c62
From: Peter Krempa <pkrempa@redhat.com>
d76c62
Date: Tue, 4 Feb 2020 15:07:50 +0100
d76c62
Subject: [PATCH] qemu: checkpoint: split out checkpoint deletion bitmaps
d76c62
MIME-Version: 1.0
d76c62
Content-Type: text/plain; charset=UTF-8
d76c62
Content-Transfer-Encoding: 8bit
d76c62
d76c62
qemuCheckpointDiscard is a massive function that can be separated into
d76c62
smaller bits. Extract the part that actually modifies the disk from the
d76c62
metadata handling.
d76c62
d76c62
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
d76c62
Reviewed-by: Eric Blake <eblake@redhat.com>
d76c62
(cherry picked from commit 44e1b85717b9a4e6df24f9cbf846627e4f29b859)
d76c62
d76c62
https://bugzilla.redhat.com/show_bug.cgi?id=1207659
d76c62
Message-Id: <b6cdc7883d1f3b16e8a496dac6e9ec046ec2c4ea.1580824112.git.pkrempa@redhat.com>
d76c62
Reviewed-by: Ján Tomko <jtomko@redhat.com>
d76c62
---
d76c62
 src/qemu/qemu_checkpoint.c | 137 ++++++++++++++++++++-----------------
d76c62
 1 file changed, 76 insertions(+), 61 deletions(-)
d76c62
d76c62
diff --git a/src/qemu/qemu_checkpoint.c b/src/qemu/qemu_checkpoint.c
d76c62
index d13d4c2a37..9ff3129570 100644
d76c62
--- a/src/qemu/qemu_checkpoint.c
d76c62
+++ b/src/qemu/qemu_checkpoint.c
d76c62
@@ -104,6 +104,81 @@ qemuCheckpointWriteMetadata(virDomainObjPtr vm,
d76c62
 }
d76c62
 
d76c62
 
d76c62
+static int
d76c62
+qemuCheckpointDiscardBitmaps(virDomainObjPtr vm,
d76c62
+                             virDomainCheckpointDefPtr chkdef,
d76c62
+                             bool chkcurrent,
d76c62
+                             virDomainMomentObjPtr parent)
d76c62
+{
d76c62
+    qemuDomainObjPrivatePtr priv = vm->privateData;
d76c62
+    virQEMUDriverPtr driver = priv->driver;
d76c62
+    virDomainMomentObjPtr moment;
d76c62
+    virDomainCheckpointDefPtr parentdef = NULL;
d76c62
+    bool search_parents;
d76c62
+    int rc;
d76c62
+    g_autoptr(virJSONValue) actions = NULL;
d76c62
+    size_t i;
d76c62
+    size_t j;
d76c62
+
d76c62
+    if (!(actions = virJSONValueNewArray()))
d76c62
+        return -1;
d76c62
+
d76c62
+    for (i = 0; i < chkdef->ndisks; i++) {
d76c62
+        virDomainCheckpointDiskDef *disk = &chkdef->disks[i];
d76c62
+        const char *node;
d76c62
+
d76c62
+        if (disk->type != VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP)
d76c62
+            continue;
d76c62
+
d76c62
+        node = qemuDomainDiskNodeFormatLookup(vm, disk->name);
d76c62
+        /* If any ancestor checkpoint has a bitmap for the same
d76c62
+         * disk, then this bitmap must be merged to the
d76c62
+         * ancestor. */
d76c62
+        search_parents = true;
d76c62
+        for (moment = parent;
d76c62
+             search_parents && moment;
d76c62
+             moment = virDomainCheckpointFindByName(vm->checkpoints,
d76c62
+                                                    parentdef->parent.parent_name)) {
d76c62
+            parentdef = virDomainCheckpointObjGetDef(moment);
d76c62
+            for (j = 0; j < parentdef->ndisks; j++) {
d76c62
+                virDomainCheckpointDiskDef *disk2;
d76c62
+                g_autoptr(virJSONValue) arr = NULL;
d76c62
+
d76c62
+                disk2 = &parentdef->disks[j];
d76c62
+                if (STRNEQ(disk->name, disk2->name) ||
d76c62
+                    disk2->type != VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP)
d76c62
+                    continue;
d76c62
+                search_parents = false;
d76c62
+
d76c62
+                if (!(arr = virJSONValueNewArray()))
d76c62
+                    return -1;
d76c62
+
d76c62
+                if (qemuMonitorTransactionBitmapMergeSourceAddBitmap(arr, node, disk->bitmap) < 0)
d76c62
+                    return -1;
d76c62
+
d76c62
+                if (chkcurrent) {
d76c62
+                    if (qemuMonitorTransactionBitmapEnable(actions, node, disk2->bitmap) < 0)
d76c62
+                        return -1;
d76c62
+                }
d76c62
+
d76c62
+                if (qemuMonitorTransactionBitmapMerge(actions, node, disk2->bitmap, &arr) < 0)
d76c62
+                    return -1;
d76c62
+            }
d76c62
+        }
d76c62
+
d76c62
+        if (qemuMonitorTransactionBitmapRemove(actions, node, disk->bitmap) < 0)
d76c62
+            return -1;
d76c62
+    }
d76c62
+
d76c62
+    qemuDomainObjEnterMonitor(driver, vm);
d76c62
+    rc = qemuMonitorTransaction(priv->mon, &actions);
d76c62
+    if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0)
d76c62
+        return -1;
d76c62
+
d76c62
+    return 0;
d76c62
+}
d76c62
+
d76c62
+
d76c62
 static int
d76c62
 qemuCheckpointDiscard(virQEMUDriverPtr driver,
d76c62
                       virDomainObjPtr vm,
d76c62
@@ -112,9 +187,6 @@ qemuCheckpointDiscard(virQEMUDriverPtr driver,
d76c62
                       bool metadata_only)
d76c62
 {
d76c62
     virDomainMomentObjPtr parent = NULL;
d76c62
-    virDomainMomentObjPtr moment;
d76c62
-    virDomainCheckpointDefPtr parentdef = NULL;
d76c62
-    size_t i, j;
d76c62
     g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
d76c62
     g_autofree char *chkFile = NULL;
d76c62
     bool chkcurrent = chk == virDomainCheckpointGetCurrent(vm->checkpoints);
d76c62
@@ -129,67 +201,10 @@ qemuCheckpointDiscard(virQEMUDriverPtr driver,
d76c62
                               chk->def->name);
d76c62
 
d76c62
     if (!metadata_only) {
d76c62
-        qemuDomainObjPrivatePtr priv = vm->privateData;
d76c62
-        bool search_parents;
d76c62
         virDomainCheckpointDefPtr chkdef = virDomainCheckpointObjGetDef(chk);
d76c62
-        int rc;
d76c62
-        g_autoptr(virJSONValue) actions = NULL;
d76c62
-
d76c62
-        if (!(actions = virJSONValueNewArray()))
d76c62
-            return -1;
d76c62
-
d76c62
         parent = virDomainCheckpointFindByName(vm->checkpoints,
d76c62
                                                chk->def->parent_name);
d76c62
-        for (i = 0; i < chkdef->ndisks; i++) {
d76c62
-            virDomainCheckpointDiskDef *disk = &chkdef->disks[i];
d76c62
-            const char *node;
d76c62
-
d76c62
-            if (disk->type != VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP)
d76c62
-                continue;
d76c62
-
d76c62
-            node = qemuDomainDiskNodeFormatLookup(vm, disk->name);
d76c62
-            /* If any ancestor checkpoint has a bitmap for the same
d76c62
-             * disk, then this bitmap must be merged to the
d76c62
-             * ancestor. */
d76c62
-            search_parents = true;
d76c62
-            for (moment = parent;
d76c62
-                 search_parents && moment;
d76c62
-                 moment = virDomainCheckpointFindByName(vm->checkpoints,
d76c62
-                                                        parentdef->parent.parent_name)) {
d76c62
-                parentdef = virDomainCheckpointObjGetDef(moment);
d76c62
-                for (j = 0; j < parentdef->ndisks; j++) {
d76c62
-                    virDomainCheckpointDiskDef *disk2;
d76c62
-                    g_autoptr(virJSONValue) arr = NULL;
d76c62
-
d76c62
-                    disk2 = &parentdef->disks[j];
d76c62
-                    if (STRNEQ(disk->name, disk2->name) ||
d76c62
-                        disk2->type != VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP)
d76c62
-                        continue;
d76c62
-                    search_parents = false;
d76c62
-
d76c62
-                    if (!(arr = virJSONValueNewArray()))
d76c62
-                        return -1;
d76c62
-
d76c62
-                    if (qemuMonitorTransactionBitmapMergeSourceAddBitmap(arr, node, disk->bitmap) < 0)
d76c62
-                        return -1;
d76c62
-
d76c62
-                    if (chkcurrent) {
d76c62
-                        if (qemuMonitorTransactionBitmapEnable(actions, node, disk2->bitmap) < 0)
d76c62
-                            return -1;
d76c62
-                    }
d76c62
-
d76c62
-                    if (qemuMonitorTransactionBitmapMerge(actions, node, disk2->bitmap, &arr) < 0)
d76c62
-                        return -1;
d76c62
-                }
d76c62
-            }
d76c62
-
d76c62
-            if (qemuMonitorTransactionBitmapRemove(actions, node, disk->bitmap) < 0)
d76c62
-                return -1;
d76c62
-        }
d76c62
-
d76c62
-        qemuDomainObjEnterMonitor(driver, vm);
d76c62
-        rc = qemuMonitorTransaction(priv->mon, &actions);
d76c62
-        if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0)
d76c62
+        if (qemuCheckpointDiscardBitmaps(vm, chkdef, chkcurrent, parent) < 0)
d76c62
             return -1;
d76c62
     }
d76c62
 
d76c62
-- 
d76c62
2.25.0
d76c62