The @tickpolicy member of the _virDomainTimerDef struct stores values of the virDomainTimerTickpolicyType enum, or -1 for the default value (when user provided no value in XML). This is needlessly complicated. Introduce new value to the enum which reflects the default state. Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- src/conf/domain_conf.c | 19 ++++++------------- src/conf/domain_conf.h | 5 +++-- src/libxl/xen_common.c | 4 ++-- src/qemu/qemu_command.c | 6 +++--- src/qemu/qemu_validate.c | 6 +++--- 5 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index fbe21c4fd2..ec12c6d8dd 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1196,6 +1196,7 @@ VIR_ENUM_IMPL(virDomainTimerTrack, VIR_ENUM_IMPL(virDomainTimerTickpolicy, VIR_DOMAIN_TIMER_TICKPOLICY_LAST, + "none", "delay", "catchup", "merge", @@ -4970,7 +4971,7 @@ virDomainDefPostParseTimer(virDomainDef *def) if (timer->name == VIR_DOMAIN_TIMER_NAME_KVMCLOCK || timer->name == VIR_DOMAIN_TIMER_NAME_HYPERVCLOCK) { - if (timer->tickpolicy != -1) { + if (timer->tickpolicy) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("timer %s doesn't support setting of " "timer tickpolicy"), @@ -12023,10 +12024,9 @@ virDomainTimerDefParseXML(xmlNodePtr node, &def->present) < 0) goto error; - def->tickpolicy = -1; tickpolicy = virXMLPropString(node, "tickpolicy"); if (tickpolicy != NULL) { - if ((def->tickpolicy = virDomainTimerTickpolicyTypeFromString(tickpolicy)) < 0) { + if ((def->tickpolicy = virDomainTimerTickpolicyTypeFromString(tickpolicy)) <= 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown timer tickpolicy '%s'"), tickpolicy); goto error; @@ -26118,16 +26118,9 @@ virDomainTimerDefFormat(virBuffer *buf, virTristateBoolTypeToString(def->present)); } - if (def->tickpolicy != -1) { - const char *tickpolicy - = virDomainTimerTickpolicyTypeToString(def->tickpolicy); - if (!tickpolicy) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected timer tickpolicy %d"), - def->tickpolicy); - return -1; - } - virBufferAsprintf(buf, " tickpolicy='%s'", tickpolicy); + if (def->tickpolicy) { + virBufferAsprintf(buf, " tickpolicy='%s'", + virDomainTimerTickpolicyTypeToString(def->tickpolicy)); } if ((def->name == VIR_DOMAIN_TIMER_NAME_PLATFORM) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index f995cbc045..1ccc63706a 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2371,7 +2371,8 @@ typedef enum { } virDomainTimerTrackType; typedef enum { - VIR_DOMAIN_TIMER_TICKPOLICY_DELAY = 0, + VIR_DOMAIN_TIMER_TICKPOLICY_NONE = 0, + VIR_DOMAIN_TIMER_TICKPOLICY_DELAY, VIR_DOMAIN_TIMER_TICKPOLICY_CATCHUP, VIR_DOMAIN_TIMER_TICKPOLICY_MERGE, VIR_DOMAIN_TIMER_TICKPOLICY_DISCARD, @@ -2410,7 +2411,7 @@ struct _virDomainTimerCatchupDef { struct _virDomainTimerDef { int name; virTristateBool present; - int tickpolicy; /* none|catchup|merge|discard */ + int tickpolicy; /* enum virDomainTimerTickpolicyType */ virDomainTimerCatchupDef catchup; diff --git a/src/libxl/xen_common.c b/src/libxl/xen_common.c index 0679f441cc..4c8bf39ddc 100644 --- a/src/libxl/xen_common.c +++ b/src/libxl/xen_common.c @@ -554,7 +554,7 @@ xenParseHypervisorFeatures(virConf *conf, virDomainDef *def) timer = g_new0(virDomainTimerDef, 1); timer->name = VIR_DOMAIN_TIMER_NAME_TSC; timer->present = VIR_TRISTATE_BOOL_YES; - timer->tickpolicy = -1; + timer->tickpolicy = VIR_DOMAIN_TIMER_TICKPOLICY_NONE; timer->mode = VIR_DOMAIN_TIMER_MODE_AUTO; timer->track = -1; if (STREQ_NULLABLE(tscmode, "always_emulate")) @@ -630,7 +630,7 @@ xenParseHypervisorFeatures(virConf *conf, virDomainDef *def) } else { timer->present = VIR_TRISTATE_BOOL_NO; } - timer->tickpolicy = -1; + timer->tickpolicy = VIR_DOMAIN_TIMER_TICKPOLICY_NONE; timer->mode = -1; timer->track = -1; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index a62d3f36ae..f0429532f8 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -6206,7 +6206,7 @@ qemuBuildClockArgStr(virDomainClockDef *def) } switch (def->timers[i]->tickpolicy) { - case -1: + case VIR_DOMAIN_TIMER_TICKPOLICY_NONE: case VIR_DOMAIN_TIMER_TICKPOLICY_DELAY: /* This is the default - missed ticks delivered when next scheduled, at normal rate */ @@ -6269,7 +6269,7 @@ qemuBuildClockCommandLine(virCommand *cmd, case VIR_DOMAIN_TIMER_NAME_PIT: switch (def->clock.timers[i]->tickpolicy) { - case -1: + case VIR_DOMAIN_TIMER_TICKPOLICY_NONE: case VIR_DOMAIN_TIMER_TICKPOLICY_DELAY: /* delay is the default if we don't have kernel (kvm-pit), otherwise, the default is catchup. */ @@ -6659,7 +6659,7 @@ qemuBuildCpuCommandLine(virCommand *cmd, case VIR_DOMAIN_TIMER_TICKPOLICY_DISCARD: virBufferAddLit(&buf, ",kvm-no-adjvtime=on"); break; - case -1: + case VIR_DOMAIN_TIMER_TICKPOLICY_NONE: case VIR_DOMAIN_TIMER_TICKPOLICY_CATCHUP: case VIR_DOMAIN_TIMER_TICKPOLICY_MERGE: break; diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index b62e49a5bc..f52217497a 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -441,7 +441,7 @@ qemuValidateDomainDefClockTimers(const virDomainDef *def, } switch (timer->tickpolicy) { - case -1: + case VIR_DOMAIN_TIMER_TICKPOLICY_NONE: case VIR_DOMAIN_TIMER_TICKPOLICY_DELAY: /* This is the default - missed ticks delivered when next scheduled, at normal rate */ @@ -461,7 +461,7 @@ qemuValidateDomainDefClockTimers(const virDomainDef *def, case VIR_DOMAIN_TIMER_NAME_PIT: switch (timer->tickpolicy) { - case -1: + case VIR_DOMAIN_TIMER_TICKPOLICY_NONE: case VIR_DOMAIN_TIMER_TICKPOLICY_DELAY: case VIR_DOMAIN_TIMER_TICKPOLICY_DISCARD: break; @@ -523,7 +523,7 @@ qemuValidateDomainDefClockTimers(const virDomainDef *def, } switch (timer->tickpolicy) { - case -1: + case VIR_DOMAIN_TIMER_TICKPOLICY_NONE: case VIR_DOMAIN_TIMER_TICKPOLICY_DELAY: case VIR_DOMAIN_TIMER_TICKPOLICY_DISCARD: break; -- 2.34.1