render / rpms / libvirt

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