From ea8c9af0b4a91ef927bbeee9afdfa7d1cea6369f Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Tue, 29 Aug 2017 00:16:22 +0200 Subject: mem-pool: track glusterfs_ctx_t in struct mem_pool In order to generate statedumps per glusterfs_ctx_t, it is needed to place all the memory pools in a structure that the context can reach. The 'struct mem_pool' has been extended with a 'list_head owner' that is linked with the glusterfs_ctx_t->mempool_list. All callers of mem_pool_new() have been updated to pass the current glusterfs_ctx_t along. This context is needed to add the new memory pool to the list and for grabbing the ctx->lock while updating the glusterfs_ctx_t->mempool_list. Updates: #307 Change-Id: Ia9384424d8d1630ef3efc9d5d523bf739c356c6e Signed-off-by: Niels de Vos Reviewed-on: https://review.gluster.org/18075 Smoke: Gluster Build System CentOS-regression: Gluster Build System Reviewed-by: Jeff Darcy --- libglusterfs/src/mem-pool.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'libglusterfs/src/mem-pool.c') diff --git a/libglusterfs/src/mem-pool.c b/libglusterfs/src/mem-pool.c index 8bd9779ce81..66b45c0d669 100644 --- a/libglusterfs/src/mem-pool.c +++ b/libglusterfs/src/mem-pool.c @@ -663,7 +663,7 @@ void mem_pools_fini (void) {} #endif struct mem_pool * -mem_pool_new_fn (unsigned long sizeof_type, +mem_pool_new_fn (glusterfs_ctx_t *ctx, unsigned long sizeof_type, unsigned long count, char *name) { unsigned int i; @@ -693,10 +693,18 @@ mem_pool_new_fn (unsigned long sizeof_type, if (!new) return NULL; + new->ctx = ctx; new->sizeof_type = sizeof_type; new->count = count; new->name = name; new->pool = pool; + INIT_LIST_HEAD (&new->owner); + + LOCK (&ctx->lock); + { + list_add (&new->owner, &ctx->mempool_list); + } + UNLOCK (&ctx->lock); return new; } @@ -867,6 +875,14 @@ mem_put (void *ptr) void mem_pool_destroy (struct mem_pool *pool) { + /* remove this pool from the owner (glusterfs_ctx_t) */ + LOCK (&pool->ctx->lock); + { + list_del (&pool->owner); + } + UNLOCK (&pool->ctx->lock); + + /* free this pool, but keep the mem_pool_shared */ GF_FREE (pool); /* -- cgit