From patchwork Tue Oct 22 16:29:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alice Mitchell X-Patchwork-Id: 11204825 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B74D2139A for ; Tue, 22 Oct 2019 16:29:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8B2172084B for ; Tue, 22 Oct 2019 16:29:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Q6eNHdwj" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732674AbfJVQ31 (ORCPT ); Tue, 22 Oct 2019 12:29:27 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:56670 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732660AbfJVQ31 (ORCPT ); Tue, 22 Oct 2019 12:29:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571761766; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=oc6JnYHv+WR7BhcilrYjRg6zWiQBk7nW50+Iq/r7Bm0=; b=Q6eNHdwjxjk3HeUKXxGH4FSuwnWUQhzwNaZpcM5l5yC5HCrvNSbOGUYC4dUSC10M8LeX86 LuqKC0K9j5X+u1TdrC1yhyYTjx3Rww97p0gVwb6QAzZf7L8i2BBSz3ZQZvAbD3wiApPfuB KR3pxZYGLCBLlneezjs1WnuKYCDIG18= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-78-a15Sj9ynOKKWciYI_Ynvmw-1; Tue, 22 Oct 2019 12:29:24 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E191B1005500 for ; Tue, 22 Oct 2019 16:29:23 +0000 (UTC) Received: from jumitche.remote.csb (unknown [10.33.36.91]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 655486012D for ; Tue, 22 Oct 2019 16:29:23 +0000 (UTC) Message-ID: <1571761761.9226.3.camel@redhat.com> Subject: [PATCH nfs-utils] Simplify vers string generation to fix issues with 4.0 handling From: Alice J Mitchell To: Linux NFS Mailing List Date: Tue, 22 Oct 2019 17:29:21 +0100 Mime-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: a15Sj9ynOKKWciYI_Ynvmw-1 X-Mimecast-Spam-Score: 0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org 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 --- 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);