21ab4e
From 4fca129115215816589ce03d23375b23a163d7f6 Mon Sep 17 00:00:00 2001
21ab4e
From: moagrawa <moagrawa@redhat.com>
21ab4e
Date: Fri, 9 Jun 2017 13:53:28 +0530
21ab4e
Subject: [PATCH 492/509] glusterfsd: Sometime brick process is crashed after
21ab4e
 enable brick mux
21ab4e
21ab4e
Problem: glusterfsd is getting Segfault while running bug-1432542-mpx-restart-crash.t
21ab4e
         in a loop in while brick mux is enabled.
21ab4e
21ab4e
Solution: Change the index_worker code as well as notify code in index.c
21ab4e
          to cleanup index_worker thread appropriately.
21ab4e
21ab4e
> BUG: 1459402
21ab4e
> Change-Id: Id036664dc34309dd3f6e54746fc2724182cb074f
21ab4e
> Signed-off-by: Mohit Agrawal <moagrawa@redhat.com>
21ab4e
> Reviewed-on: https://review.gluster.org/17471
21ab4e
> Smoke: Gluster Build System <jenkins@build.gluster.org>
21ab4e
> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
21ab4e
> CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
21ab4e
> Reviewed-by: Jeff Darcy <jeff@pl.atyp.us>
21ab4e
> (cherry picked from commit 0a07cffbf363e35e9617e5d4ef605f26ede06f05)
21ab4e
21ab4e
BUG: 1459400
21ab4e
Change-Id: I85171a2d4aa6414d86195f93486fc63b2c2a2864
21ab4e
Signed-off-by: moagrawa <moagrawa@redhat.com>
21ab4e
Reviewed-on: https://code.engineering.redhat.com/gerrit/108648
21ab4e
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
21ab4e
---
21ab4e
 xlators/features/index/src/index.c | 24 ++++++++++++++++++------
21ab4e
 xlators/features/index/src/index.h |  1 +
21ab4e
 2 files changed, 19 insertions(+), 6 deletions(-)
21ab4e
21ab4e
diff --git a/xlators/features/index/src/index.c b/xlators/features/index/src/index.c
21ab4e
index ef5a60c..29437d0 100644
21ab4e
--- a/xlators/features/index/src/index.c
21ab4e
+++ b/xlators/features/index/src/index.c
21ab4e
@@ -199,6 +199,8 @@ index_worker (void *data)
21ab4e
         xlator_t         *this = NULL;
21ab4e
         call_stub_t      *stub = NULL;
21ab4e
         int               ret = 0;
21ab4e
+        gf_boolean_t      bye = _gf_false;
21ab4e
+
21ab4e
 
21ab4e
         THIS = data;
21ab4e
         this = data;
21ab4e
@@ -208,16 +210,27 @@ index_worker (void *data)
21ab4e
                 pthread_mutex_lock (&priv->mutex);
21ab4e
                 {
21ab4e
                         while (list_empty (&priv->callstubs)) {
21ab4e
+                                if (priv->down) {
21ab4e
+                                        bye = _gf_true;/*Avoid wait*/
21ab4e
+                                        break;
21ab4e
+                                }
21ab4e
                                 ret = pthread_cond_wait (&priv->cond,
21ab4e
                                                          &priv->mutex);
21ab4e
+                                if (priv->down) {
21ab4e
+                                        bye = _gf_true;
21ab4e
+                                        break;
21ab4e
+                                }
21ab4e
                         }
21ab4e
-
21ab4e
-                        stub = __index_dequeue (&priv->callstubs);
21ab4e
+                        if (!bye)
21ab4e
+                                stub = __index_dequeue (&priv->callstubs);
21ab4e
                 }
21ab4e
                 pthread_mutex_unlock (&priv->mutex);
21ab4e
 
21ab4e
                 if (stub) /* guard against spurious wakeups */
21ab4e
                         call_resume (stub);
21ab4e
+                stub = NULL;
21ab4e
+                if (bye)
21ab4e
+                        break;
21ab4e
         }
21ab4e
 
21ab4e
         return NULL;
21ab4e
@@ -2378,6 +2391,7 @@ init (xlator_t *this)
21ab4e
         /*init indices files counts*/
21ab4e
         count = index_fetch_link_count (this, XATTROP);
21ab4e
         index_set_link_count (priv, count, XATTROP);
21ab4e
+        priv->down = _gf_false;
21ab4e
 
21ab4e
         ret = gf_thread_create (&priv->thread, &w_attr, index_worker, this);
21ab4e
         if (ret) {
21ab4e
@@ -2500,10 +2514,8 @@ notify (xlator_t *this, int event, void *data, ...)
21ab4e
 
21ab4e
         switch (event) {
21ab4e
         case GF_EVENT_CLEANUP:
21ab4e
-                if (priv->thread) {
21ab4e
-                        (void) gf_thread_cleanup_xint (priv->thread);
21ab4e
-                        priv->thread = 0;
21ab4e
-                }
21ab4e
+                priv->down = _gf_true;
21ab4e
+                pthread_cond_broadcast (&priv->cond);
21ab4e
                 break;
21ab4e
         }
21ab4e
 
21ab4e
diff --git a/xlators/features/index/src/index.h b/xlators/features/index/src/index.h
21ab4e
index f622cec..ae9091d 100644
21ab4e
--- a/xlators/features/index/src/index.h
21ab4e
+++ b/xlators/features/index/src/index.h
21ab4e
@@ -61,6 +61,7 @@ typedef struct index_priv {
21ab4e
         dict_t  *complete_watchlist;
21ab4e
         int64_t  pending_count;
21ab4e
         pthread_t thread;
21ab4e
+        gf_boolean_t down;
21ab4e
 } index_priv_t;
21ab4e
 
21ab4e
 typedef struct index_local {
21ab4e
-- 
21ab4e
1.8.3.1
21ab4e