Blame SOURCES/autofs-5.1.3-add-version-parameter-to-rpc_ping.patch

7f6688
autofs-5.1.3 - add version parameter to rpc_ping()
7f6688
7f6688
From: Ian Kent <raven@themaw.net>
7f6688
7f6688
Add an version parameter to rpc_ping() to try and avoid NFS pings
7f6688
to protocol or NFS version that isn't to be used.
7f6688
7f6688
When the port option is specified (possibly for NFS tunneling) it's
7f6688
likely that the protocol is also specified which will reduce uneeded
7f6688
NFS ping requests. But for this to work best (with the minimum delay)
7f6688
the NFS version needs to also be specified in the NFS mount options.
7f6688
7f6688
Signed-off-by: Ian Kent <raven@themaw.net>
7f6688
---
7f6688
 CHANGELOG           |    1 
7f6688
 include/rpc_subs.h  |    2 -
7f6688
 lib/rpc_subs.c      |   74 +++++++++++++++++++++++++++-------------------------
7f6688
 modules/mount_nfs.c |    2 -
7f6688
 4 files changed, 42 insertions(+), 37 deletions(-)
7f6688
7f6688
--- autofs-5.0.7.orig/CHANGELOG
7f6688
+++ autofs-5.0.7/CHANGELOG
7f6688
@@ -306,6 +306,7 @@
7f6688
 - remove some redundant rpc library code.
7f6688
 - add port parameter to rpc_ping().
7f6688
 - dont probe NFSv2 by default.
7f6688
+- add version parameter to rpc_ping().
7f6688
 
7f6688
 25/07/2012 autofs-5.0.7
7f6688
 =======================
7f6688
--- autofs-5.0.7.orig/include/rpc_subs.h
7f6688
+++ autofs-5.0.7/include/rpc_subs.h
7f6688
@@ -69,7 +69,7 @@ void rpc_destroy_tcp_client(struct conn_
7f6688
 int rpc_portmap_getclient(struct conn_info *, const char *, struct sockaddr *, size_t, int, unsigned int);
7f6688
 int rpc_portmap_getport(struct conn_info *, struct pmap *, unsigned short *);
7f6688
 int rpc_ping_proto(struct conn_info *);
7f6688
-int rpc_ping(const char *, int, long, long, unsigned int);
7f6688
+int rpc_ping(const char *, int, unsigned int, long, long, unsigned int);
7f6688
 double elapsed(struct timeval, struct timeval);
7f6688
 const char *get_addr_string(struct sockaddr *, char *, socklen_t);
7f6688
 
7f6688
--- autofs-5.0.7.orig/lib/rpc_subs.c
7f6688
+++ autofs-5.0.7/lib/rpc_subs.c
7f6688
@@ -53,6 +53,7 @@ const rpcvers_t rpcb_version = PMAPVERS;
7f6688
 
7f6688
 #include "mount.h"
7f6688
 #include "rpc_subs.h"
7f6688
+#include "replicated.h"
7f6688
 #include "automount.h"
7f6688
 
7f6688
 /* #define STANDALONE */
7f6688
@@ -1052,43 +1053,46 @@ static int __rpc_ping(const char *host,
7f6688
 }
7f6688
 
7f6688
 int rpc_ping(const char *host, int port,
7f6688
-	     long seconds, long micros, unsigned int option)
7f6688
+	     unsigned int version, long seconds, long micros,
7f6688
+	     unsigned int option)
7f6688
 {
7f6688
-	unsigned long vers4 = NFS4_VERSION;
7f6688
-	unsigned long vers3 = NFS3_VERSION;
7f6688
-	unsigned long vers2 = NFS2_VERSION;
7f6688
-	int status;
7f6688
+	int status = 0;
7f6688
+
7f6688
+	if ((version & NFS2_REQUESTED) && (version & TCP_REQUESTED)) {
7f6688
+		status = __rpc_ping(host, NFS2_VERSION,
7f6688
+				    IPPROTO_TCP, port, seconds, micros, option);
7f6688
+		if (status > 0)
7f6688
+			return RPC_PING_V2 | RPC_PING_TCP;
7f6688
+	}
7f6688
+
7f6688
+	if ((version & NFS2_REQUESTED) && (version & UDP_REQUESTED)) {
7f6688
+		status = __rpc_ping(host, NFS2_VERSION,
7f6688
+				    IPPROTO_UDP, port, seconds, micros, option);
7f6688
+		if (status > 0)
7f6688
+			return RPC_PING_V2 | RPC_PING_UDP;
7f6688
+	}
7f6688
 
7f6688
-	status = __rpc_ping(host, vers2,
7f6688
-			    IPPROTO_UDP, port, seconds, micros, option);
7f6688
-	if (status > 0)
7f6688
-		return RPC_PING_V2 | RPC_PING_UDP;
7f6688
-
7f6688
-	status = __rpc_ping(host, vers3,
7f6688
-			    IPPROTO_UDP, port, seconds, micros, option);
7f6688
-	if (status > 0)
7f6688
-		return RPC_PING_V3 | RPC_PING_UDP;
7f6688
-
7f6688
-	/* UDP isn't recommended for NFSv4, don't bother checking it.
7f6688
-	status = __rpc_ping(host, vers4, IPPROTO_UDP, seconds, micros, option);
7f6688
-	if (status > 0)
7f6688
-		return RPC_PING_V4 | RPC_PING_UDP;
7f6688
-	*/
7f6688
-
7f6688
-	status = __rpc_ping(host, vers2,
7f6688
-			    IPPROTO_TCP, port, seconds, micros, option);
7f6688
-	if (status > 0)
7f6688
-		return RPC_PING_V2 | RPC_PING_TCP;
7f6688
-
7f6688
-	status = __rpc_ping(host, vers3, port,
7f6688
-			    IPPROTO_TCP, seconds, micros, option);
7f6688
-	if (status > 0)
7f6688
-		return RPC_PING_V3 | RPC_PING_TCP;
7f6688
-
7f6688
-	status = __rpc_ping(host, vers4,
7f6688
-			    IPPROTO_TCP, port, seconds, micros, option);
7f6688
-	if (status > 0)
7f6688
-		return RPC_PING_V4 | RPC_PING_TCP;
7f6688
+	if ((version & NFS3_REQUESTED) && (version & TCP_REQUESTED)) {
7f6688
+		status = __rpc_ping(host, NFS3_VERSION,
7f6688
+				    IPPROTO_TCP, port, seconds, micros, option);
7f6688
+		if (status > 0)
7f6688
+			return RPC_PING_V3 | RPC_PING_TCP;
7f6688
+	}
7f6688
+
7f6688
+	if ((version & NFS3_REQUESTED) && (version & UDP_REQUESTED)) {
7f6688
+		status = __rpc_ping(host, NFS3_VERSION,
7f6688
+				    IPPROTO_UDP, port, seconds, micros, option);
7f6688
+		if (status > 0)
7f6688
+			return RPC_PING_V3 | RPC_PING_UDP;
7f6688
+	}
7f6688
+
7f6688
+	if (version & NFS4_REQUESTED) {
7f6688
+		/* UDP isn't recommended for NFSv4, don't check it. */
7f6688
+		status = __rpc_ping(host, NFS4_VERSION,
7f6688
+				    IPPROTO_TCP, port, seconds, micros, option);
7f6688
+		if (status > 0)
7f6688
+			return RPC_PING_V4 | RPC_PING_TCP;
7f6688
+	}
7f6688
 
7f6688
 	return status;
7f6688
 }
7f6688
--- autofs-5.0.7.orig/modules/mount_nfs.c
7f6688
+++ autofs-5.0.7/modules/mount_nfs.c
7f6688
@@ -358,7 +358,7 @@ dont_probe:
7f6688
 			char *host = this->name ? this->name : "localhost";
7f6688
 			int ret;
7f6688
 
7f6688
-			ret = rpc_ping(host, port, 2, 0, RPC_CLOSE_DEFAULT);
7f6688
+			ret = rpc_ping(host, port, vers, 2, 0, RPC_CLOSE_DEFAULT);
7f6688
 			if (ret <= 0)
7f6688
 				goto next;
7f6688
 		}