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