a3470f
From b6aa09f8718c5ab91ae4e99abb6567fb1601cdbb Mon Sep 17 00:00:00 2001
a3470f
From: Atin Mukherjee <amukherj@redhat.com>
a3470f
Date: Mon, 2 Jul 2018 20:48:22 +0530
a3470f
Subject: [PATCH 307/325] glusterd: Introduce daemon-log-level cluster wide
a3470f
 option
a3470f
a3470f
This option, applicable to the node level daemons can be very helpful in
a3470f
controlling the log level of these services. Please note any daemon
a3470f
which is started prior to setting the specific value of this option (if
a3470f
not INFO) will need to go through a restart to have this change into
a3470f
effect.
a3470f
a3470f
> upstream patch : https://review.gluster.org/#/c/20442/
a3470f
a3470f
Please note there's a difference in deownstream delta. The op-version
a3470f
against this option is already tageed as 3_11_2 in RHGS 3.3.1 and hence
a3470f
the same is retained. Marking this DOWNSTREAM_ONLY label because of
a3470f
a3470f
Label: DOWNSTREAM ONLY
a3470f
a3470f
>Change-Id: I7f6d2620bab2b094c737f5cc816bc093e9c9c4c9
a3470f
>fixes: bz#1597473
a3470f
>Signed-off-by: Atin Mukherjee <amukherj@redhat.com>
a3470f
a3470f
Change-Id: I7f6d2620bab2b094c737f5cc816bc093e9c9c4c9
a3470f
BUG: 1597511
a3470f
Signed-off-by: Atin Mukherjee <amukherj@redhat.com>
a3470f
Reviewed-on: https://code.engineering.redhat.com/gerrit/143137
a3470f
Tested-by: RHGS Build Bot <nigelb@redhat.com>
a3470f
Reviewed-by: Sanju Rakonde <srakonde@redhat.com>
a3470f
---
a3470f
 libglusterfs/src/globals.h                      |  3 +
a3470f
 tests/bugs/glusterd/daemon-log-level-option.t   | 93 +++++++++++++++++++++++++
a3470f
 xlators/mgmt/glusterd/src/glusterd-handler.c    |  1 +
a3470f
 xlators/mgmt/glusterd/src/glusterd-messages.h   | 10 ++-
a3470f
 xlators/mgmt/glusterd/src/glusterd-op-sm.c      | 51 ++++++++++++++
a3470f
 xlators/mgmt/glusterd/src/glusterd-svc-mgmt.c   |  8 +++
a3470f
 xlators/mgmt/glusterd/src/glusterd-volume-set.c |  6 ++
a3470f
 xlators/mgmt/glusterd/src/glusterd.h            |  1 +
a3470f
 8 files changed, 172 insertions(+), 1 deletion(-)
a3470f
 create mode 100644 tests/bugs/glusterd/daemon-log-level-option.t
a3470f
a3470f
diff --git a/libglusterfs/src/globals.h b/libglusterfs/src/globals.h
a3470f
index 8fd3318..39d9716 100644
a3470f
--- a/libglusterfs/src/globals.h
a3470f
+++ b/libglusterfs/src/globals.h
a3470f
@@ -109,6 +109,9 @@
a3470f
 
a3470f
 #define GD_OP_VERSION_3_13_2   31302 /* Op-version for GlusterFS 3.13.2 */
a3470f
 
a3470f
+/* Downstream only change */
a3470f
+#define GD_OP_VERSION_3_11_2   31102 /* Op-version for RHGS 3.3.1-async */
a3470f
+
a3470f
 #include "xlator.h"
a3470f
 
a3470f
 /* THIS */
a3470f
diff --git a/tests/bugs/glusterd/daemon-log-level-option.t b/tests/bugs/glusterd/daemon-log-level-option.t
a3470f
new file mode 100644
a3470f
index 0000000..66e55e3
a3470f
--- /dev/null
a3470f
+++ b/tests/bugs/glusterd/daemon-log-level-option.t
a3470f
@@ -0,0 +1,93 @@
a3470f
+#!/bin/bash
a3470f
+
a3470f
+. $(dirname $0)/../../include.rc
a3470f
+
a3470f
+function Info_messages_count() {
a3470f
+        local shd_log=$1
a3470f
+        cat $shd_log | grep " I " | wc -l
a3470f
+}
a3470f
+
a3470f
+function Warning_messages_count() {
a3470f
+        local shd_log=$1
a3470f
+        cat $shd_log | grep " W " | wc -l
a3470f
+}
a3470f
+
a3470f
+function Debug_messages_count() {
a3470f
+        local shd_log=$1
a3470f
+        cat $shd_log | grep " D " | wc -l
a3470f
+}
a3470f
+
a3470f
+function Trace_messages_count() {
a3470f
+        local shd_log=$1
a3470f
+        cat $shd_log | grep " T " | wc -l
a3470f
+}
a3470f
+
a3470f
+cleanup;
a3470f
+
a3470f
+# Basic checks
a3470f
+TEST glusterd
a3470f
+TEST pidof glusterd
a3470f
+TEST $CLI volume info
a3470f
+
a3470f
+# set cluster.daemon-log-level option to DEBUG
a3470f
+TEST $CLI volume set all cluster.daemon-log-level DEBUG
a3470f
+
a3470f
+#Create a 3X2 distributed-replicate volume
a3470f
+TEST $CLI volume create $V0 replica 2 $H0:$B0/${V0}{1..6};
a3470f
+TEST $CLI volume start $V0
a3470f
+
a3470f
+# log should not have any trace messages
a3470f
+EXPECT 0 Trace_messages_count "/var/log/glusterfs/glustershd.log"
a3470f
+
a3470f
+# stop the volume and remove glustershd log
a3470f
+TEST $CLI volume stop $V0
a3470f
+rm -f /var/log/glusterfs/glustershd.log
a3470f
+
a3470f
+# set cluster.daemon-log-level option to INFO and start the volume
a3470f
+TEST $CLI volume set all cluster.daemon-log-level INFO
a3470f
+TEST $CLI volume start $V0
a3470f
+
a3470f
+# log should not have any debug messages
a3470f
+EXPECT 0 Debug_messages_count "/var/log/glusterfs/glustershd.log"
a3470f
+
a3470f
+# log should not have any trace messages
a3470f
+EXPECT 0 Trace_messages_count "/var/log/glusterfs/glustershd.log"
a3470f
+
a3470f
+# stop the volume and remove glustershd log
a3470f
+TEST $CLI volume stop $V0
a3470f
+rm -f /var/log/glusterfs/glustershd.log
a3470f
+
a3470f
+# set cluster.daemon-log-level option to WARNING and start the volume
a3470f
+TEST $CLI volume set all cluster.daemon-log-level WARNING
a3470f
+TEST $CLI volume start $V0
a3470f
+
a3470f
+# log should not have any info messages
a3470f
+EXPECT 0 Info_messages_count "/var/log/glusterfs/glustershd.log"
a3470f
+
a3470f
+# log should not have any debug messages
a3470f
+EXPECT 0 Debug_messages_count "/var/log/glusterfs/glustershd.log"
a3470f
+
a3470f
+# log should not have any trace messages
a3470f
+EXPECT 0 Trace_messages_count "/var/log/glusterfs/glustershd.log"
a3470f
+
a3470f
+# stop the volume and remove glustershd log
a3470f
+TEST $CLI volume stop $V0
a3470f
+rm -f /var/log/glusterfs/glustershd.log
a3470f
+
a3470f
+# set cluster.daemon-log-level option to ERROR and start the volume
a3470f
+TEST $CLI volume set all cluster.daemon-log-level ERROR
a3470f
+TEST $CLI volume start $V0
a3470f
+
a3470f
+# log should not have any info messages
a3470f
+EXPECT 0 Info_messages_count "/var/log/glusterfs/glustershd.log"
a3470f
+
a3470f
+# log should not have any warning messages
a3470f
+EXPECT 0 Warning_messages_count "/var/log/glusterfs/glustershd.log"
a3470f
+
a3470f
+# log should not have any debug messages
a3470f
+EXPECT 0 Debug_messages_count "/var/log/glusterfs/glustershd.log"
a3470f
+
a3470f
+# log should not have any trace messages
a3470f
+EXPECT 0 Trace_messages_count "/var/log/glusterfs/glustershd.log"
a3470f
+
a3470f
+cleanup
a3470f
diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
a3470f
index c072b05..c0c3e25 100644
a3470f
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
a3470f
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
a3470f
@@ -4677,6 +4677,7 @@ gd_is_global_option (char *opt_key)
a3470f
                 strcmp (opt_key, GLUSTERD_GLOBAL_OP_VERSION_KEY) == 0 ||
a3470f
                 strcmp (opt_key, GLUSTERD_BRICK_MULTIPLEX_KEY) == 0 ||
a3470f
                 strcmp (opt_key, GLUSTERD_LOCALTIME_LOGGING_KEY) == 0 ||
a3470f
+                strcmp (opt_key, GLUSTERD_DAEMON_LOG_LEVEL_KEY) == 0 ||
a3470f
                 strcmp (opt_key, GLUSTERD_MAX_OP_VERSION_KEY) == 0);
a3470f
 
a3470f
 out:
a3470f
diff --git a/xlators/mgmt/glusterd/src/glusterd-messages.h b/xlators/mgmt/glusterd/src/glusterd-messages.h
a3470f
index 4ccf299..64f7378 100644
a3470f
--- a/xlators/mgmt/glusterd/src/glusterd-messages.h
a3470f
+++ b/xlators/mgmt/glusterd/src/glusterd-messages.h
a3470f
@@ -41,7 +41,7 @@
a3470f
 
a3470f
 #define GLUSTERD_COMP_BASE      GLFS_MSGID_GLUSTERD
a3470f
 
a3470f
-#define GLFS_NUM_MESSAGES       614
a3470f
+#define GLFS_NUM_MESSAGES       615
a3470f
 
a3470f
 #define GLFS_MSGID_END          (GLUSTERD_COMP_BASE + GLFS_NUM_MESSAGES + 1)
a3470f
 /* Messaged with message IDs */
a3470f
@@ -4984,6 +4984,14 @@
a3470f
  */
a3470f
 #define GD_MSG_MANAGER_FUNCTION_FAILED  (GLUSTERD_COMP_BASE + 614)
a3470f
 
a3470f
+/*!
a3470f
+ * @messageid
a3470f
+ * @diagnosis
a3470f
+ * @recommendedaction
a3470f
+ *
a3470f
+ */
a3470f
+#define GD_MSG_DAEMON_LOG_LEVEL_VOL_OPT_VALIDATE_FAIL (GLUSTERD_COMP_BASE + 615)
a3470f
+
a3470f
 /*------------*/
a3470f
 
a3470f
 #define glfs_msg_end_x GLFS_MSGID_END, "Invalid: End of messages"
a3470f
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
a3470f
index 7e959a0..d022532 100644
a3470f
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
a3470f
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
a3470f
@@ -86,6 +86,7 @@ glusterd_all_vol_opts valid_all_vol_opts[] = {
a3470f
          * dynamic value depending on the memory specifications per node */
a3470f
         { GLUSTERD_BRICKMUX_LIMIT_KEY,          "0"},
a3470f
         /*{ GLUSTERD_LOCALTIME_LOGGING_KEY,       "disable"},*/
a3470f
+        { GLUSTERD_DAEMON_LOG_LEVEL_KEY,        "INFO"},
a3470f
         { NULL },
a3470f
 };
a3470f
 
a3470f
@@ -928,6 +929,47 @@ out:
a3470f
 }
a3470f
 
a3470f
 static int
a3470f
+glusterd_validate_daemon_log_level (char *key, char *value, char *errstr)
a3470f
+{
a3470f
+        int32_t            ret                      = -1;
a3470f
+        xlator_t          *this                     = NULL;
a3470f
+        glusterd_conf_t   *conf                     = NULL;
a3470f
+
a3470f
+        this = THIS;
a3470f
+        GF_VALIDATE_OR_GOTO ("glusterd", this, out);
a3470f
+
a3470f
+        conf = this->private;
a3470f
+        GF_VALIDATE_OR_GOTO (this->name, conf, out);
a3470f
+
a3470f
+        GF_VALIDATE_OR_GOTO (this->name, key, out);
a3470f
+        GF_VALIDATE_OR_GOTO (this->name, value, out);
a3470f
+        GF_VALIDATE_OR_GOTO (this->name, errstr, out);
a3470f
+
a3470f
+        ret = 0;
a3470f
+
a3470f
+        if (strcmp (key, GLUSTERD_DAEMON_LOG_LEVEL_KEY)) {
a3470f
+                goto out;
a3470f
+        }
a3470f
+
a3470f
+        if ((strcmp (value, "INFO")) &&
a3470f
+            (strcmp (value, "WARNING")) &&
a3470f
+            (strcmp (value, "DEBUG")) &&
a3470f
+            (strcmp (value, "TRACE")) &&
a3470f
+            (strcmp (value, "ERROR"))) {
a3470f
+                snprintf (errstr, PATH_MAX,
a3470f
+                          "Invalid option(%s). Valid options "
a3470f
+                          "are 'INFO' or 'WARNING' or 'ERROR' or 'DEBUG' or "
a3470f
+                          " 'TRACE'", value);
a3470f
+                gf_msg (this->name, GF_LOG_ERROR, EINVAL,
a3470f
+                        GD_MSG_INVALID_ENTRY, "%s", errstr);
a3470f
+                ret = -1;
a3470f
+        }
a3470f
+
a3470f
+out:
a3470f
+        return ret;
a3470f
+}
a3470f
+
a3470f
+static int
a3470f
 glusterd_op_stage_set_volume (dict_t *dict, char **op_errstr)
a3470f
 {
a3470f
         int                   ret                         = -1;
a3470f
@@ -1326,6 +1368,15 @@ glusterd_op_stage_set_volume (dict_t *dict, char **op_errstr)
a3470f
                         goto out;
a3470f
                 }
a3470f
 
a3470f
+                ret = glusterd_validate_daemon_log_level (key, value, errstr);
a3470f
+                if (ret) {
a3470f
+                        gf_msg (this->name, GF_LOG_ERROR, 0,
a3470f
+                                GD_MSG_DAEMON_LOG_LEVEL_VOL_OPT_VALIDATE_FAIL,
a3470f
+                                "Failed to validate daemon-log-level volume "
a3470f
+                                "options");
a3470f
+                        goto out;
a3470f
+                }
a3470f
+
a3470f
                 if (volinfo) {
a3470f
                         ret = glusterd_volinfo_get (volinfo,
a3470f
                                                 VKEY_FEATURES_TRASH, &val_dup);
a3470f
diff --git a/xlators/mgmt/glusterd/src/glusterd-svc-mgmt.c b/xlators/mgmt/glusterd/src/glusterd-svc-mgmt.c
a3470f
index ba948b4..ebb288c 100644
a3470f
--- a/xlators/mgmt/glusterd/src/glusterd-svc-mgmt.c
a3470f
+++ b/xlators/mgmt/glusterd/src/glusterd-svc-mgmt.c
a3470f
@@ -151,6 +151,8 @@ glusterd_svc_start (glusterd_svc_t *svc, int flags, dict_t *cmdline)
a3470f
         xlator_t            *this                       = NULL;
a3470f
         char                 valgrind_logfile[PATH_MAX] = {0};
a3470f
         char                *localtime_logging          = NULL;
a3470f
+        char                *log_level                  = NULL;
a3470f
+        char                 daemon_log_level[30]       = {0};
a3470f
 
a3470f
         this = THIS;
a3470f
         GF_ASSERT (this);
a3470f
@@ -196,6 +198,12 @@ glusterd_svc_start (glusterd_svc_t *svc, int flags, dict_t *cmdline)
a3470f
                 if (strcmp (localtime_logging, "enable") == 0)
a3470f
                         runner_add_arg (&runner, "--localtime-logging");
a3470f
         }
a3470f
+        if (dict_get_str (priv->opts, GLUSTERD_DAEMON_LOG_LEVEL_KEY,
a3470f
+                          &log_level) == 0) {
a3470f
+                snprintf (daemon_log_level, 30, "--log-level=%s", log_level);
a3470f
+                runner_add_arg (&runner, daemon_log_level);
a3470f
+        }
a3470f
+
a3470f
         if (cmdline)
a3470f
                 dict_foreach (cmdline, svc_add_args, (void *) &runner);
a3470f
 
a3470f
diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-set.c b/xlators/mgmt/glusterd/src/glusterd-volume-set.c
a3470f
index b9da961..8cc756a 100644
a3470f
--- a/xlators/mgmt/glusterd/src/glusterd-volume-set.c
a3470f
+++ b/xlators/mgmt/glusterd/src/glusterd-volume-set.c
a3470f
@@ -3573,6 +3573,12 @@ struct volopt_map_entry glusterd_volopt_map[] = {
a3470f
           .op_version  = GD_OP_VERSION_3_12_0,
a3470f
           .validate_fn = validate_boolean
a3470f
         },*/
a3470f
+        { .key         = GLUSTERD_DAEMON_LOG_LEVEL_KEY,
a3470f
+          .voltype     = "mgmt/glusterd",
a3470f
+          .type        = GLOBAL_NO_DOC,
a3470f
+          .value       = "INFO",
a3470f
+          .op_version  = GD_OP_VERSION_3_11_2
a3470f
+        },
a3470f
         { .key        = "disperse.parallel-writes",
a3470f
           .voltype    = "cluster/disperse",
a3470f
           .type       = NO_DOC,
a3470f
diff --git a/xlators/mgmt/glusterd/src/glusterd.h b/xlators/mgmt/glusterd/src/glusterd.h
a3470f
index b0656e6..4ec609f 100644
a3470f
--- a/xlators/mgmt/glusterd/src/glusterd.h
a3470f
+++ b/xlators/mgmt/glusterd/src/glusterd.h
a3470f
@@ -56,6 +56,7 @@
a3470f
 #define GLUSTERD_BRICK_MULTIPLEX_KEY    "cluster.brick-multiplex"
a3470f
 #define GLUSTERD_BRICKMUX_LIMIT_KEY     "cluster.max-bricks-per-process"
a3470f
 #define GLUSTERD_LOCALTIME_LOGGING_KEY  "cluster.localtime-logging"
a3470f
+#define GLUSTERD_DAEMON_LOG_LEVEL_KEY   "cluster.daemon-log-level"
a3470f
 
a3470f
 #define GANESHA_HA_CONF  CONFDIR "/ganesha-ha.conf"
a3470f
 #define GANESHA_EXPORT_DIRECTORY        CONFDIR"/exports"
a3470f
-- 
a3470f
1.8.3.1
a3470f