]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: Fix type of @present in _virDomainTimerDef struct
authorMichal Privoznik <mprivozn@redhat.com>
Sun, 23 Jan 2022 20:15:10 +0000 (21:15 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 26 Jan 2022 09:49:18 +0000 (10:49 +0100)
In the _virDomainTimerDef structure we have @present member which
is like virTristateBool, except it's an integer and has values
shifted by one. This is harder to read. Retype the member to
virTristateBool which we are familiar with.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/conf/domain_conf.c
src/conf/domain_conf.h
src/libxl/libxl_conf.c
src/libxl/xen_common.c
src/lxc/lxc_cgroup.c
src/lxc/lxc_controller.c
src/qemu/qemu_command.c
src/qemu/qemu_validate.c

index 08b8e28c4e2e48198bf01cef7a1164bad55c1505..eeaea3dcb83885374b181b80ac8b83422ac714fd 100644 (file)
@@ -11999,7 +11999,6 @@ virDomainTimerDefParseXML(xmlNodePtr node,
     xmlNodePtr catchup;
     int ret;
     g_autofree char *name = NULL;
-    g_autofree char *present = NULL;
     g_autofree char *tickpolicy = NULL;
     g_autofree char *track = NULL;
     g_autofree char *mode = NULL;
@@ -12020,16 +12019,10 @@ virDomainTimerDefParseXML(xmlNodePtr node,
         goto error;
     }
 
-    def->present = -1; /* unspecified */
-    if ((present = virXMLPropString(node, "present")) != NULL) {
-        bool state = false;
-        if (virStringParseYesNo(present, &state) < 0) {
-            virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("unknown timer present value '%s'"), present);
-            goto error;
-        }
-        def->present = state ? 1 : 0;
-    }
+    if (virXMLPropTristateBool(node, "present",
+                               VIR_XML_PROP_NONE,
+                               &def->present) < 0)
+        goto error;
 
     def->tickpolicy = -1;
     tickpolicy = virXMLPropString(node, "tickpolicy");
@@ -20482,8 +20475,9 @@ virDomainTimerDefCheckABIStability(virDomainTimerDef *src,
 
     if (src->present != dst->present) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("Target timer presence %d does not match source %d"),
-                       dst->present, src->present);
+                       _("Target timer presence '%s' does not match source '%s'"),
+                       virTristateBoolTypeToString(dst->present),
+                       virTristateBoolTypeToString(src->present));
         return false;
     }
 
@@ -26120,10 +26114,9 @@ virDomainTimerDefFormat(virBuffer *buf,
     }
     virBufferAsprintf(buf, "<timer name='%s'", name);
 
-    if (def->present == 0) {
-        virBufferAddLit(buf, " present='no'");
-    } else if (def->present == 1) {
-        virBufferAddLit(buf, " present='yes'");
+    if (def->present != VIR_TRISTATE_BOOL_ABSENT) {
+        virBufferAsprintf(buf, " present='%s'",
+                          virTristateBoolTypeToString(def->present));
     }
 
     if (def->tickpolicy != -1) {
index 3768d82fef03664534adeca25c8493ac61354e32..b8089d90432d9d5cfeb5d588664849184d6c1a15 100644 (file)
@@ -2410,7 +2410,7 @@ struct _virDomainTimerCatchupDef {
 
 struct _virDomainTimerDef {
     int name;
-    int present;    /* unspecified = -1, no = 0, yes = 1 */
+    virTristateBool present;
     int tickpolicy; /* none|catchup|merge|discard */
 
     virDomainTimerCatchupDef catchup;
index 561171126c4e62c8e9d2c33c06a6e0f293b24d1f..5d87b999f2737cd77bccb0a12ce6d55b42392f92 100644 (file)
@@ -423,7 +423,7 @@ libxlMakeDomBuildInfo(virDomainDef *def,
                                virDomainTimerNameTypeToString(clock.timers[i]->name));
                 return -1;
             }
-            if (clock.timers[i]->present == 1)
+            if (clock.timers[i]->present == VIR_TRISTATE_BOOL_YES)
                 libxl_defbool_set(&b_info->u.hvm.hpet, 1);
             break;
 
index c3fa98b71dd860c249bbc584e3e8b2760467a23f..a8141d4f5ae990d92c0e5868e4ea7aed70526462 100644 (file)
@@ -553,7 +553,7 @@ xenParseHypervisorFeatures(virConf *conf, virDomainDef *def)
 
         timer = g_new0(virDomainTimerDef, 1);
         timer->name = VIR_DOMAIN_TIMER_NAME_TSC;
-        timer->present = 1;
+        timer->present = VIR_TRISTATE_BOOL_YES;
         timer->tickpolicy = -1;
         timer->mode = VIR_DOMAIN_TIMER_MODE_AUTO;
         timer->track = -1;
@@ -625,7 +625,7 @@ xenParseHypervisorFeatures(virConf *conf, virDomainDef *def)
 
             timer = g_new0(virDomainTimerDef, 1);
             timer->name = VIR_DOMAIN_TIMER_NAME_HPET;
-            timer->present = val;
+            timer->present = virTristateBoolFromBool(val);
             timer->tickpolicy = -1;
             timer->mode = -1;
             timer->track = -1;
@@ -2112,9 +2112,10 @@ xenFormatHypervisorFeatures(virConf *conf, virDomainDef *def)
 
         case VIR_DOMAIN_TIMER_NAME_HPET:
             if (hvm) {
-                int enable_hpet = def->clock.timers[i]->present != 0;
+                int enable_hpet = def->clock.timers[i]->present != VIR_TRISTATE_BOOL_NO;
 
-                /* disable hpet if 'present' is 0, enable otherwise */
+                /* disable hpet if 'present' is VIR_TRISTATE_BOOL_NO, enable
+                 * otherwise */
                 if (xenConfigSetInt(conf, "hpet", enable_hpet) < 0)
                     return -1;
             } else {
index 736b2000ff86aef5db393c3abbb282b96d0b042b..d31fff5f98dfecd086a43ccf1afb6d5ec6c10870 100644 (file)
@@ -332,7 +332,7 @@ static int virLXCCgroupSetupDeviceACL(virDomainDef *def,
         const char *dev = NULL;
 
         /* Check if "present" is set to "no" otherwise enable it. */
-        if (!timer->present)
+        if (timer->present == VIR_TRISTATE_BOOL_NO)
             continue;
 
         switch ((virDomainTimerNameType)timer->name) {
index 3c930eaacdee0daee47d5d0a2547205e24935225..c4e3b667511f36b0c397b2c1c30f4104bd6e2fa6 100644 (file)
@@ -1510,7 +1510,7 @@ virLXCControllerSetupTimers(virLXCController *ctrl)
         dev_t dev;
 
         /* Check if "present" is set to "no" otherwise enable it. */
-        if (!timer->present)
+        if (timer->present == VIR_TRISTATE_BOOL_NO)
             continue;
 
         switch ((virDomainTimerNameType)timer->name) {
index 2a1fe272976fa1169838064e029d0fc1f9c80571..afbce8921c7474e86c05c62f4e0307504ff600b0 100644 (file)
@@ -6293,15 +6293,14 @@ qemuBuildClockCommandLine(virCommand *cmd,
             break;
 
         case VIR_DOMAIN_TIMER_NAME_HPET:
-            /* the only meaningful attribute for hpet is "present". If
-             * present is -1, that means it wasn't specified, and
-             * should be left at the default for the
-             * hypervisor. "default" when -no-hpet exists is "yes",
-             * and when -no-hpet doesn't exist is "no". "confusing"?
-             * "yes"! */
+            /* the only meaningful attribute for hpet is "present". If present
+             * is VIR_TRISTATE_BOOL_ABSENT, that means it wasn't specified, and
+             * should be left at the default for the hypervisor. "default" when
+             * -no-hpet exists is VIR_TRISTATE_BOOL_YES, and when -no-hpet
+             *  doesn't exist is VIR_TRISTATE_BOOL_NO. "confusing"?  "yes"! */
 
             if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_NO_HPET)) {
-                if (def->clock.timers[i]->present == 0)
+                if (def->clock.timers[i]->present == VIR_TRISTATE_BOOL_NO)
                     virCommandAddArg(cmd, "-no-hpet");
             }
             break;
@@ -6638,13 +6637,14 @@ qemuBuildCpuCommandLine(virCommand *cmd,
 
         switch ((virDomainTimerNameType)timer->name) {
         case VIR_DOMAIN_TIMER_NAME_KVMCLOCK:
-            if (timer->present != -1) {
+            if (timer->present != VIR_TRISTATE_BOOL_ABSENT) {
+                /* QEMU expects on/off -> virTristateSwitch. */
                 virBufferAsprintf(&buf, ",kvmclock=%s",
-                                  timer->present ? "on" : "off");
+                                  virTristateSwitchTypeToString(timer->present));
             }
             break;
         case VIR_DOMAIN_TIMER_NAME_HYPERVCLOCK:
-            if (timer->present == 1)
+            if (timer->present == VIR_TRISTATE_BOOL_YES)
                 virBufferAddLit(&buf, ",hv-time=on");
             break;
         case VIR_DOMAIN_TIMER_NAME_TSC:
index 0a879f011528ec2707b520c89f2db570ffcdd6b2..b62e49a5bcd15965a97a8a0f4061acd11e3f6caf 100644 (file)
@@ -411,7 +411,7 @@ qemuValidateDomainDefClockTimers(const virDomainDef *def,
         case VIR_DOMAIN_TIMER_NAME_TSC:
         case VIR_DOMAIN_TIMER_NAME_KVMCLOCK:
         case VIR_DOMAIN_TIMER_NAME_HYPERVCLOCK:
-            if (!ARCH_IS_X86(def->os.arch) && timer->present == 1) {
+            if (!ARCH_IS_X86(def->os.arch) && timer->present == VIR_TRISTATE_BOOL_YES) {
                 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                                _("Configuring the '%s' timer is not supported "
                                  "for virtType=%s arch=%s machine=%s guests"),
@@ -489,7 +489,7 @@ qemuValidateDomainDefClockTimers(const virDomainDef *def,
             /* no hpet timer available. The only possible action
               is to raise an error if present="yes" */
             if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_NO_HPET) &&
-                timer->present == 1) {
+                timer->present == VIR_TRISTATE_BOOL_YES) {
                 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                                "%s", _("hpet timer is not supported"));
                 return -1;
@@ -508,7 +508,7 @@ qemuValidateDomainDefClockTimers(const virDomainDef *def,
                                def->os.machine);
                 return -1;
             }
-            if (timer->present == 0) {
+            if (timer->present == VIR_TRISTATE_BOOL_NO) {
                 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                                _("The '%s' timer can't be disabled"),
                                virDomainTimerNameTypeToString(timer->name));