From: Francesco Romani <fromani(a)redhat.com>
This patch implements the VIR_DOMAIN_STATS_BALLOON group of statistics.
Signed-off-by: Francesco Romani <fromani(a)redhat.com>
---
include/libvirt/libvirt.h.in | 1 +
src/libvirt.c | 6 ++++++
src/qemu/qemu_driver.c | 37 +++++++++++++++++++++++++++++++++++++
3 files changed, 44 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 9c4de94..825727d 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -17431,6 +17431,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,
@@ -17448,6 +17484,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 }
};
--
2.1.0