17b94a
From 541e1400ecaec5fea0f56e8ca18f00c229906d8a Mon Sep 17 00:00:00 2001
17b94a
From: Mohammed Rafi KC <rkavunga@redhat.com>
17b94a
Date: Tue, 18 Jun 2019 22:15:37 +0530
17b94a
Subject: [PATCH 203/221] glusterd/shd: Change shd logfile to a unique name
17b94a
17b94a
With the shd mux changes, shd was havinga a logfile
17b94a
with volname of the first started volume.
17b94a
17b94a
This was creating a lot confusion, as other volumes data
17b94a
is also logging to a logfile which has a different vol name.
17b94a
17b94a
With this changes the logfile will be changed to a unique name
17b94a
ie "/var/log/glusterfs/glustershd.log". This was the same
17b94a
logfile name before the shd mux
17b94a
17b94a
Backport of: https://review.gluster.org/22895
17b94a
17b94a
>Change-Id: I2b94c1f0b2cf3c9493505dddf873687755a46dda
17b94a
>fixes: bz#1721601
17b94a
>Signed-off-by: Mohammed Rafi KC <rkavunga@redhat.com>
17b94a
17b94a
Change-Id: Ia659386dd19f533fbadaf5a9d5453c9ef2acac64
17b94a
BUG: 1721351
17b94a
Signed-off-by: Mohammed Rafi KC <rkavunga@redhat.com>
17b94a
Reviewed-on: https://code.engineering.redhat.com/gerrit/174542
17b94a
Tested-by: RHGS Build Bot <nigelb@redhat.com>
17b94a
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
17b94a
---
17b94a
 .../mgmt/glusterd/src/glusterd-shd-svc-helper.c    | 12 --------
17b94a
 .../mgmt/glusterd/src/glusterd-shd-svc-helper.h    |  6 ----
17b94a
 xlators/mgmt/glusterd/src/glusterd-shd-svc.c       | 14 ++++-----
17b94a
 xlators/mgmt/glusterd/src/glusterd-svc-helper.c    | 34 +++++++++++++++++-----
17b94a
 xlators/mgmt/glusterd/src/glusterd-svc-mgmt.c      |  4 +--
17b94a
 xlators/mgmt/glusterd/src/glusterd-svc-mgmt.h      |  4 +++
17b94a
 6 files changed, 40 insertions(+), 34 deletions(-)
17b94a
17b94a
diff --git a/xlators/mgmt/glusterd/src/glusterd-shd-svc-helper.c b/xlators/mgmt/glusterd/src/glusterd-shd-svc-helper.c
17b94a
index 9196758..57ceda9 100644
17b94a
--- a/xlators/mgmt/glusterd/src/glusterd-shd-svc-helper.c
17b94a
+++ b/xlators/mgmt/glusterd/src/glusterd-shd-svc-helper.c
17b94a
@@ -75,18 +75,6 @@ glusterd_svc_build_shd_volfile_path(glusterd_volinfo_t *volinfo, char *path,
17b94a
 }
17b94a
 
17b94a
 void
17b94a
-glusterd_svc_build_shd_logdir(char *logdir, char *volname, size_t len)
17b94a
-{
17b94a
-    snprintf(logdir, len, "%s/shd/%s", DEFAULT_LOG_FILE_DIRECTORY, volname);
17b94a
-}
17b94a
-
17b94a
-void
17b94a
-glusterd_svc_build_shd_logfile(char *logfile, char *logdir, size_t len)
17b94a
-{
17b94a
-    snprintf(logfile, len, "%s/shd.log", logdir);
17b94a
-}
17b94a
-
17b94a
-void
17b94a
 glusterd_shd_svcproc_cleanup(glusterd_shdsvc_t *shd)
17b94a
 {
17b94a
     glusterd_svc_proc_t *svc_proc = NULL;
17b94a
diff --git a/xlators/mgmt/glusterd/src/glusterd-shd-svc-helper.h b/xlators/mgmt/glusterd/src/glusterd-shd-svc-helper.h
17b94a
index c70702c..59466ec 100644
17b94a
--- a/xlators/mgmt/glusterd/src/glusterd-shd-svc-helper.h
17b94a
+++ b/xlators/mgmt/glusterd/src/glusterd-shd-svc-helper.h
17b94a
@@ -27,12 +27,6 @@ glusterd_svc_build_shd_volfile_path(glusterd_volinfo_t *volinfo, char *path,
17b94a
                                     int path_len);
17b94a
 
17b94a
 void
17b94a
-glusterd_svc_build_shd_logdir(char *logdir, char *volname, size_t len);
17b94a
-
17b94a
-void
17b94a
-glusterd_svc_build_shd_logfile(char *logfile, char *logdir, size_t len);
17b94a
-
17b94a
-void
17b94a
 glusterd_shd_svcproc_cleanup(glusterd_shdsvc_t *shd);
17b94a
 
17b94a
 int
17b94a
diff --git a/xlators/mgmt/glusterd/src/glusterd-shd-svc.c b/xlators/mgmt/glusterd/src/glusterd-shd-svc.c
17b94a
index dbe2560..8ad90a9 100644
17b94a
--- a/xlators/mgmt/glusterd/src/glusterd-shd-svc.c
17b94a
+++ b/xlators/mgmt/glusterd/src/glusterd-shd-svc.c
17b94a
@@ -90,8 +90,8 @@ glusterd_shdsvc_init(void *data, glusterd_conn_t *mux_conn,
17b94a
     GLUSTERD_GET_SHD_RUNDIR(rundir, volinfo, priv);
17b94a
     glusterd_svc_create_rundir(rundir);
17b94a
 
17b94a
-    glusterd_svc_build_shd_logdir(logdir, volinfo->volname, sizeof(logdir));
17b94a
-    glusterd_svc_build_shd_logfile(logfile, logdir, sizeof(logfile));
17b94a
+    glusterd_svc_build_logfile_path(shd_svc_name, DEFAULT_LOG_FILE_DIRECTORY,
17b94a
+                                    logfile, sizeof(logfile));
17b94a
 
17b94a
     /* Initialize the connection mgmt */
17b94a
     if (mux_conn && mux_svc->rpc) {
17b94a
@@ -104,7 +104,7 @@ glusterd_shdsvc_init(void *data, glusterd_conn_t *mux_conn,
17b94a
         if (ret < 0)
17b94a
             goto out;
17b94a
     } else {
17b94a
-        ret = mkdir_p(logdir, 0755, _gf_true);
17b94a
+        ret = mkdir_p(DEFAULT_LOG_FILE_DIRECTORY, 0755, _gf_true);
17b94a
         if ((ret == -1) && (EEXIST != errno)) {
17b94a
             gf_msg(this->name, GF_LOG_ERROR, errno, GD_MSG_CREATE_DIR_FAILED,
17b94a
                    "Unable to create logdir %s", logdir);
17b94a
@@ -460,6 +460,7 @@ glusterd_shdsvc_start(glusterd_svc_t *svc, int flags)
17b94a
         return -1;
17b94a
 
17b94a
     glusterd_volinfo_ref(volinfo);
17b94a
+
17b94a
     if (!svc->inited) {
17b94a
         ret = glusterd_shd_svc_mux_init(volinfo, svc);
17b94a
         if (ret)
17b94a
@@ -471,12 +472,11 @@ glusterd_shdsvc_start(glusterd_svc_t *svc, int flags)
17b94a
         /* Unref will happen from glusterd_svc_attach_cbk */
17b94a
         ret = glusterd_attach_svc(svc, volinfo, flags);
17b94a
         if (ret) {
17b94a
-            glusterd_volinfo_unref(volinfo);
17b94a
             gf_msg("glusterd", GF_LOG_ERROR, 0, GD_MSG_VOLINFO_GET_FAIL,
17b94a
-                   "Failed to attach shd svc(volume=%s) to pid=%d. Starting"
17b94a
-                   "a new process",
17b94a
+                   "Failed to attach shd svc(volume=%s) to pid=%d",
17b94a
                    volinfo->volname, glusterd_proc_get_pid(&svc->proc));
17b94a
-            ret = glusterd_recover_shd_attach_failure(volinfo, svc, flags);
17b94a
+            glusterd_shd_svcproc_cleanup(&volinfo->shd);
17b94a
+            glusterd_volinfo_unref(volinfo);
17b94a
         }
17b94a
         goto out;
17b94a
     }
17b94a
diff --git a/xlators/mgmt/glusterd/src/glusterd-svc-helper.c b/xlators/mgmt/glusterd/src/glusterd-svc-helper.c
17b94a
index a6e662f..400826f 100644
17b94a
--- a/xlators/mgmt/glusterd/src/glusterd-svc-helper.c
17b94a
+++ b/xlators/mgmt/glusterd/src/glusterd-svc-helper.c
17b94a
@@ -469,6 +469,9 @@ glusterd_shd_svc_mux_init(glusterd_volinfo_t *volinfo, glusterd_svc_t *svc)
17b94a
     glusterd_conf_t *conf = NULL;
17b94a
     glusterd_svc_t *parent_svc = NULL;
17b94a
     int pid = -1;
17b94a
+    char pidfile[PATH_MAX] = {
17b94a
+        0,
17b94a
+    };
17b94a
 
17b94a
     GF_VALIDATE_OR_GOTO("glusterd", svc, out);
17b94a
     GF_VALIDATE_OR_GOTO("glusterd", volinfo, out);
17b94a
@@ -478,8 +481,26 @@ glusterd_shd_svc_mux_init(glusterd_volinfo_t *volinfo, glusterd_svc_t *svc)
17b94a
 
17b94a
     pthread_mutex_lock(&conf->attach_lock);
17b94a
     {
17b94a
+        if (svc->inited && !glusterd_proc_is_running(&(svc->proc))) {
17b94a
+            /* This is the case when shd process was abnormally killed */
17b94a
+            pthread_mutex_unlock(&conf->attach_lock);
17b94a
+            glusterd_shd_svcproc_cleanup(&volinfo->shd);
17b94a
+            pthread_mutex_lock(&conf->attach_lock);
17b94a
+        }
17b94a
+
17b94a
         if (!svc->inited) {
17b94a
-            if (gf_is_service_running(svc->proc.pidfile, &pid)) {
17b94a
+            glusterd_svc_build_shd_pidfile(volinfo, pidfile, sizeof(pidfile));
17b94a
+            ret = snprintf(svc->proc.name, sizeof(svc->proc.name), "%s",
17b94a
+                           "glustershd");
17b94a
+            if (ret < 0)
17b94a
+                goto unlock;
17b94a
+
17b94a
+            ret = snprintf(svc->proc.pidfile, sizeof(svc->proc.pidfile), "%s",
17b94a
+                           pidfile);
17b94a
+            if (ret < 0)
17b94a
+                goto unlock;
17b94a
+
17b94a
+            if (gf_is_service_running(pidfile, &pid)) {
17b94a
                 /* Just connect is required, but we don't know what happens
17b94a
                  * during the disconnect. So better to reattach.
17b94a
                  */
17b94a
@@ -487,10 +508,10 @@ glusterd_shd_svc_mux_init(glusterd_volinfo_t *volinfo, glusterd_svc_t *svc)
17b94a
             }
17b94a
 
17b94a
             if (!mux_proc) {
17b94a
-                if (pid != -1 && sys_access(svc->proc.pidfile, R_OK) == 0) {
17b94a
+                if (pid != -1 && sys_access(pidfile, R_OK) == 0) {
17b94a
                     /* stale pid file, stop and unlink it */
17b94a
                     glusterd_proc_stop(&svc->proc, SIGTERM, PROC_STOP_FORCE);
17b94a
-                    glusterd_unlink_file(svc->proc.pidfile);
17b94a
+                    glusterd_unlink_file(pidfile);
17b94a
                 }
17b94a
                 mux_proc = __gf_find_compatible_svc(GD_NODE_SHD);
17b94a
             }
17b94a
@@ -684,11 +705,10 @@ glusterd_svc_attach_cbk(struct rpc_req *req, struct iovec *iov, int count,
17b94a
                volinfo->volname, glusterd_proc_get_pid(&svc->proc));
17b94a
     } else {
17b94a
         gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_SVC_ATTACH_FAIL,
17b94a
-               "svc %s of volume %s failed to "
17b94a
-               "attach to pid %d. Starting a new process",
17b94a
-               svc->name, volinfo->volname, glusterd_proc_get_pid(&svc->proc));
17b94a
+               "svc %s of volume %s failed to attach to pid %d", svc->name,
17b94a
+               volinfo->volname, glusterd_proc_get_pid(&svc->proc));
17b94a
         if (!strcmp(svc->name, "glustershd")) {
17b94a
-            glusterd_recover_shd_attach_failure(volinfo, svc, *flag);
17b94a
+            glusterd_shd_svcproc_cleanup(&volinfo->shd);
17b94a
         }
17b94a
     }
17b94a
 out:
17b94a
diff --git a/xlators/mgmt/glusterd/src/glusterd-svc-mgmt.c b/xlators/mgmt/glusterd/src/glusterd-svc-mgmt.c
17b94a
index f32dafc..fa316a6 100644
17b94a
--- a/xlators/mgmt/glusterd/src/glusterd-svc-mgmt.c
17b94a
+++ b/xlators/mgmt/glusterd/src/glusterd-svc-mgmt.c
17b94a
@@ -33,14 +33,14 @@ glusterd_svc_create_rundir(char *rundir)
17b94a
     return ret;
17b94a
 }
17b94a
 
17b94a
-static void
17b94a
+void
17b94a
 glusterd_svc_build_logfile_path(char *server, char *logdir, char *logfile,
17b94a
                                 size_t len)
17b94a
 {
17b94a
     snprintf(logfile, len, "%s/%s.log", logdir, server);
17b94a
 }
17b94a
 
17b94a
-static void
17b94a
+void
17b94a
 glusterd_svc_build_volfileid_path(char *server, char *volfileid, size_t len)
17b94a
 {
17b94a
     snprintf(volfileid, len, "gluster/%s", server);
17b94a
diff --git a/xlators/mgmt/glusterd/src/glusterd-svc-mgmt.h b/xlators/mgmt/glusterd/src/glusterd-svc-mgmt.h
17b94a
index fbc5225..5a5466a 100644
17b94a
--- a/xlators/mgmt/glusterd/src/glusterd-svc-mgmt.h
17b94a
+++ b/xlators/mgmt/glusterd/src/glusterd-svc-mgmt.h
17b94a
@@ -74,6 +74,10 @@ glusterd_svc_build_volfile_path(char *server, char *workdir, char *volfile,
17b94a
                                 size_t len);
17b94a
 
17b94a
 void
17b94a
+glusterd_svc_build_logfile_path(char *server, char *logdir, char *logfile,
17b94a
+                                size_t len);
17b94a
+
17b94a
+void
17b94a
 glusterd_svc_build_svcdir(char *server, char *workdir, char *path, size_t len);
17b94a
 
17b94a
 void
17b94a
-- 
17b94a
1.8.3.1
17b94a