]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: domain: Store vcpu halted state as a tristate
authorPeter Krempa <pkrempa@redhat.com>
Tue, 6 Feb 2018 15:00:45 +0000 (16:00 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 7 Feb 2018 12:57:00 +0000 (13:57 +0100)
Since it may be possible that the state is unknown in some cases we
should store it as a tristate so that other code using it can determine
whether the state was updated.

src/qemu/qemu_domain.c
src/qemu/qemu_domain.h
src/qemu/qemu_driver.c

index 429660689b73d64fb3021a7a56716973a1dec59a..5395cd093c24c65b19a89a556350f1c8f9aa883e 100644 (file)
@@ -8737,7 +8737,8 @@ qemuDomainRefreshVcpuHalted(virQEMUDriverPtr driver,
     for (i = 0; i < maxvcpus; i++) {
         vcpu = virDomainDefGetVcpu(vm->def, i);
         vcpupriv = QEMU_DOMAIN_VCPU_PRIVATE(vcpu);
-        vcpupriv->halted = virBitmapIsBitSet(haltedmap, vcpupriv->qemu_id);
+        vcpupriv->halted = virTristateBoolFromBool(virBitmapIsBitSet(haltedmap,
+                                                                     vcpupriv->qemu_id));
     }
 
     ret = 0;
index 25328cd110edbaf214aeb83bb67939673c304390..f3ec5d8042b8019c0aab9be52087f7306e82f27b 100644 (file)
@@ -399,7 +399,7 @@ struct _qemuDomainVcpuPrivate {
     int enable_id; /* order in which the vcpus were enabled in qemu */
     int qemu_id; /* ID reported by qemu as 'CPU' in query-cpus */
     char *alias;
-    bool halted;
+    virTristateBool halted;
 
     /* information for hotpluggable cpus */
     char *type;
index eaa6049fee2a5e2d2682ede67616618814f23c20..8d77d8913a965403326d3904eae5fb2d56fd62f7 100644 (file)
@@ -19659,7 +19659,6 @@ qemuDomainGetStatsVcpu(virQEMUDriverPtr driver,
     char param_name[VIR_TYPED_PARAM_FIELD_LENGTH];
     virVcpuInfoPtr cpuinfo = NULL;
     unsigned long long *cpuwait = NULL;
-    bool vcpuhalted = false;
 
     if (virTypedParamsAddUInt(&record->params,
                               &record->nparams,
@@ -19679,15 +19678,11 @@ qemuDomainGetStatsVcpu(virQEMUDriverPtr driver,
         VIR_ALLOC_N(cpuwait, virDomainDefGetVcpus(dom->def)) < 0)
         goto cleanup;
 
-    if (HAVE_JOB(privflags) && virDomainObjIsActive(dom)) {
-        if (qemuDomainRefreshVcpuHalted(driver, dom,
-                                        QEMU_ASYNC_JOB_NONE) < 0) {
+    if (HAVE_JOB(privflags) && virDomainObjIsActive(dom) &&
+        qemuDomainRefreshVcpuHalted(driver, dom, QEMU_ASYNC_JOB_NONE) < 0) {
             /* it's ok to be silent and go ahead, because halted vcpu info
              * wasn't here from the beginning */
             virResetLastError();
-        } else {
-            vcpuhalted = true;
-        }
     }
 
     if (qemuDomainHelperGetVcpus(dom, cpuinfo, cpuwait,
@@ -19735,14 +19730,14 @@ qemuDomainGetStatsVcpu(virQEMUDriverPtr driver,
 
         vcpupriv = QEMU_DOMAIN_VCPU_PRIVATE(vcpu);
 
-        if (vcpuhalted) {
+        if (vcpupriv->halted != VIR_TRISTATE_BOOL_ABSENT) {
             snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH,
                      "vcpu.%u.halted", cpuinfo[i].number);
             if (virTypedParamsAddBoolean(&record->params,
                                          &record->nparams,
                                          maxparams,
                                          param_name,
-                                         vcpupriv->halted) < 0)
+                                         vcpupriv->halted == VIR_TRISTATE_BOOL_YES) < 0)
                 goto cleanup;
         }
     }