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
;
28 struct kmem_cache
*gfs2_quotad_cachep __read_mostly
;
30 void gfs2_assert_i(struct gfs2_sbd
*sdp
)
32 printk(KERN_EMERG
"GFS2: fsid=%s: fatal assertion failed\n",
36 int gfs2_lm_withdraw(struct gfs2_sbd
*sdp
, char *fmt
, ...)
40 if (test_and_set_bit(SDF_SHUTDOWN
, &sdp
->sd_flags
))
47 fs_err(sdp
, "about to withdraw this file system\n");
48 BUG_ON(sdp
->sd_args
.ar_debug
);
50 fs_err(sdp
, "telling LM to withdraw\n");
51 gfs2_withdraw_lockproto(&sdp
->sd_lockstruct
);
52 fs_err(sdp
, "withdrawn\n");
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
64 int gfs2_assert_withdraw_i(struct gfs2_sbd
*sdp
, char *assertion
,
65 const char *function
, char *file
, unsigned int line
)
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
);
74 return (me
) ? -1 : -2;
78 * gfs2_assert_warn_i - Print a message to the console if @assertion is false
79 * Returns: -1 if we printed something
83 int gfs2_assert_warn_i(struct gfs2_sbd
*sdp
, char *assertion
,
84 const char *function
, char *file
, unsigned int line
)
86 if (time_before(jiffies
,
87 sdp
->sd_last_warning
+
88 gfs2_tune_get(sdp
, gt_complain_secs
) * HZ
))
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
);
97 if (sdp
->sd_args
.ar_debug
)
102 sdp
->sd_last_warning
= jiffies
;
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
113 int gfs2_consist_i(struct gfs2_sbd
*sdp
, int cluster_wide
, const char *function
,
114 char *file
, unsigned int line
)
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",
121 sdp
->sd_fsname
, function
, file
, line
);
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
131 int gfs2_consist_inode_i(struct gfs2_inode
*ip
, int cluster_wide
,
132 const char *function
, char *file
, unsigned int line
)
134 struct gfs2_sbd
*sdp
= GFS2_SB(&ip
->i_inode
);
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",
141 sdp
->sd_fsname
, (unsigned long long)ip
->i_no_formal_ino
,
142 (unsigned long long)ip
->i_no_addr
,
143 sdp
->sd_fsname
, function
, file
, line
);
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
153 int gfs2_consist_rgrpd_i(struct gfs2_rgrpd
*rgd
, int cluster_wide
,
154 const char *function
, char *file
, unsigned int line
)
156 struct gfs2_sbd
*sdp
= rgd
->rd_sbd
;
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",
163 sdp
->sd_fsname
, (unsigned long long)rgd
->rd_addr
,
164 sdp
->sd_fsname
, function
, file
, line
);
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
174 int gfs2_meta_check_ii(struct gfs2_sbd
*sdp
, struct buffer_head
*bh
,
175 const char *type
, const char *function
, char *file
,
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",
184 sdp
->sd_fsname
, (unsigned long long)bh
->b_blocknr
, type
,
185 sdp
->sd_fsname
, function
, file
, line
);
186 return (me
) ? -1 : -2;
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
195 int gfs2_metatype_check_ii(struct gfs2_sbd
*sdp
, struct buffer_head
*bh
,
196 u16 type
, u16 t
, const char *function
,
197 char *file
, unsigned int line
)
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",
205 sdp
->sd_fsname
, (unsigned long long)bh
->b_blocknr
, type
, t
,
206 sdp
->sd_fsname
, function
, file
, line
);
207 return (me
) ? -1 : -2;
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
216 int gfs2_io_error_i(struct gfs2_sbd
*sdp
, const char *function
, char *file
,
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",
224 sdp
->sd_fsname
, function
, file
, line
);
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
234 int gfs2_io_error_bh_i(struct gfs2_sbd
*sdp
, struct buffer_head
*bh
,
235 const char *function
, char *file
, unsigned int line
)
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",
243 sdp
->sd_fsname
, (unsigned long long)bh
->b_blocknr
,
244 sdp
->sd_fsname
, function
, file
, line
);
248 void gfs2_icbit_munge(struct gfs2_sbd
*sdp
, unsigned char **bitmap
,
249 unsigned int bit
, int new_value
)
251 unsigned int c
, o
, b
= bit
;
254 c
= b
/ (8 * PAGE_SIZE
);
259 old_value
= (bitmap
[c
][o
] & (1 << b
));
260 gfs2_assert_withdraw(sdp
, !old_value
!= !new_value
);
263 bitmap
[c
][o
] |= 1 << b
;
265 bitmap
[c
][o
] &= ~(1 << b
);