]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: Add configuration option for timed disk statistics collection
authorPeter Krempa <pkrempa@redhat.com>
Mon, 6 Oct 2025 15:32:28 +0000 (17:32 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 5 Nov 2025 13:27:57 +0000 (14:27 +0100)
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>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
docs/formatdomain.rst
src/conf/domain_conf.c
src/conf/domain_conf.h
src/conf/schemas/domaincommon.rng

index 34dc9c3af729784b0699dddd8d56f12ca4c1b21b..4c245f41a99f7b4c49e759fb219f276acbaf9b9b 100644 (file)
@@ -3597,6 +3597,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` )
index 1e84c938410a9805b0fff11752d557eeee193358..c749d505bf341ebd7e78ad23e40f055c9c19a405 100644 (file)
@@ -8297,6 +8297,8 @@ static int
 virDomainDiskDefDriverParseXML(virDomainDiskDef *def,
                                xmlNodePtr cur)
 {
+    xmlNodePtr statisticsNode;
+
     def->driverName = virXMLPropString(cur, "name");
 
     if (virXMLPropEnum(cur, "cache", virDomainDiskCacheTypeFromString,
@@ -8346,6 +8348,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)
@@ -23864,6 +23886,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);
 }
 
index b265bf224b54514cfcb1553ef41a8a6a54b35368..81e735993d47a1d50a0d69c8766633920f039e71 100644 (file)
@@ -592,6 +592,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 */
index 110f6cbc69a9f8cced903a3fb1c51e6f4e1968af..75b5124c338fd448462bfc369813e4a720c358d3 100644 (file)
         <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>