diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index 4402c52461..6100b88e99 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -2755,6 +2755,11 @@ paravirtualized driver is specified via the ``disk`` element. ``format`` The ``format`` element contains ``type`` attribute which specifies the internal format of the backing store, such as ``raw`` or ``qcow2``. + + The ``format`` element can contain ``metadata_cache`` subelement, which + has identical semantics to the identically named subelement of ``driver`` + of a ``disk``. + ``source`` This element has the same structure as the ``source`` element in ``disk``. It specifies which file, device, or network location contains the data of @@ -2967,6 +2972,44 @@ paravirtualized driver is specified via the ``disk`` element. virtio-blk. ( :since:`Since 3.9.0` ) - For virtio disks, `Virtio-specific options <#elementsVirtio>`__ can also be set. ( :since:`Since 3.5.0` ) + - The optional ``metadata_cache`` subelement controls aspects related to the + format specific caching of storage image metadata. Note that this setting + applies only on the top level image; the identically named subelement of + ``backingStore``'s ``format`` element can be used to specify cache + settings for the backing image. + + :since:`Since 7.0.0` the maximum size of the metadata cache of ``qcow2`` + format driver of the ``qemu`` hypervisor can be controlled via the + ``max_size`` subelement (see example below). + + In the majority of cases the default configuration used by the hypervisor + is sufficient so modifying this setting should not be necessary. For + specifics on how the metadata cache of ``qcow2`` in ``qemu`` behaves refer + to the ``qemu`` + `qcow2 cache docs `__ + + **Example:** + +:: + + + + + 1234 + + + + + + + 1234 + + + + + + + ``backenddomain`` The optional ``backenddomain`` element allows specifying a backend domain diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 3480edd946..7dc419bcc3 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -1590,7 +1590,15 @@ - + + + + + + + + + @@ -2267,7 +2275,15 @@ - + + + + + + + + + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index ba213da886..472ce79e67 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -8609,6 +8609,12 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt, if (!(backingStore = virDomainStorageSourceParseBase(type, format, idx))) return -1; + if (virParseScaledValue("./format/metadata_cache/max_size", NULL, + ctxt, + &backingStore->metadataCacheMaxSize, + 1, ULLONG_MAX, false) < 0) + return -1; + /* backing store is always read-only */ backingStore->readonly = true; @@ -8959,9 +8965,13 @@ virDomainDiskDefParseValidate(const virDomainDiskDef *def) static int virDomainDiskDefDriverParseXML(virDomainDiskDefPtr def, - xmlNodePtr cur) + xmlNodePtr cur, + xmlXPathContextPtr ctxt) { g_autofree char *tmp = NULL; + VIR_XPATH_NODE_AUTORESTORE(ctxt) + + ctxt->node = cur; def->driverName = virXMLPropString(cur, "name"); @@ -9071,6 +9081,12 @@ virDomainDiskDefDriverParseXML(virDomainDiskDefPtr def, return -1; } + if (virParseScaledValue("./metadata_cache/max_size", NULL, + ctxt, + &def->src->metadataCacheMaxSize, + 1, ULLONG_MAX, false) < 0) + return -1; + return 0; } @@ -9227,7 +9243,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, if (virDomainVirtioOptionsParseXML(cur, &def->virtio) < 0) return NULL; - if (virDomainDiskDefDriverParseXML(def, cur) < 0) + if (virDomainDiskDefDriverParseXML(def, cur, ctxt) < 0) return NULL; } else if (!def->mirror && virXMLNodeNameEqual(cur, "mirror") && @@ -24081,6 +24097,8 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf, { g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER; g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf); + g_auto(virBuffer) formatAttrBuf = VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) formatChildBuf = VIR_BUFFER_INIT_CHILD(&childBuf); bool inactive = flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE; virStorageSourcePtr backingStore = src->backingStore; @@ -24108,8 +24126,22 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf, if (backingStore->id != 0) virBufferAsprintf(&attrBuf, " index='%u'", backingStore->id); - virBufferAsprintf(&childBuf, "\n", + virBufferAsprintf(&formatAttrBuf, " type='%s'", virStorageFileFormatTypeToString(backingStore->format)); + + if (backingStore->metadataCacheMaxSize > 0) { + g_auto(virBuffer) metadataCacheChildBuf = VIR_BUFFER_INIT_CHILD(&formatChildBuf); + + virBufferAsprintf(&metadataCacheChildBuf, + "%llu\n", + backingStore->metadataCacheMaxSize); + + virXMLFormatElement(&formatChildBuf, "metadata_cache", NULL, &metadataCacheChildBuf); + } + + virXMLFormatElement(&childBuf, "format", &formatAttrBuf, &formatChildBuf); + + if (virDomainDiskSourceFormat(&childBuf, backingStore, "source", 0, false, flags, false, false, xmlopt) < 0) return -1; @@ -24177,6 +24209,7 @@ virDomainDiskDefFormatDriver(virBufferPtr buf, virDomainDiskDefPtr disk) { g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf); virBufferEscapeString(&attrBuf, " name='%s'", virDomainDiskGetDriver(disk)); @@ -24228,7 +24261,17 @@ virDomainDiskDefFormatDriver(virBufferPtr buf, virDomainVirtioOptionsFormat(&attrBuf, disk->virtio); - virXMLFormatElement(buf, "driver", &attrBuf, NULL); + if (disk->src->metadataCacheMaxSize > 0) { + g_auto(virBuffer) metadataCacheChildBuf = VIR_BUFFER_INIT_CHILD(&childBuf); + + virBufferAsprintf(&metadataCacheChildBuf, + "%llu\n", + disk->src->metadataCacheMaxSize); + + virXMLFormatElement(&childBuf, "metadata_cache", NULL, &metadataCacheChildBuf); + } + + virXMLFormatElement(buf, "driver", &attrBuf, &childBuf); } diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index d67f0f2c3f..0d3c2af94f 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -2217,6 +2217,7 @@ virStorageSourceCopy(const virStorageSource *src, def->sslverify = src->sslverify; def->readahead = src->readahead; def->timeout = src->timeout; + def->metadataCacheMaxSize = src->metadataCacheMaxSize; /* storage driver metadata are not copied */ def->drv = NULL; diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index 47d901a478..5689c39092 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -322,6 +322,8 @@ struct _virStorageSource { unsigned long long clusterSize; /* in bytes, 0 if unknown */ bool has_allocation; /* Set to true when provided in XML */ + unsigned long long metadataCacheMaxSize; /* size of the metadata cache in bytes */ + size_t nseclabels; virSecurityDeviceLabelDefPtr *seclabels; diff --git a/tests/qemuxml2argvdata/disk-metadata-cache.xml b/tests/qemuxml2argvdata/disk-metadata-cache.xml new file mode 100644 index 0000000000..d79f194eee --- /dev/null +++ b/tests/qemuxml2argvdata/disk-metadata-cache.xml @@ -0,0 +1,46 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219100 + 219100 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-i386 + + + + 12345 + + + + +
+ + + + + + + + 1024 + + + + + + +
+ + + + + + diff --git a/tests/qemuxml2xmloutdata/disk-metadata-cache.x86_64-latest.xml b/tests/qemuxml2xmloutdata/disk-metadata-cache.x86_64-latest.xml new file mode 100644 index 0000000000..7104151a10 --- /dev/null +++ b/tests/qemuxml2xmloutdata/disk-metadata-cache.x86_64-latest.xml @@ -0,0 +1,58 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219100 + 219100 + 1 + + hvm + + + + qemu64 + + + destroy + restart + destroy + + /usr/bin/qemu-system-i386 + + + + 12345 + + + + +
+ + + + + + + + 1048576 + + + + + + +
+ + +
+ + +
+ + + + + +
+ + + diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index b8651901ce..ed8e22bdb1 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -294,6 +294,7 @@ mymain(void) DO_TEST_CAPS_VER("disk-cache", "2.7.0"); DO_TEST_CAPS_VER("disk-cache", "2.12.0"); DO_TEST_CAPS_LATEST("disk-cache"); + DO_TEST_CAPS_LATEST("disk-metadata-cache"); DO_TEST("disk-network-nbd", NONE); DO_TEST("disk-network-iscsi", QEMU_CAPS_VIRTIO_SCSI, QEMU_CAPS_SCSI_BLOCK);