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