]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: snapshot: Add support for <metadata_cache>
authorPeter Krempa <pkrempa@redhat.com>
Thu, 7 Jan 2021 14:30:21 +0000 (15:30 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 8 Jan 2021 14:27:00 +0000 (15:27 +0100)
Similarly to the domain config code it may be beneficial to control the
cache size of images introduced as snapshots into the backing chain.
Wire up handling of the 'metadata_cache' element.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
docs/formatsnapshot.html.in
docs/schemas/domainsnapshot.rng
src/conf/snapshot_conf.c
tests/qemudomainsnapshotxml2xmlin/qcow2-metadata-cache.xml [new file with mode: 0644]
tests/qemudomainsnapshotxml2xmlout/qcow2-metadata-cache.xml [new file with mode: 0644]
tests/qemudomainsnapshotxml2xmltest.c

index d640deb86d82c8a90a345e3e1687e4a90a9d6aa9..e481284aa8839257a54de0b200065b3a29352c75 100644 (file)
               with an attribute <code>type</code> giving the driver type (such
               as qcow2), of the new file created by the external
               snapshot of the new file.
+
+              Optionally <code>metadata_cache</code> sub-element can be used
+              with same semantics as the identically named subelement of the
+              domain definition disk's driver.
               </dd>
               <dt><code>seclabel</code></dt>
             </dl>
index e1fb4f7cea776602b11d10281606c7533a13fa42..58c370878da6ef82c4e7cdb92da43217e7d141d0 100644 (file)
             <ref name="storageFormatBacking"/>
           </attribute>
         </optional>
-        <empty/>
+        <optional>
+          <element name="metadata_cache">
+            <optional>
+              <element name="max_size">
+                <ref name="scaledInteger"/>
+              </element>
+            </optional>
+          </element>
+        </optional>
       </element>
     </optional>
   </define>
index 757af681cd872396887442d04612259abc563428..673282be7a74d30682b5746f7d32984d125926dc 100644 (file)
@@ -190,6 +190,12 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node,
             goto cleanup;
     }
 
+    if (virParseScaledValue("./driver/metadata_cache/max_size", NULL,
+                            ctxt,
+                            &def->src->metadataCacheMaxSize,
+                            1, ULLONG_MAX, false) < 0)
+        goto cleanup;
+
     /* validate that the passed path is absolute */
     if (virStorageSourceIsRelative(def->src)) {
         virReportError(VIR_ERR_XML_ERROR,
@@ -784,12 +790,27 @@ virDomainSnapshotDiskDefFormat(virBufferPtr buf,
                           virDomainSnapshotLocationTypeToString(disk->snapshot));
 
     if (disk->src->path || disk->src->format != 0) {
+        g_auto(virBuffer) driverAttrBuf = VIR_BUFFER_INITIALIZER;
+        g_auto(virBuffer) driverChildBuf = VIR_BUFFER_INIT_CHILD(&childBuf);
+
         virBufferAsprintf(&attrBuf, " type='%s'", virStorageTypeToString(disk->src->type));
 
         if (disk->src->format > 0)
-            virBufferEscapeString(&childBuf, "<driver type='%s'/>\n",
+            virBufferEscapeString(&driverAttrBuf, " type='%s'",
                                   virStorageFileFormatTypeToString(disk->src->format));
 
+        if (disk->src->metadataCacheMaxSize > 0) {
+            g_auto(virBuffer) metadataCacheChildBuf = VIR_BUFFER_INIT_CHILD(&driverChildBuf);
+
+            virBufferAsprintf(&metadataCacheChildBuf,
+                              "<max_size unit='bytes'>%llu</max_size>\n",
+                              disk->src->metadataCacheMaxSize);
+
+            virXMLFormatElement(&driverChildBuf, "metadata_cache", NULL, &metadataCacheChildBuf);
+        }
+
+        virXMLFormatElement(&childBuf, "driver", &driverAttrBuf, &driverChildBuf);
+
         if (virDomainDiskSourceFormat(&childBuf, disk->src, "source", 0, false, 0,
                                       false, false, xmlopt) < 0)
         return -1;
diff --git a/tests/qemudomainsnapshotxml2xmlin/qcow2-metadata-cache.xml b/tests/qemudomainsnapshotxml2xmlin/qcow2-metadata-cache.xml
new file mode 100644 (file)
index 0000000..92440aa
--- /dev/null
@@ -0,0 +1,14 @@
+<domainsnapshot>
+  <name>my snap name</name>
+  <description>!@#$%^</description>
+  <disks>
+    <disk name='hdd' snapshot='external'>
+      <source file='/path/to/new'/>
+      <driver type='qcow2'>
+        <metadata_cache>
+          <max_size unit='bytes'>1234</max_size>
+          </metadata_cache>
+      </driver>
+    </disk>
+  </disks>
+</domainsnapshot>
diff --git a/tests/qemudomainsnapshotxml2xmlout/qcow2-metadata-cache.xml b/tests/qemudomainsnapshotxml2xmlout/qcow2-metadata-cache.xml
new file mode 100644 (file)
index 0000000..def2a8f
--- /dev/null
@@ -0,0 +1,18 @@
+<domainsnapshot>
+  <name>my snap name</name>
+  <description>!@#$%^</description>
+  <creationTime>1386166249</creationTime>
+  <disks>
+    <disk name='hdd' snapshot='external' type='file'>
+      <driver type='qcow2'>
+        <metadata_cache>
+          <max_size unit='bytes'>1234</max_size>
+        </metadata_cache>
+      </driver>
+      <source file='/path/to/new'/>
+    </disk>
+  </disks>
+  <domain>
+    <uuid>9d37b878-a7cc-9f9a-b78f-49b3abad25a8</uuid>
+  </domain>
+</domainsnapshot>
index 4b92967339f62574c0656edd856acd935f9d82d8..2a1fe1f52dfe332e4eaf28d35cc990fc4e945683 100644 (file)
@@ -181,6 +181,9 @@ mymain(void)
     DO_TEST_IN("description_only", NULL);
     DO_TEST_IN("name_only", NULL);
 
+    DO_TEST_INOUT("qcow2-metadata-cache", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8",
+                  1386166249, 0);
+
     qemuTestDriverFree(&driver);
 
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;