lfs_debug.c revision 1.49 1 /* $NetBSD: lfs_debug.c,v 1.49 2015/08/02 18:14:16 dholland 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.49 2015/08/02 18:14:16 dholland Exp $");
64
65 #ifdef DEBUG
66
67 #include <sys/param.h>
68 #include <sys/systm.h>
69 #include <sys/namei.h>
70 #include <sys/vnode.h>
71 #include <sys/mount.h>
72 #include <sys/buf.h>
73 #include <sys/syslog.h>
74 #include <sys/proc.h>
75
76 #include <ufs/lfs/ulfs_inode.h>
77 #include <ufs/lfs/lfs.h>
78 #include <ufs/lfs/lfs_accessors.h>
79 #include <ufs/lfs/lfs_extern.h>
80
81 int lfs_lognum;
82 struct lfs_log_entry lfs_log[LFS_LOGLENGTH];
83
84 int
85 lfs_bwrite_log(struct buf *bp, const char *file, int line)
86 {
87 struct vop_bwrite_args a;
88
89 a.a_desc = VDESC(vop_bwrite);
90 a.a_bp = bp;
91
92 if (!(bp->b_flags & B_GATHERED) && !(bp->b_oflags & BO_DELWRI)) {
93 LFS_ENTER_LOG("write", file, line, bp->b_lblkno, bp->b_flags,
94 curproc->p_pid);
95 }
96 return (VCALL(bp->b_vp, VOFFSET(vop_bwrite), &a));
97 }
98
99 void
100 lfs_dumplog(void)
101 {
102 int i;
103 const char *cp;
104
105 for (i = lfs_lognum; i != (lfs_lognum - 1) % LFS_LOGLENGTH;
106 i = (i + 1) % LFS_LOGLENGTH)
107 if (lfs_log[i].file) {
108 /* Only print out basename, for readability */
109 cp = lfs_log[i].file;
110 while(*cp)
111 ++cp;
112 while(*cp != '/' && cp > lfs_log[i].file)
113 --cp;
114
115 printf("lbn %" PRId64 " %s %lx %d, %d %s\n",
116 lfs_log[i].block,
117 lfs_log[i].op,
118 lfs_log[i].flags,
119 lfs_log[i].pid,
120 lfs_log[i].line,
121 cp);
122 }
123 }
124
125 void
126 lfs_dump_super(struct lfs *lfsp)
127 {
128 int i;
129
130 printf("%s%x\t%s%x\t%s%ju\t%s%d\n",
131 "magic ", lfsp->lfs_magic,
132 "version ", lfs_sb_getversion(lfsp),
133 "size ", (uintmax_t)lfs_sb_getsize(lfsp),
134 "ssize ", lfs_sb_getssize(lfsp));
135 printf("%s%ju\t%s%d\t%s%d\t%s%d\n",
136 "dsize ", (uintmax_t)lfs_sb_getdsize(lfsp),
137 "bsize ", lfs_sb_getbsize(lfsp),
138 "fsize ", lfs_sb_getfsize(lfsp),
139 "frag ", lfs_sb_getfrag(lfsp));
140
141 printf("%s%d\t%s%d\t%s%d\t%s%d\n",
142 "minfree ", lfs_sb_getminfree(lfsp),
143 "inopb ", lfs_sb_getinopb(lfsp),
144 "ifpb ", lfs_sb_getifpb(lfsp),
145 "nindir ", lfs_sb_getnindir(lfsp));
146
147 printf("%s%d\t%s%d\t%s%d\t%s%d\n",
148 "nseg ", lfs_sb_getnseg(lfsp),
149 "nspf ", lfs_sb_getnspf(lfsp),
150 "cleansz ", lfs_sb_getcleansz(lfsp),
151 "segtabsz ", lfs_sb_getsegtabsz(lfsp));
152
153 printf("%s%x\t%s%d\t%s%lx\t%s%d\n",
154 "segmask ", lfs_sb_getsegmask(lfsp),
155 "segshift ", lfs_sb_getsegshift(lfsp),
156 "bmask ", (unsigned long)lfs_sb_getbmask(lfsp),
157 "bshift ", lfs_sb_getbshift(lfsp));
158
159 printf("%s%lu\t%s%d\t%s%lx\t%s%u\n",
160 "ffmask ", (unsigned long)lfs_sb_getffmask(lfsp),
161 "ffshift ", lfs_sb_getffshift(lfsp),
162 "fbmask ", (unsigned long)lfs_sb_getfbmask(lfsp),
163 "fbshift ", lfs_sb_getfbshift(lfsp));
164
165 printf("%s%d\t%s%d\t%s%x\t%s%jx\n",
166 "sushift ", lfs_sb_getsushift(lfsp),
167 "fsbtodb ", lfs_sb_getfsbtodb(lfsp),
168 "cksum ", lfs_sb_getcksum(lfsp),
169 "maxfilesize ", (uintmax_t)lfs_sb_getmaxfilesize(lfsp));
170
171 printf("Superblock disk addresses:");
172 for (i = 0; i < LFS_MAXNUMSB; i++)
173 printf(" %jx", (intmax_t)lfs_sb_getsboff(lfsp, i));
174 printf("\n");
175
176 printf("Checkpoint Info\n");
177 printf("%s%d\t%s%jx\t%s%d\n",
178 "freehd ", lfs_sb_getfreehd(lfsp),
179 "idaddr ", (intmax_t)lfs_sb_getidaddr(lfsp),
180 "ifile ", lfs_sb_getifile(lfsp));
181 printf("%s%jx\t%s%d\t%s%jx\t%s%jx\t%s%jx\t%s%jx\n",
182 "bfree ", (intmax_t)lfs_sb_getbfree(lfsp),
183 "nfiles ", lfs_sb_getnfiles(lfsp),
184 "lastseg ", (intmax_t)lfs_sb_getlastseg(lfsp),
185 "nextseg ", (intmax_t)lfs_sb_getnextseg(lfsp),
186 "curseg ", (intmax_t)lfs_sb_getcurseg(lfsp),
187 "offset ", (intmax_t)lfs_sb_getoffset(lfsp));
188 printf("tstamp %llx\n", (long long)lfs_sb_gettstamp(lfsp));
189 }
190
191 void
192 lfs_dump_dinode(struct ulfs1_dinode *dip)
193 {
194 int i;
195
196 printf("%s%u\t%s%d\t%s%u\t%s%u\t%s%qu\t%s%d\n",
197 "mode ", dip->di_mode,
198 "nlink ", dip->di_nlink,
199 "uid ", dip->di_uid,
200 "gid ", dip->di_gid,
201 "size ", (long long)dip->di_size,
202 "blocks ", dip->di_blocks);
203 printf("inum %d\n", dip->di_inumber);
204 printf("Direct Addresses\n");
205 for (i = 0; i < ULFS_NDADDR; i++) {
206 printf("\t%x", dip->di_db[i]);
207 if ((i % 6) == 5)
208 printf("\n");
209 }
210 for (i = 0; i < ULFS_NIADDR; i++)
211 printf("\t%x", dip->di_ib[i]);
212 printf("\n");
213 }
214
215 void
216 lfs_check_segsum(struct lfs *fs, struct segment *sp, char *file, int line)
217 {
218 int actual;
219 #if 0
220 static int offset;
221 #endif
222
223 if ((actual = 1) == 1)
224 return; /* XXXX not checking this anymore, really */
225
226 if (sp->sum_bytes_left >= FINFOSIZE
227 && sp->fip->fi_nblocks > 512) {
228 printf("%s:%d: fi_nblocks = %d\n",file,line,sp->fip->fi_nblocks);
229 #ifdef DDB
230 Debugger();
231 #endif
232 }
233
234 if (sp->sum_bytes_left > 484) {
235 printf("%s:%d: bad value (%d = -%d) for sum_bytes_left\n",
236 file, line, sp->sum_bytes_left, lfs_sb_getsumsize(fs)-sp->sum_bytes_left);
237 panic("too many bytes");
238 }
239
240 actual = lfs_sb_getsumsize(fs)
241 /* amount taken up by FINFOs */
242 - ((char *)&(sp->fip->fi_blocks[sp->fip->fi_nblocks]) - (char *)(sp->segsum))
243 /* amount taken up by inode blocks */
244 - sizeof(int32_t)*((sp->ninodes+LFS_INOPB(fs)-1) / LFS_INOPB(fs));
245 #if 0
246 if (actual - sp->sum_bytes_left < offset)
247 {
248 printf("%s:%d: offset changed %d -> %d\n", file, line,
249 offset, actual-sp->sum_bytes_left);
250 offset = actual - sp->sum_bytes_left;
251 /* panic("byte mismatch"); */
252 }
253 #endif
254 #if 0
255 if (actual != sp->sum_bytes_left)
256 printf("%s:%d: warning: segsum miscalc at %d (-%d => %d)\n",
257 file, line, sp->sum_bytes_left,
258 lfs_sb_getsumsize(fs)-sp->sum_bytes_left,
259 actual);
260 #endif
261 if (sp->sum_bytes_left > 0
262 && ((char *)(sp->segsum))[lfs_sb_getsumsize(fs)
263 - sizeof(int32_t) * ((sp->ninodes+LFS_INOPB(fs)-1) / LFS_INOPB(fs))
264 - sp->sum_bytes_left] != '\0') {
265 printf("%s:%d: warning: segsum overwrite at %d (-%d => %d)\n",
266 file, line, sp->sum_bytes_left,
267 lfs_sb_getsumsize(fs)-sp->sum_bytes_left,
268 actual);
269 #ifdef DDB
270 Debugger();
271 #endif
272 }
273 }
274
275 void
276 lfs_check_bpp(struct lfs *fs, struct segment *sp, char *file, int line)
277 {
278 daddr_t blkno;
279 struct buf **bpp;
280 struct vnode *devvp;
281
282 devvp = VTOI(fs->lfs_ivnode)->i_devvp;
283 blkno = (*(sp->bpp))->b_blkno;
284 for (bpp = sp->bpp; bpp < sp->cbpp; bpp++) {
285 if ((*bpp)->b_blkno != blkno) {
286 if ((*bpp)->b_vp == devvp) {
287 printf("Oops, would misplace raw block "
288 "0x%" PRIx64 " at 0x%" PRIx64 "\n",
289 (*bpp)->b_blkno,
290 blkno);
291 } else {
292 printf("%s:%d: misplace ino %llu lbn %" PRId64
293 " at 0x%" PRIx64 " instead of "
294 "0x%" PRIx64 "\n",
295 file, line,
296 (unsigned long long)
297 VTOI((*bpp)->b_vp)->i_number,
298 (*bpp)->b_lblkno,
299 blkno,
300 (*bpp)->b_blkno);
301 }
302 }
303 blkno += LFS_FSBTODB(fs, lfs_btofsb(fs, (*bpp)->b_bcount));
304 }
305 }
306
307 int lfs_debug_log_subsys[DLOG_MAX];
308
309 /*
310 * Log events from various debugging areas of LFS, depending on what
311 * the user has enabled.
312 */
313 void
314 lfs_debug_log(int subsys, const char *fmt, ...)
315 {
316 va_list ap;
317
318 /* If not debugging this subsys, exit */
319 if (lfs_debug_log_subsys[subsys] == 0)
320 return;
321
322 va_start(ap, fmt);
323 vlog(LOG_DEBUG, fmt, ap);
324 va_end(ap);
325 }
326 #endif /* DEBUG */
327