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@xxxxxxxxxx> --- docs/formatsnapshot.html.in | 4 ++++ docs/schemas/domainsnapshot.rng | 10 +++++++- src/conf/snapshot_conf.c | 23 ++++++++++++++++++- .../qcow2-metadata-cache.xml | 14 +++++++++++ .../qcow2-metadata-cache.xml | 18 +++++++++++++++ tests/qemudomainsnapshotxml2xmltest.c | 3 +++ 6 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 tests/qemudomainsnapshotxml2xmlin/qcow2-metadata-cache.xml create mode 100644 tests/qemudomainsnapshotxml2xmlout/qcow2-metadata-cache.xml diff --git a/docs/formatsnapshot.html.in b/docs/formatsnapshot.html.in index d640deb86d..e481284aa8 100644 --- a/docs/formatsnapshot.html.in +++ b/docs/formatsnapshot.html.in @@ -186,6 +186,10 @@ 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> diff --git a/docs/schemas/domainsnapshot.rng b/docs/schemas/domainsnapshot.rng index e1fb4f7cea..58c370878d 100644 --- a/docs/schemas/domainsnapshot.rng +++ b/docs/schemas/domainsnapshot.rng @@ -212,7 +212,15 @@ <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> diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index 757af681cd..673282be7a 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -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 index 0000000000..92440aa0ae --- /dev/null +++ b/tests/qemudomainsnapshotxml2xmlin/qcow2-metadata-cache.xml @@ -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 index 0000000000..def2a8ffce --- /dev/null +++ b/tests/qemudomainsnapshotxml2xmlout/qcow2-metadata-cache.xml @@ -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> diff --git a/tests/qemudomainsnapshotxml2xmltest.c b/tests/qemudomainsnapshotxml2xmltest.c index 4b92967339..2a1fe1f52d 100644 --- a/tests/qemudomainsnapshotxml2xmltest.c +++ b/tests/qemudomainsnapshotxml2xmltest.c @@ -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; -- 2.29.2