7f4c2a
From 4319e82ca0823c6e62f37fe27cff4e8e26d29522 Mon Sep 17 00:00:00 2001
7f4c2a
From: anand <anekkunt@redhat.com>
7f4c2a
Date: Fri, 10 Apr 2015 16:41:25 +0530
7f4c2a
Subject: [PATCH 36/57] glusterd: Stop tcp/ip listeners during  glusterd exit
7f4c2a
7f4c2a
Problem : Because of race between exit thread and rpc thread
7f4c2a
causing the glusterd crash while glusterd exiting/stoping.
7f4c2a
7f4c2a
Fix : Stop tcp/ip socket listeners in cleanup_and_exit to
7f4c2a
avoid new rpc events.
7f4c2a
7f4c2a
Backport of :
7f4c2a
>Change-Id: Ie9280c8c9d7c350a176529375d861432f3de94ac
7f4c2a
>BUG: 1209461
7f4c2a
>Signed-off-by: anand <anekkunt@redhat.com>
7f4c2a
>Reviewed-on: http://review.gluster.org/10197
7f4c2a
>Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
7f4c2a
>Tested-by: NetBSD Build System <jenkins@build.gluster.org>
7f4c2a
>Reviewed-by: Kaushal M <kaushal@redhat.com>
7f4c2a
7f4c2a
Change-Id: Ia209927c61c1eeb0542a2e59ea60e48f74e3ca80
7f4c2a
BUG: 1230195
7f4c2a
Signed-off-by: anand <anekkunt@redhat.com>
7f4c2a
Reviewed-on: https://code.engineering.redhat.com/gerrit/50436
7f4c2a
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
7f4c2a
Tested-by: Atin Mukherjee <amukherj@redhat.com>
7f4c2a
---
7f4c2a
 xlators/mgmt/glusterd/src/glusterd.c |   48 +++++++++++++++++++++++++++++++--
7f4c2a
 1 files changed, 45 insertions(+), 3 deletions(-)
7f4c2a
7f4c2a
diff --git a/xlators/mgmt/glusterd/src/glusterd.c b/xlators/mgmt/glusterd/src/glusterd.c
7f4c2a
index 54a5fbd..39160c0 100644
7f4c2a
--- a/xlators/mgmt/glusterd/src/glusterd.c
7f4c2a
+++ b/xlators/mgmt/glusterd/src/glusterd.c
7f4c2a
@@ -1113,8 +1113,38 @@ glusterd_stop_uds_listener (xlator_t *this)
7f4c2a
         }
7f4c2a
         unlink (sockfile);
7f4c2a
 
7f4c2a
-        GF_FREE (conf->uds_rpc);
7f4c2a
-        conf->uds_rpc = NULL;
7f4c2a
+        return;
7f4c2a
+}
7f4c2a
+
7f4c2a
+
7f4c2a
+void
7f4c2a
+glusterd_stop_listener (xlator_t *this)
7f4c2a
+{
7f4c2a
+        glusterd_conf_t         *conf = NULL;
7f4c2a
+        rpcsvc_listener_t       *listener = NULL;
7f4c2a
+        rpcsvc_listener_t       *next = NULL;
7f4c2a
+        int                      i = 0;
7f4c2a
+
7f4c2a
+        GF_VALIDATE_OR_GOTO ("glusterd", this, out);
7f4c2a
+        conf = this->private;
7f4c2a
+        GF_VALIDATE_OR_GOTO (this->name, conf, out);
7f4c2a
+
7f4c2a
+        gf_log (this->name, GF_LOG_DEBUG,
7f4c2a
+                "%s function called ", __func__);
7f4c2a
+
7f4c2a
+        for (i = 0; i < gd_inet_programs_count; i++) {
7f4c2a
+              rpcsvc_program_unregister (conf->rpc, gd_inet_programs[i]);
7f4c2a
+        }
7f4c2a
+
7f4c2a
+        list_for_each_entry_safe (listener, next, &conf->rpc->listeners, list) {
7f4c2a
+                rpcsvc_listener_destroy (listener);
7f4c2a
+        }
7f4c2a
+
7f4c2a
+        (void) rpcsvc_unregister_notify (conf->rpc,
7f4c2a
+                                         glusterd_rpcsvc_notify,
7f4c2a
+                                         this);
7f4c2a
+
7f4c2a
+out:
7f4c2a
 
7f4c2a
         return;
7f4c2a
 }
7f4c2a
@@ -1743,8 +1773,19 @@ fini (xlator_t *this)
7f4c2a
 
7f4c2a
         conf = this->private;
7f4c2a
 
7f4c2a
-        glusterd_stop_uds_listener (this);
7f4c2a
+        glusterd_stop_uds_listener (this); /*stop unix socket rpc*/
7f4c2a
+        glusterd_stop_listener (this);     /*stop tcp/ip socket rpc*/
7f4c2a
 
7f4c2a
+#if 0
7f4c2a
+       /* Running threads might be using these resourses, we have to cancel/stop
7f4c2a
+        * running threads before deallocating the memeory, but we don't have
7f4c2a
+        * control over the running threads to do pthread_cancel().
7f4c2a
+        * So memeory freeing handover to kernel.
7f4c2a
+        */
7f4c2a
+        /*TODO: cancel/stop the running threads*/
7f4c2a
+
7f4c2a
+        GF_FREE (conf->uds_rpc);
7f4c2a
+        GF_FREE (conf->rpc);
7f4c2a
         FREE (conf->pmap);
7f4c2a
         if (conf->handle)
7f4c2a
                 gf_store_handle_destroy (conf->handle);
7f4c2a
@@ -1754,6 +1795,7 @@ fini (xlator_t *this)
7f4c2a
         GF_FREE (conf);
7f4c2a
 
7f4c2a
         this->private = NULL;
7f4c2a
+#endif
7f4c2a
 out:
7f4c2a
         return;
7f4c2a
 }
7f4c2a
-- 
7f4c2a
1.7.1
7f4c2a