From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jan Viktorin Subject: [PATCH v1 04/28] eal/linux: extract function rte_eal_get_kernel_driver_by_path Date: Fri, 6 May 2016 15:47:46 +0200 Message-ID: <1462542490-15556-5-git-send-email-viktorin@rehivetech.com> References: <1462542490-15556-1-git-send-email-viktorin@rehivetech.com> Cc: Jan Viktorin , David Marchand , Thomas Monjalon , Bruce Richardson , Declan Doherty , jianbo.liu@linaro.org, jerin.jacob@caviumnetworks.com, Keith Wiles , Stephen Hemminger To: dev@dpdk.org Return-path: Received: from wes1-so2.wedos.net (wes1-so2.wedos.net [46.28.106.16]) by dpdk.org (Postfix) with ESMTP id A89E65594 for ; Fri, 6 May 2016 15:50:08 +0200 (CEST) In-Reply-To: <1462542490-15556-1-git-send-email-viktorin@rehivetech.com> In-Reply-To: <1451682326-5834-1-git-send-email-viktorin@rehivetech.com> References: <1451682326-5834-1-git-send-email-viktorin@rehivetech.com> List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 --- 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 ("/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