Commit 476c006b authored by Josef Bacik's avatar Josef Bacik Committed by Steven Whitehouse

[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: default avatarJosef Bacik <jwhiter@redhat.com>
Signed-off-by: default avatarSteven Whitehouse <swhiteho@redhat.com>
parent 30d3a237
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include <linux/buffer_head.h> #include <linux/buffer_head.h>
#include <linux/gfs2_ondisk.h> #include <linux/gfs2_ondisk.h>
#include <linux/lm_interface.h> #include <linux/lm_interface.h>
#include <linux/parser.h>
#include "gfs2.h" #include "gfs2.h"
#include "incore.h" #include "incore.h"
...@@ -20,6 +21,52 @@ ...@@ -20,6 +21,52 @@
#include "sys.h" #include "sys.h"
#include "util.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 * gfs2_mount_args - Parse mount options
* @sdp: * @sdp:
...@@ -54,146 +101,150 @@ int gfs2_mount_args(struct gfs2_sbd *sdp, char *data_arg, int remount) ...@@ -54,146 +101,150 @@ int gfs2_mount_args(struct gfs2_sbd *sdp, char *data_arg, int remount)
process them */ process them */
for (options = data; (o = strsep(&options, ",")); ) { for (options = data; (o = strsep(&options, ",")); ) {
int token, option;
substring_t tmp[MAX_OPT_ARGS];
if (!*o) if (!*o)
continue; continue;
v = strchr(o, '='); token = match_token(o, tokens, tmp);
if (v) switch (token) {
*v++ = 0; 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 (remount && strcmp(v, args->ar_lockproto)) {
if (!v) kfree(v);
goto need_value;
if (remount && strcmp(v, args->ar_lockproto))
goto cant_remount; goto cant_remount;
}
strncpy(args->ar_lockproto, v, GFS2_LOCKNAME_LEN); strncpy(args->ar_lockproto, v, GFS2_LOCKNAME_LEN);
args->ar_lockproto[GFS2_LOCKNAME_LEN - 1] = 0; 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 (remount && strcmp(v, args->ar_locktable)) {
if (!v) kfree(v);
goto need_value;
if (remount && strcmp(v, args->ar_locktable))
goto cant_remount; goto cant_remount;
}
strncpy(args->ar_locktable, v, GFS2_LOCKNAME_LEN); 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 (remount && strcmp(v, args->ar_hostdata)) {
if (!v) kfree(v);
goto need_value;
if (remount && strcmp(v, args->ar_hostdata))
goto cant_remount; goto cant_remount;
}
strncpy(args->ar_hostdata, v, GFS2_LOCKNAME_LEN); strncpy(args->ar_hostdata, v, GFS2_LOCKNAME_LEN);
args->ar_hostdata[GFS2_LOCKNAME_LEN - 1] = 0; args->ar_hostdata[GFS2_LOCKNAME_LEN - 1] = 0;
} kfree(v);
break;
else if (!strcmp(o, "spectator")) { case Opt_spectator:
if (remount && !args->ar_spectator) if (remount && !args->ar_spectator)
goto cant_remount; goto cant_remount;
args->ar_spectator = 1; args->ar_spectator = 1;
sdp->sd_vfs->s_flags |= MS_RDONLY; sdp->sd_vfs->s_flags |= MS_RDONLY;
} break;
case Opt_ignore_local_fs:
else if (!strcmp(o, "ignore_local_fs")) {
if (remount && !args->ar_ignore_local_fs) if (remount && !args->ar_ignore_local_fs)
goto cant_remount; goto cant_remount;
args->ar_ignore_local_fs = 1; args->ar_ignore_local_fs = 1;
} break;
case Opt_localflocks:
else if (!strcmp(o, "localflocks")) {
if (remount && !args->ar_localflocks) if (remount && !args->ar_localflocks)
goto cant_remount; goto cant_remount;
args->ar_localflocks = 1; args->ar_localflocks = 1;
} break;
case Opt_localcaching:
else if (!strcmp(o, "localcaching")) {
if (remount && !args->ar_localcaching) if (remount && !args->ar_localcaching)
goto cant_remount; goto cant_remount;
args->ar_localcaching = 1; args->ar_localcaching = 1;
} break;
case Opt_debug:
else if (!strcmp(o, "debug"))
args->ar_debug = 1; args->ar_debug = 1;
break;
else if (!strcmp(o, "nodebug")) case Opt_nodebug:
args->ar_debug = 0; args->ar_debug = 0;
break;
else if (!strcmp(o, "upgrade")) { case Opt_upgrade:
if (remount && !args->ar_upgrade) if (remount && !args->ar_upgrade)
goto cant_remount; goto cant_remount;
args->ar_upgrade = 1; 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")) { if (remount && option != args->ar_num_glockd)
unsigned int x;
if (!v)
goto need_value;
sscanf(v, "%u", &x);
if (remount && x != args->ar_num_glockd)
goto cant_remount; 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", fs_info(sdp, "0 < num_glockd <= %u (not %u)\n",
GFS2_GLOCKD_MAX, x); GFS2_GLOCKD_MAX, option);
error = -EINVAL; error = -EINVAL;
break; goto out_error;
} }
args->ar_num_glockd = x; args->ar_num_glockd = option;
} break;
case Opt_acl:
else if (!strcmp(o, "acl")) {
args->ar_posix_acl = 1; args->ar_posix_acl = 1;
sdp->sd_vfs->s_flags |= MS_POSIXACL; sdp->sd_vfs->s_flags |= MS_POSIXACL;
} break;
case Opt_noacl:
else if (!strcmp(o, "noacl")) {
args->ar_posix_acl = 0; args->ar_posix_acl = 0;
sdp->sd_vfs->s_flags &= ~MS_POSIXACL; sdp->sd_vfs->s_flags &= ~MS_POSIXACL;
} break;
case Opt_quota_off:
else if (!strcmp(o, "quota")) { args->ar_quota = GFS2_QUOTA_OFF;
if (!v) break;
goto need_value; case Opt_quota_account:
if (!strcmp(v, "off")) args->ar_quota = GFS2_QUOTA_ACCOUNT;
args->ar_quota = GFS2_QUOTA_OFF; break;
else if (!strcmp(v, "account")) case Opt_quota_on:
args->ar_quota = GFS2_QUOTA_ACCOUNT; args->ar_quota = GFS2_QUOTA_ON;
else if (!strcmp(v, "on")) break;
args->ar_quota = GFS2_QUOTA_ON; case Opt_suiddir:
else {
fs_info(sdp, "invalid value for quota\n");
error = -EINVAL;
break;
}
}
else if (!strcmp(o, "suiddir"))
args->ar_suiddir = 1; args->ar_suiddir = 1;
break;
else if (!strcmp(o, "nosuiddir")) case Opt_nosuiddir:
args->ar_suiddir = 0; args->ar_suiddir = 0;
break;
else if (!strcmp(o, "data")) { case Opt_data_writeback:
if (!v) args->ar_data = GFS2_DATA_WRITEBACK;
goto need_value; break;
if (!strcmp(v, "writeback")) case Opt_data_ordered:
args->ar_data = GFS2_DATA_WRITEBACK; args->ar_data = GFS2_DATA_ORDERED;
else if (!strcmp(v, "ordered")) break;
args->ar_data = GFS2_DATA_ORDERED; default:
else {
fs_info(sdp, "invalid value for data\n");
error = -EINVAL;
break;
}
}
else {
fs_info(sdp, "unknown option: %s\n", o); fs_info(sdp, "unknown option: %s\n", o);
error = -EINVAL; error = -EINVAL;
break; goto out_error;
} }
} }
out_error:
if (error) if (error)
fs_info(sdp, "invalid mount option(s)\n"); 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) ...@@ -202,10 +253,6 @@ int gfs2_mount_args(struct gfs2_sbd *sdp, char *data_arg, int remount)
return error; return error;
need_value:
fs_info(sdp, "need value for option %s\n", o);
return -EINVAL;
cant_remount: cant_remount:
fs_info(sdp, "can't remount with option %s\n", o); fs_info(sdp, "can't remount with option %s\n", o);
return -EINVAL; return -EINVAL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment