c1c534
From 82aa1d86ca26a7693b3817cc6331c9f094549098 Mon Sep 17 00:00:00 2001
c1c534
Message-Id: <82aa1d86ca26a7693b3817cc6331c9f094549098@dist-git>
c1c534
From: Peter Krempa <pkrempa@redhat.com>
c1c534
Date: Wed, 7 Feb 2018 14:15:59 +0100
c1c534
Subject: [PATCH] qemu: driver: Extract vcpu halted state directly
c1c534
c1c534
Don't extract the halted state into a separate array, but rater access
c1c534
the vcpu structures directly. We still need to call the vcpu helper to
c1c534
retrieve the performance statistics though.
c1c534
c1c534
(cherry picked from commit 38d26864f7b0bf780ff07bf95c81a68699ddebaf)
c1c534
c1c534
https://bugzilla.redhat.com/show_bug.cgi?id=1534585
c1c534
---
c1c534
 src/qemu/qemu_driver.c | 21 ++++++++++++++-------
c1c534
 1 file changed, 14 insertions(+), 7 deletions(-)
c1c534
c1c534
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
c1c534
index 0bc6eaa431..bfb3c3c4c5 100644
c1c534
--- a/src/qemu/qemu_driver.c
c1c534
+++ b/src/qemu/qemu_driver.c
c1c534
@@ -19527,12 +19527,14 @@ qemuDomainGetStatsVcpu(virQEMUDriverPtr driver,
c1c534
                        int *maxparams,
c1c534
                        unsigned int privflags)
c1c534
 {
c1c534
+    virDomainVcpuDefPtr vcpu;
c1c534
+    qemuDomainVcpuPrivatePtr vcpupriv;
c1c534
     size_t i;
c1c534
     int ret = -1;
c1c534
     char param_name[VIR_TYPED_PARAM_FIELD_LENGTH];
c1c534
     virVcpuInfoPtr cpuinfo = NULL;
c1c534
     unsigned long long *cpuwait = NULL;
c1c534
-    bool *cpuhalted = NULL;
c1c534
+    bool vcpuhalted = false;
c1c534
 
c1c534
     if (virTypedParamsAddUInt(&record->params,
c1c534
                               &record->nparams,
c1c534
@@ -19558,14 +19560,14 @@ qemuDomainGetStatsVcpu(virQEMUDriverPtr driver,
c1c534
             /* it's ok to be silent and go ahead, because halted vcpu info
c1c534
              * wasn't here from the beginning */
c1c534
             virResetLastError();
c1c534
-        } else if (VIR_ALLOC_N(cpuhalted, virDomainDefGetVcpus(dom->def)) < 0) {
c1c534
-            goto cleanup;
c1c534
+        } else {
c1c534
+            vcpuhalted = true;
c1c534
         }
c1c534
     }
c1c534
 
c1c534
     if (qemuDomainHelperGetVcpus(dom, cpuinfo, cpuwait,
c1c534
                                  virDomainDefGetVcpus(dom->def),
c1c534
-                                 NULL, 0, cpuhalted) < 0) {
c1c534
+                                 NULL, 0, NULL) < 0) {
c1c534
         virResetLastError();
c1c534
         ret = 0; /* it's ok to be silent and go ahead */
c1c534
         goto cleanup;
c1c534
@@ -19602,14 +19604,20 @@ qemuDomainGetStatsVcpu(virQEMUDriverPtr driver,
c1c534
                                     cpuwait[i]) < 0)
c1c534
             goto cleanup;
c1c534
 
c1c534
-        if (cpuhalted) {
c1c534
+        /* state below is extracted from the individual vcpu structs */
c1c534
+        if (!(vcpu = virDomainDefGetVcpu(dom->def, cpuinfo[i].number)))
c1c534
+            continue;
c1c534
+
c1c534
+        vcpupriv = QEMU_DOMAIN_VCPU_PRIVATE(vcpu);
c1c534
+
c1c534
+        if (vcpuhalted) {
c1c534
             snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH,
c1c534
                      "vcpu.%u.halted", cpuinfo[i].number);
c1c534
             if (virTypedParamsAddBoolean(&record->params,
c1c534
                                          &record->nparams,
c1c534
                                          maxparams,
c1c534
                                          param_name,
c1c534
-                                         cpuhalted[i]) < 0)
c1c534
+                                         vcpupriv->halted) < 0)
c1c534
                 goto cleanup;
c1c534
         }
c1c534
     }
c1c534
@@ -19619,7 +19627,6 @@ qemuDomainGetStatsVcpu(virQEMUDriverPtr driver,
c1c534
  cleanup:
c1c534
     VIR_FREE(cpuinfo);
c1c534
     VIR_FREE(cpuwait);
c1c534
-    VIR_FREE(cpuhalted);
c1c534
     return ret;
c1c534
 }
c1c534
 
c1c534
-- 
c1c534
2.16.1
c1c534