1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-20 07:59:00 +00:00

conf: Fix type of @present in _virDomainTimerDef struct

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>
This commit is contained in:
Michal Privoznik 2022-01-23 21:15:10 +01:00
parent 9198b7090b
commit 754a7f6c94
8 changed files with 32 additions and 38 deletions

View 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) {

View 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;

View 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;

View 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 {

View 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) {

View 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) {

View 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:

View 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));