The @mode member of the _virDomainTimerDef struct stores
values of the virDomainTimerModeType 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(a)redhat.com>
---
src/conf/domain_conf.c | 19 ++++++-------------
src/conf/domain_conf.h | 5 +++--
src/libxl/xen_common.c | 2 +-
3 files changed, 10 insertions(+), 16 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 848efa30b8..c0851f4f60 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1206,6 +1206,7 @@ VIR_ENUM_IMPL(virDomainTimerTickpolicy,
VIR_ENUM_IMPL(virDomainTimerMode,
VIR_DOMAIN_TIMER_MODE_LAST,
+ "none",
"auto",
"native",
"emulate",
@@ -5000,7 +5001,7 @@ virDomainDefPostParseTimer(virDomainDef *def)
return -1;
}
- if (timer->mode != -1) {
+ if (timer->mode) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("timer %s doesn't support setting of "
"timer mode"),
@@ -12052,10 +12053,9 @@ virDomainTimerDefParseXML(xmlNodePtr node,
goto error;
}
- def->mode = -1;
mode = virXMLPropString(node, "mode");
if (mode != NULL) {
- if ((def->mode = virDomainTimerModeTypeFromString(mode)) < 0) {
+ if ((def->mode = virDomainTimerModeTypeFromString(mode)) <= 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown timer mode '%s'"), mode);
goto error;
@@ -26132,16 +26132,9 @@ virDomainTimerDefFormat(virBuffer *buf,
if (def->frequency > 0)
virBufferAsprintf(buf, " frequency='%llu'",
def->frequency);
- if (def->mode != -1) {
- const char *mode
- = virDomainTimerModeTypeToString(def->mode);
- if (!mode) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("unexpected timer mode %d"),
- def->mode);
- return -1;
- }
- virBufferAsprintf(buf, " mode='%s'", mode);
+ if (def->mode) {
+ virBufferAsprintf(buf, " mode='%s'",
+ virDomainTimerModeTypeToString(def->mode));
}
}
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 17ebface32..6291587ac4 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2382,7 +2382,8 @@ typedef enum {
} virDomainTimerTickpolicyType;
typedef enum {
- VIR_DOMAIN_TIMER_MODE_AUTO = 0,
+ VIR_DOMAIN_TIMER_MODE_NONE = 0,
+ VIR_DOMAIN_TIMER_MODE_AUTO,
VIR_DOMAIN_TIMER_MODE_NATIVE,
VIR_DOMAIN_TIMER_MODE_EMULATE,
VIR_DOMAIN_TIMER_MODE_PARAVIRT,
@@ -2421,7 +2422,7 @@ struct _virDomainTimerDef {
/* frequency & mode are only valid for name='tsc' */
unsigned long long frequency; /* in Hz, unspecified = 0 */
- int mode; /* auto|native|emulate|paravirt */
+ int mode; /* enum virDomainTimerModeType */
};
typedef enum {
diff --git a/src/libxl/xen_common.c b/src/libxl/xen_common.c
index 78f3b78ac8..5a1fab857f 100644
--- a/src/libxl/xen_common.c
+++ b/src/libxl/xen_common.c
@@ -631,7 +631,7 @@ xenParseHypervisorFeatures(virConf *conf, virDomainDef *def)
timer->present = VIR_TRISTATE_BOOL_NO;
}
timer->tickpolicy = VIR_DOMAIN_TIMER_TICKPOLICY_NONE;
- timer->mode = -1;
+ timer->mode = VIR_DOMAIN_TIMER_MODE_NONE;
timer->track = VIR_DOMAIN_TIMER_TRACK_NONE;
def->clock.timers[def->clock.ntimers - 1] = timer;
--
2.34.1