[PATCH v13 30/49] move virHostdevPrepareHostSCSIDevices to virhostdev.c

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

 



Signed-off-by: Chunyan Liu <cyliu@xxxxxxxx>
---
 src/libvirt_private.syms |    1 +
 src/qemu/qemu_hostdev.c  |  112 ----------------------------------------------
 src/util/virhostdev.c    |  112 ++++++++++++++++++++++++++++++++++++++++++++++
 src/util/virhostdev.h    |    6 +++
 4 files changed, 119 insertions(+), 112 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 01f6c81..fd92467 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1294,6 +1294,7 @@ virHookPresent;
 #util/virhostdev.h
 virHostdevManagerGetDefault;
 virHostdevPreparePCIDevices;
+virHostdevPrepareSCSIDevices;
 virHostdevPrepareUSBDevices;
 virHostdevReAttachPCIDevices;
 virHostdevUpdateActivePciHostdevs;
diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c
index a7b4e74..add887f 100644
--- a/src/qemu/qemu_hostdev.c
+++ b/src/qemu/qemu_hostdev.c
@@ -263,118 +263,6 @@ qemuPrepareHostUSBDevices(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
                                        hostdevs, nhostdevs, flags);
 }
 
-static int
-virHostdevPrepareSCSIDevices(virHostdevManagerPtr hostdev_mgr,
-                             const char *drv_name,
-                             const char *name,
-                             virDomainHostdevDefPtr *hostdevs,
-                             int nhostdevs)
-{
-    size_t i, j;
-    int count;
-    virSCSIDeviceListPtr list;
-    virSCSIDevicePtr tmp;
-
-    /* To prevent situation where SCSI device is assigned to two domains
-     * we need to keep a list of currently assigned SCSI devices.
-     * This is done in several loops which cannot be joined into one big
-     * loop. See qemuPrepareHostdevPCIDevices()
-     */
-    if (!(list = virSCSIDeviceListNew()))
-        goto cleanup;
-
-    /* Loop 1: build temporary list */
-    for (i = 0; i < nhostdevs; i++) {
-        virDomainHostdevDefPtr hostdev = hostdevs[i];
-        virSCSIDevicePtr scsi;
-
-        if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
-            hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI)
-            continue;
-
-        if (hostdev->managed) {
-            virReportError(VIR_ERR_XML_ERROR, "%s",
-                           _("SCSI host device doesn't support managed mode"));
-            goto cleanup;
-        }
-
-        if (!(scsi = virSCSIDeviceNew(NULL,
-                                      hostdev->source.subsys.u.scsi.adapter,
-                                      hostdev->source.subsys.u.scsi.bus,
-                                      hostdev->source.subsys.u.scsi.target,
-                                      hostdev->source.subsys.u.scsi.unit,
-                                      hostdev->readonly,
-                                      hostdev->shareable)))
-            goto cleanup;
-
-        if (scsi && virSCSIDeviceListAdd(list, scsi) < 0) {
-            virSCSIDeviceFree(scsi);
-            goto cleanup;
-        }
-    }
-
-    /* Loop 2: Mark devices in temporary list as used by @name
-     * and add them to driver list. However, if something goes
-     * wrong, perform rollback.
-     */
-    virObjectLock(hostdev_mgr->activeScsiHostdevs);
-    count = virSCSIDeviceListCount(list);
-
-    for (i = 0; i < count; i++) {
-        virSCSIDevicePtr scsi = virSCSIDeviceListGet(list, i);
-        if ((tmp = virSCSIDeviceListFind(hostdev_mgr->activeScsiHostdevs,
-                                         scsi))) {
-            bool scsi_shareable = virSCSIDeviceGetShareable(scsi);
-            bool tmp_shareable = virSCSIDeviceGetShareable(tmp);
-
-            if (!(scsi_shareable && tmp_shareable)) {
-                virReportError(VIR_ERR_OPERATION_INVALID,
-                               _("SCSI device %s is already in use by "
-                                 "other domain(s) as '%s'"),
-                               virSCSIDeviceGetName(tmp),
-                               tmp_shareable ? "shareable" : "non-shareable");
-                goto error;
-            }
-
-            if (virSCSIDeviceSetUsedBy(tmp, drv_name, name) < 0)
-                goto error;
-        } else {
-            if (virSCSIDeviceSetUsedBy(scsi, drv_name, name) < 0)
-                goto error;
-
-            VIR_DEBUG("Adding %s to activeScsiHostdevs", virSCSIDeviceGetName(scsi));
-
-            if (virSCSIDeviceListAdd(hostdev_mgr->activeScsiHostdevs, scsi) < 0)
-                goto error;
-        }
-    }
-
-    virObjectUnlock(hostdev_mgr->activeScsiHostdevs);
-
-    /* Loop 3: Temporary list was successfully merged with
-     * driver list, so steal all items to avoid freeing them
-     * when freeing temporary list.
-     */
-    while (virSCSIDeviceListCount(list) > 0) {
-        tmp = virSCSIDeviceListGet(list, 0);
-        virSCSIDeviceListSteal(list, tmp);
-    }
-
-    virObjectUnref(list);
-    return 0;
-
-error:
-    for (j = 0; j < i; j++) {
-        tmp = virSCSIDeviceListGet(list, i);
-        virSCSIDeviceListSteal(hostdev_mgr->activeScsiHostdevs, tmp);
-    }
-    virObjectUnlock(hostdev_mgr->activeScsiHostdevs);
-cleanup:
-    virObjectUnref(list);
-    return -1;
-
-}
-
 int
 qemuPrepareHostdevSCSIDevices(virQEMUDriverPtr driver,
                               const char *name,
diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index 896d451..5d1bb64 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -1118,3 +1118,115 @@ cleanup:
     virObjectUnref(list);
     return ret;
 }
+
+int
+virHostdevPrepareSCSIDevices(virHostdevManagerPtr hostdev_mgr,
+                             const char *drv_name,
+                             const char *name,
+                             virDomainHostdevDefPtr *hostdevs,
+                             int nhostdevs)
+{
+    size_t i, j;
+    int count;
+    virSCSIDeviceListPtr list;
+    virSCSIDevicePtr tmp;
+
+    /* To prevent situation where SCSI device is assigned to two domains
+     * we need to keep a list of currently assigned SCSI devices.
+     * This is done in several loops which cannot be joined into one big
+     * loop. See qemuPrepareHostdevPCIDevices()
+     */
+    if (!(list = virSCSIDeviceListNew()))
+        goto cleanup;
+
+    /* Loop 1: build temporary list */
+    for (i = 0; i < nhostdevs; i++) {
+        virDomainHostdevDefPtr hostdev = hostdevs[i];
+        virSCSIDevicePtr scsi;
+
+        if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
+            hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI)
+            continue;
+
+        if (hostdev->managed) {
+            virReportError(VIR_ERR_XML_ERROR, "%s",
+                           _("SCSI host device doesn't support managed mode"));
+            goto cleanup;
+        }
+
+        if (!(scsi = virSCSIDeviceNew(NULL,
+                                      hostdev->source.subsys.u.scsi.adapter,
+                                      hostdev->source.subsys.u.scsi.bus,
+                                      hostdev->source.subsys.u.scsi.target,
+                                      hostdev->source.subsys.u.scsi.unit,
+                                      hostdev->readonly,
+                                      hostdev->shareable)))
+            goto cleanup;
+
+        if (scsi && virSCSIDeviceListAdd(list, scsi) < 0) {
+            virSCSIDeviceFree(scsi);
+            goto cleanup;
+        }
+    }
+
+    /* Loop 2: Mark devices in temporary list as used by @name
+     * and add them to driver list. However, if something goes
+     * wrong, perform rollback.
+     */
+    virObjectLock(hostdev_mgr->activeScsiHostdevs);
+    count = virSCSIDeviceListCount(list);
+
+    for (i = 0; i < count; i++) {
+        virSCSIDevicePtr scsi = virSCSIDeviceListGet(list, i);
+        if ((tmp = virSCSIDeviceListFind(hostdev_mgr->activeScsiHostdevs,
+                                         scsi))) {
+            bool scsi_shareable = virSCSIDeviceGetShareable(scsi);
+            bool tmp_shareable = virSCSIDeviceGetShareable(tmp);
+
+            if (!(scsi_shareable && tmp_shareable)) {
+                virReportError(VIR_ERR_OPERATION_INVALID,
+                               _("SCSI device %s is already in use by "
+                                 "other domain(s) as '%s'"),
+                               virSCSIDeviceGetName(tmp),
+                               tmp_shareable ? "shareable" : "non-shareable");
+                goto error;
+            }
+
+            if (virSCSIDeviceSetUsedBy(tmp, drv_name, name) < 0)
+                goto error;
+        } else {
+            if (virSCSIDeviceSetUsedBy(scsi, drv_name, name) < 0)
+                goto error;
+
+            VIR_DEBUG("Adding %s to activeScsiHostdevs", virSCSIDeviceGetName(scsi));
+
+            if (virSCSIDeviceListAdd(hostdev_mgr->activeScsiHostdevs, scsi) < 0)
+                goto error;
+        }
+    }
+
+    virObjectUnlock(hostdev_mgr->activeScsiHostdevs);
+
+    /* Loop 3: Temporary list was successfully merged with
+     * driver list, so steal all items to avoid freeing them
+     * when freeing temporary list.
+     */
+    while (virSCSIDeviceListCount(list) > 0) {
+        tmp = virSCSIDeviceListGet(list, 0);
+        virSCSIDeviceListSteal(list, tmp);
+    }
+
+    virObjectUnref(list);
+    return 0;
+
+error:
+    for (j = 0; j < i; j++) {
+        tmp = virSCSIDeviceListGet(list, i);
+        virSCSIDeviceListSteal(hostdev_mgr->activeScsiHostdevs, tmp);
+    }
+    virObjectUnlock(hostdev_mgr->activeScsiHostdevs);
+cleanup:
+    virObjectUnref(list);
+    return -1;
+
+}
diff --git a/src/util/virhostdev.h b/src/util/virhostdev.h
index 77e31fc..fc36ead 100644
--- a/src/util/virhostdev.h
+++ b/src/util/virhostdev.h
@@ -65,6 +65,12 @@ virHostdevPrepareUSBDevices(virHostdevManagerPtr hostdev_mgr,
                             virDomainHostdevDefPtr *hostdevs,
                             int nhostdevs,
                             unsigned int flags);
+int
+virHostdevPrepareSCSIDevices(virHostdevManagerPtr hostdev_mgr,
+                             const char *drv_name,
+                             const char *name,
+                             virDomainHostdevDefPtr *hostdevs,
+                             int nhostdevs);
 void
 virHostdevReAttachPCIDevices(virHostdevManagerPtr hostdev_mgr,
                              const char *drv_name,
-- 
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]