X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Fsession%2Fsegment_manager.c;h=b40675ad56f4e82181815c8b67bfb0d7cc3f935c;hb=6d7552ca885fe385818d380d7e0b4aff03c59d83;hp=ad5db656c770dd2c66d5874344eccaf24df29e0f;hpb=65c30ceb92dd79c7b00e8c31119db98d473dbfbb;p=vpp.git diff --git a/src/vnet/session/segment_manager.c b/src/vnet/session/segment_manager.c index ad5db656c77..b40675ad56f 100644 --- a/src/vnet/session/segment_manager.c +++ b/src/vnet/session/segment_manager.c @@ -211,6 +211,15 @@ segment_manager_del_segment (segment_manager_t * sm, fifo_segment_t * fs) pool_put (sm->segments, fs); } +static fifo_segment_t * +segment_manager_get_segment_if_valid (segment_manager_t * sm, + u32 segment_index) +{ + if (pool_is_free_index (sm->segments, segment_index)) + return 0; + return pool_elt_at_index (sm->segments, segment_index); +} + /** * Removes segment after acquiring writer lock */ @@ -221,15 +230,18 @@ segment_manager_lock_and_del_segment (segment_manager_t * sm, u32 fs_index) u8 is_prealloc; clib_rwlock_writer_lock (&sm->segments_rwlock); - fs = segment_manager_get_segment (sm, fs_index); + + fs = segment_manager_get_segment_if_valid (sm, fs_index); + if (!fs) + goto done; + is_prealloc = fifo_segment_flags (fs) & FIFO_SEGMENT_F_IS_PREALLOCATED; if (is_prealloc && !segment_manager_app_detached (sm)) - { - clib_rwlock_writer_unlock (&sm->segments_rwlock); - return; - } + goto done; segment_manager_del_segment (sm, fs); + +done: clib_rwlock_writer_unlock (&sm->segments_rwlock); } @@ -664,12 +676,12 @@ alloc_check: { clib_warning ("Added a segment, still can't allocate a fifo"); segment_manager_segment_reader_unlock (sm); - return SESSION_ERROR_NEW_SEG_NO_SPACE; + return SESSION_E_SEG_NO_SPACE2; } if ((new_fs_index = segment_manager_add_segment (sm, 0)) < 0) { clib_warning ("Failed to add new segment"); - return SESSION_ERROR_SEG_CREATE; + return SESSION_E_SEG_CREATE; } fs = segment_manager_get_segment_w_lock (sm, new_fs_index); alloc_fail = segment_manager_try_alloc_fifos (fs, thread_index, @@ -682,7 +694,7 @@ alloc_check: else { clib_warning ("Can't add new seg and no space to allocate fifos!"); - return SESSION_ERROR_NO_SPACE; + return SESSION_E_SEG_NO_SPACE; } } @@ -731,6 +743,30 @@ segment_manager_dealloc_fifos (svm_fifo_t * rx_fifo, svm_fifo_t * tx_fifo) segment_manager_segment_reader_unlock (sm); } +void +segment_manager_detach_fifo (segment_manager_t * sm, svm_fifo_t * f) +{ + fifo_segment_t *fs; + + fs = segment_manager_get_segment_w_lock (sm, f->segment_index); + fifo_segment_detach_fifo (fs, f); + segment_manager_segment_reader_unlock (sm); +} + +void +segment_manager_attach_fifo (segment_manager_t * sm, svm_fifo_t * f, + session_t * s) +{ + fifo_segment_t *fs; + + fs = segment_manager_get_segment_w_lock (sm, f->segment_index); + fifo_segment_attach_fifo (fs, f, s->thread_index); + segment_manager_segment_reader_unlock (sm); + + f->master_session_index = s->session_index; + f->master_thread_index = s->thread_index; +} + u32 segment_manager_evt_q_expected_size (u32 q_len) {