David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. |
Bob Peterson | da6dd40 | 2007-12-11 18:49:21 -0600 | [diff] [blame] | 3 | * Copyright (C) 2004-2007 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 | |
Joe Perches | d77d1b5 | 2014-03-06 12:10:45 -0800 | [diff] [blame] | 10 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 11 | |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 12 | #include <linux/bio.h> |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 13 | #include <linux/sched.h> |
| 14 | #include <linux/slab.h> |
| 15 | #include <linux/spinlock.h> |
| 16 | #include <linux/completion.h> |
| 17 | #include <linux/buffer_head.h> |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 18 | #include <linux/statfs.h> |
| 19 | #include <linux/seq_file.h> |
| 20 | #include <linux/mount.h> |
| 21 | #include <linux/kthread.h> |
| 22 | #include <linux/delay.h> |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 23 | #include <linux/gfs2_ondisk.h> |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 24 | #include <linux/crc32.h> |
| 25 | #include <linux/time.h> |
Steven Whitehouse | e402746 | 2010-01-25 11:20:19 +0000 | [diff] [blame] | 26 | #include <linux/wait.h> |
Christoph Hellwig | a9185b4 | 2010-03-05 09:21:37 +0100 | [diff] [blame] | 27 | #include <linux/writeback.h> |
Steven Whitehouse | 4667a0e | 2011-04-18 14:18:09 +0100 | [diff] [blame] | 28 | #include <linux/backing-dev.h> |
Benjamin Marzinski | 2e60d76 | 2014-11-13 20:42:04 -0600 | [diff] [blame] | 29 | #include <linux/kernel.h> |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 30 | |
| 31 | #include "gfs2.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 32 | #include "incore.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 33 | #include "bmap.h" |
| 34 | #include "dir.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 35 | #include "glock.h" |
| 36 | #include "glops.h" |
| 37 | #include "inode.h" |
| 38 | #include "log.h" |
| 39 | #include "meta_io.h" |
| 40 | #include "quota.h" |
| 41 | #include "recovery.h" |
| 42 | #include "rgrp.h" |
| 43 | #include "super.h" |
| 44 | #include "trans.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 45 | #include "util.h" |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 46 | #include "sys.h" |
Steven Whitehouse | 307cf6e | 2009-08-26 18:51:04 +0100 | [diff] [blame] | 47 | #include "xattr.h" |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 48 | |
| 49 | #define args_neq(a1, a2, x) ((a1)->ar_##x != (a2)->ar_##x) |
| 50 | |
| 51 | enum { |
| 52 | Opt_lockproto, |
| 53 | Opt_locktable, |
| 54 | Opt_hostdata, |
| 55 | Opt_spectator, |
| 56 | Opt_ignore_local_fs, |
| 57 | Opt_localflocks, |
| 58 | Opt_localcaching, |
| 59 | Opt_debug, |
| 60 | Opt_nodebug, |
| 61 | Opt_upgrade, |
| 62 | Opt_acl, |
| 63 | Opt_noacl, |
| 64 | Opt_quota_off, |
| 65 | Opt_quota_account, |
| 66 | Opt_quota_on, |
| 67 | Opt_quota, |
| 68 | Opt_noquota, |
| 69 | Opt_suiddir, |
| 70 | Opt_nosuiddir, |
| 71 | Opt_data_writeback, |
| 72 | Opt_data_ordered, |
| 73 | Opt_meta, |
| 74 | Opt_discard, |
| 75 | Opt_nodiscard, |
| 76 | Opt_commit, |
Bob Peterson | d34843d | 2009-08-24 10:44:18 +0100 | [diff] [blame] | 77 | Opt_err_withdraw, |
| 78 | Opt_err_panic, |
Benjamin Marzinski | 3d3c10f | 2009-10-20 02:39:44 -0500 | [diff] [blame] | 79 | Opt_statfs_quantum, |
| 80 | Opt_statfs_percent, |
| 81 | Opt_quota_quantum, |
Christoph Hellwig | f25934c | 2009-10-30 08:03:27 +0100 | [diff] [blame] | 82 | Opt_barrier, |
| 83 | Opt_nobarrier, |
Benjamin Marzinski | 90306c4 | 2012-05-29 23:01:09 -0500 | [diff] [blame] | 84 | Opt_rgrplvb, |
| 85 | Opt_norgrplvb, |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 86 | Opt_error, |
| 87 | }; |
| 88 | |
| 89 | static const match_table_t tokens = { |
| 90 | {Opt_lockproto, "lockproto=%s"}, |
| 91 | {Opt_locktable, "locktable=%s"}, |
| 92 | {Opt_hostdata, "hostdata=%s"}, |
| 93 | {Opt_spectator, "spectator"}, |
Steven Whitehouse | 43f74c1 | 2010-09-29 14:24:41 +0100 | [diff] [blame] | 94 | {Opt_spectator, "norecovery"}, |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 95 | {Opt_ignore_local_fs, "ignore_local_fs"}, |
| 96 | {Opt_localflocks, "localflocks"}, |
| 97 | {Opt_localcaching, "localcaching"}, |
| 98 | {Opt_debug, "debug"}, |
| 99 | {Opt_nodebug, "nodebug"}, |
| 100 | {Opt_upgrade, "upgrade"}, |
| 101 | {Opt_acl, "acl"}, |
| 102 | {Opt_noacl, "noacl"}, |
| 103 | {Opt_quota_off, "quota=off"}, |
| 104 | {Opt_quota_account, "quota=account"}, |
| 105 | {Opt_quota_on, "quota=on"}, |
| 106 | {Opt_quota, "quota"}, |
| 107 | {Opt_noquota, "noquota"}, |
| 108 | {Opt_suiddir, "suiddir"}, |
| 109 | {Opt_nosuiddir, "nosuiddir"}, |
| 110 | {Opt_data_writeback, "data=writeback"}, |
| 111 | {Opt_data_ordered, "data=ordered"}, |
| 112 | {Opt_meta, "meta"}, |
| 113 | {Opt_discard, "discard"}, |
| 114 | {Opt_nodiscard, "nodiscard"}, |
| 115 | {Opt_commit, "commit=%d"}, |
Bob Peterson | d34843d | 2009-08-24 10:44:18 +0100 | [diff] [blame] | 116 | {Opt_err_withdraw, "errors=withdraw"}, |
| 117 | {Opt_err_panic, "errors=panic"}, |
Benjamin Marzinski | 3d3c10f | 2009-10-20 02:39:44 -0500 | [diff] [blame] | 118 | {Opt_statfs_quantum, "statfs_quantum=%d"}, |
| 119 | {Opt_statfs_percent, "statfs_percent=%d"}, |
| 120 | {Opt_quota_quantum, "quota_quantum=%d"}, |
Christoph Hellwig | f25934c | 2009-10-30 08:03:27 +0100 | [diff] [blame] | 121 | {Opt_barrier, "barrier"}, |
| 122 | {Opt_nobarrier, "nobarrier"}, |
Benjamin Marzinski | 90306c4 | 2012-05-29 23:01:09 -0500 | [diff] [blame] | 123 | {Opt_rgrplvb, "rgrplvb"}, |
| 124 | {Opt_norgrplvb, "norgrplvb"}, |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 125 | {Opt_error, NULL} |
| 126 | }; |
| 127 | |
| 128 | /** |
| 129 | * gfs2_mount_args - Parse mount options |
Steven Whitehouse | f55073f | 2009-09-28 10:30:49 +0100 | [diff] [blame] | 130 | * @args: The structure into which the parsed options will be written |
| 131 | * @options: The options to parse |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 132 | * |
| 133 | * Return: errno |
| 134 | */ |
| 135 | |
Steven Whitehouse | f55073f | 2009-09-28 10:30:49 +0100 | [diff] [blame] | 136 | int gfs2_mount_args(struct gfs2_args *args, char *options) |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 137 | { |
| 138 | char *o; |
| 139 | int token; |
| 140 | substring_t tmp[MAX_OPT_ARGS]; |
| 141 | int rv; |
| 142 | |
| 143 | /* Split the options into tokens with the "," character and |
| 144 | process them */ |
| 145 | |
| 146 | while (1) { |
| 147 | o = strsep(&options, ","); |
| 148 | if (o == NULL) |
| 149 | break; |
| 150 | if (*o == '\0') |
| 151 | continue; |
| 152 | |
| 153 | token = match_token(o, tokens, tmp); |
| 154 | switch (token) { |
| 155 | case Opt_lockproto: |
| 156 | match_strlcpy(args->ar_lockproto, &tmp[0], |
| 157 | GFS2_LOCKNAME_LEN); |
| 158 | break; |
| 159 | case Opt_locktable: |
| 160 | match_strlcpy(args->ar_locktable, &tmp[0], |
| 161 | GFS2_LOCKNAME_LEN); |
| 162 | break; |
| 163 | case Opt_hostdata: |
| 164 | match_strlcpy(args->ar_hostdata, &tmp[0], |
| 165 | GFS2_LOCKNAME_LEN); |
| 166 | break; |
| 167 | case Opt_spectator: |
| 168 | args->ar_spectator = 1; |
| 169 | break; |
| 170 | case Opt_ignore_local_fs: |
Steven Whitehouse | f57a024 | 2010-09-23 13:41:42 +0100 | [diff] [blame] | 171 | /* Retained for backwards compat only */ |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 172 | break; |
| 173 | case Opt_localflocks: |
| 174 | args->ar_localflocks = 1; |
| 175 | break; |
| 176 | case Opt_localcaching: |
Steven Whitehouse | c2048b00 | 2010-09-23 14:00:31 +0100 | [diff] [blame] | 177 | /* Retained for backwards compat only */ |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 178 | break; |
| 179 | case Opt_debug: |
Bob Peterson | d34843d | 2009-08-24 10:44:18 +0100 | [diff] [blame] | 180 | if (args->ar_errors == GFS2_ERRORS_PANIC) { |
Joe Perches | d77d1b5 | 2014-03-06 12:10:45 -0800 | [diff] [blame] | 181 | pr_warn("-o debug and -o errors=panic are mutually exclusive\n"); |
Bob Peterson | d34843d | 2009-08-24 10:44:18 +0100 | [diff] [blame] | 182 | return -EINVAL; |
| 183 | } |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 184 | args->ar_debug = 1; |
| 185 | break; |
| 186 | case Opt_nodebug: |
| 187 | args->ar_debug = 0; |
| 188 | break; |
| 189 | case Opt_upgrade: |
Steven Whitehouse | c80dbb5 | 2010-09-24 09:55:07 +0100 | [diff] [blame] | 190 | /* Retained for backwards compat only */ |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 191 | break; |
| 192 | case Opt_acl: |
| 193 | args->ar_posix_acl = 1; |
| 194 | break; |
| 195 | case Opt_noacl: |
| 196 | args->ar_posix_acl = 0; |
| 197 | break; |
| 198 | case Opt_quota_off: |
| 199 | case Opt_noquota: |
| 200 | args->ar_quota = GFS2_QUOTA_OFF; |
| 201 | break; |
| 202 | case Opt_quota_account: |
| 203 | args->ar_quota = GFS2_QUOTA_ACCOUNT; |
| 204 | break; |
| 205 | case Opt_quota_on: |
| 206 | case Opt_quota: |
| 207 | args->ar_quota = GFS2_QUOTA_ON; |
| 208 | break; |
| 209 | case Opt_suiddir: |
| 210 | args->ar_suiddir = 1; |
| 211 | break; |
| 212 | case Opt_nosuiddir: |
| 213 | args->ar_suiddir = 0; |
| 214 | break; |
| 215 | case Opt_data_writeback: |
| 216 | args->ar_data = GFS2_DATA_WRITEBACK; |
| 217 | break; |
| 218 | case Opt_data_ordered: |
| 219 | args->ar_data = GFS2_DATA_ORDERED; |
| 220 | break; |
| 221 | case Opt_meta: |
| 222 | args->ar_meta = 1; |
| 223 | break; |
| 224 | case Opt_discard: |
| 225 | args->ar_discard = 1; |
| 226 | break; |
| 227 | case Opt_nodiscard: |
| 228 | args->ar_discard = 0; |
| 229 | break; |
| 230 | case Opt_commit: |
| 231 | rv = match_int(&tmp[0], &args->ar_commit); |
| 232 | if (rv || args->ar_commit <= 0) { |
Joe Perches | d77d1b5 | 2014-03-06 12:10:45 -0800 | [diff] [blame] | 233 | pr_warn("commit mount option requires a positive numeric argument\n"); |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 234 | return rv ? rv : -EINVAL; |
| 235 | } |
| 236 | break; |
Benjamin Marzinski | 3d3c10f | 2009-10-20 02:39:44 -0500 | [diff] [blame] | 237 | case Opt_statfs_quantum: |
| 238 | rv = match_int(&tmp[0], &args->ar_statfs_quantum); |
| 239 | if (rv || args->ar_statfs_quantum < 0) { |
Joe Perches | d77d1b5 | 2014-03-06 12:10:45 -0800 | [diff] [blame] | 240 | pr_warn("statfs_quantum mount option requires a non-negative numeric argument\n"); |
Benjamin Marzinski | 3d3c10f | 2009-10-20 02:39:44 -0500 | [diff] [blame] | 241 | return rv ? rv : -EINVAL; |
| 242 | } |
| 243 | break; |
| 244 | case Opt_quota_quantum: |
| 245 | rv = match_int(&tmp[0], &args->ar_quota_quantum); |
| 246 | if (rv || args->ar_quota_quantum <= 0) { |
Joe Perches | d77d1b5 | 2014-03-06 12:10:45 -0800 | [diff] [blame] | 247 | pr_warn("quota_quantum mount option requires a positive numeric argument\n"); |
Benjamin Marzinski | 3d3c10f | 2009-10-20 02:39:44 -0500 | [diff] [blame] | 248 | return rv ? rv : -EINVAL; |
| 249 | } |
| 250 | break; |
| 251 | case Opt_statfs_percent: |
| 252 | rv = match_int(&tmp[0], &args->ar_statfs_percent); |
| 253 | if (rv || args->ar_statfs_percent < 0 || |
| 254 | args->ar_statfs_percent > 100) { |
Fabian Frederick | fc554ed | 2014-03-05 22:06:42 +0800 | [diff] [blame] | 255 | pr_warn("statfs_percent mount option requires a numeric argument between 0 and 100\n"); |
Benjamin Marzinski | 3d3c10f | 2009-10-20 02:39:44 -0500 | [diff] [blame] | 256 | return rv ? rv : -EINVAL; |
| 257 | } |
| 258 | break; |
Bob Peterson | d34843d | 2009-08-24 10:44:18 +0100 | [diff] [blame] | 259 | case Opt_err_withdraw: |
| 260 | args->ar_errors = GFS2_ERRORS_WITHDRAW; |
| 261 | break; |
| 262 | case Opt_err_panic: |
| 263 | if (args->ar_debug) { |
Joe Perches | d77d1b5 | 2014-03-06 12:10:45 -0800 | [diff] [blame] | 264 | pr_warn("-o debug and -o errors=panic are mutually exclusive\n"); |
Bob Peterson | d34843d | 2009-08-24 10:44:18 +0100 | [diff] [blame] | 265 | return -EINVAL; |
| 266 | } |
| 267 | args->ar_errors = GFS2_ERRORS_PANIC; |
| 268 | break; |
Christoph Hellwig | f25934c | 2009-10-30 08:03:27 +0100 | [diff] [blame] | 269 | case Opt_barrier: |
| 270 | args->ar_nobarrier = 0; |
| 271 | break; |
| 272 | case Opt_nobarrier: |
| 273 | args->ar_nobarrier = 1; |
| 274 | break; |
Benjamin Marzinski | 90306c4 | 2012-05-29 23:01:09 -0500 | [diff] [blame] | 275 | case Opt_rgrplvb: |
| 276 | args->ar_rgrplvb = 1; |
| 277 | break; |
| 278 | case Opt_norgrplvb: |
| 279 | args->ar_rgrplvb = 0; |
| 280 | break; |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 281 | case Opt_error: |
| 282 | default: |
Joe Perches | d77d1b5 | 2014-03-06 12:10:45 -0800 | [diff] [blame] | 283 | pr_warn("invalid mount option: %s\n", o); |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 284 | return -EINVAL; |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | return 0; |
| 289 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 290 | |
Steven Whitehouse | fefc03b | 2008-12-19 15:32:06 +0000 | [diff] [blame] | 291 | /** |
| 292 | * gfs2_jindex_free - Clear all the journal index information |
| 293 | * @sdp: The GFS2 superblock |
| 294 | * |
| 295 | */ |
| 296 | |
| 297 | void gfs2_jindex_free(struct gfs2_sbd *sdp) |
| 298 | { |
Steven Whitehouse | b50f227 | 2014-03-03 13:35:57 +0000 | [diff] [blame] | 299 | struct list_head list; |
Steven Whitehouse | fefc03b | 2008-12-19 15:32:06 +0000 | [diff] [blame] | 300 | struct gfs2_jdesc *jd; |
Steven Whitehouse | fefc03b | 2008-12-19 15:32:06 +0000 | [diff] [blame] | 301 | |
| 302 | spin_lock(&sdp->sd_jindex_spin); |
| 303 | list_add(&list, &sdp->sd_jindex_list); |
| 304 | list_del_init(&sdp->sd_jindex_list); |
| 305 | sdp->sd_journals = 0; |
| 306 | spin_unlock(&sdp->sd_jindex_spin); |
| 307 | |
| 308 | while (!list_empty(&list)) { |
| 309 | jd = list_entry(list.next, struct gfs2_jdesc, jd_list); |
Steven Whitehouse | b50f227 | 2014-03-03 13:35:57 +0000 | [diff] [blame] | 310 | gfs2_free_journal_extents(jd); |
Steven Whitehouse | fefc03b | 2008-12-19 15:32:06 +0000 | [diff] [blame] | 311 | list_del(&jd->jd_list); |
| 312 | iput(jd->jd_inode); |
| 313 | kfree(jd); |
| 314 | } |
| 315 | } |
| 316 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 317 | static struct gfs2_jdesc *jdesc_find_i(struct list_head *head, unsigned int jid) |
| 318 | { |
| 319 | struct gfs2_jdesc *jd; |
| 320 | int found = 0; |
| 321 | |
| 322 | list_for_each_entry(jd, head, jd_list) { |
| 323 | if (jd->jd_jid == jid) { |
| 324 | found = 1; |
| 325 | break; |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | if (!found) |
| 330 | jd = NULL; |
| 331 | |
| 332 | return jd; |
| 333 | } |
| 334 | |
| 335 | struct gfs2_jdesc *gfs2_jdesc_find(struct gfs2_sbd *sdp, unsigned int jid) |
| 336 | { |
| 337 | struct gfs2_jdesc *jd; |
| 338 | |
| 339 | spin_lock(&sdp->sd_jindex_spin); |
| 340 | jd = jdesc_find_i(&sdp->sd_jindex_list, jid); |
| 341 | spin_unlock(&sdp->sd_jindex_spin); |
| 342 | |
| 343 | return jd; |
| 344 | } |
| 345 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 346 | int gfs2_jdesc_check(struct gfs2_jdesc *jd) |
| 347 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 348 | struct gfs2_inode *ip = GFS2_I(jd->jd_inode); |
| 349 | struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode); |
Steven Whitehouse | a2e0f79 | 2010-08-11 09:53:11 +0100 | [diff] [blame] | 350 | u64 size = i_size_read(jd->jd_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 351 | |
Steven Whitehouse | a2e0f79 | 2010-08-11 09:53:11 +0100 | [diff] [blame] | 352 | if (gfs2_check_internal_file_size(jd->jd_inode, 8 << 20, 1 << 30)) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 353 | return -EIO; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 354 | |
Steven Whitehouse | a2e0f79 | 2010-08-11 09:53:11 +0100 | [diff] [blame] | 355 | jd->jd_blocks = size >> sdp->sd_sb.sb_bsize_shift; |
| 356 | |
| 357 | if (gfs2_write_alloc_required(ip, 0, size)) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 358 | gfs2_consist_inode(ip); |
Bob Peterson | 461cb41 | 2010-06-24 19:21:20 -0400 | [diff] [blame] | 359 | return -EIO; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 360 | } |
| 361 | |
Bob Peterson | 461cb41 | 2010-06-24 19:21:20 -0400 | [diff] [blame] | 362 | return 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 363 | } |
| 364 | |
Steven Whitehouse | 8ad151c | 2013-12-12 11:34:09 +0000 | [diff] [blame] | 365 | static int init_threads(struct gfs2_sbd *sdp) |
| 366 | { |
| 367 | struct task_struct *p; |
| 368 | int error = 0; |
| 369 | |
| 370 | p = kthread_run(gfs2_logd, sdp, "gfs2_logd"); |
| 371 | if (IS_ERR(p)) { |
| 372 | error = PTR_ERR(p); |
| 373 | fs_err(sdp, "can't start logd thread: %d\n", error); |
| 374 | return error; |
| 375 | } |
| 376 | sdp->sd_logd_process = p; |
| 377 | |
| 378 | p = kthread_run(gfs2_quotad, sdp, "gfs2_quotad"); |
| 379 | if (IS_ERR(p)) { |
| 380 | error = PTR_ERR(p); |
| 381 | fs_err(sdp, "can't start quotad thread: %d\n", error); |
| 382 | goto fail; |
| 383 | } |
| 384 | sdp->sd_quotad_process = p; |
| 385 | return 0; |
| 386 | |
| 387 | fail: |
| 388 | kthread_stop(sdp->sd_logd_process); |
| 389 | return error; |
| 390 | } |
| 391 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 392 | /** |
| 393 | * gfs2_make_fs_rw - Turn a Read-Only FS into a Read-Write one |
| 394 | * @sdp: the filesystem |
| 395 | * |
| 396 | * Returns: errno |
| 397 | */ |
| 398 | |
| 399 | int gfs2_make_fs_rw(struct gfs2_sbd *sdp) |
| 400 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 401 | struct gfs2_inode *ip = GFS2_I(sdp->sd_jdesc->jd_inode); |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 402 | struct gfs2_glock *j_gl = ip->i_gl; |
Benjamin Marzinski | 2e60d76 | 2014-11-13 20:42:04 -0600 | [diff] [blame] | 403 | struct gfs2_holder freeze_gh; |
Al Viro | 5516762 | 2006-10-13 21:47:13 -0400 | [diff] [blame] | 404 | struct gfs2_log_header_host head; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 405 | int error; |
| 406 | |
Steven Whitehouse | 8ad151c | 2013-12-12 11:34:09 +0000 | [diff] [blame] | 407 | error = init_threads(sdp); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 408 | if (error) |
| 409 | return error; |
| 410 | |
Benjamin Marzinski | 2497255 | 2014-05-01 22:26:55 -0500 | [diff] [blame] | 411 | error = gfs2_glock_nq_init(sdp->sd_freeze_gl, LM_ST_SHARED, 0, |
Benjamin Marzinski | 2e60d76 | 2014-11-13 20:42:04 -0600 | [diff] [blame] | 412 | &freeze_gh); |
Steven Whitehouse | 8ad151c | 2013-12-12 11:34:09 +0000 | [diff] [blame] | 413 | if (error) |
| 414 | goto fail_threads; |
| 415 | |
Steven Whitehouse | 1a14d3a | 2006-11-20 10:37:45 -0500 | [diff] [blame] | 416 | j_gl->gl_ops->go_inval(j_gl, DIO_METADATA); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 417 | |
| 418 | error = gfs2_find_jhead(sdp->sd_jdesc, &head); |
| 419 | if (error) |
| 420 | goto fail; |
| 421 | |
| 422 | if (!(head.lh_flags & GFS2_LOG_HEAD_UNMOUNT)) { |
| 423 | gfs2_consist(sdp); |
| 424 | error = -EIO; |
| 425 | goto fail; |
| 426 | } |
| 427 | |
| 428 | /* Initialize some head of the log stuff */ |
| 429 | sdp->sd_log_sequence = head.lh_sequence + 1; |
| 430 | gfs2_log_pointers_init(sdp, head.lh_blkno); |
| 431 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 432 | error = gfs2_quota_init(sdp); |
| 433 | if (error) |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 434 | goto fail; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 435 | |
| 436 | set_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags); |
| 437 | |
Benjamin Marzinski | 2e60d76 | 2014-11-13 20:42:04 -0600 | [diff] [blame] | 438 | gfs2_glock_dq_uninit(&freeze_gh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 439 | |
| 440 | return 0; |
| 441 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 442 | fail: |
Benjamin Marzinski | 2e60d76 | 2014-11-13 20:42:04 -0600 | [diff] [blame] | 443 | freeze_gh.gh_flags |= GL_NOCACHE; |
| 444 | gfs2_glock_dq_uninit(&freeze_gh); |
Steven Whitehouse | 8ad151c | 2013-12-12 11:34:09 +0000 | [diff] [blame] | 445 | fail_threads: |
| 446 | kthread_stop(sdp->sd_quotad_process); |
| 447 | kthread_stop(sdp->sd_logd_process); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 448 | return error; |
| 449 | } |
| 450 | |
Benjamin Marzinski | 1946f70 | 2009-06-25 15:09:51 -0500 | [diff] [blame] | 451 | void gfs2_statfs_change_in(struct gfs2_statfs_change_host *sc, const void *buf) |
Steven Whitehouse | bb8d8a6 | 2007-06-01 14:11:58 +0100 | [diff] [blame] | 452 | { |
| 453 | const struct gfs2_statfs_change *str = buf; |
| 454 | |
| 455 | sc->sc_total = be64_to_cpu(str->sc_total); |
| 456 | sc->sc_free = be64_to_cpu(str->sc_free); |
| 457 | sc->sc_dinodes = be64_to_cpu(str->sc_dinodes); |
| 458 | } |
| 459 | |
| 460 | static void gfs2_statfs_change_out(const struct gfs2_statfs_change_host *sc, void *buf) |
| 461 | { |
| 462 | struct gfs2_statfs_change *str = buf; |
| 463 | |
| 464 | str->sc_total = cpu_to_be64(sc->sc_total); |
| 465 | str->sc_free = cpu_to_be64(sc->sc_free); |
| 466 | str->sc_dinodes = cpu_to_be64(sc->sc_dinodes); |
| 467 | } |
| 468 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 469 | int gfs2_statfs_init(struct gfs2_sbd *sdp) |
| 470 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 471 | struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode); |
Al Viro | bd209cc | 2006-10-13 23:43:19 -0400 | [diff] [blame] | 472 | struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master; |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 473 | struct gfs2_inode *l_ip = GFS2_I(sdp->sd_sc_inode); |
Al Viro | bd209cc | 2006-10-13 23:43:19 -0400 | [diff] [blame] | 474 | struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 475 | struct buffer_head *m_bh, *l_bh; |
| 476 | struct gfs2_holder gh; |
| 477 | int error; |
| 478 | |
| 479 | error = gfs2_glock_nq_init(m_ip->i_gl, LM_ST_EXCLUSIVE, GL_NOCACHE, |
| 480 | &gh); |
| 481 | if (error) |
| 482 | return error; |
| 483 | |
| 484 | error = gfs2_meta_inode_buffer(m_ip, &m_bh); |
| 485 | if (error) |
| 486 | goto out; |
| 487 | |
| 488 | if (sdp->sd_args.ar_spectator) { |
| 489 | spin_lock(&sdp->sd_statfs_spin); |
| 490 | gfs2_statfs_change_in(m_sc, m_bh->b_data + |
| 491 | sizeof(struct gfs2_dinode)); |
| 492 | spin_unlock(&sdp->sd_statfs_spin); |
| 493 | } else { |
| 494 | error = gfs2_meta_inode_buffer(l_ip, &l_bh); |
| 495 | if (error) |
| 496 | goto out_m_bh; |
| 497 | |
| 498 | spin_lock(&sdp->sd_statfs_spin); |
| 499 | gfs2_statfs_change_in(m_sc, m_bh->b_data + |
| 500 | sizeof(struct gfs2_dinode)); |
| 501 | gfs2_statfs_change_in(l_sc, l_bh->b_data + |
| 502 | sizeof(struct gfs2_dinode)); |
| 503 | spin_unlock(&sdp->sd_statfs_spin); |
| 504 | |
| 505 | brelse(l_bh); |
| 506 | } |
| 507 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 508 | out_m_bh: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 509 | brelse(m_bh); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 510 | out: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 511 | gfs2_glock_dq_uninit(&gh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 512 | return 0; |
| 513 | } |
| 514 | |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 515 | void gfs2_statfs_change(struct gfs2_sbd *sdp, s64 total, s64 free, |
| 516 | s64 dinodes) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 517 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 518 | struct gfs2_inode *l_ip = GFS2_I(sdp->sd_sc_inode); |
Al Viro | bd209cc | 2006-10-13 23:43:19 -0400 | [diff] [blame] | 519 | struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local; |
Benjamin Marzinski | 3d3c10f | 2009-10-20 02:39:44 -0500 | [diff] [blame] | 520 | struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 521 | struct buffer_head *l_bh; |
Benjamin Marzinski | c14f573 | 2009-10-26 13:29:47 -0500 | [diff] [blame] | 522 | s64 x, y; |
| 523 | int need_sync = 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 524 | int error; |
| 525 | |
| 526 | error = gfs2_meta_inode_buffer(l_ip, &l_bh); |
| 527 | if (error) |
| 528 | return; |
| 529 | |
Steven Whitehouse | 350a9b0 | 2012-12-14 12:36:02 +0000 | [diff] [blame] | 530 | gfs2_trans_add_meta(l_ip->i_gl, l_bh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 531 | |
| 532 | spin_lock(&sdp->sd_statfs_spin); |
| 533 | l_sc->sc_total += total; |
| 534 | l_sc->sc_free += free; |
| 535 | l_sc->sc_dinodes += dinodes; |
Steven Whitehouse | 907b9bc | 2006-09-25 09:26:04 -0400 | [diff] [blame] | 536 | gfs2_statfs_change_out(l_sc, l_bh->b_data + sizeof(struct gfs2_dinode)); |
Benjamin Marzinski | c14f573 | 2009-10-26 13:29:47 -0500 | [diff] [blame] | 537 | if (sdp->sd_args.ar_statfs_percent) { |
| 538 | x = 100 * l_sc->sc_free; |
| 539 | y = m_sc->sc_free * sdp->sd_args.ar_statfs_percent; |
| 540 | if (x >= y || x <= -y) |
| 541 | need_sync = 1; |
| 542 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 543 | spin_unlock(&sdp->sd_statfs_spin); |
| 544 | |
| 545 | brelse(l_bh); |
Benjamin Marzinski | c14f573 | 2009-10-26 13:29:47 -0500 | [diff] [blame] | 546 | if (need_sync) |
Benjamin Marzinski | 3d3c10f | 2009-10-20 02:39:44 -0500 | [diff] [blame] | 547 | gfs2_wake_up_statfs(sdp); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 548 | } |
| 549 | |
Benjamin Marzinski | 1946f70 | 2009-06-25 15:09:51 -0500 | [diff] [blame] | 550 | void update_statfs(struct gfs2_sbd *sdp, struct buffer_head *m_bh, |
| 551 | struct buffer_head *l_bh) |
| 552 | { |
| 553 | struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode); |
| 554 | struct gfs2_inode *l_ip = GFS2_I(sdp->sd_sc_inode); |
| 555 | struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master; |
| 556 | struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local; |
| 557 | |
Steven Whitehouse | 350a9b0 | 2012-12-14 12:36:02 +0000 | [diff] [blame] | 558 | gfs2_trans_add_meta(l_ip->i_gl, l_bh); |
Benjamin Marzinski | 1946f70 | 2009-06-25 15:09:51 -0500 | [diff] [blame] | 559 | |
| 560 | spin_lock(&sdp->sd_statfs_spin); |
| 561 | m_sc->sc_total += l_sc->sc_total; |
| 562 | m_sc->sc_free += l_sc->sc_free; |
| 563 | m_sc->sc_dinodes += l_sc->sc_dinodes; |
| 564 | memset(l_sc, 0, sizeof(struct gfs2_statfs_change)); |
| 565 | memset(l_bh->b_data + sizeof(struct gfs2_dinode), |
| 566 | 0, sizeof(struct gfs2_statfs_change)); |
| 567 | spin_unlock(&sdp->sd_statfs_spin); |
| 568 | |
Steven Whitehouse | 350a9b0 | 2012-12-14 12:36:02 +0000 | [diff] [blame] | 569 | gfs2_trans_add_meta(m_ip->i_gl, m_bh); |
Benjamin Marzinski | 1946f70 | 2009-06-25 15:09:51 -0500 | [diff] [blame] | 570 | gfs2_statfs_change_out(m_sc, m_bh->b_data + sizeof(struct gfs2_dinode)); |
| 571 | } |
| 572 | |
Steven Whitehouse | 8c42d63 | 2009-09-11 14:36:44 +0100 | [diff] [blame] | 573 | int gfs2_statfs_sync(struct super_block *sb, int type) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 574 | { |
Steven Whitehouse | 8c42d63 | 2009-09-11 14:36:44 +0100 | [diff] [blame] | 575 | struct gfs2_sbd *sdp = sb->s_fs_info; |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 576 | struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode); |
| 577 | struct gfs2_inode *l_ip = GFS2_I(sdp->sd_sc_inode); |
Al Viro | bd209cc | 2006-10-13 23:43:19 -0400 | [diff] [blame] | 578 | struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master; |
| 579 | struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 580 | struct gfs2_holder gh; |
| 581 | struct buffer_head *m_bh, *l_bh; |
| 582 | int error; |
| 583 | |
Benjamin Marzinski | 2e60d76 | 2014-11-13 20:42:04 -0600 | [diff] [blame] | 584 | sb_start_write(sb); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 585 | error = gfs2_glock_nq_init(m_ip->i_gl, LM_ST_EXCLUSIVE, GL_NOCACHE, |
| 586 | &gh); |
| 587 | if (error) |
Benjamin Marzinski | 2e60d76 | 2014-11-13 20:42:04 -0600 | [diff] [blame] | 588 | goto out; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 589 | |
| 590 | error = gfs2_meta_inode_buffer(m_ip, &m_bh); |
| 591 | if (error) |
Benjamin Marzinski | 2e60d76 | 2014-11-13 20:42:04 -0600 | [diff] [blame] | 592 | goto out_unlock; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 593 | |
| 594 | spin_lock(&sdp->sd_statfs_spin); |
| 595 | gfs2_statfs_change_in(m_sc, m_bh->b_data + |
Steven Whitehouse | 907b9bc | 2006-09-25 09:26:04 -0400 | [diff] [blame] | 596 | sizeof(struct gfs2_dinode)); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 597 | if (!l_sc->sc_total && !l_sc->sc_free && !l_sc->sc_dinodes) { |
| 598 | spin_unlock(&sdp->sd_statfs_spin); |
| 599 | goto out_bh; |
| 600 | } |
| 601 | spin_unlock(&sdp->sd_statfs_spin); |
| 602 | |
| 603 | error = gfs2_meta_inode_buffer(l_ip, &l_bh); |
| 604 | if (error) |
| 605 | goto out_bh; |
| 606 | |
| 607 | error = gfs2_trans_begin(sdp, 2 * RES_DINODE, 0); |
| 608 | if (error) |
| 609 | goto out_bh2; |
| 610 | |
Benjamin Marzinski | 1946f70 | 2009-06-25 15:09:51 -0500 | [diff] [blame] | 611 | update_statfs(sdp, m_bh, l_bh); |
Benjamin Marzinski | 3d3c10f | 2009-10-20 02:39:44 -0500 | [diff] [blame] | 612 | sdp->sd_statfs_force_sync = 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 613 | |
| 614 | gfs2_trans_end(sdp); |
| 615 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 616 | out_bh2: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 617 | brelse(l_bh); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 618 | out_bh: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 619 | brelse(m_bh); |
Benjamin Marzinski | 2e60d76 | 2014-11-13 20:42:04 -0600 | [diff] [blame] | 620 | out_unlock: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 621 | gfs2_glock_dq_uninit(&gh); |
Benjamin Marzinski | 2e60d76 | 2014-11-13 20:42:04 -0600 | [diff] [blame] | 622 | out: |
| 623 | sb_end_write(sb); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 624 | return error; |
| 625 | } |
| 626 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 627 | struct lfcc { |
| 628 | struct list_head list; |
| 629 | struct gfs2_holder gh; |
| 630 | }; |
| 631 | |
| 632 | /** |
| 633 | * gfs2_lock_fs_check_clean - Stop all writes to the FS and check that all |
| 634 | * journals are clean |
| 635 | * @sdp: the file system |
| 636 | * @state: the state to put the transaction lock into |
| 637 | * @t_gh: the hold on the transaction lock |
| 638 | * |
| 639 | * Returns: errno |
| 640 | */ |
| 641 | |
Adrian Bunk | 08bc2db | 2006-04-28 10:59:12 -0400 | [diff] [blame] | 642 | static int gfs2_lock_fs_check_clean(struct gfs2_sbd *sdp, |
Benjamin Marzinski | 2497255 | 2014-05-01 22:26:55 -0500 | [diff] [blame] | 643 | struct gfs2_holder *freeze_gh) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 644 | { |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 645 | struct gfs2_inode *ip; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 646 | struct gfs2_jdesc *jd; |
| 647 | struct lfcc *lfcc; |
| 648 | LIST_HEAD(list); |
Al Viro | 5516762 | 2006-10-13 21:47:13 -0400 | [diff] [blame] | 649 | struct gfs2_log_header_host lh; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 650 | int error; |
| 651 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 652 | list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) { |
| 653 | lfcc = kmalloc(sizeof(struct lfcc), GFP_KERNEL); |
| 654 | if (!lfcc) { |
| 655 | error = -ENOMEM; |
| 656 | goto out; |
| 657 | } |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 658 | ip = GFS2_I(jd->jd_inode); |
| 659 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &lfcc->gh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 660 | if (error) { |
| 661 | kfree(lfcc); |
| 662 | goto out; |
| 663 | } |
| 664 | list_add(&lfcc->list, &list); |
| 665 | } |
| 666 | |
Benjamin Marzinski | 2497255 | 2014-05-01 22:26:55 -0500 | [diff] [blame] | 667 | error = gfs2_glock_nq_init(sdp->sd_freeze_gl, LM_ST_EXCLUSIVE, |
| 668 | GL_NOCACHE, freeze_gh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 669 | |
| 670 | list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) { |
| 671 | error = gfs2_jdesc_check(jd); |
| 672 | if (error) |
| 673 | break; |
| 674 | error = gfs2_find_jhead(jd, &lh); |
| 675 | if (error) |
| 676 | break; |
| 677 | if (!(lh.lh_flags & GFS2_LOG_HEAD_UNMOUNT)) { |
| 678 | error = -EBUSY; |
| 679 | break; |
| 680 | } |
| 681 | } |
| 682 | |
| 683 | if (error) |
Benjamin Marzinski | 2497255 | 2014-05-01 22:26:55 -0500 | [diff] [blame] | 684 | gfs2_glock_dq_uninit(freeze_gh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 685 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 686 | out: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 687 | while (!list_empty(&list)) { |
| 688 | lfcc = list_entry(list.next, struct lfcc, list); |
| 689 | list_del(&lfcc->list); |
| 690 | gfs2_glock_dq_uninit(&lfcc->gh); |
| 691 | kfree(lfcc); |
| 692 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 693 | return error; |
| 694 | } |
| 695 | |
Steven Whitehouse | 9eed04c | 2011-05-09 14:11:40 +0100 | [diff] [blame] | 696 | void gfs2_dinode_out(const struct gfs2_inode *ip, void *buf) |
| 697 | { |
| 698 | struct gfs2_dinode *str = buf; |
| 699 | |
| 700 | str->di_header.mh_magic = cpu_to_be32(GFS2_MAGIC); |
| 701 | str->di_header.mh_type = cpu_to_be32(GFS2_METATYPE_DI); |
| 702 | str->di_header.mh_format = cpu_to_be32(GFS2_FORMAT_DI); |
| 703 | str->di_num.no_addr = cpu_to_be64(ip->i_no_addr); |
| 704 | str->di_num.no_formal_ino = cpu_to_be64(ip->i_no_formal_ino); |
| 705 | str->di_mode = cpu_to_be32(ip->i_inode.i_mode); |
Eric W. Biederman | d054642 | 2013-01-31 22:08:10 -0800 | [diff] [blame] | 706 | str->di_uid = cpu_to_be32(i_uid_read(&ip->i_inode)); |
| 707 | str->di_gid = cpu_to_be32(i_gid_read(&ip->i_inode)); |
Steven Whitehouse | 9eed04c | 2011-05-09 14:11:40 +0100 | [diff] [blame] | 708 | str->di_nlink = cpu_to_be32(ip->i_inode.i_nlink); |
| 709 | str->di_size = cpu_to_be64(i_size_read(&ip->i_inode)); |
| 710 | str->di_blocks = cpu_to_be64(gfs2_get_inode_blocks(&ip->i_inode)); |
| 711 | str->di_atime = cpu_to_be64(ip->i_inode.i_atime.tv_sec); |
| 712 | str->di_mtime = cpu_to_be64(ip->i_inode.i_mtime.tv_sec); |
| 713 | str->di_ctime = cpu_to_be64(ip->i_inode.i_ctime.tv_sec); |
| 714 | |
| 715 | str->di_goal_meta = cpu_to_be64(ip->i_goal); |
| 716 | str->di_goal_data = cpu_to_be64(ip->i_goal); |
| 717 | str->di_generation = cpu_to_be64(ip->i_generation); |
| 718 | |
| 719 | str->di_flags = cpu_to_be32(ip->i_diskflags); |
| 720 | str->di_height = cpu_to_be16(ip->i_height); |
| 721 | str->di_payload_format = cpu_to_be32(S_ISDIR(ip->i_inode.i_mode) && |
| 722 | !(ip->i_diskflags & GFS2_DIF_EXHASH) ? |
| 723 | GFS2_FORMAT_DE : 0); |
| 724 | str->di_depth = cpu_to_be16(ip->i_depth); |
| 725 | str->di_entries = cpu_to_be32(ip->i_entries); |
| 726 | |
| 727 | str->di_eattr = cpu_to_be64(ip->i_eattr); |
| 728 | str->di_atime_nsec = cpu_to_be32(ip->i_inode.i_atime.tv_nsec); |
| 729 | str->di_mtime_nsec = cpu_to_be32(ip->i_inode.i_mtime.tv_nsec); |
| 730 | str->di_ctime_nsec = cpu_to_be32(ip->i_inode.i_ctime.tv_nsec); |
| 731 | } |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 732 | |
| 733 | /** |
| 734 | * gfs2_write_inode - Make sure the inode is stable on the disk |
| 735 | * @inode: The inode |
Steven Whitehouse | 1027efa | 2011-03-30 16:13:25 +0100 | [diff] [blame] | 736 | * @wbc: The writeback control structure |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 737 | * |
| 738 | * Returns: errno |
| 739 | */ |
| 740 | |
Christoph Hellwig | a9185b4 | 2010-03-05 09:21:37 +0100 | [diff] [blame] | 741 | static int gfs2_write_inode(struct inode *inode, struct writeback_control *wbc) |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 742 | { |
| 743 | struct gfs2_inode *ip = GFS2_I(inode); |
| 744 | struct gfs2_sbd *sdp = GFS2_SB(inode); |
Steven Whitehouse | 1027efa | 2011-03-30 16:13:25 +0100 | [diff] [blame] | 745 | struct address_space *metamapping = gfs2_glock2aspace(ip->i_gl); |
Christoph Hellwig | de1414a | 2015-01-14 10:42:36 +0100 | [diff] [blame] | 746 | struct backing_dev_info *bdi = inode_to_bdi(metamapping->host); |
Steven Whitehouse | ab9bbda | 2011-08-15 14:20:36 +0100 | [diff] [blame] | 747 | int ret = 0; |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 748 | |
Christoph Hellwig | a9185b4 | 2010-03-05 09:21:37 +0100 | [diff] [blame] | 749 | if (wbc->sync_mode == WB_SYNC_ALL) |
Benjamin Marzinski | 2497255 | 2014-05-01 22:26:55 -0500 | [diff] [blame] | 750 | gfs2_log_flush(GFS2_SB(inode), ip->i_gl, NORMAL_FLUSH); |
Steven Whitehouse | 4667a0e | 2011-04-18 14:18:09 +0100 | [diff] [blame] | 751 | if (bdi->dirty_exceeded) |
| 752 | gfs2_ail1_flush(sdp, wbc); |
Steven Whitehouse | 1d4ec64 | 2011-08-02 13:13:20 +0100 | [diff] [blame] | 753 | else |
| 754 | filemap_fdatawrite(metamapping); |
Steven Whitehouse | ab9bbda | 2011-08-15 14:20:36 +0100 | [diff] [blame] | 755 | if (wbc->sync_mode == WB_SYNC_ALL) |
Steven Whitehouse | 1027efa | 2011-03-30 16:13:25 +0100 | [diff] [blame] | 756 | ret = filemap_fdatawait(metamapping); |
| 757 | if (ret) |
| 758 | mark_inode_dirty_sync(inode); |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 759 | return ret; |
| 760 | } |
| 761 | |
| 762 | /** |
Steven Whitehouse | ab9bbda | 2011-08-15 14:20:36 +0100 | [diff] [blame] | 763 | * gfs2_dirty_inode - check for atime updates |
| 764 | * @inode: The inode in question |
| 765 | * @flags: The type of dirty |
| 766 | * |
| 767 | * Unfortunately it can be called under any combination of inode |
| 768 | * glock and transaction lock, so we have to check carefully. |
| 769 | * |
| 770 | * At the moment this deals only with atime - it should be possible |
| 771 | * to expand that role in future, once a review of the locking has |
| 772 | * been carried out. |
| 773 | */ |
| 774 | |
| 775 | static void gfs2_dirty_inode(struct inode *inode, int flags) |
| 776 | { |
| 777 | struct gfs2_inode *ip = GFS2_I(inode); |
| 778 | struct gfs2_sbd *sdp = GFS2_SB(inode); |
| 779 | struct buffer_head *bh; |
| 780 | struct gfs2_holder gh; |
| 781 | int need_unlock = 0; |
| 782 | int need_endtrans = 0; |
| 783 | int ret; |
| 784 | |
| 785 | if (!(flags & (I_DIRTY_DATASYNC|I_DIRTY_SYNC))) |
| 786 | return; |
| 787 | |
| 788 | if (!gfs2_glock_is_locked_by_me(ip->i_gl)) { |
| 789 | ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); |
| 790 | if (ret) { |
| 791 | fs_err(sdp, "dirty_inode: glock %d\n", ret); |
| 792 | return; |
| 793 | } |
| 794 | need_unlock = 1; |
Benjamin Marzinski | 3d16268 | 2012-11-06 00:49:28 -0600 | [diff] [blame] | 795 | } else if (WARN_ON_ONCE(ip->i_gl->gl_state != LM_ST_EXCLUSIVE)) |
| 796 | return; |
Steven Whitehouse | ab9bbda | 2011-08-15 14:20:36 +0100 | [diff] [blame] | 797 | |
| 798 | if (current->journal_info == NULL) { |
| 799 | ret = gfs2_trans_begin(sdp, RES_DINODE, 0); |
| 800 | if (ret) { |
| 801 | fs_err(sdp, "dirty_inode: gfs2_trans_begin %d\n", ret); |
| 802 | goto out; |
| 803 | } |
| 804 | need_endtrans = 1; |
| 805 | } |
| 806 | |
| 807 | ret = gfs2_meta_inode_buffer(ip, &bh); |
| 808 | if (ret == 0) { |
Steven Whitehouse | 350a9b0 | 2012-12-14 12:36:02 +0000 | [diff] [blame] | 809 | gfs2_trans_add_meta(ip->i_gl, bh); |
Steven Whitehouse | ab9bbda | 2011-08-15 14:20:36 +0100 | [diff] [blame] | 810 | gfs2_dinode_out(ip, bh->b_data); |
| 811 | brelse(bh); |
| 812 | } |
| 813 | |
| 814 | if (need_endtrans) |
| 815 | gfs2_trans_end(sdp); |
| 816 | out: |
| 817 | if (need_unlock) |
| 818 | gfs2_glock_dq_uninit(&gh); |
| 819 | } |
| 820 | |
| 821 | /** |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 822 | * gfs2_make_fs_ro - Turn a Read-Write FS into a Read-Only one |
| 823 | * @sdp: the filesystem |
| 824 | * |
| 825 | * Returns: errno |
| 826 | */ |
| 827 | |
| 828 | static int gfs2_make_fs_ro(struct gfs2_sbd *sdp) |
| 829 | { |
Benjamin Marzinski | 2e60d76 | 2014-11-13 20:42:04 -0600 | [diff] [blame] | 830 | struct gfs2_holder freeze_gh; |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 831 | int error; |
| 832 | |
Benjamin Marzinski | 2497255 | 2014-05-01 22:26:55 -0500 | [diff] [blame] | 833 | error = gfs2_glock_nq_init(sdp->sd_freeze_gl, LM_ST_SHARED, GL_NOCACHE, |
Benjamin Marzinski | 2e60d76 | 2014-11-13 20:42:04 -0600 | [diff] [blame] | 834 | &freeze_gh); |
Benjamin Marzinski | 2497255 | 2014-05-01 22:26:55 -0500 | [diff] [blame] | 835 | if (error && !test_bit(SDF_SHUTDOWN, &sdp->sd_flags)) |
| 836 | return error; |
| 837 | |
Steven Whitehouse | 8ad151c | 2013-12-12 11:34:09 +0000 | [diff] [blame] | 838 | kthread_stop(sdp->sd_quotad_process); |
| 839 | kthread_stop(sdp->sd_logd_process); |
| 840 | |
Benjamin Marzinski | b94a170 | 2009-07-23 18:52:34 -0500 | [diff] [blame] | 841 | flush_workqueue(gfs2_delete_workqueue); |
Jan Kara | ceed172 | 2012-07-03 16:45:28 +0200 | [diff] [blame] | 842 | gfs2_quota_sync(sdp->sd_vfs, 0); |
Steven Whitehouse | 8c42d63 | 2009-09-11 14:36:44 +0100 | [diff] [blame] | 843 | gfs2_statfs_sync(sdp->sd_vfs, 0); |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 844 | |
Benjamin Marzinski | 2e60d76 | 2014-11-13 20:42:04 -0600 | [diff] [blame] | 845 | down_write(&sdp->sd_log_flush_lock); |
| 846 | clear_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags); |
| 847 | up_write(&sdp->sd_log_flush_lock); |
| 848 | |
Benjamin Marzinski | 2497255 | 2014-05-01 22:26:55 -0500 | [diff] [blame] | 849 | gfs2_log_flush(sdp, NULL, SHUTDOWN_FLUSH); |
Benjamin Marzinski | 2e60d76 | 2014-11-13 20:42:04 -0600 | [diff] [blame] | 850 | wait_event(sdp->sd_reserving_log_wait, atomic_read(&sdp->sd_reserving_log) == 0); |
Benjamin Marzinski | 2497255 | 2014-05-01 22:26:55 -0500 | [diff] [blame] | 851 | gfs2_assert_warn(sdp, atomic_read(&sdp->sd_log_blks_free) == sdp->sd_jdesc->jd_blocks); |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 852 | |
Benjamin Marzinski | 2e60d76 | 2014-11-13 20:42:04 -0600 | [diff] [blame] | 853 | if (freeze_gh.gh_gl) |
| 854 | gfs2_glock_dq_uninit(&freeze_gh); |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 855 | |
| 856 | gfs2_quota_cleanup(sdp); |
| 857 | |
| 858 | return error; |
| 859 | } |
| 860 | |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 861 | /** |
| 862 | * gfs2_put_super - Unmount the filesystem |
| 863 | * @sb: The VFS superblock |
| 864 | * |
| 865 | */ |
| 866 | |
| 867 | static void gfs2_put_super(struct super_block *sb) |
| 868 | { |
| 869 | struct gfs2_sbd *sdp = sb->s_fs_info; |
| 870 | int error; |
| 871 | struct gfs2_jdesc *jd; |
| 872 | |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 873 | /* No more recovery requests */ |
| 874 | set_bit(SDF_NORECOVERY, &sdp->sd_flags); |
| 875 | smp_mb(); |
| 876 | |
| 877 | /* Wait on outstanding recovery */ |
| 878 | restart: |
| 879 | spin_lock(&sdp->sd_jindex_spin); |
| 880 | list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) { |
| 881 | if (!test_bit(JDF_RECOVERY, &jd->jd_flags)) |
| 882 | continue; |
| 883 | spin_unlock(&sdp->sd_jindex_spin); |
| 884 | wait_on_bit(&jd->jd_flags, JDF_RECOVERY, |
NeilBrown | 7431620 | 2014-07-07 15:16:04 +1000 | [diff] [blame] | 885 | TASK_UNINTERRUPTIBLE); |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 886 | goto restart; |
| 887 | } |
| 888 | spin_unlock(&sdp->sd_jindex_spin); |
| 889 | |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 890 | if (!(sb->s_flags & MS_RDONLY)) { |
| 891 | error = gfs2_make_fs_ro(sdp); |
| 892 | if (error) |
| 893 | gfs2_io_error(sdp); |
| 894 | } |
| 895 | /* At this point, we're through modifying the disk */ |
| 896 | |
| 897 | /* Release stuff */ |
| 898 | |
| 899 | iput(sdp->sd_jindex); |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 900 | iput(sdp->sd_statfs_inode); |
| 901 | iput(sdp->sd_rindex); |
| 902 | iput(sdp->sd_quota_inode); |
| 903 | |
| 904 | gfs2_glock_put(sdp->sd_rename_gl); |
Benjamin Marzinski | 2497255 | 2014-05-01 22:26:55 -0500 | [diff] [blame] | 905 | gfs2_glock_put(sdp->sd_freeze_gl); |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 906 | |
| 907 | if (!sdp->sd_args.ar_spectator) { |
| 908 | gfs2_glock_dq_uninit(&sdp->sd_journal_gh); |
| 909 | gfs2_glock_dq_uninit(&sdp->sd_jinode_gh); |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 910 | gfs2_glock_dq_uninit(&sdp->sd_sc_gh); |
| 911 | gfs2_glock_dq_uninit(&sdp->sd_qc_gh); |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 912 | iput(sdp->sd_sc_inode); |
| 913 | iput(sdp->sd_qc_inode); |
| 914 | } |
| 915 | |
| 916 | gfs2_glock_dq_uninit(&sdp->sd_live_gh); |
| 917 | gfs2_clear_rgrpd(sdp); |
| 918 | gfs2_jindex_free(sdp); |
| 919 | /* Take apart glock structures and buffer lists */ |
| 920 | gfs2_gl_hash_clear(sdp); |
| 921 | /* Unmount the locking protocol */ |
| 922 | gfs2_lm_unmount(sdp); |
| 923 | |
| 924 | /* At this point, we're through participating in the lockspace */ |
| 925 | gfs2_sys_fs_del(sdp); |
| 926 | } |
| 927 | |
| 928 | /** |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 929 | * gfs2_sync_fs - sync the filesystem |
| 930 | * @sb: the superblock |
| 931 | * |
| 932 | * Flushes the log to disk. |
| 933 | */ |
| 934 | |
| 935 | static int gfs2_sync_fs(struct super_block *sb, int wait) |
| 936 | { |
Steven Whitehouse | 1027efa | 2011-03-30 16:13:25 +0100 | [diff] [blame] | 937 | struct gfs2_sbd *sdp = sb->s_fs_info; |
Jan Kara | a117782 | 2012-07-03 16:45:29 +0200 | [diff] [blame] | 938 | |
| 939 | gfs2_quota_sync(sb, -1); |
Benjamin Marzinski | 2e60d76 | 2014-11-13 20:42:04 -0600 | [diff] [blame] | 940 | if (wait && sdp) |
Benjamin Marzinski | 2497255 | 2014-05-01 22:26:55 -0500 | [diff] [blame] | 941 | gfs2_log_flush(sdp, NULL, NORMAL_FLUSH); |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 942 | return 0; |
| 943 | } |
| 944 | |
Benjamin Marzinski | 2e60d76 | 2014-11-13 20:42:04 -0600 | [diff] [blame] | 945 | void gfs2_freeze_func(struct work_struct *work) |
| 946 | { |
| 947 | int error; |
| 948 | struct gfs2_holder freeze_gh; |
| 949 | struct gfs2_sbd *sdp = container_of(work, struct gfs2_sbd, sd_freeze_work); |
| 950 | struct super_block *sb = sdp->sd_vfs; |
| 951 | |
| 952 | atomic_inc(&sb->s_active); |
| 953 | error = gfs2_glock_nq_init(sdp->sd_freeze_gl, LM_ST_SHARED, 0, |
| 954 | &freeze_gh); |
| 955 | if (error) { |
| 956 | printk(KERN_INFO "GFS2: couln't get freeze lock : %d\n", error); |
| 957 | gfs2_assert_withdraw(sdp, 0); |
| 958 | } |
| 959 | else { |
| 960 | atomic_set(&sdp->sd_freeze_state, SFS_UNFROZEN); |
| 961 | error = thaw_super(sb); |
| 962 | if (error) { |
| 963 | printk(KERN_INFO "GFS2: couldn't thaw filesystem: %d\n", |
| 964 | error); |
| 965 | gfs2_assert_withdraw(sdp, 0); |
| 966 | } |
| 967 | if (!test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) |
| 968 | freeze_gh.gh_flags |= GL_NOCACHE; |
| 969 | gfs2_glock_dq_uninit(&freeze_gh); |
| 970 | } |
| 971 | deactivate_super(sb); |
| 972 | return; |
| 973 | } |
| 974 | |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 975 | /** |
| 976 | * gfs2_freeze - prevent further writes to the filesystem |
| 977 | * @sb: the VFS structure for the filesystem |
| 978 | * |
| 979 | */ |
| 980 | |
| 981 | static int gfs2_freeze(struct super_block *sb) |
| 982 | { |
| 983 | struct gfs2_sbd *sdp = sb->s_fs_info; |
Benjamin Marzinski | 2e60d76 | 2014-11-13 20:42:04 -0600 | [diff] [blame] | 984 | int error = 0; |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 985 | |
Benjamin Marzinski | 2e60d76 | 2014-11-13 20:42:04 -0600 | [diff] [blame] | 986 | mutex_lock(&sdp->sd_freeze_mutex); |
| 987 | if (atomic_read(&sdp->sd_freeze_state) != SFS_UNFROZEN) |
| 988 | goto out; |
| 989 | |
| 990 | if (test_bit(SDF_SHUTDOWN, &sdp->sd_flags)) { |
| 991 | error = -EINVAL; |
| 992 | goto out; |
| 993 | } |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 994 | |
| 995 | for (;;) { |
Steven Whitehouse | d564053f | 2013-01-11 10:49:34 +0000 | [diff] [blame] | 996 | error = gfs2_lock_fs_check_clean(sdp, &sdp->sd_freeze_gh); |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 997 | if (!error) |
| 998 | break; |
| 999 | |
| 1000 | switch (error) { |
| 1001 | case -EBUSY: |
| 1002 | fs_err(sdp, "waiting for recovery before freeze\n"); |
| 1003 | break; |
| 1004 | |
| 1005 | default: |
| 1006 | fs_err(sdp, "error freezing FS: %d\n", error); |
| 1007 | break; |
| 1008 | } |
| 1009 | |
| 1010 | fs_err(sdp, "retrying...\n"); |
| 1011 | msleep(1000); |
| 1012 | } |
Benjamin Marzinski | 2e60d76 | 2014-11-13 20:42:04 -0600 | [diff] [blame] | 1013 | error = 0; |
| 1014 | out: |
| 1015 | mutex_unlock(&sdp->sd_freeze_mutex); |
| 1016 | return error; |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1017 | } |
| 1018 | |
| 1019 | /** |
| 1020 | * gfs2_unfreeze - reallow writes to the filesystem |
| 1021 | * @sb: the VFS structure for the filesystem |
| 1022 | * |
| 1023 | */ |
| 1024 | |
| 1025 | static int gfs2_unfreeze(struct super_block *sb) |
| 1026 | { |
Steven Whitehouse | d564053f | 2013-01-11 10:49:34 +0000 | [diff] [blame] | 1027 | struct gfs2_sbd *sdp = sb->s_fs_info; |
| 1028 | |
Benjamin Marzinski | 2e60d76 | 2014-11-13 20:42:04 -0600 | [diff] [blame] | 1029 | mutex_lock(&sdp->sd_freeze_mutex); |
| 1030 | if (atomic_read(&sdp->sd_freeze_state) != SFS_FROZEN || |
| 1031 | sdp->sd_freeze_gh.gh_gl == NULL) { |
| 1032 | mutex_unlock(&sdp->sd_freeze_mutex); |
| 1033 | return 0; |
| 1034 | } |
| 1035 | |
Steven Whitehouse | d564053f | 2013-01-11 10:49:34 +0000 | [diff] [blame] | 1036 | gfs2_glock_dq_uninit(&sdp->sd_freeze_gh); |
Benjamin Marzinski | 2e60d76 | 2014-11-13 20:42:04 -0600 | [diff] [blame] | 1037 | mutex_unlock(&sdp->sd_freeze_mutex); |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1038 | return 0; |
| 1039 | } |
| 1040 | |
| 1041 | /** |
| 1042 | * statfs_fill - fill in the sg for a given RG |
| 1043 | * @rgd: the RG |
| 1044 | * @sc: the sc structure |
| 1045 | * |
| 1046 | * Returns: 0 on success, -ESTALE if the LVB is invalid |
| 1047 | */ |
| 1048 | |
| 1049 | static int statfs_slow_fill(struct gfs2_rgrpd *rgd, |
| 1050 | struct gfs2_statfs_change_host *sc) |
| 1051 | { |
| 1052 | gfs2_rgrp_verify(rgd); |
| 1053 | sc->sc_total += rgd->rd_data; |
| 1054 | sc->sc_free += rgd->rd_free; |
| 1055 | sc->sc_dinodes += rgd->rd_dinodes; |
| 1056 | return 0; |
| 1057 | } |
| 1058 | |
| 1059 | /** |
| 1060 | * gfs2_statfs_slow - Stat a filesystem using asynchronous locking |
| 1061 | * @sdp: the filesystem |
| 1062 | * @sc: the sc info that will be returned |
| 1063 | * |
| 1064 | * Any error (other than a signal) will cause this routine to fall back |
| 1065 | * to the synchronous version. |
| 1066 | * |
| 1067 | * FIXME: This really shouldn't busy wait like this. |
| 1068 | * |
| 1069 | * Returns: errno |
| 1070 | */ |
| 1071 | |
| 1072 | static int gfs2_statfs_slow(struct gfs2_sbd *sdp, struct gfs2_statfs_change_host *sc) |
| 1073 | { |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1074 | struct gfs2_rgrpd *rgd_next; |
| 1075 | struct gfs2_holder *gha, *gh; |
| 1076 | unsigned int slots = 64; |
| 1077 | unsigned int x; |
| 1078 | int done; |
| 1079 | int error = 0, err; |
| 1080 | |
| 1081 | memset(sc, 0, sizeof(struct gfs2_statfs_change_host)); |
| 1082 | gha = kcalloc(slots, sizeof(struct gfs2_holder), GFP_KERNEL); |
| 1083 | if (!gha) |
| 1084 | return -ENOMEM; |
| 1085 | |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1086 | rgd_next = gfs2_rgrpd_get_first(sdp); |
| 1087 | |
| 1088 | for (;;) { |
| 1089 | done = 1; |
| 1090 | |
| 1091 | for (x = 0; x < slots; x++) { |
| 1092 | gh = gha + x; |
| 1093 | |
| 1094 | if (gh->gh_gl && gfs2_glock_poll(gh)) { |
| 1095 | err = gfs2_glock_wait(gh); |
| 1096 | if (err) { |
| 1097 | gfs2_holder_uninit(gh); |
| 1098 | error = err; |
| 1099 | } else { |
| 1100 | if (!error) |
| 1101 | error = statfs_slow_fill( |
| 1102 | gh->gh_gl->gl_object, sc); |
| 1103 | gfs2_glock_dq_uninit(gh); |
| 1104 | } |
| 1105 | } |
| 1106 | |
| 1107 | if (gh->gh_gl) |
| 1108 | done = 0; |
| 1109 | else if (rgd_next && !error) { |
| 1110 | error = gfs2_glock_nq_init(rgd_next->rd_gl, |
| 1111 | LM_ST_SHARED, |
| 1112 | GL_ASYNC, |
| 1113 | gh); |
| 1114 | rgd_next = gfs2_rgrpd_get_next(rgd_next); |
| 1115 | done = 0; |
| 1116 | } |
| 1117 | |
| 1118 | if (signal_pending(current)) |
| 1119 | error = -ERESTARTSYS; |
| 1120 | } |
| 1121 | |
| 1122 | if (done) |
| 1123 | break; |
| 1124 | |
| 1125 | yield(); |
| 1126 | } |
| 1127 | |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1128 | kfree(gha); |
| 1129 | return error; |
| 1130 | } |
| 1131 | |
| 1132 | /** |
| 1133 | * gfs2_statfs_i - Do a statfs |
| 1134 | * @sdp: the filesystem |
| 1135 | * @sg: the sg structure |
| 1136 | * |
| 1137 | * Returns: errno |
| 1138 | */ |
| 1139 | |
| 1140 | static int gfs2_statfs_i(struct gfs2_sbd *sdp, struct gfs2_statfs_change_host *sc) |
| 1141 | { |
| 1142 | struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master; |
| 1143 | struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local; |
| 1144 | |
| 1145 | spin_lock(&sdp->sd_statfs_spin); |
| 1146 | |
| 1147 | *sc = *m_sc; |
| 1148 | sc->sc_total += l_sc->sc_total; |
| 1149 | sc->sc_free += l_sc->sc_free; |
| 1150 | sc->sc_dinodes += l_sc->sc_dinodes; |
| 1151 | |
| 1152 | spin_unlock(&sdp->sd_statfs_spin); |
| 1153 | |
| 1154 | if (sc->sc_free < 0) |
| 1155 | sc->sc_free = 0; |
| 1156 | if (sc->sc_free > sc->sc_total) |
| 1157 | sc->sc_free = sc->sc_total; |
| 1158 | if (sc->sc_dinodes < 0) |
| 1159 | sc->sc_dinodes = 0; |
| 1160 | |
| 1161 | return 0; |
| 1162 | } |
| 1163 | |
| 1164 | /** |
| 1165 | * gfs2_statfs - Gather and return stats about the filesystem |
| 1166 | * @sb: The superblock |
| 1167 | * @statfsbuf: The buffer |
| 1168 | * |
| 1169 | * Returns: 0 on success or error code |
| 1170 | */ |
| 1171 | |
| 1172 | static int gfs2_statfs(struct dentry *dentry, struct kstatfs *buf) |
| 1173 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1174 | struct super_block *sb = d_inode(dentry)->i_sb; |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1175 | struct gfs2_sbd *sdp = sb->s_fs_info; |
| 1176 | struct gfs2_statfs_change_host sc; |
| 1177 | int error; |
| 1178 | |
Steven Whitehouse | 8339ee5 | 2011-08-31 16:38:29 +0100 | [diff] [blame] | 1179 | error = gfs2_rindex_update(sdp); |
| 1180 | if (error) |
| 1181 | return error; |
| 1182 | |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1183 | if (gfs2_tune_get(sdp, gt_statfs_slow)) |
| 1184 | error = gfs2_statfs_slow(sdp, &sc); |
| 1185 | else |
| 1186 | error = gfs2_statfs_i(sdp, &sc); |
| 1187 | |
| 1188 | if (error) |
| 1189 | return error; |
| 1190 | |
| 1191 | buf->f_type = GFS2_MAGIC; |
| 1192 | buf->f_bsize = sdp->sd_sb.sb_bsize; |
| 1193 | buf->f_blocks = sc.sc_total; |
| 1194 | buf->f_bfree = sc.sc_free; |
| 1195 | buf->f_bavail = sc.sc_free; |
| 1196 | buf->f_files = sc.sc_dinodes + sc.sc_free; |
| 1197 | buf->f_ffree = sc.sc_free; |
| 1198 | buf->f_namelen = GFS2_FNAMESIZE; |
| 1199 | |
| 1200 | return 0; |
| 1201 | } |
| 1202 | |
| 1203 | /** |
| 1204 | * gfs2_remount_fs - called when the FS is remounted |
| 1205 | * @sb: the filesystem |
| 1206 | * @flags: the remount flags |
| 1207 | * @data: extra data passed in (not used right now) |
| 1208 | * |
| 1209 | * Returns: errno |
| 1210 | */ |
| 1211 | |
| 1212 | static int gfs2_remount_fs(struct super_block *sb, int *flags, char *data) |
| 1213 | { |
| 1214 | struct gfs2_sbd *sdp = sb->s_fs_info; |
| 1215 | struct gfs2_args args = sdp->sd_args; /* Default to current settings */ |
| 1216 | struct gfs2_tune *gt = &sdp->sd_tune; |
| 1217 | int error; |
| 1218 | |
Theodore Ts'o | 02b9984 | 2014-03-13 10:14:33 -0400 | [diff] [blame] | 1219 | sync_filesystem(sb); |
| 1220 | |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1221 | spin_lock(>->gt_spin); |
Benjamin Marzinski | 5e687ea | 2010-05-04 14:29:16 -0500 | [diff] [blame] | 1222 | args.ar_commit = gt->gt_logd_secs; |
Benjamin Marzinski | 3d3c10f | 2009-10-20 02:39:44 -0500 | [diff] [blame] | 1223 | args.ar_quota_quantum = gt->gt_quota_quantum; |
| 1224 | if (gt->gt_statfs_slow) |
| 1225 | args.ar_statfs_quantum = 0; |
| 1226 | else |
| 1227 | args.ar_statfs_quantum = gt->gt_statfs_quantum; |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1228 | spin_unlock(>->gt_spin); |
Steven Whitehouse | f55073f | 2009-09-28 10:30:49 +0100 | [diff] [blame] | 1229 | error = gfs2_mount_args(&args, data); |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1230 | if (error) |
| 1231 | return error; |
| 1232 | |
| 1233 | /* Not allowed to change locking details */ |
| 1234 | if (strcmp(args.ar_lockproto, sdp->sd_args.ar_lockproto) || |
| 1235 | strcmp(args.ar_locktable, sdp->sd_args.ar_locktable) || |
| 1236 | strcmp(args.ar_hostdata, sdp->sd_args.ar_hostdata)) |
| 1237 | return -EINVAL; |
| 1238 | |
| 1239 | /* Some flags must not be changed */ |
| 1240 | if (args_neq(&args, &sdp->sd_args, spectator) || |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1241 | args_neq(&args, &sdp->sd_args, localflocks) || |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1242 | args_neq(&args, &sdp->sd_args, meta)) |
| 1243 | return -EINVAL; |
| 1244 | |
| 1245 | if (sdp->sd_args.ar_spectator) |
| 1246 | *flags |= MS_RDONLY; |
| 1247 | |
| 1248 | if ((sb->s_flags ^ *flags) & MS_RDONLY) { |
| 1249 | if (*flags & MS_RDONLY) |
| 1250 | error = gfs2_make_fs_ro(sdp); |
| 1251 | else |
| 1252 | error = gfs2_make_fs_rw(sdp); |
| 1253 | if (error) |
| 1254 | return error; |
| 1255 | } |
| 1256 | |
| 1257 | sdp->sd_args = args; |
| 1258 | if (sdp->sd_args.ar_posix_acl) |
| 1259 | sb->s_flags |= MS_POSIXACL; |
| 1260 | else |
| 1261 | sb->s_flags &= ~MS_POSIXACL; |
Christoph Hellwig | f25934c | 2009-10-30 08:03:27 +0100 | [diff] [blame] | 1262 | if (sdp->sd_args.ar_nobarrier) |
| 1263 | set_bit(SDF_NOBARRIERS, &sdp->sd_flags); |
| 1264 | else |
| 1265 | clear_bit(SDF_NOBARRIERS, &sdp->sd_flags); |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1266 | spin_lock(>->gt_spin); |
Benjamin Marzinski | 5e687ea | 2010-05-04 14:29:16 -0500 | [diff] [blame] | 1267 | gt->gt_logd_secs = args.ar_commit; |
Benjamin Marzinski | 3d3c10f | 2009-10-20 02:39:44 -0500 | [diff] [blame] | 1268 | gt->gt_quota_quantum = args.ar_quota_quantum; |
| 1269 | if (args.ar_statfs_quantum) { |
| 1270 | gt->gt_statfs_slow = 0; |
| 1271 | gt->gt_statfs_quantum = args.ar_statfs_quantum; |
| 1272 | } |
| 1273 | else { |
| 1274 | gt->gt_statfs_slow = 1; |
| 1275 | gt->gt_statfs_quantum = 30; |
| 1276 | } |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1277 | spin_unlock(>->gt_spin); |
| 1278 | |
Steven Whitehouse | 8633ecf | 2009-07-31 11:07:29 +0100 | [diff] [blame] | 1279 | gfs2_online_uevent(sdp); |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1280 | return 0; |
| 1281 | } |
| 1282 | |
| 1283 | /** |
| 1284 | * gfs2_drop_inode - Drop an inode (test for remote unlink) |
| 1285 | * @inode: The inode to drop |
| 1286 | * |
| 1287 | * If we've received a callback on an iopen lock then its because a |
| 1288 | * remote node tried to deallocate the inode but failed due to this node |
| 1289 | * still having the inode open. Here we mark the link count zero |
| 1290 | * since we know that it must have reached zero if the GLF_DEMOTE flag |
| 1291 | * is set on the iopen glock. If we didn't do a disk read since the |
| 1292 | * remote node removed the final link then we might otherwise miss |
| 1293 | * this event. This check ensures that this node will deallocate the |
| 1294 | * inode's blocks, or alternatively pass the baton on to another |
| 1295 | * node for later deallocation. |
| 1296 | */ |
| 1297 | |
Al Viro | 45321ac | 2010-06-07 13:43:19 -0400 | [diff] [blame] | 1298 | static int gfs2_drop_inode(struct inode *inode) |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1299 | { |
| 1300 | struct gfs2_inode *ip = GFS2_I(inode); |
| 1301 | |
Abhi Das | 0597880 | 2014-03-31 10:33:17 -0500 | [diff] [blame] | 1302 | if (!test_bit(GIF_FREE_VFS_INODE, &ip->i_flags) && inode->i_nlink) { |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1303 | struct gfs2_glock *gl = ip->i_iopen_gh.gh_gl; |
| 1304 | if (gl && test_bit(GLF_DEMOTE, &gl->gl_flags)) |
| 1305 | clear_nlink(inode); |
| 1306 | } |
Al Viro | 45321ac | 2010-06-07 13:43:19 -0400 | [diff] [blame] | 1307 | return generic_drop_inode(inode); |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1308 | } |
| 1309 | |
| 1310 | static int is_ancestor(const struct dentry *d1, const struct dentry *d2) |
| 1311 | { |
| 1312 | do { |
| 1313 | if (d1 == d2) |
| 1314 | return 1; |
| 1315 | d1 = d1->d_parent; |
| 1316 | } while (!IS_ROOT(d1)); |
| 1317 | return 0; |
| 1318 | } |
| 1319 | |
| 1320 | /** |
| 1321 | * gfs2_show_options - Show mount options for /proc/mounts |
| 1322 | * @s: seq_file structure |
Al Viro | 34c80b1 | 2011-12-08 21:32:45 -0500 | [diff] [blame] | 1323 | * @root: root of this (sub)tree |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1324 | * |
| 1325 | * Returns: 0 on success or error code |
| 1326 | */ |
| 1327 | |
Al Viro | 34c80b1 | 2011-12-08 21:32:45 -0500 | [diff] [blame] | 1328 | static int gfs2_show_options(struct seq_file *s, struct dentry *root) |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1329 | { |
Al Viro | 34c80b1 | 2011-12-08 21:32:45 -0500 | [diff] [blame] | 1330 | struct gfs2_sbd *sdp = root->d_sb->s_fs_info; |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1331 | struct gfs2_args *args = &sdp->sd_args; |
Benjamin Marzinski | 3d3c10f | 2009-10-20 02:39:44 -0500 | [diff] [blame] | 1332 | int val; |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1333 | |
Al Viro | 34c80b1 | 2011-12-08 21:32:45 -0500 | [diff] [blame] | 1334 | if (is_ancestor(root, sdp->sd_master_dir)) |
Fabian Frederick | eaebded | 2014-07-02 22:08:46 +0200 | [diff] [blame] | 1335 | seq_puts(s, ",meta"); |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1336 | if (args->ar_lockproto[0]) |
| 1337 | seq_printf(s, ",lockproto=%s", args->ar_lockproto); |
| 1338 | if (args->ar_locktable[0]) |
| 1339 | seq_printf(s, ",locktable=%s", args->ar_locktable); |
| 1340 | if (args->ar_hostdata[0]) |
| 1341 | seq_printf(s, ",hostdata=%s", args->ar_hostdata); |
| 1342 | if (args->ar_spectator) |
Fabian Frederick | eaebded | 2014-07-02 22:08:46 +0200 | [diff] [blame] | 1343 | seq_puts(s, ",spectator"); |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1344 | if (args->ar_localflocks) |
Fabian Frederick | eaebded | 2014-07-02 22:08:46 +0200 | [diff] [blame] | 1345 | seq_puts(s, ",localflocks"); |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1346 | if (args->ar_debug) |
Fabian Frederick | eaebded | 2014-07-02 22:08:46 +0200 | [diff] [blame] | 1347 | seq_puts(s, ",debug"); |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1348 | if (args->ar_posix_acl) |
Fabian Frederick | eaebded | 2014-07-02 22:08:46 +0200 | [diff] [blame] | 1349 | seq_puts(s, ",acl"); |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1350 | if (args->ar_quota != GFS2_QUOTA_DEFAULT) { |
| 1351 | char *state; |
| 1352 | switch (args->ar_quota) { |
| 1353 | case GFS2_QUOTA_OFF: |
| 1354 | state = "off"; |
| 1355 | break; |
| 1356 | case GFS2_QUOTA_ACCOUNT: |
| 1357 | state = "account"; |
| 1358 | break; |
| 1359 | case GFS2_QUOTA_ON: |
| 1360 | state = "on"; |
| 1361 | break; |
| 1362 | default: |
| 1363 | state = "unknown"; |
| 1364 | break; |
| 1365 | } |
| 1366 | seq_printf(s, ",quota=%s", state); |
| 1367 | } |
| 1368 | if (args->ar_suiddir) |
Fabian Frederick | eaebded | 2014-07-02 22:08:46 +0200 | [diff] [blame] | 1369 | seq_puts(s, ",suiddir"); |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1370 | if (args->ar_data != GFS2_DATA_DEFAULT) { |
| 1371 | char *state; |
| 1372 | switch (args->ar_data) { |
| 1373 | case GFS2_DATA_WRITEBACK: |
| 1374 | state = "writeback"; |
| 1375 | break; |
| 1376 | case GFS2_DATA_ORDERED: |
| 1377 | state = "ordered"; |
| 1378 | break; |
| 1379 | default: |
| 1380 | state = "unknown"; |
| 1381 | break; |
| 1382 | } |
| 1383 | seq_printf(s, ",data=%s", state); |
| 1384 | } |
| 1385 | if (args->ar_discard) |
Fabian Frederick | eaebded | 2014-07-02 22:08:46 +0200 | [diff] [blame] | 1386 | seq_puts(s, ",discard"); |
Benjamin Marzinski | 5e687ea | 2010-05-04 14:29:16 -0500 | [diff] [blame] | 1387 | val = sdp->sd_tune.gt_logd_secs; |
| 1388 | if (val != 30) |
Benjamin Marzinski | 3d3c10f | 2009-10-20 02:39:44 -0500 | [diff] [blame] | 1389 | seq_printf(s, ",commit=%d", val); |
| 1390 | val = sdp->sd_tune.gt_statfs_quantum; |
| 1391 | if (val != 30) |
| 1392 | seq_printf(s, ",statfs_quantum=%d", val); |
Steven Whitehouse | 2b9731e | 2012-08-20 17:07:49 +0100 | [diff] [blame] | 1393 | else if (sdp->sd_tune.gt_statfs_slow) |
| 1394 | seq_puts(s, ",statfs_quantum=0"); |
Benjamin Marzinski | 3d3c10f | 2009-10-20 02:39:44 -0500 | [diff] [blame] | 1395 | val = sdp->sd_tune.gt_quota_quantum; |
| 1396 | if (val != 60) |
| 1397 | seq_printf(s, ",quota_quantum=%d", val); |
| 1398 | if (args->ar_statfs_percent) |
| 1399 | seq_printf(s, ",statfs_percent=%d", args->ar_statfs_percent); |
Bob Peterson | d34843d | 2009-08-24 10:44:18 +0100 | [diff] [blame] | 1400 | if (args->ar_errors != GFS2_ERRORS_DEFAULT) { |
| 1401 | const char *state; |
| 1402 | |
| 1403 | switch (args->ar_errors) { |
| 1404 | case GFS2_ERRORS_WITHDRAW: |
| 1405 | state = "withdraw"; |
| 1406 | break; |
| 1407 | case GFS2_ERRORS_PANIC: |
| 1408 | state = "panic"; |
| 1409 | break; |
| 1410 | default: |
| 1411 | state = "unknown"; |
| 1412 | break; |
| 1413 | } |
| 1414 | seq_printf(s, ",errors=%s", state); |
| 1415 | } |
Steven Whitehouse | cdcfde6 | 2009-10-30 10:48:53 +0000 | [diff] [blame] | 1416 | if (test_bit(SDF_NOBARRIERS, &sdp->sd_flags)) |
Fabian Frederick | eaebded | 2014-07-02 22:08:46 +0200 | [diff] [blame] | 1417 | seq_puts(s, ",nobarrier"); |
Steven Whitehouse | 913a71d | 2010-05-06 11:03:29 +0100 | [diff] [blame] | 1418 | if (test_bit(SDF_DEMOTE, &sdp->sd_flags)) |
Fabian Frederick | eaebded | 2014-07-02 22:08:46 +0200 | [diff] [blame] | 1419 | seq_puts(s, ",demote_interface_used"); |
Benjamin Marzinski | 90306c4 | 2012-05-29 23:01:09 -0500 | [diff] [blame] | 1420 | if (args->ar_rgrplvb) |
Fabian Frederick | eaebded | 2014-07-02 22:08:46 +0200 | [diff] [blame] | 1421 | seq_puts(s, ",rgrplvb"); |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1422 | return 0; |
| 1423 | } |
| 1424 | |
Steven Whitehouse | f42ab08 | 2011-04-14 16:50:31 +0100 | [diff] [blame] | 1425 | static void gfs2_final_release_pages(struct gfs2_inode *ip) |
| 1426 | { |
| 1427 | struct inode *inode = &ip->i_inode; |
| 1428 | struct gfs2_glock *gl = ip->i_gl; |
| 1429 | |
| 1430 | truncate_inode_pages(gfs2_glock2aspace(ip->i_gl), 0); |
| 1431 | truncate_inode_pages(&inode->i_data, 0); |
| 1432 | |
| 1433 | if (atomic_read(&gl->gl_revokes) == 0) { |
| 1434 | clear_bit(GLF_LFLUSH, &gl->gl_flags); |
| 1435 | clear_bit(GLF_DIRTY, &gl->gl_flags); |
| 1436 | } |
| 1437 | } |
| 1438 | |
| 1439 | static int gfs2_dinode_dealloc(struct gfs2_inode *ip) |
| 1440 | { |
| 1441 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); |
Steven Whitehouse | f42ab08 | 2011-04-14 16:50:31 +0100 | [diff] [blame] | 1442 | struct gfs2_rgrpd *rgd; |
Bob Peterson | 564e12b | 2011-11-21 13:36:17 -0500 | [diff] [blame] | 1443 | struct gfs2_holder gh; |
Steven Whitehouse | f42ab08 | 2011-04-14 16:50:31 +0100 | [diff] [blame] | 1444 | int error; |
| 1445 | |
| 1446 | if (gfs2_get_inode_blocks(&ip->i_inode) != 1) { |
Steven Whitehouse | 94fb763 | 2011-05-09 13:36:10 +0100 | [diff] [blame] | 1447 | gfs2_consist_inode(ip); |
Steven Whitehouse | f42ab08 | 2011-04-14 16:50:31 +0100 | [diff] [blame] | 1448 | return -EIO; |
| 1449 | } |
| 1450 | |
Bob Peterson | 8e2e004 | 2012-07-19 08:12:40 -0400 | [diff] [blame] | 1451 | error = gfs2_rindex_update(sdp); |
| 1452 | if (error) |
| 1453 | return error; |
Steven Whitehouse | f42ab08 | 2011-04-14 16:50:31 +0100 | [diff] [blame] | 1454 | |
Eric W. Biederman | f4108a6 | 2013-01-31 17:49:26 -0800 | [diff] [blame] | 1455 | error = gfs2_quota_hold(ip, NO_UID_QUOTA_CHANGE, NO_GID_QUOTA_CHANGE); |
Steven Whitehouse | f42ab08 | 2011-04-14 16:50:31 +0100 | [diff] [blame] | 1456 | if (error) |
Bob Peterson | 5407e24 | 2012-05-18 09:28:23 -0400 | [diff] [blame] | 1457 | return error; |
Steven Whitehouse | f42ab08 | 2011-04-14 16:50:31 +0100 | [diff] [blame] | 1458 | |
Steven Whitehouse | 66fc061 | 2012-02-08 12:58:32 +0000 | [diff] [blame] | 1459 | rgd = gfs2_blk2rgrpd(sdp, ip->i_no_addr, 1); |
Steven Whitehouse | f42ab08 | 2011-04-14 16:50:31 +0100 | [diff] [blame] | 1460 | if (!rgd) { |
| 1461 | gfs2_consist_inode(ip); |
| 1462 | error = -EIO; |
Steven Whitehouse | 8339ee5 | 2011-08-31 16:38:29 +0100 | [diff] [blame] | 1463 | goto out_qs; |
Steven Whitehouse | f42ab08 | 2011-04-14 16:50:31 +0100 | [diff] [blame] | 1464 | } |
| 1465 | |
Bob Peterson | 564e12b | 2011-11-21 13:36:17 -0500 | [diff] [blame] | 1466 | error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, &gh); |
Steven Whitehouse | f42ab08 | 2011-04-14 16:50:31 +0100 | [diff] [blame] | 1467 | if (error) |
Steven Whitehouse | 8339ee5 | 2011-08-31 16:38:29 +0100 | [diff] [blame] | 1468 | goto out_qs; |
Steven Whitehouse | f42ab08 | 2011-04-14 16:50:31 +0100 | [diff] [blame] | 1469 | |
Steven Whitehouse | 4667a0e | 2011-04-18 14:18:09 +0100 | [diff] [blame] | 1470 | error = gfs2_trans_begin(sdp, RES_RG_BIT + RES_STATFS + RES_QUOTA, |
| 1471 | sdp->sd_jdesc->jd_blocks); |
Steven Whitehouse | f42ab08 | 2011-04-14 16:50:31 +0100 | [diff] [blame] | 1472 | if (error) |
| 1473 | goto out_rg_gunlock; |
| 1474 | |
| 1475 | gfs2_free_di(rgd, ip); |
| 1476 | |
| 1477 | gfs2_final_release_pages(ip); |
| 1478 | |
| 1479 | gfs2_trans_end(sdp); |
| 1480 | |
| 1481 | out_rg_gunlock: |
Bob Peterson | 564e12b | 2011-11-21 13:36:17 -0500 | [diff] [blame] | 1482 | gfs2_glock_dq_uninit(&gh); |
Steven Whitehouse | f42ab08 | 2011-04-14 16:50:31 +0100 | [diff] [blame] | 1483 | out_qs: |
| 1484 | gfs2_quota_unhold(ip); |
Steven Whitehouse | f42ab08 | 2011-04-14 16:50:31 +0100 | [diff] [blame] | 1485 | return error; |
| 1486 | } |
| 1487 | |
Steven Whitehouse | 380f7c6 | 2011-07-14 08:59:44 +0100 | [diff] [blame] | 1488 | /** |
| 1489 | * gfs2_evict_inode - Remove an inode from cache |
| 1490 | * @inode: The inode to evict |
| 1491 | * |
| 1492 | * There are three cases to consider: |
| 1493 | * 1. i_nlink == 0, we are final opener (and must deallocate) |
| 1494 | * 2. i_nlink == 0, we are not the final opener (and cannot deallocate) |
| 1495 | * 3. i_nlink > 0 |
| 1496 | * |
| 1497 | * If the fs is read only, then we have to treat all cases as per #3 |
| 1498 | * since we are unable to do any deallocation. The inode will be |
| 1499 | * deallocated by the next read/write node to attempt an allocation |
| 1500 | * in the same resource group |
| 1501 | * |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1502 | * We have to (at the moment) hold the inodes main lock to cover |
| 1503 | * the gap between unlocking the shared lock on the iopen lock and |
| 1504 | * taking the exclusive lock. I'd rather do a shared -> exclusive |
| 1505 | * conversion on the iopen lock, but we can change that later. This |
| 1506 | * is safe, just less efficient. |
| 1507 | */ |
| 1508 | |
Al Viro | d5c1515 | 2010-06-07 11:05:19 -0400 | [diff] [blame] | 1509 | static void gfs2_evict_inode(struct inode *inode) |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1510 | { |
Steven Whitehouse | 001e8e8 | 2011-03-30 14:17:51 +0100 | [diff] [blame] | 1511 | struct super_block *sb = inode->i_sb; |
| 1512 | struct gfs2_sbd *sdp = sb->s_fs_info; |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1513 | struct gfs2_inode *ip = GFS2_I(inode); |
| 1514 | struct gfs2_holder gh; |
| 1515 | int error; |
| 1516 | |
Abhi Das | 0597880 | 2014-03-31 10:33:17 -0500 | [diff] [blame] | 1517 | if (test_bit(GIF_FREE_VFS_INODE, &ip->i_flags)) { |
| 1518 | clear_inode(inode); |
| 1519 | return; |
| 1520 | } |
| 1521 | |
Steven Whitehouse | 001e8e8 | 2011-03-30 14:17:51 +0100 | [diff] [blame] | 1522 | if (inode->i_nlink || (sb->s_flags & MS_RDONLY)) |
Al Viro | d5c1515 | 2010-06-07 11:05:19 -0400 | [diff] [blame] | 1523 | goto out; |
| 1524 | |
Bob Peterson | 44ad37d | 2011-03-17 16:19:58 -0400 | [diff] [blame] | 1525 | /* Must not read inode block until block type has been verified */ |
| 1526 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, GL_SKIP, &gh); |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1527 | if (unlikely(error)) { |
Bob Peterson | a6a4d98 | 2013-05-29 11:51:52 -0400 | [diff] [blame] | 1528 | ip->i_iopen_gh.gh_flags |= GL_NOCACHE; |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1529 | gfs2_glock_dq_uninit(&ip->i_iopen_gh); |
| 1530 | goto out; |
| 1531 | } |
| 1532 | |
Steven Whitehouse | 40ac218 | 2011-08-02 13:17:27 +0100 | [diff] [blame] | 1533 | if (!test_bit(GIF_ALLOC_FAILED, &ip->i_flags)) { |
| 1534 | error = gfs2_check_blk_type(sdp, ip->i_no_addr, GFS2_BLKST_UNLINKED); |
| 1535 | if (error) |
| 1536 | goto out_truncate; |
| 1537 | } |
Steven Whitehouse | acf7e24 | 2009-09-08 18:00:30 +0100 | [diff] [blame] | 1538 | |
Bob Peterson | 44ad37d | 2011-03-17 16:19:58 -0400 | [diff] [blame] | 1539 | if (test_bit(GIF_INVALID, &ip->i_flags)) { |
| 1540 | error = gfs2_inode_refresh(ip); |
| 1541 | if (error) |
| 1542 | goto out_truncate; |
| 1543 | } |
| 1544 | |
Benjamin Marzinski | 23c3010 | 2011-01-14 22:39:16 -0600 | [diff] [blame] | 1545 | ip->i_iopen_gh.gh_flags |= GL_NOCACHE; |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1546 | gfs2_glock_dq_wait(&ip->i_iopen_gh); |
| 1547 | gfs2_holder_reinit(LM_ST_EXCLUSIVE, LM_FLAG_TRY_1CB | GL_NOCACHE, &ip->i_iopen_gh); |
| 1548 | error = gfs2_glock_nq(&ip->i_iopen_gh); |
| 1549 | if (error) |
| 1550 | goto out_truncate; |
| 1551 | |
Steven Whitehouse | 380f7c6 | 2011-07-14 08:59:44 +0100 | [diff] [blame] | 1552 | /* Case 1 starts here */ |
| 1553 | |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1554 | if (S_ISDIR(inode->i_mode) && |
| 1555 | (ip->i_diskflags & GFS2_DIF_EXHASH)) { |
| 1556 | error = gfs2_dir_exhash_dealloc(ip); |
| 1557 | if (error) |
| 1558 | goto out_unlock; |
| 1559 | } |
| 1560 | |
| 1561 | if (ip->i_eattr) { |
| 1562 | error = gfs2_ea_dealloc(ip); |
| 1563 | if (error) |
| 1564 | goto out_unlock; |
| 1565 | } |
| 1566 | |
| 1567 | if (!gfs2_is_stuffed(ip)) { |
| 1568 | error = gfs2_file_dealloc(ip); |
| 1569 | if (error) |
| 1570 | goto out_unlock; |
| 1571 | } |
| 1572 | |
| 1573 | error = gfs2_dinode_dealloc(ip); |
Steven Whitehouse | f42ab08 | 2011-04-14 16:50:31 +0100 | [diff] [blame] | 1574 | goto out_unlock; |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1575 | |
| 1576 | out_truncate: |
Benjamin Marzinski | 2497255 | 2014-05-01 22:26:55 -0500 | [diff] [blame] | 1577 | gfs2_log_flush(sdp, ip->i_gl, NORMAL_FLUSH); |
Benjamin Marzinski | 2216db7 | 2012-09-20 09:52:58 -0500 | [diff] [blame] | 1578 | if (test_bit(GLF_DIRTY, &ip->i_gl->gl_flags)) { |
| 1579 | struct address_space *metamapping = gfs2_glock2aspace(ip->i_gl); |
| 1580 | filemap_fdatawrite(metamapping); |
| 1581 | filemap_fdatawait(metamapping); |
| 1582 | } |
Steven Whitehouse | 40ac218 | 2011-08-02 13:17:27 +0100 | [diff] [blame] | 1583 | write_inode_now(inode, 1); |
Steven Whitehouse | b5b24d7 | 2011-09-07 10:33:25 +0100 | [diff] [blame] | 1584 | gfs2_ail_flush(ip->i_gl, 0); |
Steven Whitehouse | 40ac218 | 2011-08-02 13:17:27 +0100 | [diff] [blame] | 1585 | |
Steven Whitehouse | 380f7c6 | 2011-07-14 08:59:44 +0100 | [diff] [blame] | 1586 | /* Case 2 starts here */ |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1587 | error = gfs2_trans_begin(sdp, 0, sdp->sd_jdesc->jd_blocks); |
| 1588 | if (error) |
| 1589 | goto out_unlock; |
Steven Whitehouse | 380f7c6 | 2011-07-14 08:59:44 +0100 | [diff] [blame] | 1590 | /* Needs to be done before glock release & also in a transaction */ |
| 1591 | truncate_inode_pages(&inode->i_data, 0); |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1592 | gfs2_trans_end(sdp); |
| 1593 | |
| 1594 | out_unlock: |
Steven Whitehouse | 380f7c6 | 2011-07-14 08:59:44 +0100 | [diff] [blame] | 1595 | /* Error path for case 1 */ |
Bob Peterson | 8e2e004 | 2012-07-19 08:12:40 -0400 | [diff] [blame] | 1596 | if (gfs2_rs_active(ip->i_res)) |
Bob Peterson | 2009521 | 2013-03-13 10:26:38 -0400 | [diff] [blame] | 1597 | gfs2_rs_deltree(ip->i_res); |
Bob Peterson | 8e2e004 | 2012-07-19 08:12:40 -0400 | [diff] [blame] | 1598 | |
Bob Peterson | a6a4d98 | 2013-05-29 11:51:52 -0400 | [diff] [blame] | 1599 | if (test_bit(HIF_HOLDER, &ip->i_iopen_gh.gh_iflags)) { |
| 1600 | ip->i_iopen_gh.gh_flags |= GL_NOCACHE; |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1601 | gfs2_glock_dq(&ip->i_iopen_gh); |
Bob Peterson | a6a4d98 | 2013-05-29 11:51:52 -0400 | [diff] [blame] | 1602 | } |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1603 | gfs2_holder_uninit(&ip->i_iopen_gh); |
| 1604 | gfs2_glock_dq_uninit(&gh); |
| 1605 | if (error && error != GLR_TRYFAILED && error != -EROFS) |
Al Viro | d5c1515 | 2010-06-07 11:05:19 -0400 | [diff] [blame] | 1606 | fs_warn(sdp, "gfs2_evict_inode: %d\n", error); |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1607 | out: |
Steven Whitehouse | 380f7c6 | 2011-07-14 08:59:44 +0100 | [diff] [blame] | 1608 | /* Case 3 starts here */ |
Johannes Weiner | 91b0abe | 2014-04-03 14:47:49 -0700 | [diff] [blame] | 1609 | truncate_inode_pages_final(&inode->i_data); |
Steven Whitehouse | af5c269 | 2013-09-27 12:49:33 +0100 | [diff] [blame] | 1610 | gfs2_rs_delete(ip, NULL); |
Steven Whitehouse | 4513899 | 2013-01-28 09:30:07 +0000 | [diff] [blame] | 1611 | gfs2_ordered_del_inode(ip); |
Jan Kara | dbd5768 | 2012-05-03 14:48:02 +0200 | [diff] [blame] | 1612 | clear_inode(inode); |
Steven Whitehouse | 17d539f | 2011-06-15 10:29:37 +0100 | [diff] [blame] | 1613 | gfs2_dir_hash_inval(ip); |
Al Viro | d5c1515 | 2010-06-07 11:05:19 -0400 | [diff] [blame] | 1614 | ip->i_gl->gl_object = NULL; |
Tejun Heo | 4382973 | 2012-08-20 14:51:24 -0700 | [diff] [blame] | 1615 | flush_delayed_work(&ip->i_gl->gl_work); |
Steven Whitehouse | 29687a2 | 2011-03-30 16:33:25 +0100 | [diff] [blame] | 1616 | gfs2_glock_add_to_lru(ip->i_gl); |
Al Viro | d5c1515 | 2010-06-07 11:05:19 -0400 | [diff] [blame] | 1617 | gfs2_glock_put(ip->i_gl); |
| 1618 | ip->i_gl = NULL; |
| 1619 | if (ip->i_iopen_gh.gh_gl) { |
| 1620 | ip->i_iopen_gh.gh_gl->gl_object = NULL; |
Bob Peterson | a6a4d98 | 2013-05-29 11:51:52 -0400 | [diff] [blame] | 1621 | ip->i_iopen_gh.gh_flags |= GL_NOCACHE; |
Al Viro | d5c1515 | 2010-06-07 11:05:19 -0400 | [diff] [blame] | 1622 | gfs2_glock_dq_uninit(&ip->i_iopen_gh); |
| 1623 | } |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1624 | } |
| 1625 | |
| 1626 | static struct inode *gfs2_alloc_inode(struct super_block *sb) |
| 1627 | { |
| 1628 | struct gfs2_inode *ip; |
| 1629 | |
| 1630 | ip = kmem_cache_alloc(gfs2_inode_cachep, GFP_KERNEL); |
| 1631 | if (ip) { |
| 1632 | ip->i_flags = 0; |
| 1633 | ip->i_gl = NULL; |
Steven Whitehouse | 54335b1 | 2011-09-01 13:31:59 +0100 | [diff] [blame] | 1634 | ip->i_rgd = NULL; |
Bob Peterson | 0a305e4 | 2012-06-06 11:17:59 +0100 | [diff] [blame] | 1635 | ip->i_res = NULL; |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1636 | } |
| 1637 | return &ip->i_inode; |
| 1638 | } |
| 1639 | |
Nick Piggin | fa0d7e3d | 2011-01-07 17:49:49 +1100 | [diff] [blame] | 1640 | static void gfs2_i_callback(struct rcu_head *head) |
| 1641 | { |
| 1642 | struct inode *inode = container_of(head, struct inode, i_rcu); |
Nick Piggin | fa0d7e3d | 2011-01-07 17:49:49 +1100 | [diff] [blame] | 1643 | kmem_cache_free(gfs2_inode_cachep, inode); |
| 1644 | } |
| 1645 | |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1646 | static void gfs2_destroy_inode(struct inode *inode) |
| 1647 | { |
Nick Piggin | fa0d7e3d | 2011-01-07 17:49:49 +1100 | [diff] [blame] | 1648 | call_rcu(&inode->i_rcu, gfs2_i_callback); |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1649 | } |
| 1650 | |
| 1651 | const struct super_operations gfs2_super_ops = { |
| 1652 | .alloc_inode = gfs2_alloc_inode, |
| 1653 | .destroy_inode = gfs2_destroy_inode, |
| 1654 | .write_inode = gfs2_write_inode, |
Steven Whitehouse | ab9bbda | 2011-08-15 14:20:36 +0100 | [diff] [blame] | 1655 | .dirty_inode = gfs2_dirty_inode, |
Al Viro | d5c1515 | 2010-06-07 11:05:19 -0400 | [diff] [blame] | 1656 | .evict_inode = gfs2_evict_inode, |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1657 | .put_super = gfs2_put_super, |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1658 | .sync_fs = gfs2_sync_fs, |
Benjamin Marzinski | 2e60d76 | 2014-11-13 20:42:04 -0600 | [diff] [blame] | 1659 | .freeze_super = gfs2_freeze, |
| 1660 | .thaw_super = gfs2_unfreeze, |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1661 | .statfs = gfs2_statfs, |
| 1662 | .remount_fs = gfs2_remount_fs, |
Steven Whitehouse | 9e6e0a1 | 2009-05-22 10:36:01 +0100 | [diff] [blame] | 1663 | .drop_inode = gfs2_drop_inode, |
| 1664 | .show_options = gfs2_show_options, |
| 1665 | }; |
| 1666 | |