f338ef
From b1a4947e382c5e2ba1137ed606ecffc69fcf00e9 Mon Sep 17 00:00:00 2001
f338ef
From: Mohit Agrawal <moagrawa@redhat.com>
f338ef
Date: Tue, 25 Jun 2019 17:30:17 +0530
f338ef
Subject: [PATCH 205/221] glusterd: Can't run rebalance due to long unix socket
f338ef
f338ef
Problem: glusterd populate unix socket file name based
f338ef
         on volname and if volname is lengthy socket
f338ef
         system call's are failed due to breach maximum length
f338ef
         is defined in the kernel.
f338ef
f338ef
Solution:Convert unix socket name to hash to resolve the issue
f338ef
f338ef
> Change-Id: I5072e8184013095587537dbfa4767286307fff65
f338ef
> fixes: bz#1720566
f338ef
> (Cherry pick from commit 2d7b77eb971700c1073db2b74f5877c1ae8293fc)
f338ef
> (Reviewed on upstream link https://review.gluster.org/#/c/glusterfs/+/22869/)
f338ef
f338ef
BUG: 1720192
f338ef
Change-Id: I5072e8184013095587537dbfa4767286307fff65
f338ef
Signed-off-by: Mohit Agrawal <moagrawa@redhat.com>
f338ef
Reviewed-on: https://code.engineering.redhat.com/gerrit/174557
f338ef
Tested-by: RHGS Build Bot <nigelb@redhat.com>
f338ef
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
f338ef
---
f338ef
 tests/bugs/glusterd/bug-1720566.t              | 50 ++++++++++++++++++++++++++
f338ef
 xlators/mgmt/glusterd/src/glusterd-rebalance.c | 38 +-------------------
f338ef
 xlators/mgmt/glusterd/src/glusterd.h           | 23 +++++-------
f338ef
 3 files changed, 59 insertions(+), 52 deletions(-)
f338ef
 create mode 100644 tests/bugs/glusterd/bug-1720566.t
f338ef
f338ef
diff --git a/tests/bugs/glusterd/bug-1720566.t b/tests/bugs/glusterd/bug-1720566.t
f338ef
new file mode 100644
f338ef
index 0000000..99bcf6f
f338ef
--- /dev/null
f338ef
+++ b/tests/bugs/glusterd/bug-1720566.t
f338ef
@@ -0,0 +1,50 @@
f338ef
+#!/bin/bash
f338ef
+
f338ef
+. $(dirname $0)/../../include.rc
f338ef
+. $(dirname $0)/../../cluster.rc
f338ef
+. $(dirname $0)/../../volume.rc
f338ef
+
f338ef
+
f338ef
+cleanup;
f338ef
+V0="TestLongVolnamec363b7b536700ff06eedeae0dd9037fec363b7b536700ff06eedeae0dd9037fec363b7b536700ff06eedeae0dd9abcd"
f338ef
+V1="TestLongVolname3102bd28a16c49440bd5210e4ec4d5d93102bd28a16c49440bd5210e4ec4d5d933102bd28a16c49440bd5210e4ebbcd"
f338ef
+TEST launch_cluster 2;
f338ef
+TEST $CLI_1 peer probe $H2;
f338ef
+
f338ef
+EXPECT_WITHIN $PROBE_TIMEOUT 1 peer_count
f338ef
+
f338ef
+$CLI_1 volume create $V0 $H1:$B1/$V0  $H2:$B2/$V0
f338ef
+EXPECT 'Created' cluster_volinfo_field 1 $V0 'Status';
f338ef
+$CLI_1 volume create $V1 $H1:$B1/$V1  $H2:$B2/$V1
f338ef
+EXPECT 'Created' cluster_volinfo_field 1 $V1 'Status';
f338ef
+
f338ef
+$CLI_1 volume start $V0
f338ef
+EXPECT 'Started' cluster_volinfo_field 1 $V0 'Status';
f338ef
+
f338ef
+$CLI_1 volume start $V1
f338ef
+EXPECT 'Started' cluster_volinfo_field 1 $V1 'Status';
f338ef
+
f338ef
+#Mount FUSE
f338ef
+TEST glusterfs -s $H1 --volfile-id=$V0 $M0;
f338ef
+
f338ef
+
f338ef
+#Mount FUSE
f338ef
+TEST glusterfs -s $H1 --volfile-id=$V1 $M1;
f338ef
+
f338ef
+TEST mkdir $M0/dir{1..4};
f338ef
+TEST touch $M0/dir{1..4}/files{1..4};
f338ef
+
f338ef
+TEST mkdir $M1/dir{1..4};
f338ef
+TEST touch $M1/dir{1..4}/files{1..4};
f338ef
+
f338ef
+TEST $CLI_1 volume add-brick $V0 $H1:$B1/${V0}_1 $H2:$B2/${V0}_1
f338ef
+TEST $CLI_1 volume add-brick $V1 $H1:$B1/${V1}_1 $H2:$B2/${V1}_1
f338ef
+
f338ef
+
f338ef
+TEST $CLI_1 volume rebalance $V0 start
f338ef
+TEST $CLI_1 volume rebalance $V1  start
f338ef
+
f338ef
+EXPECT_WITHIN $REBALANCE_TIMEOUT "completed" cluster_rebalance_status_field 1 $V0
f338ef
+EXPECT_WITHIN $REBALANCE_TIMEOUT "completed" cluster_rebalance_status_field 1  $V1
f338ef
+
f338ef
+cleanup;
f338ef
diff --git a/xlators/mgmt/glusterd/src/glusterd-rebalance.c b/xlators/mgmt/glusterd/src/glusterd-rebalance.c
f338ef
index cbed9a9..b419a89 100644
f338ef
--- a/xlators/mgmt/glusterd/src/glusterd-rebalance.c
f338ef
+++ b/xlators/mgmt/glusterd/src/glusterd-rebalance.c
f338ef
@@ -266,18 +266,7 @@ glusterd_handle_defrag_start(glusterd_volinfo_t *volinfo, char *op_errstr,
f338ef
 
f338ef
     if (dict_get_strn(this->options, "transport.socket.bind-address",
f338ef
                       SLEN("transport.socket.bind-address"),
f338ef
-                      &volfileserver) == 0) {
f338ef
-        /*In the case of running multiple glusterds on a single machine,
f338ef
-         *we should ensure that log file and unix socket file should be
f338ef
-         *unique in given cluster */
f338ef
-
f338ef
-        GLUSTERD_GET_DEFRAG_SOCK_FILE_OLD(sockfile, volinfo, priv);
f338ef
-        snprintf(logfile, PATH_MAX, "%s/%s-%s-%s.log",
f338ef
-                 DEFAULT_LOG_FILE_DIRECTORY, volinfo->volname,
f338ef
-                 (cmd == GF_DEFRAG_CMD_START_TIER ? "tier" : "rebalance"),
f338ef
-                 uuid_utoa(MY_UUID));
f338ef
-
f338ef
-    } else {
f338ef
+                      &volfileserver) != 0) {
f338ef
         volfileserver = "localhost";
f338ef
     }
f338ef
 
f338ef
@@ -378,9 +367,6 @@ glusterd_rebalance_rpc_create(glusterd_volinfo_t *volinfo)
f338ef
     glusterd_defrag_info_t *defrag = volinfo->rebal.defrag;
f338ef
     glusterd_conf_t *priv = NULL;
f338ef
     xlator_t *this = NULL;
f338ef
-    struct stat buf = {
f338ef
-        0,
f338ef
-    };
f338ef
 
f338ef
     this = THIS;
f338ef
     GF_ASSERT(this);
f338ef
@@ -396,28 +382,6 @@ glusterd_rebalance_rpc_create(glusterd_volinfo_t *volinfo)
f338ef
         goto out;
f338ef
 
f338ef
     GLUSTERD_GET_DEFRAG_SOCK_FILE(sockfile, volinfo);
f338ef
-    /* Check if defrag sockfile exists in the new location
f338ef
-     * in /var/run/ , if it does not try the old location
f338ef
-     */
f338ef
-    ret = sys_stat(sockfile, &buf;;
f338ef
-    /* TODO: Remove this once we don't need backward compatibility
f338ef
-     * with the older path
f338ef
-     */
f338ef
-    if (ret && (errno == ENOENT)) {
f338ef
-        gf_msg(this->name, GF_LOG_WARNING, errno, GD_MSG_FILE_OP_FAILED,
f338ef
-               "Rebalance sockfile "
f338ef
-               "%s does not exist. Trying old path.",
f338ef
-               sockfile);
f338ef
-        GLUSTERD_GET_DEFRAG_SOCK_FILE_OLD(sockfile, volinfo, priv);
f338ef
-        ret = sys_stat(sockfile, &buf;;
f338ef
-        if (ret && (ENOENT == errno)) {
f338ef
-            gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_REBAL_NO_SOCK_FILE,
f338ef
-                   "Rebalance "
f338ef
-                   "sockfile %s does not exist",
f338ef
-                   sockfile);
f338ef
-            goto out;
f338ef
-        }
f338ef
-    }
f338ef
 
f338ef
     /* Setting frame-timeout to 10mins (600seconds).
f338ef
      * Unix domain sockets ensures that the connection is reliable. The
f338ef
diff --git a/xlators/mgmt/glusterd/src/glusterd.h b/xlators/mgmt/glusterd/src/glusterd.h
f338ef
index f96bca3..7d07d33 100644
f338ef
--- a/xlators/mgmt/glusterd/src/glusterd.h
f338ef
+++ b/xlators/mgmt/glusterd/src/glusterd.h
f338ef
@@ -910,30 +910,23 @@ typedef ssize_t (*gd_serialize_t)(struct iovec outmsg, void *args);
f338ef
         }                                                                      \
f338ef
     } while (0)
f338ef
 
f338ef
-#define GLUSTERD_GET_DEFRAG_SOCK_FILE_OLD(path, volinfo, priv)                 \
f338ef
-    do {                                                                       \
f338ef
-        char defrag_path[PATH_MAX];                                            \
f338ef
-        int32_t _sockfile_old_len;                                             \
f338ef
-        GLUSTERD_GET_DEFRAG_DIR(defrag_path, volinfo, priv);                   \
f338ef
-        _sockfile_old_len = snprintf(path, PATH_MAX, "%s/%s.sock",             \
f338ef
-                                     defrag_path, uuid_utoa(MY_UUID));         \
f338ef
-        if ((_sockfile_old_len < 0) || (_sockfile_old_len >= PATH_MAX)) {      \
f338ef
-            path[0] = 0;                                                       \
f338ef
-        }                                                                      \
f338ef
-    } while (0)
f338ef
-
f338ef
 #define GLUSTERD_GET_DEFRAG_SOCK_FILE(path, volinfo)                           \
f338ef
     do {                                                                       \
f338ef
         char operation[NAME_MAX];                                              \
f338ef
+        char tmppath[PATH_MAX] = {                                             \
f338ef
+            0,                                                                 \
f338ef
+        };                                                                     \
f338ef
         int32_t _defrag_sockfile_len;                                          \
f338ef
         GLUSTERD_GET_DEFRAG_PROCESS(operation, volinfo);                       \
f338ef
         _defrag_sockfile_len = snprintf(                                       \
f338ef
-            path, UNIX_PATH_MAX,                                               \
f338ef
-            DEFAULT_VAR_RUN_DIRECTORY "/gluster-%s-%s.sock", operation,        \
f338ef
-            uuid_utoa(volinfo->volume_id));                                    \
f338ef
+            tmppath, PATH_MAX,                                                 \
f338ef
+            DEFAULT_VAR_RUN_DIRECTORY "/gluster-%s-%s-%s.sock", operation,     \
f338ef
+            volinfo->volname, uuid_utoa(MY_UUID));                             \
f338ef
         if ((_defrag_sockfile_len < 0) ||                                      \
f338ef
             (_defrag_sockfile_len >= PATH_MAX)) {                              \
f338ef
             path[0] = 0;                                                       \
f338ef
+        } else {                                                               \
f338ef
+            glusterd_set_socket_filepath(tmppath, path, sizeof(path));         \
f338ef
         }                                                                      \
f338ef
     } while (0)
f338ef
 
f338ef
-- 
f338ef
1.8.3.1
f338ef