[PATCH v2 2/2] eal/linux: Add support for handling built-in kernel modules
From: Kamil Rytarowski <hidden>
Date: 2015-12-07 16:58:17
Subsystem:
library code, the rest · Maintainers:
Andrew Morton, Linus Torvalds
Currently rte_eal_check_module() detects Linux kernel modules via reading /proc/modules. Built-in ones aren't listed there and therefore they are not being found by the script. Add support for checking built-in modules with parsing the sysfs files Signed-off-by: Kamil Rytarowski <redacted> --- lib/librte_eal/linuxapp/eal/eal.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index 635ec36..6cab906 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c@@ -52,6 +52,8 @@ #if defined(RTE_ARCH_X86_64) || defined(RTE_ARCH_I686) #include <sys/io.h> #endif +#include <sys/types.h> +#include <sys/stat.h> #include <rte_common.h> #include <rte_debug.h>
@@ -902,7 +904,10 @@ int rte_eal_check_module(const char *module_name) { char mod_name[30]; /* Any module names can be longer than 30 bytes? */ + char sysfs_mod_name[PATH_MAX]; + struct stat st; int ret = 0; + int rv; int n; if (NULL == module_name)
@@ -918,9 +923,23 @@ rte_eal_check_module(const char *module_name) n = fscanf(fd, "%29s %*[^\n]", mod_name); if ((n == 1) && !strcmp(mod_name, module_name)) { ret = 1; - break; + goto finish; } } + RTE_LOG(DEBUG, EAL, "Module %s not found in /proc/modules", + module_name); + + /* A module might be builtin, try sysfs */ + snprintf(sysfs_mod_name, PATH_MAX, "/sys/module/%s", module_name); + if ((rv = stat(sysfs_mod_name, &st)) == 0) { + ret = 1; + goto finish; + } + + RTE_LOG(DEBUG, EAL, "Open %s failed! error %i (%s)\n", + sysfs_mod_name, errno, strerror(errno)); + +finish: fclose(fd); return ret;
--
2.5.0