From: Derbyshev Dmitry <dderbyshev(a)virtuozzo.com>
To collect all balloon statistics for all guests it was necessary to make
several libvirt requests (one per VE).
This patch allows doing this via qemuConnectGetAllDomainStats in one request.
Changes:
* qemuDomainMemoryStats became a helper function which calls
qemuDomainMemoryStatsInternal, which contains all logic.
* flags in qemuDomainMemoryStatsInternal may passed from qemuDomainMemoryStats
or qemuDomainGetStatsBalloon via different variables
* qemuDomainGetStatsBalloon reports memory stats fields by calling
qemuDomainMemoryStatsInternal
Signed-off-by: Derbyshev Dmitry <dderbyshev(a)virtuozzo.com>
---
src/qemu/qemu_driver.c | 84 +++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 66 insertions(+), 18 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index fc43bcb..4dbd4ed 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -11120,31 +11120,21 @@ qemuDomainGetInterfaceParameters(virDomainPtr dom,
}
static int
-qemuDomainMemoryStats(virDomainPtr dom,
- virDomainMemoryStatPtr stats,
- unsigned int nr_stats,
- unsigned int flags)
+qemuDomainMemoryStatsInternal(virQEMUDriverPtr driver,
+ virDomainObjPtr vm,
+ virDomainMemoryStatPtr stats,
+ unsigned int nr_stats,
+ unsigned int flags)
{
- virQEMUDriverPtr driver = dom->conn->privateData;
- virDomainObjPtr vm;
int ret = -1;
long rss;
virCheckFlags(0, -1);
- if (!(vm = qemuDomObjFromDomain(dom)))
- goto cleanup;
-
- if (virDomainMemoryStatsEnsureACL(dom->conn, vm->def) < 0)
- goto cleanup;
-
- if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_QUERY) < 0)
- goto cleanup;
-
if (!virDomainObjIsActive(vm)) {
virReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("domain is not running"));
- goto endjob;
+ goto cleanup;
}
if (vm->def->memballoon &&
@@ -11155,7 +11145,7 @@ qemuDomainMemoryStats(virDomainPtr dom,
ret = -1;
if (ret < 0 || ret >= nr_stats)
- goto endjob;
+ goto cleanup;
} else {
ret = 0;
}
@@ -11169,7 +11159,33 @@ qemuDomainMemoryStats(virDomainPtr dom,
ret++;
}
- endjob:
+ cleanup:
+ return ret;
+}
+
+static int
+qemuDomainMemoryStats(virDomainPtr dom,
+ virDomainMemoryStatPtr stats,
+ unsigned int nr_stats,
+ unsigned int flags)
+{
+ virQEMUDriverPtr driver = dom->conn->privateData;
+ virDomainObjPtr vm;
+ int ret = -1;
+
+ virCheckFlags(0, -1);
+
+ if (!(vm = qemuDomObjFromDomain(dom)))
+ goto cleanup;
+
+ if (virDomainMemoryStatsEnsureACL(dom->conn, vm->def) < 0)
+ goto cleanup;
+
+ if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_QUERY) < 0)
+ goto cleanup;
+
+ ret = qemuDomainMemoryStatsInternal(driver, vm, stats, nr_stats, flags);
+
qemuDomainObjEndJob(driver, vm);
cleanup:
@@ -18650,6 +18666,17 @@ qemuDomainGetStatsCpu(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
return 0;
}
+
+#define STORE_MEM_RECORD(TAG, NAME) { \
+ if (stats[i].tag == VIR_DOMAIN_MEMORY_STAT_ ##TAG) \
+ if (virTypedParamsAddULLong(&record->params, \
+ &record->nparams, \
+ maxparams, \
+ "balloon." NAME, \
+ stats[i].val) < 0) \
+ return -1; \
+}
+
static int
qemuDomainGetStatsBalloon(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
virDomainObjPtr dom,
@@ -18658,7 +18685,10 @@ qemuDomainGetStatsBalloon(virQEMUDriverPtr driver
ATTRIBUTE_UNUSED,
unsigned int privflags ATTRIBUTE_UNUSED)
{
qemuDomainObjPrivatePtr priv = dom->privateData;
+ virDomainMemoryStatStruct stats[VIR_DOMAIN_MEMORY_STAT_NR];
+ int nr_stats;
unsigned long long cur_balloon = 0;
+ size_t i;
int err = 0;
if (!virDomainDefHasMemballoon(dom->def)) {
@@ -18683,8 +18713,26 @@ qemuDomainGetStatsBalloon(virQEMUDriverPtr driver
ATTRIBUTE_UNUSED,
virDomainDefGetMemoryActual(dom->def)) < 0)
return -1;
+ nr_stats = qemuDomainMemoryStatsInternal(driver, dom, stats,
+ VIR_DOMAIN_MEMORY_STAT_NR, 0);
+ if (nr_stats < 0)
+ return 0;
+ for (i = 0; i < nr_stats; i++) {
+ STORE_MEM_RECORD(SWAP_IN, "swap_in")
+ STORE_MEM_RECORD(SWAP_OUT, "swap_out")
+ STORE_MEM_RECORD(MAJOR_FAULT, "major_fault")
+ STORE_MEM_RECORD(MINOR_FAULT, "minor_fault")
+ STORE_MEM_RECORD(UNUSED, "unused")
+ STORE_MEM_RECORD(AVAILABLE, "available")
+ STORE_MEM_RECORD(ACTUAL_BALLOON, "actual")
+ STORE_MEM_RECORD(RSS, "rss")
+ STORE_MEM_RECORD(LAST_UPDATE, "last-update")
+ STORE_MEM_RECORD(USABLE, "usable")
+ }
+
return 0;
}
+#undef STORE_MEM_RECORD
static int
--
1.9.5.msysgit.0