bapi: add options to have vpp cleanup client registration

A client can send a memclnt delete message and ask vpp to cleanup the
shared memory queue. Obviously, in this case no delete reply is sent
back to the client.

Change-Id: I9c8375093f8607680ad498a6bed0690ba02a7c3b
Signed-off-by: Florin Coras <fcoras@cisco.com>
This commit is contained in:
Florin Coras
2018-12-04 16:34:05 -08:00
committed by Dave Barach
parent 955bfbbb69
commit eaec2a6d9a
5 changed files with 36 additions and 25 deletions

View File

@ -737,14 +737,17 @@ vcl_intercept_sigchld_handler (int signum, siginfo_t * si, void *uc)
return; return;
child_wrk = vcl_worker_get_if_valid (wrk->forked_child); child_wrk = vcl_worker_get_if_valid (wrk->forked_child);
if (si->si_pid != child_wrk->current_pid) if (!child_wrk)
goto done;
if (si && si->si_pid != child_wrk->current_pid)
{ {
VDBG (0, "unexpected child pid %u", si->si_pid); VDBG (0, "unexpected child pid %u", si->si_pid);
return; goto done;
} }
if (child_wrk)
vcl_cleanup_forked_child (wrk, child_wrk); vcl_cleanup_forked_child (wrk, child_wrk);
done:
if (old_sa.sa_flags & SA_SIGINFO) if (old_sa.sa_flags & SA_SIGINFO)
{ {
void (*fn) (int, siginfo_t *, void *) = old_sa.sa_sigaction; void (*fn) (int, siginfo_t *, void *) = old_sa.sa_sigaction;
@ -848,7 +851,7 @@ vppcom_app_exit (void)
if (vec_len (vcm->workers) == 1) if (vec_len (vcm->workers) == 1)
vl_client_disconnect_from_vlib (); vl_client_disconnect_from_vlib ();
else else
vl_client_send_disconnect (); vl_client_send_disconnect (1 /* vpp should cleanup */ );
} }
/* /*

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
option version = "2.0.0"; option version = "2.1.0";
/* /*
* Define services not following the normal conventions here * Define services not following the normal conventions here
@ -53,6 +53,7 @@ manual_print
define memclnt_delete { define memclnt_delete {
u32 index; /* index, used e.g. by API trace replay */ u32 index; /* index, used e.g. by API trace replay */
u64 handle; /* handle by which vlib knows this client */ u64 handle; /* handle by which vlib knows this client */
u8 do_cleanup; /* vlib to cleanup the registration */
}; };
define memclnt_delete_reply { define memclnt_delete_reply {

View File

@ -296,6 +296,9 @@ vl_api_memclnt_delete_t_handler (vl_api_memclnt_delete_t * mp)
svm = am->vlib_rp; svm = am->vlib_rp;
int private_registration = 0; int private_registration = 0;
/* Send reply unless client asked us to do the cleanup */
if (!mp->do_cleanup)
{
/* /*
* Note: the API message handling path will set am->vlib_rp * Note: the API message handling path will set am->vlib_rp
* as appropriate for pairwise / private memory segments * as appropriate for pairwise / private memory segments
@ -306,14 +309,15 @@ vl_api_memclnt_delete_t_handler (vl_api_memclnt_delete_t * mp)
rp->response = 1; rp->response = 1;
vl_msg_api_send_shmem (regp->vl_input_queue, (u8 *) & rp); vl_msg_api_send_shmem (regp->vl_input_queue, (u8 *) & rp);
if (client_index != regp->vl_api_registration_pool_index) if (client_index != regp->vl_api_registration_pool_index)
{ {
clib_warning ("mismatch client_index %d pool_index %d", clib_warning ("mismatch client_index %d pool_index %d",
client_index, regp->vl_api_registration_pool_index); client_index,
regp->vl_api_registration_pool_index);
vl_msg_api_free (rp); vl_msg_api_free (rp);
return; return;
} }
}
/* For horizontal scaling, add a hash table... */ /* For horizontal scaling, add a hash table... */
for (i = 0; i < vec_len (am->vlib_private_rps); i++) for (i = 0; i < vec_len (am->vlib_private_rps); i++)
@ -352,6 +356,8 @@ vl_api_memclnt_delete_t_handler (vl_api_memclnt_delete_t * mp)
regp->vl_api_registration_pool_index); regp->vl_api_registration_pool_index);
pthread_mutex_lock (&svm->mutex); pthread_mutex_lock (&svm->mutex);
oldheap = svm_push_data_heap (svm); oldheap = svm_push_data_heap (svm);
if (mp->do_cleanup)
svm_queue_free (regp->vl_input_queue);
vec_free (regp->name); vec_free (regp->name);
/* Poison the old registration */ /* Poison the old registration */
clib_memset (regp, 0xF1, sizeof (*regp)); clib_memset (regp, 0xF1, sizeof (*regp));

View File

@ -271,7 +271,7 @@ vl_api_memclnt_delete_reply_t_handler (vl_api_memclnt_delete_reply_t * mp)
} }
void void
vl_client_send_disconnect (void) vl_client_send_disconnect (u8 do_cleanup)
{ {
vl_api_memclnt_delete_t *mp; vl_api_memclnt_delete_t *mp;
vl_shmem_hdr_t *shmem_hdr; vl_shmem_hdr_t *shmem_hdr;
@ -286,6 +286,7 @@ vl_client_send_disconnect (void)
mp->_vl_msg_id = ntohs (VL_API_MEMCLNT_DELETE); mp->_vl_msg_id = ntohs (VL_API_MEMCLNT_DELETE);
mp->index = am->my_client_index; mp->index = am->my_client_index;
mp->handle = (uword) am->my_registration; mp->handle = (uword) am->my_registration;
mp->do_cleanup = do_cleanup;
vl_msg_api_send_shmem (shmem_hdr->vl_input_queue, (u8 *) & mp); vl_msg_api_send_shmem (shmem_hdr->vl_input_queue, (u8 *) & mp);
} }
@ -299,7 +300,7 @@ vl_client_disconnect (void)
time_t begin; time_t begin;
vl_input_queue = am->vl_input_queue; vl_input_queue = am->vl_input_queue;
vl_client_send_disconnect (); vl_client_send_disconnect (0 /* wait for reply */ );
/* /*
* Have to be careful here, in case the client is disconnecting * Have to be careful here, in case the client is disconnecting

View File

@ -21,7 +21,7 @@
#include <vlibmemory/memory_shared.h> #include <vlibmemory/memory_shared.h>
int vl_client_connect (const char *name, int ctx_quota, int input_queue_size); int vl_client_connect (const char *name, int ctx_quota, int input_queue_size);
void vl_client_send_disconnect (void); void vl_client_send_disconnect (u8 do_cleanup);
int vl_client_disconnect (void); int vl_client_disconnect (void);
int vl_client_api_map (const char *region_name); int vl_client_api_map (const char *region_name);
void vl_client_api_unmap (void); void vl_client_api_unmap (void);