blob: d31e355c61fbc5040f0a2b8ac9775724a67eee53 [file] [log] [blame]
David Teiglandb3b94fa2006-01-16 16:50:04 +00001/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
Steven Whitehouse3a8a9a12006-05-18 15:09:15 -04003 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
David Teiglandb3b94fa2006-01-16 16:50:04 +00004 *
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 Whitehousee9fc2aa2006-09-01 11:05:15 -04007 * of the GNU General Public License version 2.
David Teiglandb3b94fa2006-01-16 16:50:04 +00008 */
9
David Teiglandb3b94fa2006-01-16 16:50:04 +000010#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 Whitehouse5c676f62006-02-27 17:23:27 -050015#include <linux/gfs2_ondisk.h>
Fabio Massimo Di Nitto7d308592006-09-19 07:56:29 +020016#include <linux/lm_interface.h>
David Teiglandb3b94fa2006-01-16 16:50:04 +000017#include <asm/uaccess.h>
18
19#include "gfs2.h"
Steven Whitehouse5c676f62006-02-27 17:23:27 -050020#include "incore.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000021#include "glock.h"
Steven Whitehouse5c676f62006-02-27 17:23:27 -050022#include "util.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000023
Christoph Lametere18b8902006-12-06 20:33:20 -080024struct kmem_cache *gfs2_glock_cachep __read_mostly;
25struct kmem_cache *gfs2_inode_cachep __read_mostly;
26struct kmem_cache *gfs2_bufdata_cachep __read_mostly;
Bob Peterson6bdd9be2008-01-28 17:20:26 -060027struct kmem_cache *gfs2_rgrpd_cachep __read_mostly;
David Teiglandb3b94fa2006-01-16 16:50:04 +000028
David Teiglandb3b94fa2006-01-16 16:50:04 +000029void 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 Whitehouseda755fd2008-01-30 15:34:04 +000035int gfs2_lm_withdraw(struct gfs2_sbd *sdp, char *fmt, ...)
36{
37 va_list args;
38
39 if (test_and_set_bit(SDF_SHUTDOWN, &sdp->sd_flags))
40 return 0;
41
42 va_start(args, fmt);
43 vprintk(fmt, args);
44 va_end(args);
45
46 fs_err(sdp, "about to withdraw this file system\n");
47 BUG_ON(sdp->sd_args.ar_debug);
48
49 fs_err(sdp, "telling LM to withdraw\n");
50 gfs2_withdraw_lockproto(&sdp->sd_lockstruct);
51 fs_err(sdp, "withdrawn\n");
52 dump_stack();
53
54 return -1;
55}
56
David Teiglandb3b94fa2006-01-16 16:50:04 +000057/**
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
61 */
62
63int gfs2_assert_withdraw_i(struct gfs2_sbd *sdp, char *assertion,
64 const char *function, char *file, unsigned int line)
65{
66 int me;
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);
Steven Whitehouse18ec7d52006-02-08 11:50:51 +000072 dump_stack();
David Teiglandb3b94fa2006-01-16 16:50:04 +000073 return (me) ? -1 : -2;
74}
75
76/**
77 * gfs2_assert_warn_i - Print a message to the console if @assertion is false
78 * Returns: -1 if we printed something
79 * -2 if we didn't
80 */
81
82int gfs2_assert_warn_i(struct gfs2_sbd *sdp, char *assertion,
83 const char *function, char *file, unsigned int line)
84{
85 if (time_before(jiffies,
86 sdp->sd_last_warning +
87 gfs2_tune_get(sdp, gt_complain_secs) * HZ))
88 return -2;
89
90 printk(KERN_WARNING
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);
95
96 if (sdp->sd_args.ar_debug)
97 BUG();
Steven Whitehouse18ec7d52006-02-08 11:50:51 +000098 else
99 dump_stack();
David Teiglandb3b94fa2006-01-16 16:50:04 +0000100
101 sdp->sd_last_warning = jiffies;
102
103 return -1;
104}
105
106/**
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
110 */
111
112int gfs2_consist_i(struct gfs2_sbd *sdp, int cluster_wide, const char *function,
113 char *file, unsigned int line)
114{
115 int rv;
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",
119 sdp->sd_fsname,
120 sdp->sd_fsname, function, file, line);
121 return rv;
122}
123
124/**
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
128 */
129
130int gfs2_consist_inode_i(struct gfs2_inode *ip, int cluster_wide,
131 const char *function, char *file, unsigned int line)
132{
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400133 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000134 int rv;
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",
139 sdp->sd_fsname,
Steven Whitehousedbb7cae2007-05-15 15:37:50 +0100140 sdp->sd_fsname, (unsigned long long)ip->i_no_formal_ino,
141 (unsigned long long)ip->i_no_addr,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000142 sdp->sd_fsname, function, file, line);
143 return rv;
144}
145
146/**
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
150 */
151
152int gfs2_consist_rgrpd_i(struct gfs2_rgrpd *rgd, int cluster_wide,
153 const char *function, char *file, unsigned int line)
154{
155 struct gfs2_sbd *sdp = rgd->rd_sbd;
156 int rv;
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",
161 sdp->sd_fsname,
Steven Whitehousebb8d8a62007-06-01 14:11:58 +0100162 sdp->sd_fsname, (unsigned long long)rgd->rd_addr,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000163 sdp->sd_fsname, function, file, line);
164 return rv;
165}
166
167/**
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
171 */
172
173int gfs2_meta_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
174 const char *type, const char *function, char *file,
175 unsigned int line)
176{
177 int me;
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",
182 sdp->sd_fsname,
Steven Whitehouse382066d2006-05-24 10:22:09 -0400183 sdp->sd_fsname, (unsigned long long)bh->b_blocknr, type,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000184 sdp->sd_fsname, function, file, line);
185 return (me) ? -1 : -2;
186}
187
188/**
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
192 */
193
194int gfs2_metatype_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
Steven Whitehousecd915492006-09-04 12:49:07 -0400195 u16 type, u16 t, const char *function,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000196 char *file, unsigned int line)
197{
198 int me;
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",
203 sdp->sd_fsname,
Steven Whitehouse382066d2006-05-24 10:22:09 -0400204 sdp->sd_fsname, (unsigned long long)bh->b_blocknr, type, t,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000205 sdp->sd_fsname, function, file, line);
206 return (me) ? -1 : -2;
207}
208
209/**
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
213 */
214
215int gfs2_io_error_i(struct gfs2_sbd *sdp, const char *function, char *file,
216 unsigned int line)
217{
218 int rv;
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",
222 sdp->sd_fsname,
223 sdp->sd_fsname, function, file, line);
224 return rv;
225}
226
227/**
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
231 */
232
233int gfs2_io_error_bh_i(struct gfs2_sbd *sdp, struct buffer_head *bh,
234 const char *function, char *file, unsigned int line)
235{
236 int rv;
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",
241 sdp->sd_fsname,
Steven Whitehouse382066d2006-05-24 10:22:09 -0400242 sdp->sd_fsname, (unsigned long long)bh->b_blocknr,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000243 sdp->sd_fsname, function, file, line);
244 return rv;
245}
246
David Teiglandb3b94fa2006-01-16 16:50:04 +0000247void gfs2_icbit_munge(struct gfs2_sbd *sdp, unsigned char **bitmap,
248 unsigned int bit, int new_value)
249{
250 unsigned int c, o, b = bit;
251 int old_value;
252
253 c = b / (8 * PAGE_SIZE);
254 b %= 8 * PAGE_SIZE;
255 o = b / 8;
256 b %= 8;
257
258 old_value = (bitmap[c][o] & (1 << b));
259 gfs2_assert_withdraw(sdp, !old_value != !new_value);
260
261 if (new_value)
262 bitmap[c][o] |= 1 << b;
263 else
264 bitmap[c][o] &= ~(1 << b);
265}
266