Blob Blame History Raw
From 31d0ef0a4fc9d8028f45c9306df0430a0767a33f Mon Sep 17 00:00:00 2001
From: Rajesh Joseph <rjoseph@redhat.com>
Date: Mon, 14 Nov 2016 15:40:32 +0530
Subject: [PATCH 189/206] libglusterfs:Now mempool is added to ctx pool list
 under a lock

mempool is added to ctx pool list without any lock. This can cause undefined
behaviour in case of multithreaded environment.

Fix: modify the list only under ctx->lock

> Reviewed-on: http://review.gluster.org/15842
> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
> Smoke: Gluster Build System <jenkins@build.gluster.org>
> CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
> Reviewed-by: Raghavendra Talur <rtalur@redhat.com>
> Reviewed-by: Shyamsundar Ranganathan <srangana@redhat.com>
> Reviewed-by: Poornima G <pgurusid@redhat.com>
> Reviewed-by: Niels de Vos <ndevos@redhat.com>

Change-Id: I7bdbb3db48a899bb0e41427e149b13c0facaedba
Signed-off-by: Rajesh Joseph <rjoseph@redhat.com>
BUG: 1387558
Reviewed-on: https://code.engineering.redhat.com/gerrit/90965
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
---
 api/src/glfs.c              | 2 --
 libglusterfs/src/mem-pool.c | 6 +++++-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/api/src/glfs.c b/api/src/glfs.c
index ef713f9..307e22c 100644
--- a/api/src/glfs.c
+++ b/api/src/glfs.c
@@ -149,8 +149,6 @@ glusterfs_ctx_defaults_init (glusterfs_ctx_t *ctx)
 	LOCK_INIT (&pool->lock);
 	ctx->pool = pool;
 
-	LOCK_INIT (&ctx->lock);
-
 	ret = 0;
 err:
 	if (ret && pool) {
diff --git a/libglusterfs/src/mem-pool.c b/libglusterfs/src/mem-pool.c
index 78fecec..88fbdf5 100644
--- a/libglusterfs/src/mem-pool.c
+++ b/libglusterfs/src/mem-pool.c
@@ -422,7 +422,11 @@ mem_pool_new_fn (unsigned long sizeof_type,
         if (!ctx)
                 goto out;
 
-        list_add (&mem_pool->global_list, &ctx->mempool_list);
+        LOCK (&ctx->lock);
+        {
+                list_add (&mem_pool->global_list, &ctx->mempool_list);
+        }
+        UNLOCK (&ctx->lock);
 
 out:
         return mem_pool;
-- 
2.9.3