blob: 374f50e954967a147e56dffe2eec590c9fc087bc [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;
Steven Whitehouse37b2c832008-11-17 14:25:37 +000028struct kmem_cache *gfs2_quotad_cachep __read_mostly;
David Teiglandb3b94fa2006-01-16 16:50:04 +000029
David Teiglandb3b94fa2006-01-16 16:50:04 +000030void 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 Whitehouseda755fd2008-01-30 15:34:04 +000036int gfs2_lm_withdraw(struct gfs2_sbd *sdp, char *fmt, ...)
37{
38 va_list args;
39
40 if (test_and_set_bit(SDF_SHUTDOWN, &sdp->sd_flags))
41 return 0;
42
43 va_start(args, fmt);
44 vprintk(fmt, args);
45 va_end(args);
46
47 fs_err(sdp, "about to withdraw this file system\n");
48 BUG_ON(sdp->sd_args.ar_debug);
49
50 fs_err(sdp, "telling LM to withdraw\n");
51 gfs2_withdraw_lockproto(&sdp->sd_lockstruct);
52 fs_err(sdp, "withdrawn\n");
53 dump_stack();
54
55 return -1;
56}
57
David Teiglandb3b94fa2006-01-16 16:50:04 +000058/**
59 * gfs2_assert_withdraw_i - Cause the machine to withdraw if @assertion is false
60 * Returns: -1 if this call withdrew the machine,
61 * -2 if it was already withdrawn
62 */
63
64int gfs2_assert_withdraw_i(struct gfs2_sbd *sdp, char *assertion,
65 const char *function, char *file, unsigned int line)
66{
67 int me;
68 me = gfs2_lm_withdraw(sdp,
69 "GFS2: fsid=%s: fatal: assertion \"%s\" failed\n"
70 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
71 sdp->sd_fsname, assertion,
72 sdp->sd_fsname, function, file, line);
Steven Whitehouse18ec7d52006-02-08 11:50:51 +000073 dump_stack();
David Teiglandb3b94fa2006-01-16 16:50:04 +000074 return (me) ? -1 : -2;
75}
76
77/**
78 * gfs2_assert_warn_i - Print a message to the console if @assertion is false
79 * Returns: -1 if we printed something
80 * -2 if we didn't
81 */
82
83int gfs2_assert_warn_i(struct gfs2_sbd *sdp, char *assertion,
84 const char *function, char *file, unsigned int line)
85{
86 if (time_before(jiffies,
87 sdp->sd_last_warning +
88 gfs2_tune_get(sdp, gt_complain_secs) * HZ))
89 return -2;
90
91 printk(KERN_WARNING
92 "GFS2: fsid=%s: warning: assertion \"%s\" failed\n"
93 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
94 sdp->sd_fsname, assertion,
95 sdp->sd_fsname, function, file, line);
96
97 if (sdp->sd_args.ar_debug)
98 BUG();
Steven Whitehouse18ec7d52006-02-08 11:50:51 +000099 else
100 dump_stack();
David Teiglandb3b94fa2006-01-16 16:50:04 +0000101
102 sdp->sd_last_warning = jiffies;
103
104 return -1;
105}
106
107/**
108 * gfs2_consist_i - Flag a filesystem consistency error and withdraw
109 * Returns: -1 if this call withdrew the machine,
110 * 0 if it was already withdrawn
111 */
112
113int gfs2_consist_i(struct gfs2_sbd *sdp, int cluster_wide, const char *function,
114 char *file, unsigned int line)
115{
116 int rv;
117 rv = gfs2_lm_withdraw(sdp,
118 "GFS2: fsid=%s: fatal: filesystem consistency error\n"
119 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
120 sdp->sd_fsname,
121 sdp->sd_fsname, function, file, line);
122 return rv;
123}
124
125/**
126 * gfs2_consist_inode_i - Flag an inode consistency error and withdraw
127 * Returns: -1 if this call withdrew the machine,
128 * 0 if it was already withdrawn
129 */
130
131int gfs2_consist_inode_i(struct gfs2_inode *ip, int cluster_wide,
132 const char *function, char *file, unsigned int line)
133{
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400134 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000135 int rv;
136 rv = gfs2_lm_withdraw(sdp,
137 "GFS2: fsid=%s: fatal: filesystem consistency error\n"
138 "GFS2: fsid=%s: inode = %llu %llu\n"
139 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
140 sdp->sd_fsname,
Steven Whitehousedbb7cae2007-05-15 15:37:50 +0100141 sdp->sd_fsname, (unsigned long long)ip->i_no_formal_ino,
142 (unsigned long long)ip->i_no_addr,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000143 sdp->sd_fsname, function, file, line);
144 return rv;
145}
146
147/**
148 * gfs2_consist_rgrpd_i - Flag a RG consistency error and withdraw
149 * Returns: -1 if this call withdrew the machine,
150 * 0 if it was already withdrawn
151 */
152
153int gfs2_consist_rgrpd_i(struct gfs2_rgrpd *rgd, int cluster_wide,
154 const char *function, char *file, unsigned int line)
155{
156 struct gfs2_sbd *sdp = rgd->rd_sbd;
157 int rv;
158 rv = gfs2_lm_withdraw(sdp,
159 "GFS2: fsid=%s: fatal: filesystem consistency error\n"
160 "GFS2: fsid=%s: RG = %llu\n"
161 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
162 sdp->sd_fsname,
Steven Whitehousebb8d8a62007-06-01 14:11:58 +0100163 sdp->sd_fsname, (unsigned long long)rgd->rd_addr,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000164 sdp->sd_fsname, function, file, line);
165 return rv;
166}
167
168/**
169 * gfs2_meta_check_ii - Flag a magic number consistency error and withdraw
170 * Returns: -1 if this call withdrew the machine,
171 * -2 if it was already withdrawn
172 */
173
174int gfs2_meta_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
175 const char *type, const char *function, char *file,
176 unsigned int line)
177{
178 int me;
179 me = gfs2_lm_withdraw(sdp,
180 "GFS2: fsid=%s: fatal: invalid metadata block\n"
181 "GFS2: fsid=%s: bh = %llu (%s)\n"
182 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
183 sdp->sd_fsname,
Steven Whitehouse382066d2006-05-24 10:22:09 -0400184 sdp->sd_fsname, (unsigned long long)bh->b_blocknr, type,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000185 sdp->sd_fsname, function, file, line);
186 return (me) ? -1 : -2;
187}
188
189/**
190 * gfs2_metatype_check_ii - Flag a metadata type consistency error and withdraw
191 * Returns: -1 if this call withdrew the machine,
192 * -2 if it was already withdrawn
193 */
194
195int gfs2_metatype_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
Steven Whitehousecd915492006-09-04 12:49:07 -0400196 u16 type, u16 t, const char *function,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000197 char *file, unsigned int line)
198{
199 int me;
200 me = gfs2_lm_withdraw(sdp,
201 "GFS2: fsid=%s: fatal: invalid metadata block\n"
202 "GFS2: fsid=%s: bh = %llu (type: exp=%u, found=%u)\n"
203 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
204 sdp->sd_fsname,
Steven Whitehouse382066d2006-05-24 10:22:09 -0400205 sdp->sd_fsname, (unsigned long long)bh->b_blocknr, type, t,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000206 sdp->sd_fsname, function, file, line);
207 return (me) ? -1 : -2;
208}
209
210/**
211 * gfs2_io_error_i - Flag an I/O error and withdraw
212 * Returns: -1 if this call withdrew the machine,
213 * 0 if it was already withdrawn
214 */
215
216int gfs2_io_error_i(struct gfs2_sbd *sdp, const char *function, char *file,
217 unsigned int line)
218{
219 int rv;
220 rv = gfs2_lm_withdraw(sdp,
221 "GFS2: fsid=%s: fatal: I/O error\n"
222 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
223 sdp->sd_fsname,
224 sdp->sd_fsname, function, file, line);
225 return rv;
226}
227
228/**
229 * gfs2_io_error_bh_i - Flag a buffer I/O error and withdraw
230 * Returns: -1 if this call withdrew the machine,
231 * 0 if it was already withdrawn
232 */
233
234int gfs2_io_error_bh_i(struct gfs2_sbd *sdp, struct buffer_head *bh,
235 const char *function, char *file, unsigned int line)
236{
237 int rv;
238 rv = gfs2_lm_withdraw(sdp,
239 "GFS2: fsid=%s: fatal: I/O error\n"
240 "GFS2: fsid=%s: block = %llu\n"
241 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
242 sdp->sd_fsname,
Steven Whitehouse382066d2006-05-24 10:22:09 -0400243 sdp->sd_fsname, (unsigned long long)bh->b_blocknr,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000244 sdp->sd_fsname, function, file, line);
245 return rv;
246}
247
David Teiglandb3b94fa2006-01-16 16:50:04 +0000248void gfs2_icbit_munge(struct gfs2_sbd *sdp, unsigned char **bitmap,
249 unsigned int bit, int new_value)
250{
251 unsigned int c, o, b = bit;
252 int old_value;
253
254 c = b / (8 * PAGE_SIZE);
255 b %= 8 * PAGE_SIZE;
256 o = b / 8;
257 b %= 8;
258
259 old_value = (bitmap[c][o] & (1 << b));
260 gfs2_assert_withdraw(sdp, !old_value != !new_value);
261
262 if (new_value)
263 bitmap[c][o] |= 1 << b;
264 else
265 bitmap[c][o] &= ~(1 << b);
266}
267