Merge branch 'release' of git://git.kernel.org/pub/scm/linux/kernel/git/aegl/linux-2.6
[deliverable/linux.git] / fs / gfs2 / mount.c
CommitLineData
b3b94faa
DT
1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3a8a9a10 3 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
b3b94faa
DT
4 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
e9fc2aa0 7 * of the GNU General Public License version 2.
b3b94faa
DT
8 */
9
b3b94faa
DT
10#include <linux/slab.h>
11#include <linux/spinlock.h>
12#include <linux/completion.h>
13#include <linux/buffer_head.h>
5c676f6d 14#include <linux/gfs2_ondisk.h>
7d308590 15#include <linux/lm_interface.h>
476c006b 16#include <linux/parser.h>
b3b94faa
DT
17
18#include "gfs2.h"
5c676f6d 19#include "incore.h"
b3b94faa
DT
20#include "mount.h"
21#include "sys.h"
5c676f6d 22#include "util.h"
b3b94faa 23
476c006b
JB
24enum {
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
b3b94faa
DT
70/**
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
d18c4d68
SW
85 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);
569a7b6c 93
d18c4d68
SW
94 /* 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 }
b3b94faa
DT
99
100 /* Split the options into tokens with the "," character and
101 process them */
102
103 for (options = data; (o = strsep(&options, ",")); ) {
476c006b
JB
104 int token, option;
105 substring_t tmp[MAX_OPT_ARGS];
106
b3b94faa
DT
107 if (!*o)
108 continue;
109
476c006b
JB
110 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 }
b3b94faa 119
476c006b
JB
120 if (remount && strcmp(v, args->ar_lockproto)) {
121 kfree(v);
b3b94faa 122 goto cant_remount;
476c006b
JB
123 }
124
b3b94faa
DT
125 strncpy(args->ar_lockproto, v, GFS2_LOCKNAME_LEN);
126 args->ar_lockproto[GFS2_LOCKNAME_LEN - 1] = 0;
476c006b
JB
127 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 }
b3b94faa 136
476c006b
JB
137 if (remount && strcmp(v, args->ar_locktable)) {
138 kfree(v);
b3b94faa 139 goto cant_remount;
476c006b
JB
140 }
141
b3b94faa 142 strncpy(args->ar_locktable, v, GFS2_LOCKNAME_LEN);
476c006b
JB
143 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 }
b3b94faa 153
476c006b
JB
154 if (remount && strcmp(v, args->ar_hostdata)) {
155 kfree(v);
b3b94faa 156 goto cant_remount;
476c006b
JB
157 }
158
b3b94faa
DT
159 strncpy(args->ar_hostdata, v, GFS2_LOCKNAME_LEN);
160 args->ar_hostdata[GFS2_LOCKNAME_LEN - 1] = 0;
476c006b
JB
161 kfree(v);
162 break;
163 case Opt_spectator:
b3b94faa
DT
164 if (remount && !args->ar_spectator)
165 goto cant_remount;
166 args->ar_spectator = 1;
167 sdp->sd_vfs->s_flags |= MS_RDONLY;
476c006b
JB
168 break;
169 case Opt_ignore_local_fs:
b3b94faa
DT
170 if (remount && !args->ar_ignore_local_fs)
171 goto cant_remount;
172 args->ar_ignore_local_fs = 1;
476c006b
JB
173 break;
174 case Opt_localflocks:
b3b94faa
DT
175 if (remount && !args->ar_localflocks)
176 goto cant_remount;
177 args->ar_localflocks = 1;
476c006b
JB
178 break;
179 case Opt_localcaching:
b3b94faa
DT
180 if (remount && !args->ar_localcaching)
181 goto cant_remount;
182 args->ar_localcaching = 1;
476c006b
JB
183 break;
184 case Opt_debug:
b3b94faa 185 args->ar_debug = 1;
476c006b
JB
186 break;
187 case Opt_nodebug:
b3b94faa 188 args->ar_debug = 0;
476c006b
JB
189 break;
190 case Opt_upgrade:
b3b94faa
DT
191 if (remount && !args->ar_upgrade)
192 goto cant_remount;
193 args->ar_upgrade = 1;
476c006b
JB
194 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;
199 }
b3b94faa 200
476c006b 201 if (remount && option != args->ar_num_glockd)
b3b94faa 202 goto cant_remount;
476c006b 203 if (!option || option > GFS2_GLOCKD_MAX) {
b3b94faa 204 fs_info(sdp, "0 < num_glockd <= %u (not %u)\n",
476c006b 205 GFS2_GLOCKD_MAX, option);
b3b94faa 206 error = -EINVAL;
476c006b 207 goto out_error;
b3b94faa 208 }
476c006b
JB
209 args->ar_num_glockd = option;
210 break;
211 case Opt_acl:
b3b94faa
DT
212 args->ar_posix_acl = 1;
213 sdp->sd_vfs->s_flags |= MS_POSIXACL;
476c006b
JB
214 break;
215 case Opt_noacl:
b3b94faa
DT
216 args->ar_posix_acl = 0;
217 sdp->sd_vfs->s_flags &= ~MS_POSIXACL;
476c006b
JB
218 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:
b3b94faa 229 args->ar_suiddir = 1;
476c006b
JB
230 break;
231 case Opt_nosuiddir:
b3b94faa 232 args->ar_suiddir = 0;
476c006b
JB
233 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:
b3b94faa
DT
241 fs_info(sdp, "unknown option: %s\n", o);
242 error = -EINVAL;
476c006b 243 goto out_error;
b3b94faa
DT
244 }
245 }
246
476c006b 247out_error:
b3b94faa
DT
248 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
a91ea69f 256cant_remount:
b3b94faa
DT
257 fs_info(sdp, "can't remount with option %s\n", o);
258 return -EINVAL;
259}
260
This page took 0.178344 seconds and 5 git commands to generate.