[PATCH v13 28/49] extract general code from qemuPrepareHostSCSIDevices

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

 



Extract general code from qemuPrepareHostSCSIDevices to
virHostdevPrepareHostSCSIDevices.

Signed-off-by: Chunyan Liu <cyliu@xxxxxxxx>
---
 src/qemu/qemu_hostdev.c |   70 +++++++++++++++++++++++++++-------------------
 1 files changed, 41 insertions(+), 29 deletions(-)

diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c
index 2934e65..5eb12d1 100644
--- a/src/qemu/qemu_hostdev.c
+++ b/src/qemu/qemu_hostdev.c
@@ -263,34 +263,16 @@ qemuPrepareHostUSBDevices(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
                                        hostdevs, nhostdevs, flags);
 }
 
-
-int
-qemuPrepareHostdevSCSIDevices(virQEMUDriverPtr driver,
-                              const char *name,
-                              virDomainHostdevDefPtr *hostdevs,
-                              int nhostdevs)
+static int
+virHostdevPrepareSCSIDevices(virHostdevManagerPtr hostdev_mgr,
+                             const char *name,
+                             virDomainHostdevDefPtr *hostdevs,
+                             int nhostdevs)
 {
     size_t i, j;
     int count;
     virSCSIDeviceListPtr list;
     virSCSIDevicePtr tmp;
-    virHostdevManagerPtr hostdev_mgr;
-
-    /* Loop 1: Add the shared scsi host device to shared device
-     * table.
-     */
-    for (i = 0; i < nhostdevs; i++) {
-        virDomainDeviceDef dev;
-
-        dev.type = VIR_DOMAIN_DEVICE_HOSTDEV;
-        dev.data.hostdev = hostdevs[i];
-
-        if (qemuAddSharedDevice(driver, &dev, name) < 0)
-            return -1;
-
-        if (qemuSetUnprivSGIO(&dev) < 0)
-            return -1;
-    }
 
     /* To prevent situation where SCSI device is assigned to two domains
      * we need to keep a list of currently assigned SCSI devices.
@@ -300,7 +282,7 @@ qemuPrepareHostdevSCSIDevices(virQEMUDriverPtr driver,
     if (!(list = virSCSIDeviceListNew()))
         goto cleanup;
 
-    /* Loop 2: build temporary list */
+    /* Loop 1: build temporary list */
     for (i = 0; i < nhostdevs; i++) {
         virDomainHostdevDefPtr hostdev = hostdevs[i];
         virSCSIDevicePtr scsi;
@@ -330,13 +312,10 @@ qemuPrepareHostdevSCSIDevices(virQEMUDriverPtr driver,
         }
     }
 
-    /* Loop 3: Mark devices in temporary list as used by @name
+    /* Loop 2: Mark devices in temporary list as used by @name
      * and add them to driver list. However, if something goes
      * wrong, perform rollback.
      */
-    hostdev_mgr = virHostdevManagerGetDefault();
-    if (hostdev_mgr == NULL)
-        goto cleanup;
     virObjectLock(hostdev_mgr->activeScsiHostdevs);
     count = virSCSIDeviceListCount(list);
 
@@ -371,7 +350,7 @@ qemuPrepareHostdevSCSIDevices(virQEMUDriverPtr driver,
 
     virObjectUnlock(hostdev_mgr->activeScsiHostdevs);
 
-    /* Loop 4: Temporary list was successfully merged with
+    /* Loop 3: Temporary list was successfully merged with
      * driver list, so steal all items to avoid freeing them
      * when freeing temporary list.
      */
@@ -392,6 +371,39 @@ error:
 cleanup:
     virObjectUnref(list);
     return -1;
+
+}
+
+int
+qemuPrepareHostdevSCSIDevices(virQEMUDriverPtr driver,
+                              const char *name,
+                              virDomainHostdevDefPtr *hostdevs,
+                              int nhostdevs)
+{
+    size_t i;
+    virHostdevManagerPtr hostdev_mgr;
+
+    hostdev_mgr = virHostdevManagerGetDefault();
+    if (hostdev_mgr == NULL)
+        return -1;
+
+    /* Loop 1: Add the shared scsi host device to shared device
+     * table.
+     */
+    for (i = 0; i < nhostdevs; i++) {
+        virDomainDeviceDef dev;
+
+        dev.type = VIR_DOMAIN_DEVICE_HOSTDEV;
+        dev.data.hostdev = hostdevs[i];
+
+        if (qemuAddSharedDevice(driver, &dev, name) < 0)
+            return -1;
+
+        if (qemuSetUnprivSGIO(&dev) < 0)
+            return -1;
+    }
+
+    return virHostdevPrepareSCSIDevices(hostdev_mgr, name, hostdevs, nhostdevs);
 }
 
 
-- 
1.6.0.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]