The virDomainHostdevSubsysSCSIDefParseXML() function uses old
style of parsing XML (virXMLPropString + str2enum conversion).
Use virXMLPropEnumDefault() which encapsulates those steps.

Signed-off-by: Michal Privoznik <mpriv...@redhat.com>
---
 src/conf/domain_conf.c   | 19 ++++++-------------
 src/conf/domain_conf.h   |  2 +-
 src/qemu/qemu_command.c  |  4 ++--
 src/qemu/qemu_domain.c   |  4 ++--
 src/qemu/qemu_driver.c   |  2 +-
 src/qemu/qemu_process.c  |  2 +-
 tests/qemuxml2argvtest.c |  2 +-
 7 files changed, 14 insertions(+), 21 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 17ac74abcd..ded2c4aacf 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -7233,20 +7233,13 @@ virDomainHostdevSubsysSCSIDefParseXML(xmlNodePtr 
sourcenode,
                                       unsigned int flags,
                                       virDomainXMLOption *xmlopt)
 {
-    g_autofree char *protocol = NULL;
+    if (virXMLPropEnum(sourcenode, "protocol",
+                       virDomainHostdevSubsysSCSIProtocolTypeFromString,
+                       VIR_XML_PROP_NONE,
+                       &scsisrc->protocol) < 0)
+        return -1;
 
-    if ((protocol = virXMLPropString(sourcenode, "protocol"))) {
-        scsisrc->protocol =
-            virDomainHostdevSubsysSCSIProtocolTypeFromString(protocol);
-        if (scsisrc->protocol < 0) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("Unknown SCSI subsystem protocol '%s'"),
-                           protocol);
-            return -1;
-        }
-    }
-
-    switch ((virDomainHostdevSCSIProtocolType) scsisrc->protocol) {
+    switch (scsisrc->protocol) {
     case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_NONE:
         return virDomainHostdevSubsysSCSIHostDefParseXML(sourcenode, ctxt, 
scsisrc,
                                                          flags, xmlopt);
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index f325bfb51e..667845ac10 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -270,7 +270,7 @@ typedef enum {
 } virDomainDeviceSGIO;
 
 struct _virDomainHostdevSubsysSCSI {
-    int protocol; /* enum virDomainHostdevSCSIProtocolType */
+    virDomainHostdevSCSIProtocolType protocol;
     virDomainDeviceSGIO sgio;
     virTristateBool rawio;
     union {
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index dac8aabad4..5ea88bf239 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -5284,7 +5284,7 @@ qemuBuildHostdevSCSIDetachPrepare(virDomainHostdevDef 
*hostdev,
         virStorageSource *src;
         qemuDomainStorageSourcePrivate *srcpriv;
 
-        switch ((virDomainHostdevSCSIProtocolType) scsisrc->protocol) {
+        switch (scsisrc->protocol) {
         case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_NONE:
             src = scsisrc->u.host.src;
             break;
@@ -5325,7 +5325,7 @@ qemuBuildHostdevSCSIAttachPrepare(virDomainHostdevDef 
*hostdev,
     virStorageSource *src = NULL;
 
     if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV_HOSTDEV_SCSI)) {
-        switch ((virDomainHostdevSCSIProtocolType) scsisrc->protocol) {
+        switch (scsisrc->protocol) {
         case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_NONE:
             src = scsisrc->u.host.src;
             break;
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 948ab76304..30ef5b7550 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -5731,7 +5731,7 @@ 
qemuDomainDeviceHostdevDefPostParseRestoreBackendAlias(virDomainHostdevDef *host
         !virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV_HOSTDEV_SCSI))
         return 0;
 
-    switch ((virDomainHostdevSCSIProtocolType) scsisrc->protocol) {
+    switch (scsisrc->protocol) {
     case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_NONE:
         if (!scsisrc->u.host.src)
             scsisrc->u.host.src = virStorageSourceNew();
@@ -10961,7 +10961,7 @@ qemuDomainPrepareHostdev(virDomainHostdevDef *hostdev,
         virDomainHostdevSubsysSCSI *scsisrc = &hostdev->source.subsys.u.scsi;
         virStorageSource *src = NULL;
 
-        switch ((virDomainHostdevSCSIProtocolType) scsisrc->protocol) {
+        switch (scsisrc->protocol) {
         case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_NONE:
             virObjectUnref(scsisrc->u.host.src);
             scsisrc->u.host.src = virStorageSourceNew();
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 1d50aa5271..f0be25a12d 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -6284,7 +6284,7 @@ 
qemuConnectDomainXMLToNativePrepareHostHostdev(virDomainHostdevDef *hostdev)
     if (virHostdevIsSCSIDevice(hostdev)) {
         virDomainHostdevSubsysSCSI *scsisrc = &hostdev->source.subsys.u.scsi;
 
-        switch ((virDomainHostdevSCSIProtocolType) scsisrc->protocol) {
+        switch (scsisrc->protocol) {
         case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_NONE: {
             virDomainHostdevSubsysSCSIHost *scsihostsrc = &scsisrc->u.host;
             virStorageSource *src = scsisrc->u.host.src;
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 033d3d5bc6..929986745e 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -6368,7 +6368,7 @@ qemuProcessPrepareHostHostdev(virDomainHostdevDef 
*hostdev)
     if (virHostdevIsSCSIDevice(hostdev)) {
         virDomainHostdevSubsysSCSI *scsisrc = &hostdev->source.subsys.u.scsi;
 
-        switch ((virDomainHostdevSCSIProtocolType) scsisrc->protocol) {
+        switch (scsisrc->protocol) {
         case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_NONE: {
             virDomainHostdevSubsysSCSIHost *scsihostsrc = &scsisrc->u.host;
             virStorageSource *src = scsisrc->u.host.src;
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index aadfaddc17..4a5da784fa 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -425,7 +425,7 @@ testCompareXMLToArgvCreateArgs(virQEMUDriver *drv,
         if (virHostdevIsSCSIDevice(hostdev)) {
             virDomainHostdevSubsysSCSI *scsisrc = 
&hostdev->source.subsys.u.scsi;
 
-            switch ((virDomainHostdevSCSIProtocolType) scsisrc->protocol) {
+            switch (scsisrc->protocol) {
             case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_NONE:
                 scsisrc->u.host.src->path = g_strdup("/dev/sg0");
                 break;
-- 
2.35.1

Reply via email to