Skip to contentSkip to conversation

Allow vers=4 and nfsvers=4 mount options

PATCH In review Kevin Constantine 3 participants 7 messages May 5, 2009 – May 7, 2009 4 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

I've run into a problem recently while trying to set up an environment for testing nfsv4. In our environment, we have a mixture of Linux, and OSX, and all of our mounts are made via automount maps stored in LDAP which are shared among the platforms. The problem is made even more complicated by the fact that some of our file servers support v4, while others do not. This means that v4 mounts need to be specified on a mount by mount basis, and only on certain test machines.

With nfsv4, Linux appears to use fstype=nfs4 to distinguish between v2,3 and v4, and attempts to specify vers=4, or nfsvers=4 error. OSX doesn't understand fstype and mounts error when this option is encountered. OSX instead relies on vers=2,3,4 or nfsvers=2,3,4 to determine the version. It appears that Solaris will likely behave the same way as OSX based on the manpage, though I haven't tested it.

I've written the following patches to allow vers=4, and nfsvers=4 to be passed to the mount command. There's a patch for the text-based mount, and a second for the older style mount options. In both cases, I attempt to detect the vers= option as early as possible in order to set fstype=nfs4, and then let the code continue on as though the user had specified fstype=nfs4 on the command line.

Using these patches, I can now specify something like:

pamtest4  -rw,intr,hard,timeo=600$RSZ,vers=$NFSVERS     supportsv4:/vol/someexport
pamtest3  -rw,intr,hard,timeo=600$RSZ                   supportsv3only:/vol/v3export

in the automount map. The variable $NFSVERS is set to 4 on the test clients, and 3 on production Linux machines, and OSX.

[PATCH 1/2] Allow nfs/vers=4 option in old style mount commands [PATCH 2/2] Allow nfs/vers=4 option in text-based mount commands

-kevin

A message that is not in the archive (sent off-list or not yet received): 1241560004-16787-1-git-send-email-kevin.constantine-FfNkGbSheRGpB8w63BLUukEOCMrvLtNR@public.gmane.org

#2 lore raw

PATCH 1/2 Allow nfs/vers=4 option in old style mount commands

This allows a user to specify nfsvers=4, or vers=4 on the mount commandline and have mount.nfs4 called as though fstype=nfs4 were specified. This patch handles the nfs4mount, and nfsmount cases in try_mount().

Added the function find_rightmost() to return the rightmost option in the extra_opts string. If vers=4 is overridden later in the string by vers=3, we need to honor that.

---
 utils/mount/mount.c |   41 ++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 40 insertions(+), 1 deletions(-)
utils/mount/mount.c +40 -1
index 06e2804..4cebc0f 100644
@@ -444,11 +444,38 @@ static int try_mount(char *spec, char *mount_point, int flags,
 	return ret;
 }
 
+static void find_rightmost(char *extra_opts, char *search_opt, char **rightmost_opt)
+{
+	char *opts = xstrdup(extra_opts);
+	char *right_opt = NULL, *token = NULL;
+	int i = 0;
+
+	for (;;) {
+		if (i == 0) {
+			token = strtok(opts, ",");
+			i++;
+		}
+		else 
+			token = strtok(NULL, ",");
+
+		if (token == NULL) 
+			break;
+		if (! strncmp(token, search_opt, strlen(search_opt))) 
+			right_opt = xstrdup(token);
+	}
+	if (right_opt != NULL) {
+		*rightmost_opt = xmalloc(strlen(right_opt));
+		strcpy(*rightmost_opt, right_opt);
+	}
+	free(opts);
+	free(right_opt);
+}
+
 int main(int argc, char *argv[])
 {
 	int c, flags = 0, mnt_err = 1, fake = 0;
 	char *spec, *mount_point, *fs_type = "nfs";
-	char *extra_opts = NULL, *mount_opts = NULL;
+	char *extra_opts = NULL, *mount_opts = NULL, *vers_opt=NULL;
 	uid_t uid = getuid();
 
 	progname = basename(argv[0]);
@@ -562,6 +589,18 @@ int main(int argc, char *argv[])
 
 	parse_opts(mount_opts, &flags, &extra_opts);
 
+	find_rightmost(extra_opts, "vers", &vers_opt);
+	if (vers_opt != NULL) {
+		if ((strcmp(vers_opt, "vers=4")) == 0) 
+			fs_type = "nfs4";
+	}
+
+	find_rightmost(extra_opts, "nfsvers", &vers_opt);
+	if (vers_opt != NULL) {
+		if ((strcmp(vers_opt, "nfsvers=4")) == 0) 
+			fs_type = "nfs4";
+	}
+
 	if (uid != 0) {
 		if (!(flags & (MS_USERS|MS_USER))) {
 			nfs_error(_("%s: permission denied"), progname);
Signature · 1 line
1.6.2.1

A message that is not in the archive (sent off-list or not yet received): 1241560004-16787-2-git-send-email-kevin.constantine-FfNkGbSheRGpB8w63BLUukEOCMrvLtNR@public.gmane.org

#4 lore raw

PATCH 2/2 Allow nfs/vers=4 option in text-based mount commands

This allows a user to specify nfsvers=4, or vers=4 on the mount commandline and have mount.nfs4 called as though fstype=nfs4 were specified. This patch handles the nfsmount_string case in mount.c's try_mount().

We get the value of the "vers=" or "nfsvers=" from the nfsmount_info structure, and if the value equals 4, we set the fstype to nfs4, and remove the nfsvers/vers options from the structure since it shouldn't be there in the first place, and we don't want to pass it along down the stack.

po_get_numeric returns the rightmost instance, so we honor the last value of nfsvers/vers in the event that it is overridden later in the options string.

---
 utils/mount/stropts.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
utils/mount/stropts.c +9 -0
index c369136..72b0d13 100644
@@ -754,6 +754,15 @@ static const char *nfs_background_opttbl[] = {
 
 static int nfsmount_start(struct nfsmount_info *mi)
 {
+	long tmp;
+	po_get_numeric(mi->options, "vers", &tmp);
+	po_get_numeric(mi->options, "nfsvers", &tmp);
+	if (tmp == 4) {
+		mi->type = "nfs4";
+		po_remove_all(mi->options, "vers");
+		po_remove_all(mi->options, "nfsvers");
+	}
+
 	if (!nfs_validate_options(mi))
 		return EX_FAIL;
 
Signature · 1 line
1.6.2.1

A message that is not in the archive (sent off-list or not yet received): 1241560004-16787-3-git-send-email-kevin.constantine-FfNkGbSheRGpB8w63BLUukEOCMrvLtNR@public.gmane.org

#6 lore raw

Re: [PATCH 2/2] Allow nfs/vers=4 option in text-based mount commands

Quoted 26 lines · Kevin Constantine

This allows a user to specify nfsvers=4, or vers=4 on the mount commandline and have mount.nfs4 called as though fstype=nfs4 were specified. This patch handles the nfsmount_string case in mount.c's try_mount().

We get the value of the "vers=" or "nfsvers=" from the nfsmount_info structure, and if the value equals 4, we set the fstype to nfs4, and remove the nfsvers/vers options from the structure since it shouldn't be there in the first place, and we don't want to pass it along down the stack.

po_get_numeric returns the rightmost instance, so we honor the last value of nfsvers/vers in the event that it is overridden later in the options string.

Quoted 1 line

---
utils/mount/stropts.c | 9 +++++++++

1 files changed, 9 insertions(+), 0 deletions(-)
utils/mount/stropts.c +0 -0
index c369136..72b0d13 100644

utils/mount/stropts.c static const char *nfs_background_opttbl[] = { · line 759

Quoted 6 lines
utils/mount/stropts.c +3 -0
@@ -754,6 +754,15 @@ static const char *nfs_background_opttbl[] = {
 
 static int nfsmount_start(struct nfsmount_info *mi)
 {
+	long tmp;
+	po_get_numeric(mi->options, "vers", &tmp);
+	po_get_numeric(mi->options, "nfsvers", &tmp);

If someone specifies both a vers= and a nfsvers= on the command line, this won't handle it. You need to implement a rightmost search, as Steve's patch (posted previously on this list) did.

Quoted 16 lines
utils/mount/stropts.c +6 -0
+	if (tmp == 4) {
+		mi->type = "nfs4";
+		po_remove_all(mi->options, "vers");
+		po_remove_all(mi->options, "nfsvers");
+	}
+
 	if (!nfs_validate_options(mi))
 		return EX_FAIL;
 
Signature · 6 lines
1.6.2.1

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Chuck Lever
chuck[dot]lever[at]oracle[dot]com
#7 lore raw

Re: [PATCH 2/2] Allow nfs/vers=4 option in text-based mount commands

Quoted 29 lines · Chuck Lever
Quoted 26 lines · Kevin Constantine

This allows a user to specify nfsvers=4, or vers=4 on the mount commandline and have mount.nfs4 called as though fstype=nfs4 were specified. This patch handles the nfsmount_string case in mount.c's try_mount().

We get the value of the "vers=" or "nfsvers=" from the nfsmount_info structure, and if the value equals 4, we set the fstype to nfs4, and remove the nfsvers/vers options from the structure since it shouldn't be there in the first place, and we don't want to pass it along down the stack.

po_get_numeric returns the rightmost instance, so we honor the last value of nfsvers/vers in the event that it is overridden later in the options string.

---
utils/mount/stropts.c | 9 +++++++++

1 files changed, 9 insertions(+), 0 deletions(-)
utils/mount/stropts.c +0 -0
index c369136..72b0d13 100644
@@ -754,6 +754,15 @@ static const char *nfs_background_opttbl[] = {
 
Quoted 8 lines

utils/mount/stropts.c static const char *nfs_background_opttbl[] = { · line 759

Quoted 5 lines
utils/mount/stropts.c +3 -0
 static int nfsmount_start(struct nfsmount_info *mi)
 {
+    long tmp;
+    po_get_numeric(mi->options, "vers", &tmp);
+    po_get_numeric(mi->options, "nfsvers", &tmp);

If someone specifies both a vers= and a nfsvers= on the command line, this won't handle it. You need to implement a rightmost search, as Steve's patch (posted previously on this list) did.

I can't seem to find Steve's patches relating to this issue. I'm assuming that since there are already patches related to this, it's not worth pursuing these particular patches.

Let me know

-kevin

Quoted 17 lines
Quoted 16 lines
utils/mount/stropts.c +6 -0
+    if (tmp == 4) {
+        mi->type = "nfs4";
+        po_remove_all(mi->options, "vers");
+        po_remove_all(mi->options, "nfsvers");
+    }
+
    if (!nfs_validate_options(mi))
        return EX_FAIL;
 
Signature · 6 lines
1.6.2.1

-- 
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Signature · 8 lines
------------------------------------------------------------
Kevin Constantine

Systems Engineer		t: 818.460.8221
Walt Disney Animation Studios	e: kevin.constantine-P5ys19MLBK/[email protected]

Any sufficiently advanced technology is indistinguishable from magic.
    - Arthur C. Clarke

A message that is not in the archive (sent off-list or not yet received): 4A033E7C.9060605-P5ys19MLBK/[email protected]

#9 lore raw

Re: [PATCH 2/2] Allow nfs/vers=4 option in text-based mount commands

Quoted 29 lines · Kevin Constantine
Quoted 28 lines · Chuck Lever
Quoted 27 lines · Kevin Constantine

This allows a user to specify nfsvers=4, or vers=4 on the mount commandline and have mount.nfs4 called as though fstype=nfs4 were specified. This patch handles the nfsmount_string case in mount.c's try_mount().

We get the value of the "vers=" or "nfsvers=" from the nfsmount_info structure, and if the value equals 4, we set the fstype to nfs4, and remove the nfsvers/vers options from the structure since it shouldn't be there in the first place, and we don't want to pass it along down the stack.

po_get_numeric returns the rightmost instance, so we honor the last value of nfsvers/vers in the event that it is overridden later in the options string.

Quoted 1 line

---
utils/mount/stropts.c | 9 +++++++++

1 files changed, 9 insertions(+), 0 deletions(-)
utils/mount/stropts.c +0 -0
index c369136..72b0d13 100644
@@ -754,6 +754,15 @@ static const char *nfs_background_opttbl[] = {
 
Quoted 8 lines
Quoted 6 lines

utils/mount/stropts.c static const char *nfs_background_opttbl[] = { · line 759

Quoted 5 lines
utils/mount/stropts.c +3 -0
 static int nfsmount_start(struct nfsmount_info *mi)
 {
+    long tmp;
+    po_get_numeric(mi->options, "vers", &tmp);
+    po_get_numeric(mi->options, "nfsvers", &tmp);

If someone specifies both a vers= and a nfsvers= on the command line, this won't handle it. You need to implement a rightmost search, as Steve's patch (posted previously on this list) did.

I can't seem to find Steve's patches relating to this issue. I'm assuming that since there are already patches related to this, it's not worth pursuing these particular patches.

It was on the NFSv4 mailing list. Sorry about that.

Hi Steve-

Yep, this is the idea. Comments below.

Quoted 54 lines · Steve Dickson
Quoted 42 lines · Chuck Lever
Quoted 15 lines · Steve Dickson
Quoted 6 lines · Chuck Lever

Hi Steve-

You could limit this to just text-based mounts, then the existing option
parser would handle most of this for you.

I took a look at that approach... Basically have parse_opts() and/or parse_opt() do the work figuring out what nfsvers or vers is set to. But the problem with that, I would have to pass down the address of fs_type pointer so I could overwritten... Adding that extra parameter
I didn't think was the best approach... bordering on the hacky side...

Quoted 5 lines

So took the approach of lets set file system type once and only once...
Unfortunately that approach does call for me to strip out the "nfsvers"
or "vers" string from that options string...

The text-based path uses a single data structure, nfs_mountinfo, which
carries all the mount data through the whole code path. In nfsmount_start() you can add a little logic that resets the fs_type (in
the .type field) before proceeding with the rest of the mount.

You would also need to expose nfs_nfs_version() in utils/mount/ network.c
(and add support for version 4) so you can handle the case where someone
specifies "vers=" more than once on the command line (or specifies something obnoxious like "v2,nfsvers=4,vers=3", and you can also detect
"v4" here as well.

There is code at the top of nfs_construct_new_options() which provides
an example of how to easily strip out the existing vers options.

Quoted 6 lines

So nfsmount_start() could call nfs_nfs_version to see what version to use if the passed-in fs_type is "nfs", and if it's version 4, just remove all the vers options, and say 'mi.type = "nfs4";'.

All that assumes you don't care about providing nfsvers=4 support for legacy non-text-based mounts.

Here is the patch implementing your suggestion...

The patches are about the same size... As you mentioned this patch does not provide legacy support, which may or may not matter...

Quoted 7 lines

Both patches have to remove the version option from the list pumped down to the kernel, since the option will cause the kernel routines to error out... Its much cleaner to remove moved the option 'mount_options' list than stripping the option from the string.

So I guess it comes down to do we really care about legacy support??

I don't have a strong opinion, but my preference would be to leave enhancements like this to text-based mounts only.

Quoted 33 lines

steved.

Using only the string option parsing routine, allow the file system type to be changed to 'nfs4' when the NFS version options are specified.

-----------

utils/mount/network.c +7 -0
index bcd0c0f..612c9c2 100644
@@ -94,6 +94,12 @@ static const char *nfs_version_opttbl[] = {
 	"nfsvers",
 	NULL,
 };
+static const char *nfs_fstype_opttbl[] = {
+	"v4",
+	"vers",
+	"nfsvers",
+	NULL,
+};
 
 static const unsigned long nfs_to_mnt[] = {
 	0,
@@ -1242,6 +1248,47 @@ static rpcvers_t nfs_nfs_version(struct  
 mount_options *options)
 }
 
 /*
+ * Returns either "nfs" or "nfs4" as the file system type

utils/mount/network.c static rpcvers_t nfs_nfs_version(struct · line 1262

Quoted 10 lines
utils/mount/network.c +10 -0
+ * depending on which (if any) of the nfs version options
+ * are specified.
+ */
+char *nfs_fs_type(struct mount_options *options)
+{
+	char *keyword;
+	long tmp;
+	static char *fs_type = "nfs";
+
+	switch (po_rightmost(options, nfs_fstype_opttbl)) {

As far as I recall, we recently fixed po_rightmost() to return a C- style array offset. Shouldn't the cases be 0, 1, and 2?

Quoted 14 lines
utils/mount/network.c +14 -0
+	case 2: /* v4 */
+		keyword = "v4";
+		break;
+	case 3:	/* vers */
+		if (po_get_numeric(options, "vers", &tmp) == PO_FOUND)
+			if (tmp != 4)
+				return fs_type;
+		keyword = "vers";
+		break;
+	case 4: /* nfsvers */
+		if (po_get_numeric(options, "nfsvers", &tmp) == PO_FOUND)
+			if (tmp != 4)
+				return fs_type;
+		keyword = "nfsvers";

utils/mount/network.c static rpcvers_t nfs_nfs_version(struct · line 1286

Quoted 10 lines
utils/mount/network.c +10 -0
+		break;
+	default:
+		return fs_type;
+	}
+
+	/*
+	 * Need to remove the v4 version option from the
+	 * list since the kernel will not how to parse it.
+	 */
+	po_remove_all(options, keyword);

You always need to remove all of "nfsvers," "vers", "v2", "v3", and "v4" if this is a nfs4 mount. The reason for this is to make sure the user hasn't specified something bogus like "nfsvers=2,vers=3,v4". In that case the correct behavior is to do a "nfs4" mount and strip out all verison options. For something like "v4,nfsvers=3,vers=2" the correct behavior is to do a "nfs" mount and remove any v4-related version options (which the kernel won't like). The rule is "rightmost wins".

So you need two exits from this function:

* for "nfs" mounts, return "nfs" and make sure any of "v4"
"nfsvers=4" or "vers=4" are removed, and

* for "nfs4" mounts, return "nfs4" and strip all version options
from the mount string.

utils/mount/network.c static rpcvers_t nfs_nfs_version(struct · line 1289

Quoted 3 lines
utils/mount/network.c +3 -0
+	fs_type = "nfs4";
+
+	return fs_type;

I'm pretty sure you can get the same effect (returning a statically allocated character string) with:

	return "nfs4";
Quoted 12 lines
utils/mount/network.c +3 -0
+}
+
+/*
 * Returns the NFS transport protocol specified by the given mount  

options
*
* Returns the IPPROTO_ value specified by the given mount options, or

utils/mount/network.h +0 -0
index 0dd90f8..203e728 100644

utils/mount/network.h void nfs_options2pmap(struct mount_options *, · line 67

Quoted 4 lines
utils/mount/network.h +1 -0
@@ -64,6 +64,7 @@ void nfs_options2pmap(struct mount_options *,
 int start_statd(void);
 
 unsigned long nfsvers_to_mnt(const unsigned long);
+char *nfs_fs_type(struct mount_options *);

If you're not going to use nfs_nfs_version() at all, then this function would be better off living in utils/mount/stropts.c. network.c is just for the network-related functions (like creating a socket, handling DNS lookups, or doing getport calls), and they are generally shared between legacy and text-based support. This is clearly going to be a text-based-only kind of thing.

Quoted 7 lines
utils/mount/network.h +0 -0
 int nfs_call_umount(clnt_addr_t *, dirpath *);
 int nfs_advise_umount(const struct sockaddr *, const socklen_t,
utils/mount/stropts.c +0 -0
index c369136..7a4f533 100644

utils/mount/stropts.c static const char *nfs_background_opttbl[] = { · line 761

Quoted 8 lines
utils/mount/stropts.c +3 -0
@@ -754,6 +754,9 @@ static const char *nfs_background_opttbl[] = {
 
 static int nfsmount_start(struct nfsmount_info *mi)
 {
+
+	mi->type = nfs_fs_type(mi->options);
+
 	if (!nfs_validate_options(mi))
 		return EX_FAIL;

--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com
_______________________________________________
NFSv4 mailing list
[email protected]
http://linux-nfs.org/cgi-bin/mailman/listinfo/nfsv4

--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com

#10 lore raw

Re: [PATCH 1/2] Allow nfs/vers=4 option in old style mount commands

In reply to a message not in the archive
Quoted 62 lines · Kevin Constantine

This allows a user to specify nfsvers=4, or vers=4 on the mount commandline and have mount.nfs4 called as though fstype=nfs4 were specified. This patch handles the nfs4mount, and nfsmount cases in try_mount().

Added the function find_rightmost() to return the rightmost option in the extra_opts string. If vers=4 is overridden later in the string by vers=3, we need to honor that.

Quoted 1 line

---
utils/mount/mount.c | 41 ++++++++++++++++++++++++++++++++++++++++-

1 files changed, 40 insertions(+), 1 deletions(-)
utils/mount/mount.c +28 -1
index 06e2804..4cebc0f 100644
@@ -444,11 +444,38 @@ static int try_mount(char *spec, char  
 *mount_point, int flags,
 	return ret;
 }
 
+static void find_rightmost(char *extra_opts, char *search_opt, char  
 **rightmost_opt)
+{
+	char *opts = xstrdup(extra_opts);
+	char *right_opt = NULL, *token = NULL;
+	int i = 0;
+
+	for (;;) {
+		if (i == 0) {
+			token = strtok(opts, ",");
+			i++;
+		}
+		else
+			token = strtok(NULL, ",");
+
+		if (token == NULL)
+			break;
+		if (! strncmp(token, search_opt, strlen(search_opt)))
+			right_opt = xstrdup(token);
+	}
+	if (right_opt != NULL) {
+		*rightmost_opt = xmalloc(strlen(right_opt));
+		strcpy(*rightmost_opt, right_opt);
+	}
+	free(opts);
+	free(right_opt);
+}
+
 int main(int argc, char *argv[])
 {
 	int c, flags = 0, mnt_err = 1, fake = 0;
 	char *spec, *mount_point, *fs_type = "nfs";
-	char *extra_opts = NULL, *mount_opts = NULL;
+	char *extra_opts = NULL, *mount_opts = NULL, *vers_opt=NULL;
 	uid_t uid = getuid();
	progname = basename(argv[0]);

utils/mount/mount.c int main(int argc, char *argv[]) · line 592

Quoted 4 lines
utils/mount/mount.c +1 -0
@@ -562,6 +589,18 @@ int main(int argc, char *argv[])
 
 	parse_opts(mount_opts, &flags, &extra_opts);
 
+	find_rightmost(extra_opts, "vers", &vers_opt);

Calling this here means it will affect both text-based and non-text-based mounts. A better place for it would be in try_mount(), as Steve's previous posted patch did.

Do you really need this support on legacy kernels? Parsing this properly for the binary case will be a challenge.

Quoted 14 lines
utils/mount/mount.c +11 -0
+	if (vers_opt != NULL) {
+		if ((strcmp(vers_opt, "vers=4")) == 0)
+			fs_type = "nfs4";
+	}
+
+	find_rightmost(extra_opts, "nfsvers", &vers_opt);
+	if (vers_opt != NULL) {
+		if ((strcmp(vers_opt, "nfsvers=4")) == 0)
+			fs_type = "nfs4";
+	}
+
 
 	if (uid != 0) {
 		if (!(flags & (MS_USERS|MS_USER))) {
Quoted 1 line
			nfs_error(_("%s: permission denied"), progname);

--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com