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