aboutsummaryrefslogtreecommitdiffstats
path: root/src/vlib
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2018-04-05 21:32:29 +0200
committerDave Barach <openvpp@barachs.net>2018-04-09 16:06:20 +0000
commit72d2c4f3718ba5293e9e0fa8726406ee7d9f3940 (patch)
tree799a61d776b35e640bf2542148bcca946b926dca /src/vlib
parentf13a8787365300d757eca4624c8f8a6b7c49392b (diff)
plugins: unload plugin if early init fails
Change-Id: I32f68e2ee8f5d32962acdefb0193583f71d342b3 Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vlib')
-rw-r--r--src/vlib/buffer.h4
-rw-r--r--src/vlib/cli.h9
-rw-r--r--src/vlib/init.h63
-rw-r--r--src/vlib/mc.h8
-rw-r--r--src/vlib/node.h8
-rw-r--r--src/vlib/pci/pci.h8
-rw-r--r--src/vlib/threads.h7
-rw-r--r--src/vlib/unix/plugin.c6
8 files changed, 111 insertions, 2 deletions
diff --git a/src/vlib/buffer.h b/src/vlib/buffer.h
index 48988222de7..6d352ce580f 100644
--- a/src/vlib/buffer.h
+++ b/src/vlib/buffer.h
@@ -565,6 +565,10 @@ static void __vlib_add_buffer_callbacks_t_##x (void) \
clib_panic ("vlib buffer callbacks already registered"); \
vlib_buffer_callbacks = &__##x##_buffer_callbacks; \
} \
+static void __vlib_rm_buffer_callbacks_t_##x (void) \
+ __attribute__((__destructor__)) ; \
+static void __vlib_rm_buffer_callbacks_t_##x (void) \
+{ vlib_buffer_callbacks = 0; } \
__VA_ARGS__ vlib_buffer_callbacks_t __##x##_buffer_callbacks
/*
diff --git a/src/vlib/cli.h b/src/vlib/cli.h
index e713808f18e..e8ba507bfa8 100644
--- a/src/vlib/cli.h
+++ b/src/vlib/cli.h
@@ -162,6 +162,15 @@ static void __vlib_cli_command_registration_##x (void) \
x.next_cli_command = cm->cli_command_registrations; \
cm->cli_command_registrations = &x; \
} \
+static void __vlib_cli_command_unregistration_##x (void) \
+ __attribute__((__destructor__)) ; \
+static void __vlib_cli_command_unregistration_##x (void) \
+{ \
+ vlib_main_t * vm = vlib_get_main(); \
+ vlib_cli_main_t *cm = &vm->cli_main; \
+ VLIB_REMOVE_FROM_LINKED_LIST (cm->cli_command_registrations, &x, \
+ next_cli_command); \
+} \
__VA_ARGS__ vlib_cli_command_t x
#define VLIB_CLI_PARSE_RULE(x) \
vlib_cli_parse_rule_t x
diff --git a/src/vlib/init.h b/src/vlib/init.h
index 12db3f90b96..1eddbb13d5a 100644
--- a/src/vlib/init.h
+++ b/src/vlib/init.h
@@ -79,6 +79,25 @@ typedef struct vlib_config_function_runtime_t
char name[32];
} vlib_config_function_runtime_t;
+#define VLIB_REMOVE_FROM_LINKED_LIST(first,p,next) \
+{ \
+ if (first == p) \
+ first = (p)->next; \
+ else \
+ { \
+ __typeof__ (p) current = first; \
+ while (current->next) \
+ { \
+ if (current->next == p) \
+ { \
+ current->next = current->next->next; \
+ break; \
+ } \
+ current = current->next; \
+ } \
+ } \
+}
+
#define _VLIB_INIT_FUNCTION_SYMBOL(x, type) \
_vlib_##type##_function_##x
@@ -106,6 +125,30 @@ static void __vlib_add_##tag##_function_##x (void) \
= vm->tag##_function_registrations; \
vm->tag##_function_registrations = &_vlib_init_function; \
_vlib_init_function.f = &x; \
+} \
+static void __vlib_rm_##tag##_function_##x (void) \
+ __attribute__((__destructor__)) ; \
+static void __vlib_rm_##tag##_function_##x (void) \
+{ \
+ vlib_main_t * vm = vlib_get_main(); \
+ _vlib_init_function_list_elt_t *next; \
+ if (vm->tag##_function_registrations->f == &x) \
+ { \
+ vm->tag##_function_registrations = \
+ vm->tag##_function_registrations->next_init_function; \
+ return; \
+ } \
+ next = vm->tag##_function_registrations; \
+ while (next->next_init_function) \
+ { \
+ if (next->next_init_function->f == &x) \
+ { \
+ next->next_init_function = \
+ next->next_init_function->next_init_function; \
+ return; \
+ } \
+ next = next->next_init_function; \
+ } \
}
#define VLIB_INIT_FUNCTION(x) VLIB_DECLARE_INIT_FUNCTION(x,init)
@@ -129,6 +172,16 @@ static void __vlib_add_config_function_##x (void) \
vm->config_function_registrations \
= &VLIB_CONFIG_FUNCTION_SYMBOL(x); \
} \
+static void __vlib_rm_config_function_##x (void) \
+ __attribute__((__destructor__)) ; \
+static void __vlib_rm_config_function_##x (void) \
+{ \
+ vlib_main_t * vm = vlib_get_main(); \
+ vlib_config_function_runtime_t *p = \
+ & VLIB_CONFIG_FUNCTION_SYMBOL (x); \
+ VLIB_REMOVE_FROM_LINKED_LIST \
+ (vm->config_function_registrations, p, next_registration);\
+} \
vlib_config_function_runtime_t \
VLIB_CONFIG_FUNCTION_SYMBOL (x) \
= { \
@@ -150,6 +203,16 @@ static void __vlib_add_config_function_##x (void) \
vm->config_function_registrations \
= &VLIB_CONFIG_FUNCTION_SYMBOL(x); \
} \
+static void __vlib_rm_config_function_##x (void) \
+ __attribute__((__destructor__)) ; \
+static void __vlib_rm_config_function_##x (void) \
+{ \
+ vlib_main_t * vm = vlib_get_main(); \
+ vlib_config_function_runtime_t *p = \
+ & VLIB_CONFIG_FUNCTION_SYMBOL (x); \
+ VLIB_REMOVE_FROM_LINKED_LIST \
+ (vm->config_function_registrations, p, next_registration);\
+} \
vlib_config_function_runtime_t \
VLIB_CONFIG_FUNCTION_SYMBOL (x) \
= { \
diff --git a/src/vlib/mc.h b/src/vlib/mc.h
index dc95b0e9074..28f94350537 100644
--- a/src/vlib/mc.h
+++ b/src/vlib/mc.h
@@ -261,6 +261,14 @@ static void __mc_serialize_msg_registration_##x (void) \
x.next_registration = vm->mc_msg_registrations; \
vm->mc_msg_registrations = &x; \
} \
+static void __mc_serialize_msg_unregistration_##x (void) \
+ __attribute__((__destructor__)) ; \
+static void __mc_serialize_msg_unregistration_##x (void) \
+{ \
+ vlib_main_t * vm = vlib_get_main(); \
+ VLIB_REMOVE_FROM_LINKED_LIST (vm->mc_msg_registrations, &x, \
+ next_registration); \
+} \
__VA_ARGS__ mc_serialize_msg_t x
typedef enum
diff --git a/src/vlib/node.h b/src/vlib/node.h
index 2acd61ce3f6..7177bebeffb 100644
--- a/src/vlib/node.h
+++ b/src/vlib/node.h
@@ -150,6 +150,14 @@ static void __vlib_add_node_registration_##x (void) \
x.next_registration = vm->node_main.node_registrations; \
vm->node_main.node_registrations = &x; \
} \
+static void __vlib_rm_node_registration_##x (void) \
+ __attribute__((__destructor__)) ; \
+static void __vlib_rm_node_registration_##x (void) \
+{ \
+ vlib_main_t * vm = vlib_get_main(); \
+ VLIB_REMOVE_FROM_LINKED_LIST (vm->node_main.node_registrations, \
+ &x, next_registration); \
+} \
__VA_ARGS__ vlib_node_registration_t x
#if CLIB_DEBUG > 0
diff --git a/src/vlib/pci/pci.h b/src/vlib/pci/pci.h
index ec805b3ed53..a705671d875 100644
--- a/src/vlib/pci/pci.h
+++ b/src/vlib/pci/pci.h
@@ -159,6 +159,14 @@ static void __vlib_add_pci_device_registration_##x (void) \
x.next_registration = pm->pci_device_registrations; \
pm->pci_device_registrations = &x; \
} \
+static void __vlib_rm_pci_device_registration_##x (void) \
+ __attribute__((__destructor__)) ; \
+static void __vlib_rm_pci_device_registration_##x (void) \
+{ \
+ vlib_pci_main_t * pm = &pci_main; \
+ VLIB_REMOVE_FROM_LINKED_LIST (pm->pci_device_registrations, \
+ &x, next_registration); \
+} \
__VA_ARGS__ pci_device_registration_t x
clib_error_t *vlib_pci_bind_to_uio (vlib_pci_addr_t * addr,
diff --git a/src/vlib/threads.h b/src/vlib/threads.h
index 8931584b5a9..aaba218ffd3 100644
--- a/src/vlib/threads.h
+++ b/src/vlib/threads.h
@@ -362,6 +362,13 @@ static void __vlib_add_thread_registration_##x (void) \
x.next = tm->next; \
tm->next = &x; \
} \
+static void __vlib_rm_thread_registration_##x (void) \
+ __attribute__((__destructor__)) ; \
+static void __vlib_rm_thread_registration_##x (void) \
+{ \
+ vlib_thread_main_t * tm = &vlib_thread_main; \
+ VLIB_REMOVE_FROM_LINKED_LIST (tm->next, &x, next); \
+} \
__VA_ARGS__ vlib_thread_registration_t x
always_inline u32
diff --git a/src/vlib/unix/plugin.c b/src/vlib/unix/plugin.c
index b4eb0b92fb4..61eaad471ff 100644
--- a/src/vlib/unix/plugin.c
+++ b/src/vlib/unix/plugin.c
@@ -155,7 +155,8 @@ load_one_plugin (plugin_main_t * pm, plugin_info_t * pi, int from_early_init)
{
/* This should never happen unless somebody chagnes registration macro */
clib_warning ("Missing plugin registration in plugin '%s'", pi->name);
- os_exit (1);
+ dlclose (pi->handle);
+ goto error;
}
pi->reg = reg;
@@ -175,7 +176,8 @@ load_one_plugin (plugin_main_t * pm, plugin_info_t * pi, int from_early_init)
if (error)
{
clib_error_report (error);
- os_exit (1);
+ dlclose (pi->handle);
+ goto error;
}
}
else