David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. |
Steven Whitehouse | 3a8a9a1 | 2006-05-18 15:09:15 -0400 | [diff] [blame] | 3 | * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 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 |
Steven Whitehouse | e9fc2aa | 2006-09-01 11:05:15 -0400 | [diff] [blame] | 7 | * of the GNU General Public License version 2. |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 10 | #include <linux/slab.h> |
| 11 | #include <linux/spinlock.h> |
| 12 | #include <linux/completion.h> |
| 13 | #include <linux/buffer_head.h> |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 14 | #include <linux/gfs2_ondisk.h> |
Fabio Massimo Di Nitto | 7d30859 | 2006-09-19 07:56:29 +0200 | [diff] [blame] | 15 | #include <linux/lm_interface.h> |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 16 | #include <linux/parser.h> |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 17 | |
| 18 | #include "gfs2.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 19 | #include "incore.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 20 | #include "mount.h" |
| 21 | #include "sys.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 22 | #include "util.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 23 | |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 24 | enum { |
| 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, |
Benjamin Marzinski | 9a5ad13 | 2007-08-17 20:22:07 -0500 | [diff] [blame] | 45 | Opt_err, |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | static match_table_t tokens = { |
| 49 | {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"}, |
| 59 | {Opt_num_glockd, "num_glockd=%d"}, |
| 60 | {Opt_acl, "acl"}, |
| 61 | {Opt_noacl, "noacl"}, |
| 62 | {Opt_quota_off, "quota=off"}, |
| 63 | {Opt_quota_account, "quota=account"}, |
| 64 | {Opt_quota_on, "quota=on"}, |
| 65 | {Opt_suiddir, "suiddir"}, |
| 66 | {Opt_nosuiddir, "nosuiddir"}, |
| 67 | {Opt_data_writeback, "data=writeback"}, |
Benjamin Marzinski | 9a5ad13 | 2007-08-17 20:22:07 -0500 | [diff] [blame] | 68 | {Opt_data_ordered, "data=ordered"}, |
| 69 | {Opt_err, NULL} |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 70 | }; |
| 71 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 72 | /** |
| 73 | * gfs2_mount_args - Parse mount options |
| 74 | * @sdp: |
| 75 | * @data: |
| 76 | * |
| 77 | * Return: errno |
| 78 | */ |
| 79 | |
| 80 | int 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 Whitehouse | d18c4d6 | 2007-07-19 16:12:50 +0100 | [diff] [blame] | 87 | if (!remount) { |
| 88 | /* If someone preloaded options, use those instead */ |
| 89 | spin_lock(&gfs2_sys_margs_lock); |
| 90 | if (gfs2_sys_margs) { |
| 91 | data = gfs2_sys_margs; |
| 92 | gfs2_sys_margs = NULL; |
| 93 | } |
| 94 | spin_unlock(&gfs2_sys_margs_lock); |
Bob Peterson | 569a7b6 | 2007-06-27 10:15:56 -0500 | [diff] [blame] | 95 | |
Steven Whitehouse | d18c4d6 | 2007-07-19 16:12:50 +0100 | [diff] [blame] | 96 | /* Set some defaults */ |
| 97 | args->ar_num_glockd = GFS2_GLOCKD_DEFAULT; |
| 98 | args->ar_quota = GFS2_QUOTA_DEFAULT; |
| 99 | args->ar_data = GFS2_DATA_DEFAULT; |
| 100 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 101 | |
| 102 | /* Split the options into tokens with the "," character and |
| 103 | process them */ |
| 104 | |
| 105 | for (options = data; (o = strsep(&options, ",")); ) { |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 106 | int token, option; |
| 107 | substring_t tmp[MAX_OPT_ARGS]; |
| 108 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 109 | if (!*o) |
| 110 | continue; |
| 111 | |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 112 | token = match_token(o, tokens, tmp); |
| 113 | switch (token) { |
| 114 | case Opt_lockproto: |
| 115 | v = match_strdup(&tmp[0]); |
| 116 | if (!v) { |
| 117 | fs_info(sdp, "no memory for lockproto\n"); |
| 118 | error = -ENOMEM; |
| 119 | goto out_error; |
| 120 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 121 | |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 122 | if (remount && strcmp(v, args->ar_lockproto)) { |
| 123 | kfree(v); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 124 | goto cant_remount; |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 125 | } |
| 126 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 127 | strncpy(args->ar_lockproto, v, GFS2_LOCKNAME_LEN); |
| 128 | args->ar_lockproto[GFS2_LOCKNAME_LEN - 1] = 0; |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 129 | kfree(v); |
| 130 | break; |
| 131 | case Opt_locktable: |
| 132 | v = match_strdup(&tmp[0]); |
| 133 | if (!v) { |
| 134 | fs_info(sdp, "no memory for locktable\n"); |
| 135 | error = -ENOMEM; |
| 136 | goto out_error; |
| 137 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 138 | |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 139 | if (remount && strcmp(v, args->ar_locktable)) { |
| 140 | kfree(v); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 141 | goto cant_remount; |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 142 | } |
| 143 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 144 | strncpy(args->ar_locktable, v, GFS2_LOCKNAME_LEN); |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 145 | args->ar_locktable[GFS2_LOCKNAME_LEN - 1] = 0; |
| 146 | kfree(v); |
| 147 | break; |
| 148 | case Opt_hostdata: |
| 149 | v = match_strdup(&tmp[0]); |
| 150 | if (!v) { |
| 151 | fs_info(sdp, "no memory for hostdata\n"); |
| 152 | error = -ENOMEM; |
| 153 | goto out_error; |
| 154 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 155 | |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 156 | if (remount && strcmp(v, args->ar_hostdata)) { |
| 157 | kfree(v); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 158 | goto cant_remount; |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 159 | } |
| 160 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 161 | strncpy(args->ar_hostdata, v, GFS2_LOCKNAME_LEN); |
| 162 | args->ar_hostdata[GFS2_LOCKNAME_LEN - 1] = 0; |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 163 | kfree(v); |
| 164 | break; |
| 165 | case Opt_spectator: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 166 | if (remount && !args->ar_spectator) |
| 167 | goto cant_remount; |
| 168 | args->ar_spectator = 1; |
| 169 | sdp->sd_vfs->s_flags |= MS_RDONLY; |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 170 | break; |
| 171 | case Opt_ignore_local_fs: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 172 | if (remount && !args->ar_ignore_local_fs) |
| 173 | goto cant_remount; |
| 174 | args->ar_ignore_local_fs = 1; |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 175 | break; |
| 176 | case Opt_localflocks: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 177 | if (remount && !args->ar_localflocks) |
| 178 | goto cant_remount; |
| 179 | args->ar_localflocks = 1; |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 180 | break; |
| 181 | case Opt_localcaching: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 182 | if (remount && !args->ar_localcaching) |
| 183 | goto cant_remount; |
| 184 | args->ar_localcaching = 1; |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 185 | break; |
| 186 | case Opt_debug: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 187 | args->ar_debug = 1; |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 188 | break; |
| 189 | case Opt_nodebug: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 190 | args->ar_debug = 0; |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 191 | break; |
| 192 | case Opt_upgrade: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 193 | if (remount && !args->ar_upgrade) |
| 194 | goto cant_remount; |
| 195 | args->ar_upgrade = 1; |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 196 | break; |
| 197 | case Opt_num_glockd: |
| 198 | if ((error = match_int(&tmp[0], &option))) { |
| 199 | fs_info(sdp, "problem getting num_glockd\n"); |
| 200 | goto out_error; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 201 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 202 | |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 203 | if (remount && option != args->ar_num_glockd) |
| 204 | goto cant_remount; |
| 205 | if (!option || option > GFS2_GLOCKD_MAX) { |
| 206 | fs_info(sdp, "0 < num_glockd <= %u (not %u)\n", |
| 207 | GFS2_GLOCKD_MAX, option); |
| 208 | error = -EINVAL; |
| 209 | goto out_error; |
| 210 | } |
| 211 | args->ar_num_glockd = option; |
| 212 | break; |
| 213 | case Opt_acl: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 214 | args->ar_posix_acl = 1; |
| 215 | sdp->sd_vfs->s_flags |= MS_POSIXACL; |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 216 | break; |
| 217 | case Opt_noacl: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 218 | args->ar_posix_acl = 0; |
| 219 | sdp->sd_vfs->s_flags &= ~MS_POSIXACL; |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 220 | break; |
| 221 | case Opt_quota_off: |
| 222 | args->ar_quota = GFS2_QUOTA_OFF; |
| 223 | break; |
| 224 | case Opt_quota_account: |
| 225 | args->ar_quota = GFS2_QUOTA_ACCOUNT; |
| 226 | break; |
| 227 | case Opt_quota_on: |
| 228 | args->ar_quota = GFS2_QUOTA_ON; |
| 229 | break; |
| 230 | case Opt_suiddir: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 231 | args->ar_suiddir = 1; |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 232 | break; |
| 233 | case Opt_nosuiddir: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 234 | args->ar_suiddir = 0; |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 235 | break; |
| 236 | case Opt_data_writeback: |
| 237 | args->ar_data = GFS2_DATA_WRITEBACK; |
| 238 | break; |
| 239 | case Opt_data_ordered: |
| 240 | args->ar_data = GFS2_DATA_ORDERED; |
| 241 | break; |
Benjamin Marzinski | 9a5ad13 | 2007-08-17 20:22:07 -0500 | [diff] [blame] | 242 | case Opt_err: |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 243 | default: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 244 | fs_info(sdp, "unknown option: %s\n", o); |
| 245 | error = -EINVAL; |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 246 | goto out_error; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 247 | } |
| 248 | } |
| 249 | |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 250 | out_error: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 251 | if (error) |
| 252 | fs_info(sdp, "invalid mount option(s)\n"); |
| 253 | |
| 254 | if (data != data_arg) |
| 255 | kfree(data); |
| 256 | |
| 257 | return error; |
| 258 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 259 | cant_remount: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 260 | fs_info(sdp, "can't remount with option %s\n", o); |
| 261 | return -EINVAL; |
| 262 | } |
| 263 | |