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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On May 5, 2009, at 5:46 PM, Kevin Constantine wrote:

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.

Signed-off-by: Kevin Constantine <kevin.constantine@xxxxxxxxxxxxxxxxxxx >
---
utils/mount/mount.c |   41 ++++++++++++++++++++++++++++++++++++++++-
1 files changed, 40 insertions(+), 1 deletions(-)

diff --git a/utils/mount/mount.c b/utils/mount/mount.c
index 06e2804..4cebc0f 100644
--- a/utils/mount/mount.c
+++ b/utils/mount/mount.c
@@ -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);

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.

+	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);

--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Filesystem Development]     [Linux USB Development]     [Linux Media Development]     [Video for Linux]     [Linux NILFS]     [Linux Audio Users]     [Yosemite Info]     [Linux SCSI]

  Powered by Linux