plugins: odp: Fix error when all interfaces removed 95/9995/2
authorMichal Mazur <mkm@semihalf.com>
Thu, 4 Jan 2018 20:12:15 +0000 (21:12 +0100)
committerMichal Mazur <mkm@semihalf.com>
Thu, 11 Jan 2018 21:32:38 +0000 (22:32 +0100)
Packet pool cannot be destroyed when last interface is deleted
because it will not be reallocated on creation of a new interface.

Change-Id: Iec7b03b4413fc6602a7a1493ffd706f4c4dd1309
Signed-off-by: Michal Mazur <mkm@semihalf.com>
src/plugins/odp/odp_packet.c

index 2cf6ff9..e1b259f 100755 (executable)
@@ -278,7 +278,6 @@ odp_packet_delete_if (vlib_main_t * vm, u8 * host_if_name)
   odp_packet_main_t *om = odp_packet_main;
   odp_packet_if_t *oif = 0;
   uword *p;
-  vlib_thread_main_t *tm = vlib_get_thread_main ();
 
   p = mhash_get (&om->if_index_by_host_if_name, host_if_name);
 
@@ -306,13 +305,7 @@ odp_packet_delete_if (vlib_main_t * vm, u8 * host_if_name)
 
   pool_put (om->interfaces, oif);
 
-  if (tm->n_vlib_mains > 1 && pool_elts (om->interfaces) == 0)
-    {
-      odp_pool_destroy (om->pool);
-    }
-
   return 0;
-
 }
 
 static clib_error_t *
@@ -559,6 +552,26 @@ odp_packet_init (vlib_main_t * vm)
 
 VLIB_INIT_FUNCTION (odp_packet_init);
 
+static clib_error_t *
+odp_packet_exit (vlib_main_t *vm)
+{
+  odp_packet_main_t *om = odp_packet_main;
+  odp_packet_if_t *port;
+
+  pool_foreach (port, om->interfaces,
+    ({
+      odp_packet_delete_if (vm, port->host_if_name);
+    }));
+
+  odp_pool_destroy (om->pool);
+  odp_shm_free (odp_shm_lookup("odp_packet_main"));
+  odp_packet_main = 0x0;
+
+  return 0;
+}
+
+VLIB_MAIN_LOOP_EXIT_FUNCTION (odp_packet_exit);
+
 /* *INDENT-OFF* */
 VLIB_PLUGIN_REGISTER () = {
     .version = VPP_BUILD_VER,