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 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
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/uaccess.h>
25 struct kmem_cache
*gfs2_glock_cachep __read_mostly
;
26 struct kmem_cache
*gfs2_glock_aspace_cachep __read_mostly
;
27 struct kmem_cache
*gfs2_inode_cachep __read_mostly
;
28 struct kmem_cache
*gfs2_bufdata_cachep __read_mostly
;
29 struct kmem_cache
*gfs2_rgrpd_cachep __read_mostly
;
30 struct kmem_cache
*gfs2_quotad_cachep __read_mostly
;
31 struct kmem_cache
*gfs2_qadata_cachep __read_mostly
;
32 mempool_t
*gfs2_page_pool __read_mostly
;
34 void gfs2_assert_i(struct gfs2_sbd
*sdp
)
36 fs_emerg(sdp
, "fatal assertion failed\n");
39 int gfs2_lm_withdraw(struct gfs2_sbd
*sdp
, const char *fmt
, ...)
41 struct lm_lockstruct
*ls
= &sdp
->sd_lockstruct
;
42 const struct lm_lockops
*lm
= ls
->ls_ops
;
46 if (sdp
->sd_args
.ar_errors
== GFS2_ERRORS_WITHDRAW
&&
47 test_and_set_bit(SDF_SHUTDOWN
, &sdp
->sd_flags
))
56 fs_err(sdp
, "%pV", &vaf
);
61 if (sdp
->sd_args
.ar_errors
== GFS2_ERRORS_WITHDRAW
) {
62 fs_err(sdp
, "about to withdraw this file system\n");
63 BUG_ON(sdp
->sd_args
.ar_debug
);
65 kobject_uevent(&sdp
->sd_kobj
, KOBJ_OFFLINE
);
67 if (!strcmp(sdp
->sd_lockstruct
.ls_ops
->lm_proto_name
, "lock_dlm"))
68 wait_for_completion(&sdp
->sd_wdack
);
71 fs_err(sdp
, "telling LM to unmount\n");
74 set_bit(SDF_SKIP_DLM_UNLOCK
, &sdp
->sd_flags
);
75 fs_err(sdp
, "withdrawn\n");
79 if (sdp
->sd_args
.ar_errors
== GFS2_ERRORS_PANIC
)
80 panic("GFS2: fsid=%s: panic requested\n", sdp
->sd_fsname
);
86 * gfs2_assert_withdraw_i - Cause the machine to withdraw if @assertion is false
87 * Returns: -1 if this call withdrew the machine,
88 * -2 if it was already withdrawn
91 int gfs2_assert_withdraw_i(struct gfs2_sbd
*sdp
, char *assertion
,
92 const char *function
, char *file
, unsigned int line
)
95 me
= gfs2_lm_withdraw(sdp
,
96 "fatal: assertion \"%s\" failed\n"
97 " function = %s, file = %s, line = %u\n",
98 assertion
, function
, file
, line
);
100 return (me
) ? -1 : -2;
104 * gfs2_assert_warn_i - Print a message to the console if @assertion is false
105 * Returns: -1 if we printed something
109 int gfs2_assert_warn_i(struct gfs2_sbd
*sdp
, char *assertion
,
110 const char *function
, char *file
, unsigned int line
)
112 if (time_before(jiffies
,
113 sdp
->sd_last_warning
+
114 gfs2_tune_get(sdp
, gt_complain_secs
) * HZ
))
117 if (sdp
->sd_args
.ar_errors
== GFS2_ERRORS_WITHDRAW
)
118 fs_warn(sdp
, "warning: assertion \"%s\" failed at function = %s, file = %s, line = %u\n",
119 assertion
, function
, file
, line
);
121 if (sdp
->sd_args
.ar_debug
)
126 if (sdp
->sd_args
.ar_errors
== GFS2_ERRORS_PANIC
)
127 panic("GFS2: fsid=%s: warning: assertion \"%s\" failed\n"
128 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
129 sdp
->sd_fsname
, assertion
,
130 sdp
->sd_fsname
, function
, file
, line
);
132 sdp
->sd_last_warning
= jiffies
;
138 * gfs2_consist_i - Flag a filesystem consistency error and withdraw
139 * Returns: -1 if this call withdrew the machine,
140 * 0 if it was already withdrawn
143 int gfs2_consist_i(struct gfs2_sbd
*sdp
, int cluster_wide
, const char *function
,
144 char *file
, unsigned int line
)
147 rv
= gfs2_lm_withdraw(sdp
,
148 "fatal: filesystem consistency error - function = %s, file = %s, line = %u\n",
149 function
, file
, line
);
154 * gfs2_consist_inode_i - Flag an inode consistency error and withdraw
155 * Returns: -1 if this call withdrew the machine,
156 * 0 if it was already withdrawn
159 int gfs2_consist_inode_i(struct gfs2_inode
*ip
, int cluster_wide
,
160 const char *function
, char *file
, unsigned int line
)
162 struct gfs2_sbd
*sdp
= GFS2_SB(&ip
->i_inode
);
164 rv
= gfs2_lm_withdraw(sdp
,
165 "fatal: filesystem consistency error\n"
166 " inode = %llu %llu\n"
167 " function = %s, file = %s, line = %u\n",
168 (unsigned long long)ip
->i_no_formal_ino
,
169 (unsigned long long)ip
->i_no_addr
,
170 function
, file
, line
);
175 * gfs2_consist_rgrpd_i - Flag a RG consistency error and withdraw
176 * Returns: -1 if this call withdrew the machine,
177 * 0 if it was already withdrawn
180 int gfs2_consist_rgrpd_i(struct gfs2_rgrpd
*rgd
, int cluster_wide
,
181 const char *function
, char *file
, unsigned int line
)
183 struct gfs2_sbd
*sdp
= rgd
->rd_sbd
;
186 gfs2_rgrp_dump(NULL
, rgd
->rd_gl
);
187 rv
= gfs2_lm_withdraw(sdp
,
188 "fatal: filesystem consistency error\n"
190 " function = %s, file = %s, line = %u\n",
191 (unsigned long long)rgd
->rd_addr
,
192 function
, file
, line
);
197 * gfs2_meta_check_ii - Flag a magic number consistency error and withdraw
198 * Returns: -1 if this call withdrew the machine,
199 * -2 if it was already withdrawn
202 int gfs2_meta_check_ii(struct gfs2_sbd
*sdp
, struct buffer_head
*bh
,
203 const char *type
, const char *function
, char *file
,
207 me
= gfs2_lm_withdraw(sdp
,
208 "fatal: invalid metadata block\n"
210 " function = %s, file = %s, line = %u\n",
211 (unsigned long long)bh
->b_blocknr
, type
,
212 function
, file
, line
);
213 return (me
) ? -1 : -2;
217 * gfs2_metatype_check_ii - Flag a metadata type consistency error and withdraw
218 * Returns: -1 if this call withdrew the machine,
219 * -2 if it was already withdrawn
222 int gfs2_metatype_check_ii(struct gfs2_sbd
*sdp
, struct buffer_head
*bh
,
223 u16 type
, u16 t
, const char *function
,
224 char *file
, unsigned int line
)
227 me
= gfs2_lm_withdraw(sdp
,
228 "fatal: invalid metadata block\n"
229 " bh = %llu (type: exp=%u, found=%u)\n"
230 " function = %s, file = %s, line = %u\n",
231 (unsigned long long)bh
->b_blocknr
, type
, t
,
232 function
, file
, line
);
233 return (me
) ? -1 : -2;
237 * gfs2_io_error_i - Flag an I/O error and withdraw
238 * Returns: -1 if this call withdrew the machine,
239 * 0 if it was already withdrawn
242 int gfs2_io_error_i(struct gfs2_sbd
*sdp
, const char *function
, char *file
,
246 rv
= gfs2_lm_withdraw(sdp
,
248 " function = %s, file = %s, line = %u\n",
249 function
, file
, line
);
254 * gfs2_io_error_bh_i - Flag a buffer I/O error
255 * @withdraw: withdraw the filesystem
258 void gfs2_io_error_bh_i(struct gfs2_sbd
*sdp
, struct buffer_head
*bh
,
259 const char *function
, char *file
, unsigned int line
,
262 if (!test_bit(SDF_SHUTDOWN
, &sdp
->sd_flags
))
266 " function = %s, file = %s, line = %u\n",
267 (unsigned long long)bh
->b_blocknr
,
268 function
, file
, line
);
270 gfs2_lm_withdraw(sdp
, NULL
);