The @track member of the _virDomainTimerDef struct stores values of the virDomainTimerTrackType 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 | 22 ++++++---------------- src/conf/domain_conf.h | 5 +++-- src/libxl/xen_common.c | 4 ++-- src/qemu/qemu_command.c | 2 +- src/qemu/qemu_validate.c | 2 +- 5 files changed, 13 insertions(+), 22 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index ec12c6d8dd..848efa30b8 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1188,6 +1188,7 @@ VIR_ENUM_IMPL(virDomainTimerName, VIR_ENUM_IMPL(virDomainTimerTrack, VIR_DOMAIN_TIMER_TRACK_LAST, + "none", "boot", "guest", "wall", @@ -5010,7 +5011,7 @@ virDomainDefPostParseTimer(virDomainDef *def) if (timer->name != VIR_DOMAIN_TIMER_NAME_PLATFORM && timer->name != VIR_DOMAIN_TIMER_NAME_RTC) { - if (timer->track != -1) { + if (timer->track != VIR_DOMAIN_TIMER_TRACK_NONE) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("timer %s doesn't support setting of " "timer track"), @@ -12033,10 +12034,9 @@ virDomainTimerDefParseXML(xmlNodePtr node, } } - def->track = -1; track = virXMLPropString(node, "track"); if (track != NULL) { - if ((def->track = virDomainTimerTrackTypeFromString(track)) < 0) { + if ((def->track = virDomainTimerTrackTypeFromString(track)) <= 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown timer track '%s'"), track); goto error; @@ -26123,19 +26123,9 @@ virDomainTimerDefFormat(virBuffer *buf, virDomainTimerTickpolicyTypeToString(def->tickpolicy)); } - if ((def->name == VIR_DOMAIN_TIMER_NAME_PLATFORM) - || (def->name == VIR_DOMAIN_TIMER_NAME_RTC)) { - if (def->track != -1) { - const char *track - = virDomainTimerTrackTypeToString(def->track); - if (!track) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected timer track %d"), - def->track); - return -1; - } - virBufferAsprintf(buf, " track='%s'", track); - } + if (def->track != VIR_DOMAIN_TIMER_TRACK_NONE) { + virBufferAsprintf(buf, " track='%s'", + virDomainTimerTrackTypeToString(def->track)); } if (def->name == VIR_DOMAIN_TIMER_NAME_TSC) { diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 1ccc63706a..17ebface32 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2362,7 +2362,8 @@ typedef enum { } virDomainTimerNameType; typedef enum { - VIR_DOMAIN_TIMER_TRACK_BOOT = 0, + VIR_DOMAIN_TIMER_TRACK_NONE = 0, + VIR_DOMAIN_TIMER_TRACK_BOOT, VIR_DOMAIN_TIMER_TRACK_GUEST, VIR_DOMAIN_TIMER_TRACK_WALL, VIR_DOMAIN_TIMER_TRACK_REALTIME, @@ -2416,7 +2417,7 @@ struct _virDomainTimerDef { virDomainTimerCatchupDef catchup; /* track is only valid for name='platform|rtc' */ - int track; /* boot|guest|wall */ + int track; /* enum virDomainTimerTrackType */ /* frequency & mode are only valid for name='tsc' */ unsigned long long frequency; /* in Hz, unspecified = 0 */ diff --git a/src/libxl/xen_common.c b/src/libxl/xen_common.c index 4c8bf39ddc..78f3b78ac8 100644 --- a/src/libxl/xen_common.c +++ b/src/libxl/xen_common.c @@ -556,7 +556,7 @@ xenParseHypervisorFeatures(virConf *conf, virDomainDef *def) timer->present = VIR_TRISTATE_BOOL_YES; timer->tickpolicy = VIR_DOMAIN_TIMER_TICKPOLICY_NONE; timer->mode = VIR_DOMAIN_TIMER_MODE_AUTO; - timer->track = -1; + timer->track = VIR_DOMAIN_TIMER_TRACK_NONE; if (STREQ_NULLABLE(tscmode, "always_emulate")) timer->mode = VIR_DOMAIN_TIMER_MODE_EMULATE; else if (STREQ_NULLABLE(tscmode, "native")) @@ -632,7 +632,7 @@ xenParseHypervisorFeatures(virConf *conf, virDomainDef *def) } timer->tickpolicy = VIR_DOMAIN_TIMER_TICKPOLICY_NONE; timer->mode = -1; - timer->track = -1; + timer->track = VIR_DOMAIN_TIMER_TRACK_NONE; def->clock.timers[def->clock.ntimers - 1] = timer; } diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index f0429532f8..bd32921c04 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -6190,7 +6190,7 @@ qemuBuildClockArgStr(virDomainClockDef *def) for (i = 0; i < def->ntimers; i++) { if (def->timers[i]->name == VIR_DOMAIN_TIMER_NAME_RTC) { switch (def->timers[i]->track) { - case -1: /* unspecified - use hypervisor default */ + case VIR_DOMAIN_TIMER_TRACK_NONE: /* unspecified - use hypervisor default */ break; case VIR_DOMAIN_TIMER_TRACK_BOOT: return NULL; diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index f52217497a..3bf39f8d93 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -428,7 +428,7 @@ qemuValidateDomainDefClockTimers(const virDomainDef *def, case VIR_DOMAIN_TIMER_NAME_RTC: switch (timer->track) { - case -1: /* unspecified - use hypervisor default */ + case VIR_DOMAIN_TIMER_TRACK_NONE: /* unspecified - use hypervisor default */ case VIR_DOMAIN_TIMER_TRACK_GUEST: case VIR_DOMAIN_TIMER_TRACK_WALL: case VIR_DOMAIN_TIMER_TRACK_REALTIME: -- 2.34.1