1 /*
2  * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
3  * All Rights Reserved.
4  *
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.
8  *
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.
13  *
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
17  */
18 #include "xfs.h"
19 #include "xfs_fs.h"
20 #include "xfs_types.h"
21 #include "xfs_inum.h"
22 #include "xfs_dir.h"
23 #include "xfs_dir2.h"
24 #include "xfs_da_btree.h"
25 #include "xfs_bmap_btree.h"
26 #include "xfs_dir_sf.h"
27 #include "xfs_dir2_sf.h"
28 #include "xfs_attr_sf.h"
29 #include "xfs_dinode.h"
30 #include "xfs_inode.h"
31 #include "xfs_dir2_trace.h"
32 
33 #ifdef XFS_DIR2_TRACE
34 ktrace_t	*xfs_dir2_trace_buf;
35 
36 /*
37  * Enter something in the trace buffers.
38  */
39 static void
xfs_dir2_trace_enter(xfs_inode_t * dp,int type,char * where,char * name,int namelen,void * a0,void * a1,void * a2,void * a3,void * a4,void * a5,void * a6,void * a7)40 xfs_dir2_trace_enter(
41 	xfs_inode_t	*dp,
42 	int		type,
43 	char		*where,
44 	char		*name,
45 	int		namelen,
46 	void		*a0,
47 	void		*a1,
48 	void		*a2,
49 	void		*a3,
50 	void		*a4,
51 	void		*a5,
52 	void		*a6,
53 	void		*a7)
54 {
55 	void		*n[5];
56 
57 	ASSERT(xfs_dir2_trace_buf);
58 	ASSERT(dp->i_dir_trace);
59 	if (name)
60 		memcpy(n, name, min((int)sizeof(n), namelen));
61 	else
62 		memset((char *)n, 0, sizeof(n));
63 	ktrace_enter(xfs_dir2_trace_buf,
64 		(void *)(long)type, (void *)where,
65 		(void *)a0, (void *)a1, (void *)a2, (void *)a3,
66 		(void *)a4, (void *)a5, (void *)a6, (void *)a7,
67 		(void *)(long)namelen,
68 		(void *)n[0], (void *)n[1], (void *)n[2],
69 		(void *)n[3], (void *)n[4]);
70 	ktrace_enter(dp->i_dir_trace,
71 		(void *)(long)type, (void *)where,
72 		(void *)a0, (void *)a1, (void *)a2, (void *)a3,
73 		(void *)a4, (void *)a5, (void *)a6, (void *)a7,
74 		(void *)(long)namelen,
75 		(void *)n[0], (void *)n[1], (void *)n[2],
76 		(void *)n[3], (void *)n[4]);
77 }
78 
79 void
xfs_dir2_trace_args(char * where,xfs_da_args_t * args)80 xfs_dir2_trace_args(
81 	char		*where,
82 	xfs_da_args_t	*args)
83 {
84 	xfs_dir2_trace_enter(args->dp, XFS_DIR2_KTRACE_ARGS, where,
85 		(char *)args->name, (int)args->namelen,
86 		(void *)(unsigned long)args->hashval,
87 		(void *)((unsigned long)(args->inumber >> 32)),
88 		(void *)((unsigned long)(args->inumber & 0xFFFFFFFF)),
89 		(void *)args->dp, (void *)args->trans,
90 		(void *)(unsigned long)args->justcheck, NULL, NULL);
91 }
92 
93 void
xfs_dir2_trace_args_b(char * where,xfs_da_args_t * args,xfs_dabuf_t * bp)94 xfs_dir2_trace_args_b(
95 	char		*where,
96 	xfs_da_args_t	*args,
97 	xfs_dabuf_t	*bp)
98 {
99 	xfs_dir2_trace_enter(args->dp, XFS_DIR2_KTRACE_ARGS_B, where,
100 		(char *)args->name, (int)args->namelen,
101 		(void *)(unsigned long)args->hashval,
102 		(void *)((unsigned long)(args->inumber >> 32)),
103 		(void *)((unsigned long)(args->inumber & 0xFFFFFFFF)),
104 		(void *)args->dp, (void *)args->trans,
105 		(void *)(unsigned long)args->justcheck,
106 		(void *)(bp ? bp->bps[0] : NULL), NULL);
107 }
108 
109 void
xfs_dir2_trace_args_bb(char * where,xfs_da_args_t * args,xfs_dabuf_t * lbp,xfs_dabuf_t * dbp)110 xfs_dir2_trace_args_bb(
111 	char		*where,
112 	xfs_da_args_t	*args,
113 	xfs_dabuf_t	*lbp,
114 	xfs_dabuf_t	*dbp)
115 {
116 	xfs_dir2_trace_enter(args->dp, XFS_DIR2_KTRACE_ARGS_BB, where,
117 		(char *)args->name, (int)args->namelen,
118 		(void *)(unsigned long)args->hashval,
119 		(void *)((unsigned long)(args->inumber >> 32)),
120 		(void *)((unsigned long)(args->inumber & 0xFFFFFFFF)),
121 		(void *)args->dp, (void *)args->trans,
122 		(void *)(unsigned long)args->justcheck,
123 		(void *)(lbp ? lbp->bps[0] : NULL),
124 		(void *)(dbp ? dbp->bps[0] : NULL));
125 }
126 
127 void
xfs_dir2_trace_args_bibii(char * where,xfs_da_args_t * args,xfs_dabuf_t * bs,int ss,xfs_dabuf_t * bd,int sd,int c)128 xfs_dir2_trace_args_bibii(
129 	char		*where,
130 	xfs_da_args_t	*args,
131 	xfs_dabuf_t	*bs,
132 	int		ss,
133 	xfs_dabuf_t	*bd,
134 	int		sd,
135 	int		c)
136 {
137 	xfs_buf_t	*bpbs = bs ? bs->bps[0] : NULL;
138 	xfs_buf_t	*bpbd = bd ? bd->bps[0] : NULL;
139 
140 	xfs_dir2_trace_enter(args->dp, XFS_DIR2_KTRACE_ARGS_BIBII, where,
141 		(char *)args->name, (int)args->namelen,
142 		(void *)args->dp, (void *)args->trans,
143 		(void *)bpbs, (void *)(long)ss, (void *)bpbd, (void *)(long)sd,
144 		(void *)(long)c, NULL);
145 }
146 
147 void
xfs_dir2_trace_args_db(char * where,xfs_da_args_t * args,xfs_dir2_db_t db,xfs_dabuf_t * bp)148 xfs_dir2_trace_args_db(
149 	char		*where,
150 	xfs_da_args_t	*args,
151 	xfs_dir2_db_t	db,
152 	xfs_dabuf_t	*bp)
153 {
154 	xfs_buf_t	*dbp = bp ? bp->bps[0] : NULL;
155 
156 	xfs_dir2_trace_enter(args->dp, XFS_DIR2_KTRACE_ARGS_DB, where,
157 		(char *)args->name, (int)args->namelen,
158 		(void *)(unsigned long)args->hashval,
159 		(void *)((unsigned long)(args->inumber >> 32)),
160 		(void *)((unsigned long)(args->inumber & 0xFFFFFFFF)),
161 		(void *)args->dp, (void *)args->trans,
162 		(void *)(unsigned long)args->justcheck, (void *)(long)db,
163 		(void *)dbp);
164 }
165 
166 void
xfs_dir2_trace_args_i(char * where,xfs_da_args_t * args,xfs_ino_t i)167 xfs_dir2_trace_args_i(
168 	char		*where,
169 	xfs_da_args_t	*args,
170 	xfs_ino_t	i)
171 {
172 	xfs_dir2_trace_enter(args->dp, XFS_DIR2_KTRACE_ARGS_I, where,
173 		(char *)args->name, (int)args->namelen,
174 		(void *)(unsigned long)args->hashval,
175 		(void *)((unsigned long)(args->inumber >> 32)),
176 		(void *)((unsigned long)(args->inumber & 0xFFFFFFFF)),
177 		(void *)args->dp, (void *)args->trans,
178 		(void *)(unsigned long)args->justcheck,
179 		(void *)((unsigned long)(i >> 32)),
180 		(void *)((unsigned long)(i & 0xFFFFFFFF)));
181 }
182 
183 void
xfs_dir2_trace_args_s(char * where,xfs_da_args_t * args,int s)184 xfs_dir2_trace_args_s(
185 	char		*where,
186 	xfs_da_args_t	*args,
187 	int		s)
188 {
189 	xfs_dir2_trace_enter(args->dp, XFS_DIR2_KTRACE_ARGS_S, where,
190 		(char *)args->name, (int)args->namelen,
191 		(void *)(unsigned long)args->hashval,
192 		(void *)((unsigned long)(args->inumber >> 32)),
193 		(void *)((unsigned long)(args->inumber & 0xFFFFFFFF)),
194 		(void *)args->dp, (void *)args->trans,
195 		(void *)(unsigned long)args->justcheck, (void *)(long)s, NULL);
196 }
197 
198 void
xfs_dir2_trace_args_sb(char * where,xfs_da_args_t * args,int s,xfs_dabuf_t * bp)199 xfs_dir2_trace_args_sb(
200 	char		*where,
201 	xfs_da_args_t	*args,
202 	int		s,
203 	xfs_dabuf_t	*bp)
204 {
205 	xfs_buf_t	*dbp = bp ? bp->bps[0] : NULL;
206 
207 	xfs_dir2_trace_enter(args->dp, XFS_DIR2_KTRACE_ARGS_SB, where,
208 		(char *)args->name, (int)args->namelen,
209 		(void *)(unsigned long)args->hashval,
210 		(void *)((unsigned long)(args->inumber >> 32)),
211 		(void *)((unsigned long)(args->inumber & 0xFFFFFFFF)),
212 		(void *)args->dp, (void *)args->trans,
213 		(void *)(unsigned long)args->justcheck, (void *)(long)s,
214 		(void *)dbp);
215 }
216 #endif	/* XFS_DIR2_TRACE */
217