blob: 6f006a804db33c48310c5af608ed4aa53805625c [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
Bob Peterson569a7b62007-06-27 10:15:56 -050085 /* If someone preloaded options, use those instead */
86 spin_lock(&gfs2_sys_margs_lock);
87 if (!remount && gfs2_sys_margs) {
88 data = gfs2_sys_margs;
89 gfs2_sys_margs = NULL;
David Teiglandb3b94fa2006-01-16 16:50:04 +000090 }
Bob Peterson569a7b62007-06-27 10:15:56 -050091 spin_unlock(&gfs2_sys_margs_lock);
92
93 /* Set some defaults */
94 memset(args, 0, sizeof(struct gfs2_args));
95 args->ar_num_glockd = GFS2_GLOCKD_DEFAULT;
96 args->ar_quota = GFS2_QUOTA_DEFAULT;
97 args->ar_data = GFS2_DATA_DEFAULT;
David Teiglandb3b94fa2006-01-16 16:50:04 +000098
99 /* Split the options into tokens with the "," character and
100 process them */
101
102 for (options = data; (o = strsep(&options, ",")); ) {
Josef Bacik476c0062007-04-23 11:55:39 -0400103 int token, option;
104 substring_t tmp[MAX_OPT_ARGS];
105
David Teiglandb3b94fa2006-01-16 16:50:04 +0000106 if (!*o)
107 continue;
108
Josef Bacik476c0062007-04-23 11:55:39 -0400109 token = match_token(o, tokens, tmp);
110 switch (token) {
111 case Opt_lockproto:
112 v = match_strdup(&tmp[0]);
113 if (!v) {
114 fs_info(sdp, "no memory for lockproto\n");
115 error = -ENOMEM;
116 goto out_error;
117 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000118
Josef Bacik476c0062007-04-23 11:55:39 -0400119 if (remount && strcmp(v, args->ar_lockproto)) {
120 kfree(v);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000121 goto cant_remount;
Josef Bacik476c0062007-04-23 11:55:39 -0400122 }
123
David Teiglandb3b94fa2006-01-16 16:50:04 +0000124 strncpy(args->ar_lockproto, v, GFS2_LOCKNAME_LEN);
125 args->ar_lockproto[GFS2_LOCKNAME_LEN - 1] = 0;
Josef Bacik476c0062007-04-23 11:55:39 -0400126 kfree(v);
127 break;
128 case Opt_locktable:
129 v = match_strdup(&tmp[0]);
130 if (!v) {
131 fs_info(sdp, "no memory for locktable\n");
132 error = -ENOMEM;
133 goto out_error;
134 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000135
Josef Bacik476c0062007-04-23 11:55:39 -0400136 if (remount && strcmp(v, args->ar_locktable)) {
137 kfree(v);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000138 goto cant_remount;
Josef Bacik476c0062007-04-23 11:55:39 -0400139 }
140
David Teiglandb3b94fa2006-01-16 16:50:04 +0000141 strncpy(args->ar_locktable, v, GFS2_LOCKNAME_LEN);
Josef Bacik476c0062007-04-23 11:55:39 -0400142 args->ar_locktable[GFS2_LOCKNAME_LEN - 1] = 0;
143 kfree(v);
144 break;
145 case Opt_hostdata:
146 v = match_strdup(&tmp[0]);
147 if (!v) {
148 fs_info(sdp, "no memory for hostdata\n");
149 error = -ENOMEM;
150 goto out_error;
151 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000152
Josef Bacik476c0062007-04-23 11:55:39 -0400153 if (remount && strcmp(v, args->ar_hostdata)) {
154 kfree(v);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000155 goto cant_remount;
Josef Bacik476c0062007-04-23 11:55:39 -0400156 }
157
David Teiglandb3b94fa2006-01-16 16:50:04 +0000158 strncpy(args->ar_hostdata, v, GFS2_LOCKNAME_LEN);
159 args->ar_hostdata[GFS2_LOCKNAME_LEN - 1] = 0;
Josef Bacik476c0062007-04-23 11:55:39 -0400160 kfree(v);
161 break;
162 case Opt_spectator:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000163 if (remount && !args->ar_spectator)
164 goto cant_remount;
165 args->ar_spectator = 1;
166 sdp->sd_vfs->s_flags |= MS_RDONLY;
Josef Bacik476c0062007-04-23 11:55:39 -0400167 break;
168 case Opt_ignore_local_fs:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000169 if (remount && !args->ar_ignore_local_fs)
170 goto cant_remount;
171 args->ar_ignore_local_fs = 1;
Josef Bacik476c0062007-04-23 11:55:39 -0400172 break;
173 case Opt_localflocks:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000174 if (remount && !args->ar_localflocks)
175 goto cant_remount;
176 args->ar_localflocks = 1;
Josef Bacik476c0062007-04-23 11:55:39 -0400177 break;
178 case Opt_localcaching:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000179 if (remount && !args->ar_localcaching)
180 goto cant_remount;
181 args->ar_localcaching = 1;
Josef Bacik476c0062007-04-23 11:55:39 -0400182 break;
183 case Opt_debug:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000184 args->ar_debug = 1;
Josef Bacik476c0062007-04-23 11:55:39 -0400185 break;
186 case Opt_nodebug:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000187 args->ar_debug = 0;
Josef Bacik476c0062007-04-23 11:55:39 -0400188 break;
189 case Opt_upgrade:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000190 if (remount && !args->ar_upgrade)
191 goto cant_remount;
192 args->ar_upgrade = 1;
Josef Bacik476c0062007-04-23 11:55:39 -0400193 break;
194 case Opt_num_glockd:
195 if ((error = match_int(&tmp[0], &option))) {
196 fs_info(sdp, "problem getting num_glockd\n");
197 goto out_error;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000198 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000199
Josef Bacik476c0062007-04-23 11:55:39 -0400200 if (remount && option != args->ar_num_glockd)
201 goto cant_remount;
202 if (!option || option > GFS2_GLOCKD_MAX) {
203 fs_info(sdp, "0 < num_glockd <= %u (not %u)\n",
204 GFS2_GLOCKD_MAX, option);
205 error = -EINVAL;
206 goto out_error;
207 }
208 args->ar_num_glockd = option;
209 break;
210 case Opt_acl:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000211 args->ar_posix_acl = 1;
212 sdp->sd_vfs->s_flags |= MS_POSIXACL;
Josef Bacik476c0062007-04-23 11:55:39 -0400213 break;
214 case Opt_noacl:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000215 args->ar_posix_acl = 0;
216 sdp->sd_vfs->s_flags &= ~MS_POSIXACL;
Josef Bacik476c0062007-04-23 11:55:39 -0400217 break;
218 case Opt_quota_off:
219 args->ar_quota = GFS2_QUOTA_OFF;
220 break;
221 case Opt_quota_account:
222 args->ar_quota = GFS2_QUOTA_ACCOUNT;
223 break;
224 case Opt_quota_on:
225 args->ar_quota = GFS2_QUOTA_ON;
226 break;
227 case Opt_suiddir:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000228 args->ar_suiddir = 1;
Josef Bacik476c0062007-04-23 11:55:39 -0400229 break;
230 case Opt_nosuiddir:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000231 args->ar_suiddir = 0;
Josef Bacik476c0062007-04-23 11:55:39 -0400232 break;
233 case Opt_data_writeback:
234 args->ar_data = GFS2_DATA_WRITEBACK;
235 break;
236 case Opt_data_ordered:
237 args->ar_data = GFS2_DATA_ORDERED;
238 break;
239 default:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000240 fs_info(sdp, "unknown option: %s\n", o);
241 error = -EINVAL;
Josef Bacik476c0062007-04-23 11:55:39 -0400242 goto out_error;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000243 }
244 }
245
Josef Bacik476c0062007-04-23 11:55:39 -0400246out_error:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000247 if (error)
248 fs_info(sdp, "invalid mount option(s)\n");
249
250 if (data != data_arg)
251 kfree(data);
252
253 return error;
254
Steven Whitehousea91ea692006-09-04 12:04:26 -0400255cant_remount:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000256 fs_info(sdp, "can't remount with option %s\n", o);
257 return -EINVAL;
258}
259