From 804ce8e7b26dbf84a6f788627ee6d80fe6e10188 Mon Sep 17 00:00:00 2001 From: Vijay Bellur Date: Fri, 19 May 2017 13:48:47 +0530 Subject: gluster-blockd: use SO_REUSEADDR on bind Currently immediate restarts of gluster-blockd failsi with: [1495181620] ERROR: bind on port 24006 failed (Address already in use) Since the closed socket connection is still in TIME_WAIT on 24006 This patch sets socket option SO_REUSEADDR, which allows gluster-blockd to bind even if socket is in a TIME_WAIT state. Change-Id: I4e6b3c5d3930e6fca222b11c34b35f883d9be730 Signed-off-by: Vijay Bellur Signed-off-by: Prasanna Kumar Kalever --- daemon/gluster-blockd.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/daemon/gluster-blockd.c b/daemon/gluster-blockd.c index 54329bc..3c38798 100644 --- a/daemon/gluster-blockd.c +++ b/daemon/gluster-blockd.c @@ -119,6 +119,7 @@ glusterBlockServerThreadProc(void *vargp) register SVCXPRT *transp = NULL; struct sockaddr_in sain = {0, }; int sockfd; + int opt = 1; if ((sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { @@ -127,6 +128,12 @@ glusterBlockServerThreadProc(void *vargp) goto out; } + if (setsockopt (sockfd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof (opt)) < 0) { + LOG("mgmt", GB_LOG_ERROR, + "setsockopt() for SO_REUSEADDR failed (%s)", strerror (errno)); + goto out; + } + sain.sin_family = AF_INET; sain.sin_addr.s_addr = INADDR_ANY; sain.sin_port = htons(GB_TCP_PORT); -- cgit