2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
7 * of the GNU General Public License version 2.
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>
15 #include <linux/gfs2_ondisk.h>
16 #include <linux/lm_interface.h>
17 #include <asm/uaccess.h>
24 struct kmem_cache *gfs2_glock_cachep __read_mostly;
25 struct kmem_cache *gfs2_inode_cachep __read_mostly;
26 struct kmem_cache *gfs2_bufdata_cachep __read_mostly;
27 struct kmem_cache *gfs2_rgrpd_cachep __read_mostly;
29 void gfs2_assert_i(struct gfs2_sbd *sdp)
31 printk(KERN_EMERG "GFS2: fsid=%s: fatal assertion failed\n",
35 int gfs2_lm_withdraw(struct gfs2_sbd *sdp, char *fmt, ...)
39 if (test_and_set_bit(SDF_SHUTDOWN, &sdp->sd_flags))
46 fs_err(sdp, "about to withdraw this file system\n");
47 BUG_ON(sdp->sd_args.ar_debug);
49 fs_err(sdp, "telling LM to withdraw\n");
50 gfs2_withdraw_lockproto(&sdp->sd_lockstruct);
51 fs_err(sdp, "withdrawn\n");
58 * gfs2_assert_withdraw_i - Cause the machine to withdraw if @assertion is false
59 * Returns: -1 if this call withdrew the machine,
60 * -2 if it was already withdrawn
63 int gfs2_assert_withdraw_i(struct gfs2_sbd *sdp, char *assertion,
64 const char *function, char *file, unsigned int line)
67 me = gfs2_lm_withdraw(sdp,
68 "GFS2: fsid=%s: fatal: assertion \"%s\" failed\n"
69 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
70 sdp->sd_fsname, assertion,
71 sdp->sd_fsname, function, file, line);
73 return (me) ? -1 : -2;
77 * gfs2_assert_warn_i - Print a message to the console if @assertion is false
78 * Returns: -1 if we printed something
82 int gfs2_assert_warn_i(struct gfs2_sbd *sdp, char *assertion,
83 const char *function, char *file, unsigned int line)
85 if (time_before(jiffies,
86 sdp->sd_last_warning +
87 gfs2_tune_get(sdp, gt_complain_secs) * HZ))
91 "GFS2: fsid=%s: warning: assertion \"%s\" failed\n"
92 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
93 sdp->sd_fsname, assertion,
94 sdp->sd_fsname, function, file, line);
96 if (sdp->sd_args.ar_debug)
101 sdp->sd_last_warning = jiffies;
107 * gfs2_consist_i - Flag a filesystem consistency error and withdraw
108 * Returns: -1 if this call withdrew the machine,
109 * 0 if it was already withdrawn
112 int gfs2_consist_i(struct gfs2_sbd *sdp, int cluster_wide, const char *function,
113 char *file, unsigned int line)
116 rv = gfs2_lm_withdraw(sdp,
117 "GFS2: fsid=%s: fatal: filesystem consistency error\n"
118 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
120 sdp->sd_fsname, function, file, line);
125 * gfs2_consist_inode_i - Flag an inode consistency error and withdraw
126 * Returns: -1 if this call withdrew the machine,
127 * 0 if it was already withdrawn
130 int gfs2_consist_inode_i(struct gfs2_inode *ip, int cluster_wide,
131 const char *function, char *file, unsigned int line)
133 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
135 rv = gfs2_lm_withdraw(sdp,
136 "GFS2: fsid=%s: fatal: filesystem consistency error\n"
137 "GFS2: fsid=%s: inode = %llu %llu\n"
138 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
140 sdp->sd_fsname, (unsigned long long)ip->i_no_formal_ino,
141 (unsigned long long)ip->i_no_addr,
142 sdp->sd_fsname, function, file, line);
147 * gfs2_consist_rgrpd_i - Flag a RG consistency error and withdraw
148 * Returns: -1 if this call withdrew the machine,
149 * 0 if it was already withdrawn
152 int gfs2_consist_rgrpd_i(struct gfs2_rgrpd *rgd, int cluster_wide,
153 const char *function, char *file, unsigned int line)
155 struct gfs2_sbd *sdp = rgd->rd_sbd;
157 rv = gfs2_lm_withdraw(sdp,
158 "GFS2: fsid=%s: fatal: filesystem consistency error\n"
159 "GFS2: fsid=%s: RG = %llu\n"
160 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
162 sdp->sd_fsname, (unsigned long long)rgd->rd_addr,
163 sdp->sd_fsname, function, file, line);
168 * gfs2_meta_check_ii - Flag a magic number consistency error and withdraw
169 * Returns: -1 if this call withdrew the machine,
170 * -2 if it was already withdrawn
173 int gfs2_meta_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
174 const char *type, const char *function, char *file,
178 me = gfs2_lm_withdraw(sdp,
179 "GFS2: fsid=%s: fatal: invalid metadata block\n"
180 "GFS2: fsid=%s: bh = %llu (%s)\n"
181 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
183 sdp->sd_fsname, (unsigned long long)bh->b_blocknr, type,
184 sdp->sd_fsname, function, file, line);
185 return (me) ? -1 : -2;
189 * gfs2_metatype_check_ii - Flag a metadata type consistency error and withdraw
190 * Returns: -1 if this call withdrew the machine,
191 * -2 if it was already withdrawn
194 int gfs2_metatype_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
195 u16 type, u16 t, const char *function,
196 char *file, unsigned int line)
199 me = gfs2_lm_withdraw(sdp,
200 "GFS2: fsid=%s: fatal: invalid metadata block\n"
201 "GFS2: fsid=%s: bh = %llu (type: exp=%u, found=%u)\n"
202 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
204 sdp->sd_fsname, (unsigned long long)bh->b_blocknr, type, t,
205 sdp->sd_fsname, function, file, line);
206 return (me) ? -1 : -2;
210 * gfs2_io_error_i - Flag an I/O error and withdraw
211 * Returns: -1 if this call withdrew the machine,
212 * 0 if it was already withdrawn
215 int gfs2_io_error_i(struct gfs2_sbd *sdp, const char *function, char *file,
219 rv = gfs2_lm_withdraw(sdp,
220 "GFS2: fsid=%s: fatal: I/O error\n"
221 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
223 sdp->sd_fsname, function, file, line);
228 * gfs2_io_error_bh_i - Flag a buffer I/O error and withdraw
229 * Returns: -1 if this call withdrew the machine,
230 * 0 if it was already withdrawn
233 int gfs2_io_error_bh_i(struct gfs2_sbd *sdp, struct buffer_head *bh,
234 const char *function, char *file, unsigned int line)
237 rv = gfs2_lm_withdraw(sdp,
238 "GFS2: fsid=%s: fatal: I/O error\n"
239 "GFS2: fsid=%s: block = %llu\n"
240 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
242 sdp->sd_fsname, (unsigned long long)bh->b_blocknr,
243 sdp->sd_fsname, function, file, line);
247 void gfs2_icbit_munge(struct gfs2_sbd *sdp, unsigned char **bitmap,
248 unsigned int bit, int new_value)
250 unsigned int c, o, b = bit;
253 c = b / (8 * PAGE_SIZE);
258 old_value = (bitmap[c][o] & (1 << b));
259 gfs2_assert_withdraw(sdp, !old_value != !new_value);
262 bitmap[c][o] |= 1 << b;
264 bitmap[c][o] &= ~(1 << b);