public inbox for linux-nfs@vger.kernel.org
 help / color / mirror / Atom feed
From: NeilBrown <neilb@suse.de>
To: Steve Dickson <steved@redhat.com>
Cc: Justin Mitchell <jumitche@redhat.com>,
	Benjamin Coddington <bcodding@redhat.com>,
	linux-nfs@vger.kernel.org
Subject: [PATCH 6/7] mount: don't add config-file protcol version options when already present.
Date: Wed, 16 Dec 2020 15:43:03 +1100	[thread overview]
Message-ID: <160809378308.7232.14269291283808304181.stgit@noble> (raw)
In-Reply-To: <160809318571.7232.10427700322834760606.stgit@noble>

If there is already an option specifying the protocol version, whether
from the command line or from an earlier config section, don't add new
version options.

There are multiple different version options, so they need to be handled
differently from other options.  There could in the future be more
options that start "v4.", e.g.  "v4.3" might happen one day.  So rather
than list possible "v4.x" options, handle "v4." separately.

Signed-off-by: NeilBrown <neilb@suse.de>
---
 utils/mount/configfile.c |   26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/utils/mount/configfile.c b/utils/mount/configfile.c
index 40378ab247fc..7934f4f625d9 100644
--- a/utils/mount/configfile.c
+++ b/utils/mount/configfile.c
@@ -70,8 +70,23 @@ struct mnt_alias {
 };
 int mnt_alias_sz = (sizeof(mnt_alias_tab)/sizeof(mnt_alias_tab[0]));
 
+static const char *version_keys[] = {
+	"v2", "v3", "v4", "vers", "nfsvers", "minorversion", NULL
+};
+
 static int strict;
 
+static int is_version(const char *field)
+{
+	int i;
+	for (i = 0; version_keys[i] ; i++)
+		if (strcmp(version_keys[i], field) == 0)
+			return 1;
+	if (strncmp(field, "v4.", 3) == 0)
+		return 1;
+	return 0;
+}
+
 /*
  * See if the option is an alias, if so return the
  * real mount option along with the argument type.
@@ -195,6 +210,11 @@ conf_parse_mntopts(char *section, char *arg, struct mount_options *options)
 	char buf[BUFSIZ], *value, *field;
 	char *nvalue, *ptr;
 	int argtype;
+	int have_version = 0;
+
+	if (po_rightmost(options, version_keys) >= 0 ||
+	    po_contains_prefix(options, "v4.", NULL, 0) == PO_FOUND)
+		have_version = 1;
 
 	list = conf_get_tag_list(section, arg);
 	TAILQ_FOREACH(node, &list->fields, link) {
@@ -226,6 +246,12 @@ conf_parse_mntopts(char *section, char *arg, struct mount_options *options)
 		    po_contains(options, "fg") == PO_FOUND)
 			continue;
 
+		if (is_version(field)) {
+			if (have_version)
+				continue;
+			have_version = 1;
+		}
+
 		buf[0] = '\0';
 		value = conf_get_section(section, arg, node->field);
 		if (value == NULL)



  parent reply	other threads:[~2020-12-16  4:45 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-16  4:43 [PATCH 0/7 nfs-utils] Assorted improvements to handling nfsmount.conf NeilBrown
2020-12-16  4:43 ` [PATCH 5/7] mount: options in config file shouldn't over-ride command-line options NeilBrown
2020-12-16  4:43 ` [PATCH 2/7] mount: report error if multiple version specifiers are given NeilBrown
2020-12-16  4:43 ` [PATCH 4/7] mount: convert configfile.c to use parse_opt.c NeilBrown
2020-12-16  4:43 ` [PATCH 7/7] mount: update nfsmount.conf man page NeilBrown
2020-12-16  4:43 ` NeilBrown [this message]
2020-12-16  4:43 ` [PATCH 1/7] mount: configfile: remove whitesspace from end of lines NeilBrown
2020-12-16  4:43 ` [PATCH 3/7] Revert "mount.nfs: merge in vers= and nfsvers= options" NeilBrown
2020-12-17 15:11 ` [PATCH 0/7 nfs-utils] Assorted improvements to handling nfsmount.conf Steve Dickson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=160809378308.7232.14269291283808304181.stgit@noble \
    --to=neilb@suse.de \
    --cc=bcodding@redhat.com \
    --cc=jumitche@redhat.com \
    --cc=linux-nfs@vger.kernel.org \
    --cc=steved@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox