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