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