Blame view

fs/xfs/xfs_error.c 4.53 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
  /*
7b7187698   Nathan Scott   [XFS] Update lice...
2
3
   * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
   * All Rights Reserved.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
4
   *
7b7187698   Nathan Scott   [XFS] Update lice...
5
6
   * This program is free software; you can redistribute it and/or
   * modify it under the terms of the GNU General Public License as
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
7
8
   * published by the Free Software Foundation.
   *
7b7187698   Nathan Scott   [XFS] Update lice...
9
10
11
12
   * This program is distributed in the hope that it would be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
13
   *
7b7187698   Nathan Scott   [XFS] Update lice...
14
15
16
   * You should have received a copy of the GNU General Public License
   * along with this program; if not, write the Free Software Foundation,
   * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
17
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
18
  #include "xfs.h"
a844f4510   Nathan Scott   [XFS] Remove xfs_...
19
  #include "xfs_fs.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
20
  #include "xfs_types.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
21
  #include "xfs_log.h"
a844f4510   Nathan Scott   [XFS] Remove xfs_...
22
  #include "xfs_inum.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
23
  #include "xfs_trans.h"
a844f4510   Nathan Scott   [XFS] Remove xfs_...
24
  #include "xfs_sb.h"
da353b0d6   David Chinner   [XFS] Radix tree ...
25
  #include "xfs_ag.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
26
27
28
29
  #include "xfs_dir2.h"
  #include "xfs_dmapi.h"
  #include "xfs_mount.h"
  #include "xfs_bmap_btree.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
30
  #include "xfs_dir2_sf.h"
a844f4510   Nathan Scott   [XFS] Remove xfs_...
31
  #include "xfs_attr_sf.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
  #include "xfs_dinode.h"
  #include "xfs_inode.h"
  #include "xfs_utils.h"
  #include "xfs_error.h"
  
  #ifdef DEBUG
  
  int	xfs_etrap[XFS_ERROR_NTRAP] = {
  	0,
  };
  
  int
  xfs_error_trap(int e)
  {
  	int i;
  
  	if (!e)
  		return 0;
  	for (i = 0; i < XFS_ERROR_NTRAP; i++) {
  		if (xfs_etrap[i] == 0)
  			break;
  		if (e != xfs_etrap[i])
  			continue;
  		cmn_err(CE_NOTE, "xfs_error_trap: error %d", e);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
56
57
58
59
60
  		BUG();
  		break;
  	}
  	return e;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
61
62
63
64
  
  int	xfs_etest[XFS_NUM_INJECT_ERROR];
  int64_t	xfs_etest_fsid[XFS_NUM_INJECT_ERROR];
  char *	xfs_etest_fsname[XFS_NUM_INJECT_ERROR];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
65
66
67
68
69
70
  int
  xfs_error_test(int error_tag, int *fsidp, char *expression,
  	       int line, char *file, unsigned long randfactor)
  {
  	int i;
  	int64_t fsid;
e7a23a9b3   Joe Perches   [XFS] reducing th...
71
  	if (random32() % randfactor)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
  		return 0;
  
  	memcpy(&fsid, fsidp, sizeof(xfs_fsid_t));
  
  	for (i = 0; i < XFS_NUM_INJECT_ERROR; i++)  {
  		if (xfs_etest[i] == error_tag && xfs_etest_fsid[i] == fsid) {
  			cmn_err(CE_WARN,
  	"Injecting error (%s) at file %s, line %d, on filesystem \"%s\"",
  				expression, file, line, xfs_etest_fsname[i]);
  			return 1;
  		}
  	}
  
  	return 0;
  }
  
  int
  xfs_errortag_add(int error_tag, xfs_mount_t *mp)
  {
  	int i;
  	int len;
  	int64_t fsid;
  
  	memcpy(&fsid, mp->m_fixedfsid, sizeof(xfs_fsid_t));
  
  	for (i = 0; i < XFS_NUM_INJECT_ERROR; i++)  {
  		if (xfs_etest_fsid[i] == fsid && xfs_etest[i] == error_tag) {
  			cmn_err(CE_WARN, "XFS error tag #%d on", error_tag);
  			return 0;
  		}
  	}
  
  	for (i = 0; i < XFS_NUM_INJECT_ERROR; i++)  {
  		if (xfs_etest[i] == 0) {
  			cmn_err(CE_WARN, "Turned on XFS error tag #%d",
  				error_tag);
  			xfs_etest[i] = error_tag;
  			xfs_etest_fsid[i] = fsid;
  			len = strlen(mp->m_fsname);
  			xfs_etest_fsname[i] = kmem_alloc(len + 1, KM_SLEEP);
  			strcpy(xfs_etest_fsname[i], mp->m_fsname);
  			return 0;
  		}
  	}
  
  	cmn_err(CE_WARN, "error tag overflow, too many turned on");
  
  	return 1;
  }
  
  int
0ce4cfd4f   Christoph Hellwig   [XFS] kill the vf...
123
  xfs_errortag_clearall(xfs_mount_t *mp, int loud)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
124
  {
0ce4cfd4f   Christoph Hellwig   [XFS] kill the vf...
125
  	int64_t fsid;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
126
  	int cleared = 0;
0ce4cfd4f   Christoph Hellwig   [XFS] kill the vf...
127
128
129
  	int i;
  
  	memcpy(&fsid, mp->m_fixedfsid, sizeof(xfs_fsid_t));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
130
131
132
133
134
135
136
137
138
  
  	for (i = 0; i < XFS_NUM_INJECT_ERROR; i++) {
  		if ((fsid == 0LL || xfs_etest_fsid[i] == fsid) &&
  		     xfs_etest[i] != 0) {
  			cleared = 1;
  			cmn_err(CE_WARN, "Clearing XFS error tag #%d",
  				xfs_etest[i]);
  			xfs_etest[i] = 0;
  			xfs_etest_fsid[i] = 0LL;
f0e2d93c2   Denys Vlasenko   [XFS] Remove unus...
139
  			kmem_free(xfs_etest_fsname[i]);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
140
141
142
143
144
145
146
  			xfs_etest_fsname[i] = NULL;
  		}
  	}
  
  	if (loud || cleared)
  		cmn_err(CE_WARN,
  			"Cleared all XFS error tags for filesystem \"%s\"",
0ce4cfd4f   Christoph Hellwig   [XFS] kill the vf...
147
  			mp->m_fsname);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
148
149
150
  
  	return 0;
  }
1550d0b0b   Christoph Hellwig   [XFS] kill INDUCE...
151
  #endif /* DEBUG */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
152

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
  
  void
  xfs_fs_cmn_err(int level, xfs_mount_t *mp, char *fmt, ...)
  {
  	va_list ap;
  
  	va_start(ap, fmt);
  	xfs_fs_vcmn_err(level, mp, fmt, ap);
  	va_end(ap);
  }
  
  void
  xfs_cmn_err(int panic_tag, int level, xfs_mount_t *mp, char *fmt, ...)
  {
  	va_list ap;
  
  #ifdef DEBUG
  	xfs_panic_mask |= XFS_PTAG_SHUTDOWN_CORRUPT;
  #endif
  
  	if (xfs_panic_mask && (xfs_panic_mask & panic_tag)
  	    && (level & CE_ALERT)) {
  		level &= ~CE_ALERT;
  		level |= CE_PANIC;
  		cmn_err(CE_ALERT, "XFS: Transforming an alert into a BUG.");
  	}
  	va_start(ap, fmt);
  	xfs_fs_vcmn_err(level, mp, fmt, ap);
  	va_end(ap);
  }
  
  void
  xfs_error_report(
  	char		*tag,
  	int		level,
  	xfs_mount_t	*mp,
  	char		*fname,
  	int		linenum,
  	inst_t		*ra)
  {
  	if (level <= xfs_error_level) {
  		xfs_cmn_err(XFS_PTAG_ERROR_REPORT,
  			    CE_ALERT, mp,
  		"XFS internal error %s at line %d of file %s.  Caller 0x%p
  ",
  			    tag, linenum, fname, ra);
  
  		xfs_stack_trace();
  	}
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
203
204
205
206
207
208
209
210
211
212
213
214
215
216
  void
  xfs_corruption_error(
  	char		*tag,
  	int		level,
  	xfs_mount_t	*mp,
  	void		*p,
  	char		*fname,
  	int		linenum,
  	inst_t		*ra)
  {
  	if (level <= xfs_error_level)
  		xfs_hex_dump(p, 16);
  	xfs_error_report(tag, level, mp, fname, linenum, ra);
  }