Generalize the PCI-specific pci_get_kernel_driver_by_path. The function is
general enough, we have just moved it to eal.c, changed the prefix to rte_eal
and provided it privately to other parts of EAL.

Signed-off-by: Jan Viktorin <viktorin at rehivetech.com>
---
 lib/librte_eal/common/eal_private.h   | 14 ++++++++++++++
 lib/librte_eal/linuxapp/eal/eal.c     | 29 +++++++++++++++++++++++++++++
 lib/librte_eal/linuxapp/eal/eal_pci.c | 31 +------------------------------
 3 files changed, 44 insertions(+), 30 deletions(-)

diff --git a/lib/librte_eal/common/eal_private.h 
b/lib/librte_eal/common/eal_private.h
index 3fb8353..9a81fdd 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -302,6 +302,20 @@ int rte_eal_check_module(const char *module_name);
 int rte_eal_unbind_kernel_driver(const char *devpath, const char *devid);

 /**
+ * Extrat the kernel driver name from the absolute path to the driver.
+ *
+ * @param filename  path to the driver ("<path-to-device>/driver")
+ * @path  dri_name  target buffer where to place the driver name
+ *                  (should be at least PATH_MAX long)
+ *
+ * @return
+ *      -1   on failure
+ *       0   when successful
+ *       1   when there is no such driver
+ */
+int rte_eal_get_kernel_driver_by_path(const char *filename, char *dri_name);
+
+/**
  * Get cpu core_id.
  *
  * This function is private to the EAL.
diff --git a/lib/librte_eal/linuxapp/eal/eal.c 
b/lib/librte_eal/linuxapp/eal/eal.c
index 844f958..a9f3ae2 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -975,3 +975,32 @@ error:
        fclose(f);
        return -1;
 }
+
+int
+rte_eal_get_kernel_driver_by_path(const char *filename, char *dri_name)
+{
+       int count;
+       char path[PATH_MAX];
+       char *name;
+
+       if (!filename || !dri_name)
+               return -1;
+
+       count = readlink(filename, path, PATH_MAX);
+       if (count >= PATH_MAX)
+               return -1;
+
+       /* For device does not have a driver */
+       if (count < 0)
+               return 1;
+
+       path[count] = '\0';
+
+       name = strrchr(path, '/');
+       if (name) {
+               strncpy(dri_name, name + 1, strlen(name + 1) + 1);
+               return 0;
+       }
+
+       return -1;
+}
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c 
b/lib/librte_eal/linuxapp/eal/eal_pci.c
index 312cb14..162d46e 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -78,35 +78,6 @@ pci_unbind_kernel_driver(struct rte_pci_device *dev)
        return rte_eal_unbind_kernel_driver(devpath, devid);
 }

-static int
-pci_get_kernel_driver_by_path(const char *filename, char *dri_name)
-{
-       int count;
-       char path[PATH_MAX];
-       char *name;
-
-       if (!filename || !dri_name)
-               return -1;
-
-       count = readlink(filename, path, PATH_MAX);
-       if (count >= PATH_MAX)
-               return -1;
-
-       /* For device does not have a driver */
-       if (count < 0)
-               return 1;
-
-       path[count] = '\0';
-
-       name = strrchr(path, '/');
-       if (name) {
-               strncpy(dri_name, name + 1, strlen(name + 1) + 1);
-               return 0;
-       }
-
-       return -1;
-}
-
 /* Map pci device */
 int
 rte_eal_pci_map_device(struct rte_pci_device *dev)
@@ -330,7 +301,7 @@ pci_scan_one(const char *dirname, uint16_t domain, uint8_t 
bus,

        /* parse driver */
        snprintf(filename, sizeof(filename), "%s/driver", dirname);
-       ret = pci_get_kernel_driver_by_path(filename, driver);
+       ret = rte_eal_get_kernel_driver_by_path(filename, driver);
        if (ret < 0) {
                RTE_LOG(ERR, EAL, "Fail to get kernel driver\n");
                free(dev);
-- 
2.8.0

Reply via email to