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 <asm/uaccess.h>
23 struct kmem_cache
*gfs2_glock_cachep __read_mostly
;
24 struct kmem_cache
*gfs2_glock_aspace_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
, ...)
38 struct lm_lockstruct
*ls
= &sdp
->sd_lockstruct
;
39 const struct lm_lockops
*lm
= ls
->ls_ops
;
42 if (sdp
->sd_args
.ar_errors
== GFS2_ERRORS_WITHDRAW
&&
43 test_and_set_bit(SDF_SHUTDOWN
, &sdp
->sd_flags
))
50 if (sdp
->sd_args
.ar_errors
== GFS2_ERRORS_WITHDRAW
) {
51 fs_err(sdp
, "about to withdraw this file system\n");
52 BUG_ON(sdp
->sd_args
.ar_debug
);
54 kobject_uevent(&sdp
->sd_kobj
, KOBJ_OFFLINE
);
57 fs_err(sdp
, "telling LM to unmount\n");
60 fs_err(sdp
, "withdrawn\n");
64 if (sdp
->sd_args
.ar_errors
== GFS2_ERRORS_PANIC
)
65 panic("GFS2: fsid=%s: panic requested.\n", sdp
->sd_fsname
);
71 * gfs2_assert_withdraw_i - Cause the machine to withdraw if @assertion is false
72 * Returns: -1 if this call withdrew the machine,
73 * -2 if it was already withdrawn
76 int gfs2_assert_withdraw_i(struct gfs2_sbd
*sdp
, char *assertion
,
77 const char *function
, char *file
, unsigned int line
)
80 me
= gfs2_lm_withdraw(sdp
,
81 "GFS2: fsid=%s: fatal: assertion \"%s\" failed\n"
82 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
83 sdp
->sd_fsname
, assertion
,
84 sdp
->sd_fsname
, function
, file
, line
);
86 return (me
) ? -1 : -2;
90 * gfs2_assert_warn_i - Print a message to the console if @assertion is false
91 * Returns: -1 if we printed something
95 int gfs2_assert_warn_i(struct gfs2_sbd
*sdp
, char *assertion
,
96 const char *function
, char *file
, unsigned int line
)
98 if (time_before(jiffies
,
99 sdp
->sd_last_warning
+
100 gfs2_tune_get(sdp
, gt_complain_secs
) * HZ
))
103 if (sdp
->sd_args
.ar_errors
== GFS2_ERRORS_WITHDRAW
)
105 "GFS2: fsid=%s: warning: assertion \"%s\" failed\n"
106 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
107 sdp
->sd_fsname
, assertion
,
108 sdp
->sd_fsname
, function
, file
, line
);
110 if (sdp
->sd_args
.ar_debug
)
115 if (sdp
->sd_args
.ar_errors
== GFS2_ERRORS_PANIC
)
116 panic("GFS2: fsid=%s: warning: assertion \"%s\" failed\n"
117 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
118 sdp
->sd_fsname
, assertion
,
119 sdp
->sd_fsname
, function
, file
, line
);
121 sdp
->sd_last_warning
= jiffies
;
127 * gfs2_consist_i - Flag a filesystem consistency error and withdraw
128 * Returns: -1 if this call withdrew the machine,
129 * 0 if it was already withdrawn
132 int gfs2_consist_i(struct gfs2_sbd
*sdp
, int cluster_wide
, const char *function
,
133 char *file
, unsigned int line
)
136 rv
= gfs2_lm_withdraw(sdp
,
137 "GFS2: fsid=%s: fatal: filesystem consistency error\n"
138 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
140 sdp
->sd_fsname
, function
, file
, line
);
145 * gfs2_consist_inode_i - Flag an inode consistency error and withdraw
146 * Returns: -1 if this call withdrew the machine,
147 * 0 if it was already withdrawn
150 int gfs2_consist_inode_i(struct gfs2_inode
*ip
, int cluster_wide
,
151 const char *function
, char *file
, unsigned int line
)
153 struct gfs2_sbd
*sdp
= GFS2_SB(&ip
->i_inode
);
155 rv
= gfs2_lm_withdraw(sdp
,
156 "GFS2: fsid=%s: fatal: filesystem consistency error\n"
157 "GFS2: fsid=%s: inode = %llu %llu\n"
158 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
160 sdp
->sd_fsname
, (unsigned long long)ip
->i_no_formal_ino
,
161 (unsigned long long)ip
->i_no_addr
,
162 sdp
->sd_fsname
, function
, file
, line
);
167 * gfs2_consist_rgrpd_i - Flag a RG consistency error and withdraw
168 * Returns: -1 if this call withdrew the machine,
169 * 0 if it was already withdrawn
172 int gfs2_consist_rgrpd_i(struct gfs2_rgrpd
*rgd
, int cluster_wide
,
173 const char *function
, char *file
, unsigned int line
)
175 struct gfs2_sbd
*sdp
= rgd
->rd_sbd
;
177 rv
= gfs2_lm_withdraw(sdp
,
178 "GFS2: fsid=%s: fatal: filesystem consistency error\n"
179 "GFS2: fsid=%s: RG = %llu\n"
180 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
182 sdp
->sd_fsname
, (unsigned long long)rgd
->rd_addr
,
183 sdp
->sd_fsname
, function
, file
, line
);
188 * gfs2_meta_check_ii - Flag a magic number consistency error and withdraw
189 * Returns: -1 if this call withdrew the machine,
190 * -2 if it was already withdrawn
193 int gfs2_meta_check_ii(struct gfs2_sbd
*sdp
, struct buffer_head
*bh
,
194 const char *type
, const char *function
, char *file
,
198 me
= gfs2_lm_withdraw(sdp
,
199 "GFS2: fsid=%s: fatal: invalid metadata block\n"
200 "GFS2: fsid=%s: bh = %llu (%s)\n"
201 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
203 sdp
->sd_fsname
, (unsigned long long)bh
->b_blocknr
, type
,
204 sdp
->sd_fsname
, function
, file
, line
);
205 return (me
) ? -1 : -2;
209 * gfs2_metatype_check_ii - Flag a metadata type consistency error and withdraw
210 * Returns: -1 if this call withdrew the machine,
211 * -2 if it was already withdrawn
214 int gfs2_metatype_check_ii(struct gfs2_sbd
*sdp
, struct buffer_head
*bh
,
215 u16 type
, u16 t
, const char *function
,
216 char *file
, unsigned int line
)
219 me
= gfs2_lm_withdraw(sdp
,
220 "GFS2: fsid=%s: fatal: invalid metadata block\n"
221 "GFS2: fsid=%s: bh = %llu (type: exp=%u, found=%u)\n"
222 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
224 sdp
->sd_fsname
, (unsigned long long)bh
->b_blocknr
, type
, t
,
225 sdp
->sd_fsname
, function
, file
, line
);
226 return (me
) ? -1 : -2;
230 * gfs2_io_error_i - Flag an I/O error and withdraw
231 * Returns: -1 if this call withdrew the machine,
232 * 0 if it was already withdrawn
235 int gfs2_io_error_i(struct gfs2_sbd
*sdp
, const char *function
, char *file
,
239 rv
= gfs2_lm_withdraw(sdp
,
240 "GFS2: fsid=%s: fatal: I/O error\n"
241 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
243 sdp
->sd_fsname
, function
, file
, line
);
248 * gfs2_io_error_bh_i - Flag a buffer I/O error and withdraw
249 * Returns: -1 if this call withdrew the machine,
250 * 0 if it was already withdrawn
253 int gfs2_io_error_bh_i(struct gfs2_sbd
*sdp
, struct buffer_head
*bh
,
254 const char *function
, char *file
, unsigned int line
)
257 rv
= gfs2_lm_withdraw(sdp
,
258 "GFS2: fsid=%s: fatal: I/O error\n"
259 "GFS2: fsid=%s: block = %llu\n"
260 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
262 sdp
->sd_fsname
, (unsigned long long)bh
->b_blocknr
,
263 sdp
->sd_fsname
, function
, file
, line
);
267 void gfs2_icbit_munge(struct gfs2_sbd
*sdp
, unsigned char **bitmap
,
268 unsigned int bit
, int new_value
)
270 unsigned int c
, o
, b
= bit
;
273 c
= b
/ (8 * PAGE_SIZE
);
278 old_value
= (bitmap
[c
][o
] & (1 << b
));
279 gfs2_assert_withdraw(sdp
, !old_value
!= !new_value
);
282 bitmap
[c
][o
] |= 1 << b
;
284 bitmap
[c
][o
] &= ~(1 << b
);