Blame SOURCES/nfs-utils-1.3.0-mount-turnoffv4.patch

5fd2c0
diff -up nfs-utils-1.3.0/support/include/nfs/nfs.h.orig nfs-utils-1.3.0/support/include/nfs/nfs.h
5fd2c0
--- nfs-utils-1.3.0/support/include/nfs/nfs.h.orig	2018-08-20 14:18:13.975034097 -0400
5fd2c0
+++ nfs-utils-1.3.0/support/include/nfs/nfs.h	2018-08-20 14:18:29.624303893 -0400
5fd2c0
@@ -16,8 +16,8 @@
5fd2c0
 #define NFSD_MINVERS 2
5fd2c0
 #define NFSD_MAXVERS 4
5fd2c0
 
5fd2c0
-#define NFS4_MINMINOR 1
5fd2c0
-#define NFS4_MAXMINOR WORD_BIT
5fd2c0
+#define NFS4_MINMINOR 0
5fd2c0
+#define NFS4_MAXMINOR (WORD_BIT-1)
5fd2c0
 
5fd2c0
 struct nfs_fh_len {
5fd2c0
 	int		fh_size;
5fd2c0
@@ -49,16 +49,19 @@ struct nfs_fh_old {
5fd2c0
 #define NFSCTL_TCPBIT		      (1 << (18 - 1))
5fd2c0
 
5fd2c0
 #define NFSCTL_VERUNSET(_cltbits, _v) ((_cltbits) &= ~(1 << ((_v) - 1))) 
5fd2c0
+#define NFSCTL_MINORUNSET(_cltbits, _v) ((_cltbits) &= ~(1 << (_v)))
5fd2c0
 #define NFSCTL_UDPUNSET(_cltbits)     ((_cltbits) &= ~NFSCTL_UDPBIT) 
5fd2c0
 #define NFSCTL_TCPUNSET(_cltbits)     ((_cltbits) &= ~NFSCTL_TCPBIT) 
5fd2c0
 
5fd2c0
 #define NFSCTL_VERISSET(_cltbits, _v) ((_cltbits) & (1 << ((_v) - 1))) 
5fd2c0
+#define NFSCTL_MINORISSET(_cltbits, _v) ((_cltbits) & (1 << (_v)))
5fd2c0
 #define NFSCTL_UDPISSET(_cltbits)     ((_cltbits) & NFSCTL_UDPBIT) 
5fd2c0
 #define NFSCTL_TCPISSET(_cltbits)     ((_cltbits) & NFSCTL_TCPBIT) 
5fd2c0
 
5fd2c0
 #define NFSCTL_VERDEFAULT (0xc)       /* versions 3 and 4 */
5fd2c0
 #define NFSCTL_MINDEFAULT (0x7)       /* minor versions 4.1 and 4.2 */
5fd2c0
 #define NFSCTL_VERSET(_cltbits, _v)   ((_cltbits) |= (1 << ((_v) - 1))) 
5fd2c0
+#define NFSCTL_MINORSET(_cltbits, _v)   ((_cltbits) |= (1 << (_v)))
5fd2c0
 #define NFSCTL_UDPSET(_cltbits)       ((_cltbits) |= NFSCTL_UDPBIT)
5fd2c0
 #define NFSCTL_TCPSET(_cltbits)       ((_cltbits) |= NFSCTL_TCPBIT)
5fd2c0
 
5fd2c0
diff -up nfs-utils-1.3.0/utils/nfsd/nfsd.c.orig nfs-utils-1.3.0/utils/nfsd/nfsd.c
5fd2c0
--- nfs-utils-1.3.0/utils/nfsd/nfsd.c.orig	2018-08-20 14:18:13.975034097 -0400
5fd2c0
+++ nfs-utils-1.3.0/utils/nfsd/nfsd.c	2018-08-20 14:18:58.023793505 -0400
5fd2c0
@@ -66,10 +66,12 @@ main(int argc, char **argv)
5fd2c0
 	int	socket_up = 0;
5fd2c0
 	unsigned int minorvers = NFSCTL_MINDEFAULT;
5fd2c0
 	unsigned int minorversset = NFSCTL_MINDEFAULT;
5fd2c0
+	unsigned int minormask = 0;
5fd2c0
 	unsigned int versbits = NFSCTL_VERDEFAULT;
5fd2c0
 	unsigned int protobits = NFSCTL_ALLBITS;
5fd2c0
 	int grace = -1;
5fd2c0
 	int lease = -1;
5fd2c0
+	int force4dot0 = 0;
5fd2c0
 
5fd2c0
 	progname = basename(argv[0]);
5fd2c0
 	haddr = xmalloc(sizeof(char *));
5fd2c0
@@ -103,6 +105,8 @@ main(int argc, char **argv)
5fd2c0
 		else
5fd2c0
 			NFSCTL_VERUNSET(versbits, i);
5fd2c0
 	}
5fd2c0
+
5fd2c0
+	nfssvc_get_minormask(&minormask);
5fd2c0
 	/* We assume the kernel will default all minor versions to 'on',
5fd2c0
 	 * and allow the config file to disable some.
5fd2c0
 	 */
5fd2c0
@@ -118,12 +122,16 @@ main(int argc, char **argv)
5fd2c0
 		 * (i.e. don't set the bit in minorversset).
5fd2c0
 		 */
5fd2c0
 		if (!conf_get_bool("nfsd", tag, 1)) {
5fd2c0
-			NFSCTL_VERSET(minorversset, i);
5fd2c0
-			NFSCTL_VERUNSET(minorvers, i);
5fd2c0
+			NFSCTL_MINORSET(minorversset, i);
5fd2c0
+			NFSCTL_MINORUNSET(minorvers, i);
5fd2c0
+			if (i == 0)
5fd2c0
+				force4dot0 = 1;
5fd2c0
 		}
5fd2c0
 		if (conf_get_bool("nfsd", tag, 0)) {
5fd2c0
-			NFSCTL_VERSET(minorversset, i);
5fd2c0
-			NFSCTL_VERSET(minorvers, i);
5fd2c0
+			NFSCTL_MINORSET(minorversset, i);
5fd2c0
+			NFSCTL_MINORSET(minorvers, i);
5fd2c0
+			if (i == 0)
5fd2c0
+				force4dot0 = 1;
5fd2c0
 		}
5fd2c0
 	}
5fd2c0
 
5fd2c0
@@ -178,13 +186,19 @@ main(int argc, char **argv)
5fd2c0
 			case 4:
5fd2c0
 				if (*p == '.') {
5fd2c0
 					int i = atoi(p+1);
5fd2c0
-					if (i < NFS4_MINMINOR || i > NFS4_MAXMINOR) {
5fd2c0
+					if (i < 0 || i > NFS4_MAXMINOR) {
5fd2c0
 						fprintf(stderr, "%s: unsupported minor version\n", optarg);
5fd2c0
 						exit(1);
5fd2c0
 					}
5fd2c0
-					NFSCTL_VERSET(minorversset, i);
5fd2c0
-					NFSCTL_VERUNSET(minorvers, i);
5fd2c0
-					break;
5fd2c0
+					NFSCTL_MINORSET(minorversset, i);
5fd2c0
+					NFSCTL_MINORUNSET(minorvers, i);
5fd2c0
+					if (i == 0)
5fd2c0
+						force4dot0 = 1;
5fd2c0
+					if (minorvers != 0)
5fd2c0
+						break;
5fd2c0
+				} else {
5fd2c0
+					minorvers = 0;
5fd2c0
+					minorversset = minormask;
5fd2c0
 				}
5fd2c0
 			case 3:
5fd2c0
 			case 2:
5fd2c0
@@ -200,14 +214,16 @@ main(int argc, char **argv)
5fd2c0
 			case 4:
5fd2c0
 				if (*p == '.') {
5fd2c0
 					int i = atoi(p+1);
5fd2c0
-					if (i < NFS4_MINMINOR || i > NFS4_MAXMINOR) {
5fd2c0
+					if (i < 0 || i > NFS4_MAXMINOR) {
5fd2c0
 						fprintf(stderr, "%s: unsupported minor version\n", optarg);
5fd2c0
 						exit(1);
5fd2c0
 					}
5fd2c0
-					NFSCTL_VERSET(minorversset, i);
5fd2c0
-					NFSCTL_VERSET(minorvers, i);
5fd2c0
-					break;
5fd2c0
-				}
5fd2c0
+					NFSCTL_MINORSET(minorversset, i);
5fd2c0
+					NFSCTL_MINORSET(minorvers, i);
5fd2c0
+					if (i == 0)
5fd2c0
+						force4dot0 = 1;
5fd2c0
+				} else
5fd2c0
+					minorvers = minorversset = minormask;
5fd2c0
 			case 3:
5fd2c0
 			case 2:
5fd2c0
 				NFSCTL_VERSET(versbits, c);
5fd2c0
@@ -305,7 +321,7 @@ main(int argc, char **argv)
5fd2c0
 	 * Timeouts must also be set before ports are created else we get
5fd2c0
 	 * EBUSY.
5fd2c0
 	 */
5fd2c0
-	nfssvc_setvers(versbits, minorvers, minorversset);
5fd2c0
+	nfssvc_setvers(versbits, minorvers, minorversset, force4dot0);
5fd2c0
 	if (grace > 0)
5fd2c0
 		nfssvc_set_time("grace", grace);
5fd2c0
 	if (lease  > 0)
5fd2c0
diff -up nfs-utils-1.3.0/utils/nfsd/nfsd.man.orig nfs-utils-1.3.0/utils/nfsd/nfsd.man
5fd2c0
--- nfs-utils-1.3.0/utils/nfsd/nfsd.man.orig	2018-08-20 14:18:13.934033391 -0400
5fd2c0
+++ nfs-utils-1.3.0/utils/nfsd/nfsd.man	2018-08-20 14:18:29.625303910 -0400
5fd2c0
@@ -57,7 +57,7 @@ This option can be used to request that
5fd2c0
 .B rpc.nfsd
5fd2c0
 does not offer certain versions of NFS. The current version of
5fd2c0
 .B rpc.nfsd
5fd2c0
-can support major NFS versions 2,3,4 and the minor versions 4.1 and 4.2.
5fd2c0
+can support major NFS versions 2,3,4 and the minor versions 4.0, 4.1 and 4.2.
5fd2c0
 .TP
5fd2c0
 .B \-s " or " \-\-syslog
5fd2c0
 By default,
5fd2c0
@@ -82,7 +82,7 @@ This option can be used to request that
5fd2c0
 .B rpc.nfsd
5fd2c0
 offer certain versions of NFS. The current version of
5fd2c0
 .B rpc.nfsd
5fd2c0
-can support major NFS versions 2,3,4 and the minor versions 4.1 and 4.2.
5fd2c0
+can support major NFS versions 2,3,4 and the minor versions 4.0, 4.1 and 4.2.
5fd2c0
 .TP
5fd2c0
 .B \-L " or " \-\-lease-time seconds
5fd2c0
 Set the lease-time used for NFSv4.  This corresponds to how often
5fd2c0
diff -up nfs-utils-1.3.0/utils/nfsd/nfssvc.c.orig nfs-utils-1.3.0/utils/nfsd/nfssvc.c
5fd2c0
--- nfs-utils-1.3.0/utils/nfsd/nfssvc.c.orig	2018-08-20 14:18:13.963033891 -0400
5fd2c0
+++ nfs-utils-1.3.0/utils/nfsd/nfssvc.c	2018-08-20 14:18:58.023793505 -0400
5fd2c0
@@ -24,6 +24,7 @@
5fd2c0
 #include "nfslib.h"
5fd2c0
 #include "xlog.h"
5fd2c0
 #include "nfssvc.h"
5fd2c0
+#include "../mount/version.h"
5fd2c0
 
5fd2c0
 #ifndef NFSD_FS_DIR
5fd2c0
 #define NFSD_FS_DIR	  "/proc/fs/nfsd"
5fd2c0
@@ -333,36 +334,81 @@ nfssvc_set_time(const char *type, const
5fd2c0
 }
5fd2c0
 
5fd2c0
 void
5fd2c0
-nfssvc_setvers(unsigned int ctlbits, unsigned int minorvers, unsigned int minorversset)
5fd2c0
+nfssvc_get_minormask(unsigned int *mask)
5fd2c0
+{
5fd2c0
+	int fd;
5fd2c0
+	char *ptr = buf;
5fd2c0
+	ssize_t size;
5fd2c0
+
5fd2c0
+	fd = open(NFSD_VERS_FILE, O_RDONLY);
5fd2c0
+	if (fd < 0)
5fd2c0
+		return;
5fd2c0
+
5fd2c0
+	size = read(fd, buf, sizeof(buf));
5fd2c0
+	if (size < 0) {
5fd2c0
+		xlog(L_ERROR, "Getting versions failed: errno %d (%m)", errno);
5fd2c0
+		goto out;
5fd2c0
+	}
5fd2c0
+	ptr[size] = '\0';
5fd2c0
+	for (;;) {
5fd2c0
+		unsigned vers, minor = 0;
5fd2c0
+		char *token = strtok(ptr, " ");
5fd2c0
+
5fd2c0
+		if (!token)
5fd2c0
+			break;
5fd2c0
+		ptr = NULL;
5fd2c0
+		if (*token != '+' && *token != '-')
5fd2c0
+			continue;
5fd2c0
+		if (sscanf(++token, "%u.%u", &vers, &minor) > 0 &&
5fd2c0
+		    vers == 4 && minor <= NFS4_MAXMINOR)
5fd2c0
+			NFSCTL_MINORSET(*mask, minor);
5fd2c0
+	}
5fd2c0
+out:
5fd2c0
+	close(fd);
5fd2c0
+	return;
5fd2c0
+}
5fd2c0
+
5fd2c0
+static int
5fd2c0
+nfssvc_print_vers(char *ptr, unsigned size, unsigned vers, unsigned minorvers,
5fd2c0
+		int isset, int force4dot0)
5fd2c0
+{
5fd2c0
+	char sign = isset ? '+' : '-';
5fd2c0
+	if (minorvers == 0)
5fd2c0
+		if (linux_version_code() < MAKE_VERSION(4, 11, 0) || !force4dot0)
5fd2c0
+			return snprintf(ptr, size, "%c%u ", sign, vers);
5fd2c0
+	return snprintf(ptr, size, "%c%u.%u ", sign, vers, minorvers);
5fd2c0
+}
5fd2c0
+
5fd2c0
+void
5fd2c0
+nfssvc_setvers(unsigned int ctlbits, unsigned int minorvers, unsigned int minorversset,
5fd2c0
+	       int force4dot0)
5fd2c0
 {
5fd2c0
 	int fd, n, off;
5fd2c0
-	char *ptr;
5fd2c0
 
5fd2c0
-	ptr = buf;
5fd2c0
 	off = 0;
5fd2c0
 	fd = open(NFSD_VERS_FILE, O_WRONLY);
5fd2c0
 	if (fd < 0)
5fd2c0
 		return;
5fd2c0
 
5fd2c0
-	for (n = NFS4_MINMINOR; n <= NFS4_MAXMINOR; n++) {
5fd2c0
-		if (NFSCTL_VERISSET(minorversset, n)) {
5fd2c0
-			if (NFSCTL_VERISSET(minorvers, n))
5fd2c0
-				off += snprintf(ptr+off, sizeof(buf) - off, "+4.%d ", n);
5fd2c0
-			else
5fd2c0
-				off += snprintf(ptr+off, sizeof(buf) - off, "-4.%d ", n);
5fd2c0
-		}
5fd2c0
-	}
5fd2c0
-	for (n = NFSD_MINVERS; n <= NFSD_MAXVERS; n++) {
5fd2c0
-		if (NFSCTL_VERISSET(ctlbits, n))
5fd2c0
-		    off += snprintf(ptr+off, sizeof(buf) - off, "+%d ", n);
5fd2c0
-		else
5fd2c0
-		    off += snprintf(ptr+off, sizeof(buf) - off, "-%d ", n);
5fd2c0
+	for (n = NFSD_MINVERS; n <= ((NFSD_MAXVERS < 3) ? NFSD_MAXVERS : 3); n++)
5fd2c0
+		off += nfssvc_print_vers(&buf[off], sizeof(buf) - off,
5fd2c0
+				n, 0, NFSCTL_VERISSET(ctlbits, n), 0);
5fd2c0
+
5fd2c0
+	for (n = 0; n <= NFS4_MAXMINOR; n++) {
5fd2c0
+		if (!NFSCTL_MINORISSET(minorversset, n))
5fd2c0
+			continue;
5fd2c0
+		off += nfssvc_print_vers(&buf[off], sizeof(buf) - off,
5fd2c0
+				4, n, NFSCTL_MINORISSET(minorvers, n),
5fd2c0
+				(n == 0) ? force4dot0 : 0);
5fd2c0
 	}
5fd2c0
+	if (!off--)
5fd2c0
+		goto out;
5fd2c0
+	buf[off] = '\0';
5fd2c0
 	xlog(D_GENERAL, "Writing version string to kernel: %s", buf);
5fd2c0
-	snprintf(ptr+off, sizeof(buf) - off, "\n");
5fd2c0
+	snprintf(&buf[off], sizeof(buf) - off, "\n");
5fd2c0
 	if (write(fd, buf, strlen(buf)) != (ssize_t)strlen(buf))
5fd2c0
 		xlog(L_ERROR, "Setting version failed: errno %d (%m)", errno);
5fd2c0
-
5fd2c0
+out:
5fd2c0
 	close(fd);
5fd2c0
 
5fd2c0
 	return;
5fd2c0
diff -up nfs-utils-1.3.0/utils/nfsd/nfssvc.h.orig nfs-utils-1.3.0/utils/nfsd/nfssvc.h
5fd2c0
--- nfs-utils-1.3.0/utils/nfsd/nfssvc.h.orig	2018-08-20 14:18:13.934033391 -0400
5fd2c0
+++ nfs-utils-1.3.0/utils/nfsd/nfssvc.h	2018-08-20 14:18:58.023793505 -0400
5fd2c0
@@ -26,5 +26,7 @@ int	nfssvc_set_sockets(const unsigned in
5fd2c0
 			   const char *host, const char *port);
5fd2c0
 void	nfssvc_set_time(const char *type, const int seconds);
5fd2c0
 int	nfssvc_set_rdmaport(const char *port);
5fd2c0
-void	nfssvc_setvers(unsigned int ctlbits, unsigned int minorvers4, unsigned int minorvers4set);
5fd2c0
-int	nfssvc_threads(unsigned short port, int nrservs);
5fd2c0
+void	nfssvc_setvers(unsigned int ctlbits, unsigned int minorvers4,
5fd2c0
+		       unsigned int minorvers4set, int force4dot0);
5fd2c0
+int		nfssvc_threads(unsigned short port, int nrservs);
5fd2c0
+void	nfssvc_get_minormask(unsigned int *mask);