e7a346
From 11f9ffcd733c95e8a728c150ff2ffc3dbeaddac1 Mon Sep 17 00:00:00 2001
e7a346
From: Mohit Agrawal <moagrawa@redhat.com>
e7a346
Date: Fri, 11 Jan 2019 11:57:20 +0530
e7a346
Subject: [PATCH 502/506] posix: posix_health_check_thread_proc crash due to
e7a346
 priv is NULL
e7a346
e7a346
Problem: posix_fini sends a cancellation request to health_check
e7a346
         thread and cleanup priv without ensuring health_check thread
e7a346
         is running
e7a346
e7a346
Solution: Make health_check && disk_space thread joinable and call
e7a346
          gf_thread_cleanup_xint to wait unless thread is not finished
e7a346
e7a346
> Change-Id: I4d37b08138766881dab0922a47ed68a2c3411f13
e7a346
> fixes: bz#1636570
e7a346
> (Reviewed on upstream link https://review.gluster.org/#/c/glusterfs/+/21717/)
e7a346
> (Cherry pick from commit e82bcc33ed2d5cd54d3f918397f31818089299ad)
e7a346
e7a346
Change-Id: I9edadd5bc445549b5f45bab98e4794d62a185f1c
e7a346
BUG: 1662828
e7a346
Signed-off-by: Mohit Agrawal <moagrawa@redhat.com>
e7a346
Reviewed-on: https://code.engineering.redhat.com/gerrit/160404
e7a346
Tested-by: RHGS Build Bot <nigelb@redhat.com>
e7a346
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
e7a346
---
e7a346
 xlators/storage/posix/src/posix-helpers.c |  8 +++-----
e7a346
 xlators/storage/posix/src/posix.c         | 15 +++++++++++----
e7a346
 2 files changed, 14 insertions(+), 9 deletions(-)
e7a346
e7a346
diff --git a/xlators/storage/posix/src/posix-helpers.c b/xlators/storage/posix/src/posix-helpers.c
e7a346
index cddf02e63..ed5d3e55e 100644
e7a346
--- a/xlators/storage/posix/src/posix-helpers.c
e7a346
+++ b/xlators/storage/posix/src/posix-helpers.c
e7a346
@@ -1854,8 +1854,6 @@ posix_spawn_health_check_thread (xlator_t *xl)
e7a346
                         goto unlock;
e7a346
                 }
e7a346
 
e7a346
-                /* run the thread detached, resources will be freed on exit */
e7a346
-                pthread_detach (priv->health_check);
e7a346
                 priv->health_check_active = _gf_true;
e7a346
         }
e7a346
 unlock:
e7a346
@@ -1958,9 +1956,9 @@ posix_spawn_disk_space_check_thread (xlator_t *xl)
e7a346
                         priv->disk_space_check_active = _gf_false;
e7a346
                 }
e7a346
 
e7a346
-                ret = gf_thread_create_detached (&priv->disk_space_check,
e7a346
-                                                 posix_disk_space_check_thread_proc,
e7a346
-                                                 xl, "posix_reserve");
e7a346
+                ret = gf_thread_create (&priv->disk_space_check, NULL,
e7a346
+                                        posix_disk_space_check_thread_proc,
e7a346
+                                        xl, "posix_reserve");
e7a346
                 if (ret < 0) {
e7a346
                         priv->disk_space_check_active = _gf_false;
e7a346
                         gf_msg (xl->name, GF_LOG_ERROR, errno,
e7a346
diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c
e7a346
index 13b4aa6b6..591119ea9 100644
e7a346
--- a/xlators/storage/posix/src/posix.c
e7a346
+++ b/xlators/storage/posix/src/posix.c
e7a346
@@ -7999,18 +7999,25 @@ void
e7a346
 fini (xlator_t *this)
e7a346
 {
e7a346
         struct posix_private *priv = this->private;
e7a346
+        gf_boolean_t health_check = _gf_false;
e7a346
+
e7a346
         if (!priv)
e7a346
                 return;
e7a346
         LOCK (&priv->lock);
e7a346
-        if (priv->health_check_active) {
e7a346
+        {
e7a346
+                health_check = priv->health_check_active;
e7a346
                 priv->health_check_active = _gf_false;
e7a346
-                pthread_cancel (priv->health_check);
e7a346
-                priv->health_check = 0;
e7a346
         }
e7a346
         UNLOCK (&priv->lock);
e7a346
+
e7a346
+        if (health_check) {
e7a346
+                (void)gf_thread_cleanup_xint(priv->health_check);
e7a346
+                priv->health_check = 0;
e7a346
+        }
e7a346
+
e7a346
         if (priv->disk_space_check) {
e7a346
                 priv->disk_space_check_active = _gf_false;
e7a346
-                pthread_cancel (priv->disk_space_check);
e7a346
+                (void)gf_thread_cleanup_xint(priv->disk_space_check);
e7a346
                 priv->disk_space_check = 0;
e7a346
         }
e7a346
         if (priv->janitor) {
e7a346
-- 
e7a346
2.20.1
e7a346