render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Blob Blame History Raw
From 5f9e238175a43da530e2bfc7946cd81659bad915 Mon Sep 17 00:00:00 2001
Message-Id: <5f9e238175a43da530e2bfc7946cd81659bad915@dist-git>
From: Francesco Romani <fromani@redhat.com>
Date: Wed, 1 Oct 2014 11:20:11 +0200
Subject: [PATCH] qemu: bulk stats: extend internal collection API

https://bugzilla.redhat.com/show_bug.cgi?id=1113116

Future patches which will implement more bulk stats groups for QEMU will
need to access the connection object.

To accommodate that, a few changes are needed:

* enrich internal prototype to pass qemu driver object

* add per-group flag to mark if one collector needs monitor access or not

* If at least one collector of the requested stats needs monitor access
  we must start a query job for each domain.  The specific collectors
  will run nested monitor jobs inside that.

* If the job can't be acquired we pass flags to the collector so
  specific collectors that need monitor access can be skipped in order
  to gather as much data as is possible.

Signed-off-by: Francesco Romani <fromani@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
(cherry picked from commit 1f4831ee6ecc17d0f2008d7db15bfd9bc3b1d685)
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/qemu/qemu_driver.c | 63 +++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 55 insertions(+), 8 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 08f0142..1d94330 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -17412,7 +17412,8 @@ qemuConnectGetDomainCapabilities(virConnectPtr conn,
 
 
 static int
-qemuDomainGetStatsState(virDomainObjPtr dom,
+qemuDomainGetStatsState(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
+                        virDomainObjPtr dom,
                         virDomainStatsRecordPtr record,
                         int *maxparams,
                         unsigned int privflags ATTRIBUTE_UNUSED)
@@ -17435,8 +17436,18 @@ qemuDomainGetStatsState(virDomainObjPtr dom,
 }
 
 
+typedef enum {
+    QEMU_DOMAIN_STATS_HAVE_JOB = (1 << 0), /* job is entered, monitor can be
+                                              accessed */
+} qemuDomainStatsFlags;
+
+
+#define HAVE_JOB(flags) ((flags) & QEMU_DOMAIN_STATS_HAVE_JOB)
+
+
 typedef int
-(*qemuDomainGetStatsFunc)(virDomainObjPtr dom,
+(*qemuDomainGetStatsFunc)(virQEMUDriverPtr driver,
+                          virDomainObjPtr dom,
                           virDomainStatsRecordPtr record,
                           int *maxparams,
                           unsigned int flags);
@@ -17444,11 +17455,12 @@ typedef int
 struct qemuDomainGetStatsWorker {
     qemuDomainGetStatsFunc func;
     unsigned int stats;
+    bool monitor;
 };
 
 static struct qemuDomainGetStatsWorker qemuDomainGetStatsWorkers[] = {
-    { qemuDomainGetStatsState, VIR_DOMAIN_STATS_STATE},
-    { NULL, 0 }
+    { qemuDomainGetStatsState, VIR_DOMAIN_STATS_STATE, false },
+    { NULL, 0, false }
 };
 
 
@@ -17480,6 +17492,20 @@ qemuDomainGetStatsCheckSupport(unsigned int *stats,
 }
 
 
+static bool
+qemuDomainGetStatsNeedMonitor(unsigned int stats)
+{
+    size_t i;
+
+    for (i = 0; qemuDomainGetStatsWorkers[i].func; i++)
+        if (stats & qemuDomainGetStatsWorkers[i].stats &&
+            qemuDomainGetStatsWorkers[i].monitor)
+            return true;
+
+    return false;
+}
+
+
 static int
 qemuDomainGetStats(virConnectPtr conn,
                    virDomainObjPtr dom,
@@ -17497,8 +17523,8 @@ qemuDomainGetStats(virConnectPtr conn,
 
     for (i = 0; qemuDomainGetStatsWorkers[i].func; i++) {
         if (stats & qemuDomainGetStatsWorkers[i].stats) {
-            if (qemuDomainGetStatsWorkers[i].func(dom, tmp, &maxparams,
-                                                  flags) < 0)
+            if (qemuDomainGetStatsWorkers[i].func(conn->privateData, dom, tmp,
+                                                  &maxparams, flags) < 0)
                 goto cleanup;
         }
     }
@@ -17537,6 +17563,8 @@ qemuConnectGetAllDomainStats(virConnectPtr conn,
     int nstats = 0;
     size_t i;
     int ret = -1;
+    unsigned int privflags = 0;
+    unsigned int domflags = 0;
 
     if (ndoms)
         virCheckFlags(VIR_CONNECT_GET_ALL_DOMAINS_STATS_ENFORCE_STATS, -1);
@@ -17571,7 +17599,11 @@ qemuConnectGetAllDomainStats(virConnectPtr conn,
     if (VIR_ALLOC_N(tmpstats, ndoms + 1) < 0)
         goto cleanup;
 
+    if (qemuDomainGetStatsNeedMonitor(stats))
+        privflags |= QEMU_DOMAIN_STATS_HAVE_JOB;
+
     for (i = 0; i < ndoms; i++) {
+        domflags = privflags;
         virDomainStatsRecordPtr tmp = NULL;
 
         if (!(dom = qemuDomObjFromDomain(doms[i])))
@@ -17581,12 +17613,22 @@ qemuConnectGetAllDomainStats(virConnectPtr conn,
             !virConnectGetAllDomainStatsCheckACL(conn, dom->def))
             continue;
 
-        if (qemuDomainGetStats(conn, dom, stats, &tmp, flags) < 0)
-            goto cleanup;
+        if (HAVE_JOB(domflags) &&
+            qemuDomainObjBeginJob(driver, dom, QEMU_JOB_QUERY) < 0)
+            /* As it was never requested. Gather as much as possible anyway. */
+            domflags &= ~QEMU_DOMAIN_STATS_HAVE_JOB;
+
+        if (qemuDomainGetStats(conn, dom, stats, &tmp, domflags) < 0)
+            goto endjob;
 
         if (tmp)
             tmpstats[nstats++] = tmp;
 
+        if (HAVE_JOB(domflags) && !qemuDomainObjEndJob(driver, dom)) {
+            dom = NULL;
+            continue;
+        }
+
         virObjectUnlock(dom);
         dom = NULL;
     }
@@ -17596,6 +17638,11 @@ qemuConnectGetAllDomainStats(virConnectPtr conn,
 
     ret = nstats;
 
+ endjob:
+    if (HAVE_JOB(domflags) && dom)
+        if (!qemuDomainObjEndJob(driver, dom))
+            dom = NULL;
+
  cleanup:
     if (dom)
         virObjectUnlock(dom);
-- 
2.1.2