eal: move plugin loading from linuxapp to common
There's no good reason to limit plugins to Linux, make it available on FreeBSD too. Refactor the plugin code from Linux EAL to common helper functions, also check for and fail on errors during initialization. Signed-off-by: Panu Matilainen <pmatilai@redhat.com> Acked-by: David Marchand <david.marchand@6wind.com>
This commit is contained in:
parent
3ca3325578
commit
fa9cdc6f84
@ -571,6 +571,9 @@ rte_eal_init(int argc, char **argv)
|
||||
|
||||
rte_eal_mcfg_complete();
|
||||
|
||||
if (eal_plugins_init() < 0)
|
||||
rte_panic("Cannot init plugins\n");
|
||||
|
||||
eal_thread_init_master(rte_config.master_lcore);
|
||||
|
||||
ret = eal_thread_dump_affinity(cpuset, RTE_CPU_AFFINITY_STR_LEN);
|
||||
|
@ -39,6 +39,7 @@
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
#include <getopt.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include <rte_eal.h>
|
||||
#include <rte_log.h>
|
||||
@ -94,6 +95,20 @@ eal_long_options[] = {
|
||||
{0, 0, NULL, 0 }
|
||||
};
|
||||
|
||||
TAILQ_HEAD(shared_driver_list, shared_driver);
|
||||
|
||||
/* Definition for shared object drivers. */
|
||||
struct shared_driver {
|
||||
TAILQ_ENTRY(shared_driver) next;
|
||||
|
||||
char name[PATH_MAX];
|
||||
void* lib_handle;
|
||||
};
|
||||
|
||||
/* List of external loadable drivers */
|
||||
static struct shared_driver_list solib_list =
|
||||
TAILQ_HEAD_INITIALIZER(solib_list);
|
||||
|
||||
static int master_lcore_parsed;
|
||||
static int mem_parsed;
|
||||
|
||||
@ -134,6 +149,40 @@ eal_reset_internal_config(struct internal_config *internal_cfg)
|
||||
internal_cfg->create_uio_dev = 0;
|
||||
}
|
||||
|
||||
static int
|
||||
eal_plugin_add(const char *path)
|
||||
{
|
||||
struct shared_driver *solib;
|
||||
|
||||
solib = malloc(sizeof(*solib));
|
||||
if (solib == NULL) {
|
||||
RTE_LOG(ERR, EAL, "malloc(solib) failed\n");
|
||||
return -1;
|
||||
}
|
||||
memset(solib, 0, sizeof(*solib));
|
||||
strncpy(solib->name, path, PATH_MAX-1);
|
||||
solib->name[PATH_MAX-1] = 0;
|
||||
TAILQ_INSERT_TAIL(&solib_list, solib, next);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
eal_plugins_init(void)
|
||||
{
|
||||
struct shared_driver *solib = NULL;
|
||||
|
||||
TAILQ_FOREACH(solib, &solib_list, next) {
|
||||
RTE_LOG(DEBUG, EAL, "open shared lib %s\n", solib->name);
|
||||
solib->lib_handle = dlopen(solib->name, RTLD_NOW);
|
||||
if (solib->lib_handle == NULL) {
|
||||
RTE_LOG(ERR, EAL, "%s\n", dlerror());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse the coremask given as argument (hexadecimal string) and fill
|
||||
* the global configuration (core role and core count) with the parsed
|
||||
@ -706,6 +755,11 @@ eal_parse_common_option(int opt, const char *optarg,
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
/* force loading of external driver */
|
||||
case 'd':
|
||||
if (eal_plugin_add(optarg) == -1)
|
||||
return -1;
|
||||
break;
|
||||
case 'v':
|
||||
/* since message is explicitly requested by user, we
|
||||
* write message at highest log level so it can always
|
||||
@ -894,6 +948,7 @@ eal_common_usage(void)
|
||||
" --"OPT_VDEV" Add a virtual device.\n"
|
||||
" The argument format is <driver><id>[,key=val,...]\n"
|
||||
" (ex: --vdev=eth_pcap0,iface=eth2).\n"
|
||||
" -d LIB.so Add driver (can be used multiple times)\n"
|
||||
" --"OPT_VMWARE_TSC_MAP" Use VMware TSC map instead of native RDTSC\n"
|
||||
" --"OPT_PROC_TYPE" Type of this process (primary|secondary|auto)\n"
|
||||
" --"OPT_SYSLOG" Set syslog facility\n"
|
||||
|
@ -95,5 +95,6 @@ int eal_adjust_config(struct internal_config *internal_cfg);
|
||||
int eal_check_common_options(struct internal_config *internal_cfg);
|
||||
void eal_common_usage(void);
|
||||
enum rte_proc_type_t eal_proc_type_detect(void);
|
||||
int eal_plugins_init(void);
|
||||
|
||||
#endif /* EAL_OPTIONS_H */
|
||||
|
@ -43,7 +43,6 @@
|
||||
#include <getopt.h>
|
||||
#include <sys/file.h>
|
||||
#include <fcntl.h>
|
||||
#include <dlfcn.h>
|
||||
#include <stddef.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
@ -90,20 +89,6 @@
|
||||
/* Allow the application to print its usage message too if set */
|
||||
static rte_usage_hook_t rte_application_usage_hook = NULL;
|
||||
|
||||
TAILQ_HEAD(shared_driver_list, shared_driver);
|
||||
|
||||
/* Definition for shared object drivers. */
|
||||
struct shared_driver {
|
||||
TAILQ_ENTRY(shared_driver) next;
|
||||
|
||||
char name[PATH_MAX];
|
||||
void* lib_handle;
|
||||
};
|
||||
|
||||
/* List of external loadable drivers */
|
||||
static struct shared_driver_list solib_list =
|
||||
TAILQ_HEAD_INITIALIZER(solib_list);
|
||||
|
||||
/* early configuration structure, when memory config is not mmapped */
|
||||
static struct rte_mem_config early_mem_config;
|
||||
|
||||
@ -350,7 +335,6 @@ eal_usage(const char *prgname)
|
||||
printf("\nUsage: %s ", prgname);
|
||||
eal_common_usage();
|
||||
printf("EAL Linux options:\n"
|
||||
" -d LIB.so Add driver (can be used multiple times)\n"
|
||||
" --"OPT_SOCKET_MEM" Memory to allocate on sockets (comma separated values)\n"
|
||||
" --"OPT_HUGE_DIR" Directory where hugetlbfs is mounted\n"
|
||||
" --"OPT_FILE_PREFIX" Prefix for hugepage filenames\n"
|
||||
@ -545,7 +529,6 @@ eal_parse_args(int argc, char **argv)
|
||||
char **argvopt;
|
||||
int option_index;
|
||||
char *prgname = argv[0];
|
||||
struct shared_driver *solib;
|
||||
const int old_optind = optind;
|
||||
const int old_optopt = optopt;
|
||||
char * const old_optarg = optarg;
|
||||
@ -579,20 +562,6 @@ eal_parse_args(int argc, char **argv)
|
||||
eal_usage(prgname);
|
||||
exit(EXIT_SUCCESS);
|
||||
|
||||
/* force loading of external driver */
|
||||
case 'd':
|
||||
solib = malloc(sizeof(*solib));
|
||||
if (solib == NULL) {
|
||||
RTE_LOG(ERR, EAL, "malloc(solib) failed\n");
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
memset(solib, 0, sizeof(*solib));
|
||||
strncpy(solib->name, optarg, PATH_MAX-1);
|
||||
solib->name[PATH_MAX-1] = 0;
|
||||
TAILQ_INSERT_TAIL(&solib_list, solib, next);
|
||||
break;
|
||||
|
||||
/* long options */
|
||||
case OPT_XEN_DOM0_NUM:
|
||||
#ifdef RTE_LIBRTE_XEN_DOM0
|
||||
@ -758,7 +727,6 @@ rte_eal_init(int argc, char **argv)
|
||||
int i, fctret, ret;
|
||||
pthread_t thread_id;
|
||||
static rte_atomic32_t run_once = RTE_ATOMIC32_INIT(0);
|
||||
struct shared_driver *solib = NULL;
|
||||
const char *logid;
|
||||
char cpuset[RTE_CPU_AFFINITY_STR_LEN];
|
||||
char thread_name[RTE_MAX_THREAD_NAME_LEN];
|
||||
@ -852,12 +820,8 @@ rte_eal_init(int argc, char **argv)
|
||||
|
||||
rte_eal_mcfg_complete();
|
||||
|
||||
TAILQ_FOREACH(solib, &solib_list, next) {
|
||||
RTE_LOG(DEBUG, EAL, "open shared lib %s\n", solib->name);
|
||||
solib->lib_handle = dlopen(solib->name, RTLD_NOW);
|
||||
if (solib->lib_handle == NULL)
|
||||
RTE_LOG(WARNING, EAL, "%s\n", dlerror());
|
||||
}
|
||||
if (eal_plugins_init() < 0)
|
||||
rte_panic("Cannot init plugins\n");
|
||||
|
||||
eal_thread_init_master(rte_config.master_lcore);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user