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/
35 #include "xfs_macros.h"
36 #include "xfs_types.h"
40 #include "xfs_trans.h"
43 #include "xfs_dmapi.h"
44 #include "xfs_mount.h"
45 #include "xfs_bmap_btree.h"
46 #include "xfs_attr_sf.h"
47 #include "xfs_dir_sf.h"
48 #include "xfs_dir2_sf.h"
49 #include "xfs_dinode.h"
50 #include "xfs_inode.h"
51 #include "xfs_utils.h"
52 #include "xfs_error.h"
56 int xfs_etrap[XFS_ERROR_NTRAP] = {
67 for (i = 0; i < XFS_ERROR_NTRAP; i++) {
68 if (xfs_etrap[i] == 0)
70 if (e != xfs_etrap[i])
72 cmn_err(CE_NOTE, "xfs_error_trap: error %d", e);
73 debug_stop_all_cpus((void *)-1LL);
81 #if (defined(DEBUG) || defined(INDUCE_IO_ERROR))
83 int xfs_etest[XFS_NUM_INJECT_ERROR];
84 int64_t xfs_etest_fsid[XFS_NUM_INJECT_ERROR];
85 char * xfs_etest_fsname[XFS_NUM_INJECT_ERROR];
88 xfs_error_test_init(void)
90 memset(xfs_etest, 0, sizeof(xfs_etest));
91 memset(xfs_etest_fsid, 0, sizeof(xfs_etest_fsid));
92 memset(xfs_etest_fsname, 0, sizeof(xfs_etest_fsname));
96 xfs_error_test(int error_tag, int *fsidp, char *expression,
97 int line, char *file, unsigned long randfactor)
102 if (random() % randfactor)
105 memcpy(&fsid, fsidp, sizeof(xfs_fsid_t));
107 for (i = 0; i < XFS_NUM_INJECT_ERROR; i++) {
108 if (xfs_etest[i] == error_tag && xfs_etest_fsid[i] == fsid) {
110 "Injecting error (%s) at file %s, line %d, on filesystem \"%s\"",
111 expression, file, line, xfs_etest_fsname[i]);
120 xfs_errortag_add(int error_tag, xfs_mount_t *mp)
126 memcpy(&fsid, mp->m_fixedfsid, sizeof(xfs_fsid_t));
128 for (i = 0; i < XFS_NUM_INJECT_ERROR; i++) {
129 if (xfs_etest_fsid[i] == fsid && xfs_etest[i] == error_tag) {
130 cmn_err(CE_WARN, "XFS error tag #%d on", error_tag);
135 for (i = 0; i < XFS_NUM_INJECT_ERROR; i++) {
136 if (xfs_etest[i] == 0) {
137 cmn_err(CE_WARN, "Turned on XFS error tag #%d",
139 xfs_etest[i] = error_tag;
140 xfs_etest_fsid[i] = fsid;
141 len = strlen(mp->m_fsname);
142 xfs_etest_fsname[i] = kmem_alloc(len + 1, KM_SLEEP);
143 strcpy(xfs_etest_fsname[i], mp->m_fsname);
148 cmn_err(CE_WARN, "error tag overflow, too many turned on");
154 xfs_errortag_clear(int error_tag, xfs_mount_t *mp)
159 memcpy(&fsid, mp->m_fixedfsid, sizeof(xfs_fsid_t));
161 for (i = 0; i < XFS_NUM_INJECT_ERROR; i++) {
162 if (xfs_etest_fsid[i] == fsid && xfs_etest[i] == error_tag) {
164 xfs_etest_fsid[i] = 0LL;
165 kmem_free(xfs_etest_fsname[i],
166 strlen(xfs_etest_fsname[i]) + 1);
167 xfs_etest_fsname[i] = NULL;
168 cmn_err(CE_WARN, "Cleared XFS error tag #%d",
174 cmn_err(CE_WARN, "XFS error tag %d not on", error_tag);
180 xfs_errortag_clearall_umount(int64_t fsid, char *fsname, int loud)
185 for (i = 0; i < XFS_NUM_INJECT_ERROR; i++) {
186 if ((fsid == 0LL || xfs_etest_fsid[i] == fsid) &&
189 cmn_err(CE_WARN, "Clearing XFS error tag #%d",
192 xfs_etest_fsid[i] = 0LL;
193 kmem_free(xfs_etest_fsname[i],
194 strlen(xfs_etest_fsname[i]) + 1);
195 xfs_etest_fsname[i] = NULL;
201 "Cleared all XFS error tags for filesystem \"%s\"",
208 xfs_errortag_clearall(xfs_mount_t *mp)
212 memcpy(&fsid, mp->m_fixedfsid, sizeof(xfs_fsid_t));
214 return xfs_errortag_clearall_umount(fsid, mp->m_fsname, 1);
216 #endif /* DEBUG || INDUCE_IO_ERROR */
219 xfs_fs_vcmn_err(int level, xfs_mount_t *mp, char *fmt, va_list ap)
223 int len = 16 + mp->m_fsname_len + strlen(fmt);
225 newfmt = kmem_alloc(len, KM_SLEEP);
226 sprintf(newfmt, "Filesystem \"%s\": %s", mp->m_fsname, fmt);
227 icmn_err(level, newfmt, ap);
228 kmem_free(newfmt, len);
230 icmn_err(level, fmt, ap);
235 xfs_fs_cmn_err(int level, xfs_mount_t *mp, char *fmt, ...)
240 xfs_fs_vcmn_err(level, mp, fmt, ap);
245 xfs_cmn_err(int panic_tag, int level, xfs_mount_t *mp, char *fmt, ...)
250 xfs_panic_mask |= XFS_PTAG_SHUTDOWN_CORRUPT;
253 if (xfs_panic_mask && (xfs_panic_mask & panic_tag)
254 && (level & CE_ALERT)) {
257 cmn_err(CE_ALERT, "XFS: Transforming an alert into a BUG.");
260 xfs_fs_vcmn_err(level, mp, fmt, ap);
273 if (level <= xfs_error_level) {
274 xfs_cmn_err(XFS_PTAG_ERROR_REPORT,
276 "XFS internal error %s at line %d of file %s. Caller 0x%p\n",
277 tag, linenum, fname, ra);
284 xfs_hex_dump(void *p, int length)
286 __uint8_t *uip = (__uint8_t*)p;
292 for (i=0; i<length; i++, uip++) {
295 cmn_err(CE_ALERT, "%s\n", sbuf);
297 sprintf(s, "0x%x: ", i);
301 sprintf(s, "%02x ", *uip);
304 * the kernel sprintf is a void; user sprintf returns
305 * the sprintf'ed string's length. Find the new end-
311 cmn_err(CE_ALERT, "%s\n", sbuf);
315 xfs_corruption_error(
324 if (level <= xfs_error_level)
326 xfs_error_report(tag, level, mp, fname, linenum, ra);