]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu_domain: add statsSchema to qemuDomainObjPrivate
authorAmneesh Singh <natto@weirdnatto.in>
Wed, 7 Sep 2022 10:34:20 +0000 (16:04 +0530)
committerMartin Kletzander <mkletzan@redhat.com>
Wed, 19 Oct 2022 13:58:29 +0000 (15:58 +0200)
This patch adds a hashtable for storing the stats schema and a function
to refresh it by querying "query-stats-schemas" using
qemuMonitorQueryStatsSchema

Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
src/qemu/qemu_domain.c
src/qemu/qemu_domain.h

index 4c14fc2aef85d6d4dc87af81c4e935fac81e75a1..429a53872fe1a79fa6b982cfb14047552583d55d 100644 (file)
@@ -1740,6 +1740,8 @@ qemuDomainObjPrivateDataClear(qemuDomainObjPrivate *priv)
 
     priv->originalMemlock = 0;
     priv->preMigrationMemlock = 0;
+
+    virHashRemoveAll(priv->statsSchema);
 }
 
 
@@ -1778,6 +1780,9 @@ qemuDomainObjPrivateFree(void *data)
         g_object_unref(priv->eventThread);
     }
 
+    if (priv->statsSchema)
+        g_clear_pointer(&priv->statsSchema, g_hash_table_destroy);
+
     g_free(priv);
 }
 
@@ -1799,6 +1804,8 @@ qemuDomainObjPrivateAlloc(void *opaque)
     priv->migMaxBandwidth = QEMU_DOMAIN_MIG_BANDWIDTH_MAX;
     priv->driver = opaque;
 
+    priv->statsSchema = NULL;
+
     return g_steal_pointer(&priv);
 }
 
@@ -11774,3 +11781,38 @@ qemuDomainObjWait(virDomainObj *vm)
 
     return 0;
 }
+
+
+/**
+ * virDomainRefreshStatsSchema:
+ * @driver: qemu driver data
+ * @vm: Pointer to the vm object
+ *
+ * Load data into dom->privateData->statsSchema if not stored
+ *
+ * Returns -1 on failure, 0 otherwise.
+ */
+int
+qemuDomainRefreshStatsSchema(virDomainObj *dom)
+{
+    qemuDomainObjPrivate *priv = dom->privateData;
+    GHashTable *schema = priv->statsSchema;
+
+    if (schema && g_hash_table_size(schema) > 0)
+        return 0;
+
+    if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_QUERY_STATS_SCHEMAS))
+        return -1;
+
+    qemuDomainObjEnterMonitor(dom);
+    schema = qemuMonitorQueryStatsSchema(priv->mon, QEMU_MONITOR_QUERY_STATS_PROVIDER_LAST);
+    qemuDomainObjExitMonitor(dom);
+
+    if (!schema)
+        return -1;
+
+    g_hash_table_unref(priv->statsSchema);
+    priv->statsSchema = schema;
+
+    return 0;
+}
index a22deaf1135d657e39ad176a6609b4af7bb845d8..975fa99cca91b280413e467e46b36c317f0ac83e 100644 (file)
@@ -242,6 +242,8 @@ struct _qemuDomainObjPrivate {
 
     unsigned long long originalMemlock; /* Original RLIMIT_MEMLOCK, zero if no
                                          * restore will be required later */
+
+    GHashTable *statsSchema; /* (name, data) pair for stats */
 };
 
 #define QEMU_DOMAIN_PRIVATE(vm) \
@@ -1098,3 +1100,6 @@ qemuDomainRemoveLogs(virQEMUDriver *driver,
 
 int
 qemuDomainObjWait(virDomainObj *vm);
+
+int
+qemuDomainRefreshStatsSchema(virDomainObj *dom);