blob: 4864659555d4f94d49132a2727a4acd0b5e1d5e4 [file] [log] [blame]
David Teiglandb3b94fa2006-01-16 16:50:04 +00001/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
Steven Whitehouse3a8a9a12006-05-18 15:09:15 -04003 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
David Teiglandb3b94fa2006-01-16 16:50:04 +00004 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
Steven Whitehousee9fc2aa2006-09-01 11:05:15 -04007 * of the GNU General Public License version 2.
David Teiglandb3b94fa2006-01-16 16:50:04 +00008 */
9
David Teiglandb3b94fa2006-01-16 16:50:04 +000010#include <linux/slab.h>
11#include <linux/spinlock.h>
12#include <linux/completion.h>
13#include <linux/buffer_head.h>
Steven Whitehouse5c676f62006-02-27 17:23:27 -050014#include <linux/gfs2_ondisk.h>
Fabio Massimo Di Nitto7d308592006-09-19 07:56:29 +020015#include <linux/lm_interface.h>
Josef Bacik476c0062007-04-23 11:55:39 -040016#include <linux/parser.h>
David Teiglandb3b94fa2006-01-16 16:50:04 +000017
18#include "gfs2.h"
Steven Whitehouse5c676f62006-02-27 17:23:27 -050019#include "incore.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000020#include "mount.h"
21#include "sys.h"
Steven Whitehouse5c676f62006-02-27 17:23:27 -050022#include "util.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000023
Josef Bacik476c0062007-04-23 11:55:39 -040024enum {
25 Opt_lockproto,
26 Opt_locktable,
27 Opt_hostdata,
28 Opt_spectator,
29 Opt_ignore_local_fs,
30 Opt_localflocks,
31 Opt_localcaching,
32 Opt_debug,
33 Opt_nodebug,
34 Opt_upgrade,
35 Opt_num_glockd,
36 Opt_acl,
37 Opt_noacl,
38 Opt_quota_off,
39 Opt_quota_account,
40 Opt_quota_on,
41 Opt_suiddir,
42 Opt_nosuiddir,
43 Opt_data_writeback,
44 Opt_data_ordered,
45};
46
47static match_table_t tokens = {
48 {Opt_lockproto, "lockproto=%s"},
49 {Opt_locktable, "locktable=%s"},
50 {Opt_hostdata, "hostdata=%s"},
51 {Opt_spectator, "spectator"},
52 {Opt_ignore_local_fs, "ignore_local_fs"},
53 {Opt_localflocks, "localflocks"},
54 {Opt_localcaching, "localcaching"},
55 {Opt_debug, "debug"},
56 {Opt_nodebug, "nodebug"},
57 {Opt_upgrade, "upgrade"},
58 {Opt_num_glockd, "num_glockd=%d"},
59 {Opt_acl, "acl"},
60 {Opt_noacl, "noacl"},
61 {Opt_quota_off, "quota=off"},
62 {Opt_quota_account, "quota=account"},
63 {Opt_quota_on, "quota=on"},
64 {Opt_suiddir, "suiddir"},
65 {Opt_nosuiddir, "nosuiddir"},
66 {Opt_data_writeback, "data=writeback"},
67 {Opt_data_ordered, "data=ordered"}
68};
69
David Teiglandb3b94fa2006-01-16 16:50:04 +000070/**
71 * gfs2_mount_args - Parse mount options
72 * @sdp:
73 * @data:
74 *
75 * Return: errno
76 */
77
78int gfs2_mount_args(struct gfs2_sbd *sdp, char *data_arg, int remount)
79{
80 struct gfs2_args *args = &sdp->sd_args;
81 char *data = data_arg;
82 char *options, *o, *v;
83 int error = 0;
84
Steven Whitehoused18c4d62007-07-19 16:12:50 +010085 if (!remount) {
86 /* If someone preloaded options, use those instead */
87 spin_lock(&gfs2_sys_margs_lock);
88 if (gfs2_sys_margs) {
89 data = gfs2_sys_margs;
90 gfs2_sys_margs = NULL;
91 }
92 spin_unlock(&gfs2_sys_margs_lock);
Bob Peterson569a7b62007-06-27 10:15:56 -050093
Steven Whitehoused18c4d62007-07-19 16:12:50 +010094 /* Set some defaults */
95 args->ar_num_glockd = GFS2_GLOCKD_DEFAULT;
96 args->ar_quota = GFS2_QUOTA_DEFAULT;
97 args->ar_data = GFS2_DATA_DEFAULT;
98 }
David Teiglandb3b94fa2006-01-16 16:50:04 +000099
100 /* Split the options into tokens with the "," character and
101 process them */
102
103 for (options = data; (o = strsep(&options, ",")); ) {
Josef Bacik476c0062007-04-23 11:55:39 -0400104 int token, option;
105 substring_t tmp[MAX_OPT_ARGS];
106
David Teiglandb3b94fa2006-01-16 16:50:04 +0000107 if (!*o)
108 continue;
109
Josef Bacik476c0062007-04-23 11:55:39 -0400110 token = match_token(o, tokens, tmp);
111 switch (token) {
112 case Opt_lockproto:
113 v = match_strdup(&tmp[0]);
114 if (!v) {
115 fs_info(sdp, "no memory for lockproto\n");
116 error = -ENOMEM;
117 goto out_error;
118 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000119
Josef Bacik476c0062007-04-23 11:55:39 -0400120 if (remount && strcmp(v, args->ar_lockproto)) {
121 kfree(v);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000122 goto cant_remount;
Josef Bacik476c0062007-04-23 11:55:39 -0400123 }
124
David Teiglandb3b94fa2006-01-16 16:50:04 +0000125 strncpy(args->ar_lockproto, v, GFS2_LOCKNAME_LEN);
126 args->ar_lockproto[GFS2_LOCKNAME_LEN - 1] = 0;
Josef Bacik476c0062007-04-23 11:55:39 -0400127 kfree(v);
128 break;
129 case Opt_locktable:
130 v = match_strdup(&tmp[0]);
131 if (!v) {
132 fs_info(sdp, "no memory for locktable\n");
133 error = -ENOMEM;
134 goto out_error;
135 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000136
Josef Bacik476c0062007-04-23 11:55:39 -0400137 if (remount && strcmp(v, args->ar_locktable)) {
138 kfree(v);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000139 goto cant_remount;
Josef Bacik476c0062007-04-23 11:55:39 -0400140 }
141
David Teiglandb3b94fa2006-01-16 16:50:04 +0000142 strncpy(args->ar_locktable, v, GFS2_LOCKNAME_LEN);
Josef Bacik476c0062007-04-23 11:55:39 -0400143 args->ar_locktable[GFS2_LOCKNAME_LEN - 1] = 0;
144 kfree(v);
145 break;
146 case Opt_hostdata:
147 v = match_strdup(&tmp[0]);
148 if (!v) {
149 fs_info(sdp, "no memory for hostdata\n");
150 error = -ENOMEM;
151 goto out_error;
152 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000153
Josef Bacik476c0062007-04-23 11:55:39 -0400154 if (remount && strcmp(v, args->ar_hostdata)) {
155 kfree(v);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000156 goto cant_remount;
Josef Bacik476c0062007-04-23 11:55:39 -0400157 }
158
David Teiglandb3b94fa2006-01-16 16:50:04 +0000159 strncpy(args->ar_hostdata, v, GFS2_LOCKNAME_LEN);
160 args->ar_hostdata[GFS2_LOCKNAME_LEN - 1] = 0;
Josef Bacik476c0062007-04-23 11:55:39 -0400161 kfree(v);
162 break;
163 case Opt_spectator:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000164 if (remount && !args->ar_spectator)
165 goto cant_remount;
166 args->ar_spectator = 1;
167 sdp->sd_vfs->s_flags |= MS_RDONLY;
Josef Bacik476c0062007-04-23 11:55:39 -0400168 break;
169 case Opt_ignore_local_fs:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000170 if (remount && !args->ar_ignore_local_fs)
171 goto cant_remount;
172 args->ar_ignore_local_fs = 1;
Josef Bacik476c0062007-04-23 11:55:39 -0400173 break;
174 case Opt_localflocks:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000175 if (remount && !args->ar_localflocks)
176 goto cant_remount;
177 args->ar_localflocks = 1;
Josef Bacik476c0062007-04-23 11:55:39 -0400178 break;
179 case Opt_localcaching:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000180 if (remount && !args->ar_localcaching)
181 goto cant_remount;
182 args->ar_localcaching = 1;
Josef Bacik476c0062007-04-23 11:55:39 -0400183 break;
184 case Opt_debug:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000185 args->ar_debug = 1;
Josef Bacik476c0062007-04-23 11:55:39 -0400186 break;
187 case Opt_nodebug:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000188 args->ar_debug = 0;
Josef Bacik476c0062007-04-23 11:55:39 -0400189 break;
190 case Opt_upgrade:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000191 if (remount && !args->ar_upgrade)
192 goto cant_remount;
193 args->ar_upgrade = 1;
Josef Bacik476c0062007-04-23 11:55:39 -0400194 break;
195 case Opt_num_glockd:
196 if ((error = match_int(&tmp[0], &option))) {
197 fs_info(sdp, "problem getting num_glockd\n");
198 goto out_error;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000199 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000200
Josef Bacik476c0062007-04-23 11:55:39 -0400201 if (remount && option != args->ar_num_glockd)
202 goto cant_remount;
203 if (!option || option > GFS2_GLOCKD_MAX) {
204 fs_info(sdp, "0 < num_glockd <= %u (not %u)\n",
205 GFS2_GLOCKD_MAX, option);
206 error = -EINVAL;
207 goto out_error;
208 }
209 args->ar_num_glockd = option;
210 break;
211 case Opt_acl:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000212 args->ar_posix_acl = 1;
213 sdp->sd_vfs->s_flags |= MS_POSIXACL;
Josef Bacik476c0062007-04-23 11:55:39 -0400214 break;
215 case Opt_noacl:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000216 args->ar_posix_acl = 0;
217 sdp->sd_vfs->s_flags &= ~MS_POSIXACL;
Josef Bacik476c0062007-04-23 11:55:39 -0400218 break;
219 case Opt_quota_off:
220 args->ar_quota = GFS2_QUOTA_OFF;
221 break;
222 case Opt_quota_account:
223 args->ar_quota = GFS2_QUOTA_ACCOUNT;
224 break;
225 case Opt_quota_on:
226 args->ar_quota = GFS2_QUOTA_ON;
227 break;
228 case Opt_suiddir:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000229 args->ar_suiddir = 1;
Josef Bacik476c0062007-04-23 11:55:39 -0400230 break;
231 case Opt_nosuiddir:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000232 args->ar_suiddir = 0;
Josef Bacik476c0062007-04-23 11:55:39 -0400233 break;
234 case Opt_data_writeback:
235 args->ar_data = GFS2_DATA_WRITEBACK;
236 break;
237 case Opt_data_ordered:
238 args->ar_data = GFS2_DATA_ORDERED;
239 break;
240 default:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000241 fs_info(sdp, "unknown option: %s\n", o);
242 error = -EINVAL;
Josef Bacik476c0062007-04-23 11:55:39 -0400243 goto out_error;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000244 }
245 }
246
Josef Bacik476c0062007-04-23 11:55:39 -0400247out_error:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000248 if (error)
249 fs_info(sdp, "invalid mount option(s)\n");
250
251 if (data != data_arg)
252 kfree(data);
253
254 return error;
255
Steven Whitehousea91ea692006-09-04 12:04:26 -0400256cant_remount:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000257 fs_info(sdp, "can't remount with option %s\n", o);
258 return -EINVAL;
259}
260