[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCHv5 3/8] qemu: bulk stats: implement balloon group



This patch implements the VIR_DOMAIN_STATS_BALLOON
group of statistics.

Signed-off-by: Francesco Romani <fromani redhat com>
---
 include/libvirt/libvirt.h.in |  1 +
 src/libvirt.c                |  6 ++++++
 src/qemu/qemu_driver.c       | 38 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index eb62f96..a5033ed 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -2514,6 +2514,7 @@ struct _virDomainStatsRecord {
 typedef enum {
     VIR_DOMAIN_STATS_STATE = (1 << 0), /* return domain state */
     VIR_DOMAIN_STATS_CPU_TOTAL = (1 << 1), /* return domain CPU info */
+    VIR_DOMAIN_STATS_BALLOON = (1 << 2), /* return domain balloon info */
 } virDomainStatsTypes;
 
 typedef enum {
diff --git a/src/libvirt.c b/src/libvirt.c
index dfbd5c7..b3b71a0 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -21602,6 +21602,12 @@ virConnectGetDomainCapabilities(virConnectPtr conn,
  * "cpu.user" - user cpu time spent as unsigned long long.
  * "cpu.system" - system cpu time spent as unsigned long long.
  *
+ * VIR_DOMAIN_STATS_BALLOON: Return memory balloon device information.
+ * The typed parameter keys are in this format:
+ * "balloon.current" - the memory in kiB currently used
+ *                     as unsigned long long.
+ * "balloon.maximum" - the maximum memory in kiB allowed
+ *                     as unsigned long long.
  *
  * Using 0 for @stats returns all stats groups supported by the given
  * hypervisor.
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index d0fad61..745b4f1 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -2525,6 +2525,7 @@ static int qemuDomainSendKey(virDomainPtr domain,
     return ret;
 }
 
+
 static int qemuDomainGetInfo(virDomainPtr dom,
                              virDomainInfoPtr info)
 {
@@ -17427,6 +17428,42 @@ qemuDomainGetStatsCpu(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
     return 0;
 }
 
+static int
+qemuDomainGetStatsBalloon(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
+                          virDomainObjPtr dom,
+                          virDomainStatsRecordPtr record,
+                          int *maxparams,
+                          unsigned int privflags ATTRIBUTE_UNUSED)
+{
+    qemuDomainObjPrivatePtr priv = dom->privateData;
+    unsigned long long cur_balloon = 0;
+    int err = 0;
+
+    if (dom->def->memballoon &&
+        dom->def->memballoon->model == VIR_DOMAIN_MEMBALLOON_MODEL_NONE) {
+        cur_balloon = dom->def->mem.max_balloon;
+    } else if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BALLOON_EVENT)) {
+        cur_balloon = dom->def->mem.cur_balloon;
+    } else {
+        err = -1;
+    }
+
+    if (!err && virTypedParamsAddULLong(&record->params,
+                                        &record->nparams,
+                                        maxparams,
+                                        "balloon.current",
+                                        cur_balloon) < 0)
+        return -1;
+
+    if (virTypedParamsAddULLong(&record->params,
+                                &record->nparams,
+                                maxparams,
+                                "balloon.maximum",
+                                dom->def->mem.max_balloon) < 0)
+        return -1;
+
+    return 0;
+}
 
 typedef int
 (*qemuDomainGetStatsFunc)(virQEMUDriverPtr driver,
@@ -17444,6 +17481,7 @@ struct qemuDomainGetStatsWorker {
 static struct qemuDomainGetStatsWorker qemuDomainGetStatsWorkers[] = {
     { qemuDomainGetStatsState, VIR_DOMAIN_STATS_STATE, false },
     { qemuDomainGetStatsCpu, VIR_DOMAIN_STATS_CPU_TOTAL, false },
+    { qemuDomainGetStatsBalloon, VIR_DOMAIN_STATS_BALLOON, true },
     { NULL, 0, false }
 };
 
-- 
1.9.3


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]