Refresh the VCPU halted states in API functions returning domain
VCPU state information to make sure it's current. This affects
qemuDomainGetVcpus and  qemuDomainGetStatsVcpu

Signed-off-by: Viktor Mihajlovski <mihaj...@linux.vnet.ibm.com>
Reviewed-by: Bjoern Walk <bw...@linux.vnet.ibm.com>
Reviewed-by: Hao QingFeng <ha...@linux.vnet.ibm.com>
Signed-off-by: Boris Fiuczynski <fiu...@linux.vnet.ibm.com>
---
V3 Changes:
- don't emit errors for refresh calls and let the
  qemuDomainHelperGetVcpus() call decide whether the API
  call succeeded or not

 src/qemu/qemu_driver.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index e6f845d..4d3fc21 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1478,13 +1478,17 @@ qemuDomainHelperGetVcpus(virDomainObjPtr vm,
         virDomainVcpuDefPtr vcpu = virDomainDefGetVcpu(vm->def, i);
         pid_t vcpupid = qemuDomainGetVcpuPid(vm, i);
         virVcpuInfoPtr vcpuinfo = info + ncpuinfo;
+        bool vcpuhalted = qemuDomainGetVcpuHalted(vm, i);
 
         if (!vcpu->online)
             continue;
 
         if (info) {
             vcpuinfo->number = i;
-            vcpuinfo->state = VIR_VCPU_RUNNING;
+            if (vcpuhalted)
+                vcpuinfo->state = VIR_VCPU_HALTED;
+            else
+                vcpuinfo->state = VIR_VCPU_RUNNING;
 
             if (qemuGetProcessInfo(&vcpuinfo->cpuTime,
                                    &vcpuinfo->cpu, NULL,
@@ -5440,6 +5444,7 @@ qemuDomainGetVcpus(virDomainPtr dom,
                    unsigned char *cpumaps,
                    int maplen)
 {
+    virQEMUDriverPtr driver = dom->conn->privateData;
     virDomainObjPtr vm;
     int ret = -1;
 
@@ -5455,6 +5460,9 @@ qemuDomainGetVcpus(virDomainPtr dom,
         goto cleanup;
     }
 
+    /* ignoring potential failure retains legacy behavior */
+    qemuDomainRefreshVcpuHalted(driver, vm, QEMU_ASYNC_JOB_NONE);
+
     ret = qemuDomainHelperGetVcpus(vm, info, NULL, maxinfo, cpumaps, maplen);
 
  cleanup:
@@ -18922,7 +18930,7 @@ qemuDomainGetStatsBalloon(virQEMUDriverPtr driver,
 
 
 static int
-qemuDomainGetStatsVcpu(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
+qemuDomainGetStatsVcpu(virQEMUDriverPtr driver,
                        virDomainObjPtr dom,
                        virDomainStatsRecordPtr record,
                        int *maxparams,
@@ -18952,6 +18960,9 @@ qemuDomainGetStatsVcpu(virQEMUDriverPtr driver 
ATTRIBUTE_UNUSED,
         VIR_ALLOC_N(cpuwait, virDomainDefGetVcpus(dom->def)) < 0)
         goto cleanup;
 
+    /* ignoring potential failure retains legacy behavior */
+    qemuDomainRefreshVcpuHalted(driver, dom, QEMU_ASYNC_JOB_NONE);
+
     if (qemuDomainHelperGetVcpus(dom, cpuinfo, cpuwait,
                                  virDomainDefGetVcpus(dom->def),
                                  NULL, 0) < 0) {
-- 
1.9.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to