diff options
Diffstat (limited to 'src/vlibmemory/memory_api.c')
-rw-r--r-- | src/vlibmemory/memory_api.c | 104 |
1 files changed, 58 insertions, 46 deletions
diff --git a/src/vlibmemory/memory_api.c b/src/vlibmemory/memory_api.c index 752f50717b0..0ee1384f22b 100644 --- a/src/vlibmemory/memory_api.c +++ b/src/vlibmemory/memory_api.c @@ -198,6 +198,7 @@ vl_api_memclnt_create_t_handler (vl_api_memclnt_create_t * mp) regp->vl_api_registration_pool_index = regpp - am->vl_clients; regp->vlib_rp = svm; regp->shmem_hdr = am->shmem_hdr; + regp->clib_file_index = am->shmem_hdr->clib_file_index; q = regp->vl_input_queue = (svm_queue_t *) (uword) mp->input_queue; @@ -273,7 +274,7 @@ vl_api_memclnt_delete_t_handler (vl_api_memclnt_delete_t * mp) return; } - regpp = am->vl_clients + client_index; + regpp = pool_elt_at_index (am->vl_clients, client_index); if (!pool_is_free (am->vl_clients, regpp)) { @@ -509,11 +510,54 @@ send_memclnt_keepalive (vl_api_registration_t * regp, f64 now) am->shmem_hdr = save_shmem_hdr; } +static void +vl_mem_send_client_keepalive_w_reg (api_main_t * am, f64 now, + vl_api_registration_t ** regpp, + u32 ** dead_indices, + u32 ** confused_indices) +{ + vl_api_registration_t *regp = *regpp; + if (regp) + { + /* If we haven't heard from this client recently... */ + if (regp->last_heard < (now - 10.0)) + { + if (regp->unanswered_pings == 2) + { + svm_queue_t *q; + q = regp->vl_input_queue; + if (kill (q->consumer_pid, 0) >= 0) + { + clib_warning ("REAPER: lazy binary API client '%s'", + regp->name); + regp->unanswered_pings = 0; + regp->last_heard = now; + } + else + { + clib_warning ("REAPER: binary API client '%s' died", + regp->name); + vec_add1 (*dead_indices, regpp - am->vl_clients); + } + } + else + send_memclnt_keepalive (regp, now); + } + else + regp->unanswered_pings = 0; + } + else + { + clib_warning ("NULL client registration index %d", + regpp - am->vl_clients); + vec_add1 (*confused_indices, regpp - am->vl_clients); + } +} + void vl_mem_api_dead_client_scan (api_main_t * am, vl_shmem_hdr_t * shm, f64 now) { vl_api_registration_t **regpp; - vl_api_registration_t *regp; static u32 *dead_indices; static u32 *confused_indices; @@ -521,46 +565,12 @@ vl_mem_api_dead_client_scan (api_main_t * am, vl_shmem_hdr_t * shm, f64 now) vec_reset_length (confused_indices); /* *INDENT-OFF* */ - pool_foreach (regpp, am->vl_clients, - ({ - regp = *regpp; - if (regp) - { - /* If we haven't heard from this client recently... */ - if (regp->last_heard < (now - 10.0)) - { - if (regp->unanswered_pings == 2) - { - svm_queue_t *q; - q = regp->vl_input_queue; - if (kill (q->consumer_pid, 0) >=0) - { - clib_warning ("REAPER: lazy binary API client '%s'", - regp->name); - regp->unanswered_pings = 0; - regp->last_heard = now; - } - else - { - clib_warning ("REAPER: binary API client '%s' died", - regp->name); - vec_add1(dead_indices, regpp - am->vl_clients); - } - } - else - send_memclnt_keepalive (regp, now); - } - else - regp->unanswered_pings = 0; - } - else - { - clib_warning ("NULL client registration index %d", - regpp - am->vl_clients); - vec_add1 (confused_indices, regpp - am->vl_clients); - } + pool_foreach (regpp, am->vl_clients, ({ + vl_mem_send_client_keepalive_w_reg (am, now, regpp, &dead_indices, + &confused_indices); })); /* *INDENT-ON* */ + /* This should "never happen," but if it does, fix it... */ if (PREDICT_FALSE (vec_len (confused_indices) > 0)) { @@ -702,24 +712,26 @@ vl_mem_api_client_index_to_registration (u32 handle) vl_api_registration_t **regpp; vl_api_registration_t *regp; api_main_t *am = &api_main; + vl_shmem_hdr_t *shmem_hdr; u32 index; index = vl_msg_api_handle_get_index (handle); - if ((am->shmem_hdr->application_restarts & VL_API_EPOCH_MASK) - != vl_msg_api_handle_get_epoch (handle)) + regpp = am->vl_clients + index; + + if (pool_is_free (am->vl_clients, regpp)) { vl_msg_api_increment_missing_client_counter (); return 0; } + regp = *regpp; - regpp = am->vl_clients + index; - - if (pool_is_free (am->vl_clients, regpp)) + shmem_hdr = (vl_shmem_hdr_t *) regp->shmem_hdr; + if (!vl_msg_api_handle_is_valid (handle, shmem_hdr->application_restarts)) { vl_msg_api_increment_missing_client_counter (); return 0; } - regp = *regpp; + return (regp); } |