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