[RFC PATCH v2 REBASE 05/18] conf: Introduce virDomainHostdevDefPostParse

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

 



Just to make the code a bit cleaner, move hostdev specific post parse
code to its own function just in case it grows in the future.

Signed-off-by: Erik Skultety <eskultet@xxxxxxxxxx>
---
 src/conf/domain_conf.c | 76 +++++++++++++++++++++++++++++++-------------------
 1 file changed, 48 insertions(+), 28 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 3aee8b6..522553c 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -4208,6 +4208,51 @@ virDomainHostdevAssignAddress(virDomainXMLOptionPtr xmlopt,
 
 
 static int
+virDomainHostdevDefPostParse(virDomainHostdevDefPtr dev,
+                             const virDomainDef *def,
+                             virDomainXMLOptionPtr xmlopt)
+{
+    if (dev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
+        return 0;
+
+    switch (dev->source.subsys.type) {
+    case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI:
+        if (dev->info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
+            virDomainHostdevAssignAddress(xmlopt, def, dev) < 0) {
+            virReportError(VIR_ERR_XML_ERROR, "%s",
+                           _("Cannot assign SCSI host device address"));
+            return -1;
+        } else {
+            /* Ensure provided address doesn't conflict with existing
+             * scsi disk drive address
+             */
+            virDomainDeviceDriveAddressPtr addr = &dev->info->addr.drive;
+            if (virDomainDriveAddressIsUsedByDisk(def,
+                                                  VIR_DOMAIN_DISK_BUS_SCSI,
+                                                  addr)) {
+                virReportError(VIR_ERR_XML_ERROR,
+                               _("SCSI host address controller='%u' "
+                                 "bus='%u' target='%u' unit='%u' in "
+                                 "use by a SCSI disk"),
+                               addr->controller, addr->bus,
+                               addr->target, addr->unit);
+                return -1;
+            }
+        }
+        break;
+    case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
+    case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
+    case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST:
+    case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
+    case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
+        break;
+    }
+
+    return 0;
+}
+
+
+static int
 virDomainDeviceDefPostParseInternal(virDomainDeviceDefPtr dev,
                                     const virDomainDef *def,
                                     virCapsPtr caps ATTRIBUTE_UNUSED,
@@ -4288,34 +4333,9 @@ virDomainDeviceDefPostParseInternal(virDomainDeviceDefPtr dev,
         video->vram = VIR_ROUND_UP_POWER_OF_TWO(video->vram);
     }
 
-    if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV) {
-        virDomainHostdevDefPtr hdev = dev->data.hostdev;
-
-        if (virHostdevIsSCSIDevice(hdev)) {
-            if (hdev->info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
-                virDomainHostdevAssignAddress(xmlopt, def, hdev) < 0) {
-                virReportError(VIR_ERR_XML_ERROR, "%s",
-                               _("Cannot assign SCSI host device address"));
-                return -1;
-            } else {
-                /* Ensure provided address doesn't conflict with existing
-                 * scsi disk drive address
-                 */
-                virDomainDeviceDriveAddressPtr addr = &hdev->info->addr.drive;
-                if (virDomainDriveAddressIsUsedByDisk(def,
-                                                      VIR_DOMAIN_DISK_BUS_SCSI,
-                                                      addr)) {
-                    virReportError(VIR_ERR_XML_ERROR,
-                                   _("SCSI host address controller='%u' "
-                                     "bus='%u' target='%u' unit='%u' in "
-                                     "use by a SCSI disk"),
-                                   addr->controller, addr->bus,
-                                   addr->target, addr->unit);
-                    return -1;
-                }
-            }
-        }
-    }
+    if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV &&
+        virDomainHostdevDefPostParse(dev->data.hostdev, def, xmlopt) < 0)
+        return -1;
 
     if (dev->type == VIR_DOMAIN_DEVICE_CONTROLLER) {
         virDomainControllerDefPtr cdev = dev->data.controller;
-- 
2.10.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[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