walters / rpms / nfs-utils

Forked from rpms/nfs-utils 6 years ago
Clone
46431c9
commit b8711a0665b9ecff9d59ee36d756f50823242f64
46431c9
Author: Chuck Lever <chuck.lever@oracle.com>
46431c9
Date:   Tue Dec 2 07:43:54 2008 -0500
46431c9
46431c9
    mount command: remove local getport() implementation
46431c9
    
46431c9
    Eliminate local getport() implementation from utils/mount/network.c, as
46431c9
    it is no longer used.
46431c9
    
46431c9
    Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
46431c9
    Signed-off-by: Steve Dickson <steved@redhat.com>
46431c9
46431c9
commit cc58ba0c98b2f687810a5af9e6185bcc5e855fb0
46431c9
Author: Chuck Lever <chuck.lever@oracle.com>
46431c9
Date:   Tue Dec 2 07:43:01 2008 -0500
46431c9
46431c9
    mount command: Replace clnt_ping() and getport() calls in   probe_port()
46431c9
    
46431c9
    Update the mount command's probe_port() function to call the new shared
46431c9
    rpcbind query and RPC ping functions.  This provides immediate support
46431c9
    for
46431c9
    rpcbind v3/v4 queries, and paves the way for supporting AF_INET6 in the
46431c9
    probe_bothports() path.
46431c9
    
46431c9
    Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
46431c9
    Signed-off-by: Steve Dickson <steved@redhat.com>
46431c9
46431c9
commit 14b0dae49afae3fcf05c19ae84829aeef2f6876e
46431c9
Author: Chuck Lever <chuck.lever@oracle.com>
46431c9
Date:   Tue Dec 2 07:40:16 2008 -0500
46431c9
46431c9
    mount command: Use nfs_error() instead of perror()
46431c9
    
46431c9
    So we can ensure that error output is directed appropriately, use
46431c9
    nfs_error() instead of perror() in start_statd().
46431c9
    
46431c9
    Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
46431c9
    Signed-off-by: Steve Dickson <steved@redhat.com>
46431c9
46431c9
commit ea0473feffd8071216c96217df3202a8deed2c65
46431c9
Author: Chuck Lever <chuck.lever@oracle.com>
46431c9
Date:   Tue Dec 2 07:39:06 2008 -0500
46431c9
46431c9
    mount command: Use nfs_pmap_getport() in probe_statd()
46431c9
    
46431c9
    Repace the getport() and clnt_ping() calls in probe_statd() with their
46431c9
    new shared equivalents.
46431c9
    
46431c9
    Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
46431c9
    Signed-off-by: Steve Dickson <steved@redhat.com>
46431c9
46431c9
diff -up nfs-utils-1.1.4/utils/mount/network.c.orig nfs-utils-1.1.4/utils/mount/network.c
46431c9
--- nfs-utils-1.1.4/utils/mount/network.c.orig	2008-12-01 09:14:24.000000000 -0500
46431c9
+++ nfs-utils-1.1.4/utils/mount/network.c	2008-12-02 08:32:00.000000000 -0500
46431c9
@@ -47,6 +47,7 @@
46431c9
 #include "nls.h"
46431c9
 #include "nfs_mount.h"
46431c9
 #include "mount_constants.h"
46431c9
+#include "nfsrpc.h"
46431c9
 #include "network.h"
46431c9
 
46431c9
 /*
46431c9
@@ -79,6 +80,11 @@ extern int nfs_mount_data_version;
46431c9
 extern char *progname;
46431c9
 extern int verbose;
46431c9
 
46431c9
+static const char *nfs_ns_pgmtbl[] = {
46431c9
+	"status",
46431c9
+	NULL,
46431c9
+};
46431c9
+
46431c9
 static const unsigned long nfs_to_mnt[] = {
46431c9
 	0,
46431c9
 	0,
46431c9
@@ -443,76 +449,25 @@ err_connect:
46431c9
 	return RPC_ANYSOCK;
46431c9
 }
46431c9
 
46431c9
-/*
46431c9
- * getport() is very similar to pmap_getport() with the exception that
46431c9
- * this version tries to use an ephemeral port, since reserved ports are
46431c9
- * not needed for GETPORT queries.  This conserves the very limited
46431c9
- * reserved port space, which helps reduce failed socket binds
46431c9
- * during mount storms.
46431c9
- *
46431c9
- * A side effect of calling this function is that rpccreateerr is set.
46431c9
- */
46431c9
-static unsigned short getport(struct sockaddr_in *saddr,
46431c9
-				unsigned long program,
46431c9
-				unsigned long version,
46431c9
-				unsigned int proto)
46431c9
-{
46431c9
-	struct sockaddr_in bind_saddr;
46431c9
-	unsigned short port = 0;
46431c9
-	int socket;
46431c9
-	CLIENT *clnt = NULL;
46431c9
-	enum clnt_stat stat;
46431c9
- 
46431c9
-	bind_saddr = *saddr;
46431c9
-	bind_saddr.sin_port = htons(PMAPPORT);
46431c9
-
46431c9
-	socket = get_socket(&bind_saddr, proto, PMAP_TIMEOUT, FALSE, TRUE);
46431c9
-	if (socket == RPC_ANYSOCK) {
46431c9
-		if (proto == IPPROTO_TCP &&
46431c9
-		    rpc_createerr.cf_error.re_errno == ETIMEDOUT)
46431c9
-			rpc_createerr.cf_stat = RPC_TIMEDOUT;
46431c9
-		return 0;
46431c9
-	}
46431c9
+static void nfs_pp_debug(const struct sockaddr *sap, const socklen_t salen,
46431c9
+			 const rpcprog_t program, const rpcvers_t version,
46431c9
+			 const unsigned short protocol,
46431c9
+			 const unsigned short port)
46431c9
+{
46431c9
+	char buf[NI_MAXHOST];
46431c9
 
46431c9
-	switch (proto) {
46431c9
-	case IPPROTO_UDP:
46431c9
-		clnt = clntudp_bufcreate(&bind_saddr,
46431c9
-					 PMAPPROG, PMAPVERS,
46431c9
-					 RETRY_TIMEOUT, &socket,
46431c9
-					 RPCSMALLMSGSIZE,
46431c9
-					 RPCSMALLMSGSIZE);
46431c9
-		break;
46431c9
-	case IPPROTO_TCP:
46431c9
-		clnt = clnttcp_create(&bind_saddr,
46431c9
-				      PMAPPROG, PMAPVERS,
46431c9
-				      &socket,
46431c9
-				      RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
46431c9
-		break;
46431c9
-	}
46431c9
-	if (clnt != NULL) {
46431c9
-		struct pmap parms = {
46431c9
-			.pm_prog	= program,
46431c9
-			.pm_vers	= version,
46431c9
-			.pm_prot	= proto,
46431c9
-		};
46431c9
-
46431c9
-		stat = clnt_call(clnt, PMAPPROC_GETPORT,
46431c9
-				 (xdrproc_t)xdr_pmap, (caddr_t)&parms,
46431c9
-				 (xdrproc_t)xdr_u_short, (caddr_t)&port,
46431c9
-				 TIMEOUT);
46431c9
-		if (stat) {
46431c9
-			clnt_geterr(clnt, &rpc_createerr.cf_error);
46431c9
-			rpc_createerr.cf_stat = stat;
46431c9
-		}
46431c9
-		clnt_destroy(clnt);
46431c9
-		if (stat != RPC_SUCCESS)
46431c9
-			port = 0;
46431c9
-		else if (port == 0)
46431c9
-			rpc_createerr.cf_stat = RPC_PROGNOTREGISTERED;
46431c9
+	if (!verbose)
46431c9
+		return;
46431c9
+
46431c9
+	if (nfs_present_sockaddr(sap, salen, buf, sizeof(buf)) == 0) {
46431c9
+		buf[0] = '\0';
46431c9
+		strcat(buf, "unknown host");
46431c9
 	}
46431c9
-	close(socket);
46431c9
 
46431c9
-	return port;
46431c9
+	fprintf(stderr, _("%s: trying %s prog %ld vers %ld prot %s port %d\n"),
46431c9
+			progname, buf, program, version,
46431c9
+			(protocol == IPPROTO_UDP ? _("UDP") : _("TCP")),
46431c9
+			port);
46431c9
 }
46431c9
 
46431c9
 /*
46431c9
@@ -523,7 +478,8 @@ static unsigned short getport(struct soc
46431c9
 static int probe_port(clnt_addr_t *server, const unsigned long *versions,
46431c9
 			const unsigned int *protos)
46431c9
 {
46431c9
-	struct sockaddr_in *saddr = &server->saddr;
46431c9
+	const struct sockaddr *saddr = (struct sockaddr *)&server->saddr;
46431c9
+	const socklen_t salen = sizeof(server->saddr);
46431c9
 	struct pmap *pmap = &server->pmap;
46431c9
 	const unsigned long prog = pmap->pm_prog, *p_vers;
46431c9
 	const unsigned int prot = (u_int)pmap->pm_prot, *p_prot;
46431c9
@@ -535,21 +491,14 @@ static int probe_port(clnt_addr_t *serve
46431c9
 	p_vers = vers ? &vers : versions;
46431c9
 	rpc_createerr.cf_stat = 0;
46431c9
 	for (;;) {
46431c9
-		p_port = getport(saddr, prog, *p_vers, *p_prot);
46431c9
+		p_port = nfs_getport(saddr, salen, prog, *p_vers, *p_prot);
46431c9
 		if (p_port) {
46431c9
 			if (!port || port == p_port) {
46431c9
-				saddr->sin_port = htons(p_port);
46431c9
-				if (verbose) {
46431c9
-					printf(_("%s: trying %s prog %ld vers "
46431c9
-						"%ld prot %s port %d\n"),
46431c9
-						progname,
46431c9
-						inet_ntoa(saddr->sin_addr),
46431c9
-						prog, *p_vers,
46431c9
-						*p_prot == IPPROTO_UDP ?
46431c9
-							_("UDP") : _("TCP"),
46431c9
-						p_port);
46431c9
-                                }
46431c9
-				if (clnt_ping(saddr, prog, *p_vers, *p_prot, NULL))
46431c9
+				server->saddr.sin_port = htons(p_port);
46431c9
+				nfs_pp_debug(saddr, salen, prog, *p_vers,
46431c9
+						*p_prot, p_port);
46431c9
+				if (nfs_rpc_ping(saddr, salen, prog,
46431c9
+							*p_vers, *p_prot, NULL))
46431c9
 					goto out_ok;
46431c9
 			}
46431c9
 		}
46431c9
@@ -669,24 +618,16 @@ version_fixed:
46431c9
 	return probe_mntport(mnt_server);
46431c9
 }
46431c9
 
46431c9
-static int probe_statd(void)
46431c9
+static int nfs_probe_statd(void)
46431c9
 {
46431c9
-	struct sockaddr_in addr;
46431c9
-	unsigned short port;
46431c9
-
46431c9
-	memset(&addr, 0, sizeof(addr));
46431c9
-	addr.sin_family = AF_INET;
46431c9
-	addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
46431c9
-	port = getport(&addr, 100024, 1, IPPROTO_UDP);
46431c9
-
46431c9
-	if (port == 0)
46431c9
-		return 0;
46431c9
-	addr.sin_port = htons(port);
46431c9
-
46431c9
-	if (clnt_ping(&addr, 100024, 1, IPPROTO_UDP, NULL) <= 0)
46431c9
-		return 0;
46431c9
+	struct sockaddr_in addr = {
46431c9
+		.sin_family		= AF_INET,
46431c9
+		.sin_addr.s_addr	= htonl(INADDR_LOOPBACK),
46431c9
+	};
46431c9
+	rpcprog_t program = nfs_getrpcbyname(NSMPROG, nfs_ns_pgmtbl);
46431c9
 
46431c9
-	return 1;
46431c9
+	return nfs_getport_ping((struct sockaddr *)&addr, sizeof(addr),
46431c9
+				program, (rpcvers_t)1, IPPROTO_UDP);
46431c9
 }
46431c9
 
46431c9
 /**
46431c9
@@ -700,7 +641,7 @@ int start_statd(void)
46431c9
 	struct stat stb;
46431c9
 #endif
46431c9
 
46431c9
-	if (probe_statd())
46431c9
+	if (nfs_probe_statd())
46431c9
 		return 1;
46431c9
 
46431c9
 #ifdef START_STATD
46431c9
@@ -712,13 +653,14 @@ int start_statd(void)
46431c9
 				execl(START_STATD, START_STATD, NULL);
46431c9
 				exit(1);
46431c9
 			case -1: /* error */
46431c9
-				perror("Fork failed");
46431c9
+				nfs_error(_("fork failed: %s"),
46431c9
+							strerror(errno));
46431c9
 				break;
46431c9
 			default: /* parent */
46431c9
 				waitpid(pid, NULL,0);
46431c9
 				break;
46431c9
 			}
46431c9
-			if (probe_statd())
46431c9
+			if (nfs_probe_statd())
46431c9
 				return 1;
46431c9
 		}
46431c9
 	}
46431c9
@@ -829,9 +771,9 @@ void mnt_closeclnt(CLIENT *clnt, int mso
46431c9
  * @prot: target RPC protocol
46431c9
  * @caddr: filled in with our network address
46431c9
  *
46431c9
- * Sigh... getport() doesn't actually check the version number.
46431c9
+ * Sigh... GETPORT queries don't actually check the version number.
46431c9
  * In order to make sure that the server actually supports the service
46431c9
- * we're requesting, we open and RPC client, and fire off a NULL
46431c9
+ * we're requesting, we open an RPC client, and fire off a NULL
46431c9
  * RPC call.
46431c9
  *
46431c9
  * caddr is the network address that the server will use to call us back.