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;
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");
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;
}
}
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) {
struct _virDomainTimerDef {
int name;
- int present; /* unspecified = -1, no = 0, yes = 1 */
+ virTristateBool present;
int tickpolicy; /* none|catchup|merge|discard */
virDomainTimerCatchupDef catchup;
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;
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;
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;
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 {
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) {
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) {
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;
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:
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"),
/* 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;
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));