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