[PATCH 1/5] conf: simplify functions virDomainSCSIDriveAddressIsUsedBy*()

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

 



Pass the virDomainDeviceDriveAddress as a struct instead of individual
arguments. Reworked the function descriptions.

Signed-off-by: Marc Hartmayer <mhartmay@xxxxxxxxxxxxxxxxxx>
Reviewed-by: Boris Fiuczynski <fiuczy@xxxxxxxxxxxxxxxxxx>
---
 src/conf/domain_conf.c | 76 ++++++++++++++++++++++++++++----------------------
 1 file changed, 43 insertions(+), 33 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index b001efc..6836d4e 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -4016,16 +4016,19 @@ virDomainDefPostParseGraphics(virDomainDef *def)
 }
 
 
-/* Check if a drive type address $controller:$bus:$target:$unit is already
- * taken by a disk or not.
+/**
+ * virDomainDriveAddressIsUsedByDisk:
+ * @def: domain definition containing the disks to check
+ * @type: bus type
+ * @addr: address to check for duplicates
+ *
+ * Return true if any disk is already using the given address on the
+ * given bus, false otherwise.
  */
 static bool
 virDomainDriveAddressIsUsedByDisk(const virDomainDef *def,
                                   virDomainDiskBus type,
-                                  unsigned int controller,
-                                  unsigned int bus,
-                                  unsigned int target,
-                                  unsigned int unit)
+                                  const virDomainDeviceDriveAddress *addr)
 {
     virDomainDiskDefPtr disk;
     size_t i;
@@ -4037,10 +4040,10 @@ virDomainDriveAddressIsUsedByDisk(const virDomainDef *def,
             disk->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE)
             continue;
 
-        if (disk->info.addr.drive.controller == controller &&
-            disk->info.addr.drive.unit == unit &&
-            disk->info.addr.drive.bus == bus &&
-            disk->info.addr.drive.target == target)
+        if (disk->info.addr.drive.controller == addr->controller &&
+            disk->info.addr.drive.unit == addr->unit &&
+            disk->info.addr.drive.bus == addr->bus &&
+            disk->info.addr.drive.target == addr->target)
             return true;
     }
 
@@ -4048,16 +4051,19 @@ virDomainDriveAddressIsUsedByDisk(const virDomainDef *def,
 }
 
 
-/* Check if a drive type address $controller:$target:$bus:$unit is already
- * taken by a host device or not.
+/**
+ * virDomainDriveAddressIsUsedByHostdev:
+ * @def: domain definition containing the hostdevs to check
+ * @type: bus type
+ * @addr: address to check for duplicates
+ *
+ * Return true if any hostdev is already using the given address on the
+ * given bus, false otherwise.
  */
 static bool
 virDomainDriveAddressIsUsedByHostdev(const virDomainDef *def,
                                      virDomainHostdevSubsysType type,
-                                     unsigned int controller,
-                                     unsigned int bus,
-                                     unsigned int target,
-                                     unsigned int unit)
+                                     const virDomainDeviceDriveAddress *addr)
 {
     virDomainHostdevDefPtr hostdev;
     size_t i;
@@ -4069,10 +4075,10 @@ virDomainDriveAddressIsUsedByHostdev(const virDomainDef *def,
             hostdev->info->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE)
             continue;
 
-        if (hostdev->info->addr.drive.controller == controller &&
-            hostdev->info->addr.drive.unit == unit &&
-            hostdev->info->addr.drive.bus == bus &&
-            hostdev->info->addr.drive.target == target)
+        if (hostdev->info->addr.drive.controller == addr->controller &&
+            hostdev->info->addr.drive.unit == addr->unit &&
+            hostdev->info->addr.drive.bus == addr->bus &&
+            hostdev->info->addr.drive.target == addr->target)
             return true;
     }
 
@@ -4080,24 +4086,29 @@ virDomainDriveAddressIsUsedByHostdev(const virDomainDef *def,
 }
 
 
+/**
+ * virDomainSCSIDriveAddressIsUsed:
+ * @def: domain definition to check against
+ * @addr: address to check for duplicates
+ *
+ * Return true if the SCSI drive address is already in use, false
+ * otherwise.
+ */
 static bool
 virDomainSCSIDriveAddressIsUsed(const virDomainDef *def,
-                                unsigned int controller,
-                                unsigned int bus,
-                                unsigned int target,
-                                unsigned int unit)
+                                const virDomainDeviceDriveAddress *addr)
 {
     /* In current implementation, the maximum unit number of a controller
      * is either 16 or 7 (narrow SCSI bus), and if the maximum unit number
      * is 16, the controller itself is on unit 7 */
-    if (unit == 7)
+    if (addr->unit == 7)
         return true;
 
     if (virDomainDriveAddressIsUsedByDisk(def, VIR_DOMAIN_DISK_BUS_SCSI,
-                                          controller, bus, target, unit) ||
+                                          addr) ||
         virDomainDriveAddressIsUsedByHostdev(def,
                                              VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI,
-                                             controller, bus, target, unit))
+                                             addr))
         return true;
 
     return false;
@@ -4114,7 +4125,8 @@ virDomainControllerSCSINextUnit(const virDomainDef *def,
 
     for (i = 0; i < max_unit; i++) {
         /* Default to assigning addresses using bus = target = 0 */
-        if (!virDomainSCSIDriveAddressIsUsed(def, controller, 0, 0, i))
+        const virDomainDeviceDriveAddress addr = {controller, 0, 0, i};
+        if (!virDomainSCSIDriveAddressIsUsed(def, &addr))
             return i;
     }
 
@@ -4270,10 +4282,7 @@ virDomainDeviceDefPostParseInternal(virDomainDeviceDefPtr dev,
                 virDomainDeviceDriveAddressPtr addr = &hdev->info->addr.drive;
                 if (virDomainDriveAddressIsUsedByDisk(def,
                                                       VIR_DOMAIN_DISK_BUS_SCSI,
-                                                      addr->controller,
-                                                      addr->bus,
-                                                      addr->target,
-                                                      addr->unit)) {
+                                                      addr)) {
                     virReportError(VIR_ERR_XML_ERROR,
                                    _("SCSI host address controller='%u' "
                                      "bus='%u' target='%u' unit='%u' in "
@@ -6559,9 +6568,10 @@ virDomainDiskDefAssignAddress(virDomainXMLOptionPtr xmlopt,
             unit = idx % 7;
         }
 
+        const virDomainDeviceDriveAddress addr = {controller, 0, 0, unit};
         if (virDomainDriveAddressIsUsedByHostdev(vmdef,
                                                  VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI,
-                                                 controller, 0, 0, unit)) {
+                                                 &addr)) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                            _("using disk target name '%s' conflicts with "
                              "SCSI host device address controller='%u' "
-- 
2.5.5

--
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