David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. |
Steven Whitehouse | 3a8a9a1 | 2006-05-18 15:09:15 -0400 | [diff] [blame] | 3 | * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 4 | * |
| 5 | * This copyrighted material is made available to anyone wishing to use, |
| 6 | * modify, copy, or redistribute it subject to the terms and conditions |
Steven Whitehouse | e9fc2aa | 2006-09-01 11:05:15 -0400 | [diff] [blame] | 7 | * of the GNU General Public License version 2. |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 10 | #include <linux/spinlock.h> |
| 11 | #include <linux/completion.h> |
| 12 | #include <linux/buffer_head.h> |
| 13 | #include <linux/crc32.h> |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 14 | #include <linux/gfs2_ondisk.h> |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 15 | #include <asm/uaccess.h> |
| 16 | |
| 17 | #include "gfs2.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 18 | #include "incore.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 19 | #include "glock.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 20 | #include "util.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 21 | |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 22 | struct kmem_cache *gfs2_glock_cachep __read_mostly; |
Steven Whitehouse | 009d851 | 2009-12-08 12:12:13 +0000 | [diff] [blame] | 23 | struct kmem_cache *gfs2_glock_aspace_cachep __read_mostly; |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 24 | struct kmem_cache *gfs2_inode_cachep __read_mostly; |
| 25 | struct kmem_cache *gfs2_bufdata_cachep __read_mostly; |
Bob Peterson | 6bdd9be | 2008-01-28 17:20:26 -0600 | [diff] [blame] | 26 | struct kmem_cache *gfs2_rgrpd_cachep __read_mostly; |
Steven Whitehouse | 37b2c83 | 2008-11-17 14:25:37 +0000 | [diff] [blame] | 27 | struct kmem_cache *gfs2_quotad_cachep __read_mostly; |
Steven Whitehouse | 75ca61c | 2012-03-08 12:10:23 +0000 | [diff] [blame] | 28 | mempool_t *gfs2_bh_pool __read_mostly; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 29 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 30 | void gfs2_assert_i(struct gfs2_sbd *sdp) |
| 31 | { |
| 32 | printk(KERN_EMERG "GFS2: fsid=%s: fatal assertion failed\n", |
| 33 | sdp->sd_fsname); |
| 34 | } |
| 35 | |
Steven Whitehouse | da755fd | 2008-01-30 15:34:04 +0000 | [diff] [blame] | 36 | int gfs2_lm_withdraw(struct gfs2_sbd *sdp, char *fmt, ...) |
| 37 | { |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 38 | struct lm_lockstruct *ls = &sdp->sd_lockstruct; |
| 39 | const struct lm_lockops *lm = ls->ls_ops; |
Steven Whitehouse | da755fd | 2008-01-30 15:34:04 +0000 | [diff] [blame] | 40 | va_list args; |
| 41 | |
Bob Peterson | d34843d | 2009-08-24 10:44:18 +0100 | [diff] [blame] | 42 | if (sdp->sd_args.ar_errors == GFS2_ERRORS_WITHDRAW && |
| 43 | test_and_set_bit(SDF_SHUTDOWN, &sdp->sd_flags)) |
Steven Whitehouse | da755fd | 2008-01-30 15:34:04 +0000 | [diff] [blame] | 44 | return 0; |
| 45 | |
| 46 | va_start(args, fmt); |
| 47 | vprintk(fmt, args); |
| 48 | va_end(args); |
| 49 | |
Bob Peterson | d34843d | 2009-08-24 10:44:18 +0100 | [diff] [blame] | 50 | if (sdp->sd_args.ar_errors == GFS2_ERRORS_WITHDRAW) { |
| 51 | fs_err(sdp, "about to withdraw this file system\n"); |
| 52 | BUG_ON(sdp->sd_args.ar_debug); |
Steven Whitehouse | da755fd | 2008-01-30 15:34:04 +0000 | [diff] [blame] | 53 | |
Bob Peterson | d34843d | 2009-08-24 10:44:18 +0100 | [diff] [blame] | 54 | kobject_uevent(&sdp->sd_kobj, KOBJ_OFFLINE); |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 55 | |
Bob Peterson | d34843d | 2009-08-24 10:44:18 +0100 | [diff] [blame] | 56 | if (lm->lm_unmount) { |
| 57 | fs_err(sdp, "telling LM to unmount\n"); |
| 58 | lm->lm_unmount(sdp); |
| 59 | } |
| 60 | fs_err(sdp, "withdrawn\n"); |
| 61 | dump_stack(); |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 62 | } |
Bob Peterson | d34843d | 2009-08-24 10:44:18 +0100 | [diff] [blame] | 63 | |
| 64 | if (sdp->sd_args.ar_errors == GFS2_ERRORS_PANIC) |
| 65 | panic("GFS2: fsid=%s: panic requested.\n", sdp->sd_fsname); |
Steven Whitehouse | da755fd | 2008-01-30 15:34:04 +0000 | [diff] [blame] | 66 | |
| 67 | return -1; |
| 68 | } |
| 69 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 70 | /** |
| 71 | * gfs2_assert_withdraw_i - Cause the machine to withdraw if @assertion is false |
| 72 | * Returns: -1 if this call withdrew the machine, |
| 73 | * -2 if it was already withdrawn |
| 74 | */ |
| 75 | |
| 76 | int gfs2_assert_withdraw_i(struct gfs2_sbd *sdp, char *assertion, |
| 77 | const char *function, char *file, unsigned int line) |
| 78 | { |
| 79 | int me; |
| 80 | me = gfs2_lm_withdraw(sdp, |
| 81 | "GFS2: fsid=%s: fatal: assertion \"%s\" failed\n" |
| 82 | "GFS2: fsid=%s: function = %s, file = %s, line = %u\n", |
| 83 | sdp->sd_fsname, assertion, |
| 84 | sdp->sd_fsname, function, file, line); |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 85 | dump_stack(); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 86 | return (me) ? -1 : -2; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * gfs2_assert_warn_i - Print a message to the console if @assertion is false |
| 91 | * Returns: -1 if we printed something |
| 92 | * -2 if we didn't |
| 93 | */ |
| 94 | |
| 95 | int gfs2_assert_warn_i(struct gfs2_sbd *sdp, char *assertion, |
| 96 | const char *function, char *file, unsigned int line) |
| 97 | { |
| 98 | if (time_before(jiffies, |
| 99 | sdp->sd_last_warning + |
| 100 | gfs2_tune_get(sdp, gt_complain_secs) * HZ)) |
| 101 | return -2; |
| 102 | |
Bob Peterson | d34843d | 2009-08-24 10:44:18 +0100 | [diff] [blame] | 103 | if (sdp->sd_args.ar_errors == GFS2_ERRORS_WITHDRAW) |
| 104 | printk(KERN_WARNING |
| 105 | "GFS2: fsid=%s: warning: assertion \"%s\" failed\n" |
| 106 | "GFS2: fsid=%s: function = %s, file = %s, line = %u\n", |
| 107 | sdp->sd_fsname, assertion, |
| 108 | sdp->sd_fsname, function, file, line); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 109 | |
| 110 | if (sdp->sd_args.ar_debug) |
| 111 | BUG(); |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 112 | else |
| 113 | dump_stack(); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 114 | |
Bob Peterson | d34843d | 2009-08-24 10:44:18 +0100 | [diff] [blame] | 115 | if (sdp->sd_args.ar_errors == GFS2_ERRORS_PANIC) |
| 116 | panic("GFS2: fsid=%s: warning: assertion \"%s\" failed\n" |
| 117 | "GFS2: fsid=%s: function = %s, file = %s, line = %u\n", |
| 118 | sdp->sd_fsname, assertion, |
| 119 | sdp->sd_fsname, function, file, line); |
| 120 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 121 | sdp->sd_last_warning = jiffies; |
| 122 | |
| 123 | return -1; |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * gfs2_consist_i - Flag a filesystem consistency error and withdraw |
| 128 | * Returns: -1 if this call withdrew the machine, |
| 129 | * 0 if it was already withdrawn |
| 130 | */ |
| 131 | |
| 132 | int gfs2_consist_i(struct gfs2_sbd *sdp, int cluster_wide, const char *function, |
| 133 | char *file, unsigned int line) |
| 134 | { |
| 135 | int rv; |
| 136 | rv = gfs2_lm_withdraw(sdp, |
| 137 | "GFS2: fsid=%s: fatal: filesystem consistency error\n" |
| 138 | "GFS2: fsid=%s: function = %s, file = %s, line = %u\n", |
| 139 | sdp->sd_fsname, |
| 140 | sdp->sd_fsname, function, file, line); |
| 141 | return rv; |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * gfs2_consist_inode_i - Flag an inode consistency error and withdraw |
| 146 | * Returns: -1 if this call withdrew the machine, |
| 147 | * 0 if it was already withdrawn |
| 148 | */ |
| 149 | |
| 150 | int gfs2_consist_inode_i(struct gfs2_inode *ip, int cluster_wide, |
| 151 | const char *function, char *file, unsigned int line) |
| 152 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 153 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 154 | int rv; |
| 155 | rv = gfs2_lm_withdraw(sdp, |
| 156 | "GFS2: fsid=%s: fatal: filesystem consistency error\n" |
| 157 | "GFS2: fsid=%s: inode = %llu %llu\n" |
| 158 | "GFS2: fsid=%s: function = %s, file = %s, line = %u\n", |
| 159 | sdp->sd_fsname, |
Steven Whitehouse | dbb7cae | 2007-05-15 15:37:50 +0100 | [diff] [blame] | 160 | sdp->sd_fsname, (unsigned long long)ip->i_no_formal_ino, |
| 161 | (unsigned long long)ip->i_no_addr, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 162 | sdp->sd_fsname, function, file, line); |
| 163 | return rv; |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * gfs2_consist_rgrpd_i - Flag a RG consistency error and withdraw |
| 168 | * Returns: -1 if this call withdrew the machine, |
| 169 | * 0 if it was already withdrawn |
| 170 | */ |
| 171 | |
| 172 | int gfs2_consist_rgrpd_i(struct gfs2_rgrpd *rgd, int cluster_wide, |
| 173 | const char *function, char *file, unsigned int line) |
| 174 | { |
| 175 | struct gfs2_sbd *sdp = rgd->rd_sbd; |
| 176 | int rv; |
| 177 | rv = gfs2_lm_withdraw(sdp, |
| 178 | "GFS2: fsid=%s: fatal: filesystem consistency error\n" |
| 179 | "GFS2: fsid=%s: RG = %llu\n" |
| 180 | "GFS2: fsid=%s: function = %s, file = %s, line = %u\n", |
| 181 | sdp->sd_fsname, |
Steven Whitehouse | bb8d8a6 | 2007-06-01 14:11:58 +0100 | [diff] [blame] | 182 | sdp->sd_fsname, (unsigned long long)rgd->rd_addr, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 183 | sdp->sd_fsname, function, file, line); |
| 184 | return rv; |
| 185 | } |
| 186 | |
| 187 | /** |
| 188 | * gfs2_meta_check_ii - Flag a magic number consistency error and withdraw |
| 189 | * Returns: -1 if this call withdrew the machine, |
| 190 | * -2 if it was already withdrawn |
| 191 | */ |
| 192 | |
| 193 | int gfs2_meta_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh, |
| 194 | const char *type, const char *function, char *file, |
| 195 | unsigned int line) |
| 196 | { |
| 197 | int me; |
| 198 | me = gfs2_lm_withdraw(sdp, |
| 199 | "GFS2: fsid=%s: fatal: invalid metadata block\n" |
| 200 | "GFS2: fsid=%s: bh = %llu (%s)\n" |
| 201 | "GFS2: fsid=%s: function = %s, file = %s, line = %u\n", |
| 202 | sdp->sd_fsname, |
Steven Whitehouse | 382066d | 2006-05-24 10:22:09 -0400 | [diff] [blame] | 203 | sdp->sd_fsname, (unsigned long long)bh->b_blocknr, type, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 204 | sdp->sd_fsname, function, file, line); |
| 205 | return (me) ? -1 : -2; |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * gfs2_metatype_check_ii - Flag a metadata type consistency error and withdraw |
| 210 | * Returns: -1 if this call withdrew the machine, |
| 211 | * -2 if it was already withdrawn |
| 212 | */ |
| 213 | |
| 214 | int gfs2_metatype_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh, |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 215 | u16 type, u16 t, const char *function, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 216 | char *file, unsigned int line) |
| 217 | { |
| 218 | int me; |
| 219 | me = gfs2_lm_withdraw(sdp, |
| 220 | "GFS2: fsid=%s: fatal: invalid metadata block\n" |
| 221 | "GFS2: fsid=%s: bh = %llu (type: exp=%u, found=%u)\n" |
| 222 | "GFS2: fsid=%s: function = %s, file = %s, line = %u\n", |
| 223 | sdp->sd_fsname, |
Steven Whitehouse | 382066d | 2006-05-24 10:22:09 -0400 | [diff] [blame] | 224 | sdp->sd_fsname, (unsigned long long)bh->b_blocknr, type, t, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 225 | sdp->sd_fsname, function, file, line); |
| 226 | return (me) ? -1 : -2; |
| 227 | } |
| 228 | |
| 229 | /** |
| 230 | * gfs2_io_error_i - Flag an I/O error and withdraw |
| 231 | * Returns: -1 if this call withdrew the machine, |
| 232 | * 0 if it was already withdrawn |
| 233 | */ |
| 234 | |
| 235 | int gfs2_io_error_i(struct gfs2_sbd *sdp, const char *function, char *file, |
| 236 | unsigned int line) |
| 237 | { |
| 238 | int rv; |
| 239 | rv = gfs2_lm_withdraw(sdp, |
| 240 | "GFS2: fsid=%s: fatal: I/O error\n" |
| 241 | "GFS2: fsid=%s: function = %s, file = %s, line = %u\n", |
| 242 | sdp->sd_fsname, |
| 243 | sdp->sd_fsname, function, file, line); |
| 244 | return rv; |
| 245 | } |
| 246 | |
| 247 | /** |
| 248 | * gfs2_io_error_bh_i - Flag a buffer I/O error and withdraw |
| 249 | * Returns: -1 if this call withdrew the machine, |
| 250 | * 0 if it was already withdrawn |
| 251 | */ |
| 252 | |
| 253 | int gfs2_io_error_bh_i(struct gfs2_sbd *sdp, struct buffer_head *bh, |
| 254 | const char *function, char *file, unsigned int line) |
| 255 | { |
| 256 | int rv; |
| 257 | rv = gfs2_lm_withdraw(sdp, |
| 258 | "GFS2: fsid=%s: fatal: I/O error\n" |
| 259 | "GFS2: fsid=%s: block = %llu\n" |
| 260 | "GFS2: fsid=%s: function = %s, file = %s, line = %u\n", |
| 261 | sdp->sd_fsname, |
Steven Whitehouse | 382066d | 2006-05-24 10:22:09 -0400 | [diff] [blame] | 262 | sdp->sd_fsname, (unsigned long long)bh->b_blocknr, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 263 | sdp->sd_fsname, function, file, line); |
| 264 | return rv; |
| 265 | } |
| 266 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 267 | void gfs2_icbit_munge(struct gfs2_sbd *sdp, unsigned char **bitmap, |
| 268 | unsigned int bit, int new_value) |
| 269 | { |
| 270 | unsigned int c, o, b = bit; |
| 271 | int old_value; |
| 272 | |
| 273 | c = b / (8 * PAGE_SIZE); |
| 274 | b %= 8 * PAGE_SIZE; |
| 275 | o = b / 8; |
| 276 | b %= 8; |
| 277 | |
| 278 | old_value = (bitmap[c][o] & (1 << b)); |
| 279 | gfs2_assert_withdraw(sdp, !old_value != !new_value); |
| 280 | |
| 281 | if (new_value) |
| 282 | bitmap[c][o] |= 1 << b; |
| 283 | else |
| 284 | bitmap[c][o] &= ~(1 << b); |
| 285 | } |
| 286 | |