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 | 13 +++---------- src/conf/domain_conf.h | 2 +- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 858ef5db9d..0128c9d480 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -9344,7 +9344,6 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt, g_autofree char *bus = NULL; g_autofree char *serial = NULL; g_autofree char *startupPolicy = NULL; - g_autofree char *tray = NULL; g_autofree char *removable = NULL; g_autofree char *logical_block_size = NULL; g_autofree char *physical_block_size = NULL; @@ -9415,7 +9414,9 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt, virXMLNodeNameEqual(cur, "target")) { target = virXMLPropString(cur, "dev"); bus = virXMLPropString(cur, "bus"); - tray = virXMLPropString(cur, "tray"); + if (virXMLPropEnum(cur, "tray", virDomainDiskTrayTypeFromString, + VIR_XML_PROP_OPTIONAL, &def->tray_status) < 0) + return NULL; removable = virXMLPropString(cur, "removable"); rotation_rate = virXMLPropString(cur, "rotation_rate"); @@ -9634,14 +9635,6 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt, } } - if (tray) { - if ((def->tray_status = virDomainDiskTrayTypeFromString(tray)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown disk tray status '%s'"), tray); - return NULL; - } - } - if (removable) { if ((def->removable = virTristateSwitchTypeFromString(removable)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index f610e78e3a..2f8ef74020 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -537,7 +537,7 @@ struct _virDomainDiskDef { int device; /* enum virDomainDiskDevice */ int bus; /* enum virDomainDiskBus */ char *dst; - int tray_status; /* enum virDomainDiskTray */ + virDomainDiskTray tray_status; int removable; /* enum virTristateSwitch */ unsigned int rotation_rate; -- 2.30.2