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