cluster-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
From: Steven Whitehouse <swhiteho@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [GFS2] use lib/parser for parsing mount options [30/34]
Date: Tue, 01 May 2007 11:22:55 +0100	[thread overview]
Message-ID: <1178014975.5462.190.camel@quoit.chygwyn.com> (raw)
In-Reply-To: <1178013376.5462.127.camel@quoit.chygwyn.com>

From 476c006be009d4121e401a9e9f49a3362a7a272f Mon Sep 17 00:00:00 2001
From: Josef Bacik <jwhiter@redhat.com>
Date: Mon, 23 Apr 2007 11:55:39 -0400
Subject: [PATCH] [GFS2] use lib/parser for parsing mount options

This patch converts the mount option parsing to use the kernels lib/parser stuff
like all of the other filesystems.  I tested this and it works well.  Thank you,

Signed-off-by: Josef Bacik <jwhiter@redhat.com>
Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>

diff --git a/fs/gfs2/mount.c b/fs/gfs2/mount.c
index 32caecd..4864659 100644
--- a/fs/gfs2/mount.c
+++ b/fs/gfs2/mount.c
@@ -13,6 +13,7 @@
 #include <linux/buffer_head.h>
 #include <linux/gfs2_ondisk.h>
 #include <linux/lm_interface.h>
+#include <linux/parser.h>
 
 #include "gfs2.h"
 #include "incore.h"
@@ -20,6 +21,52 @@
 #include "sys.h"
 #include "util.h"
 
+enum {
+	Opt_lockproto,
+	Opt_locktable,
+	Opt_hostdata,
+	Opt_spectator,
+	Opt_ignore_local_fs,
+	Opt_localflocks,
+	Opt_localcaching,
+	Opt_debug,
+	Opt_nodebug,
+	Opt_upgrade,
+	Opt_num_glockd,
+	Opt_acl,
+	Opt_noacl,
+	Opt_quota_off,
+	Opt_quota_account,
+	Opt_quota_on,
+	Opt_suiddir,
+	Opt_nosuiddir,
+	Opt_data_writeback,
+	Opt_data_ordered,
+};
+
+static match_table_t tokens = {
+	{Opt_lockproto, "lockproto=%s"},
+	{Opt_locktable, "locktable=%s"},
+	{Opt_hostdata, "hostdata=%s"},
+	{Opt_spectator, "spectator"},
+	{Opt_ignore_local_fs, "ignore_local_fs"},
+	{Opt_localflocks, "localflocks"},
+	{Opt_localcaching, "localcaching"},
+	{Opt_debug, "debug"},
+	{Opt_nodebug, "nodebug"},
+	{Opt_upgrade, "upgrade"},
+	{Opt_num_glockd, "num_glockd=%d"},
+	{Opt_acl, "acl"},
+	{Opt_noacl, "noacl"},
+	{Opt_quota_off, "quota=off"},
+	{Opt_quota_account, "quota=account"},
+	{Opt_quota_on, "quota=on"},
+	{Opt_suiddir, "suiddir"},
+	{Opt_nosuiddir, "nosuiddir"},
+	{Opt_data_writeback, "data=writeback"},
+	{Opt_data_ordered, "data=ordered"}
+};
+
 /**
  * gfs2_mount_args - Parse mount options
  * @sdp:
@@ -54,146 +101,150 @@ int gfs2_mount_args(struct gfs2_sbd *sdp, char *data_arg, int remount)
 	   process them */
 
 	for (options = data; (o = strsep(&options, ",")); ) {
+		int token, option;
+		substring_t tmp[MAX_OPT_ARGS];
+
 		if (!*o)
 			continue;
 
-		v = strchr(o, '=');
-		if (v)
-			*v++ = 0;
+		token = match_token(o, tokens, tmp);
+		switch (token) {
+		case Opt_lockproto:
+			v = match_strdup(&tmp[0]);
+			if (!v) {
+				fs_info(sdp, "no memory for lockproto\n");
+				error = -ENOMEM;
+				goto out_error;
+			}
 
-		if (!strcmp(o, "lockproto")) {
-			if (!v)
-				goto need_value;
-			if (remount && strcmp(v, args->ar_lockproto))
+			if (remount && strcmp(v, args->ar_lockproto)) {
+				kfree(v);
 				goto cant_remount;
+			}
+			
 			strncpy(args->ar_lockproto, v, GFS2_LOCKNAME_LEN);
 			args->ar_lockproto[GFS2_LOCKNAME_LEN - 1] = 0;
-		}
+			kfree(v);
+			break;
+		case Opt_locktable:
+			v = match_strdup(&tmp[0]);
+			if (!v) {
+				fs_info(sdp, "no memory for locktable\n");
+				error = -ENOMEM;
+				goto out_error;
+			}
 
-		else if (!strcmp(o, "locktable")) {
-			if (!v)
-				goto need_value;
-			if (remount && strcmp(v, args->ar_locktable))
+			if (remount && strcmp(v, args->ar_locktable)) {
+				kfree(v);
 				goto cant_remount;
+			}
+
 			strncpy(args->ar_locktable, v, GFS2_LOCKNAME_LEN);
-			args->ar_locktable[GFS2_LOCKNAME_LEN - 1] = 0;
-		}
+			args->ar_locktable[GFS2_LOCKNAME_LEN - 1]  = 0;
+			kfree(v);
+			break;
+		case Opt_hostdata:
+			v = match_strdup(&tmp[0]);
+			if (!v) {
+				fs_info(sdp, "no memory for hostdata\n");
+				error = -ENOMEM;
+				goto out_error;
+			}
 
-		else if (!strcmp(o, "hostdata")) {
-			if (!v)
-				goto need_value;
-			if (remount && strcmp(v, args->ar_hostdata))
+			if (remount && strcmp(v, args->ar_hostdata)) {
+				kfree(v);
 				goto cant_remount;
+			}
+
 			strncpy(args->ar_hostdata, v, GFS2_LOCKNAME_LEN);
 			args->ar_hostdata[GFS2_LOCKNAME_LEN - 1] = 0;
-		}
-
-		else if (!strcmp(o, "spectator")) {
+			kfree(v);
+			break;
+		case Opt_spectator:
 			if (remount && !args->ar_spectator)
 				goto cant_remount;
 			args->ar_spectator = 1;
 			sdp->sd_vfs->s_flags |= MS_RDONLY;
-		}
-
-		else if (!strcmp(o, "ignore_local_fs")) {
+			break;
+		case Opt_ignore_local_fs:
 			if (remount && !args->ar_ignore_local_fs)
 				goto cant_remount;
 			args->ar_ignore_local_fs = 1;
-		}
-
-		else if (!strcmp(o, "localflocks")) {
+			break;
+		case Opt_localflocks:
 			if (remount && !args->ar_localflocks)
 				goto cant_remount;
 			args->ar_localflocks = 1;
-		}
-
-		else if (!strcmp(o, "localcaching")) {
+			break;
+		case Opt_localcaching:
 			if (remount && !args->ar_localcaching)
 				goto cant_remount;
 			args->ar_localcaching = 1;
-		}
-
-		else if (!strcmp(o, "debug"))
+			break;
+		case Opt_debug:
 			args->ar_debug = 1;
-
-		else if (!strcmp(o, "nodebug"))
+			break;
+		case Opt_nodebug:
 			args->ar_debug = 0;
-
-		else if (!strcmp(o, "upgrade")) {
+			break;
+		case Opt_upgrade:
 			if (remount && !args->ar_upgrade)
 				goto cant_remount;
 			args->ar_upgrade = 1;
-		}
+			break;
+		case Opt_num_glockd:
+			if ((error = match_int(&tmp[0], &option))) {
+				fs_info(sdp, "problem getting num_glockd\n");
+				goto out_error;
+			}
 
-		else if (!strcmp(o, "num_glockd")) {
-			unsigned int x;
-			if (!v)
-				goto need_value;
-			sscanf(v, "%u", &x);
-			if (remount && x != args->ar_num_glockd)
+			if (remount && option != args->ar_num_glockd)
 				goto cant_remount;
-			if (!x || x > GFS2_GLOCKD_MAX) {
+			if (!option || option > GFS2_GLOCKD_MAX) {
 				fs_info(sdp, "0 < num_glockd <= %u  (not %u)\n",
-				        GFS2_GLOCKD_MAX, x);
+				        GFS2_GLOCKD_MAX, option);
 				error = -EINVAL;
-				break;
+				goto out_error;
 			}
-			args->ar_num_glockd = x;
-		}
-
-		else if (!strcmp(o, "acl")) {
+			args->ar_num_glockd = option;
+			break;
+		case Opt_acl:
 			args->ar_posix_acl = 1;
 			sdp->sd_vfs->s_flags |= MS_POSIXACL;
-		}
-
-		else if (!strcmp(o, "noacl")) {
+			break;
+		case Opt_noacl:
 			args->ar_posix_acl = 0;
 			sdp->sd_vfs->s_flags &= ~MS_POSIXACL;
-		}
-
-		else if (!strcmp(o, "quota")) {
-			if (!v)
-				goto need_value;
-			if (!strcmp(v, "off"))
-				args->ar_quota = GFS2_QUOTA_OFF;
-			else if (!strcmp(v, "account"))
-				args->ar_quota = GFS2_QUOTA_ACCOUNT;
-			else if (!strcmp(v, "on"))
-				args->ar_quota = GFS2_QUOTA_ON;
-			else {
-				fs_info(sdp, "invalid value for quota\n");
-				error = -EINVAL;
-				break;
-			}
-		}
-
-		else if (!strcmp(o, "suiddir"))
+			break;
+		case Opt_quota_off:
+			args->ar_quota = GFS2_QUOTA_OFF;
+			break;
+		case Opt_quota_account:
+			args->ar_quota = GFS2_QUOTA_ACCOUNT;
+			break;
+		case Opt_quota_on:
+			args->ar_quota = GFS2_QUOTA_ON;
+			break;
+		case Opt_suiddir:
 			args->ar_suiddir = 1;
-
-		else if (!strcmp(o, "nosuiddir"))
+			break;
+		case Opt_nosuiddir:
 			args->ar_suiddir = 0;
-
-		else if (!strcmp(o, "data")) {
-			if (!v)
-				goto need_value;
-			if (!strcmp(v, "writeback"))
-				args->ar_data = GFS2_DATA_WRITEBACK;
-			else if (!strcmp(v, "ordered"))
-				args->ar_data = GFS2_DATA_ORDERED;
-			else {
-				fs_info(sdp, "invalid value for data\n");
-				error = -EINVAL;
-				break;
-			}
-		}
-
-		else {
+			break;
+		case Opt_data_writeback:
+			args->ar_data = GFS2_DATA_WRITEBACK;
+			break;
+		case Opt_data_ordered:
+			args->ar_data = GFS2_DATA_ORDERED;
+			break;
+		default:
 			fs_info(sdp, "unknown option: %s\n", o);
 			error = -EINVAL;
-			break;
+			goto out_error;
 		}
 	}
 
+out_error:
 	if (error)
 		fs_info(sdp, "invalid mount option(s)\n");
 
@@ -202,10 +253,6 @@ int gfs2_mount_args(struct gfs2_sbd *sdp, char *data_arg, int remount)
 
 	return error;
 
-need_value:
-	fs_info(sdp, "need value for option %s\n", o);
-	return -EINVAL;
-
 cant_remount:
 	fs_info(sdp, "can't remount with option %s\n", o);
 	return -EINVAL;
-- 
1.5.1.2





  parent reply	other threads:[~2007-05-01 10:22 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-01  9:56 [Cluster-devel] [GFS2] Patches for the current merge window [0/34] Steven Whitehouse
2007-05-01  9:58 ` [Cluster-devel] [GFS2] Add gfs2_tool lockdump support to gfs2 (bz 228540) [1/34] Steven Whitehouse
2007-05-01  9:59 ` [Cluster-devel] [GFS2] fix bz 231369, gfs2 will oops if you specify an invalid mount option [2/34] Steven Whitehouse
2007-05-01 10:28   ` [Cluster-devel] " Christoph Hellwig
2007-05-01 13:41     ` Steven Whitehouse
2007-05-01  9:59 ` [Cluster-devel] [DLM] Fix uninitialised variable in receiving [3/34] Steven Whitehouse
2007-05-01 10:01 ` [Cluster-devel] [GFS2] Fix bz 231380, unlock page before dequeing glocks in gfs2_commit_write [4/34] Steven Whitehouse
2007-05-01 10:02 ` [Cluster-devel] [GFS2] Fix bz 224480 and cleanup glock demotion code [5/34] Steven Whitehouse
2007-05-01 10:02 ` [Cluster-devel] [GFS2] Fix a bug on i386 due to evaluation order [6/34] Steven Whitehouse
2007-05-01 10:03 ` [Cluster-devel] [DLM] Don't delete misc device if lockspace removal fails [7/43] Steven Whitehouse
2007-05-01 10:04 ` [Cluster-devel] [GFS2] Speed up lock_dlm's locking (move sprintf) [8/34] Steven Whitehouse
2007-05-01 10:05 ` [Cluster-devel] [GFS2] Fix log entry list corruption [9/34] Steven Whitehouse
2007-05-01 10:06 ` [Cluster-devel] [GFS2] flush the log if a transaction can't allocate space [10/34] Steven Whitehouse
2007-05-01 10:07 ` [Cluster-devel] [GFS2] Red Hat bz 228540: owner references [11/34] Steven Whitehouse
2007-05-01 10:07 ` [Cluster-devel] [DLM] fix coverity-spotted stupidity [12/34] Steven Whitehouse
2007-05-01 10:09 ` [Cluster-devel] [DLM] overlapping cancel and unlock [13/34] Steven Whitehouse
2007-05-01 10:09 ` [Cluster-devel] [GFS2] use log_error before LM_OUT_ERROR [14/34] Steven Whitehouse
2007-05-01 10:10 ` [Cluster-devel] [GFS2] Set drop_count to 0 (off) by default [15/34] Steven Whitehouse
2007-05-01 10:11 ` [Cluster-devel] [DLM] split create_message function [16/34] Steven Whitehouse
2007-05-01 10:12 ` [Cluster-devel] [DLM] add orphan purging code (1/2) [17/34] Steven Whitehouse
2007-05-01 10:12 ` [Cluster-devel] [DLM] interface for purge (2/2) [18/34] Steven Whitehouse
2007-05-01 10:13 ` [Cluster-devel] [DLM] change lkid format [19/34] Steven Whitehouse
2007-05-01 10:14 ` Steven Whitehouse
2007-05-01 10:14 ` [Cluster-devel] GFS2] Fix bz 234168 (ignoring rgrp flags) [20/34] Steven Whitehouse
2007-05-01 10:15 ` [Cluster-devel] [DLM] Remove redundant assignment [21/34] Steven Whitehouse
2007-05-01 10:16 ` [Cluster-devel] [DLM] Consolidate transport protocols [21/34] Steven Whitehouse
2007-05-01 10:17 ` [Cluster-devel] DLM] fs/dlm/ast.c should #include "ast.h" [23/34] Steven Whitehouse
2007-05-01 10:18 ` [Cluster-devel] [GFS2] bz 236008: Kernel gpf doing cat /debugfs/gfs2/xxx (lock dump) [24/34] Steven Whitehouse
2007-05-01 10:19 ` [Cluster-devel] [GFS2] Patch to detect corrupt number of dir entries in leaf and/or inode blocks [25/34] Steven Whitehouse
2007-05-01 10:20 ` [Cluster-devel] [GFS2] lockdump improvements [26/34] Steven Whitehouse
2007-05-01 10:20 ` [Cluster-devel] [DLM] fix mode munging [27/34] Steven Whitehouse
2007-05-01 10:21 ` [Cluster-devel] [DLM] Fix dlm_lowcoms_stop hang [28/34] Steven Whitehouse
2007-05-01 10:22 ` [Cluster-devel] [DLM] Lowcomms nodeid range & initialisation fixes [29/34] Steven Whitehouse
2007-05-01 10:22 ` Steven Whitehouse [this message]
2007-05-01 10:23 ` [Cluster-devel] [GFS2] Patch to fix mmap of stuffed files [31/34] Steven Whitehouse
2007-05-01 10:24 ` [Cluster-devel] [GFS2] printk warning fixes [32/34] Steven Whitehouse
2007-05-01 10:24 ` [Cluster-devel] [DLM] lowcomms style [33/34] Steven Whitehouse
2007-05-01 10:25 ` [Cluster-devel] [GFS2] Uncomment sprintf_symbol calling code [34/34] Steven Whitehouse
2007-05-01 14:11 ` [Cluster-devel] [GFS2/DLM] Pull request Steven Whitehouse

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=1178014975.5462.190.camel@quoit.chygwyn.com \
    --to=swhiteho@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;
as well as URLs for NNTP newsgroup(s).