render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
c1c534
From d75ea91fe4c95b17f928931637f65fcf317e986c Mon Sep 17 00:00:00 2001
c1c534
Message-Id: <d75ea91fe4c95b17f928931637f65fcf317e986c@dist-git>
c1c534
From: Peter Krempa <pkrempa@redhat.com>
c1c534
Date: Wed, 7 Feb 2018 14:16:01 +0100
c1c534
Subject: [PATCH] qemu: domain: Store vcpu halted state as a tristate
c1c534
c1c534
Since it may be possible that the state is unknown in some cases we
c1c534
should store it as a tristate so that other code using it can determine
c1c534
whether the state was updated.
c1c534
c1c534
(cherry picked from commit ca588a34b23a1f30dc7eeb7d5134706e31b403ef)
c1c534
c1c534
https://bugzilla.redhat.com/show_bug.cgi?id=1534585
c1c534
---
c1c534
 src/qemu/qemu_domain.c |  3 ++-
c1c534
 src/qemu/qemu_domain.h |  2 +-
c1c534
 src/qemu/qemu_driver.c | 13 ++++---------
c1c534
 3 files changed, 7 insertions(+), 11 deletions(-)
c1c534
c1c534
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
c1c534
index b0c78cc7c4..e87c7d030c 100644
c1c534
--- a/src/qemu/qemu_domain.c
c1c534
+++ b/src/qemu/qemu_domain.c
c1c534
@@ -8000,7 +8000,8 @@ qemuDomainRefreshVcpuHalted(virQEMUDriverPtr driver,
c1c534
     for (i = 0; i < maxvcpus; i++) {
c1c534
         vcpu = virDomainDefGetVcpu(vm->def, i);
c1c534
         vcpupriv = QEMU_DOMAIN_VCPU_PRIVATE(vcpu);
c1c534
-        vcpupriv->halted = virBitmapIsBitSet(haltedmap, vcpupriv->qemu_id);
c1c534
+        vcpupriv->halted = virTristateBoolFromBool(virBitmapIsBitSet(haltedmap,
c1c534
+                                                                     vcpupriv->qemu_id));
c1c534
     }
c1c534
 
c1c534
     ret = 0;
c1c534
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
c1c534
index 1a82922415..19e58ef3be 100644
c1c534
--- a/src/qemu/qemu_domain.h
c1c534
+++ b/src/qemu/qemu_domain.h
c1c534
@@ -389,7 +389,7 @@ struct _qemuDomainVcpuPrivate {
c1c534
     int enable_id; /* order in which the vcpus were enabled in qemu */
c1c534
     int qemu_id; /* ID reported by qemu as 'CPU' in query-cpus */
c1c534
     char *alias;
c1c534
-    bool halted;
c1c534
+    virTristateBool halted;
c1c534
 
c1c534
     /* information for hotpluggable cpus */
c1c534
     char *type;
c1c534
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
c1c534
index b5bef7442e..b8022a06ba 100644
c1c534
--- a/src/qemu/qemu_driver.c
c1c534
+++ b/src/qemu/qemu_driver.c
c1c534
@@ -19526,7 +19526,6 @@ qemuDomainGetStatsVcpu(virQEMUDriverPtr driver,
c1c534
     char param_name[VIR_TYPED_PARAM_FIELD_LENGTH];
c1c534
     virVcpuInfoPtr cpuinfo = NULL;
c1c534
     unsigned long long *cpuwait = NULL;
c1c534
-    bool vcpuhalted = false;
c1c534
 
c1c534
     if (virTypedParamsAddUInt(&record->params,
c1c534
                               &record->nparams,
c1c534
@@ -19546,15 +19545,11 @@ qemuDomainGetStatsVcpu(virQEMUDriverPtr driver,
c1c534
         VIR_ALLOC_N(cpuwait, virDomainDefGetVcpus(dom->def)) < 0)
c1c534
         goto cleanup;
c1c534
 
c1c534
-    if (HAVE_JOB(privflags) && virDomainObjIsActive(dom)) {
c1c534
-        if (qemuDomainRefreshVcpuHalted(driver, dom,
c1c534
-                                        QEMU_ASYNC_JOB_NONE) < 0) {
c1c534
+    if (HAVE_JOB(privflags) && virDomainObjIsActive(dom) &&
c1c534
+        qemuDomainRefreshVcpuHalted(driver, dom, QEMU_ASYNC_JOB_NONE) < 0) {
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 {
c1c534
-            vcpuhalted = true;
c1c534
-        }
c1c534
     }
c1c534
 
c1c534
     if (qemuDomainHelperGetVcpus(dom, cpuinfo, cpuwait,
c1c534
@@ -19602,14 +19597,14 @@ qemuDomainGetStatsVcpu(virQEMUDriverPtr driver,
c1c534
 
c1c534
         vcpupriv = QEMU_DOMAIN_VCPU_PRIVATE(vcpu);
c1c534
 
c1c534
-        if (vcpuhalted) {
c1c534
+        if (vcpupriv->halted != VIR_TRISTATE_BOOL_ABSENT) {
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
-                                         vcpupriv->halted) < 0)
c1c534
+                                         vcpupriv->halted == VIR_TRISTATE_BOOL_YES) < 0)
c1c534
                 goto cleanup;
c1c534
         }
c1c534
     }
c1c534
-- 
c1c534
2.16.1
c1c534