EAL provides a "check if a kernel module is loaded" function, but the only consumer of that function is VFIO. Move it and make it internal to VFIO.
Signed-off-by: Anatoly Burakov <[email protected]> --- lib/eal/common/eal_private.h | 14 ------------ lib/eal/linux/eal.c | 35 ------------------------------ lib/eal/linux/eal_vfio.c | 41 ++++++++++++++++++++++++++++++++++-- 3 files changed, 39 insertions(+), 51 deletions(-) diff --git a/lib/eal/common/eal_private.h b/lib/eal/common/eal_private.h index 6340bab8be0..8507791ec26 100644 --- a/lib/eal/common/eal_private.h +++ b/lib/eal/common/eal_private.h @@ -206,20 +206,6 @@ int rte_eal_alarm_init(void); */ void rte_eal_alarm_cleanup(void); -/** - * Function is to check if the kernel module(like, vfio, vfio_iommu_type1, - * etc.) loaded. - * - * @param module_name - * The module's name which need to be checked - * - * @return - * -1 means some error happens(NULL pointer or open failure) - * 0 means the module not loaded - * 1 means the module loaded - */ -int rte_eal_check_module(const char *module_name); - /** * Memory reservation flags. */ diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c index 5577bab24a2..1d0894e7eab 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -17,9 +17,7 @@ #include <fnmatch.h> #include <stddef.h> #include <errno.h> -#include <limits.h> #include <sys/mman.h> -#include <sys/stat.h> #if defined(RTE_ARCH_X86) #include <sys/io.h> #endif @@ -1028,36 +1026,3 @@ rte_eal_vfio_get_vf_token(rte_uuid_t vf_token) rte_uuid_copy(vf_token, cfg->vfio_vf_token); } -int -rte_eal_check_module(const char *module_name) -{ - char sysfs_mod_name[PATH_MAX]; - struct stat st; - int n; - - if (NULL == module_name) - return -1; - - /* Check if there is sysfs mounted */ - if (stat("/sys/module", &st) != 0) { - EAL_LOG(DEBUG, "sysfs is not mounted! error %i (%s)", - errno, strerror(errno)); - return -1; - } - - /* A module might be built-in, therefore try sysfs */ - n = snprintf(sysfs_mod_name, PATH_MAX, "/sys/module/%s", module_name); - if (n < 0 || n > PATH_MAX) { - EAL_LOG(DEBUG, "Could not format module path"); - return -1; - } - - if (stat(sysfs_mod_name, &st) != 0) { - EAL_LOG(DEBUG, "Module %s not found! error %i (%s)", - sysfs_mod_name, errno, strerror(errno)); - return 0; - } - - /* Module has been found */ - return 1; -} diff --git a/lib/eal/linux/eal_vfio.c b/lib/eal/linux/eal_vfio.c index 8959a161530..ce247362662 100644 --- a/lib/eal/linux/eal_vfio.c +++ b/lib/eal/linux/eal_vfio.c @@ -4,9 +4,12 @@ #include <uapi/linux/vfio.h> +#include <errno.h> #include <inttypes.h> +#include <limits.h> #include <string.h> #include <fcntl.h> +#include <sys/stat.h> #include <unistd.h> #include <sys/ioctl.h> #include <dirent.h> @@ -60,6 +63,40 @@ static struct vfio_config *default_vfio_cfg = &vfio_cfgs[0]; /* whether VFIO is enabled (usable) in this process */ static bool vfio_enabled; +static int +vfio_check_module(const char *module_name) +{ + char sysfs_mod_name[PATH_MAX]; + struct stat st; + int n; + + if (NULL == module_name) + return -1; + + /* Check if there is sysfs mounted */ + if (stat("/sys/module", &st) != 0) { + EAL_LOG(DEBUG, "sysfs is not mounted! error %i (%s)", + errno, strerror(errno)); + return -1; + } + + /* A module might be built-in, therefore try sysfs */ + n = snprintf(sysfs_mod_name, PATH_MAX, "/sys/module/%s", module_name); + if (n < 0 || n > PATH_MAX) { + EAL_LOG(DEBUG, "Could not format module path"); + return -1; + } + + if (stat(sysfs_mod_name, &st) != 0) { + EAL_LOG(DEBUG, "Module %s not found! error %i (%s)", + sysfs_mod_name, errno, strerror(errno)); + return 0; + } + + /* Module has been found */ + return 1; +} + static int vfio_type1_dma_map(int); static int vfio_type1_dma_mem_map(int, uint64_t, uint64_t, uint64_t, int); static int vfio_spapr_dma_map(int); @@ -1152,7 +1189,7 @@ rte_vfio_enable(const char *modname) EAL_LOG(DEBUG, "Probing VFIO support..."); /* check if vfio module is loaded */ - vfio_available = rte_eal_check_module(modname); + vfio_available = vfio_check_module(modname); /* return error directly */ if (vfio_available == -1) { @@ -1204,7 +1241,7 @@ RTE_EXPORT_INTERNAL_SYMBOL(rte_vfio_is_enabled) int rte_vfio_is_enabled(const char *modname) { - const int mod_available = rte_eal_check_module(modname) > 0; + const int mod_available = vfio_check_module(modname) > 0; return vfio_enabled && mod_available; } -- 2.52.0

