From: Adheer Chandravanshi <[email protected]>

This makes iscsiuio more compatible with newer adapters by eliminating
the need to always update iscsiuio with the PCI IDs of the new adapter.

Signed-off-by: Adheer Chandravanshi <[email protected]>
---
 iscsiuio/src/unix/nic.c       |   22 +++++++++++---
 iscsiuio/src/unix/nic.h       |    6 ++-
 iscsiuio/src/unix/nic_id.c    |    2 +
 iscsiuio/src/unix/nic_utils.c |   65 +++++++++++++++++++++++++++--------------
 4 files changed, 66 insertions(+), 29 deletions(-)

diff --git a/iscsiuio/src/unix/nic.c b/iscsiuio/src/unix/nic.c
index 38a5776..fb3b7c3 100644
--- a/iscsiuio/src/unix/nic.c
+++ b/iscsiuio/src/unix/nic.c
@@ -152,7 +152,6 @@ static int load_nic_library(nic_lib_handle_t *handle)
        /*  Validate the NIC library ops table to ensure that all the proper
         *  fields are filled */
        if ((handle->ops->lib_ops.get_library_name == NULL) ||
-           (handle->ops->lib_ops.get_pci_table == NULL) ||
            (handle->ops->lib_ops.get_library_version == NULL) ||
            (handle->ops->lib_ops.get_build_date == NULL) ||
            (handle->ops->lib_ops.get_transport_name == NULL)) {
@@ -247,7 +246,8 @@ int unload_all_nic_libraries()
        return 0;
 }
 
-NIC_LIBRARY_EXIST_T does_nic_uio_name_exist(char *name)
+NIC_LIBRARY_EXIST_T does_nic_uio_name_exist(char *name,
+                                           nic_lib_handle_t **handle)
 {
        NIC_LIBRARY_EXIST_T rc;
        nic_lib_handle_t *current;
@@ -263,6 +263,9 @@ NIC_LIBRARY_EXIST_T does_nic_uio_name_exist(char *name)
                                                       &uio_name_size);
 
                if (strncmp(name, uio_name, uio_name_size) == 0) {
+                       if (handle)
+                               *handle = current;
+
                        rc = NIC_LIBRARY_EXSITS;
                        goto done;
                }
@@ -277,7 +280,8 @@ done:
        return rc;
 }
 
-NIC_LIBRARY_EXIST_T does_nic_library_exist(char *name)
+NIC_LIBRARY_EXIST_T does_nic_library_exist(char *name,
+                                          nic_lib_handle_t **handle)
 {
        NIC_LIBRARY_EXIST_T rc;
        nic_lib_handle_t *current;
@@ -293,6 +297,9 @@ NIC_LIBRARY_EXIST_T does_nic_library_exist(char *name)
                                                           &library_name_size);
 
                if (strncmp(name, library_name, library_name_size) == 0) {
+                       if (handle)
+                               *handle = current;
+
                        rc = NIC_LIBRARY_EXSITS;
                        goto done;
                }
@@ -333,8 +340,13 @@ int find_nic_lib_using_pci_id(uint32_t vendor, uint32_t 
device,
                uint32_t entries;
                int i;
 
-               current->ops->lib_ops.get_pci_table(&pci_table, &entries);
-
+               if (current->ops->lib_ops.get_pci_table != NULL) {
+                       current->ops->lib_ops.get_pci_table(&pci_table,
+                                                           &entries);
+               } else {
+                       current = current->next;
+                       continue;
+               }
                /*  Sanity check the the pci table coming from the
                 *  hardware library */
                if (entries > MAX_PCI_DEVICE_ENTRIES) {
diff --git a/iscsiuio/src/unix/nic.h b/iscsiuio/src/unix/nic.h
index 8484032..e99fd8e 100644
--- a/iscsiuio/src/unix/nic.h
+++ b/iscsiuio/src/unix/nic.h
@@ -351,8 +351,10 @@ typedef enum {
        NIC_LIBRARY_DOESNT_EXIST = 2,
 } NIC_LIBRARY_EXIST_T;
 
-NIC_LIBRARY_EXIST_T does_nic_uio_name_exist(char *name);
-NIC_LIBRARY_EXIST_T does_nic_library_exist(char *name);
+NIC_LIBRARY_EXIST_T does_nic_uio_name_exist(char *name,
+                                           nic_lib_handle_t **handle);
+NIC_LIBRARY_EXIST_T does_nic_library_exist(char *name,
+                                          nic_lib_handle_t **handle);
 
 
/*******************************************************************************
  *  Packet management utility functions
diff --git a/iscsiuio/src/unix/nic_id.c b/iscsiuio/src/unix/nic_id.c
index 6b2467c..6da0a38 100644
--- a/iscsiuio/src/unix/nic_id.c
+++ b/iscsiuio/src/unix/nic_id.c
@@ -308,6 +308,7 @@ int find_set_nic_lib(nic_t *nic)
 
        nic_lib_handle_t *handle;
        struct pci_device_id *pci_entry;
+       size_t name_size;
 
        rc = get_vendor(nic, &vendor);
        if (rc != 0) {
@@ -357,6 +358,7 @@ int find_set_nic_lib(nic_t *nic)
 
        /*  Prepare the NIC library op table */
        nic->ops = handle->ops;
+       (*nic->ops->lib_ops.get_library_name) (&nic->library_name, &name_size);
 
        return 0;
 }
diff --git a/iscsiuio/src/unix/nic_utils.c b/iscsiuio/src/unix/nic_utils.c
index d57cc4f..0daffd2 100644
--- a/iscsiuio/src/unix/nic_utils.c
+++ b/iscsiuio/src/unix/nic_utils.c
@@ -700,6 +700,9 @@ int nic_verify_uio_sysfs_name(nic_t *nic)
        uint32_t raw_size = 0;
        char temp_path[sizeof(nic_uio_sysfs_name_tempate) + 8];
        int rc = 0;
+       nic_lib_handle_t *handle = NULL;
+       size_t name_size;
+
 
        /*  Build the path to determine uio name */
        snprintf(temp_path, sizeof(temp_path),
@@ -716,37 +719,43 @@ int nic_verify_uio_sysfs_name(nic_t *nic)
        *raw_tmp = '\0';
 
        /*  If the nic library is not set then check if there is a library
-        *  which matches the library name */
+        *  which matches the uio sysfs name */
        if (nic->nic_library == NULL) {
                NIC_LIBRARY_EXIST_T exist;
 
-               exist = does_nic_uio_name_exist(raw);
+               exist = does_nic_uio_name_exist(raw, &handle);
                if (exist == NIC_LIBRARY_DOESNT_EXIST) {
-                       LOG_ERR(PFX "%s: could not find library: %s ",
+                       LOG_ERR(PFX "%s: could not find library for uio name: 
%s",
                                nic->log_name, raw);
-                       rc = -EIO;
+                       rc = -EINVAL;
+                       goto error;
                }
-       } else {
-               char *library_name;
-               size_t library_name_size;
 
-               /*  Get the string name from the NIC library */
-               (*nic->ops->lib_ops.get_library_name) (&library_name,
-                                                      &library_name_size);
+               /* fill the lib info */
+               nic->nic_library = handle;
+               nic->ops = handle->ops;
+               (*nic->ops->lib_ops.get_library_name) (&nic->library_name,
+                                                      &name_size);
+       } else {
+               /*  Get the uio sysfs name from the NIC library */
+               (*nic->ops->lib_ops.get_uio_name) (&raw_tmp, &name_size);
 
-               if (strcmp(raw, library_name) != 0) {
+               if (strncmp(raw, raw_tmp, name_size) != 0) {
                        LOG_ERR(PFX "%s: uio names not equal: "
                                "expecting %s got %s from %s",
-                               nic->log_name, library_name, raw, temp_path);
-                       rc = -EIO;
+                               nic->log_name, raw, raw_tmp, temp_path);
+                       rc = -EINVAL;
+                       goto error;
                }
        }
 
-       free(raw);
-
-       LOG_INFO(PFX "%s: Verified is a cnic_uio device", nic->log_name);
+       LOG_INFO(PFX "%s: Verified uio name %s with library %s",
+                nic->log_name, raw, nic->library_name);
 
 error:
+       if (raw)
+               free(raw);
+
        return rc;
 }
 
@@ -844,28 +853,40 @@ void prepare_library(nic_t *nic)
 {
        int rc;
        NIC_LIBRARY_EXIST_T exist;
+       nic_lib_handle_t *handle = NULL;
 
        nic_fill_name(nic);
 
        /* No assoicated library, we can skip it */
        if (nic->library_name != NULL) {
                /*  Check that we have the proper NIC library loaded */
-               exist = does_nic_library_exist(nic->library_name);
+               exist = does_nic_library_exist(nic->library_name, &handle);
                if (exist == NIC_LIBRARY_DOESNT_EXIST) {
                        LOG_ERR(PFX "NIC library doesn't exists: %s",
                                nic->library_name);
                        goto error;
+               } else if (handle && (nic->nic_library == handle) &&
+                         (nic->ops == handle->ops)) {
+                       LOG_INFO("%s: Have NIC library '%s'",
+                                nic->log_name, nic->library_name);
                }
        }
 
-       /*  Determine the NIC library to use based on the PCI Id */
-       rc = find_set_nic_lib(nic);
+       /*  Verify the NIC library to use */
+       rc = nic_verify_uio_sysfs_name(nic);
        if (rc != 0) {
-               LOG_ERR(PFX "%s: Couldn't find NIC library", nic->log_name);
-               goto error;
+               /*  Determine the NIC library to use based on the PCI Id */
+               rc = find_set_nic_lib(nic);
+               if (rc != 0) {
+                       LOG_ERR(PFX "%s: Couldn't find NIC library",
+                               nic->log_name);
+                       goto error;
+               }
+
        }
 
-       LOG_INFO("%s: found NIC '%s'", nic->log_name, nic->pci_id->device_name);
+       LOG_INFO("%s: found NIC with library '%s'",
+                nic->log_name, nic->library_name);
 error:
        return;
 }
-- 
1.7.1

-- 
You received this message because you are subscribed to the Google Groups 
"open-iscsi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/open-iscsi.
For more options, visit https://groups.google.com/d/optout.

Reply via email to