[PATCH 03/11] nodedev: Add ability to find a vport capable vHBA

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

 



If a <parent> is not supplied in the XML used to create a non-persistent
vHBA, then instead of failing, let's try to find a "vports" capable node
device and use that.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/conf/node_device_conf.c          | 39 ++++++++++++++++++++++++++++++++++++
 src/conf/node_device_conf.h          |  3 +++
 src/libvirt_private.syms             |  1 +
 src/node_device/node_device_driver.c | 15 +++++++++-----
 4 files changed, 53 insertions(+), 5 deletions(-)

diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
index 5396681..3aa77cf 100644
--- a/src/conf/node_device_conf.c
+++ b/src/conf/node_device_conf.c
@@ -151,6 +151,23 @@ virNodeDeviceObjPtr virNodeDeviceFindByName(virNodeDeviceObjListPtr devs,
 }
 
 
+static virNodeDeviceObjPtr
+virNodeDeviceFindByCap(virNodeDeviceObjListPtr devs,
+                       const char *cap)
+{
+    size_t i;
+
+    for (i = 0; i < devs->count; i++) {
+        virNodeDeviceObjLock(devs->objs[i]);
+        if (virNodeDeviceHasCap(devs->objs[i], cap))
+            return devs->objs[i];
+        virNodeDeviceObjUnlock(devs->objs[i]);
+    }
+
+    return NULL;
+}
+
+
 void virNodeDeviceDefFree(virNodeDeviceDefPtr def)
 {
     virNodeDevCapsDefPtr caps;
@@ -1828,6 +1845,28 @@ virNodeDeviceGetParentHost(virNodeDeviceObjListPtr devs,
     return ret;
 }
 
+
+int
+virNodeDeviceFindVportParentHost(virNodeDeviceObjListPtr devs,
+                                 int *parent_host)
+{
+    virNodeDeviceObjPtr parent = NULL;
+    int ret;
+
+    if (!(parent = virNodeDeviceFindByCap(devs, "vports"))) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("Could not find any vport capable device"));
+        return -1;
+    }
+
+    ret = virNodeDeviceFindFCParentHost(parent, parent_host);
+
+    virNodeDeviceObjUnlock(parent);
+
+    return ret;
+}
+
+
 void virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps)
 {
     size_t i = 0;
diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h
index 9f00500..2b2aed7 100644
--- a/src/conf/node_device_conf.h
+++ b/src/conf/node_device_conf.h
@@ -273,6 +273,9 @@ int virNodeDeviceGetParentHost(virNodeDeviceObjListPtr devs,
                                const char *parent_name,
                                int *parent_host);
 
+int virNodeDeviceFindVportParentHost(virNodeDeviceObjListPtr devs,
+                                     int *parent_host);
+
 void virNodeDeviceDefFree(virNodeDeviceDefPtr def);
 
 void virNodeDeviceObjFree(virNodeDeviceObjPtr dev);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index baff82b..de14a7e 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -699,6 +699,7 @@ virNodeDeviceDefParseNode;
 virNodeDeviceDefParseString;
 virNodeDeviceFindByName;
 virNodeDeviceFindBySysfsPath;
+virNodeDeviceFindVportParentHost;
 virNodeDeviceGetParentHost;
 virNodeDeviceGetWWNs;
 virNodeDeviceHasCap;
diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c
index 91bb142..0e091fe 100644
--- a/src/node_device/node_device_driver.c
+++ b/src/node_device/node_device_driver.c
@@ -584,11 +584,16 @@ nodeDeviceCreateXML(virConnectPtr conn,
     if (virNodeDeviceGetWWNs(def, &wwnn, &wwpn) == -1)
         goto cleanup;
 
-    if (virNodeDeviceGetParentHost(&driver->devs,
-                                   def->name,
-                                   def->parent,
-                                   &parent_host) == -1) {
-        goto cleanup;
+    if (def->parent) {
+        if (virNodeDeviceGetParentHost(&driver->devs,
+                                       def->name,
+                                       def->parent,
+                                       &parent_host) < 0)
+            goto cleanup;
+    } else {
+        /* Try to find "a" vport capable scsi_host when no parent supplied */
+        if (virNodeDeviceFindVportParentHost(&driver->devs, &parent_host) < 0)
+            goto cleanup;
     }
 
     if (virManageVport(parent_host,
-- 
2.7.4

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