From: Peter Krempa <pkrempa@redhat.com> QEMU supports collection of disk statistics in configurable time windows. Add support for enabling this feature to the conf parser. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- docs/formatdomain.rst | 17 ++++++++++++++++ src/conf/domain_conf.c | 34 +++++++++++++++++++++++++++++++ src/conf/domain_conf.h | 2 ++ src/conf/schemas/domaincommon.rng | 11 ++++++++++ 4 files changed, 64 insertions(+) diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index f50dce477f..f46a21463f 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -3588,6 +3588,23 @@ paravirtualized driver is specified via the ``disk`` element. </iothreads> </driver> + - The optional ``statistics`` sub-element allows configuring statistics + collection in configurable intervals for the given disk. Intervals are + configured by ``<statistic>`` sub-elements with ``interval`` attribute + configuring the collection window duration in seconds. The statistics + are available via the bulk statistics API. + + Example:: + + <driver name='qemu'> + <statistics> + <statistic interval='1'/> + <statistic interval='10'/> + </statistics> + </driver> + + :since:`Since 11.9.0 (QEMU 10.2, virtio, ide, scsi disks only)`. + - The optional ``queues`` attribute specifies the number of virt queues for virtio-blk ( :since:`Since 3.9.0` ) or vhost-user-blk ( :since:`Since 7.1.0` ) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 281846dfbe..b6832d193a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -8288,6 +8288,8 @@ static int virDomainDiskDefDriverParseXML(virDomainDiskDef *def, xmlNodePtr cur) { + xmlNodePtr statisticsNode; + def->driverName = virXMLPropString(cur, "name"); if (virXMLPropEnum(cur, "cache", virDomainDiskCacheTypeFromString, @@ -8337,6 +8339,26 @@ virDomainDiskDefDriverParseXML(virDomainDiskDef *def, if (virDomainIothreadMappingDefParse(cur, &def->iothreads) < 0) return -1; + if ((statisticsNode = virXMLNodeGetSubelement(cur, "statistics"))) { + g_autoptr(GPtrArray) statisticNodes = NULL; + + statisticNodes = virXMLNodeGetSubelementList(statisticsNode, "statistic"); + + if (statisticNodes->len > 0) { + size_t i; + + def->statistics = g_new0(unsigned int, statisticNodes->len + 1); + + for (i = 0; i < statisticNodes->len; i++) { + if (virXMLPropUInt(g_ptr_array_index(statisticNodes, i), + "interval", 10, + VIR_XML_PROP_REQUIRED | VIR_XML_PROP_NONZERO, + def->statistics + i) < 0) + return -1; + } + } + } + if (virXMLPropEnum(cur, "detect_zeroes", virDomainDiskDetectZeroesTypeFromString, VIR_XML_PROP_NONZERO, &def->detect_zeroes) < 0) @@ -23826,6 +23848,18 @@ virDomainDiskDefFormatDriver(virBuffer *buf, virDomainIothreadMappingDefFormat(&childBuf, disk->iothreads); + if (disk->statistics) { + g_auto(virBuffer) statisticsChildBuf = VIR_BUFFER_INIT_CHILD(&childBuf); + size_t i; + + for (i = 0; disk->statistics[i] > 0; i++) + virBufferAsprintf(&statisticsChildBuf, "<statistic interval='%u'/>\n", + disk->statistics[i]); + + virXMLFormatElement(&childBuf, "statistics", NULL, &statisticsChildBuf); + } + + virXMLFormatElement(buf, "driver", &attrBuf, &childBuf); } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 39807b5fe3..4110ca75ac 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -591,6 +591,8 @@ struct _virDomainDiskDef { virDomainDiskDiscard discard; unsigned int iothread; /* unused = 0, > 0 specific thread # */ GSList *iothreads; /* List of virDomainIothreadMappingDef */ + unsigned int *statistics; /* Optional, zero terminated list of intervals to + collect statistics for */ virDomainDiskDetectZeroes detect_zeroes; virTristateSwitch discard_no_unref; char *domain_name; /* backend domain name */ diff --git a/src/conf/schemas/domaincommon.rng b/src/conf/schemas/domaincommon.rng index b9230a35b4..1303c392ae 100644 --- a/src/conf/schemas/domaincommon.rng +++ b/src/conf/schemas/domaincommon.rng @@ -2742,6 +2742,17 @@ <optional> <ref name="iothreadMapping"/> </optional> + <optional> + <element name="statistics"> + <zeroOrMore> + <element name="statistic"> + <attribute name="interval"> + <ref name="unsignedInt"/> + </attribute> + </element> + </zeroOrMore> + </element> + </optional> </interleave> </element> </define> -- 2.51.0