[PATCH 12/12] conf: Convert virDomainHostdevDefParseXMLSubsys() to virXMLProp*()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



After previous cleanups, the virDomainHostdevDefParseXMLSubsys()
function uses a mixture of virXMLProp*() and the old
virXMLPropString() + virXXXTypeFromString() patterns. Rework it
so that virXMLProp*() is used.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/conf/domain_conf.c        | 60 ++++++++++++-----------------------
 src/conf/domain_conf.h        | 26 +++++++--------
 src/qemu/qemu_command.c       |  4 +--
 src/qemu/qemu_hostdev.c       |  4 +--
 src/qemu/qemu_hotplug.c       |  3 +-
 src/qemu/qemu_validate.c      |  2 +-
 src/security/virt-aa-helper.c |  2 +-
 7 files changed, 42 insertions(+), 59 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index a25beaee3e..f97bd7bf22 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -7293,14 +7293,12 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
                                   virDomainXMLOption *xmlopt)
 {
     xmlNodePtr sourcenode;
-    int backend;
+    xmlNodePtr driver_node = NULL;
     virDomainHostdevSubsysPCI *pcisrc = &def->source.subsys.u.pci;
     virDomainHostdevSubsysSCSI *scsisrc = &def->source.subsys.u.scsi;
     virDomainHostdevSubsysSCSIVHost *scsihostsrc = &def->source.subsys.u.scsi_host;
     virDomainHostdevSubsysMediatedDev *mdevsrc = &def->source.subsys.u.mdev;
     virTristateBool managed;
-    g_autofree char *sgio = NULL;
-    g_autofree char *backendStr = NULL;
     g_autofree char *model = NULL;
     int rv;
 
@@ -7313,7 +7311,6 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
                                         VIR_XML_PROP_NONE, &managed));
     virTristateBoolToBool(managed, &def->managed);
 
-    sgio = virXMLPropString(node, "sgio");
     model = virXMLPropString(node, "model");
 
     /* @type is passed in from the caller rather than read from the
@@ -7352,18 +7349,17 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
         return -1;
     }
 
-    if (sgio) {
+    if ((rv = virXMLPropEnum(node, "sgio",
+                             virDomainDeviceSGIOTypeFromString,
+                             VIR_XML_PROP_NONZERO,
+                             &scsisrc->sgio)) < 0) {
+        return -1;
+    } else if (rv > 0) {
         if (def->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI) {
             virReportError(VIR_ERR_XML_ERROR, "%s",
                            _("sgio is only supported for scsi host device"));
             return -1;
         }
-
-        if ((scsisrc->sgio = virDomainDeviceSGIOTypeFromString(sgio)) <= 0) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("unknown sgio mode '%s'"), sgio);
-            return -1;
-        }
     }
 
     if ((rv = virXMLPropTristateBool(node, "rawio",
@@ -7389,27 +7385,17 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
     }
 
     if (def->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST) {
-        if (model &&
-            ((scsihostsrc->model = virDomainHostdevSubsysSCSIVHostModelTypeFromString(model)) < 0)) {
-            virReportError(VIR_ERR_XML_ERROR,
-                           _("unknown hostdev model '%s'"),
-                           model);
+        if (virXMLPropEnum(node, "model",
+                           virDomainHostdevSubsysSCSIVHostModelTypeFromString,
+                           VIR_XML_PROP_NONE,
+                           &scsihostsrc->model) < 0)
             return -1;
-        }
     } else if (def->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV) {
-        if (!model) {
-            virReportError(VIR_ERR_XML_ERROR, "%s",
-                           _("Missing 'model' attribute in mediated device's "
-                             "<hostdev> element"));
+        if (virXMLPropEnum(node, "model",
+                           virMediatedDeviceModelTypeFromString,
+                           VIR_XML_PROP_REQUIRED,
+                           &mdevsrc->model) < 0)
             return -1;
-        }
-
-        if ((mdevsrc->model = virMediatedDeviceModelTypeFromString(model)) < 0) {
-            virReportError(VIR_ERR_XML_ERROR,
-                           _("unknown hostdev model '%s'"),
-                           model);
-            return -1;
-        }
 
         if (virXMLPropTristateSwitch(node, "display",
                                      VIR_XML_PROP_NONE,
@@ -7427,16 +7413,12 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
         if (virDomainHostdevSubsysPCIDefParseXML(sourcenode, ctxt, def, flags) < 0)
             return -1;
 
-        backend = VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT;
-        if ((backendStr = virXPathString("string(./driver/@name)", ctxt)) &&
-            (((backend = virDomainHostdevSubsysPCIBackendTypeFromString(backendStr)) < 0) ||
-             backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT)) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("Unknown PCI device <driver name='%s'/> "
-                             "has been specified"), backendStr);
+        driver_node = virXPathNode("./driver", ctxt);
+        if (virXMLPropEnum(driver_node, "name",
+                           virDomainHostdevSubsysPCIBackendTypeFromString,
+                           VIR_XML_PROP_NONZERO,
+                           &pcisrc->backend) < 0)
             return -1;
-        }
-        pcisrc->backend = backend;
 
         break;
 
@@ -30564,7 +30546,7 @@ virDomainNetDefActualToNetworkPort(virDomainDef *dom,
         }
         port->plug.hostdevpci.managed = virTristateBoolFromBool(actual->data.hostdev.def.managed);
         port->plug.hostdevpci.addr = actual->data.hostdev.def.source.subsys.u.pci.addr;
-        switch ((virDomainHostdevSubsysPCIBackendType)actual->data.hostdev.def.source.subsys.u.pci.backend) {
+        switch (actual->data.hostdev.def.source.subsys.u.pci.backend) {
         case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT:
             port->plug.hostdevpci.driver = VIR_NETWORK_FORWARD_DRIVER_NAME_DEFAULT;
             break;
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 8a4d7b6f99..3e63d2513b 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -214,7 +214,7 @@ typedef enum {
 
 /* the backend driver used for PCI hostdev devices */
 typedef enum {
-    VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT, /* detect automatically, prefer VFIO */
+    VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT = 0, /* detect automatically, prefer VFIO */
     VIR_DOMAIN_HOSTDEV_PCI_BACKEND_KVM,    /* force legacy kvm style */
     VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO,   /* force vfio */
     VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN,    /* force legacy xen style, use pciback */
@@ -245,7 +245,7 @@ struct _virDomainHostdevSubsysUSB {
 
 struct _virDomainHostdevSubsysPCI {
     virPCIDeviceAddress addr; /* host address */
-    int backend; /* enum virDomainHostdevSubsysPCIBackendType */
+    virDomainHostdevSubsysPCIBackendType backend;
 };
 
 struct _virDomainHostdevSubsysSCSIHost {
@@ -260,9 +260,17 @@ struct _virDomainHostdevSubsysSCSIiSCSI {
     virStorageSource *src;
 };
 
+typedef enum {
+    VIR_DOMAIN_DEVICE_SGIO_DEFAULT = 0,
+    VIR_DOMAIN_DEVICE_SGIO_FILTERED,
+    VIR_DOMAIN_DEVICE_SGIO_UNFILTERED,
+
+    VIR_DOMAIN_DEVICE_SGIO_LAST
+} virDomainDeviceSGIO;
+
 struct _virDomainHostdevSubsysSCSI {
     int protocol; /* enum virDomainHostdevSCSIProtocolType */
-    int sgio; /* enum virDomainDeviceSGIO */
+    virDomainDeviceSGIO sgio;
     virTristateBool rawio;
     union {
         virDomainHostdevSubsysSCSIHost host;
@@ -271,7 +279,7 @@ struct _virDomainHostdevSubsysSCSI {
 };
 
 struct _virDomainHostdevSubsysMediatedDev {
-    int model;                          /* enum virMediatedDeviceModelType */
+    virMediatedDeviceModelType model;
     virTristateSwitch display;
     char uuidstr[VIR_UUID_STRING_BUFLEN];   /* mediated device's uuid string */
     virTristateSwitch ramfb;
@@ -300,7 +308,7 @@ VIR_ENUM_DECL(virDomainHostdevSubsysSCSIVHostModel);
 struct _virDomainHostdevSubsysSCSIVHost {
     int protocol; /* enum virDomainHostdevSubsysSCSIHostProtocolType */
     char *wwpn;
-    int model; /* enum virDomainHostdevSubsysSCSIVHostModelType */
+    virDomainHostdevSubsysSCSIVHostModelType model;
 };
 
 struct _virDomainHostdevSubsys {
@@ -449,14 +457,6 @@ typedef enum {
     VIR_DOMAIN_DISK_IO_LAST
 } virDomainDiskIo;
 
-typedef enum {
-    VIR_DOMAIN_DEVICE_SGIO_DEFAULT = 0,
-    VIR_DOMAIN_DEVICE_SGIO_FILTERED,
-    VIR_DOMAIN_DEVICE_SGIO_UNFILTERED,
-
-    VIR_DOMAIN_DEVICE_SGIO_LAST
-} virDomainDeviceSGIO;
-
 typedef enum {
     VIR_DOMAIN_DISK_DISCARD_DEFAULT = 0,
     VIR_DOMAIN_DISK_DISCARD_UNMAP,
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 99ac44d7f1..f5d7cd2c1b 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -4967,7 +4967,7 @@ qemuBuildPCIHostdevDevProps(const virDomainDef *def,
     const char *failover_pair_id = NULL;
 
     /* caller has to assign proper passthrough backend type */
-    switch ((virDomainHostdevSubsysPCIBackendType) pcisrc->backend) {
+    switch (pcisrc->backend) {
     case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO:
         break;
 
@@ -5480,7 +5480,7 @@ qemuBuildHostdevCommandLine(virCommand *cmd,
 
         /* MDEV */
         case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
-            switch ((virMediatedDeviceModelType) mdevsrc->model) {
+            switch (mdevsrc->model) {
             case VIR_MDEV_MODEL_TYPE_VFIO_PCI:
             case VIR_MDEV_MODEL_TYPE_VFIO_CCW:
             case VIR_MDEV_MODEL_TYPE_VFIO_AP:
diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c
index dfe657c51e..8af22bdd58 100644
--- a/src/qemu/qemu_hostdev.c
+++ b/src/qemu/qemu_hostdev.c
@@ -169,14 +169,14 @@ qemuHostdevPreparePCIDevicesCheckSupport(virDomainHostdevDef **hostdevs,
     /* assign defaults for hostdev passthrough */
     for (i = 0; i < nhostdevs; i++) {
         virDomainHostdevDef *hostdev = hostdevs[i];
-        int *backend = &hostdev->source.subsys.u.pci.backend;
+        virDomainHostdevSubsysPCIBackendType *backend = &hostdev->source.subsys.u.pci.backend;
 
         if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
             continue;
         if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
             continue;
 
-        switch ((virDomainHostdevSubsysPCIBackendType)*backend) {
+        switch (*backend) {
         case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT:
             if (supportsPassthroughVFIO &&
                 virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) {
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index f3ec24635d..22acbd0852 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1622,7 +1622,7 @@ qemuDomainAttachHostPCIDevice(virQEMUDriver *driver,
     /* this could have been changed by qemuHostdevPreparePCIDevices */
     backend = hostdev->source.subsys.u.pci.backend;
 
-    switch ((virDomainHostdevSubsysPCIBackendType)backend) {
+    switch (backend) {
     case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO:
         if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
@@ -2814,6 +2814,7 @@ qemuDomainAttachMediatedDevice(virQEMUDriver *driver,
         if (qemuDomainEnsureVirtioAddress(&releaseaddr, vm, &dev) < 0)
             return -1;
     }   break;
+    case VIR_MDEV_MODEL_TYPE_VFIO_AP:
     case VIR_MDEV_MODEL_TYPE_LAST:
         break;
     }
diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index 7eaad3614e..0a879f0115 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -2357,7 +2357,7 @@ qemuValidateDomainMdevDef(const virDomainHostdevDef *hostdev,
     const virDomainHostdevSubsysMediatedDev *mdevsrc;
 
     mdevsrc = &hostdev->source.subsys.u.mdev;
-    switch ((virMediatedDeviceModelType) mdevsrc->model) {
+    switch (mdevsrc->model) {
     case VIR_MDEV_MODEL_TYPE_VFIO_PCI:
         return qemuValidateDomainMdevDefVFIOPCI(hostdev, def, qemuCaps);
     case VIR_MDEV_MODEL_TYPE_VFIO_AP:
diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c
index 28717b7e38..1f1cce8b3d 100644
--- a/src/security/virt-aa-helper.c
+++ b/src/security/virt-aa-helper.c
@@ -1070,7 +1070,7 @@ get_files(vahControl * ctl)
 
             case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
                 virDomainHostdevSubsysMediatedDev *mdevsrc = &dev->source.subsys.u.mdev;
-                switch ((virMediatedDeviceModelType) mdevsrc->model) {
+                switch (mdevsrc->model) {
                     case VIR_MDEV_MODEL_TYPE_VFIO_PCI:
                     case VIR_MDEV_MODEL_TYPE_VFIO_AP:
                     case VIR_MDEV_MODEL_TYPE_VFIO_CCW:
-- 
2.34.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux