lfs_debug.c revision 1.28 1 /* $NetBSD: lfs_debug.c,v 1.28 2005/03/26 19:39:08 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.28 2005/03/26 19:39:08 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, 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 return (VCALL(bp->b_vp, VOFFSET(vop_bwrite), &a));
99 }
100
101 void lfs_dumplog(void)
102 {
103 int i;
104
105 for (i = lfs_lognum; i != (lfs_lognum - 1) % LFS_LOGLENGTH; i = (i + 1) % LFS_LOGLENGTH)
106 if (lfs_log[i].file) {
107 printf("lbn %" PRId64 " %s %lx %d %s\n",
108 lfs_log[i].block,
109 lfs_log[i].op,
110 lfs_log[i].flags,
111 lfs_log[i].line,
112 lfs_log[i].file + 56);
113 }
114 }
115
116 void
117 lfs_dump_super(struct lfs *lfsp)
118 {
119 int i;
120
121 printf("%s%x\t%s%x\t%s%d\t%s%d\n",
122 "magic ", lfsp->lfs_magic,
123 "version ", lfsp->lfs_version,
124 "size ", lfsp->lfs_size,
125 "ssize ", lfsp->lfs_ssize);
126 printf("%s%d\t%s%d\t%s%d\t%s%d\n",
127 "dsize ", lfsp->lfs_dsize,
128 "bsize ", lfsp->lfs_bsize,
129 "fsize ", lfsp->lfs_fsize,
130 "frag ", lfsp->lfs_frag);
131
132 printf("%s%d\t%s%d\t%s%d\t%s%d\n",
133 "minfree ", lfsp->lfs_minfree,
134 "inopb ", lfsp->lfs_inopb,
135 "ifpb ", lfsp->lfs_ifpb,
136 "nindir ", lfsp->lfs_nindir);
137
138 printf("%s%d\t%s%d\t%s%d\t%s%d\n",
139 "nseg ", lfsp->lfs_nseg,
140 "nspf ", lfsp->lfs_nspf,
141 "cleansz ", lfsp->lfs_cleansz,
142 "segtabsz ", lfsp->lfs_segtabsz);
143
144 printf("%s%x\t%s%d\t%s%lx\t%s%d\n",
145 "segmask ", lfsp->lfs_segmask,
146 "segshift ", lfsp->lfs_segshift,
147 "bmask ", (unsigned long)lfsp->lfs_bmask,
148 "bshift ", lfsp->lfs_bshift);
149
150 printf("%s%lu\t%s%d\t%s%lx\t%s%u\n",
151 "ffmask ", (unsigned long)lfsp->lfs_ffmask,
152 "ffshift ", lfsp->lfs_ffshift,
153 "fbmask ", (unsigned long)lfsp->lfs_fbmask,
154 "fbshift ", lfsp->lfs_fbshift);
155
156 printf("%s%d\t%s%d\t%s%x\t%s%qx\n",
157 "sushift ", lfsp->lfs_sushift,
158 "fsbtodb ", lfsp->lfs_fsbtodb,
159 "cksum ", lfsp->lfs_cksum,
160 "maxfilesize ", (long long)lfsp->lfs_maxfilesize);
161
162 printf("Superblock disk addresses:");
163 for (i = 0; i < LFS_MAXNUMSB; i++)
164 printf(" %x", lfsp->lfs_sboffs[i]);
165 printf("\n");
166
167 printf("Checkpoint Info\n");
168 printf("%s%d\t%s%x\t%s%d\n",
169 "freehd ", lfsp->lfs_freehd,
170 "idaddr ", lfsp->lfs_idaddr,
171 "ifile ", lfsp->lfs_ifile);
172 printf("%s%x\t%s%d\t%s%x\t%s%x\t%s%x\t%s%x\n",
173 "bfree ", lfsp->lfs_bfree,
174 "nfiles ", lfsp->lfs_nfiles,
175 "lastseg ", lfsp->lfs_lastseg,
176 "nextseg ", lfsp->lfs_nextseg,
177 "curseg ", lfsp->lfs_curseg,
178 "offset ", lfsp->lfs_offset);
179 printf("tstamp %llx\n", (long long)lfsp->lfs_tstamp);
180 }
181
182 void
183 lfs_dump_dinode(struct ufs1_dinode *dip)
184 {
185 int i;
186
187 printf("%s%u\t%s%d\t%s%u\t%s%u\t%s%qu\t%s%d\n",
188 "mode ", dip->di_mode,
189 "nlink ", dip->di_nlink,
190 "uid ", dip->di_uid,
191 "gid ", dip->di_gid,
192 "size ", (long long)dip->di_size,
193 "blocks ", dip->di_blocks);
194 printf("inum %d\n", dip->di_inumber);
195 printf("Direct Addresses\n");
196 for (i = 0; i < NDADDR; i++) {
197 printf("\t%x", dip->di_db[i]);
198 if ((i % 6) == 5)
199 printf("\n");
200 }
201 for (i = 0; i < NIADDR; i++)
202 printf("\t%x", dip->di_ib[i]);
203 printf("\n");
204 }
205
206 void
207 lfs_check_segsum(struct lfs *fs, struct segment *sp, char *file, int line)
208 {
209 int actual;
210 #if 0
211 static int offset;
212 #endif
213
214 if ((actual = 1) == 1)
215 return; /* XXXX not checking this anymore, really */
216
217 if (sp->sum_bytes_left >= FINFOSIZE
218 && sp->fip->fi_nblocks > 512) {
219 printf("%s:%d: fi_nblocks = %d\n",file,line,sp->fip->fi_nblocks);
220 #ifdef DDB
221 Debugger();
222 #endif
223 }
224
225 if (sp->sum_bytes_left > 484) {
226 printf("%s:%d: bad value (%d = -%d) for sum_bytes_left\n",
227 file, line, sp->sum_bytes_left, fs->lfs_sumsize-sp->sum_bytes_left);
228 panic("too many bytes");
229 }
230
231 actual = fs->lfs_sumsize
232 /* amount taken up by FINFOs */
233 - ((char *)&(sp->fip->fi_blocks[sp->fip->fi_nblocks]) - (char *)(sp->segsum))
234 /* amount taken up by inode blocks */
235 - sizeof(int32_t)*((sp->ninodes+INOPB(fs)-1) / INOPB(fs));
236 #if 0
237 if (actual - sp->sum_bytes_left < offset)
238 {
239 printf("%s:%d: offset changed %d -> %d\n", file, line,
240 offset, actual-sp->sum_bytes_left);
241 offset = actual - sp->sum_bytes_left;
242 /* panic("byte mismatch"); */
243 }
244 #endif
245 #if 0
246 if (actual != sp->sum_bytes_left)
247 printf("%s:%d: warning: segsum miscalc at %d (-%d => %d)\n",
248 file, line, sp->sum_bytes_left,
249 fs->lfs_sumsize-sp->sum_bytes_left,
250 actual);
251 #endif
252 if (sp->sum_bytes_left > 0
253 && ((char *)(sp->segsum))[fs->lfs_sumsize
254 - sizeof(int32_t) * ((sp->ninodes+INOPB(fs)-1) / INOPB(fs))
255 - sp->sum_bytes_left] != '\0') {
256 printf("%s:%d: warning: segsum overwrite at %d (-%d => %d)\n",
257 file, line, sp->sum_bytes_left,
258 fs->lfs_sumsize-sp->sum_bytes_left,
259 actual);
260 #ifdef DDB
261 Debugger();
262 #endif
263 }
264 }
265
266 void
267 lfs_check_bpp(struct lfs *fs, struct segment *sp, char *file, int line)
268 {
269 daddr_t blkno;
270 struct buf **bpp;
271 struct vnode *devvp;
272
273 devvp = VTOI(fs->lfs_ivnode)->i_devvp;
274 blkno = (*(sp->bpp))->b_blkno;
275 for (bpp = sp->bpp; bpp < sp->cbpp; bpp++) {
276 if ((*bpp)->b_blkno != blkno) {
277 if ((*bpp)->b_vp == devvp) {
278 printf("Oops, would misplace raw block "
279 "0x%" PRIx64 " at 0x%" PRIx64 "\n",
280 (*bpp)->b_blkno,
281 blkno);
282 } else {
283 printf("%s:%d: misplace ino %d lbn %" PRId64
284 " at 0x%" PRIx64 " instead of "
285 "0x%" PRIx64 "\n",
286 file, line,
287 VTOI((*bpp)->b_vp)->i_number, (*bpp)->b_lblkno,
288 blkno,
289 (*bpp)->b_blkno);
290 }
291 }
292 blkno += fsbtodb(fs, btofsb(fs, (*bpp)->b_bcount));
293 }
294 }
295
296 int lfs_debug_log_subsys[DLOG_MAX];
297
298 /*
299 * Log events from various debugging areas of LFS, depending on what
300 * the user has enabled.
301 */
302 void
303 lfs_debug_log(int subsys, const char *fmt, ...)
304 {
305 va_list ap;
306
307 /* If not debugging this subsys, exit */
308 if (lfs_debug_log_subsys[subsys] == 0)
309 return;
310
311 va_start(fmt, ap);
312 vlog(LOG_DEBUG, fmt, ap);
313 va_end(ap);
314 }
315 #endif /* DEBUG */
316