]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: blockjob: Store list of bitmaps disabled prior to commit
authorPeter Krempa <pkrempa@redhat.com>
Tue, 25 Feb 2020 06:28:44 +0000 (07:28 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 16 Mar 2020 16:33:08 +0000 (17:33 +0100)
Starting a commit job will require disabling bitmaps in the base image
so that they are not dirtied by the commit job. We need to store a list
of the bitmaps so that we can later re-enable them.

Add a field and status XML handling code as well as a test.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
src/qemu/qemu_blockjob.h
src/qemu/qemu_domain.c
tests/qemustatusxml2xmldata/blockjob-blockdev-in.xml

index 72c7fa053e8b4f25d5fd30705ba50f8f99acfed5..e2e28ca4d37905356932032b22784ae042498b5d 100644 (file)
@@ -88,6 +88,8 @@ struct _qemuBlockJobCommitData {
     virStorageSourcePtr top;
     virStorageSourcePtr base;
     bool deleteCommittedImages;
+    char **disabledBitmapsBase; /* a NULL-terminated list of bitmap names which
+                                   were disabled in @base for the commit job */
 };
 
 
index e4aa25c34344041b314c89b78771f663e9f9b105..edc8ba2ddb7672043bbbcba62fc85936a4f1b6a4 100644 (file)
@@ -2611,6 +2611,9 @@ static void
 qemuDomainPrivateBlockJobFormatCommit(qemuBlockJobDataPtr job,
                                       virBufferPtr buf)
 {
+    g_auto(virBuffer) disabledBitmapsBuf = VIR_BUFFER_INIT_CHILD(buf);
+    char **bitmaps = job->data.commit.disabledBitmapsBase;
+
     if (job->data.commit.base)
         virBufferAsprintf(buf, "<base node='%s'/>\n", job->data.commit.base->nodeformat);
 
@@ -2622,6 +2625,11 @@ qemuDomainPrivateBlockJobFormatCommit(qemuBlockJobDataPtr job,
 
     if (job->data.commit.deleteCommittedImages)
         virBufferAddLit(buf, "<deleteCommittedImages/>\n");
+
+    while (bitmaps && *bitmaps)
+        virBufferEscapeString(&disabledBitmapsBuf, "<bitmap name='%s'/>\n", *(bitmaps++));
+
+    virXMLFormatElement(buf, "disabledBaseBitmaps", NULL, &disabledBitmapsBuf);
 }
 
 
@@ -3234,6 +3242,9 @@ static int
 qemuDomainObjPrivateXMLParseBlockjobDataCommit(qemuBlockJobDataPtr job,
                                                xmlXPathContextPtr ctxt)
 {
+    g_autofree xmlNodePtr *nodes = NULL;
+    ssize_t nnodes;
+
     if (job->type == QEMU_BLOCKJOB_TYPE_COMMIT) {
         qemuDomainObjPrivateXMLParseBlockjobNodename(job,
                                                      "string(./topparent/@node)",
@@ -3260,6 +3271,21 @@ qemuDomainObjPrivateXMLParseBlockjobDataCommit(qemuBlockJobDataPtr job,
         !job->data.commit.base)
         return -1;
 
+    if ((nnodes = virXPathNodeSet("./disabledBaseBitmaps/bitmap", ctxt, &nodes)) > 0) {
+        size_t i;
+
+        job->data.commit.disabledBitmapsBase = g_new0(char *, nnodes + 1);
+
+        for (i = 0; i < nnodes; i++) {
+            char *tmp;
+
+            if (!(tmp = virXMLPropString(nodes[i], "name")))
+                return -1;
+
+            job->data.commit.disabledBitmapsBase[i] = g_steal_pointer(&tmp);
+        }
+    }
+
     return 0;
 }
 
index ca6d1101797eb15679b5426ac9a5063c88cf07f9..cc17a17ff4ddc9288ce1b9ff831efe7e5e05a7d1 100644 (file)
       <base node='libvirt-19-format'/>
       <top node='libvirt-17-format'/>
       <deleteCommittedImages/>
+      <disabledBaseBitmaps>
+        <bitmap name='test'/>
+        <bitmap name='test1'/>
+      </disabledBaseBitmaps>
     </blockjob>
     <blockjob name='create-libvirt-1337-storage' type='create' state='running'>
       <create mode='storage'/>