blob: 3cb0a44ba0237830d3874283eab33bcdc573be7d [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,
Josef Bacik476c0062007-04-23 11:55:39 -040035 Opt_acl,
36 Opt_noacl,
37 Opt_quota_off,
38 Opt_quota_account,
39 Opt_quota_on,
40 Opt_suiddir,
41 Opt_nosuiddir,
42 Opt_data_writeback,
43 Opt_data_ordered,
Steven Whitehouse9b8df982008-08-08 13:45:13 +010044 Opt_meta,
Benjamin Marzinski9a5ad132007-08-17 20:22:07 -050045 Opt_err,
Josef Bacik476c0062007-04-23 11:55:39 -040046};
47
Steven Whitehousea447c092008-10-13 10:46:57 +010048static const match_table_t tokens = {
Josef Bacik476c0062007-04-23 11:55:39 -040049 {Opt_lockproto, "lockproto=%s"},
50 {Opt_locktable, "locktable=%s"},
51 {Opt_hostdata, "hostdata=%s"},
52 {Opt_spectator, "spectator"},
53 {Opt_ignore_local_fs, "ignore_local_fs"},
54 {Opt_localflocks, "localflocks"},
55 {Opt_localcaching, "localcaching"},
56 {Opt_debug, "debug"},
57 {Opt_nodebug, "nodebug"},
58 {Opt_upgrade, "upgrade"},
Josef Bacik476c0062007-04-23 11:55:39 -040059 {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"},
Benjamin Marzinski9a5ad132007-08-17 20:22:07 -050067 {Opt_data_ordered, "data=ordered"},
Steven Whitehouse9b8df982008-08-08 13:45:13 +010068 {Opt_meta, "meta"},
Benjamin Marzinski9a5ad132007-08-17 20:22:07 -050069 {Opt_err, NULL}
Josef Bacik476c0062007-04-23 11:55:39 -040070};
71
David Teiglandb3b94fa2006-01-16 16:50:04 +000072/**
73 * gfs2_mount_args - Parse mount options
74 * @sdp:
75 * @data:
76 *
77 * Return: errno
78 */
79
80int gfs2_mount_args(struct gfs2_sbd *sdp, char *data_arg, int remount)
81{
82 struct gfs2_args *args = &sdp->sd_args;
83 char *data = data_arg;
84 char *options, *o, *v;
85 int error = 0;
86
Steven Whitehoused18c4d62007-07-19 16:12:50 +010087 if (!remount) {
Steven Whitehoused18c4d62007-07-19 16:12:50 +010088 /* Set some defaults */
Steven Whitehoused18c4d62007-07-19 16:12:50 +010089 args->ar_quota = GFS2_QUOTA_DEFAULT;
90 args->ar_data = GFS2_DATA_DEFAULT;
91 }
David Teiglandb3b94fa2006-01-16 16:50:04 +000092
93 /* Split the options into tokens with the "," character and
94 process them */
95
96 for (options = data; (o = strsep(&options, ",")); ) {
Steven Whitehouse97cc10252008-11-20 13:39:47 +000097 int token;
Josef Bacik476c0062007-04-23 11:55:39 -040098 substring_t tmp[MAX_OPT_ARGS];
99
David Teiglandb3b94fa2006-01-16 16:50:04 +0000100 if (!*o)
101 continue;
102
Josef Bacik476c0062007-04-23 11:55:39 -0400103 token = match_token(o, tokens, tmp);
104 switch (token) {
105 case Opt_lockproto:
106 v = match_strdup(&tmp[0]);
107 if (!v) {
108 fs_info(sdp, "no memory for lockproto\n");
109 error = -ENOMEM;
110 goto out_error;
111 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000112
Josef Bacik476c0062007-04-23 11:55:39 -0400113 if (remount && strcmp(v, args->ar_lockproto)) {
114 kfree(v);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000115 goto cant_remount;
Josef Bacik476c0062007-04-23 11:55:39 -0400116 }
117
David Teiglandb3b94fa2006-01-16 16:50:04 +0000118 strncpy(args->ar_lockproto, v, GFS2_LOCKNAME_LEN);
119 args->ar_lockproto[GFS2_LOCKNAME_LEN - 1] = 0;
Josef Bacik476c0062007-04-23 11:55:39 -0400120 kfree(v);
121 break;
122 case Opt_locktable:
123 v = match_strdup(&tmp[0]);
124 if (!v) {
125 fs_info(sdp, "no memory for locktable\n");
126 error = -ENOMEM;
127 goto out_error;
128 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000129
Josef Bacik476c0062007-04-23 11:55:39 -0400130 if (remount && strcmp(v, args->ar_locktable)) {
131 kfree(v);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000132 goto cant_remount;
Josef Bacik476c0062007-04-23 11:55:39 -0400133 }
134
David Teiglandb3b94fa2006-01-16 16:50:04 +0000135 strncpy(args->ar_locktable, v, GFS2_LOCKNAME_LEN);
Josef Bacik476c0062007-04-23 11:55:39 -0400136 args->ar_locktable[GFS2_LOCKNAME_LEN - 1] = 0;
137 kfree(v);
138 break;
139 case Opt_hostdata:
140 v = match_strdup(&tmp[0]);
141 if (!v) {
142 fs_info(sdp, "no memory for hostdata\n");
143 error = -ENOMEM;
144 goto out_error;
145 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000146
Josef Bacik476c0062007-04-23 11:55:39 -0400147 if (remount && strcmp(v, args->ar_hostdata)) {
148 kfree(v);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000149 goto cant_remount;
Josef Bacik476c0062007-04-23 11:55:39 -0400150 }
151
David Teiglandb3b94fa2006-01-16 16:50:04 +0000152 strncpy(args->ar_hostdata, v, GFS2_LOCKNAME_LEN);
153 args->ar_hostdata[GFS2_LOCKNAME_LEN - 1] = 0;
Josef Bacik476c0062007-04-23 11:55:39 -0400154 kfree(v);
155 break;
156 case Opt_spectator:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000157 if (remount && !args->ar_spectator)
158 goto cant_remount;
159 args->ar_spectator = 1;
160 sdp->sd_vfs->s_flags |= MS_RDONLY;
Josef Bacik476c0062007-04-23 11:55:39 -0400161 break;
162 case Opt_ignore_local_fs:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000163 if (remount && !args->ar_ignore_local_fs)
164 goto cant_remount;
165 args->ar_ignore_local_fs = 1;
Josef Bacik476c0062007-04-23 11:55:39 -0400166 break;
167 case Opt_localflocks:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000168 if (remount && !args->ar_localflocks)
169 goto cant_remount;
170 args->ar_localflocks = 1;
Josef Bacik476c0062007-04-23 11:55:39 -0400171 break;
172 case Opt_localcaching:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000173 if (remount && !args->ar_localcaching)
174 goto cant_remount;
175 args->ar_localcaching = 1;
Josef Bacik476c0062007-04-23 11:55:39 -0400176 break;
177 case Opt_debug:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000178 args->ar_debug = 1;
Josef Bacik476c0062007-04-23 11:55:39 -0400179 break;
180 case Opt_nodebug:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000181 args->ar_debug = 0;
Josef Bacik476c0062007-04-23 11:55:39 -0400182 break;
183 case Opt_upgrade:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000184 if (remount && !args->ar_upgrade)
185 goto cant_remount;
186 args->ar_upgrade = 1;
Josef Bacik476c0062007-04-23 11:55:39 -0400187 break;
Josef Bacik476c0062007-04-23 11:55:39 -0400188 case Opt_acl:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000189 args->ar_posix_acl = 1;
190 sdp->sd_vfs->s_flags |= MS_POSIXACL;
Josef Bacik476c0062007-04-23 11:55:39 -0400191 break;
192 case Opt_noacl:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000193 args->ar_posix_acl = 0;
194 sdp->sd_vfs->s_flags &= ~MS_POSIXACL;
Josef Bacik476c0062007-04-23 11:55:39 -0400195 break;
196 case Opt_quota_off:
197 args->ar_quota = GFS2_QUOTA_OFF;
198 break;
199 case Opt_quota_account:
200 args->ar_quota = GFS2_QUOTA_ACCOUNT;
201 break;
202 case Opt_quota_on:
203 args->ar_quota = GFS2_QUOTA_ON;
204 break;
205 case Opt_suiddir:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000206 args->ar_suiddir = 1;
Josef Bacik476c0062007-04-23 11:55:39 -0400207 break;
208 case Opt_nosuiddir:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000209 args->ar_suiddir = 0;
Josef Bacik476c0062007-04-23 11:55:39 -0400210 break;
211 case Opt_data_writeback:
212 args->ar_data = GFS2_DATA_WRITEBACK;
213 break;
214 case Opt_data_ordered:
215 args->ar_data = GFS2_DATA_ORDERED;
216 break;
Steven Whitehouse9b8df982008-08-08 13:45:13 +0100217 case Opt_meta:
218 if (remount && args->ar_meta != 1)
219 goto cant_remount;
220 args->ar_meta = 1;
221 break;
Benjamin Marzinski9a5ad132007-08-17 20:22:07 -0500222 case Opt_err:
Josef Bacik476c0062007-04-23 11:55:39 -0400223 default:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000224 fs_info(sdp, "unknown option: %s\n", o);
225 error = -EINVAL;
Josef Bacik476c0062007-04-23 11:55:39 -0400226 goto out_error;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000227 }
228 }
229
Josef Bacik476c0062007-04-23 11:55:39 -0400230out_error:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000231 if (error)
232 fs_info(sdp, "invalid mount option(s)\n");
233
234 if (data != data_arg)
235 kfree(data);
236
237 return error;
238
Steven Whitehousea91ea692006-09-04 12:04:26 -0400239cant_remount:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000240 fs_info(sdp, "can't remount with option %s\n", o);
241 return -EINVAL;
242}
243