The virDomainHostdevSubsysSCSIDefParseXML() 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 | 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 451221624e..f35fd080aa 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -7197,20 +7197,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 694491cd63..83bed11c29 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 faf18fd6a8..8eda740571 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -5293,7 +5293,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;
@@ -5334,7 +5334,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 8d40e1801b..15f753b0fc 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -5724,7 +5724,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();
@@ -10996,7 +10996,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 7cc2278c65..76d2c52845 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -6162,7 +6162,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 995737ce86..8c19b812da 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -6310,7 +6310,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 ed41b7a7a2..7bf1379e76 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -424,7 +424,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