render / rpms / libvirt

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