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/sched.h>
11 #include <linux/slab.h>
12 #include <linux/spinlock.h>
13 #include <linux/completion.h>
14 #include <linux/buffer_head.h>
15 #include <linux/crc32.h>
16 #include <linux/gfs2_ondisk.h>
17 #include <linux/lm_interface.h>
18 #include <asm/uaccess.h>
26 struct kmem_cache
*gfs2_glock_cachep __read_mostly
;
27 struct kmem_cache
*gfs2_inode_cachep __read_mostly
;
28 struct kmem_cache
*gfs2_bufdata_cachep __read_mostly
;
30 void gfs2_assert_i(struct gfs2_sbd
*sdp
)
32 printk(KERN_EMERG
"GFS2: fsid=%s: fatal assertion failed\n",
37 * gfs2_assert_withdraw_i - Cause the machine to withdraw if @assertion is false
38 * Returns: -1 if this call withdrew the machine,
39 * -2 if it was already withdrawn
42 int gfs2_assert_withdraw_i(struct gfs2_sbd
*sdp
, char *assertion
,
43 const char *function
, char *file
, unsigned int line
)
46 me
= gfs2_lm_withdraw(sdp
,
47 "GFS2: fsid=%s: fatal: assertion \"%s\" failed\n"
48 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
49 sdp
->sd_fsname
, assertion
,
50 sdp
->sd_fsname
, function
, file
, line
);
52 return (me
) ? -1 : -2;
56 * gfs2_assert_warn_i - Print a message to the console if @assertion is false
57 * Returns: -1 if we printed something
61 int gfs2_assert_warn_i(struct gfs2_sbd
*sdp
, char *assertion
,
62 const char *function
, char *file
, unsigned int line
)
64 if (time_before(jiffies
,
65 sdp
->sd_last_warning
+
66 gfs2_tune_get(sdp
, gt_complain_secs
) * HZ
))
70 "GFS2: fsid=%s: warning: assertion \"%s\" failed\n"
71 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
72 sdp
->sd_fsname
, assertion
,
73 sdp
->sd_fsname
, function
, file
, line
);
75 if (sdp
->sd_args
.ar_debug
)
80 sdp
->sd_last_warning
= jiffies
;
86 * gfs2_consist_i - Flag a filesystem consistency error and withdraw
87 * Returns: -1 if this call withdrew the machine,
88 * 0 if it was already withdrawn
91 int gfs2_consist_i(struct gfs2_sbd
*sdp
, int cluster_wide
, const char *function
,
92 char *file
, unsigned int line
)
95 rv
= gfs2_lm_withdraw(sdp
,
96 "GFS2: fsid=%s: fatal: filesystem consistency error\n"
97 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
99 sdp
->sd_fsname
, function
, file
, line
);
104 * gfs2_consist_inode_i - Flag an inode consistency error and withdraw
105 * Returns: -1 if this call withdrew the machine,
106 * 0 if it was already withdrawn
109 int gfs2_consist_inode_i(struct gfs2_inode
*ip
, int cluster_wide
,
110 const char *function
, char *file
, unsigned int line
)
112 struct gfs2_sbd
*sdp
= GFS2_SB(&ip
->i_inode
);
114 rv
= gfs2_lm_withdraw(sdp
,
115 "GFS2: fsid=%s: fatal: filesystem consistency error\n"
116 "GFS2: fsid=%s: inode = %llu %llu\n"
117 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
119 sdp
->sd_fsname
, (unsigned long long)ip
->i_num
.no_formal_ino
,
120 (unsigned long long)ip
->i_num
.no_addr
,
121 sdp
->sd_fsname
, function
, file
, line
);
126 * gfs2_consist_rgrpd_i - Flag a RG consistency error and withdraw
127 * Returns: -1 if this call withdrew the machine,
128 * 0 if it was already withdrawn
131 int gfs2_consist_rgrpd_i(struct gfs2_rgrpd
*rgd
, int cluster_wide
,
132 const char *function
, char *file
, unsigned int line
)
134 struct gfs2_sbd
*sdp
= rgd
->rd_sbd
;
136 rv
= gfs2_lm_withdraw(sdp
,
137 "GFS2: fsid=%s: fatal: filesystem consistency error\n"
138 "GFS2: fsid=%s: RG = %llu\n"
139 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
141 sdp
->sd_fsname
, (unsigned long long)rgd
->rd_ri
.ri_addr
,
142 sdp
->sd_fsname
, function
, file
, line
);
147 * gfs2_meta_check_ii - Flag a magic number consistency error and withdraw
148 * Returns: -1 if this call withdrew the machine,
149 * -2 if it was already withdrawn
152 int gfs2_meta_check_ii(struct gfs2_sbd
*sdp
, struct buffer_head
*bh
,
153 const char *type
, const char *function
, char *file
,
157 me
= gfs2_lm_withdraw(sdp
,
158 "GFS2: fsid=%s: fatal: invalid metadata block\n"
159 "GFS2: fsid=%s: bh = %llu (%s)\n"
160 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
162 sdp
->sd_fsname
, (unsigned long long)bh
->b_blocknr
, type
,
163 sdp
->sd_fsname
, function
, file
, line
);
164 return (me
) ? -1 : -2;
168 * gfs2_metatype_check_ii - Flag a metadata type consistency error and withdraw
169 * Returns: -1 if this call withdrew the machine,
170 * -2 if it was already withdrawn
173 int gfs2_metatype_check_ii(struct gfs2_sbd
*sdp
, struct buffer_head
*bh
,
174 u16 type
, u16 t
, const char *function
,
175 char *file
, unsigned int line
)
178 me
= gfs2_lm_withdraw(sdp
,
179 "GFS2: fsid=%s: fatal: invalid metadata block\n"
180 "GFS2: fsid=%s: bh = %llu (type: exp=%u, found=%u)\n"
181 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
183 sdp
->sd_fsname
, (unsigned long long)bh
->b_blocknr
, type
, t
,
184 sdp
->sd_fsname
, function
, file
, line
);
185 return (me
) ? -1 : -2;
189 * gfs2_io_error_i - Flag an I/O error and withdraw
190 * Returns: -1 if this call withdrew the machine,
191 * 0 if it was already withdrawn
194 int gfs2_io_error_i(struct gfs2_sbd
*sdp
, const char *function
, char *file
,
198 rv
= gfs2_lm_withdraw(sdp
,
199 "GFS2: fsid=%s: fatal: I/O error\n"
200 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
202 sdp
->sd_fsname
, function
, file
, line
);
207 * gfs2_io_error_bh_i - Flag a buffer I/O error and withdraw
208 * Returns: -1 if this call withdrew the machine,
209 * 0 if it was already withdrawn
212 int gfs2_io_error_bh_i(struct gfs2_sbd
*sdp
, struct buffer_head
*bh
,
213 const char *function
, char *file
, unsigned int line
)
216 rv
= gfs2_lm_withdraw(sdp
,
217 "GFS2: fsid=%s: fatal: I/O error\n"
218 "GFS2: fsid=%s: block = %llu\n"
219 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
221 sdp
->sd_fsname
, (unsigned long long)bh
->b_blocknr
,
222 sdp
->sd_fsname
, function
, file
, line
);
226 void gfs2_icbit_munge(struct gfs2_sbd
*sdp
, unsigned char **bitmap
,
227 unsigned int bit
, int new_value
)
229 unsigned int c
, o
, b
= bit
;
232 c
= b
/ (8 * PAGE_SIZE
);
237 old_value
= (bitmap
[c
][o
] & (1 << b
));
238 gfs2_assert_withdraw(sdp
, !old_value
!= !new_value
);
241 bitmap
[c
][o
] |= 1 << b
;
243 bitmap
[c
][o
] &= ~(1 << b
);