[PATCH v2 18/23] src: add constants for domain stats 'iothread.' parameters

Daniel P. Berrangé posted 23 patches 22 hours ago
[PATCH v2 18/23] src: add constants for domain stats 'iothread.' parameters
Posted by Daniel P. Berrangé 22 hours ago
Contrary to most APIs returning typed parameters, there are no constants
defined for the domain stats data keys. This is was because many of the
keys needs to be dynamically constructed using one or more array index
values.

It is possible to define constants while still supporting dynamic
array indexes by simply defining the prefixes and suffixes as constants.
The consuming code can then combine the constants with array index
value.

With this approach, it is practical to add constants for the domain stats
API keys.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 include/libvirt/libvirt-domain.h | 56 ++++++++++++++++++++++++++++++++
 src/libvirt-domain.c             | 24 ++------------
 src/qemu/qemu_driver.c           |  9 ++---
 3 files changed, 63 insertions(+), 26 deletions(-)

diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index 4680d32b53..2128b7a0f3 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -3700,6 +3700,62 @@ struct _virDomainStatsRecord {
  */
 #define VIR_DOMAIN_STATS_PERF_EMULATION_FAULTS "perf.emulation_faults"
 
+
+/**
+ * VIR_DOMAIN_STATS_IOTHREAD_COUNT:
+ *
+ * Maximum number of IOThreads in the subsequent list as unsigned int. Each
+ * IOThread in the list will will use it's iothread_id value as the array
+ * index. There may be fewer array entries than the iothread.count value if
+ * the polling values are not supported.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_STATS_IOTHREAD_COUNT "iothread.count"
+
+/**
+ * VIR_DOMAIN_STATS_IOTHREAD_PREFIX:
+ *
+ * The parameter name prefix to access each iothread entry. Concatenate the
+ * prefix, the entry number formatted as an unsigned integer and one of the
+ * iothread suffix parameters to form a complete parameter name.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_STATS_IOTHREAD_PREFIX "iothread."
+
+/**
+ * VIR_DOMAIN_STATS_IOTHREAD_SUFFIX_POLL_MAX_NS:
+ *
+ * Maximum polling time in ns as an unsigned long long. A 0 (zero) means
+ * polling is disabled.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_STATS_IOTHREAD_SUFFIX_POLL_MAX_NS ".poll-max-ns"
+
+/**
+ * VIR_DOMAIN_STATS_IOTHREAD_SUFFIX_POLL_GROW:
+ *
+ * Polling time factor as an unsigned int or unsigned long long if exceeding
+ * range of unsigned int. A 0 (zero) indicates to allow the underlying
+ * hypervisor to choose how to grow the polling time.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_STATS_IOTHREAD_SUFFIX_POLL_GROW ".poll-grow"
+
+/**
+ * VIR_DOMAIN_STATS_IOTHREAD_SUFFIX_POLL_SHRINK:
+ *
+ * Polling time divisor as an unsigned int or unsigned long long if exceeding
+ * range of unsigned int. A 0 (zero) indicates to allow the underlying
+ * hypervisor to choose how to shrink the polling time.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_STATS_IOTHREAD_SUFFIX_POLL_SHRINK ".poll-shrink"
+
 /**
  * virDomainStatsTypes:
  *
diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index a10746344c..d3e701081b 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -12313,28 +12313,8 @@ virConnectGetDomainCapabilities(virConnectPtr conn,
  *     which could quickly exceed poll-max-ns; however, a poll-shrink of
  *     10 would cut that polling time more gradually.
  *
- *     The typed parameter keys are in this format:
- *
- *     "iothread.count" - maximum number of IOThreads in the subsequent list
- *                        as unsigned int. Each IOThread in the list will
- *                        will use it's iothread_id value as the <id>. There
- *                        may be fewer <id> entries than the iothread.count
- *                        value if the polling values are not supported.
- *     "iothread.<id>.poll-max-ns" - maximum polling time in ns as an unsigned
- *                                   long long. A 0 (zero) means polling is
- *                                   disabled.
- *     "iothread.<id>.poll-grow" - polling time factor as an unsigned int or
- *                                 unsigned long long if exceeding range of
- *                                 unsigned int.
- *                                 A 0 (zero) indicates to allow the underlying
- *                                 hypervisor to choose how to grow the
- *                                 polling time.
- *     "iothread.<id>.poll-shrink" - polling time divisor as an unsigned int or
- *                                   unsigned long long if exceeding range of
- *                                   unsigned int.
- *                                   A 0 (zero) indicates to allow the underlying
- *                                   hypervisor to choose how to shrink the
- *                                   polling time.
+ *     The VIR_DOMAIN_STATS_IOTHREAD_* constants define the known typed
+ *     parameter keys.
  *
  * VIR_DOMAIN_STATS_MEMORY:
  *     Return memory bandwidth statistics and the usage information. The typed
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 29c5a7df29..2f4d0c1a5d 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -17576,18 +17576,19 @@ qemuDomainGetStatsIOThread(virQEMUDriver *driver G_GNUC_UNUSED,
     if (niothreads == 0)
         return;
 
-    virTypedParamListAddUInt(params, niothreads, "iothread.count");
+    virTypedParamListAddUInt(params, niothreads,
+                             VIR_DOMAIN_STATS_IOTHREAD_COUNT);
 
     for (i = 0; i < niothreads; i++) {
         if (iothreads[i]->poll_valid) {
             virTypedParamListAddULLong(params, iothreads[i]->poll_max_ns,
-                                       "iothread.%u.poll-max-ns",
+                                       VIR_DOMAIN_STATS_IOTHREAD_PREFIX "%u" VIR_DOMAIN_STATS_IOTHREAD_SUFFIX_POLL_MAX_NS,
                                        iothreads[i]->iothread_id);
             virTypedParamListAddUnsigned(params, iothreads[i]->poll_grow,
-                                         "iothread.%u.poll-grow",
+                                         VIR_DOMAIN_STATS_IOTHREAD_PREFIX "%u" VIR_DOMAIN_STATS_IOTHREAD_SUFFIX_POLL_GROW,
                                          iothreads[i]->iothread_id);
             virTypedParamListAddUnsigned(params, iothreads[i]->poll_shrink,
-                                         "iothread.%u.poll-shrink",
+                                         VIR_DOMAIN_STATS_IOTHREAD_PREFIX "%u" VIR_DOMAIN_STATS_IOTHREAD_SUFFIX_POLL_SHRINK,
                                          iothreads[i]->iothread_id);
         }
     }
-- 
2.48.1