74096c
From 2dad17fdbaab2ab2cda6a05dec9dcd2d37ea32ff Mon Sep 17 00:00:00 2001
74096c
From: Nikhil Ladha <nladha@redhat.com>
74096c
Date: Wed, 10 Feb 2021 15:07:32 +0530
74096c
Subject: [PATCH 532/532] glusterd: fix for starting brick on new port
74096c
74096c
The Errno set by the runner code was not correct when the bind() fails
74096c
to assign an already occupied port in the __socket_server_bind().
74096c
74096c
Fix:
74096c
Updated the code to return the correct errno from the
74096c
__socket_server_bind() if the bind() fails due to EADDRINUSE error. And,
74096c
use the returned errno from runner_run() to retry allocating a new port
74096c
to the brick process.
74096c
74096c
>Fixes: #1101
74096c
74096c
>Change-Id: If124337f41344a04f050754e402490529ef4ecdc
74096c
>Signed-off-by: nik-redhat nladha@redhat.com
74096c
74096c
Upstream patch: https://github.com/gluster/glusterfs/pull/2090
74096c
74096c
BUG: 1865796
74096c
74096c
Change-Id: If124337f41344a04f050754e402490529ef4ecdc
74096c
Signed-off-by: nik-redhat <nladha@redhat.com>
74096c
Reviewed-on: https://code.engineering.redhat.com/gerrit/227261
74096c
Tested-by: RHGS Build Bot <nigelb@redhat.com>
74096c
Reviewed-by: Xavi Hernandez Juan <xhernandez@redhat.com>
74096c
---
74096c
 rpc/rpc-transport/socket/src/socket.c      | 3 +++
74096c
 xlators/mgmt/glusterd/src/glusterd-utils.c | 6 ++----
74096c
 2 files changed, 5 insertions(+), 4 deletions(-)
74096c
74096c
diff --git a/rpc/rpc-transport/socket/src/socket.c b/rpc/rpc-transport/socket/src/socket.c
74096c
index 1ee7320..96ed9f1 100644
74096c
--- a/rpc/rpc-transport/socket/src/socket.c
74096c
+++ b/rpc/rpc-transport/socket/src/socket.c
74096c
@@ -973,8 +973,11 @@ __socket_server_bind(rpc_transport_t *this)
74096c
                this->myinfo.identifier, strerror(errno));
74096c
         if (errno == EADDRINUSE) {
74096c
             gf_log(this->name, GF_LOG_ERROR, "Port is already in use");
74096c
+            ret = -EADDRINUSE;
74096c
+            goto out;
74096c
         }
74096c
     }
74096c
+
74096c
     if (AF_UNIX != SA(&this->myinfo.sockaddr)->sa_family) {
74096c
         if (getsockname(priv->sock, SA(&this->myinfo.sockaddr),
74096c
                         &this->myinfo.sockaddr_len) != 0) {
74096c
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
74096c
index cf32bd9..bc188a2 100644
74096c
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
74096c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
74096c
@@ -2151,6 +2151,7 @@ glusterd_volume_start_glusterfs(glusterd_volinfo_t *volinfo,
74096c
         ret = -1;
74096c
         goto out;
74096c
     }
74096c
+
74096c
     /* Build the exp_path, before starting the glusterfsd even in
74096c
        valgrind mode. Otherwise all the glusterfsd processes start
74096c
        writing the valgrind log to the same file.
74096c
@@ -2289,13 +2290,10 @@ retry:
74096c
 
74096c
     if (wait) {
74096c
         synclock_unlock(&priv->big_lock);
74096c
-        errno = 0;
74096c
         ret = runner_run(&runner);
74096c
-        if (errno != 0)
74096c
-            ret = errno;
74096c
         synclock_lock(&priv->big_lock);
74096c
 
74096c
-        if (ret == EADDRINUSE) {
74096c
+        if (ret == -EADDRINUSE) {
74096c
             /* retry after getting a new port */
74096c
             gf_msg(this->name, GF_LOG_WARNING, -ret,
74096c
                    GD_MSG_SRC_BRICK_PORT_UNAVAIL,
74096c
-- 
74096c
1.8.3.1
74096c