Convert the field and adjust the XML parser to use
virXMLPropEnum().

Signed-off-by: Michal Privoznik <mpriv...@redhat.com>
---
 src/conf/domain_conf.c | 17 +++++------------
 src/conf/domain_conf.h |  4 ++--
 2 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index ef5f02a23b..65b7b44ccb 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6095,24 +6095,17 @@ 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"));
-        return -1;
-    }
 
-    if ((hostsrc->protocol =
-         virDomainHostdevSubsysSCSIHostProtocolTypeFromString(protocol)) <= 0) 
{
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("Unknown scsi_host subsystem protocol '%1$s'"),
-                       protocol);
+    if (virXMLPropEnum(sourcenode, "protocol",
+                       virDomainHostdevSubsysSCSIHostProtocolTypeFromString,
+                       VIR_XML_PROP_REQUIRED | VIR_XML_PROP_NONZERO,
+                       &hostsrc->protocol) < 0) {
         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 5cce60420f..d6d0799f63 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -290,7 +290,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,
@@ -310,7 +310,7 @@ typedef enum {
 VIR_ENUM_DECL(virDomainHostdevSubsysSCSIVHostModel);
 
 struct _virDomainHostdevSubsysSCSIVHost {
-    int protocol; /* enum virDomainHostdevSubsysSCSIHostProtocolType */
+    virDomainHostdevSubsysSCSIHostProtocolType protocol;
     char *wwpn;
     virDomainHostdevSubsysSCSIVHostModelType model;
 };
-- 
2.41.0

Reply via email to