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