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