7c2869
From 8239d2fec5c182c0501b2fc292024b15cb6bdc91 Mon Sep 17 00:00:00 2001
7c2869
From: Atin Mukherjee <amukherj@redhat.com>
7c2869
Date: Mon, 2 Jul 2018 20:48:22 +0530
7c2869
Subject: [PATCH 679/685] glusterd: Introduce daemon-log-level cluster wide
7c2869
 option
7c2869
7c2869
This option, applicable to the node level daemons can be very helpful in
7c2869
controlling the log level of these services. Please note any daemon
7c2869
which is started prior to setting the specific value of this option (if
7c2869
not INFO) will need to go through a restart to have this change into
7c2869
effect.
7c2869
7c2869
> upstream patch : https://review.gluster.org/#/c/20442/
7c2869
7c2869
Please note there's a difference in deownstream delta. The op-version
7c2869
has to be handled a bit differently as we don't want to get into an
7c2869
op-version (4_2_0) which is higher than RHGS 3.4.0. So we bump up thei
7c2869
current op-version of RHGS 3.3.1 by 1 to have that control which is a
7c2869
downstream only change. Marking this DOWNSTREAM_ONLY label because of
7c2869
it.
7c2869
7c2869
Label: DOWNSTREAM ONLY
7c2869
7c2869
>Change-Id: I7f6d2620bab2b094c737f5cc816bc093e9c9c4c9
7c2869
>fixes: bz#1597473
7c2869
>Signed-off-by: Atin Mukherjee <amukherj@redhat.com>
7c2869
7c2869
Change-Id: I45cf09dbccd27daf8c2bcfd06cc1557953ca0230
7c2869
BUG: 1597509
7c2869
Signed-off-by: Atin Mukherjee <amukherj@redhat.com>
7c2869
Reviewed-on: https://code.engineering.redhat.com/gerrit/143106
7c2869
Reviewed-by: Sanju Rakonde <srakonde@redhat.com>
7c2869
Tested-by: RHGS Build Bot <nigelb@redhat.com>
7c2869
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
7c2869
---
7c2869
 libglusterfs/src/globals.h                      |  5 +-
7c2869
 tests/bugs/glusterd/daemon-log-level-option.t   | 93 +++++++++++++++++++++++++
7c2869
 xlators/mgmt/glusterd/src/glusterd-handler.c    |  3 +-
7c2869
 xlators/mgmt/glusterd/src/glusterd-messages.h   | 10 ++-
7c2869
 xlators/mgmt/glusterd/src/glusterd-op-sm.c      | 50 +++++++++++++
7c2869
 xlators/mgmt/glusterd/src/glusterd-svc-mgmt.c   |  8 +++
7c2869
 xlators/mgmt/glusterd/src/glusterd-volume-set.c |  9 ++-
7c2869
 xlators/mgmt/glusterd/src/glusterd.h            |  1 +
7c2869
 8 files changed, 175 insertions(+), 4 deletions(-)
7c2869
 create mode 100644 tests/bugs/glusterd/daemon-log-level-option.t
7c2869
7c2869
diff --git a/libglusterfs/src/globals.h b/libglusterfs/src/globals.h
7c2869
index caa7f64..6682dc2 100644
7c2869
--- a/libglusterfs/src/globals.h
7c2869
+++ b/libglusterfs/src/globals.h
7c2869
@@ -43,7 +43,7 @@
7c2869
  */
7c2869
 #define GD_OP_VERSION_MIN  1 /* MIN is the fresh start op-version, mostly
7c2869
                                 should not change */
7c2869
-#define GD_OP_VERSION_MAX  GD_OP_VERSION_3_11_1 /* MAX VERSION is the maximum
7c2869
+#define GD_OP_VERSION_MAX  GD_OP_VERSION_3_11_2 /* MAX VERSION is the maximum
7c2869
                                                   count in VME table, should
7c2869
                                                   keep changing with
7c2869
                                                   introduction of newer
7c2869
@@ -93,6 +93,9 @@
7c2869
 
7c2869
 #define GD_OP_VERSION_3_11_1   31101 /* Op-version for GlusterFS 3.11.1 */
7c2869
 
7c2869
+/* Downstream only change */
7c2869
+#define GD_OP_VERSION_3_11_2   31102 /* Op-version for RHGS 3.3.1-async */
7c2869
+
7c2869
 #include "xlator.h"
7c2869
 
7c2869
 /* THIS */
7c2869
diff --git a/tests/bugs/glusterd/daemon-log-level-option.t b/tests/bugs/glusterd/daemon-log-level-option.t
7c2869
new file mode 100644
7c2869
index 0000000..66e55e3
7c2869
--- /dev/null
7c2869
+++ b/tests/bugs/glusterd/daemon-log-level-option.t
7c2869
@@ -0,0 +1,93 @@
7c2869
+#!/bin/bash
7c2869
+
7c2869
+. $(dirname $0)/../../include.rc
7c2869
+
7c2869
+function Info_messages_count() {
7c2869
+        local shd_log=$1
7c2869
+        cat $shd_log | grep " I " | wc -l
7c2869
+}
7c2869
+
7c2869
+function Warning_messages_count() {
7c2869
+        local shd_log=$1
7c2869
+        cat $shd_log | grep " W " | wc -l
7c2869
+}
7c2869
+
7c2869
+function Debug_messages_count() {
7c2869
+        local shd_log=$1
7c2869
+        cat $shd_log | grep " D " | wc -l
7c2869
+}
7c2869
+
7c2869
+function Trace_messages_count() {
7c2869
+        local shd_log=$1
7c2869
+        cat $shd_log | grep " T " | wc -l
7c2869
+}
7c2869
+
7c2869
+cleanup;
7c2869
+
7c2869
+# Basic checks
7c2869
+TEST glusterd
7c2869
+TEST pidof glusterd
7c2869
+TEST $CLI volume info
7c2869
+
7c2869
+# set cluster.daemon-log-level option to DEBUG
7c2869
+TEST $CLI volume set all cluster.daemon-log-level DEBUG
7c2869
+
7c2869
+#Create a 3X2 distributed-replicate volume
7c2869
+TEST $CLI volume create $V0 replica 2 $H0:$B0/${V0}{1..6};
7c2869
+TEST $CLI volume start $V0
7c2869
+
7c2869
+# log should not have any trace messages
7c2869
+EXPECT 0 Trace_messages_count "/var/log/glusterfs/glustershd.log"
7c2869
+
7c2869
+# stop the volume and remove glustershd log
7c2869
+TEST $CLI volume stop $V0
7c2869
+rm -f /var/log/glusterfs/glustershd.log
7c2869
+
7c2869
+# set cluster.daemon-log-level option to INFO and start the volume
7c2869
+TEST $CLI volume set all cluster.daemon-log-level INFO
7c2869
+TEST $CLI volume start $V0
7c2869
+
7c2869
+# log should not have any debug messages
7c2869
+EXPECT 0 Debug_messages_count "/var/log/glusterfs/glustershd.log"
7c2869
+
7c2869
+# log should not have any trace messages
7c2869
+EXPECT 0 Trace_messages_count "/var/log/glusterfs/glustershd.log"
7c2869
+
7c2869
+# stop the volume and remove glustershd log
7c2869
+TEST $CLI volume stop $V0
7c2869
+rm -f /var/log/glusterfs/glustershd.log
7c2869
+
7c2869
+# set cluster.daemon-log-level option to WARNING and start the volume
7c2869
+TEST $CLI volume set all cluster.daemon-log-level WARNING
7c2869
+TEST $CLI volume start $V0
7c2869
+
7c2869
+# log should not have any info messages
7c2869
+EXPECT 0 Info_messages_count "/var/log/glusterfs/glustershd.log"
7c2869
+
7c2869
+# log should not have any debug messages
7c2869
+EXPECT 0 Debug_messages_count "/var/log/glusterfs/glustershd.log"
7c2869
+
7c2869
+# log should not have any trace messages
7c2869
+EXPECT 0 Trace_messages_count "/var/log/glusterfs/glustershd.log"
7c2869
+
7c2869
+# stop the volume and remove glustershd log
7c2869
+TEST $CLI volume stop $V0
7c2869
+rm -f /var/log/glusterfs/glustershd.log
7c2869
+
7c2869
+# set cluster.daemon-log-level option to ERROR and start the volume
7c2869
+TEST $CLI volume set all cluster.daemon-log-level ERROR
7c2869
+TEST $CLI volume start $V0
7c2869
+
7c2869
+# log should not have any info messages
7c2869
+EXPECT 0 Info_messages_count "/var/log/glusterfs/glustershd.log"
7c2869
+
7c2869
+# log should not have any warning messages
7c2869
+EXPECT 0 Warning_messages_count "/var/log/glusterfs/glustershd.log"
7c2869
+
7c2869
+# log should not have any debug messages
7c2869
+EXPECT 0 Debug_messages_count "/var/log/glusterfs/glustershd.log"
7c2869
+
7c2869
+# log should not have any trace messages
7c2869
+EXPECT 0 Trace_messages_count "/var/log/glusterfs/glustershd.log"
7c2869
+
7c2869
+cleanup
7c2869
diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
7c2869
index 0f97573..6d66301 100644
7c2869
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
7c2869
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
7c2869
@@ -4642,7 +4642,8 @@ gd_is_global_option (char *opt_key)
7c2869
         return (strcmp (opt_key, GLUSTERD_SHARED_STORAGE_KEY) == 0 ||
7c2869
                 strcmp (opt_key, GLUSTERD_QUORUM_RATIO_KEY) == 0 ||
7c2869
                 strcmp (opt_key, GLUSTERD_GLOBAL_OP_VERSION_KEY) == 0 ||
7c2869
-                strcmp (opt_key, GLUSTERD_BRICK_MULTIPLEX_KEY) == 0);
7c2869
+                strcmp (opt_key, GLUSTERD_BRICK_MULTIPLEX_KEY) == 0 ||
7c2869
+                strcmp (opt_key, GLUSTERD_DAEMON_LOG_LEVEL_KEY) == 0);
7c2869
 
7c2869
 out:
7c2869
         return _gf_false;
7c2869
diff --git a/xlators/mgmt/glusterd/src/glusterd-messages.h b/xlators/mgmt/glusterd/src/glusterd-messages.h
7c2869
index 0548bd2..a5dc6a3 100644
7c2869
--- a/xlators/mgmt/glusterd/src/glusterd-messages.h
7c2869
+++ b/xlators/mgmt/glusterd/src/glusterd-messages.h
7c2869
@@ -41,7 +41,7 @@
7c2869
 
7c2869
 #define GLUSTERD_COMP_BASE      GLFS_MSGID_GLUSTERD
7c2869
 
7c2869
-#define GLFS_NUM_MESSAGES       599
7c2869
+#define GLFS_NUM_MESSAGES       600
7c2869
 
7c2869
 #define GLFS_MSGID_END          (GLUSTERD_COMP_BASE + GLFS_NUM_MESSAGES + 1)
7c2869
 /* Messaged with message IDs */
7c2869
@@ -4857,6 +4857,14 @@
7c2869
  */
7c2869
 #define GD_MSG_CLIENTS_GET_STATE_FAILED            (GLUSTERD_COMP_BASE + 599)
7c2869
 
7c2869
+/*!
7c2869
+ * @messageid
7c2869
+ * @diagnosis
7c2869
+ * @recommendedaction
7c2869
+ *
7c2869
+ */
7c2869
+#define GD_MSG_DAEMON_LOG_LEVEL_VOL_OPT_VALIDATE_FAIL (GLUSTERD_COMP_BASE + 600)
7c2869
+
7c2869
 /*------------*/
7c2869
 
7c2869
 #define glfs_msg_end_x GLFS_MSGID_END, "Invalid: End of messages"
7c2869
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
7c2869
index ab2886e..91df502 100644
7c2869
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
7c2869
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
7c2869
@@ -84,6 +84,7 @@ glusterd_all_vol_opts valid_all_vol_opts[] = {
7c2869
          * TBD: Discuss the default value for this. Maybe this should be a
7c2869
          * dynamic value depending on the memory specifications per node */
7c2869
         { GLUSTERD_BRICKMUX_LIMIT_KEY,          "0"},
7c2869
+        { GLUSTERD_DAEMON_LOG_LEVEL_KEY,        "INFO"},
7c2869
         { NULL },
7c2869
 };
7c2869
 
7c2869
@@ -865,6 +866,47 @@ out:
7c2869
 }
7c2869
 
7c2869
 static int
7c2869
+glusterd_validate_daemon_log_level (char *key, char *value, char *errstr)
7c2869
+{
7c2869
+        int32_t            ret                      = -1;
7c2869
+        xlator_t          *this                     = NULL;
7c2869
+        glusterd_conf_t   *conf                     = NULL;
7c2869
+
7c2869
+        this = THIS;
7c2869
+        GF_VALIDATE_OR_GOTO ("glusterd", this, out);
7c2869
+
7c2869
+        conf = this->private;
7c2869
+        GF_VALIDATE_OR_GOTO (this->name, conf, out);
7c2869
+
7c2869
+        GF_VALIDATE_OR_GOTO (this->name, key, out);
7c2869
+        GF_VALIDATE_OR_GOTO (this->name, value, out);
7c2869
+        GF_VALIDATE_OR_GOTO (this->name, errstr, out);
7c2869
+
7c2869
+        ret = 0;
7c2869
+
7c2869
+        if (strcmp (key, GLUSTERD_DAEMON_LOG_LEVEL_KEY)) {
7c2869
+                goto out;
7c2869
+        }
7c2869
+
7c2869
+        if ((strcmp (value, "INFO")) &&
7c2869
+            (strcmp (value, "WARNING")) &&
7c2869
+            (strcmp (value, "DEBUG")) &&
7c2869
+            (strcmp (value, "TRACE")) &&
7c2869
+            (strcmp (value, "ERROR"))) {
7c2869
+                snprintf (errstr, PATH_MAX,
7c2869
+                          "Invalid option(%s). Valid options "
7c2869
+                          "are 'INFO' or 'WARNING' or 'ERROR' or 'DEBUG' or "
7c2869
+                          " 'TRACE'", value);
7c2869
+                gf_msg (this->name, GF_LOG_ERROR, EINVAL,
7c2869
+                        GD_MSG_INVALID_ENTRY, "%s", errstr);
7c2869
+                ret = -1;
7c2869
+        }
7c2869
+
7c2869
+out:
7c2869
+        return ret;
7c2869
+}
7c2869
+
7c2869
+static int
7c2869
 glusterd_op_stage_set_volume (dict_t *dict, char **op_errstr)
7c2869
 {
7c2869
         int                   ret                         = -1;
7c2869
@@ -1265,6 +1307,14 @@ glusterd_op_stage_set_volume (dict_t *dict, char **op_errstr)
7c2869
                                 "storage volume options");
7c2869
                         goto out;
7c2869
                 }
7c2869
+                ret = glusterd_validate_daemon_log_level (key, value, errstr);
7c2869
+                if (ret) {
7c2869
+                        gf_msg (this->name, GF_LOG_ERROR, 0,
7c2869
+                                GD_MSG_DAEMON_LOG_LEVEL_VOL_OPT_VALIDATE_FAIL,
7c2869
+                                "Failed to validate daemon-log-level volume "
7c2869
+                                "options");
7c2869
+                        goto out;
7c2869
+                }
7c2869
 
7c2869
                 if (!strcmp(key, "features.trash-dir") && trash_enabled) {
7c2869
                         if (strchr (value, '/')) {
7c2869
diff --git a/xlators/mgmt/glusterd/src/glusterd-svc-mgmt.c b/xlators/mgmt/glusterd/src/glusterd-svc-mgmt.c
7c2869
index 9dcf503..03a2ee0 100644
7c2869
--- a/xlators/mgmt/glusterd/src/glusterd-svc-mgmt.c
7c2869
+++ b/xlators/mgmt/glusterd/src/glusterd-svc-mgmt.c
7c2869
@@ -150,6 +150,8 @@ glusterd_svc_start (glusterd_svc_t *svc, int flags, dict_t *cmdline)
7c2869
         glusterd_conf_t     *priv                       = NULL;
7c2869
         xlator_t            *this                       = NULL;
7c2869
         char                 valgrind_logfile[PATH_MAX] = {0};
7c2869
+        char                *log_level                  = NULL;
7c2869
+        char                 daemon_log_level[30]       = {0};
7c2869
 
7c2869
         this = THIS;
7c2869
         GF_ASSERT (this);
7c2869
@@ -190,6 +192,12 @@ glusterd_svc_start (glusterd_svc_t *svc, int flags, dict_t *cmdline)
7c2869
                          "-S", svc->conn.sockpath,
7c2869
                          NULL);
7c2869
 
7c2869
+        if (dict_get_str (priv->opts, GLUSTERD_DAEMON_LOG_LEVEL_KEY,
7c2869
+                          &log_level) == 0) {
7c2869
+                snprintf (daemon_log_level, 30, "--log-level=%s", log_level);
7c2869
+                runner_add_arg (&runner, daemon_log_level);
7c2869
+        }
7c2869
+
7c2869
         if (cmdline)
7c2869
                 dict_foreach (cmdline, svc_add_args, (void *) &runner);
7c2869
 
7c2869
diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-set.c b/xlators/mgmt/glusterd/src/glusterd-volume-set.c
7c2869
index ddda66e..d894679 100644
7c2869
--- a/xlators/mgmt/glusterd/src/glusterd-volume-set.c
7c2869
+++ b/xlators/mgmt/glusterd/src/glusterd-volume-set.c
7c2869
@@ -3295,6 +3295,13 @@ struct volopt_map_entry glusterd_volopt_map[] = {
7c2869
                          "process. Also this option can't be set when the "
7c2869
                          "brick-multiplexing feature is disabled."
7c2869
         },
7c2869
-        { .key         = NULL
7c2869
+        { .key        = GLUSTERD_DAEMON_LOG_LEVEL_KEY,
7c2869
+          .voltype    = "mgmt/glusterd",
7c2869
+          .type       = GLOBAL_NO_DOC,
7c2869
+          .value      = "INFO",
7c2869
+          .op_version = GD_OP_VERSION_3_11_2,
7c2869
+        },
7c2869
+        {
7c2869
+          .key = NULL
7c2869
         }
7c2869
 };
7c2869
diff --git a/xlators/mgmt/glusterd/src/glusterd.h b/xlators/mgmt/glusterd/src/glusterd.h
7c2869
index b94ccc9..3750fe8 100644
7c2869
--- a/xlators/mgmt/glusterd/src/glusterd.h
7c2869
+++ b/xlators/mgmt/glusterd/src/glusterd.h
7c2869
@@ -53,6 +53,7 @@
7c2869
 #define GLUSTERD_SHARED_STORAGE_KEY     "cluster.enable-shared-storage"
7c2869
 #define GLUSTERD_BRICK_MULTIPLEX_KEY    "cluster.brick-multiplex"
7c2869
 #define GLUSTERD_BRICKMUX_LIMIT_KEY     "cluster.max-bricks-per-process"
7c2869
+#define GLUSTERD_DAEMON_LOG_LEVEL_KEY   "cluster.daemon-log-level"
7c2869
 
7c2869
 #define GANESHA_HA_CONF  CONFDIR "/ganesha-ha.conf"
7c2869
 #define GANESHA_EXPORT_DIRECTORY        CONFDIR"/exports"
7c2869
-- 
7c2869
1.8.3.1
7c2869