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, |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 35 | 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 Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 44 | Opt_meta, |
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 | |
Steven Whitehouse | a447c09 | 2008-10-13 10:46:57 +0100 | [diff] [blame] | 48 | static const match_table_t tokens = { |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 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"}, |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 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"}, |
Benjamin Marzinski | 9a5ad13 | 2007-08-17 20:22:07 -0500 | [diff] [blame] | 67 | {Opt_data_ordered, "data=ordered"}, |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 68 | {Opt_meta, "meta"}, |
Benjamin Marzinski | 9a5ad13 | 2007-08-17 20:22:07 -0500 | [diff] [blame] | 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 */ |
Steven Whitehouse | d18c4d6 | 2007-07-19 16:12:50 +0100 | [diff] [blame] | 97 | args->ar_quota = GFS2_QUOTA_DEFAULT; |
| 98 | args->ar_data = GFS2_DATA_DEFAULT; |
| 99 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 100 | |
| 101 | /* Split the options into tokens with the "," character and |
| 102 | process them */ |
| 103 | |
| 104 | for (options = data; (o = strsep(&options, ",")); ) { |
Steven Whitehouse | 97cc1025 | 2008-11-20 13:39:47 +0000 | [diff] [blame^] | 105 | int token; |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 106 | substring_t tmp[MAX_OPT_ARGS]; |
| 107 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 108 | if (!*o) |
| 109 | continue; |
| 110 | |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 111 | token = match_token(o, tokens, tmp); |
| 112 | switch (token) { |
| 113 | case Opt_lockproto: |
| 114 | v = match_strdup(&tmp[0]); |
| 115 | if (!v) { |
| 116 | fs_info(sdp, "no memory for lockproto\n"); |
| 117 | error = -ENOMEM; |
| 118 | goto out_error; |
| 119 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 120 | |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 121 | if (remount && strcmp(v, args->ar_lockproto)) { |
| 122 | kfree(v); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 123 | goto cant_remount; |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 124 | } |
| 125 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 126 | strncpy(args->ar_lockproto, v, GFS2_LOCKNAME_LEN); |
| 127 | args->ar_lockproto[GFS2_LOCKNAME_LEN - 1] = 0; |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 128 | kfree(v); |
| 129 | break; |
| 130 | case Opt_locktable: |
| 131 | v = match_strdup(&tmp[0]); |
| 132 | if (!v) { |
| 133 | fs_info(sdp, "no memory for locktable\n"); |
| 134 | error = -ENOMEM; |
| 135 | goto out_error; |
| 136 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 137 | |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 138 | if (remount && strcmp(v, args->ar_locktable)) { |
| 139 | kfree(v); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 140 | goto cant_remount; |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 141 | } |
| 142 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 143 | strncpy(args->ar_locktable, v, GFS2_LOCKNAME_LEN); |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 144 | args->ar_locktable[GFS2_LOCKNAME_LEN - 1] = 0; |
| 145 | kfree(v); |
| 146 | break; |
| 147 | case Opt_hostdata: |
| 148 | v = match_strdup(&tmp[0]); |
| 149 | if (!v) { |
| 150 | fs_info(sdp, "no memory for hostdata\n"); |
| 151 | error = -ENOMEM; |
| 152 | goto out_error; |
| 153 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 154 | |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 155 | if (remount && strcmp(v, args->ar_hostdata)) { |
| 156 | kfree(v); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 157 | goto cant_remount; |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 158 | } |
| 159 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 160 | strncpy(args->ar_hostdata, v, GFS2_LOCKNAME_LEN); |
| 161 | args->ar_hostdata[GFS2_LOCKNAME_LEN - 1] = 0; |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 162 | kfree(v); |
| 163 | break; |
| 164 | case Opt_spectator: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 165 | if (remount && !args->ar_spectator) |
| 166 | goto cant_remount; |
| 167 | args->ar_spectator = 1; |
| 168 | sdp->sd_vfs->s_flags |= MS_RDONLY; |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 169 | break; |
| 170 | case Opt_ignore_local_fs: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 171 | if (remount && !args->ar_ignore_local_fs) |
| 172 | goto cant_remount; |
| 173 | args->ar_ignore_local_fs = 1; |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 174 | break; |
| 175 | case Opt_localflocks: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 176 | if (remount && !args->ar_localflocks) |
| 177 | goto cant_remount; |
| 178 | args->ar_localflocks = 1; |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 179 | break; |
| 180 | case Opt_localcaching: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 181 | if (remount && !args->ar_localcaching) |
| 182 | goto cant_remount; |
| 183 | args->ar_localcaching = 1; |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 184 | break; |
| 185 | case Opt_debug: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 186 | args->ar_debug = 1; |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 187 | break; |
| 188 | case Opt_nodebug: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 189 | args->ar_debug = 0; |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 190 | break; |
| 191 | case Opt_upgrade: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 192 | if (remount && !args->ar_upgrade) |
| 193 | goto cant_remount; |
| 194 | args->ar_upgrade = 1; |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 195 | break; |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 196 | case Opt_acl: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 197 | args->ar_posix_acl = 1; |
| 198 | sdp->sd_vfs->s_flags |= MS_POSIXACL; |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 199 | break; |
| 200 | case Opt_noacl: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 201 | args->ar_posix_acl = 0; |
| 202 | sdp->sd_vfs->s_flags &= ~MS_POSIXACL; |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 203 | break; |
| 204 | case Opt_quota_off: |
| 205 | args->ar_quota = GFS2_QUOTA_OFF; |
| 206 | break; |
| 207 | case Opt_quota_account: |
| 208 | args->ar_quota = GFS2_QUOTA_ACCOUNT; |
| 209 | break; |
| 210 | case Opt_quota_on: |
| 211 | args->ar_quota = GFS2_QUOTA_ON; |
| 212 | break; |
| 213 | case Opt_suiddir: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 214 | args->ar_suiddir = 1; |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 215 | break; |
| 216 | case Opt_nosuiddir: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 217 | args->ar_suiddir = 0; |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 218 | break; |
| 219 | case Opt_data_writeback: |
| 220 | args->ar_data = GFS2_DATA_WRITEBACK; |
| 221 | break; |
| 222 | case Opt_data_ordered: |
| 223 | args->ar_data = GFS2_DATA_ORDERED; |
| 224 | break; |
Steven Whitehouse | 9b8df98 | 2008-08-08 13:45:13 +0100 | [diff] [blame] | 225 | case Opt_meta: |
| 226 | if (remount && args->ar_meta != 1) |
| 227 | goto cant_remount; |
| 228 | args->ar_meta = 1; |
| 229 | break; |
Benjamin Marzinski | 9a5ad13 | 2007-08-17 20:22:07 -0500 | [diff] [blame] | 230 | case Opt_err: |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 231 | default: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 232 | fs_info(sdp, "unknown option: %s\n", o); |
| 233 | error = -EINVAL; |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 234 | goto out_error; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 235 | } |
| 236 | } |
| 237 | |
Josef Bacik | 476c006 | 2007-04-23 11:55:39 -0400 | [diff] [blame] | 238 | out_error: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 239 | if (error) |
| 240 | fs_info(sdp, "invalid mount option(s)\n"); |
| 241 | |
| 242 | if (data != data_arg) |
| 243 | kfree(data); |
| 244 | |
| 245 | return error; |
| 246 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 247 | cant_remount: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 248 | fs_info(sdp, "can't remount with option %s\n", o); |
| 249 | return -EINVAL; |
| 250 | } |
| 251 | |