Blame SOURCES/nfs-utils-1.3.0-mount-restore-econn.patch

fc3648
diff --git a/utils/mount/network.c b/utils/mount/network.c
fc3648
index 751f9b8..b2e4374 100644
fc3648
--- a/utils/mount/network.c
fc3648
+++ b/utils/mount/network.c
fc3648
@@ -33,11 +33,13 @@
fc3648
 #include <errno.h>
fc3648
 #include <netdb.h>
fc3648
 #include <time.h>
fc3648
+#include <grp.h>
fc3648
 
fc3648
 #include <sys/types.h>
fc3648
 #include <sys/socket.h>
fc3648
 #include <sys/wait.h>
fc3648
 #include <sys/stat.h>
fc3648
+#include <linux/in6.h>
fc3648
 #include <netinet/in.h>
fc3648
 #include <rpc/rpc.h>
fc3648
 #include <rpc/pmap_prot.h>
fc3648
@@ -802,6 +804,7 @@ int start_statd(void)
fc3648
 			pid_t pid = fork();
fc3648
 			switch (pid) {
fc3648
 			case 0: /* child */
fc3648
+				setgroups(0, NULL);
fc3648
 				setgid(0);
fc3648
 				setuid(0);
fc3648
 				execle(START_STATD, START_STATD, NULL, envp);
fc3648
@@ -1112,6 +1115,7 @@ static int nfs_ca_sockname(const struct sockaddr *sap, const socklen_t salen,
fc3648
 		.sin6_addr		= IN6ADDR_ANY_INIT,
fc3648
 	};
fc3648
 	int sock, result = 0;
fc3648
+	int val;
fc3648
 
fc3648
 	sock = socket(sap->sa_family, SOCK_DGRAM, IPPROTO_UDP);
fc3648
 	if (sock < 0)
fc3648
@@ -1123,6 +1127,9 @@ static int nfs_ca_sockname(const struct sockaddr *sap, const socklen_t salen,
fc3648
 			goto out;
fc3648
 		break;
fc3648
 	case AF_INET6:
fc3648
+		/* Make sure the call-back address is public/permanent */
fc3648
+		val = IPV6_PREFER_SRC_PUBLIC;
fc3648
+		setsockopt(sock, SOL_IPV6, IPV6_ADDR_PREFERENCES, &val, sizeof(val));
fc3648
 		if (bind(sock, SAFE_SOCKADDR(&sin6), sizeof(sin6)) < 0)
fc3648
 			goto out;
fc3648
 		break;
fc3648
diff --git a/utils/mount/stropts.c b/utils/mount/stropts.c
fc3648
index fc68d41..57e932f 100644
fc3648
--- a/utils/mount/stropts.c
fc3648
+++ b/utils/mount/stropts.c
fc3648
@@ -91,6 +91,7 @@ struct nfsmount_info {
fc3648
 				*type;		/* "nfs" or "nfs4" */
fc3648
 	char			*hostname;	/* server's hostname */
fc3648
 	struct addrinfo		*address;	/* server's addresses */
fc3648
+	sa_family_t		family;		/* Address family */
fc3648
 
fc3648
 	struct mount_options	*options;	/* parsed mount options */
fc3648
 	char			**extra_opts;	/* string for /etc/mtab */
fc3648
@@ -388,39 +389,19 @@ static int nfs_set_version(struct nfsmount_info *mi)
fc3648
  */
fc3648
 static int nfs_validate_options(struct nfsmount_info *mi)
fc3648
 {
fc3648
-	struct addrinfo hint = {
fc3648
-		.ai_protocol	= (int)IPPROTO_UDP,
fc3648
-	};
fc3648
-	sa_family_t family;
fc3648
-	int error;
fc3648
-
fc3648
 	if (!nfs_parse_devname(mi->spec, &mi->hostname, NULL))
fc3648
 		return 0;
fc3648
 
fc3648
-	if (!nfs_nfs_proto_family(mi->options, &family))
fc3648
+	if (!nfs_nfs_proto_family(mi->options, &mi->family))
fc3648
 		return 0;
fc3648
 
fc3648
 	/*
fc3648
 	 * A remount is not going to be able to change the server's address,
fc3648
 	 * nor should we try to resolve another address for the server as we
fc3648
 	 * may end up with a different address.
fc3648
+	 * A non-remount will set 'addr' from ->hostname
fc3648
 	 */
fc3648
-	if (mi->flags & MS_REMOUNT) {
fc3648
-		po_remove_all(mi->options, "addr");
fc3648
-	} else {
fc3648
-		hint.ai_family = (int)family;
fc3648
-		error = getaddrinfo(mi->hostname, NULL, &hint, &mi->address);
fc3648
-		if (error != 0) {
fc3648
-			nfs_error(_("%s: Failed to resolve server %s: %s"),
fc3648
-				progname, mi->hostname, gai_strerror(error));
fc3648
-			mi->address = NULL;
fc3648
-			return 0;
fc3648
-		}
fc3648
-
fc3648
-		if (!nfs_append_addr_option(mi->address->ai_addr,
fc3648
-						mi->address->ai_addrlen, mi->options))
fc3648
-			return 0;
fc3648
-	}
fc3648
+	po_remove_all(mi->options, "addr");
fc3648
 
fc3648
 	if (!nfs_set_version(mi))
fc3648
 		return 0;
fc3648
@@ -900,7 +881,10 @@ check_result:
fc3648
 			result = nfs_try_mount_v4(mi);
fc3648
 			if (result == 0 && errno != ECONNREFUSED)
fc3648
 				goto check_result;
fc3648
-		}
fc3648
+		} else if (result == 0)
fc3648
+			/* Restore original errno with v3 failures */
fc3648
+			errno = ECONNREFUSED;
fc3648
+
fc3648
 		return result;
fc3648
 	default:
fc3648
 		return result;
fc3648
@@ -923,6 +907,32 @@ static int nfs_try_mount(struct nfsmount_info *mi)
fc3648
 {
fc3648
 	int result = 0;
fc3648
 
fc3648
+	if (mi->address == NULL) {
fc3648
+		struct addrinfo hint = {
fc3648
+			.ai_protocol	= (int)IPPROTO_UDP,
fc3648
+		};
fc3648
+		int error;
fc3648
+		struct addrinfo *address;
fc3648
+
fc3648
+		hint.ai_family = (int)mi->family;
fc3648
+		error = getaddrinfo(mi->hostname, NULL, &hint, &address);
fc3648
+		if (error != 0) {
fc3648
+			if (error == EAI_AGAIN)
fc3648
+				errno = EAGAIN;
fc3648
+			else {
fc3648
+				nfs_error(_("%s: Failed to resolve server %s: %s"),
fc3648
+					  progname, mi->hostname, gai_strerror(error));
fc3648
+				errno = EALREADY;
fc3648
+			}
fc3648
+			return 0;
fc3648
+		}
fc3648
+
fc3648
+		if (!nfs_append_addr_option(address->ai_addr,
fc3648
+					    address->ai_addrlen, mi->options))
fc3648
+			return 0;
fc3648
+		mi->address = address;
fc3648
+	}
fc3648
+
fc3648
 	switch (mi->version.major) {
fc3648
 		case 2:
fc3648
 		case 3:
fc3648
@@ -1018,10 +1028,8 @@ static int nfsmount_fg(struct nfsmount_info *mi)
fc3648
 		if (nfs_is_permanent_error(errno))
fc3648
 			break;
fc3648
 
fc3648
-		if (time(NULL) > timeout) {
fc3648
-			errno = ETIMEDOUT;
fc3648
+		if (time(NULL) > timeout)
fc3648
 			break;
fc3648
-		}
fc3648
 
fc3648
 		if (errno != ETIMEDOUT) {
fc3648
 			if (sleep(secs))