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