From 67ba8269f798aa5438be63da5c2cb73fe31edc1d Mon Sep 17 00:00:00 2001
From: Jeff Darcy <jdarcy@fb.com>
Date: Fri, 7 Jul 2017 07:49:45 -0700
Subject: [PATCH 591/593] gfapi+libglusterfs: fix mem_pools_fini without
mem_pools_init case
The change consists of two parts: make sure it doesn't happen (in
glfs.c), and make it harmless if it does (in mem-pool.c).
Upstream reference :
>Change-Id: Icb7dda7a45dd3d1ade2ee3991bb6a22c8ec88424
>BUG: 1468863
>Signed-off-by: Jeff Darcy <jdarcy@fb.com>
>Reviewed-on: https://review.gluster.org/17728
>Tested-by: Jeff Darcy <jeff@pl.atyp.us>
>CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
>Smoke: Gluster Build System <jenkins@build.gluster.org>
>Reviewed-by: Jeff Darcy <jeff@pl.atyp.us>
Change-Id: Icb7dda7a45dd3d1ade2ee3991bb6a22c8ec88424
BUG: 1477668
Signed-off-by: Jiffin Tony Thottan <jthottan@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/114351
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
---
api/src/glfs.c | 12 ++++++------
libglusterfs/src/mem-pool.c | 18 ++++++++++++++++--
2 files changed, 22 insertions(+), 8 deletions(-)
diff --git a/api/src/glfs.c b/api/src/glfs.c
index fea30e7..97ddfcb 100644
--- a/api/src/glfs.c
+++ b/api/src/glfs.c
@@ -702,6 +702,12 @@ pub_glfs_new (const char *volname)
return NULL;
}
+ /*
+ * Do this as soon as possible in case something else depends on
+ * pool allocations.
+ */
+ mem_pools_init ();
+
fs = glfs_new_fs (volname);
if (!fs)
return NULL;
@@ -983,12 +989,6 @@ pub_glfs_init (struct glfs *fs)
return ret;
}
- /*
- * Do this as soon as possible in case something else depends on
- * pool allocations.
- */
- mem_pools_init ();
-
__GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
ret = glfs_init_common (fs);
diff --git a/libglusterfs/src/mem-pool.c b/libglusterfs/src/mem-pool.c
index 3295bdc..2d89084 100644
--- a/libglusterfs/src/mem-pool.c
+++ b/libglusterfs/src/mem-pool.c
@@ -556,10 +556,24 @@ void
mem_pools_fini (void)
{
pthread_mutex_lock (&init_mutex);
- GF_ASSERT (init_count > 0);
- if ((--init_count) == 0) {
+ switch (init_count) {
+ case 0:
+ /*
+ * If init_count is already zero (as e.g. if somebody called
+ * this before mem_pools_init) then the sweeper was probably
+ * never even started so we don't need to stop it. Even if
+ * there's some crazy circumstance where there is a sweeper but
+ * init_count is still zero, that just means we'll leave it
+ * running. Not perfect, but far better than any known
+ * alternative.
+ */
+ break;
+ case 1:
(void) pthread_cancel (sweeper_tid);
(void) pthread_join (sweeper_tid, NULL);
+ /* Fall through. */
+ default:
+ --init_count;
}
pthread_mutex_unlock (&init_mutex);
}
--
1.8.3.1