The virDomainHostdevSubsysSCSIVHostDefParseXML() function uses old style of parsing XML (virXMLPropString + str2enum conversion). Use virXMLPropEnumDefault() which encapsulates those steps. Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- src/conf/domain_conf.c | 19 +++++-------------- src/conf/domain_conf.h | 4 ++-- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index ded2c4aacf..561af84eed 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7262,24 +7262,15 @@ virDomainHostdevSubsysSCSIVHostDefParseXML(xmlNodePtr sourcenode, virDomainHostdevDef *def) { virDomainHostdevSubsysSCSIVHost *hostsrc = &def->source.subsys.u.scsi_host; - g_autofree char *protocol = NULL; g_autofree char *wwpn = NULL; - if (!(protocol = virXMLPropString(sourcenode, "protocol"))) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Missing scsi_host subsystem protocol")); + if (virXMLPropEnum(sourcenode, "protocol", + virDomainHostdevSubsysSCSIHostProtocolTypeFromString, + VIR_XML_PROP_NONZERO | VIR_XML_PROP_REQUIRED, + &hostsrc->protocol) < 0) return -1; - } - if ((hostsrc->protocol = - virDomainHostdevSubsysSCSIHostProtocolTypeFromString(protocol)) <= 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Unknown scsi_host subsystem protocol '%s'"), - protocol); - return -1; - } - - switch ((virDomainHostdevSubsysSCSIHostProtocolType) hostsrc->protocol) { + switch (hostsrc->protocol) { case VIR_DOMAIN_HOSTDEV_SUBSYS_SCSI_HOST_PROTOCOL_TYPE_VHOST: if (!(wwpn = virXMLPropString(sourcenode, "wwpn"))) { virReportError(VIR_ERR_XML_ERROR, "%s", diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 667845ac10..2f00cc7f79 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -287,7 +287,7 @@ struct _virDomainHostdevSubsysMediatedDev { }; typedef enum { - VIR_DOMAIN_HOSTDEV_SUBSYS_SCSI_HOST_PROTOCOL_TYPE_NONE, + VIR_DOMAIN_HOSTDEV_SUBSYS_SCSI_HOST_PROTOCOL_TYPE_NONE = 0, VIR_DOMAIN_HOSTDEV_SUBSYS_SCSI_HOST_PROTOCOL_TYPE_VHOST, VIR_DOMAIN_HOSTDEV_SUBSYS_SCSI_HOST_PROTOCOL_TYPE_LAST, @@ -307,7 +307,7 @@ typedef enum { VIR_ENUM_DECL(virDomainHostdevSubsysSCSIVHostModel); struct _virDomainHostdevSubsysSCSIVHost { - int protocol; /* enum virDomainHostdevSubsysSCSIHostProtocolType */ + virDomainHostdevSubsysSCSIHostProtocolType protocol; char *wwpn; virDomainHostdevSubsysSCSIVHostModelType model; }; -- 2.35.1