2019-10-22 17:17:20

by Alice Mitchell

[permalink] [raw]
Subject: [PATCH nfs-utils] Simplify vers string generation to fix issues with 4.0 handling

The existing handling does not correctly cope the case of disabling
v4.0 and then later not disabling it, the default strings omit the 4.0
flags and it thus does not get re-enabled. this simplified version
correctly handles this and other similar cases.

Signed-off-by: Alice J Mitchell <[email protected]>
---
utils/nfsd/nfsd.c | 11 +----------
utils/nfsd/nfssvc.c | 21 ++++++++++-----------
utils/nfsd/nfssvc.h | 2 +-
3 files changed, 12 insertions(+), 22 deletions(-)

diff --git a/utils/nfsd/nfsd.c b/utils/nfsd/nfsd.c
index a412a02..0c1f6cb 100644
--- a/utils/nfsd/nfsd.c
+++ b/utils/nfsd/nfsd.c
@@ -72,7 +72,6 @@ main(int argc, char **argv)
unsigned int protobits = NFSCTL_PROTODEFAULT;
int grace = -1;
int lease = -1;
- int force4dot0 = 0;

progname = basename(argv[0]);
haddr = xmalloc(sizeof(char *));
@@ -141,14 +140,10 @@ main(int argc, char **argv)
if (!conf_get_bool("nfsd", tag, 1)) {
NFSCTL_MINORSET(minorversset, i);
NFSCTL_MINORUNSET(minorvers, i);
- if (i == 0)
- force4dot0 = 1;
}
if (conf_get_bool("nfsd", tag, 0)) {
NFSCTL_MINORSET(minorversset, i);
NFSCTL_MINORSET(minorvers, i);
- if (i == 0)
- force4dot0 = 1;
}
}

@@ -209,8 +204,6 @@ main(int argc, char **argv)
}
NFSCTL_MINORSET(minorversset, i);
NFSCTL_MINORUNSET(minorvers, i);
- if (i == 0)
- force4dot0 = 1;
if (minorvers != 0)
break;
} else {
@@ -238,8 +231,6 @@ main(int argc, char **argv)
}
NFSCTL_MINORSET(minorversset, i);
NFSCTL_MINORSET(minorvers, i);
- if (i == 0)
- force4dot0 = 1;
} else
minorvers = minorversset = minormask;
/* FALLTHRU */
@@ -356,7 +347,7 @@ main(int argc, char **argv)
* Timeouts must also be set before ports are created else we get
* EBUSY.
*/
- nfssvc_setvers(versbits, minorvers, minorversset, force4dot0);
+ nfssvc_setvers(versbits, minorvers, minorversset);
if (grace > 0)
nfssvc_set_time("grace", grace);
if (lease > 0)
diff --git a/utils/nfsd/nfssvc.c b/utils/nfsd/nfssvc.c
index 720bdd9..1770ac2 100644
--- a/utils/nfsd/nfssvc.c
+++ b/utils/nfsd/nfssvc.c
@@ -368,19 +368,17 @@ out:
}

static int
-nfssvc_print_vers(char *ptr, unsigned size, unsigned vers, unsigned minorvers,
- int isset, int force4dot0)
+nfssvc_print_vers(char *ptr, unsigned size, unsigned vers, int minorvers,
+ int isset)
{
char sign = isset ? '+' : '-';
- if (minorvers == 0)
- if (linux_version_code() < MAKE_VERSION(4, 11, 0) || !force4dot0)
- return snprintf(ptr, size, "%c%u ", sign, vers);
+ if (minorvers < 0)
+ return snprintf(ptr, size, "%c%u ", sign, vers);
return snprintf(ptr, size, "%c%u.%u ", sign, vers, minorvers);
}

void
-nfssvc_setvers(unsigned int ctlbits, unsigned int minorvers, unsigned int minorversset,
- int force4dot0)
+nfssvc_setvers(unsigned int ctlbits, unsigned int minorvers, unsigned int minorversset)
{
int fd, n, off;

@@ -389,16 +387,17 @@ nfssvc_setvers(unsigned int ctlbits, unsigned int minorvers, unsigned int minorv
if (fd < 0)
return;

- for (n = NFSD_MINVERS; n <= ((NFSD_MAXVERS < 3) ? NFSD_MAXVERS : 3); n++)
+ for (n = NFSD_MINVERS; n <= ((NFSD_MAXVERS < 4) ? NFSD_MAXVERS : 4); n++)
off += nfssvc_print_vers(&buf[off], sizeof(buf) - off,
- n, 0, NFSCTL_VERISSET(ctlbits, n), 0);
+ n, -1, NFSCTL_VERISSET(ctlbits, n));

for (n = 0; n <= NFS4_MAXMINOR; n++) {
if (!NFSCTL_MINORISSET(minorversset, n))
continue;
+ if (n == 0 && linux_version_code() < MAKE_VERSION(4, 11, 0))
+ continue;
off += nfssvc_print_vers(&buf[off], sizeof(buf) - off,
- 4, n, NFSCTL_MINORISSET(minorvers, n),
- (n == 0) ? force4dot0 : 0);
+ 4, n, NFSCTL_MINORISSET(minorvers, n));
}
if (!off--)
goto out;
diff --git a/utils/nfsd/nfssvc.h b/utils/nfsd/nfssvc.h
index 4d53af1..bf747b7 100644
--- a/utils/nfsd/nfssvc.h
+++ b/utils/nfsd/nfssvc.h
@@ -27,6 +27,6 @@ int nfssvc_set_sockets(const unsigned int protobits,
void nfssvc_set_time(const char *type, const int seconds);
int nfssvc_set_rdmaport(const char *port);
void nfssvc_setvers(unsigned int ctlbits, unsigned int minorvers4,
- unsigned int minorvers4set, int force4dot0);
+ unsigned int minorvers4set);
int nfssvc_threads(int nrservs);
void nfssvc_get_minormask(unsigned int *mask);
--
1.8.3.1