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_inode_cachep __read_mostly
;
25 struct kmem_cache
*gfs2_bufdata_cachep __read_mostly
;
26 struct kmem_cache
*gfs2_rgrpd_cachep __read_mostly
;
27 struct kmem_cache
*gfs2_quotad_cachep __read_mostly
;
29 void gfs2_assert_i(struct gfs2_sbd
*sdp
)
31 printk(KERN_EMERG
"GFS2: fsid=%s: fatal assertion failed\n",
35 int gfs2_lm_withdraw(struct gfs2_sbd
*sdp
, char *fmt
, ...)
37 struct lm_lockstruct
*ls
= &sdp
->sd_lockstruct
;
38 const struct lm_lockops
*lm
= ls
->ls_ops
;
41 if (test_and_set_bit(SDF_SHUTDOWN
, &sdp
->sd_flags
))
48 fs_err(sdp
, "about to withdraw this file system\n");
49 BUG_ON(sdp
->sd_args
.ar_debug
);
51 kobject_uevent(&sdp
->sd_kobj
, KOBJ_OFFLINE
);
54 fs_err(sdp
, "telling LM to unmount\n");
57 fs_err(sdp
, "withdrawn\n");
64 * gfs2_assert_withdraw_i - Cause the machine to withdraw if @assertion is false
65 * Returns: -1 if this call withdrew the machine,
66 * -2 if it was already withdrawn
69 int gfs2_assert_withdraw_i(struct gfs2_sbd
*sdp
, char *assertion
,
70 const char *function
, char *file
, unsigned int line
)
73 me
= gfs2_lm_withdraw(sdp
,
74 "GFS2: fsid=%s: fatal: assertion \"%s\" failed\n"
75 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
76 sdp
->sd_fsname
, assertion
,
77 sdp
->sd_fsname
, function
, file
, line
);
79 return (me
) ? -1 : -2;
83 * gfs2_assert_warn_i - Print a message to the console if @assertion is false
84 * Returns: -1 if we printed something
88 int gfs2_assert_warn_i(struct gfs2_sbd
*sdp
, char *assertion
,
89 const char *function
, char *file
, unsigned int line
)
91 if (time_before(jiffies
,
92 sdp
->sd_last_warning
+
93 gfs2_tune_get(sdp
, gt_complain_secs
) * HZ
))
97 "GFS2: fsid=%s: warning: assertion \"%s\" failed\n"
98 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
99 sdp
->sd_fsname
, assertion
,
100 sdp
->sd_fsname
, function
, file
, line
);
102 if (sdp
->sd_args
.ar_debug
)
107 sdp
->sd_last_warning
= jiffies
;
113 * gfs2_consist_i - Flag a filesystem consistency error and withdraw
114 * Returns: -1 if this call withdrew the machine,
115 * 0 if it was already withdrawn
118 int gfs2_consist_i(struct gfs2_sbd
*sdp
, int cluster_wide
, const char *function
,
119 char *file
, unsigned int line
)
122 rv
= gfs2_lm_withdraw(sdp
,
123 "GFS2: fsid=%s: fatal: filesystem consistency error\n"
124 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
126 sdp
->sd_fsname
, function
, file
, line
);
131 * gfs2_consist_inode_i - Flag an inode consistency error and withdraw
132 * Returns: -1 if this call withdrew the machine,
133 * 0 if it was already withdrawn
136 int gfs2_consist_inode_i(struct gfs2_inode
*ip
, int cluster_wide
,
137 const char *function
, char *file
, unsigned int line
)
139 struct gfs2_sbd
*sdp
= GFS2_SB(&ip
->i_inode
);
141 rv
= gfs2_lm_withdraw(sdp
,
142 "GFS2: fsid=%s: fatal: filesystem consistency error\n"
143 "GFS2: fsid=%s: inode = %llu %llu\n"
144 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
146 sdp
->sd_fsname
, (unsigned long long)ip
->i_no_formal_ino
,
147 (unsigned long long)ip
->i_no_addr
,
148 sdp
->sd_fsname
, function
, file
, line
);
153 * gfs2_consist_rgrpd_i - Flag a RG consistency error and withdraw
154 * Returns: -1 if this call withdrew the machine,
155 * 0 if it was already withdrawn
158 int gfs2_consist_rgrpd_i(struct gfs2_rgrpd
*rgd
, int cluster_wide
,
159 const char *function
, char *file
, unsigned int line
)
161 struct gfs2_sbd
*sdp
= rgd
->rd_sbd
;
163 rv
= gfs2_lm_withdraw(sdp
,
164 "GFS2: fsid=%s: fatal: filesystem consistency error\n"
165 "GFS2: fsid=%s: RG = %llu\n"
166 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
168 sdp
->sd_fsname
, (unsigned long long)rgd
->rd_addr
,
169 sdp
->sd_fsname
, function
, file
, line
);
174 * gfs2_meta_check_ii - Flag a magic number consistency error and withdraw
175 * Returns: -1 if this call withdrew the machine,
176 * -2 if it was already withdrawn
179 int gfs2_meta_check_ii(struct gfs2_sbd
*sdp
, struct buffer_head
*bh
,
180 const char *type
, const char *function
, char *file
,
184 me
= gfs2_lm_withdraw(sdp
,
185 "GFS2: fsid=%s: fatal: invalid metadata block\n"
186 "GFS2: fsid=%s: bh = %llu (%s)\n"
187 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
189 sdp
->sd_fsname
, (unsigned long long)bh
->b_blocknr
, type
,
190 sdp
->sd_fsname
, function
, file
, line
);
191 return (me
) ? -1 : -2;
195 * gfs2_metatype_check_ii - Flag a metadata type consistency error and withdraw
196 * Returns: -1 if this call withdrew the machine,
197 * -2 if it was already withdrawn
200 int gfs2_metatype_check_ii(struct gfs2_sbd
*sdp
, struct buffer_head
*bh
,
201 u16 type
, u16 t
, const char *function
,
202 char *file
, unsigned int line
)
205 me
= gfs2_lm_withdraw(sdp
,
206 "GFS2: fsid=%s: fatal: invalid metadata block\n"
207 "GFS2: fsid=%s: bh = %llu (type: exp=%u, found=%u)\n"
208 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
210 sdp
->sd_fsname
, (unsigned long long)bh
->b_blocknr
, type
, t
,
211 sdp
->sd_fsname
, function
, file
, line
);
212 return (me
) ? -1 : -2;
216 * gfs2_io_error_i - Flag an I/O error and withdraw
217 * Returns: -1 if this call withdrew the machine,
218 * 0 if it was already withdrawn
221 int gfs2_io_error_i(struct gfs2_sbd
*sdp
, const char *function
, char *file
,
225 rv
= gfs2_lm_withdraw(sdp
,
226 "GFS2: fsid=%s: fatal: I/O error\n"
227 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
229 sdp
->sd_fsname
, function
, file
, line
);
234 * gfs2_io_error_bh_i - Flag a buffer I/O error and withdraw
235 * Returns: -1 if this call withdrew the machine,
236 * 0 if it was already withdrawn
239 int gfs2_io_error_bh_i(struct gfs2_sbd
*sdp
, struct buffer_head
*bh
,
240 const char *function
, char *file
, unsigned int line
)
243 rv
= gfs2_lm_withdraw(sdp
,
244 "GFS2: fsid=%s: fatal: I/O error\n"
245 "GFS2: fsid=%s: block = %llu\n"
246 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
248 sdp
->sd_fsname
, (unsigned long long)bh
->b_blocknr
,
249 sdp
->sd_fsname
, function
, file
, line
);
253 void gfs2_icbit_munge(struct gfs2_sbd
*sdp
, unsigned char **bitmap
,
254 unsigned int bit
, int new_value
)
256 unsigned int c
, o
, b
= bit
;
259 c
= b
/ (8 * PAGE_SIZE
);
264 old_value
= (bitmap
[c
][o
] & (1 << b
));
265 gfs2_assert_withdraw(sdp
, !old_value
!= !new_value
);
268 bitmap
[c
][o
] |= 1 << b
;
270 bitmap
[c
][o
] &= ~(1 << b
);