lfs_debug.c revision 1.32 1 /* $NetBSD: lfs_debug.c,v 1.32 2005/08/19 02:04:09 christos Exp $ */
2
3 /*-
4 * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Konrad E. Schroder <perseant (at) hhhh.org>.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38 /*
39 * Copyright (c) 1991, 1993
40 * The Regents of the University of California. All rights reserved.
41 *
42 * Redistribution and use in source and binary forms, with or without
43 * modification, are permitted provided that the following conditions
44 * are met:
45 * 1. Redistributions of source code must retain the above copyright
46 * notice, this list of conditions and the following disclaimer.
47 * 2. Redistributions in binary form must reproduce the above copyright
48 * notice, this list of conditions and the following disclaimer in the
49 * documentation and/or other materials provided with the distribution.
50 * 3. Neither the name of the University nor the names of its contributors
51 * may be used to endorse or promote products derived from this software
52 * without specific prior written permission.
53 *
54 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * SUCH DAMAGE.
65 *
66 * @(#)lfs_debug.c 8.1 (Berkeley) 6/11/93
67 */
68
69 #ifdef DEBUG
70
71 #include <machine/stdarg.h>
72
73 #include <sys/cdefs.h>
74 __KERNEL_RCSID(0, "$NetBSD: lfs_debug.c,v 1.32 2005/08/19 02:04:09 christos Exp $");
75 #include <sys/param.h>
76 #include <sys/systm.h>
77 #include <sys/namei.h>
78 #include <sys/vnode.h>
79 #include <sys/mount.h>
80 #include <sys/buf.h>
81 #include <sys/syslog.h>
82
83 #include <ufs/ufs/inode.h>
84 #include <ufs/lfs/lfs.h>
85 #include <ufs/lfs/lfs_extern.h>
86
87 int lfs_lognum;
88 struct lfs_log_entry lfs_log[LFS_LOGLENGTH];
89
90 int lfs_bwrite_log(struct buf *bp, const char *file, int line)
91 {
92 struct vop_bwrite_args a;
93 a.a_desc = VDESC(vop_bwrite);
94 a.a_bp = bp;
95
96 if (!(bp->b_flags & (B_DELWRI | B_GATHERED))) {
97 LFS_ENTER_LOG("write", file, line, bp->b_lblkno, bp->b_flags,
98 curproc->p_pid);
99 }
100 return (VCALL(bp->b_vp, VOFFSET(vop_bwrite), &a));
101 }
102
103 void lfs_dumplog(void)
104 {
105 int i;
106 const char *cp;
107
108 for (i = lfs_lognum; i != (lfs_lognum - 1) % LFS_LOGLENGTH;
109 i = (i + 1) % LFS_LOGLENGTH)
110 if (lfs_log[i].file) {
111 /* Only print out basename, for readability */
112 cp = lfs_log[i].file;
113 while(*cp)
114 ++cp;
115 while(*cp != '/' && cp > lfs_log[i].file)
116 --cp;
117
118 printf("lbn %" PRId64 " %s %lx %d, %d %s\n",
119 lfs_log[i].block,
120 lfs_log[i].op,
121 lfs_log[i].flags,
122 lfs_log[i].pid,
123 lfs_log[i].line,
124 cp);
125 }
126 }
127
128 void
129 lfs_dump_super(struct lfs *lfsp)
130 {
131 int i;
132
133 printf("%s%x\t%s%x\t%s%d\t%s%d\n",
134 "magic ", lfsp->lfs_magic,
135 "version ", lfsp->lfs_version,
136 "size ", lfsp->lfs_size,
137 "ssize ", lfsp->lfs_ssize);
138 printf("%s%d\t%s%d\t%s%d\t%s%d\n",
139 "dsize ", lfsp->lfs_dsize,
140 "bsize ", lfsp->lfs_bsize,
141 "fsize ", lfsp->lfs_fsize,
142 "frag ", lfsp->lfs_frag);
143
144 printf("%s%d\t%s%d\t%s%d\t%s%d\n",
145 "minfree ", lfsp->lfs_minfree,
146 "inopb ", lfsp->lfs_inopb,
147 "ifpb ", lfsp->lfs_ifpb,
148 "nindir ", lfsp->lfs_nindir);
149
150 printf("%s%d\t%s%d\t%s%d\t%s%d\n",
151 "nseg ", lfsp->lfs_nseg,
152 "nspf ", lfsp->lfs_nspf,
153 "cleansz ", lfsp->lfs_cleansz,
154 "segtabsz ", lfsp->lfs_segtabsz);
155
156 printf("%s%x\t%s%d\t%s%lx\t%s%d\n",
157 "segmask ", lfsp->lfs_segmask,
158 "segshift ", lfsp->lfs_segshift,
159 "bmask ", (unsigned long)lfsp->lfs_bmask,
160 "bshift ", lfsp->lfs_bshift);
161
162 printf("%s%lu\t%s%d\t%s%lx\t%s%u\n",
163 "ffmask ", (unsigned long)lfsp->lfs_ffmask,
164 "ffshift ", lfsp->lfs_ffshift,
165 "fbmask ", (unsigned long)lfsp->lfs_fbmask,
166 "fbshift ", lfsp->lfs_fbshift);
167
168 printf("%s%d\t%s%d\t%s%x\t%s%qx\n",
169 "sushift ", lfsp->lfs_sushift,
170 "fsbtodb ", lfsp->lfs_fsbtodb,
171 "cksum ", lfsp->lfs_cksum,
172 "maxfilesize ", (long long)lfsp->lfs_maxfilesize);
173
174 printf("Superblock disk addresses:");
175 for (i = 0; i < LFS_MAXNUMSB; i++)
176 printf(" %x", lfsp->lfs_sboffs[i]);
177 printf("\n");
178
179 printf("Checkpoint Info\n");
180 printf("%s%d\t%s%x\t%s%d\n",
181 "freehd ", lfsp->lfs_freehd,
182 "idaddr ", lfsp->lfs_idaddr,
183 "ifile ", lfsp->lfs_ifile);
184 printf("%s%x\t%s%d\t%s%x\t%s%x\t%s%x\t%s%x\n",
185 "bfree ", lfsp->lfs_bfree,
186 "nfiles ", lfsp->lfs_nfiles,
187 "lastseg ", lfsp->lfs_lastseg,
188 "nextseg ", lfsp->lfs_nextseg,
189 "curseg ", lfsp->lfs_curseg,
190 "offset ", lfsp->lfs_offset);
191 printf("tstamp %llx\n", (long long)lfsp->lfs_tstamp);
192 }
193
194 void
195 lfs_dump_dinode(struct ufs1_dinode *dip)
196 {
197 int i;
198
199 printf("%s%u\t%s%d\t%s%u\t%s%u\t%s%qu\t%s%d\n",
200 "mode ", dip->di_mode,
201 "nlink ", dip->di_nlink,
202 "uid ", dip->di_uid,
203 "gid ", dip->di_gid,
204 "size ", (long long)dip->di_size,
205 "blocks ", dip->di_blocks);
206 printf("inum %d\n", dip->di_inumber);
207 printf("Direct Addresses\n");
208 for (i = 0; i < NDADDR; i++) {
209 printf("\t%x", dip->di_db[i]);
210 if ((i % 6) == 5)
211 printf("\n");
212 }
213 for (i = 0; i < NIADDR; i++)
214 printf("\t%x", dip->di_ib[i]);
215 printf("\n");
216 }
217
218 void
219 lfs_check_segsum(struct lfs *fs, struct segment *sp, char *file, int line)
220 {
221 int actual;
222 #if 0
223 static int offset;
224 #endif
225
226 if ((actual = 1) == 1)
227 return; /* XXXX not checking this anymore, really */
228
229 if (sp->sum_bytes_left >= FINFOSIZE
230 && sp->fip->fi_nblocks > 512) {
231 printf("%s:%d: fi_nblocks = %d\n",file,line,sp->fip->fi_nblocks);
232 #ifdef DDB
233 Debugger();
234 #endif
235 }
236
237 if (sp->sum_bytes_left > 484) {
238 printf("%s:%d: bad value (%d = -%d) for sum_bytes_left\n",
239 file, line, sp->sum_bytes_left, fs->lfs_sumsize-sp->sum_bytes_left);
240 panic("too many bytes");
241 }
242
243 actual = fs->lfs_sumsize
244 /* amount taken up by FINFOs */
245 - ((char *)&(sp->fip->fi_blocks[sp->fip->fi_nblocks]) - (char *)(sp->segsum))
246 /* amount taken up by inode blocks */
247 - sizeof(int32_t)*((sp->ninodes+INOPB(fs)-1) / INOPB(fs));
248 #if 0
249 if (actual - sp->sum_bytes_left < offset)
250 {
251 printf("%s:%d: offset changed %d -> %d\n", file, line,
252 offset, actual-sp->sum_bytes_left);
253 offset = actual - sp->sum_bytes_left;
254 /* panic("byte mismatch"); */
255 }
256 #endif
257 #if 0
258 if (actual != sp->sum_bytes_left)
259 printf("%s:%d: warning: segsum miscalc at %d (-%d => %d)\n",
260 file, line, sp->sum_bytes_left,
261 fs->lfs_sumsize-sp->sum_bytes_left,
262 actual);
263 #endif
264 if (sp->sum_bytes_left > 0
265 && ((char *)(sp->segsum))[fs->lfs_sumsize
266 - sizeof(int32_t) * ((sp->ninodes+INOPB(fs)-1) / INOPB(fs))
267 - sp->sum_bytes_left] != '\0') {
268 printf("%s:%d: warning: segsum overwrite at %d (-%d => %d)\n",
269 file, line, sp->sum_bytes_left,
270 fs->lfs_sumsize-sp->sum_bytes_left,
271 actual);
272 #ifdef DDB
273 Debugger();
274 #endif
275 }
276 }
277
278 void
279 lfs_check_bpp(struct lfs *fs, struct segment *sp, char *file, int line)
280 {
281 daddr_t blkno;
282 struct buf **bpp;
283 struct vnode *devvp;
284
285 devvp = VTOI(fs->lfs_ivnode)->i_devvp;
286 blkno = (*(sp->bpp))->b_blkno;
287 for (bpp = sp->bpp; bpp < sp->cbpp; bpp++) {
288 if ((*bpp)->b_blkno != blkno) {
289 if ((*bpp)->b_vp == devvp) {
290 printf("Oops, would misplace raw block "
291 "0x%" PRIx64 " at 0x%" PRIx64 "\n",
292 (*bpp)->b_blkno,
293 blkno);
294 } else {
295 printf("%s:%d: misplace ino %llu lbn %" PRId64
296 " at 0x%" PRIx64 " instead of "
297 "0x%" PRIx64 "\n",
298 file, line,
299 (unsigned long long)
300 VTOI((*bpp)->b_vp)->i_number,
301 (*bpp)->b_lblkno,
302 blkno,
303 (*bpp)->b_blkno);
304 }
305 }
306 blkno += fsbtodb(fs, btofsb(fs, (*bpp)->b_bcount));
307 }
308 }
309
310 int lfs_debug_log_subsys[DLOG_MAX];
311
312 /*
313 * Log events from various debugging areas of LFS, depending on what
314 * the user has enabled.
315 */
316 void
317 lfs_debug_log(int subsys, const char *fmt, ...)
318 {
319 va_list ap;
320
321 /* If not debugging this subsys, exit */
322 if (lfs_debug_log_subsys[subsys] == 0)
323 return;
324
325 va_start(ap, fmt);
326 vlog(LOG_DEBUG, fmt, ap);
327 va_end(ap);
328 }
329 #endif /* DEBUG */
330