render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
d76c62
From 7322bb9f51c7c2c35d2e65734e03ff0056b5af22 Mon Sep 17 00:00:00 2001
d76c62
Message-Id: <7322bb9f51c7c2c35d2e65734e03ff0056b5af22@dist-git>
d76c62
From: Peter Krempa <pkrempa@redhat.com>
d76c62
Date: Mon, 16 Mar 2020 22:12:22 +0100
d76c62
Subject: [PATCH] qemu: blockjob: Store list of bitmaps disabled prior to
d76c62
 commit
d76c62
MIME-Version: 1.0
d76c62
Content-Type: text/plain; charset=UTF-8
d76c62
Content-Transfer-Encoding: 8bit
d76c62
d76c62
Starting a commit job will require disabling bitmaps in the base image
d76c62
so that they are not dirtied by the commit job. We need to store a list
d76c62
of the bitmaps so that we can later re-enable them.
d76c62
d76c62
Add a field and status XML handling code as well as a test.
d76c62
d76c62
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
d76c62
Reviewed-by: Eric Blake <eblake@redhat.com>
d76c62
(cherry picked from commit 41de7230ab169e80237f3e3a29bfecd9baf1a578)
d76c62
https://bugzilla.redhat.com/show_bug.cgi?id=1799013
d76c62
Message-Id: <f009cdda8b29df504d19bddffea5638913f8c931.1584391727.git.pkrempa@redhat.com>
d76c62
Reviewed-by: Ján Tomko <jtomko@redhat.com>
d76c62
---
d76c62
 src/qemu/qemu_blockjob.h                      |  2 ++
d76c62
 src/qemu/qemu_domain.c                        | 26 +++++++++++++++++++
d76c62
 .../blockjob-blockdev-in.xml                  |  4 +++
d76c62
 3 files changed, 32 insertions(+)
d76c62
d76c62
diff --git a/src/qemu/qemu_blockjob.h b/src/qemu/qemu_blockjob.h
d76c62
index 4045878568..c1d95ea3d8 100644
d76c62
--- a/src/qemu/qemu_blockjob.h
d76c62
+++ b/src/qemu/qemu_blockjob.h
d76c62
@@ -88,6 +88,8 @@ struct _qemuBlockJobCommitData {
d76c62
     virStorageSourcePtr top;
d76c62
     virStorageSourcePtr base;
d76c62
     bool deleteCommittedImages;
d76c62
+    char **disabledBitmapsBase; /* a NULL-terminated list of bitmap names which
d76c62
+                                   were disabled in @base for the commit job */
d76c62
 };
d76c62
 
d76c62
 
d76c62
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
d76c62
index 0faf042145..a273aefa6b 100644
d76c62
--- a/src/qemu/qemu_domain.c
d76c62
+++ b/src/qemu/qemu_domain.c
d76c62
@@ -2603,6 +2603,9 @@ static void
d76c62
 qemuDomainPrivateBlockJobFormatCommit(qemuBlockJobDataPtr job,
d76c62
                                       virBufferPtr buf)
d76c62
 {
d76c62
+    g_auto(virBuffer) disabledBitmapsBuf = VIR_BUFFER_INIT_CHILD(buf);
d76c62
+    char **bitmaps = job->data.commit.disabledBitmapsBase;
d76c62
+
d76c62
     if (job->data.commit.base)
d76c62
         virBufferAsprintf(buf, "<base node='%s'/>\n", job->data.commit.base->nodeformat);
d76c62
 
d76c62
@@ -2614,6 +2617,11 @@ qemuDomainPrivateBlockJobFormatCommit(qemuBlockJobDataPtr job,
d76c62
 
d76c62
     if (job->data.commit.deleteCommittedImages)
d76c62
         virBufferAddLit(buf, "<deleteCommittedImages/>\n");
d76c62
+
d76c62
+    while (bitmaps && *bitmaps)
d76c62
+        virBufferEscapeString(&disabledBitmapsBuf, "<bitmap name='%s'/>\n", *(bitmaps++));
d76c62
+
d76c62
+    virXMLFormatElement(buf, "disabledBaseBitmaps", NULL, &disabledBitmapsBuf);
d76c62
 }
d76c62
 
d76c62
 
d76c62
@@ -3240,6 +3248,9 @@ static int
d76c62
 qemuDomainObjPrivateXMLParseBlockjobDataCommit(qemuBlockJobDataPtr job,
d76c62
                                                xmlXPathContextPtr ctxt)
d76c62
 {
d76c62
+    g_autofree xmlNodePtr *nodes = NULL;
d76c62
+    ssize_t nnodes;
d76c62
+
d76c62
     if (job->type == QEMU_BLOCKJOB_TYPE_COMMIT) {
d76c62
         qemuDomainObjPrivateXMLParseBlockjobNodename(job,
d76c62
                                                      "string(./topparent/@node)",
d76c62
@@ -3266,6 +3277,21 @@ qemuDomainObjPrivateXMLParseBlockjobDataCommit(qemuBlockJobDataPtr job,
d76c62
         !job->data.commit.base)
d76c62
         return -1;
d76c62
 
d76c62
+    if ((nnodes = virXPathNodeSet("./disabledBaseBitmaps/bitmap", ctxt, &nodes)) > 0) {
d76c62
+        size_t i;
d76c62
+
d76c62
+        job->data.commit.disabledBitmapsBase = g_new0(char *, nnodes + 1);
d76c62
+
d76c62
+        for (i = 0; i < nnodes; i++) {
d76c62
+            char *tmp;
d76c62
+
d76c62
+            if (!(tmp = virXMLPropString(nodes[i], "name")))
d76c62
+                return -1;
d76c62
+
d76c62
+            job->data.commit.disabledBitmapsBase[i] = g_steal_pointer(&tmp);
d76c62
+        }
d76c62
+    }
d76c62
+
d76c62
     return 0;
d76c62
 }
d76c62
 
d76c62
diff --git a/tests/qemustatusxml2xmldata/blockjob-blockdev-in.xml b/tests/qemustatusxml2xmldata/blockjob-blockdev-in.xml
d76c62
index ca6d110179..cc17a17ff4 100644
d76c62
--- a/tests/qemustatusxml2xmldata/blockjob-blockdev-in.xml
d76c62
+++ b/tests/qemustatusxml2xmldata/blockjob-blockdev-in.xml
d76c62
@@ -243,6 +243,10 @@
d76c62
       <base node='libvirt-19-format'/>
d76c62
       <top node='libvirt-17-format'/>
d76c62
       <deleteCommittedImages/>
d76c62
+      <disabledBaseBitmaps>
d76c62
+        <bitmap name='test'/>
d76c62
+        <bitmap name='test1'/>
d76c62
+      </disabledBaseBitmaps>
d76c62
     </blockjob>
d76c62
     <blockjob name='create-libvirt-1337-storage' type='create' state='running'>
d76c62
       <create mode='storage'/>
d76c62
-- 
d76c62
2.25.1
d76c62