Use the appropriate type for the variable and refactor the XML parser to parse it correctly using virXMLPropEnum. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/conf/domain_conf.c | 18 ++++-------------- src/conf/domain_conf.h | 2 +- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 0128c9d480..0bb58ccb5f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -9343,7 +9343,6 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt, g_autofree char *target = NULL; g_autofree char *bus = NULL; g_autofree char *serial = NULL; - g_autofree char *startupPolicy = NULL; g_autofree char *removable = NULL; g_autofree char *logical_block_size = NULL; g_autofree char *physical_block_size = NULL; @@ -9401,7 +9400,10 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt, source = true; - startupPolicy = virXMLPropString(cur, "startupPolicy"); + if (virXMLPropEnum(cur, "startupPolicy", + virDomainStartupPolicyTypeFromString, + VIR_XML_PROP_OPTIONAL, &def->startupPolicy) < 0) + return NULL; if (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE) && (tmp = virXMLPropString(cur, "index")) && @@ -9655,18 +9657,6 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt, return NULL; } - if (startupPolicy) { - int val; - - if ((val = virDomainStartupPolicyTypeFromString(startupPolicy)) <= 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown startupPolicy value '%s'"), - startupPolicy); - return NULL; - } - def->startupPolicy = val; - } - def->dst = g_steal_pointer(&target); if (authdef) { /* If we've already parsed <source> and found an <auth> child, diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 2f8ef74020..99ab2a96d9 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -573,7 +573,7 @@ struct _virDomainDiskDef { virTristateSwitch event_idx; virTristateSwitch copy_on_read; int snapshot; /* virDomainSnapshotLocation, snapshot_conf.h */ - int startupPolicy; /* enum virDomainStartupPolicy */ + virDomainStartupPolicy startupPolicy; bool transient; virDomainDeviceInfo info; int rawio; /* enum virTristateBool */ -- 2.30.2