Autodetect plugin path

dpdk plugin self-disables if there are no hugepages available

Change-Id: Ib286e1a370deeb21248e6e961573ef9c68759b4c
Signed-off-by: Damjan Marion <damarion@cisco.com>
Signed-off-by: Dave Barach <dave@barachs.net>
This commit is contained in:
Damjan Marion
2018-04-04 22:43:54 +02:00
committed by Dave Barach
parent 7bf3f9f70e
commit 67d4c24b0a
4 changed files with 61 additions and 16 deletions

View File

@ -410,14 +410,12 @@ define run
@echo "WARNING: STARTUP_CONF not defined or file doesn't exist." @echo "WARNING: STARTUP_CONF not defined or file doesn't exist."
@echo " Running with minimal startup config: $(MINIMAL_STARTUP_CONF)\n" @echo " Running with minimal startup config: $(MINIMAL_STARTUP_CONF)\n"
@cd $(STARTUP_DIR) && \ @cd $(STARTUP_DIR) && \
sudo $(2) $(1)/vpp/bin/vpp $(MINIMAL_STARTUP_CONF) \ sudo $(2) $(1)/vpp/bin/vpp $(MINIMAL_STARTUP_CONF)
plugin_path $(subst $(subst ,, ),:,$(wildcard $(1)/*/lib*/vpp_plugins))
endef endef
else else
define run define run
@cd $(STARTUP_DIR) && \ @cd $(STARTUP_DIR) && \
sudo $(2) $(1)/vpp/bin/vpp $(shell cat $(STARTUP_CONF) | sed -e 's/#.*//') \ sudo $(2) $(1)/vpp/bin/vpp $(shell cat $(STARTUP_CONF) | sed -e 's/#.*//')
plugin_path $(subst $(subst ,, ),:,$(wildcard $(1)/*/lib*/vpp_plugins))
endef endef
endif endif

View File

@ -26,6 +26,7 @@
typedef struct typedef struct
{ {
u8 *name; u8 *name;
u8 *filename;
struct stat file_info; struct stat file_info;
void *handle; void *handle;
} plugin_info_t; } plugin_info_t;

View File

@ -24,13 +24,13 @@
plugin_main_t vat_plugin_main; plugin_main_t vat_plugin_main;
static int static int
load_one_plugin (plugin_main_t * pm, plugin_info_t * pi) load_one_vat_plugin (plugin_main_t * pm, plugin_info_t * pi)
{ {
void *handle, *register_handle; void *handle, *register_handle;
clib_error_t *(*fp) (vat_main_t *); clib_error_t *(*fp) (vat_main_t *);
clib_error_t *error; clib_error_t *error;
handle = dlopen ((char *) pi->name, RTLD_LAZY); handle = dlopen ((char *) pi->filename, RTLD_LAZY);
/* /*
* Note: this can happen if the plugin has an undefined symbol reference, * Note: this can happen if the plugin has an undefined symbol reference,
@ -119,6 +119,7 @@ vat_load_new_plugins (plugin_main_t * pm)
while ((entry = readdir (dp))) while ((entry = readdir (dp)))
{ {
u8 *plugin_name; u8 *plugin_name;
u8 *file_name;
if (pm->plugin_name_filter) if (pm->plugin_name_filter)
{ {
@ -128,13 +129,14 @@ vat_load_new_plugins (plugin_main_t * pm)
goto next; goto next;
} }
plugin_name = format (0, "%s/%s%c", plugin_path[i], file_name = format (0, "%s/%s%c", plugin_path[i], entry->d_name, 0);
entry->d_name, 0); plugin_name = format (0, "%s%c", entry->d_name, 0);
/* unreadable */ /* unreadable */
if (stat ((char *) plugin_name, &statb) < 0) if (stat ((char *) file_name, &statb) < 0)
{ {
ignore: ignore:
vec_free (file_name);
vec_free (plugin_name); vec_free (plugin_name);
continue; continue;
} }
@ -148,10 +150,12 @@ vat_load_new_plugins (plugin_main_t * pm)
{ {
vec_add2 (pm->plugin_info, pi, 1); vec_add2 (pm->plugin_info, pi, 1);
pi->name = plugin_name; pi->name = plugin_name;
pi->filename = file_name;
pi->file_info = statb; pi->file_info = statb;
if (load_one_plugin (pm, pi)) if (load_one_vat_plugin (pm, pi))
{ {
vec_free (file_name);
vec_free (plugin_name); vec_free (plugin_name);
_vec_len (pm->plugin_info) = vec_len (pm->plugin_info) - 1; _vec_len (pm->plugin_info) = vec_len (pm->plugin_info) - 1;
continue; continue;

View File

@ -20,7 +20,53 @@
#include <vnet/ethernet/ethernet.h> #include <vnet/ethernet/ethernet.h>
#include <vpp/app/version.h> #include <vpp/app/version.h>
#include <vpp/api/vpe_msg_enum.h> #include <vpp/api/vpe_msg_enum.h>
#include <limits.h>
/*
* Load plugins from /usr/lib/vpp_plugins by default
*/
char *vlib_plugin_path = "/usr/lib/vpp_plugins";
char *vlib_plugin_app_version = VPP_BUILD_VER;
static void
vpp_find_plugin_path ()
{
extern char *vat_plugin_path;
char *p, path[PATH_MAX];
int rv;
u8 *s;
/* find executable path */
if ((rv = readlink ("/proc/self/exe", path, PATH_MAX - 1)) == -1)
return;
/* readlink doesn't provide null termination */
path[rv] = 0;
/* strip filename */
if ((p = strrchr (path, '/')) == 0)
return;
*p = 0;
/* strip bin/ */
if ((p = strrchr (path, '/')) == 0)
return;
*p = 0;
s = format (0, "%s/lib/vpp_plugins", path);
#if uword_bits == 64
s = format (s, ":%s/lib64/vpp_plugins", path);
#endif
vec_add1 (s, 0);
vlib_plugin_path = (char *) s;
s = format (0, "%s/lib/vpp_api_test_plugins", path);
#if uword_bits == 64
s = format (s, ":%s/lib64/vpp_api_test_plugins", path);
#endif
vec_add1 (s, 0);
vat_plugin_path = (char *) s;
}
static void static void
vpe_main_init (vlib_main_t * vm) vpe_main_init (vlib_main_t * vm)
@ -39,6 +85,8 @@ vpe_main_init (vlib_main_t * vm)
* Create the binary api plugin hashes before loading plugins * Create the binary api plugin hashes before loading plugins
*/ */
vat_plugin_hash_create (); vat_plugin_hash_create ();
vpp_find_plugin_path ();
} }
/* /*
@ -46,12 +94,6 @@ vpe_main_init (vlib_main_t * vm)
*/ */
char *vlib_default_runtime_dir = "vpp"; char *vlib_default_runtime_dir = "vpp";
/*
* Load plugins from /usr/lib/vpp_plugins by default
*/
char *vlib_plugin_path = "/usr/lib/vpp_plugins";
char *vlib_plugin_app_version = VPP_BUILD_VER;
int int
main (int argc, char *argv[]) main (int argc, char *argv[])
{ {