Blob Blame History Raw
From 491a5a60132eb5bc143b75f0e94201a3ac15bd0e Mon Sep 17 00:00:00 2001
From: anand <anekkunt@redhat.com>
Date: Fri, 22 May 2015 18:18:11 +0530
Subject: [PATCH 37/57] libglusterfs: Enabling the fini()  in cleanup_and_exit()

Problem 1 : glusterd was crashing due to race between clean up thread and rpc event thread.

Scenario:
As we can observed, X thread is in the process of exiting the process. It has already
run the exit handlers, which cleanup things that require cleaning up. This includes
liburcu resources. By the time Y thread  called rcu_bp_register(), the liburcu resources
have been cleaned up. rcu_bp_register() tries to access these non-existent resources,
which leads to the segmentation fault.

Note1:
Crash happen when the process is almost at the point of stopping(exiting), it doesn't have any
serious impact to functionality apart from creating the core dump file and the log message.

Fix .Do proper clean up before calling exit().

Note2: Other xlator have clean up issues,so only glusterd clean up function invoked.

Note3: This patch also solve the selinux issue.

Problem 2 : glusterd runs as rpm_script_t when it's executed from the rpm scriptlet,files created
in this context are set as rpm_script_t, so glusterd unable to access these files when it runs
in glusterd_t context.

Fix: Fini clean up the files while glusterd exiting, so files are recreated by glusterd while
starting with proper SElinux context label.

Backport of :
>Change-Id: Idcfd087f51c18a729bdf44a146f9d294e2fca5e2
>BUG: 1209461
>Signed-off-by: anand <anekkunt@redhat.com>
>Reviewed-on: http://review.gluster.org/10894
>Tested-by: Gluster Build System <jenkins@build.gluster.com>
>Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
>Tested-by: NetBSD Build System <jenkins@build.gluster.org>
>Reviewed-by: Raghavendra Bhat <raghavendra@redhat.com>
>Reviewed-by: Vijay Bellur <vbellur@redhat.com>

Change-Id: I4b582f794a915c0bf380eaae3d23b8f075ce43fa
BUG: 1230195
Signed-off-by: anand <anekkunt@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/50437
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
Tested-by: Atin Mukherjee <amukherj@redhat.com>
---
 glusterfsd/src/glusterfsd.c |   27 +++++++++++++++++----------
 1 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/glusterfsd/src/glusterfsd.c b/glusterfsd/src/glusterfsd.c
index 61ae4e4..ffd1eb4 100644
--- a/glusterfsd/src/glusterfsd.c
+++ b/glusterfsd/src/glusterfsd.c
@@ -1246,7 +1246,6 @@ cleanup_and_exit (int signum)
 
         glusterfs_pidfile_cleanup (ctx);
 
-        exit (0);
 #if 0
         /* TODO: Properly do cleanup_and_exit(), with synchronization */
         if (ctx->mgmt) {
@@ -1254,19 +1253,27 @@ cleanup_and_exit (int signum)
                 rpc_clnt_connection_cleanup (&ctx->mgmt->conn);
                 rpc_clnt_unref (ctx->mgmt);
         }
+#endif
 
         /* call fini() of each xlator */
-        trav = NULL;
-        if (ctx->active)
-                trav = ctx->active->top;
-        while (trav) {
-                if (trav->fini) {
-                        THIS = trav;
-                        trav->fini (trav);
+
+        /*call fini for glusterd xlator */
+        /* TODO : Invoke fini for rest of the xlators */
+        if (ctx->process_mode == GF_GLUSTERD_PROCESS) {
+
+                trav = NULL;
+                if (ctx->active)
+                        trav = ctx->active->top;
+                while (trav) {
+                        if (trav->fini) {
+                                THIS = trav;
+                                trav->fini (trav);
+                        }
+                        trav = trav->next;
                 }
-                trav = trav->next;
+
         }
-#endif
+        exit(0);
 }
 
 
-- 
1.7.1