Blob Blame History Raw
From 4319e82ca0823c6e62f37fe27cff4e8e26d29522 Mon Sep 17 00:00:00 2001
From: anand <anekkunt@redhat.com>
Date: Fri, 10 Apr 2015 16:41:25 +0530
Subject: [PATCH 36/57] glusterd: Stop tcp/ip listeners during  glusterd exit

Problem : Because of race between exit thread and rpc thread
causing the glusterd crash while glusterd exiting/stoping.

Fix : Stop tcp/ip socket listeners in cleanup_and_exit to
avoid new rpc events.

Backport of :
>Change-Id: Ie9280c8c9d7c350a176529375d861432f3de94ac
>BUG: 1209461
>Signed-off-by: anand <anekkunt@redhat.com>
>Reviewed-on: http://review.gluster.org/10197
>Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
>Tested-by: NetBSD Build System <jenkins@build.gluster.org>
>Reviewed-by: Kaushal M <kaushal@redhat.com>

Change-Id: Ia209927c61c1eeb0542a2e59ea60e48f74e3ca80
BUG: 1230195
Signed-off-by: anand <anekkunt@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/50436
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
Tested-by: Atin Mukherjee <amukherj@redhat.com>
---
 xlators/mgmt/glusterd/src/glusterd.c |   48 +++++++++++++++++++++++++++++++--
 1 files changed, 45 insertions(+), 3 deletions(-)

diff --git a/xlators/mgmt/glusterd/src/glusterd.c b/xlators/mgmt/glusterd/src/glusterd.c
index 54a5fbd..39160c0 100644
--- a/xlators/mgmt/glusterd/src/glusterd.c
+++ b/xlators/mgmt/glusterd/src/glusterd.c
@@ -1113,8 +1113,38 @@ glusterd_stop_uds_listener (xlator_t *this)
         }
         unlink (sockfile);
 
-        GF_FREE (conf->uds_rpc);
-        conf->uds_rpc = NULL;
+        return;
+}
+
+
+void
+glusterd_stop_listener (xlator_t *this)
+{
+        glusterd_conf_t         *conf = NULL;
+        rpcsvc_listener_t       *listener = NULL;
+        rpcsvc_listener_t       *next = NULL;
+        int                      i = 0;
+
+        GF_VALIDATE_OR_GOTO ("glusterd", this, out);
+        conf = this->private;
+        GF_VALIDATE_OR_GOTO (this->name, conf, out);
+
+        gf_log (this->name, GF_LOG_DEBUG,
+                "%s function called ", __func__);
+
+        for (i = 0; i < gd_inet_programs_count; i++) {
+              rpcsvc_program_unregister (conf->rpc, gd_inet_programs[i]);
+        }
+
+        list_for_each_entry_safe (listener, next, &conf->rpc->listeners, list) {
+                rpcsvc_listener_destroy (listener);
+        }
+
+        (void) rpcsvc_unregister_notify (conf->rpc,
+                                         glusterd_rpcsvc_notify,
+                                         this);
+
+out:
 
         return;
 }
@@ -1743,8 +1773,19 @@ fini (xlator_t *this)
 
         conf = this->private;
 
-        glusterd_stop_uds_listener (this);
+        glusterd_stop_uds_listener (this); /*stop unix socket rpc*/
+        glusterd_stop_listener (this);     /*stop tcp/ip socket rpc*/
 
+#if 0
+       /* Running threads might be using these resourses, we have to cancel/stop
+        * running threads before deallocating the memeory, but we don't have
+        * control over the running threads to do pthread_cancel().
+        * So memeory freeing handover to kernel.
+        */
+        /*TODO: cancel/stop the running threads*/
+
+        GF_FREE (conf->uds_rpc);
+        GF_FREE (conf->rpc);
         FREE (conf->pmap);
         if (conf->handle)
                 gf_store_handle_destroy (conf->handle);
@@ -1754,6 +1795,7 @@ fini (xlator_t *this)
         GF_FREE (conf);
 
         this->private = NULL;
+#endif
 out:
         return;
 }
-- 
1.7.1