The virDomainHostdevSubsysSCSIVHostDefParseXML() function uses
old style of parsing XML (virXMLPropString + str2enum
conversion). Use virXMLPropEnumDefault() which encapsulates those
steps.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
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 f35fd080aa..bdf0ae06a8 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -7226,24 +7226,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 83bed11c29..9173c98d42 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