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