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