avf: fix race between avf and cli/api process
[vpp.git] / src / plugins / avf / cli.c
index cd5f02d..32c19f4 100644 (file)
@@ -34,7 +34,7 @@ avf_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
   avf_create_if_args_t args;
   u32 tmp;
 
-  memset (&args, 0, sizeof (avf_create_if_args_t));
+  clib_memset (&args, 0, sizeof (avf_create_if_args_t));
 
   /* Get a line of input. */
   if (!unformat_user (input, unformat_line_input, line_input))
@@ -52,6 +52,8 @@ avf_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
        args.txq_size = tmp;
       else if (unformat (line_input, "num-rx-queues %u", &tmp))
        args.rxq_num = tmp;
+      else if (unformat (line_input, "name %s", &args.name))
+       ;
       else
        return clib_error_return (0, "unknown input `%U'",
                                  format_unformat_error, input);
@@ -60,6 +62,8 @@ avf_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
 
   avf_create_if (vm, &args);
 
+  vec_free (args.name);
+
   return args.error;
 }
 
@@ -80,8 +84,6 @@ avf_delete_command_fn (vlib_main_t * vm, unformat_input_t * input,
   unformat_input_t _line_input, *line_input = &_line_input;
   u32 sw_if_index = ~0;
   vnet_hw_interface_t *hw;
-  avf_main_t *am = &avf_main;
-  avf_device_t *ad;
   vnet_main_t *vnm = vnet_get_main ();
 
   /* Get a line of input. */
@@ -105,13 +107,12 @@ avf_delete_command_fn (vlib_main_t * vm, unformat_input_t * input,
     return clib_error_return (0,
                              "please specify interface name or sw_if_index");
 
-  hw = vnet_get_sup_hw_interface (vnm, sw_if_index);
+  hw = vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index);
   if (hw == NULL || avf_device_class.index != hw->dev_class_index)
     return clib_error_return (0, "not an AVF interface");
 
-  ad = pool_elt_at_index (am->devices, hw->dev_instance);
-
-  avf_delete_if (vm, ad);
+  vlib_process_signal_event (vm, avf_process_node.index,
+                            AVF_PROCESS_EVENT_DELETE_IF, hw->dev_instance);
 
   return 0;
 }
@@ -122,6 +123,7 @@ VLIB_CLI_COMMAND (avf_delete_command, static) = {
   .short_help = "delete interface avf "
     "{<interface> | sw_if_index <sw_idx>}",
   .function = avf_delete_command_fn,
+  .is_mp_safe = 1,
 };
 /* *INDENT-ON* */
 
@@ -132,7 +134,6 @@ avf_test_command_fn (vlib_main_t * vm, unformat_input_t * input,
   unformat_input_t _line_input, *line_input = &_line_input;
   u32 sw_if_index = ~0;
   vnet_hw_interface_t *hw;
-  avf_main_t *am = &avf_main;
   avf_device_t *ad;
   vnet_main_t *vnm = vnet_get_main ();
   int test_irq = 0, enable_elog = 0, disable_elog = 0;
@@ -164,11 +165,11 @@ avf_test_command_fn (vlib_main_t * vm, unformat_input_t * input,
     return clib_error_return (0,
                              "please specify interface name or sw_if_index");
 
-  hw = vnet_get_sup_hw_interface (vnm, sw_if_index);
+  hw = vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index);
   if (hw == NULL || avf_device_class.index != hw->dev_class_index)
     return clib_error_return (0, "not a AVF interface");
 
-  ad = pool_elt_at_index (am->devices, hw->dev_instance);
+  ad = avf_get_device (hw->dev_instance);
 
   if (enable_elog)
     ad->flags |= AVF_DEVICE_F_ELOG;