blob: f96eb90a2cfa1a58d7a16215e8833e38a6e6fff3 [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,
Steven Whitehouse9b8df982008-08-08 13:45:13 +010045 Opt_meta,
Benjamin Marzinski9a5ad132007-08-17 20:22:07 -050046 Opt_err,
Josef Bacik476c0062007-04-23 11:55:39 -040047};
48
Steven Whitehousea447c092008-10-13 10:46:57 +010049static const match_table_t tokens = {
Josef Bacik476c0062007-04-23 11:55:39 -040050 {Opt_lockproto, "lockproto=%s"},
51 {Opt_locktable, "locktable=%s"},
52 {Opt_hostdata, "hostdata=%s"},
53 {Opt_spectator, "spectator"},
54 {Opt_ignore_local_fs, "ignore_local_fs"},
55 {Opt_localflocks, "localflocks"},
56 {Opt_localcaching, "localcaching"},
57 {Opt_debug, "debug"},
58 {Opt_nodebug, "nodebug"},
59 {Opt_upgrade, "upgrade"},
60 {Opt_num_glockd, "num_glockd=%d"},
61 {Opt_acl, "acl"},
62 {Opt_noacl, "noacl"},
63 {Opt_quota_off, "quota=off"},
64 {Opt_quota_account, "quota=account"},
65 {Opt_quota_on, "quota=on"},
66 {Opt_suiddir, "suiddir"},
67 {Opt_nosuiddir, "nosuiddir"},
68 {Opt_data_writeback, "data=writeback"},
Benjamin Marzinski9a5ad132007-08-17 20:22:07 -050069 {Opt_data_ordered, "data=ordered"},
Steven Whitehouse9b8df982008-08-08 13:45:13 +010070 {Opt_meta, "meta"},
Benjamin Marzinski9a5ad132007-08-17 20:22:07 -050071 {Opt_err, NULL}
Josef Bacik476c0062007-04-23 11:55:39 -040072};
73
David Teiglandb3b94fa2006-01-16 16:50:04 +000074/**
75 * gfs2_mount_args - Parse mount options
76 * @sdp:
77 * @data:
78 *
79 * Return: errno
80 */
81
82int gfs2_mount_args(struct gfs2_sbd *sdp, char *data_arg, int remount)
83{
84 struct gfs2_args *args = &sdp->sd_args;
85 char *data = data_arg;
86 char *options, *o, *v;
87 int error = 0;
88
Steven Whitehoused18c4d62007-07-19 16:12:50 +010089 if (!remount) {
90 /* If someone preloaded options, use those instead */
91 spin_lock(&gfs2_sys_margs_lock);
92 if (gfs2_sys_margs) {
93 data = gfs2_sys_margs;
94 gfs2_sys_margs = NULL;
95 }
96 spin_unlock(&gfs2_sys_margs_lock);
Bob Peterson569a7b62007-06-27 10:15:56 -050097
Steven Whitehoused18c4d62007-07-19 16:12:50 +010098 /* Set some defaults */
99 args->ar_num_glockd = GFS2_GLOCKD_DEFAULT;
100 args->ar_quota = GFS2_QUOTA_DEFAULT;
101 args->ar_data = GFS2_DATA_DEFAULT;
102 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000103
104 /* Split the options into tokens with the "," character and
105 process them */
106
107 for (options = data; (o = strsep(&options, ",")); ) {
Josef Bacik476c0062007-04-23 11:55:39 -0400108 int token, option;
109 substring_t tmp[MAX_OPT_ARGS];
110
David Teiglandb3b94fa2006-01-16 16:50:04 +0000111 if (!*o)
112 continue;
113
Josef Bacik476c0062007-04-23 11:55:39 -0400114 token = match_token(o, tokens, tmp);
115 switch (token) {
116 case Opt_lockproto:
117 v = match_strdup(&tmp[0]);
118 if (!v) {
119 fs_info(sdp, "no memory for lockproto\n");
120 error = -ENOMEM;
121 goto out_error;
122 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000123
Josef Bacik476c0062007-04-23 11:55:39 -0400124 if (remount && strcmp(v, args->ar_lockproto)) {
125 kfree(v);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000126 goto cant_remount;
Josef Bacik476c0062007-04-23 11:55:39 -0400127 }
128
David Teiglandb3b94fa2006-01-16 16:50:04 +0000129 strncpy(args->ar_lockproto, v, GFS2_LOCKNAME_LEN);
130 args->ar_lockproto[GFS2_LOCKNAME_LEN - 1] = 0;
Josef Bacik476c0062007-04-23 11:55:39 -0400131 kfree(v);
132 break;
133 case Opt_locktable:
134 v = match_strdup(&tmp[0]);
135 if (!v) {
136 fs_info(sdp, "no memory for locktable\n");
137 error = -ENOMEM;
138 goto out_error;
139 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000140
Josef Bacik476c0062007-04-23 11:55:39 -0400141 if (remount && strcmp(v, args->ar_locktable)) {
142 kfree(v);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000143 goto cant_remount;
Josef Bacik476c0062007-04-23 11:55:39 -0400144 }
145
David Teiglandb3b94fa2006-01-16 16:50:04 +0000146 strncpy(args->ar_locktable, v, GFS2_LOCKNAME_LEN);
Josef Bacik476c0062007-04-23 11:55:39 -0400147 args->ar_locktable[GFS2_LOCKNAME_LEN - 1] = 0;
148 kfree(v);
149 break;
150 case Opt_hostdata:
151 v = match_strdup(&tmp[0]);
152 if (!v) {
153 fs_info(sdp, "no memory for hostdata\n");
154 error = -ENOMEM;
155 goto out_error;
156 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000157
Josef Bacik476c0062007-04-23 11:55:39 -0400158 if (remount && strcmp(v, args->ar_hostdata)) {
159 kfree(v);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000160 goto cant_remount;
Josef Bacik476c0062007-04-23 11:55:39 -0400161 }
162
David Teiglandb3b94fa2006-01-16 16:50:04 +0000163 strncpy(args->ar_hostdata, v, GFS2_LOCKNAME_LEN);
164 args->ar_hostdata[GFS2_LOCKNAME_LEN - 1] = 0;
Josef Bacik476c0062007-04-23 11:55:39 -0400165 kfree(v);
166 break;
167 case Opt_spectator:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000168 if (remount && !args->ar_spectator)
169 goto cant_remount;
170 args->ar_spectator = 1;
171 sdp->sd_vfs->s_flags |= MS_RDONLY;
Josef Bacik476c0062007-04-23 11:55:39 -0400172 break;
173 case Opt_ignore_local_fs:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000174 if (remount && !args->ar_ignore_local_fs)
175 goto cant_remount;
176 args->ar_ignore_local_fs = 1;
Josef Bacik476c0062007-04-23 11:55:39 -0400177 break;
178 case Opt_localflocks:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000179 if (remount && !args->ar_localflocks)
180 goto cant_remount;
181 args->ar_localflocks = 1;
Josef Bacik476c0062007-04-23 11:55:39 -0400182 break;
183 case Opt_localcaching:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000184 if (remount && !args->ar_localcaching)
185 goto cant_remount;
186 args->ar_localcaching = 1;
Josef Bacik476c0062007-04-23 11:55:39 -0400187 break;
188 case Opt_debug:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000189 args->ar_debug = 1;
Josef Bacik476c0062007-04-23 11:55:39 -0400190 break;
191 case Opt_nodebug:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000192 args->ar_debug = 0;
Josef Bacik476c0062007-04-23 11:55:39 -0400193 break;
194 case Opt_upgrade:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000195 if (remount && !args->ar_upgrade)
196 goto cant_remount;
197 args->ar_upgrade = 1;
Josef Bacik476c0062007-04-23 11:55:39 -0400198 break;
199 case Opt_num_glockd:
200 if ((error = match_int(&tmp[0], &option))) {
201 fs_info(sdp, "problem getting num_glockd\n");
202 goto out_error;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000203 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000204
Josef Bacik476c0062007-04-23 11:55:39 -0400205 if (remount && option != args->ar_num_glockd)
206 goto cant_remount;
207 if (!option || option > GFS2_GLOCKD_MAX) {
208 fs_info(sdp, "0 < num_glockd <= %u (not %u)\n",
209 GFS2_GLOCKD_MAX, option);
210 error = -EINVAL;
211 goto out_error;
212 }
213 args->ar_num_glockd = option;
214 break;
215 case Opt_acl:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000216 args->ar_posix_acl = 1;
217 sdp->sd_vfs->s_flags |= MS_POSIXACL;
Josef Bacik476c0062007-04-23 11:55:39 -0400218 break;
219 case Opt_noacl:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000220 args->ar_posix_acl = 0;
221 sdp->sd_vfs->s_flags &= ~MS_POSIXACL;
Josef Bacik476c0062007-04-23 11:55:39 -0400222 break;
223 case Opt_quota_off:
224 args->ar_quota = GFS2_QUOTA_OFF;
225 break;
226 case Opt_quota_account:
227 args->ar_quota = GFS2_QUOTA_ACCOUNT;
228 break;
229 case Opt_quota_on:
230 args->ar_quota = GFS2_QUOTA_ON;
231 break;
232 case Opt_suiddir:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000233 args->ar_suiddir = 1;
Josef Bacik476c0062007-04-23 11:55:39 -0400234 break;
235 case Opt_nosuiddir:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000236 args->ar_suiddir = 0;
Josef Bacik476c0062007-04-23 11:55:39 -0400237 break;
238 case Opt_data_writeback:
239 args->ar_data = GFS2_DATA_WRITEBACK;
240 break;
241 case Opt_data_ordered:
242 args->ar_data = GFS2_DATA_ORDERED;
243 break;
Steven Whitehouse9b8df982008-08-08 13:45:13 +0100244 case Opt_meta:
245 if (remount && args->ar_meta != 1)
246 goto cant_remount;
247 args->ar_meta = 1;
248 break;
Benjamin Marzinski9a5ad132007-08-17 20:22:07 -0500249 case Opt_err:
Josef Bacik476c0062007-04-23 11:55:39 -0400250 default:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000251 fs_info(sdp, "unknown option: %s\n", o);
252 error = -EINVAL;
Josef Bacik476c0062007-04-23 11:55:39 -0400253 goto out_error;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000254 }
255 }
256
Josef Bacik476c0062007-04-23 11:55:39 -0400257out_error:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000258 if (error)
259 fs_info(sdp, "invalid mount option(s)\n");
260
261 if (data != data_arg)
262 kfree(data);
263
264 return error;
265
Steven Whitehousea91ea692006-09-04 12:04:26 -0400266cant_remount:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000267 fs_info(sdp, "can't remount with option %s\n", o);
268 return -EINVAL;
269}
270