Patchwork [BUG:1802] support for configuring keepalive idle time

login
register
Submitter Vijay Bellur
Date 2010-10-08 10:24:36
Message ID <20101008102436.GA11381@dev.gluster.com>
Download mbox | patch
Permalink /patch/5355/
State Accepted
Headers show

Comments

Vijay Bellur - 2010-10-08 10:24:36
Signed-off-by: Vijay Bellur <vijay@gluster.com>
---
 doc/glusterd.vol                      |    2 ++
 rpc/rpc-transport/socket/src/socket.c |   21 ++++++++++++++++-----
 rpc/rpc-transport/socket/src/socket.h |    1 +
 3 files changed, 19 insertions(+), 5 deletions(-)

Patch

diff --git a/doc/glusterd.vol b/doc/glusterd.vol
index 48cad95..b96cbe8 100644
--- a/doc/glusterd.vol
+++ b/doc/glusterd.vol
@@ -4,6 +4,8 @@  volume management
     option transport-type socket,rdma
     option transport.socket.listen-port 6969
     option transport.rdma.listen-port 6968
+    option transport.socket.keepalive-time 10
+    option transport.socket.keepalive-interval 2
     # option listen-port 6969
 end-volume
 
diff --git a/rpc/rpc-transport/socket/src/socket.c b/rpc/rpc-transport/socket/src/socket.c
index c524682..341c8e9 100644
--- a/rpc/rpc-transport/socket/src/socket.c
+++ b/rpc/rpc-transport/socket/src/socket.c
@@ -363,7 +363,7 @@  __socket_nodelay (int fd)
 
 
 static int
-__socket_keepalive (int fd, int keepalive_intvl)
+__socket_keepalive (int fd, int keepalive_intvl, int keepalive_idle)
 {
         int     on = 1;
         int     ret = -1;
@@ -381,7 +381,7 @@  __socket_keepalive (int fd, int keepalive_intvl)
         if (ret == -1)
                 goto err;
 #else
-        ret = setsockopt (fd, IPPROTO_TCP, TCP_KEEPIDLE, &keepalive_intvl,
+        ret = setsockopt (fd, IPPROTO_TCP, TCP_KEEPIDLE, &keepalive_idle,
                           sizeof (keepalive_intvl));
         if (ret == -1)
                 goto err;
@@ -394,7 +394,7 @@  __socket_keepalive (int fd, int keepalive_intvl)
 
 done:
         gf_log ("", GF_LOG_TRACE, "Keep-alive enabled for socket %d, interval "
-                "%d", fd, keepalive_intvl);
+                "%d, idle: %d", fd, keepalive_intvl, keepalive_idle);
 
 err:
         return ret;
@@ -1802,7 +1802,8 @@  socket_server_event_handler (int fd, int idx, void *data,
 
                         if (priv->keepalive) {
                                 ret = __socket_keepalive (new_sock,
-                                                          priv->keepaliveintvl);
+                                                          priv->keepaliveintvl,
+                                                          priv->keepaliveidle);
                                 if (ret == -1)
                                         gf_log (this->name, GF_LOG_ERROR,
                                                 "Failed to set keep-alive: %s",
@@ -2010,7 +2011,8 @@  socket_connect (rpc_transport_t *this, int port)
 
                 if (priv->keepalive) {
                         ret = __socket_keepalive (priv->sock,
-                                                  priv->keepaliveintvl);
+                                                  priv->keepaliveintvl,
+                                                  priv->keepaliveidle);
                         if (ret == -1)
                                 gf_log (this->name, GF_LOG_ERROR,
                                         "Failed to set keep-alive: %s",
@@ -2600,6 +2602,12 @@  socket_init (rpc_transport_t *this)
                 priv->keepaliveintvl = keepalive;
         }
 
+        if (dict_get_uint32 (this->options,
+                             "transport.socket.keepalive-time",
+                             &keepalive) == 0) {
+                priv->keepaliveidle = keepalive;
+        }
+
         priv->windowsize = (int)windowsize;
 out:
         this->private = priv;
@@ -2699,5 +2707,8 @@  struct volume_options options[] = {
         { .key   = {"transport.socket.keepalive-interval"},
           .type  = GF_OPTION_TYPE_INT
         },
+        { .key   = {"transport.socket.keepalive-time"},
+          .type  = GF_OPTION_TYPE_INT
+        },
         { .key = {NULL} }
 };
diff --git a/rpc/rpc-transport/socket/src/socket.h b/rpc/rpc-transport/socket/src/socket.h
index f7471ff..f54b64c 100644
--- a/rpc/rpc-transport/socket/src/socket.h
+++ b/rpc/rpc-transport/socket/src/socket.h
@@ -189,6 +189,7 @@  typedef struct {
         char                   lowlat;
         char                   nodelay;
         int                    keepalive;
+        int                    keepaliveidle;
         int                    keepaliveintvl;
 } socket_private_t;