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