[PATCH] Use 32 bit division in slab_put_obj()
[linux-2.6.22.y-op.git] / fs / xfs / xfs_error.c
blob2a21c5024017374960c40efcfd02a4488d9735b6
1 /*
2 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 #include "xfs.h"
19 #include "xfs_fs.h"
20 #include "xfs_types.h"
21 #include "xfs_log.h"
22 #include "xfs_inum.h"
23 #include "xfs_trans.h"
24 #include "xfs_sb.h"
25 #include "xfs_dir.h"
26 #include "xfs_dir2.h"
27 #include "xfs_dmapi.h"
28 #include "xfs_mount.h"
29 #include "xfs_bmap_btree.h"
30 #include "xfs_dir_sf.h"
31 #include "xfs_dir2_sf.h"
32 #include "xfs_attr_sf.h"
33 #include "xfs_dinode.h"
34 #include "xfs_inode.h"
35 #include "xfs_utils.h"
36 #include "xfs_error.h"
38 #ifdef DEBUG
40 int xfs_etrap[XFS_ERROR_NTRAP] = {
44 int
45 xfs_error_trap(int e)
47 int i;
49 if (!e)
50 return 0;
51 for (i = 0; i < XFS_ERROR_NTRAP; i++) {
52 if (xfs_etrap[i] == 0)
53 break;
54 if (e != xfs_etrap[i])
55 continue;
56 cmn_err(CE_NOTE, "xfs_error_trap: error %d", e);
57 BUG();
58 break;
60 return e;
62 #endif
64 #if (defined(DEBUG) || defined(INDUCE_IO_ERROR))
66 int xfs_etest[XFS_NUM_INJECT_ERROR];
67 int64_t xfs_etest_fsid[XFS_NUM_INJECT_ERROR];
68 char * xfs_etest_fsname[XFS_NUM_INJECT_ERROR];
70 void
71 xfs_error_test_init(void)
73 memset(xfs_etest, 0, sizeof(xfs_etest));
74 memset(xfs_etest_fsid, 0, sizeof(xfs_etest_fsid));
75 memset(xfs_etest_fsname, 0, sizeof(xfs_etest_fsname));
78 int
79 xfs_error_test(int error_tag, int *fsidp, char *expression,
80 int line, char *file, unsigned long randfactor)
82 int i;
83 int64_t fsid;
85 if (random() % randfactor)
86 return 0;
88 memcpy(&fsid, fsidp, sizeof(xfs_fsid_t));
90 for (i = 0; i < XFS_NUM_INJECT_ERROR; i++) {
91 if (xfs_etest[i] == error_tag && xfs_etest_fsid[i] == fsid) {
92 cmn_err(CE_WARN,
93 "Injecting error (%s) at file %s, line %d, on filesystem \"%s\"",
94 expression, file, line, xfs_etest_fsname[i]);
95 return 1;
99 return 0;
103 xfs_errortag_add(int error_tag, xfs_mount_t *mp)
105 int i;
106 int len;
107 int64_t fsid;
109 memcpy(&fsid, mp->m_fixedfsid, sizeof(xfs_fsid_t));
111 for (i = 0; i < XFS_NUM_INJECT_ERROR; i++) {
112 if (xfs_etest_fsid[i] == fsid && xfs_etest[i] == error_tag) {
113 cmn_err(CE_WARN, "XFS error tag #%d on", error_tag);
114 return 0;
118 for (i = 0; i < XFS_NUM_INJECT_ERROR; i++) {
119 if (xfs_etest[i] == 0) {
120 cmn_err(CE_WARN, "Turned on XFS error tag #%d",
121 error_tag);
122 xfs_etest[i] = error_tag;
123 xfs_etest_fsid[i] = fsid;
124 len = strlen(mp->m_fsname);
125 xfs_etest_fsname[i] = kmem_alloc(len + 1, KM_SLEEP);
126 strcpy(xfs_etest_fsname[i], mp->m_fsname);
127 return 0;
131 cmn_err(CE_WARN, "error tag overflow, too many turned on");
133 return 1;
137 xfs_errortag_clear(int error_tag, xfs_mount_t *mp)
139 int i;
140 int64_t fsid;
142 memcpy(&fsid, mp->m_fixedfsid, sizeof(xfs_fsid_t));
144 for (i = 0; i < XFS_NUM_INJECT_ERROR; i++) {
145 if (xfs_etest_fsid[i] == fsid && xfs_etest[i] == error_tag) {
146 xfs_etest[i] = 0;
147 xfs_etest_fsid[i] = 0LL;
148 kmem_free(xfs_etest_fsname[i],
149 strlen(xfs_etest_fsname[i]) + 1);
150 xfs_etest_fsname[i] = NULL;
151 cmn_err(CE_WARN, "Cleared XFS error tag #%d",
152 error_tag);
153 return 0;
157 cmn_err(CE_WARN, "XFS error tag %d not on", error_tag);
159 return 1;
163 xfs_errortag_clearall_umount(int64_t fsid, char *fsname, int loud)
165 int i;
166 int cleared = 0;
168 for (i = 0; i < XFS_NUM_INJECT_ERROR; i++) {
169 if ((fsid == 0LL || xfs_etest_fsid[i] == fsid) &&
170 xfs_etest[i] != 0) {
171 cleared = 1;
172 cmn_err(CE_WARN, "Clearing XFS error tag #%d",
173 xfs_etest[i]);
174 xfs_etest[i] = 0;
175 xfs_etest_fsid[i] = 0LL;
176 kmem_free(xfs_etest_fsname[i],
177 strlen(xfs_etest_fsname[i]) + 1);
178 xfs_etest_fsname[i] = NULL;
182 if (loud || cleared)
183 cmn_err(CE_WARN,
184 "Cleared all XFS error tags for filesystem \"%s\"",
185 fsname);
187 return 0;
191 xfs_errortag_clearall(xfs_mount_t *mp)
193 int64_t fsid;
195 memcpy(&fsid, mp->m_fixedfsid, sizeof(xfs_fsid_t));
197 return xfs_errortag_clearall_umount(fsid, mp->m_fsname, 1);
199 #endif /* DEBUG || INDUCE_IO_ERROR */
201 static void
202 xfs_fs_vcmn_err(int level, xfs_mount_t *mp, char *fmt, va_list ap)
204 if (mp != NULL) {
205 char *newfmt;
206 int len = 16 + mp->m_fsname_len + strlen(fmt);
208 newfmt = kmem_alloc(len, KM_SLEEP);
209 sprintf(newfmt, "Filesystem \"%s\": %s", mp->m_fsname, fmt);
210 icmn_err(level, newfmt, ap);
211 kmem_free(newfmt, len);
212 } else {
213 icmn_err(level, fmt, ap);
217 void
218 xfs_fs_cmn_err(int level, xfs_mount_t *mp, char *fmt, ...)
220 va_list ap;
222 va_start(ap, fmt);
223 xfs_fs_vcmn_err(level, mp, fmt, ap);
224 va_end(ap);
227 void
228 xfs_cmn_err(int panic_tag, int level, xfs_mount_t *mp, char *fmt, ...)
230 va_list ap;
232 #ifdef DEBUG
233 xfs_panic_mask |= XFS_PTAG_SHUTDOWN_CORRUPT;
234 #endif
236 if (xfs_panic_mask && (xfs_panic_mask & panic_tag)
237 && (level & CE_ALERT)) {
238 level &= ~CE_ALERT;
239 level |= CE_PANIC;
240 cmn_err(CE_ALERT, "XFS: Transforming an alert into a BUG.");
242 va_start(ap, fmt);
243 xfs_fs_vcmn_err(level, mp, fmt, ap);
244 va_end(ap);
247 void
248 xfs_error_report(
249 char *tag,
250 int level,
251 xfs_mount_t *mp,
252 char *fname,
253 int linenum,
254 inst_t *ra)
256 if (level <= xfs_error_level) {
257 xfs_cmn_err(XFS_PTAG_ERROR_REPORT,
258 CE_ALERT, mp,
259 "XFS internal error %s at line %d of file %s. Caller 0x%p\n",
260 tag, linenum, fname, ra);
262 xfs_stack_trace();
266 STATIC void
267 xfs_hex_dump(void *p, int length)
269 __uint8_t *uip = (__uint8_t*)p;
270 int i;
271 char sbuf[128], *s;
273 s = sbuf;
274 *s = '\0';
275 for (i=0; i<length; i++, uip++) {
276 if ((i % 16) == 0) {
277 if (*s != '\0')
278 cmn_err(CE_ALERT, "%s\n", sbuf);
279 s = sbuf;
280 sprintf(s, "0x%x: ", i);
281 while( *s != '\0')
282 s++;
284 sprintf(s, "%02x ", *uip);
287 * the kernel sprintf is a void; user sprintf returns
288 * the sprintf'ed string's length. Find the new end-
289 * of-string
291 while( *s != '\0')
292 s++;
294 cmn_err(CE_ALERT, "%s\n", sbuf);
297 void
298 xfs_corruption_error(
299 char *tag,
300 int level,
301 xfs_mount_t *mp,
302 void *p,
303 char *fname,
304 int linenum,
305 inst_t *ra)
307 if (level <= xfs_error_level)
308 xfs_hex_dump(p, 16);
309 xfs_error_report(tag, level, mp, fname, linenum, ra);