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