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

[libvirt] [PATCH 1/2] storage: Move and rename getVhbaSCSIHostParent



https://bugzilla.redhat.com/show_bug.cgi?id=1159180

Move the API from the backend to storage_conf and rename it to
virStoragePoolGetVhbaSCSIHostParent.  A future patch will need to
use this functionality from storage_conf

Signed-off-by: John Ferlan <jferlan redhat com>
---
 src/conf/storage_conf.c            | 66 ++++++++++++++++++++++++++++++++++++++
 src/conf/storage_conf.h            |  5 +++
 src/libvirt_private.syms           |  1 +
 src/storage/storage_backend_scsi.c | 66 ++------------------------------------
 4 files changed, 74 insertions(+), 64 deletions(-)

diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index 6ad37f8..751c0c0 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -2078,6 +2078,72 @@ virStoragePoolObjIsDuplicate(virStoragePoolObjListPtr pools,
     return ret;
 }
 
+/*
+ * virStoragePoolGetVhbaSCSIHostParent:
+ *
+ * Using the Node Device Driver, find the host# name found via wwnn/wwpn
+ * lookup in the fc_host sysfs tree (e.g. virGetFCHostNameByWWN) to get
+ * the parent 'scsi_host#'.
+ *
+ * @conn: Connection pointer (must be non-NULL on entry)
+ * @name: Pointer a string from a virGetFCHostNameByWWN (e.g., "host#")
+ *
+ * Returns a "scsi_host#" string of the parent of the vHBA
+ */
+char *
+virStoragePoolGetVhbaSCSIHostParent(virConnectPtr conn,
+                                    const char *name)
+{
+    char *nodedev_name = NULL;
+    virNodeDevicePtr device = NULL;
+    char *xml = NULL;
+    virNodeDeviceDefPtr def = NULL;
+    char *vhba_parent = NULL;
+    virErrorPtr savedError = NULL;
+
+    VIR_DEBUG("conn=%p, name=%s", conn, name);
+
+    /* We get passed "host#" from the return from virGetFCHostNameByWWN,
+     * so we need to adjust that to what the nodedev lookup expects
+     */
+    if (virAsprintf(&nodedev_name, "scsi_%s", name) < 0)
+        goto cleanup;
+
+    /* Compare the scsi_host for the name with the provided parent
+     * if not the same, then fail
+     */
+    if (!(device = virNodeDeviceLookupByName(conn, nodedev_name))) {
+        virReportError(VIR_ERR_XML_ERROR,
+                       _("Cannot find '%s' in node device database"),
+                       nodedev_name);
+        goto cleanup;
+    }
+
+    if (!(xml = virNodeDeviceGetXMLDesc(device, 0)))
+        goto cleanup;
+
+    if (!(def = virNodeDeviceDefParseString(xml, EXISTING_DEVICE, NULL)))
+        goto cleanup;
+
+    /* The caller checks whether the returned value is NULL or not
+     * before continuing
+     */
+    ignore_value(VIR_STRDUP(vhba_parent, def->parent));
+
+ cleanup:
+    if (!vhba_parent)
+        savedError = virSaveLastError();
+    VIR_FREE(nodedev_name);
+    virNodeDeviceDefFree(def);
+    VIR_FREE(xml);
+    virNodeDeviceFree(device);
+    if (savedError) {
+        virSetError(savedError);
+        virFreeError(savedError);
+    }
+    return vhba_parent;
+}
+
 static int
 getSCSIHostNumber(virStoragePoolSourceAdapter adapter,
                   unsigned int *hostnum)
diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h
index 765f681..228bb1c 100644
--- a/src/conf/storage_conf.h
+++ b/src/conf/storage_conf.h
@@ -30,6 +30,7 @@
 # include "virbitmap.h"
 # include "virthread.h"
 # include "device_conf.h"
+# include "node_device_conf.h"
 
 # include <libxml/tree.h>
 
@@ -389,6 +390,10 @@ int virStoragePoolObjIsDuplicate(virStoragePoolObjListPtr pools,
                                  virStoragePoolDefPtr def,
                                  unsigned int check_active);
 
+char *virStoragePoolGetVhbaSCSIHostParent(virConnectPtr conn,
+                                          const char *name)
+    ATTRIBUTE_NONNULL(1);
+
 int virStoragePoolSourceFindDuplicate(virStoragePoolObjListPtr pools,
                                       virStoragePoolDefPtr def);
 
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 0864618..ccf1cea 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -740,6 +740,7 @@ virStoragePoolDefParseString;
 virStoragePoolFormatDiskTypeToString;
 virStoragePoolFormatFileSystemNetTypeToString;
 virStoragePoolFormatFileSystemTypeToString;
+virStoragePoolGetVhbaSCSIHostParent;
 virStoragePoolLoadAllConfigs;
 virStoragePoolObjAssignDef;
 virStoragePoolObjClearVols;
diff --git a/src/storage/storage_backend_scsi.c b/src/storage/storage_backend_scsi.c
index c952b71..4be525d 100644
--- a/src/storage/storage_backend_scsi.c
+++ b/src/storage/storage_backend_scsi.c
@@ -34,7 +34,6 @@
 #include "virlog.h"
 #include "virfile.h"
 #include "vircommand.h"
-#include "viraccessapicheck.h"
 #include "virstring.h"
 
 #define VIR_FROM_THIS VIR_FROM_STORAGE
@@ -548,67 +547,6 @@ getAdapterName(virStoragePoolSourceAdapter adapter)
 
 /*
  * Using the host# name found via wwnn/wwpn lookup in the fc_host
- * sysfs tree to get the parent 'scsi_host#'. On entry we need 'conn'
- * set. We won't get here from the autostart path since the caller
- * will return true before calling this function. For the shutdown
- * path we won't be able to delete the vport.
- */
-static char * ATTRIBUTE_NONNULL(1)
-getVhbaSCSIHostParent(virConnectPtr conn,
-                      const char *name)
-{
-    char *nodedev_name = NULL;
-    virNodeDevicePtr device = NULL;
-    char *xml = NULL;
-    virNodeDeviceDefPtr def = NULL;
-    char *vhba_parent = NULL;
-    virErrorPtr savedError = NULL;
-
-    VIR_DEBUG("conn=%p, name=%s", conn, name);
-
-    /* We get passed "host#" from the return from virGetFCHostNameByWWN,
-     * so we need to adjust that to what the nodedev lookup expects
-     */
-    if (virAsprintf(&nodedev_name, "scsi_%s", name) < 0)
-        goto cleanup;
-
-    /* Compare the scsi_host for the name with the provided parent
-     * if not the same, then fail
-     */
-    if (!(device = virNodeDeviceLookupByName(conn, nodedev_name))) {
-        virReportError(VIR_ERR_XML_ERROR,
-                       _("Cannot find '%s' in node device database"),
-                       nodedev_name);
-        goto cleanup;
-    }
-
-    if (!(xml = virNodeDeviceGetXMLDesc(device, 0)))
-        goto cleanup;
-
-    if (!(def = virNodeDeviceDefParseString(xml, EXISTING_DEVICE, NULL)))
-        goto cleanup;
-
-    /* The caller checks whether the returned value is NULL or not
-     * before continuing
-     */
-    ignore_value(VIR_STRDUP(vhba_parent, def->parent));
-
- cleanup:
-    if (!vhba_parent)
-        savedError = virSaveLastError();
-    VIR_FREE(nodedev_name);
-    virNodeDeviceDefFree(def);
-    VIR_FREE(xml);
-    virNodeDeviceFree(device);
-    if (savedError) {
-        virSetError(savedError);
-        virFreeError(savedError);
-    }
-    return vhba_parent;
-}
-
-/*
- * Using the host# name found via wwnn/wwpn lookup in the fc_host
  * sysfs tree to get the parent 'scsi_host#' to ensure it matches.
  */
 static bool
@@ -625,7 +563,7 @@ checkVhbaSCSIHostParent(virConnectPtr conn,
     if (!conn)
         return true;
 
-    if (!(vhba_parent = getVhbaSCSIHostParent(conn, name)))
+    if (!(vhba_parent = virStoragePoolGetVhbaSCSIHostParent(conn, name)))
         goto cleanup;
 
     if (STRNEQ(parent_name, vhba_parent)) {
@@ -777,7 +715,7 @@ deleteVport(virConnectPtr conn,
         if (virGetSCSIHostNumber(adapter.data.fchost.parent, &parent_host) < 0)
             goto cleanup;
     } else {
-        if (!(vhba_parent = getVhbaSCSIHostParent(conn, name)))
+        if (!(vhba_parent = virStoragePoolGetVhbaSCSIHostParent(conn, name)))
             goto cleanup;
 
         if (virGetSCSIHostNumber(vhba_parent, &parent_host) < 0)
-- 
1.9.3


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