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 2/7] mount: report error if multiple version specifiers are given.
Date: Wed, 16 Dec 2020 15:43:03 +1100 [thread overview]
Message-ID: <160809378307.7232.18431719700214956275.stgit@noble> (raw)
In-Reply-To: <160809318571.7232.10427700322834760606.stgit@noble>
The NFS version can be requested with multiple different options:
v2 v3 v4 v4.x vers=x nfsvers=
If multiple versions are given with different options, the choice of
which wins is quite ideosyncratic. It certainly isn't simple "last one
wins" as with some other options.
Rather than providing a coherent rule, simply make multiple version
specifiers illegal.
This requires enhancing po_contains_prefix() to be able to look beyond
the first match, it see if there are multiple matches with the same
prefix, as well as checking all prefixes to see if more than one
matches.
Signed-off-by: NeilBrown <neilb@suse.de>
---
utils/mount/network.c | 36 ++++++++++++++++++++++--------------
utils/mount/parse_opt.c | 12 +++++++++---
utils/mount/parse_opt.h | 3 ++-
3 files changed, 33 insertions(+), 18 deletions(-)
diff --git a/utils/mount/network.c b/utils/mount/network.c
index d9c0b513101d..e803dbbe5a2c 100644
--- a/utils/mount/network.c
+++ b/utils/mount/network.c
@@ -1269,27 +1269,31 @@ int
nfs_nfs_version(char *type, struct mount_options *options, struct nfs_version *version)
{
char *version_key, *version_val = NULL, *cptr;
- int i, found = 0;
+ int i, found = -1;
version->v_mode = V_DEFAULT;
for (i = 0; nfs_version_opttbl[i]; i++) {
if (po_contains_prefix(options, nfs_version_opttbl[i],
- &version_key) == PO_FOUND) {
- found++;
- break;
+ &version_key, 0) == PO_FOUND) {
+ if (found >= 0)
+ goto ret_error_multiple;
+ if (po_contains_prefix(options, nfs_version_opttbl[i],
+ NULL, 1) == PO_FOUND)
+ goto ret_error_multiple;
+ found = i;
}
}
- if (!found && strcmp(type, "nfs4") == 0)
+ if (found < 0 && strcmp(type, "nfs4") == 0)
version_val = type + 3;
- else if (!found)
+ else if (found < 0)
return 1;
- else if (i <= 2 ) {
+ else if (found <= 2 ) {
/* v2, v3, v4 */
version_val = version_key + 1;
version->v_mode = V_SPECIFIC;
- } else if (i > 2 ) {
+ } else if (found > 2 ) {
/* vers=, nfsvers= */
version_val = po_get(options, version_key);
}
@@ -1303,7 +1307,7 @@ nfs_nfs_version(char *type, struct mount_options *options, struct nfs_version *v
if (version->major == 4 && *cptr != '.' &&
(version_val = po_get(options, "minorversion")) != NULL) {
version->minor = strtol(version_val, &cptr, 10);
- i = -1;
+ found = -1;
if (*cptr)
goto ret_error;
version->v_mode = V_SPECIFIC;
@@ -1319,7 +1323,7 @@ nfs_nfs_version(char *type, struct mount_options *options, struct nfs_version *v
if (version_val != NULL) {
version->minor = strtol(version_val, &cptr, 10);
version->v_mode = V_SPECIFIC;
- } else
+ } else
version->v_mode = V_GENERAL;
}
if (*cptr != '\0')
@@ -1327,17 +1331,21 @@ nfs_nfs_version(char *type, struct mount_options *options, struct nfs_version *v
return 1;
+ret_error_multiple:
+ nfs_error(_("%s: multiple version options not permitted"),
+ progname);
+ found = 10; /* avoid other errors */
ret_error:
- if (i < 0) {
+ if (found < 0) {
nfs_error(_("%s: parsing error on 'minorversion=' option"),
progname);
- } else if (i <= 2 ) {
+ } else if (found <= 2 ) {
nfs_error(_("%s: parsing error on 'v' option"),
progname);
- } else if (i == 3 ) {
+ } else if (found == 3 ) {
nfs_error(_("%s: parsing error on 'vers=' option"),
progname);
- } else if (i == 4) {
+ } else if (found == 4) {
nfs_error(_("%s: parsing error on 'nfsvers=' option"),
progname);
}
diff --git a/utils/mount/parse_opt.c b/utils/mount/parse_opt.c
index 7ba61c4e52d8..b6065cad2888 100644
--- a/utils/mount/parse_opt.c
+++ b/utils/mount/parse_opt.c
@@ -414,19 +414,25 @@ po_found_t po_contains(struct mount_options *options, char *keyword)
* @options: pointer to mount options
* @prefix: pointer to prefix to match against a keyword
* @keyword: pointer to a C string containing the option keyword if found
+ * @n: number of instances to skip, so '0' returns the first.
*
* On success, *keyword contains the pointer of the matching option's keyword.
*/
po_found_t po_contains_prefix(struct mount_options *options,
- const char *prefix, char **keyword)
+ const char *prefix, char **keyword, int n)
{
struct mount_option *option;
if (options && prefix) {
for (option = options->head; option; option = option->next)
if (strncmp(option->keyword, prefix, strlen(prefix)) == 0) {
- *keyword = option->keyword;
- return PO_FOUND;
+ if (n > 0) {
+ n -= 1;
+ } else {
+ if (keyword)
+ *keyword = option->keyword;
+ return PO_FOUND;
+ }
}
}
diff --git a/utils/mount/parse_opt.h b/utils/mount/parse_opt.h
index 0745e0f0833e..0a153768d434 100644
--- a/utils/mount/parse_opt.h
+++ b/utils/mount/parse_opt.h
@@ -46,7 +46,8 @@ po_return_t po_join(struct mount_options *, char **);
po_return_t po_append(struct mount_options *, char *);
po_found_t po_contains(struct mount_options *, char *);
po_found_t po_contains_prefix(struct mount_options *options,
- const char *prefix, char **keyword);
+ const char *prefix, char **keyword,
+ int n);
char * po_get(struct mount_options *, char *);
po_found_t po_get_numeric(struct mount_options *,
char *, long *);
next prev parent reply other threads:[~2020-12-16 4:44 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 4/7] mount: convert configfile.c to use parse_opt.c 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 ` NeilBrown [this message]
2020-12-16 4:43 ` [PATCH 7/7] mount: update nfsmount.conf man page NeilBrown
2020-12-16 4:43 ` [PATCH 6/7] mount: don't add config-file protcol version options when already present NeilBrown
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=160809378307.7232.18431719700214956275.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