2 * Copyright (c) 2000-2001 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
34 #include "xfs_types.h"
37 #include "xfs_trans.h"
41 #include "xfs_dmapi.h"
42 #include "xfs_mount.h"
43 #include "xfs_bmap_btree.h"
44 #include "xfs_dir_sf.h"
45 #include "xfs_dir2_sf.h"
46 #include "xfs_attr_sf.h"
47 #include "xfs_dinode.h"
48 #include "xfs_inode.h"
49 #include "xfs_utils.h"
50 #include "xfs_error.h"
54 int xfs_etrap[XFS_ERROR_NTRAP] = {
65 for (i = 0; i < XFS_ERROR_NTRAP; i++) {
66 if (xfs_etrap[i] == 0)
68 if (e != xfs_etrap[i])
70 cmn_err(CE_NOTE, "xfs_error_trap: error %d", e);
71 debug_stop_all_cpus((void *)-1LL);
79 #if (defined(DEBUG) || defined(INDUCE_IO_ERROR))
81 int xfs_etest[XFS_NUM_INJECT_ERROR];
82 int64_t xfs_etest_fsid[XFS_NUM_INJECT_ERROR];
83 char * xfs_etest_fsname[XFS_NUM_INJECT_ERROR];
86 xfs_error_test_init(void)
88 memset(xfs_etest, 0, sizeof(xfs_etest));
89 memset(xfs_etest_fsid, 0, sizeof(xfs_etest_fsid));
90 memset(xfs_etest_fsname, 0, sizeof(xfs_etest_fsname));
94 xfs_error_test(int error_tag, int *fsidp, char *expression,
95 int line, char *file, unsigned long randfactor)
100 if (random() % randfactor)
103 memcpy(&fsid, fsidp, sizeof(xfs_fsid_t));
105 for (i = 0; i < XFS_NUM_INJECT_ERROR; i++) {
106 if (xfs_etest[i] == error_tag && xfs_etest_fsid[i] == fsid) {
108 "Injecting error (%s) at file %s, line %d, on filesystem \"%s\"",
109 expression, file, line, xfs_etest_fsname[i]);
118 xfs_errortag_add(int error_tag, xfs_mount_t *mp)
124 memcpy(&fsid, mp->m_fixedfsid, sizeof(xfs_fsid_t));
126 for (i = 0; i < XFS_NUM_INJECT_ERROR; i++) {
127 if (xfs_etest_fsid[i] == fsid && xfs_etest[i] == error_tag) {
128 cmn_err(CE_WARN, "XFS error tag #%d on", error_tag);
133 for (i = 0; i < XFS_NUM_INJECT_ERROR; i++) {
134 if (xfs_etest[i] == 0) {
135 cmn_err(CE_WARN, "Turned on XFS error tag #%d",
137 xfs_etest[i] = error_tag;
138 xfs_etest_fsid[i] = fsid;
139 len = strlen(mp->m_fsname);
140 xfs_etest_fsname[i] = kmem_alloc(len + 1, KM_SLEEP);
141 strcpy(xfs_etest_fsname[i], mp->m_fsname);
146 cmn_err(CE_WARN, "error tag overflow, too many turned on");
152 xfs_errortag_clear(int error_tag, xfs_mount_t *mp)
157 memcpy(&fsid, mp->m_fixedfsid, sizeof(xfs_fsid_t));
159 for (i = 0; i < XFS_NUM_INJECT_ERROR; i++) {
160 if (xfs_etest_fsid[i] == fsid && xfs_etest[i] == error_tag) {
162 xfs_etest_fsid[i] = 0LL;
163 kmem_free(xfs_etest_fsname[i],
164 strlen(xfs_etest_fsname[i]) + 1);
165 xfs_etest_fsname[i] = NULL;
166 cmn_err(CE_WARN, "Cleared XFS error tag #%d",
172 cmn_err(CE_WARN, "XFS error tag %d not on", error_tag);
178 xfs_errortag_clearall_umount(int64_t fsid, char *fsname, int loud)
183 for (i = 0; i < XFS_NUM_INJECT_ERROR; i++) {
184 if ((fsid == 0LL || xfs_etest_fsid[i] == fsid) &&
187 cmn_err(CE_WARN, "Clearing XFS error tag #%d",
190 xfs_etest_fsid[i] = 0LL;
191 kmem_free(xfs_etest_fsname[i],
192 strlen(xfs_etest_fsname[i]) + 1);
193 xfs_etest_fsname[i] = NULL;
199 "Cleared all XFS error tags for filesystem \"%s\"",
206 xfs_errortag_clearall(xfs_mount_t *mp)
210 memcpy(&fsid, mp->m_fixedfsid, sizeof(xfs_fsid_t));
212 return xfs_errortag_clearall_umount(fsid, mp->m_fsname, 1);
214 #endif /* DEBUG || INDUCE_IO_ERROR */
217 xfs_fs_vcmn_err(int level, xfs_mount_t *mp, char *fmt, va_list ap)
221 int len = 16 + mp->m_fsname_len + strlen(fmt);
223 newfmt = kmem_alloc(len, KM_SLEEP);
224 sprintf(newfmt, "Filesystem \"%s\": %s", mp->m_fsname, fmt);
225 icmn_err(level, newfmt, ap);
226 kmem_free(newfmt, len);
228 icmn_err(level, fmt, ap);
233 xfs_fs_cmn_err(int level, xfs_mount_t *mp, char *fmt, ...)
238 xfs_fs_vcmn_err(level, mp, fmt, ap);
243 xfs_cmn_err(int panic_tag, int level, xfs_mount_t *mp, char *fmt, ...)
248 xfs_panic_mask |= XFS_PTAG_SHUTDOWN_CORRUPT;
251 if (xfs_panic_mask && (xfs_panic_mask & panic_tag)
252 && (level & CE_ALERT)) {
255 cmn_err(CE_ALERT, "XFS: Transforming an alert into a BUG.");
258 xfs_fs_vcmn_err(level, mp, fmt, ap);
271 if (level <= xfs_error_level) {
272 xfs_cmn_err(XFS_PTAG_ERROR_REPORT,
274 "XFS internal error %s at line %d of file %s. Caller 0x%p\n",
275 tag, linenum, fname, ra);
282 xfs_hex_dump(void *p, int length)
284 __uint8_t *uip = (__uint8_t*)p;
290 for (i=0; i<length; i++, uip++) {
293 cmn_err(CE_ALERT, "%s\n", sbuf);
295 sprintf(s, "0x%x: ", i);
299 sprintf(s, "%02x ", *uip);
302 * the kernel sprintf is a void; user sprintf returns
303 * the sprintf'ed string's length. Find the new end-
309 cmn_err(CE_ALERT, "%s\n", sbuf);
313 xfs_corruption_error(
322 if (level <= xfs_error_level)
324 xfs_error_report(tag, level, mp, fname, linenum, ra);