[PATCH 6/7] mount: don't add config-file protcol version options when already present.

NeilBrown
2020-12-16T04:45:00Z

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)