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