From 97084f70a6c2956d49d8dc289aeb8ede84e5f7b4 Mon Sep 17 00:00:00 2001 From: Mr NeilBrown Date: Fri, 7 Feb 2020 13:05:56 +1100 Subject: [PATCH] LU-10391 lnet: remove 'fatal' arg from lnet_{sock_}connect The 'fatal' arg for indicating if an error is fatal doesn't help make the code easier to read. In each case where it is tested, it would be more clear to directly tested for the particular errors that are not fatal. So remove the arg and change the tests. Signed-off-by: Mr NeilBrown Change-Id: I905e0c2652b3148d93219a32a6b93515af323159 Reviewed-on: https://review.whamcloud.com/37700 Reviewed-by: Aurelien Degremont Reviewed-by: James Simmons Tested-by: jenkins Tested-by: Maloo Reviewed-by: Oleg Drokin --- lnet/include/lnet/lib-lnet.h | 2 +- lnet/lnet/acceptor.c | 15 +++++++-------- lnet/lnet/lib-socket.c | 22 ++++++++-------------- 3 files changed, 16 insertions(+), 23 deletions(-) diff --git a/lnet/include/lnet/lib-lnet.h b/lnet/include/lnet/lib-lnet.h index ccc74b5..c2fec37 100644 --- a/lnet/include/lnet/lib-lnet.h +++ b/lnet/include/lnet/lib-lnet.h @@ -801,7 +801,7 @@ int lnet_sock_read(struct socket *sock, void *buffer, int nob, int timeout); int lnet_sock_listen(struct socket **sockp, __u32 ip, int port, int backlog, struct net *ns); -int lnet_sock_connect(struct socket **sockp, int *fatal, +int lnet_sock_connect(struct socket **sockp, __u32 local_ip, int local_port, __u32 peer_ip, int peer_port, struct net *ns); diff --git a/lnet/lnet/acceptor.c b/lnet/lnet/acceptor.c index 75e9f27..e1a18a4 100644 --- a/lnet/lnet/acceptor.c +++ b/lnet/lnet/acceptor.c @@ -152,7 +152,6 @@ lnet_connect(struct socket **sockp, lnet_nid_t peer_nid, struct socket *sock; int rc; int port; - int fatal; BUILD_BUG_ON(sizeof(cr) > 16); /* not too big to be on the stack */ @@ -161,13 +160,13 @@ lnet_connect(struct socket **sockp, lnet_nid_t peer_nid, --port) { /* Iterate through reserved ports. */ - rc = lnet_sock_connect(&sock, &fatal, - local_ip, port, - peer_ip, peer_port, ns); - if (rc != 0) { - if (fatal) - goto failed; - continue; + rc = lnet_sock_connect(&sock, + local_ip, port, + peer_ip, peer_port, ns); + if (rc) { + if (rc == -EADDRINUSE || rc == -EADDRNOTAVAIL) + continue; + goto failed; } BUILD_BUG_ON(LNET_PROTO_ACCEPTOR_VERSION != 1); diff --git a/lnet/lnet/lib-socket.c b/lnet/lnet/lib-socket.c index 6e6fe37..70397ee 100644 --- a/lnet/lnet/lib-socket.c +++ b/lnet/lnet/lib-socket.c @@ -176,7 +176,7 @@ lnet_sock_read(struct socket *sock, void *buffer, int nob, int timeout) EXPORT_SYMBOL(lnet_sock_read); static int -lnet_sock_create(struct socket **sockp, int *fatal, +lnet_sock_create(struct socket **sockp, __u32 local_ip, int local_port, struct net *ns) { struct sockaddr_in locaddr; @@ -184,9 +184,6 @@ lnet_sock_create(struct socket **sockp, int *fatal, int rc; int option; - /* All errors are fatal except bind failure if the port is in use */ - *fatal = 1; - #ifdef HAVE_SOCK_CREATE_KERN_USE_NET rc = sock_create_kern(ns, PF_INET, SOCK_STREAM, 0, &sock); #else @@ -217,7 +214,6 @@ lnet_sock_create(struct socket **sockp, int *fatal, sizeof(locaddr)); if (rc == -EADDRINUSE) { CDEBUG(D_NET, "Port %d already in use\n", local_port); - *fatal = 0; goto failed; } if (rc != 0) { @@ -312,12 +308,11 @@ int lnet_sock_listen(struct socket **sockp, __u32 local_ip, int local_port, int backlog, struct net *ns) { - int fatal; int rc; - rc = lnet_sock_create(sockp, &fatal, local_ip, local_port, ns); + rc = lnet_sock_create(sockp, local_ip, local_port, ns); if (rc != 0) { - if (!fatal) + if (rc == -EADDRINUSE) CERROR("Can't create socket: port %d already in use\n", local_port); return rc; @@ -333,7 +328,7 @@ lnet_sock_listen(struct socket **sockp, } int -lnet_sock_connect(struct socket **sockp, int *fatal, +lnet_sock_connect(struct socket **sockp, __u32 local_ip, int local_port, __u32 peer_ip, int peer_port, struct net *ns) @@ -341,7 +336,7 @@ lnet_sock_connect(struct socket **sockp, int *fatal, struct sockaddr_in srvaddr; int rc; - rc = lnet_sock_create(sockp, fatal, local_ip, local_port, ns); + rc = lnet_sock_create(sockp, local_ip, local_port, ns); if (rc != 0) return rc; @@ -359,11 +354,10 @@ lnet_sock_connect(struct socket **sockp, int *fatal, * peer/port on the same local port on a differently typed * connection. Let our caller retry with a different local * port... */ - *fatal = !(rc == -EADDRNOTAVAIL); - CDEBUG_LIMIT(*fatal ? D_NETERROR : D_NET, - "Error %d connecting %pI4h/%d -> %pI4h/%d\n", rc, - &local_ip, local_port, &peer_ip, peer_port); + CDEBUG_LIMIT(rc == -EADDRNOTAVAIL ? D_NET : D_NETERROR, + "Error %d connecting %pI4h/%d -> %pI4h/%d\n", rc, + &local_ip, local_port, &peer_ip, peer_port); sock_release(*sockp); return rc; -- 1.8.3.1