From a42db19a5dd796f5387b0765f5fc05cef462df22 Mon Sep 17 00:00:00 2001 From: Poornima G Date: Thu, 19 Feb 2015 04:09:26 +0530 Subject: libglusterfs: Change iobuf_pool_destroy to destroy all the arenas. Change-Id: If5e9d4ce98f845d3b52565ac62970959e663497f BUG: 1093594 Signed-off-by: Poornima G Reviewed-on: http://review.gluster.org/9699 Reviewed-by: Raghavendra Talur Tested-by: Gluster Build System Reviewed-by: Rajesh Joseph Reviewed-by: Shyamsundar Ranganathan --- libglusterfs/src/iobuf.c | 45 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) (limited to 'libglusterfs') diff --git a/libglusterfs/src/iobuf.c b/libglusterfs/src/iobuf.c index f8f1860889b..c414d728037 100644 --- a/libglusterfs/src/iobuf.c +++ b/libglusterfs/src/iobuf.c @@ -127,6 +127,7 @@ __iobuf_arena_destroy_iobufs (struct iobuf_arena *iobuf_arena) for (i = 0; i < iobuf_cnt; i++) { GF_ASSERT (iobuf->ref == 0); + LOCK_DESTROY (&iobuf->lock); list_del_init (&iobuf->list); iobuf++; } @@ -299,6 +300,7 @@ out: } +/* This function destroys all the iobufs and the iobuf_pool */ void iobuf_pool_destroy (struct iobuf_pool *iobuf_pool) { @@ -308,16 +310,45 @@ iobuf_pool_destroy (struct iobuf_pool *iobuf_pool) GF_VALIDATE_OR_GOTO ("iobuf", iobuf_pool, out); - for (i = 0; i < IOBUF_ARENA_MAX_INDEX; i++) { - list_for_each_entry_safe (iobuf_arena, tmp, - &iobuf_pool->arenas[i], list) { - list_del_init (&iobuf_arena->list); - iobuf_pool->arena_cnt--; + pthread_mutex_lock (&iobuf_pool->mutex); + { + for (i = 0; i < IOBUF_ARENA_MAX_INDEX; i++) { + list_for_each_entry_safe (iobuf_arena, tmp, + &iobuf_pool->arenas[i], list) { + list_del_init (&iobuf_arena->list); + iobuf_pool->arena_cnt--; - __iobuf_arena_destroy (iobuf_pool, iobuf_arena); + __iobuf_arena_destroy (iobuf_pool, iobuf_arena); + } + list_for_each_entry_safe (iobuf_arena, tmp, + &iobuf_pool->purge[i], list) { + list_del_init (&iobuf_arena->list); + iobuf_pool->arena_cnt--; + __iobuf_arena_destroy (iobuf_pool, iobuf_arena); + } + /* If there are no iobuf leaks, there should be no + * arenas in the filled list. If at all there are any + * arenas in the filled list, the below function will + * assert. + */ + list_for_each_entry_safe (iobuf_arena, tmp, + &iobuf_pool->filled[i], list) { + list_del_init (&iobuf_arena->list); + iobuf_pool->arena_cnt--; + __iobuf_arena_destroy (iobuf_pool, iobuf_arena); + } + /* If there are no iobuf leaks, there shoould be + * no standard alloced arenas, iobuf_put will free such + * arenas. + * TODO: Free the stdalloc arenas forcefully if present? + */ } - } + pthread_mutex_unlock (&iobuf_pool->mutex); + + pthread_mutex_destroy (&iobuf_pool->mutex); + + GF_FREE (iobuf_pool); out: return; -- cgit