21ab4e
From b78e56b839cb48bd923e07f286977e1b09fd6609 Mon Sep 17 00:00:00 2001
21ab4e
From: Mohammed Rafi KC <rkavunga@redhat.com>
21ab4e
Date: Tue, 13 Jun 2017 12:58:31 +0530
21ab4e
Subject: [PATCH 507/509] protocol/server: make listen backlog value as
21ab4e
 configurable
21ab4e
21ab4e
problem:
21ab4e
21ab4e
When we call listen from protocol/server, we are giving a
21ab4e
hard coded valie of 10 if it is not manually given.
21ab4e
With multiplexing, especially when glusterd restarts all
21ab4e
clients may try to connect to the server at a time.
21ab4e
Which will result in overflowing the queue, and kernel
21ab4e
will complain about the errors.
21ab4e
21ab4e
Solution:
21ab4e
21ab4e
This patch will introduce a volume set command to make backlog
21ab4e
value as a configurable. This patch also changes the default
21ab4e
values for backlog from 10 to 128. This changes is only applicable
21ab4e
for sockets listening from protocol.
21ab4e
21ab4e
Example:
21ab4e
21ab4e
gluster volume set <volname> transport.listen-backlog 1024
21ab4e
21ab4e
Note: 1 Brick has to be restarted to get this value in effect
21ab4e
      2 This changes won't be reflected in glusterd, or other
21ab4e
        xlators which calls listen. If you need, you have to
21ab4e
        add this option to the volfile.
21ab4e
21ab4e
Backport of>
21ab4e
>Change-Id: I0c5a2bbf28b5db612f9979e7560e05dd82b41477
21ab4e
>BUG: 1456405
21ab4e
>Signed-off-by: Mohammed Rafi KC <rkavunga@redhat.com>
21ab4e
>Reviewed-on: https://review.gluster.org/17411
21ab4e
>Smoke: Gluster Build System <jenkins@build.gluster.org>
21ab4e
>NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
21ab4e
>CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
21ab4e
>Reviewed-by: Raghavendra G <rgowdapp@redhat.com>
21ab4e
>Reviewed-by: Raghavendra Talur <rtalur@redhat.com>
21ab4e
>Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
21ab4e
>Reviewed-by: Niels de Vos <ndevos@redhat.com>
21ab4e
>Reviewed-by: Jeff Darcy <jeff@pl.atyp.us>
21ab4e
21ab4e
Change-Id: I0c5a2bbf28b5db612f9979e7560e05dd82b41477
21ab4e
BUG: 1453145
21ab4e
Signed-off-by: Mohammed Rafi KC <rkavunga@redhat.com>
21ab4e
Reviewed-on: https://code.engineering.redhat.com/gerrit/108900
21ab4e
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
21ab4e
---
21ab4e
 libglusterfs/src/globals.h                      |  2 +
21ab4e
 libglusterfs/src/glusterfs.h                    |  1 +
21ab4e
 rpc/rpc-transport/rdma/src/rdma.c               | 32 +++++++++++++-
21ab4e
 rpc/rpc-transport/rdma/src/rdma.h               |  2 +
21ab4e
 rpc/rpc-transport/socket/src/socket.c           | 25 ++++++-----
21ab4e
 tests/basic/multiplex.t                         |  3 ++
21ab4e
 xlators/mgmt/glusterd/src/glusterd-messages.h   | 10 ++++-
21ab4e
 xlators/mgmt/glusterd/src/glusterd-volume-set.c | 56 +++++++++++++++++++++++++
21ab4e
 xlators/mgmt/glusterd/src/glusterd.c            |  8 ++--
21ab4e
 xlators/mgmt/glusterd/src/glusterd.h            |  1 -
21ab4e
 xlators/protocol/server/src/server.c            |  4 ++
21ab4e
 11 files changed, 126 insertions(+), 18 deletions(-)
21ab4e
21ab4e
diff --git a/libglusterfs/src/globals.h b/libglusterfs/src/globals.h
21ab4e
index 08031a7..c7a5c16 100644
21ab4e
--- a/libglusterfs/src/globals.h
21ab4e
+++ b/libglusterfs/src/globals.h
21ab4e
@@ -91,6 +91,8 @@
21ab4e
 
21ab4e
 #define GD_OP_VERSION_3_11_0   31100 /* Op-version for GlusterFS 3.11.0 */
21ab4e
 
21ab4e
+#define GD_OP_VERSION_3_11_1   31101 /* Op-version for GlusterFS 3.11.1 */
21ab4e
+
21ab4e
 #include "xlator.h"
21ab4e
 
21ab4e
 /* THIS */
21ab4e
diff --git a/libglusterfs/src/glusterfs.h b/libglusterfs/src/glusterfs.h
21ab4e
index 3544aab..86519b0 100644
21ab4e
--- a/libglusterfs/src/glusterfs.h
21ab4e
+++ b/libglusterfs/src/glusterfs.h
21ab4e
@@ -71,6 +71,7 @@
21ab4e
 #endif
21ab4e
 
21ab4e
 #define GLUSTERD_MAX_SNAP_NAME  255
21ab4e
+#define GLUSTERFS_SOCKET_LISTEN_BACKLOG  10
21ab4e
 #define ZR_MOUNTPOINT_OPT       "mountpoint"
21ab4e
 #define ZR_ATTR_TIMEOUT_OPT     "attribute-timeout"
21ab4e
 #define ZR_ENTRY_TIMEOUT_OPT    "entry-timeout"
21ab4e
diff --git a/rpc/rpc-transport/rdma/src/rdma.c b/rpc/rpc-transport/rdma/src/rdma.c
21ab4e
index d2f04bd..4a55cce 100644
21ab4e
--- a/rpc/rpc-transport/rdma/src/rdma.c
21ab4e
+++ b/rpc/rpc-transport/rdma/src/rdma.c
21ab4e
@@ -4498,6 +4498,12 @@ gf_rdma_options_init (rpc_transport_t *this)
21ab4e
         options->attr_retry_cnt = GF_RDMA_RETRY_CNT;
21ab4e
         options->attr_rnr_retry = GF_RDMA_RNR_RETRY;
21ab4e
 
21ab4e
+        temp = dict_get (this->options, "transport.listen-backlog");
21ab4e
+        if (temp)
21ab4e
+                options->backlog = data_to_uint32 (temp);
21ab4e
+        else
21ab4e
+                options->backlog = GLUSTERFS_SOCKET_LISTEN_BACKLOG;
21ab4e
+
21ab4e
         temp = dict_get (this->options,
21ab4e
                          "transport.rdma.work-request-send-count");
21ab4e
         if (temp)
21ab4e
@@ -4634,6 +4640,7 @@ gf_rdma_init (rpc_transport_t *this)
21ab4e
         priv->peer.recv_count = options->recv_count;
21ab4e
         priv->peer.send_size = options->send_size;
21ab4e
         priv->peer.recv_size = options->recv_size;
21ab4e
+        priv->backlog = options->backlog;
21ab4e
 
21ab4e
         priv->peer.trans = this;
21ab4e
         INIT_LIST_HEAD (&priv->peer.ioq);
21ab4e
@@ -4847,7 +4854,8 @@ gf_rdma_listen (rpc_transport_t *this)
21ab4e
                 goto err;
21ab4e
         }
21ab4e
 
21ab4e
-        ret = rdma_listen (peer->cm_id, 10);
21ab4e
+        ret = rdma_listen (peer->cm_id, priv->backlog);
21ab4e
+
21ab4e
         if (ret != 0) {
21ab4e
                 gf_msg (this->name, GF_LOG_WARNING, errno,
21ab4e
                         RDMA_MSG_LISTEN_FAILED,
21ab4e
@@ -4918,6 +4926,28 @@ init (rpc_transport_t *this)
21ab4e
         return 0;
21ab4e
 }
21ab4e
 
21ab4e
+int
21ab4e
+reconfigure (rpc_transport_t *this, dict_t *options)
21ab4e
+{
21ab4e
+        gf_rdma_private_t *priv          = NULL;
21ab4e
+        uint32_t          backlog        = 0;
21ab4e
+        int               ret            = -1;
21ab4e
+
21ab4e
+        GF_VALIDATE_OR_GOTO ("rdma", this, out);
21ab4e
+        GF_VALIDATE_OR_GOTO ("rdma", this->private, out);
21ab4e
+
21ab4e
+        priv = this->private;
21ab4e
+
21ab4e
+        if (dict_get_uint32 (options, "transport.listen-backlog",
21ab4e
+                             &backlog) == 0) {
21ab4e
+                priv->backlog = backlog;
21ab4e
+                gf_log (this->name, GF_LOG_DEBUG, "Reconfigued "
21ab4e
+                        "transport.listen-backlog=%d", priv->backlog);
21ab4e
+        }
21ab4e
+        ret = 0;
21ab4e
+out:
21ab4e
+        return ret;
21ab4e
+}
21ab4e
 void
21ab4e
 fini (struct rpc_transport *this)
21ab4e
 {
21ab4e
diff --git a/rpc/rpc-transport/rdma/src/rdma.h b/rpc/rpc-transport/rdma/src/rdma.h
21ab4e
index 449861f..6bcf6bc 100644
21ab4e
--- a/rpc/rpc-transport/rdma/src/rdma.h
21ab4e
+++ b/rpc/rpc-transport/rdma/src/rdma.h
21ab4e
@@ -144,6 +144,7 @@ struct __gf_rdma_options {
21ab4e
 	uint8_t  attr_timeout;
21ab4e
 	uint8_t  attr_retry_cnt;
21ab4e
 	uint8_t  attr_rnr_retry;
21ab4e
+        uint32_t backlog;
21ab4e
 };
21ab4e
 typedef struct __gf_rdma_options gf_rdma_options_t;
21ab4e
 
21ab4e
@@ -383,6 +384,7 @@ struct __gf_rdma_private {
21ab4e
         pthread_mutex_t             recv_mutex;
21ab4e
         pthread_cond_t              recv_cond;
21ab4e
         gf_rdma_transport_entity_t  entity;
21ab4e
+        uint32_t                    backlog;
21ab4e
 };
21ab4e
 typedef struct __gf_rdma_private    gf_rdma_private_t;
21ab4e
 
21ab4e
diff --git a/rpc/rpc-transport/socket/src/socket.c b/rpc/rpc-transport/socket/src/socket.c
21ab4e
index 16cba78..4560d2f 100644
21ab4e
--- a/rpc/rpc-transport/socket/src/socket.c
21ab4e
+++ b/rpc/rpc-transport/socket/src/socket.c
21ab4e
@@ -3524,10 +3524,7 @@ socket_listen (rpc_transport_t *this)
21ab4e
                         goto unlock;
21ab4e
                 }
21ab4e
 
21ab4e
-                if (priv->backlog)
21ab4e
-                        ret = listen (priv->sock, priv->backlog);
21ab4e
-                else
21ab4e
-                        ret = listen (priv->sock, 10);
21ab4e
+                ret = listen (priv->sock, priv->backlog);
21ab4e
 
21ab4e
                 if (ret == -1) {
21ab4e
                         gf_log (this->name, GF_LOG_ERROR,
21ab4e
@@ -3843,6 +3840,7 @@ reconfigure (rpc_transport_t *this, dict_t *options)
21ab4e
         int               ret           = 0;
21ab4e
         uint64_t          windowsize    = 0;
21ab4e
         uint32_t          timeout       = 0;
21ab4e
+        uint32_t          backlog       = 0;
21ab4e
 
21ab4e
         GF_VALIDATE_OR_GOTO ("socket", this, out);
21ab4e
         GF_VALIDATE_OR_GOTO ("socket", this->private, out);
21ab4e
@@ -3878,6 +3876,13 @@ reconfigure (rpc_transport_t *this, dict_t *options)
21ab4e
                         "transport.tcp-user-timeout=%d", timeout);
21ab4e
         }
21ab4e
 
21ab4e
+        if (dict_get_uint32 (options, "transport.listen-backlog",
21ab4e
+                             &backlog) == 0) {
21ab4e
+                priv->backlog = backlog;
21ab4e
+                gf_log (this->name, GF_LOG_DEBUG, "Reconfigued "
21ab4e
+                        "transport.listen-backlog=%d", priv->backlog);
21ab4e
+        }
21ab4e
+
21ab4e
         optstr = NULL;
21ab4e
         if (dict_get_str (options, "tcp-window-size", &optstr) == 0) {
21ab4e
                 if (gf_string2uint64 (optstr, &windowsize) != 0) {
21ab4e
@@ -4144,14 +4149,17 @@ socket_init (rpc_transport_t *this)
21ab4e
                              &timeout) == 0) {
21ab4e
                 priv->timeout = timeout;
21ab4e
         }
21ab4e
+
21ab4e
         gf_log (this->name, GF_LOG_DEBUG, "Configued "
21ab4e
                 "transport.tcp-user-timeout=%d", priv->timeout);
21ab4e
 
21ab4e
         if (dict_get_uint32 (this->options,
21ab4e
-                             "transport.socket.listen-backlog",
21ab4e
-                             &backlog) == 0) {
21ab4e
-                priv->backlog = backlog;
21ab4e
+                             "transport.listen-backlog",
21ab4e
+                             &backlog) != 0) {
21ab4e
+
21ab4e
+                backlog = GLUSTERFS_SOCKET_LISTEN_BACKLOG;
21ab4e
         }
21ab4e
+        priv->backlog = backlog;
21ab4e
 
21ab4e
         optstr = NULL;
21ab4e
 
21ab4e
@@ -4561,9 +4569,6 @@ struct volume_options options[] = {
21ab4e
         { .key   = {"transport.socket.keepalive-time"},
21ab4e
           .type  = GF_OPTION_TYPE_INT
21ab4e
         },
21ab4e
-        { .key   = {"transport.socket.listen-backlog"},
21ab4e
-          .type  = GF_OPTION_TYPE_INT
21ab4e
-        },
21ab4e
         { .key   = {"transport.socket.read-fail-log"},
21ab4e
           .type  = GF_OPTION_TYPE_BOOL
21ab4e
         },
21ab4e
diff --git a/tests/basic/multiplex.t b/tests/basic/multiplex.t
21ab4e
index 819ff40..b69fe57 100644
21ab4e
--- a/tests/basic/multiplex.t
21ab4e
+++ b/tests/basic/multiplex.t
21ab4e
@@ -27,6 +27,9 @@ EXPECT_WITHIN $PROCESS_UP_TIMEOUT 2 count_up_bricks
21ab4e
 EXPECT 1 online_brick_count
21ab4e
 
21ab4e
 TEST $CLI volume stop $V0
21ab4e
+#Testing the volume set command introduced for protocol/server
21ab4e
+TEST $CLI volume set $V0 transport.listen-backlog 1024
21ab4e
+
21ab4e
 EXPECT_WITHIN $PROCESS_DOWN_TIMEOUT 0 online_brick_count
21ab4e
 TEST $CLI volume start $V0
21ab4e
 EXPECT_WITHIN $PROCESS_UP_TIMEOUT 2 count_up_bricks
21ab4e
diff --git a/xlators/mgmt/glusterd/src/glusterd-messages.h b/xlators/mgmt/glusterd/src/glusterd-messages.h
21ab4e
index 3d0f48c..58208ec 100644
21ab4e
--- a/xlators/mgmt/glusterd/src/glusterd-messages.h
21ab4e
+++ b/xlators/mgmt/glusterd/src/glusterd-messages.h
21ab4e
@@ -41,7 +41,7 @@
21ab4e
 
21ab4e
 #define GLUSTERD_COMP_BASE      GLFS_MSGID_GLUSTERD
21ab4e
 
21ab4e
-#define GLFS_NUM_MESSAGES       601
21ab4e
+#define GLFS_NUM_MESSAGES       602
21ab4e
 
21ab4e
 #define GLFS_MSGID_END          (GLUSTERD_COMP_BASE + GLFS_NUM_MESSAGES + 1)
21ab4e
 /* Messaged with message IDs */
21ab4e
@@ -4809,6 +4809,14 @@
21ab4e
  */
21ab4e
 #define GD_MSG_PIDFILE_UNLINKING                   (GLUSTERD_COMP_BASE + 601)
21ab4e
 
21ab4e
+/*!
21ab4e
+ * @messageid
21ab4e
+ * @diagnosis
21ab4e
+ * @recommendedaction
21ab4e
+ *
21ab4e
+ */
21ab4e
+#define GD_MSG_VOL_SET_VALIDATION_INFO             (GLUSTERD_COMP_BASE + 602)
21ab4e
+
21ab4e
 /*------------*/
21ab4e
 
21ab4e
 #define glfs_msg_end_x GLFS_MSGID_END, "Invalid: End of messages"
21ab4e
diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-set.c b/xlators/mgmt/glusterd/src/glusterd-volume-set.c
21ab4e
index d5fa23b..de4cfb7 100644
21ab4e
--- a/xlators/mgmt/glusterd/src/glusterd-volume-set.c
21ab4e
+++ b/xlators/mgmt/glusterd/src/glusterd-volume-set.c
21ab4e
@@ -707,6 +707,52 @@ out:
21ab4e
 }
21ab4e
 
21ab4e
 static int
21ab4e
+validate_server_options (glusterd_volinfo_t *volinfo, dict_t *dict, char *key,
21ab4e
+                         char *value, char **op_errstr)
21ab4e
+{
21ab4e
+        char                 errstr[2048]  = "";
21ab4e
+        xlator_t            *this          = NULL;
21ab4e
+        int                  ret           = -1;
21ab4e
+        int                  origin_val    = 0;
21ab4e
+
21ab4e
+        this = THIS;
21ab4e
+        GF_ASSERT (this);
21ab4e
+
21ab4e
+        if (volinfo->status == GLUSTERD_STATUS_STARTED) {
21ab4e
+                gf_msg (this->name, GF_LOG_INFO, 0,
21ab4e
+                        GD_MSG_VOL_SET_VALIDATION_INFO, "Please note that "
21ab4e
+                        "volume %s is started. This option will only get "
21ab4e
+                        "effected after a brick restart.", volinfo->volname);
21ab4e
+        }
21ab4e
+
21ab4e
+        ret = gf_string2int (value, &origin_val);
21ab4e
+        if (ret) {
21ab4e
+                snprintf (errstr, sizeof (errstr), "%s is not a compatible "
21ab4e
+                          "value. %s expects an integer value.", value, key);
21ab4e
+                ret = -1;
21ab4e
+                goto out;
21ab4e
+        }
21ab4e
+
21ab4e
+        if (origin_val < 0) {
21ab4e
+                snprintf (errstr, sizeof (errstr), "%s is not a "
21ab4e
+                          "compatible value. %s expects a positive"
21ab4e
+                          "integer value.", value, key);
21ab4e
+                ret = -1;
21ab4e
+                goto out;
21ab4e
+        }
21ab4e
+
21ab4e
+        ret = 0;
21ab4e
+out:
21ab4e
+        if (ret) {
21ab4e
+                gf_msg (this->name, GF_LOG_ERROR, EINVAL,
21ab4e
+                        GD_MSG_INCOMPATIBLE_VALUE, "%s", errstr);
21ab4e
+                *op_errstr = gf_strdup (errstr);
21ab4e
+        }
21ab4e
+
21ab4e
+        return ret;
21ab4e
+}
21ab4e
+
21ab4e
+static int
21ab4e
 validate_stripe (glusterd_volinfo_t *volinfo, dict_t *dict, char *key,
21ab4e
                  char *value, char **op_errstr)
21ab4e
 {
21ab4e
@@ -1919,6 +1965,16 @@ struct volopt_map_entry glusterd_volopt_map[] = {
21ab4e
           .op_version  = GD_OP_VERSION_3_7_4,
21ab4e
           .type        = NO_DOC,
21ab4e
         },
21ab4e
+        { .key         = "transport.listen-backlog",
21ab4e
+          .voltype     = "protocol/server",
21ab4e
+          .option      = "transport.listen-backlog",
21ab4e
+          .op_version  = GD_OP_VERSION_3_11_1,
21ab4e
+          .validate_fn = validate_server_options,
21ab4e
+          .description = "This option uses the value of backlog argument that "
21ab4e
+                         "defines the maximum length to which the queue of "
21ab4e
+                         "pending connections for socket fd may grow.",
21ab4e
+          .value       = "10",
21ab4e
+        },
21ab4e
 
21ab4e
         /* Performance xlators enable/disbable options */
21ab4e
         { .key         = "performance.write-behind",
21ab4e
diff --git a/xlators/mgmt/glusterd/src/glusterd.c b/xlators/mgmt/glusterd/src/glusterd.c
21ab4e
index f718d36..e49b186 100644
21ab4e
--- a/xlators/mgmt/glusterd/src/glusterd.c
21ab4e
+++ b/xlators/mgmt/glusterd/src/glusterd.c
21ab4e
@@ -461,14 +461,12 @@ glusterd_rpcsvc_options_build (dict_t *options)
21ab4e
         int             ret = 0;
21ab4e
         uint32_t        backlog = 0;
21ab4e
 
21ab4e
-        ret = dict_get_uint32 (options, "transport.socket.listen-backlog",
21ab4e
-                               &backlog);
21ab4e
+        ret = dict_get_uint32 (options, "transport.listen-backlog", &backlog);
21ab4e
 
21ab4e
         if (ret) {
21ab4e
-                backlog = GLUSTERD_SOCKET_LISTEN_BACKLOG;
21ab4e
+                backlog = GLUSTERFS_SOCKET_LISTEN_BACKLOG;
21ab4e
                 ret = dict_set_uint32 (options,
21ab4e
-                                      "transport.socket.listen-backlog",
21ab4e
-                                      backlog);
21ab4e
+                                      "transport.listen-backlog", backlog);
21ab4e
                 if (ret)
21ab4e
                         goto out;
21ab4e
         }
21ab4e
diff --git a/xlators/mgmt/glusterd/src/glusterd.h b/xlators/mgmt/glusterd/src/glusterd.h
21ab4e
index b5a0a3b..7b40196 100644
21ab4e
--- a/xlators/mgmt/glusterd/src/glusterd.h
21ab4e
+++ b/xlators/mgmt/glusterd/src/glusterd.h
21ab4e
@@ -39,7 +39,6 @@
21ab4e
 #include "events.h"
21ab4e
 
21ab4e
 #define GLUSTERD_TR_LOG_SIZE            50
21ab4e
-#define GLUSTERD_SOCKET_LISTEN_BACKLOG  128
21ab4e
 #define GLUSTERD_QUORUM_TYPE_KEY        "cluster.server-quorum-type"
21ab4e
 #define GLUSTERD_QUORUM_RATIO_KEY       "cluster.server-quorum-ratio"
21ab4e
 #define GLUSTERD_GLOBAL_OPT_VERSION     "global-option-version"
21ab4e
diff --git a/xlators/protocol/server/src/server.c b/xlators/protocol/server/src/server.c
21ab4e
index 6acf256..5d4d860 100644
21ab4e
--- a/xlators/protocol/server/src/server.c
21ab4e
+++ b/xlators/protocol/server/src/server.c
21ab4e
@@ -1622,6 +1622,10 @@ struct volume_options options[] = {
21ab4e
                     "socket*([ \t]),*([ \t])rdma"},
21ab4e
           .type  = GF_OPTION_TYPE_STR
21ab4e
         },
21ab4e
+        { .key   = {"transport.listen-backlog"},
21ab4e
+          .type  = GF_OPTION_TYPE_INT,
21ab4e
+          .default_value = "10",
21ab4e
+        },
21ab4e
         { .key   = {"volume-filename.*"},
21ab4e
           .type  = GF_OPTION_TYPE_PATH,
21ab4e
         },
21ab4e
-- 
21ab4e
1.8.3.1
21ab4e