aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2018-04-04 22:43:54 +0200
committerDave Barach <openvpp@barachs.net>2018-04-09 13:33:06 +0000
commit67d4c24b0a8d63c4b5a38d5c9c1ce72b75879f54 (patch)
tree74a18bea729d38b333e750c219849bebff8f35b2 /src
parent7bf3f9f70e8395c13ed235cb48ec1787b07cf2d9 (diff)
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>
Diffstat (limited to 'src')
-rw-r--r--src/vat/plugin.h1
-rw-r--r--src/vpp/api/plugin.c16
-rw-r--r--src/vpp/vnet/main.c54
3 files changed, 59 insertions, 12 deletions
diff --git a/src/vat/plugin.h b/src/vat/plugin.h
index c69186287aa..8dab168f1c1 100644
--- a/src/vat/plugin.h
+++ b/src/vat/plugin.h
@@ -26,6 +26,7 @@
typedef struct
{
u8 *name;
+ u8 *filename;
struct stat file_info;
void *handle;
} plugin_info_t;
diff --git a/src/vpp/api/plugin.c b/src/vpp/api/plugin.c
index 95bdbe6cd7e..1506a82ddca 100644
--- a/src/vpp/api/plugin.c
+++ b/src/vpp/api/plugin.c
@@ -24,13 +24,13 @@
plugin_main_t vat_plugin_main;
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;
clib_error_t *(*fp) (vat_main_t *);
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,
@@ -119,6 +119,7 @@ vat_load_new_plugins (plugin_main_t * pm)
while ((entry = readdir (dp)))
{
u8 *plugin_name;
+ u8 *file_name;
if (pm->plugin_name_filter)
{
@@ -128,13 +129,14 @@ vat_load_new_plugins (plugin_main_t * pm)
goto next;
}
- plugin_name = format (0, "%s/%s%c", plugin_path[i],
- entry->d_name, 0);
+ file_name = format (0, "%s/%s%c", plugin_path[i], entry->d_name, 0);
+ plugin_name = format (0, "%s%c", entry->d_name, 0);
/* unreadable */
- if (stat ((char *) plugin_name, &statb) < 0)
+ if (stat ((char *) file_name, &statb) < 0)
{
ignore:
+ vec_free (file_name);
vec_free (plugin_name);
continue;
}
@@ -148,10 +150,12 @@ vat_load_new_plugins (plugin_main_t * pm)
{
vec_add2 (pm->plugin_info, pi, 1);
pi->name = plugin_name;
+ pi->filename = file_name;
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_len (pm->plugin_info) = vec_len (pm->plugin_info) - 1;
continue;
diff --git a/src/vpp/vnet/main.c b/src/vpp/vnet/main.c
index b330f60fafe..6e136e19201 100644
--- a/src/vpp/vnet/main.c
+++ b/src/vpp/vnet/main.c
@@ -20,7 +20,53 @@
#include <vnet/ethernet/ethernet.h>
#include <vpp/app/version.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
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
*/
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";
-/*
- * 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
main (int argc, char *argv[])
{