GFS2: Add commit= mount option
[linux-2.6] / fs / gfs2 / mount.c
1 /*
2  * Copyright (C) Sistina Software, Inc.  1997-2003 All rights reserved.
3  * Copyright (C) 2004-2006 Red Hat, Inc.  All rights reserved.
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
7  * of the GNU General Public License version 2.
8  */
9
10 #include <linux/slab.h>
11 #include <linux/spinlock.h>
12 #include <linux/completion.h>
13 #include <linux/buffer_head.h>
14 #include <linux/gfs2_ondisk.h>
15 #include <linux/parser.h>
16
17 #include "gfs2.h"
18 #include "incore.h"
19 #include "super.h"
20 #include "sys.h"
21 #include "util.h"
22
23 enum {
24         Opt_lockproto,
25         Opt_locktable,
26         Opt_hostdata,
27         Opt_spectator,
28         Opt_ignore_local_fs,
29         Opt_localflocks,
30         Opt_localcaching,
31         Opt_debug,
32         Opt_nodebug,
33         Opt_upgrade,
34         Opt_acl,
35         Opt_noacl,
36         Opt_quota_off,
37         Opt_quota_account,
38         Opt_quota_on,
39         Opt_quota,
40         Opt_noquota,
41         Opt_suiddir,
42         Opt_nosuiddir,
43         Opt_data_writeback,
44         Opt_data_ordered,
45         Opt_meta,
46         Opt_discard,
47         Opt_nodiscard,
48         Opt_commit,
49         Opt_err,
50 };
51
52 static const match_table_t tokens = {
53         {Opt_lockproto, "lockproto=%s"},
54         {Opt_locktable, "locktable=%s"},
55         {Opt_hostdata, "hostdata=%s"},
56         {Opt_spectator, "spectator"},
57         {Opt_ignore_local_fs, "ignore_local_fs"},
58         {Opt_localflocks, "localflocks"},
59         {Opt_localcaching, "localcaching"},
60         {Opt_debug, "debug"},
61         {Opt_nodebug, "nodebug"},
62         {Opt_upgrade, "upgrade"},
63         {Opt_acl, "acl"},
64         {Opt_noacl, "noacl"},
65         {Opt_quota_off, "quota=off"},
66         {Opt_quota_account, "quota=account"},
67         {Opt_quota_on, "quota=on"},
68         {Opt_quota, "quota"},
69         {Opt_noquota, "noquota"},
70         {Opt_suiddir, "suiddir"},
71         {Opt_nosuiddir, "nosuiddir"},
72         {Opt_data_writeback, "data=writeback"},
73         {Opt_data_ordered, "data=ordered"},
74         {Opt_meta, "meta"},
75         {Opt_discard, "discard"},
76         {Opt_nodiscard, "nodiscard"},
77         {Opt_commit, "commit=%d"},
78         {Opt_err, NULL}
79 };
80
81 /**
82  * gfs2_mount_args - Parse mount options
83  * @sdp:
84  * @data:
85  *
86  * Return: errno
87  */
88
89 int gfs2_mount_args(struct gfs2_sbd *sdp, struct gfs2_args *args, char *options)
90 {
91         char *o;
92         int token;
93         substring_t tmp[MAX_OPT_ARGS];
94         int rv;
95
96         /* Split the options into tokens with the "," character and
97            process them */
98
99         while (1) {
100                 o = strsep(&options, ",");
101                 if (o == NULL)
102                         break;
103                 if (*o == '\0')
104                         continue;
105
106                 token = match_token(o, tokens, tmp);
107                 switch (token) {
108                 case Opt_lockproto:
109                         match_strlcpy(args->ar_lockproto, &tmp[0],
110                                       GFS2_LOCKNAME_LEN);
111                         break;
112                 case Opt_locktable:
113                         match_strlcpy(args->ar_locktable, &tmp[0],
114                                       GFS2_LOCKNAME_LEN);
115                         break;
116                 case Opt_hostdata:
117                         match_strlcpy(args->ar_hostdata, &tmp[0],
118                                       GFS2_LOCKNAME_LEN);
119                         break;
120                 case Opt_spectator:
121                         args->ar_spectator = 1;
122                         break;
123                 case Opt_ignore_local_fs:
124                         args->ar_ignore_local_fs = 1;
125                         break;
126                 case Opt_localflocks:
127                         args->ar_localflocks = 1;
128                         break;
129                 case Opt_localcaching:
130                         args->ar_localcaching = 1;
131                         break;
132                 case Opt_debug:
133                         args->ar_debug = 1;
134                         break;
135                 case Opt_nodebug:
136                         args->ar_debug = 0;
137                         break;
138                 case Opt_upgrade:
139                         args->ar_upgrade = 1;
140                         break;
141                 case Opt_acl:
142                         args->ar_posix_acl = 1;
143                         break;
144                 case Opt_noacl:
145                         args->ar_posix_acl = 0;
146                         break;
147                 case Opt_quota_off:
148                 case Opt_noquota:
149                         args->ar_quota = GFS2_QUOTA_OFF;
150                         break;
151                 case Opt_quota_account:
152                         args->ar_quota = GFS2_QUOTA_ACCOUNT;
153                         break;
154                 case Opt_quota_on:
155                 case Opt_quota:
156                         args->ar_quota = GFS2_QUOTA_ON;
157                         break;
158                 case Opt_suiddir:
159                         args->ar_suiddir = 1;
160                         break;
161                 case Opt_nosuiddir:
162                         args->ar_suiddir = 0;
163                         break;
164                 case Opt_data_writeback:
165                         args->ar_data = GFS2_DATA_WRITEBACK;
166                         break;
167                 case Opt_data_ordered:
168                         args->ar_data = GFS2_DATA_ORDERED;
169                         break;
170                 case Opt_meta:
171                         args->ar_meta = 1;
172                         break;
173                 case Opt_discard:
174                         args->ar_discard = 1;
175                         break;
176                 case Opt_nodiscard:
177                         args->ar_discard = 0;
178                         break;
179                 case Opt_commit:
180                         rv = match_int(&tmp[0], &args->ar_commit);
181                         if (rv || args->ar_commit <= 0) {
182                                 fs_info(sdp, "commit mount option requires a positive numeric argument\n");
183                                 return rv ? rv : -EINVAL;
184                         }
185                         break;
186                 case Opt_err:
187                 default:
188                         fs_info(sdp, "invalid mount option: %s\n", o);
189                         return -EINVAL;
190                 }
191         }
192
193         return 0;
194 }
195