From bbf923fb52e8a9062ef4d740288cf5547c4dbde4 Mon Sep 17 00:00:00 2001 From: Florin Coras Date: Fri, 12 Apr 2019 13:04:16 -0700 Subject: session: drop lock on segment allocation error Change-Id: Ib346570daa3e40f4f53100a05e9355ce60d533a4 Signed-off-by: Florin Coras --- src/vnet/session/segment_manager.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/vnet/session/segment_manager.c b/src/vnet/session/segment_manager.c index 25b641de167..c8d4be5c113 100644 --- a/src/vnet/session/segment_manager.c +++ b/src/vnet/session/segment_manager.c @@ -195,7 +195,7 @@ int segment_manager_add_segment (segment_manager_t * sm, u32 segment_size) { segment_manager_main_t *smm = &segment_manager_main; - u32 rnd_margin = 128 << 10, seg_index, page_size; + u32 rnd_margin = 128 << 10, seg_index = ~0, page_size; segment_manager_properties_t *props; uword baseva = (uword) ~ 0ULL, alloc_size; svm_fifo_segment_private_t *seg; @@ -215,15 +215,9 @@ segment_manager_add_segment (segment_manager_t * sm, u32 segment_size) * Allocate fifo segment and lock if needed */ if (vlib_num_workers ()) - { - clib_rwlock_writer_lock (&sm->segments_rwlock); - pool_get (sm->segments, seg); - } - else - { - pool_get (sm->segments, seg); - } - clib_memset (seg, 0, sizeof (*seg)); + clib_rwlock_writer_lock (&sm->segments_rwlock); + + pool_get_zero (sm->segments, seg); /* * Initialize ssvm segment and svm fifo private header @@ -239,7 +233,8 @@ segment_manager_add_segment (segment_manager_t * sm, u32 segment_size) if (!baseva) { clib_warning ("out of space for segments"); - return -1; + pool_put (sm->segments, seg); + goto done; } } else @@ -257,7 +252,7 @@ segment_manager_add_segment (segment_manager_t * sm, u32 segment_size) if (props->segment_type != SSVM_SEGMENT_PRIVATE) clib_valloc_free (&smm->va_allocator, baseva); pool_put (sm->segments, seg); - return (rv); + goto done; } svm_fifo_segment_init (seg); @@ -267,6 +262,8 @@ segment_manager_add_segment (segment_manager_t * sm, u32 segment_size) */ seg_index = seg - sm->segments; +done: + if (vlib_num_workers ()) clib_rwlock_writer_unlock (&sm->segments_rwlock); -- cgit 1.2.3-korg