]> git.decadent.org.uk Git - nfs-utils.git/commitdiff
mount.nfs: fix hang when getport() uses TCP against unavailable servers
authorChuck Lever <chuck.lever@oracle.com>
Sat, 28 Jul 2007 21:50:19 +0000 (17:50 -0400)
committerNeil Brown <neilb@suse.de>
Mon, 30 Jul 2007 06:12:53 +0000 (16:12 +1000)
If get_socket() can't get us an open TCP socket, we know the server is
down, so make  getport() exit early instead of hanging.  This logic is
copied from clnt_ping().

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Neil Brown <neilb@suse.de>
utils/mount/network.c

index 21cf4efe72c646b2d26acca4ba038dde23962ca5..565330281c940f94a5ab03bd7c945778934d1398 100644 (file)
@@ -135,8 +135,23 @@ unsigned short getport(struct sockaddr_in *saddr, unsigned long prog,
        struct pmap parms;
        enum clnt_stat stat;
 
-       saddr->sin_port = htons (PMAPPORT);
-       socket = get_socket(saddr, prot, FALSE, FALSE);
+       saddr->sin_port = htons(PMAPPORT);
+
+       /*
+        * Try to get a socket with a non-privileged port.
+        * clnt*create() will create one anyway if this
+        * fails.
+        */
+       socket = get_socket(saddr, proto, FALSE, FALSE);
+       if (socket == RPC_ANYSOCK) {
+               if (proto == IPPROTO_TCP && errno == ETIMEDOUT) {
+                       /*
+                        * TCP SYN timed out, so exit now.
+                        */
+                       rpc_createerr.cf_stat = RPC_TIMEDOUT;
+               }
+               return 0;
+       }
 
        switch (prot) {
        case IPPROTO_UDP: