74b1de
From 023854d5573211d4737eb0ebe7ec954a7b7bb4ee Mon Sep 17 00:00:00 2001
74b1de
From: Mohit Agrawal <moagrawal@redhat.com>
74b1de
Date: Mon, 15 Apr 2019 10:34:34 +0530
74b1de
Subject: [PATCH 105/124] core: Log level changes do not effect on running
74b1de
 client process
74b1de
74b1de
Problem: commit c34e4161f3cb6539ec83a9020f3d27eb4759a975 set log-level
74b1de
         per xlator during reconfigure only for a brick process not for
74b1de
         the client process.
74b1de
74b1de
Solution: 1) Change per xlator log-level only if brick_mux is enabled.To make sure
74b1de
             about brick multiplex introudce a flag brick_mux at ctx->cmd_args.
74b1de
74b1de
Note: There are two other changes done with this patch
74b1de
      1) Ignore client-log-level option to attach a brick with
74b1de
         already running brick if brick_mux is enabled
74b1de
      2) Add a log to print pid of the running process to make easier
74b1de
         debugging
74b1de
74b1de
> Change-Id: I39e85de778e150d0685cd9a79425ce8b4783f9c9
74b1de
> Signed-off-by: Mohit Agrawal <moagrawal@redhat.com>
74b1de
> Fixes: bz#1696046
74b1de
> (Cherry picked from commit 798aadbe51a9a02dd98a0f861cc239ecf7c8ed57)
74b1de
> (Reviewed on upstream link https://review.gluster.org/#/c/glusterfs/+/22495/)
74b1de
74b1de
Change-Id: If82cc8e51cf00bd50d3321d31ec420f89786ea02
74b1de
Fixes: bz#1695081
74b1de
Signed-off-by: Mohit Agrawal <moagrawal@redhat.com>
74b1de
Reviewed-on: https://code.engineering.redhat.com/gerrit/167828
74b1de
Tested-by: Mohit Agrawal <moagrawa@redhat.com>
74b1de
Tested-by: RHGS Build Bot <nigelb@redhat.com>
74b1de
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
74b1de
---
74b1de
 glusterfsd/src/glusterfsd-messages.h       |   2 +-
74b1de
 glusterfsd/src/glusterfsd.c                |  20 ++++-
74b1de
 glusterfsd/src/glusterfsd.h                |   1 +
74b1de
 libglusterfs/src/glusterfs/glusterfs.h     |   1 +
74b1de
 tests/bugs/glusterd/bug-1696046.t          | 113 +++++++++++++++++++++++++++++
74b1de
 xlators/debug/io-stats/src/io-stats.c      |  22 +++---
74b1de
 xlators/mgmt/glusterd/src/glusterd-utils.c |   7 ++
74b1de
 7 files changed, 152 insertions(+), 14 deletions(-)
74b1de
 create mode 100644 tests/bugs/glusterd/bug-1696046.t
74b1de
74b1de
diff --git a/glusterfsd/src/glusterfsd-messages.h b/glusterfsd/src/glusterfsd-messages.h
74b1de
index 94312a5..280624c 100644
74b1de
--- a/glusterfsd/src/glusterfsd-messages.h
74b1de
+++ b/glusterfsd/src/glusterfsd-messages.h
74b1de
@@ -36,6 +36,6 @@ GLFS_MSGID(GLUSTERFSD, glusterfsd_msg_1, glusterfsd_msg_2, glusterfsd_msg_3,
74b1de
            glusterfsd_msg_31, glusterfsd_msg_32, glusterfsd_msg_33,
74b1de
            glusterfsd_msg_34, glusterfsd_msg_35, glusterfsd_msg_36,
74b1de
            glusterfsd_msg_37, glusterfsd_msg_38, glusterfsd_msg_39,
74b1de
-           glusterfsd_msg_40, glusterfsd_msg_41, glusterfsd_msg_42);
74b1de
+           glusterfsd_msg_40, glusterfsd_msg_41, glusterfsd_msg_42, glusterfsd_msg_43);
74b1de
 
74b1de
 #endif /* !_GLUSTERFSD_MESSAGES_H_ */
74b1de
diff --git a/glusterfsd/src/glusterfsd.c b/glusterfsd/src/glusterfsd.c
74b1de
index 3aa89ca..6aee4c1 100644
74b1de
--- a/glusterfsd/src/glusterfsd.c
74b1de
+++ b/glusterfsd/src/glusterfsd.c
74b1de
@@ -85,8 +85,7 @@ static char gf_doc[] = "";
74b1de
 static char argp_doc[] =
74b1de
     "--volfile-server=SERVER [MOUNT-POINT]\n"
74b1de
     "--volfile=VOLFILE [MOUNT-POINT]";
74b1de
-const char *argp_program_version =
74b1de
-    PACKAGE_NAME" "PACKAGE_VERSION;
74b1de
+const char *argp_program_version = PACKAGE_NAME " " PACKAGE_VERSION;
74b1de
 const char *argp_program_bug_address = "<" PACKAGE_BUGREPORT ">";
74b1de
 
74b1de
 static error_t
74b1de
@@ -266,6 +265,7 @@ static struct argp_option gf_options[] = {
74b1de
      "attribute, dentry and page-cache. "
74b1de
      "Disable this only if same files/directories are not accessed across "
74b1de
      "two different mounts concurrently [default: \"on\"]"},
74b1de
+    {"brick-mux", ARGP_BRICK_MUX_KEY, 0, 0, "Enable brick mux. "},
74b1de
     {0, 0, 0, 0, "Miscellaneous Options:"},
74b1de
     {
74b1de
         0,
74b1de
@@ -702,7 +702,6 @@ create_fuse_mount(glusterfs_ctx_t *ctx)
74b1de
     xlator_t *master = NULL;
74b1de
 
74b1de
     cmd_args = &ctx->cmd_args;
74b1de
-
74b1de
     if (!cmd_args->mount_point) {
74b1de
         gf_msg_trace("glusterfsd", 0,
74b1de
                      "mount point not found, not a client process");
74b1de
@@ -1090,6 +1089,10 @@ parse_opts(int key, char *arg, struct argp_state *state)
74b1de
             cmd_args->thin_client = _gf_true;
74b1de
             break;
74b1de
 
74b1de
+        case ARGP_BRICK_MUX_KEY:
74b1de
+            cmd_args->brick_mux = _gf_true;
74b1de
+            break;
74b1de
+
74b1de
         case ARGP_PID_FILE_KEY:
74b1de
             cmd_args->pid_file = gf_strdup(arg);
74b1de
             break;
74b1de
@@ -1207,7 +1210,6 @@ parse_opts(int key, char *arg, struct argp_state *state)
74b1de
         case ARGP_KEY_ARG:
74b1de
             if (state->arg_num >= 1)
74b1de
                 argp_usage(state);
74b1de
-
74b1de
             cmd_args->mount_point = gf_strdup(arg);
74b1de
             break;
74b1de
 
74b1de
@@ -2540,6 +2542,8 @@ postfork:
74b1de
         if (ret)
74b1de
             goto out;
74b1de
     }
74b1de
+    gf_log("glusterfs", GF_LOG_INFO, "Pid of current running process is %d",
74b1de
+           getpid());
74b1de
     ret = gf_log_inject_timer_event(ctx);
74b1de
 
74b1de
     glusterfs_signals_setup(ctx);
74b1de
@@ -2787,6 +2791,14 @@ main(int argc, char *argv[])
74b1de
     if (ret)
74b1de
         goto out;
74b1de
 
74b1de
+    /* set brick_mux mode only for server process */
74b1de
+    if ((ctx->process_mode != GF_SERVER_PROCESS) && cmd->brick_mux) {
74b1de
+        gf_msg("glusterfs", GF_LOG_CRITICAL, 0, glusterfsd_msg_43,
74b1de
+               "command line argument --brick-mux is valid only for brick "
74b1de
+               "process");
74b1de
+        goto out;
74b1de
+    }
74b1de
+
74b1de
     /* log the version of glusterfs running here along with the actual
74b1de
        command line options. */
74b1de
     {
74b1de
diff --git a/glusterfsd/src/glusterfsd.h b/glusterfsd/src/glusterfsd.h
74b1de
index 35cf6d8..fa55789 100644
74b1de
--- a/glusterfsd/src/glusterfsd.h
74b1de
+++ b/glusterfsd/src/glusterfsd.h
74b1de
@@ -111,6 +111,7 @@ enum argp_option_keys {
74b1de
     ARGP_FUSE_FLUSH_HANDLE_INTERRUPT_KEY = 189,
74b1de
     ARGP_FUSE_LRU_LIMIT_KEY = 190,
74b1de
     ARGP_FUSE_AUTO_INVAL_KEY = 191,
74b1de
+    ARGP_BRICK_MUX_KEY = 192
74b1de
 };
74b1de
 
74b1de
 struct _gfd_vol_top_priv {
74b1de
diff --git a/libglusterfs/src/glusterfs/glusterfs.h b/libglusterfs/src/glusterfs/glusterfs.h
74b1de
index deec5ba..fb727fc 100644
74b1de
--- a/libglusterfs/src/glusterfs/glusterfs.h
74b1de
+++ b/libglusterfs/src/glusterfs/glusterfs.h
74b1de
@@ -575,6 +575,7 @@ struct _cmd_args {
74b1de
 
74b1de
     int fuse_flush_handle_interrupt;
74b1de
     int fuse_auto_inval;
74b1de
+    bool brick_mux;
74b1de
 };
74b1de
 typedef struct _cmd_args cmd_args_t;
74b1de
 
74b1de
diff --git a/tests/bugs/glusterd/bug-1696046.t b/tests/bugs/glusterd/bug-1696046.t
74b1de
new file mode 100644
74b1de
index 0000000..e1c1eb2
74b1de
--- /dev/null
74b1de
+++ b/tests/bugs/glusterd/bug-1696046.t
74b1de
@@ -0,0 +1,113 @@
74b1de
+#!/bin/bash
74b1de
+
74b1de
+. $(dirname $0)/../../include.rc
74b1de
+. $(dirname $0)/../../volume.rc
74b1de
+
74b1de
+cleanup;
74b1de
+
74b1de
+function count_up_bricks {
74b1de
+        $CLI --xml volume status $1 | grep '<status>1' | wc -l
74b1de
+}
74b1de
+
74b1de
+function count_brick_processes {
74b1de
+        pgrep glusterfsd | wc -l
74b1de
+}
74b1de
+
74b1de
+logdir=`gluster --print-logdir`
74b1de
+
74b1de
+## Start and create a volume
74b1de
+TEST glusterd;
74b1de
+TEST pidof glusterd;
74b1de
+
74b1de
+TEST $CLI volume set all cluster.brick-multiplex on
74b1de
+TEST $CLI volume create $V0 replica 3 $H0:$B0/${V0}{1,2,3};
74b1de
+TEST $CLI volume create $V1 replica 3 $H0:$B0/${V1}{1,2,3};
74b1de
+
74b1de
+## Start volume and verify
74b1de
+TEST $CLI volume start $V0;
74b1de
+EXPECT 'Started' volinfo_field $V0 'Status';
74b1de
+TEST $CLI volume start $V1;
74b1de
+EXPECT 'Started' volinfo_field $V1 'Status';
74b1de
+
74b1de
+
74b1de
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT 4 count_up_bricks $V0
74b1de
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT 4 count_up_bricks $V1
74b1de
+
74b1de
+EXPECT 1 count_brick_processes
74b1de
+
74b1de
+# Mount V0
74b1de
+TEST glusterfs --volfile-id=$V0 --volfile-server=$H0 --entry-timeout=0 $M0;
74b1de
+
74b1de
+function client-log-file-name()
74b1de
+{
74b1de
+    logfilename=$M0".log"
74b1de
+    echo ${logfilename:1} | tr / -
74b1de
+}
74b1de
+
74b1de
+function brick-log-file-name()
74b1de
+{
74b1de
+    logfilename=$B0"/"$V0"1.log"
74b1de
+    echo ${logfilename:1} | tr / -
74b1de
+}
74b1de
+
74b1de
+log_file=$logdir"/"`client-log-file-name`
74b1de
+nofdlog=$(cat $log_file | grep " D " | wc -l)
74b1de
+TEST [ $((nofdlog)) -eq 0 ]
74b1de
+
74b1de
+brick_log_file=$logdir"/bricks/"`brick-log-file-name`
74b1de
+nofdlog=$(cat $brick_log_file | grep " D " | wc -l)
74b1de
+TEST [ $((nofdlog)) -eq 0 ]
74b1de
+
74b1de
+## Set brick-log-level to DEBUG
74b1de
+TEST $CLI volume set $V0 diagnostics.brick-log-level DEBUG
74b1de
+
74b1de
+# Do some operation
74b1de
+touch $M0/file1
74b1de
+
74b1de
+# Check debug message debug message should be exist only for V0
74b1de
+# Server xlator is common in brick_mux so after enabling DEBUG log
74b1de
+# some debug message should be available for other xlators like posix
74b1de
+
74b1de
+brick_log_file=$logdir"/bricks/"`brick-log-file-name`
74b1de
+nofdlog=$(cat $brick_log_file | grep file1 | grep -v server | wc -l)
74b1de
+TEST [ $((nofdlog)) -ne 0 ]
74b1de
+
74b1de
+#Check if any debug log exist in client-log file
74b1de
+nofdlog=$(cat $log_file | grep " D " | wc -l)
74b1de
+TEST [ $((nofdlog)) -eq 0 ]
74b1de
+
74b1de
+## Set brick-log-level to INFO
74b1de
+TEST $CLI volume set $V0 diagnostics.brick-log-level INFO
74b1de
+
74b1de
+## Set client-log-level to DEBUG
74b1de
+TEST $CLI volume set $V0 diagnostics.client-log-level DEBUG
74b1de
+
74b1de
+# Do some operation
74b1de
+touch $M0/file2
74b1de
+
74b1de
+nofdlog=$(cat $brick_log_file | grep " D " | grep file2 | wc -l)
74b1de
+TEST [ $((nofdlog)) -eq 0 ]
74b1de
+
74b1de
+nofdlog=$(cat $log_file | grep " D " | wc -l)
74b1de
+TEST [ $((nofdlog)) -ne 0 ]
74b1de
+
74b1de
+# Unmount V0
74b1de
+TEST umount $M0
74b1de
+
74b1de
+#Mount V1
74b1de
+TEST glusterfs --volfile-id=$V1 --volfile-server=$H0 --entry-timeout=0 $M0;
74b1de
+
74b1de
+#do some operation
74b1de
+touch $M0/file3
74b1de
+
74b1de
+
74b1de
+# DEBUG log level is enabled only for V0 so no debug message should be available
74b1de
+# in log specific to file2 creation except for server xlator, server xlator is
74b1de
+# common xlator in brick mulitplex
74b1de
+nofdlog=$(cat $brick_log_file | grep file3 | grep -v server | wc -l)
74b1de
+TEST [ $((nofdlog)) -eq 0 ]
74b1de
+
74b1de
+# Unmount V1
74b1de
+TEST umount $M0
74b1de
+
74b1de
+cleanup;
74b1de
diff --git a/xlators/debug/io-stats/src/io-stats.c b/xlators/debug/io-stats/src/io-stats.c
74b1de
index 41b57c5..aa91a0a 100644
74b1de
--- a/xlators/debug/io-stats/src/io-stats.c
74b1de
+++ b/xlators/debug/io-stats/src/io-stats.c
74b1de
@@ -3704,19 +3704,23 @@ xlator_set_loglevel(xlator_t *this, int log_level)
74b1de
     active = ctx->active;
74b1de
     top = active->first;
74b1de
 
74b1de
-    if (strcmp(top->type, "protocol/server") || (log_level == -1))
74b1de
+    if (log_level == -1)
74b1de
         return;
74b1de
 
74b1de
-    /* Set log-level for server xlator */
74b1de
-    top->loglevel = log_level;
74b1de
+    if (ctx->cmd_args.brick_mux) {
74b1de
+        /* Set log-level for all brick xlators */
74b1de
+        top->loglevel = log_level;
74b1de
 
74b1de
-    /* Set log-level for parent xlator */
74b1de
-    if (this->parents)
74b1de
-        this->parents->xlator->loglevel = log_level;
74b1de
+        /* Set log-level for parent xlator */
74b1de
+        if (this->parents)
74b1de
+            this->parents->xlator->loglevel = log_level;
74b1de
 
74b1de
-    while (trav) {
74b1de
-        trav->loglevel = log_level;
74b1de
-        trav = trav->next;
74b1de
+        while (trav) {
74b1de
+            trav->loglevel = log_level;
74b1de
+            trav = trav->next;
74b1de
+        }
74b1de
+    } else {
74b1de
+        gf_log_set_loglevel(this->ctx, log_level);
74b1de
     }
74b1de
 }
74b1de
 
74b1de
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
74b1de
index 2dd5f91..fdd7d91 100644
74b1de
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
74b1de
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
74b1de
@@ -2240,6 +2240,9 @@ retry:
74b1de
     if (volinfo->memory_accounting)
74b1de
         runner_add_arg(&runner, "--mem-accounting");
74b1de
 
74b1de
+    if (is_brick_mx_enabled())
74b1de
+        runner_add_arg(&runner, "--brick-mux");
74b1de
+
74b1de
     runner_log(&runner, "", 0, "Starting GlusterFS");
74b1de
 
74b1de
     brickinfo->port = port;
74b1de
@@ -2378,6 +2381,10 @@ unsafe_option(dict_t *this, char *key, data_t *value, void *arg)
74b1de
         return _gf_false;
74b1de
     }
74b1de
 
74b1de
+    if (fnmatch("*diagnostics.client-log*", key, 0) == 0) {
74b1de
+        return _gf_false;
74b1de
+    }
74b1de
+
74b1de
     return _gf_true;
74b1de
 }
74b1de
 
74b1de
-- 
74b1de
1.8.3.1
74b1de