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