Blob Blame History Raw
From 338d491f48242ac85d4510a655fa85f642a11b8c Mon Sep 17 00:00:00 2001
From: Milind Changire <mchangir@redhat.com>
Date: Sun, 5 Mar 2017 21:39:20 +0530
Subject: [PATCH 349/361] rpc: avoid logging success on failure

Avoid logging Success in the event of failure especially when errno has
no meaningful value w.r.t. the failure. In this case the errno is set to
zero when there's indeed a failure at the RPC level.

mainline:
> BUG: 1426032
> Reviewed-on: https://review.gluster.org/16730
> Smoke: Gluster Build System <jenkins@build.gluster.org>
> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
> CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
> Reviewed-by: N Balachandran <nbalacha@redhat.com>
> Reviewed-by: Jeff Darcy <jdarcy@redhat.com>
(cherry picked from commit b6163b90fff47f4bd31cf1d33e60118b25f920d3)

BUG: 1387328
Change-Id: If2cc81aa1e590023ed22892dacbef7cac213e591
Signed-off-by: Milind Changire <mchangir@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/101325
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
---
 api/src/glfs-mgmt.c                   | 15 ++++++++++-----
 glusterfsd/src/glusterfsd-mgmt.c      | 17 ++++++++++++++---
 rpc/rpc-lib/src/rpc-transport.h       |  5 +++++
 rpc/rpc-transport/socket/src/socket.c |  2 ++
 4 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/api/src/glfs-mgmt.c b/api/src/glfs-mgmt.c
index 9a33736..0109764 100644
--- a/api/src/glfs-mgmt.c
+++ b/api/src/glfs-mgmt.c
@@ -789,11 +789,16 @@ mgmt_rpc_notify (struct rpc_clnt *rpc, void *mydata, rpc_clnt_event_t event,
 	switch (event) {
 	case RPC_CLNT_DISCONNECT:
 		if (!ctx->active) {
-                        gf_msg ("glfs-mgmt", GF_LOG_ERROR, errno,
-                                API_MSG_REMOTE_HOST_CONN_FAILED,
-                                "failed to connect with remote-host: %s (%s)",
-                                ctx->cmd_args.volfile_server,
-                                strerror (errno));
+                        if (rpc_trans->connect_failed)
+                                gf_msg ("glfs-mgmt", GF_LOG_ERROR, 0,
+                                        API_MSG_REMOTE_HOST_CONN_FAILED,
+                                        "failed to connect to remote-host: %s",
+                                        ctx->cmd_args.volfile_server);
+                        else
+                                gf_msg ("glfs-mgmt", GF_LOG_INFO, 0,
+                                        API_MSG_REMOTE_HOST_CONN_FAILED,
+                                        "disconnected from remote-host: %s",
+                                        ctx->cmd_args.volfile_server);
 
                         if (!rpc->disabled) {
                                 /*
diff --git a/glusterfsd/src/glusterfsd-mgmt.c b/glusterfsd/src/glusterfsd-mgmt.c
index 9cb8b41..1bbc5c8 100644
--- a/glusterfsd/src/glusterfsd-mgmt.c
+++ b/glusterfsd/src/glusterfsd-mgmt.c
@@ -2097,9 +2097,20 @@ mgmt_rpc_notify (struct rpc_clnt *rpc, void *mydata, rpc_clnt_event_t event,
 
         switch (event) {
         case RPC_CLNT_DISCONNECT:
-                GF_LOG_OCCASIONALLY (log_ctr1, "glusterfsd-mgmt", GF_LOG_ERROR,
-                        "failed to connect with remote-host: %s (%s)",
-                        ctx->cmd_args.volfile_server, strerror (errno));
+                if (rpc_trans->connect_failed) {
+                        GF_LOG_OCCASIONALLY (log_ctr1, "glusterfsd-mgmt",
+                                             GF_LOG_ERROR,
+                                             "failed to connect to remote-"
+                                             "host: %s",
+                                             ctx->cmd_args.volfile_server);
+                } else {
+                        GF_LOG_OCCASIONALLY (log_ctr1, "glusterfsd-mgmt",
+                                             GF_LOG_INFO,
+                                             "disconnected from remote-"
+                                             "host: %s",
+                                             ctx->cmd_args.volfile_server);
+                }
+
                 if (!rpc->disabled) {
                         /*
                          * Check if dnscache is exhausted for current server
diff --git a/rpc/rpc-lib/src/rpc-transport.h b/rpc/rpc-lib/src/rpc-transport.h
index dbfa32a..12dcfaf 100644
--- a/rpc/rpc-lib/src/rpc-transport.h
+++ b/rpc/rpc-lib/src/rpc-transport.h
@@ -211,6 +211,11 @@ struct rpc_transport {
         char                      *ssl_name;
         dict_t                    *clnt_options; /* store options received from
                                                   * client */
+        /* connect_failed: saves the connect() syscall status as socket_t
+         * member holding connect() status can't be accessed by higher gfapi
+         * layer or in client management notification handler functions
+         */
+        gf_boolean_t               connect_failed;
 };
 
 struct rpc_transport_ops {
diff --git a/rpc/rpc-transport/socket/src/socket.c b/rpc/rpc-transport/socket/src/socket.c
index cf2f75e..ca939bb 100644
--- a/rpc/rpc-transport/socket/src/socket.c
+++ b/rpc/rpc-transport/socket/src/socket.c
@@ -3148,6 +3148,7 @@ socket_connect (rpc_transport_t *this, int port)
                         }
                 }
 
+                this->connect_failed = _gf_false;
                 if (ign_enoent) {
                         ret = connect_loop (priv->sock,
                                             SA (&this->peerinfo.sockaddr),
@@ -3171,6 +3172,7 @@ socket_connect (rpc_transport_t *this, int port)
                         /* TBD: What about ENOENT, we will do getsockopt there
                         as well, so how is that exempt from such a problem? */
                         priv->connect_failed = 1;
+                        this->connect_failed = _gf_true;
 
                         goto handler;
                 }
-- 
1.8.3.1