From owner-freebsd-fs@FreeBSD.ORG Fri Sep 17 18:41:18 2010 Return-Path: Delivered-To: freebsd-fs@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3F53A106564A for ; Fri, 17 Sep 2010 18:41:18 +0000 (UTC) (envelope-from obrien@NUXI.org) Received: from dragon.nuxi.org (trang.nuxi.org [74.95.12.85]) by mx1.freebsd.org (Postfix) with ESMTP id 030F98FC1C for ; Fri, 17 Sep 2010 18:41:17 +0000 (UTC) Received: from dragon.nuxi.org (obrien@localhost [127.0.0.1]) by dragon.nuxi.org (8.14.4/8.14.4) with ESMTP id o8HI7cUf051716 for ; Fri, 17 Sep 2010 11:07:38 -0700 (PDT) (envelope-from obrien@dragon.nuxi.org) Received: (from obrien@localhost) by dragon.nuxi.org (8.14.4/8.14.4/Submit) id o8HI7cEg051715 for freebsd-fs@freebsd.org; Fri, 17 Sep 2010 11:07:38 -0700 (PDT) (envelope-from obrien) Date: Fri, 17 Sep 2010 11:07:38 -0700 From: "David O'Brien" To: freebsd-fs@freebsd.org Message-ID: <20100917180738.GA51572@dragon.NUXI.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Operating-System: FreeBSD 9.0-CURRENT X-to-the-FBI-CIA-and-NSA: HI! HOW YA DOIN? User-Agent: Mutt/1.5.16 (2007-06-09) Subject: [PATCH] replace INVARIANTS+panic() with KASSERT X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: obrien@freebsd.org List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Sep 2010 18:41:18 -0000 This patch changes most of the "asserts" and panic() within #ifdef INVARIANTS of olden years with KASSERTS. In doing so, it also changes some '"%s: blah", "thing"' with just '"thing: blah"' to make grep'ing easier. Some "notyet" code from the early 2000s is also reaped. Some sysctls are also added to make it easier to change some diagnostics values at runtime vs. I believe using the debugger to change them. thoughts? -- -- David (obrien@FreeBSD.org) Index: IVs/ffs/ffs_softdep.c =================================================================== --- ufs/ffs/ffs_softdep.c (revision 212799) +++ ufs/ffs/ffs_softdep.c (working copy) @@ -6015,11 +6015,9 @@ handle_complete_freeblocks(freeblks) vput(vp); } -#ifdef INVARIANTS - if (freeblks->fb_chkcnt != 0 && - ((fs->fs_flags & FS_UNCLEAN) == 0 || (flags & LK_NOWAIT) != 0)) - printf("handle_workitem_freeblocks: block count\n"); -#endif /* INVARIANTS */ + KASSERT(freeblks->fb_chkcnt != 0 && + ((fs->fs_flags & FS_UNCLEAN) == 0 || (flags & LK_NOWAIT) != 0), + ("handle_workitem_freeblocks: block count")); ACQUIRE_LOCK(&lk); /* @@ -6089,12 +6087,7 @@ indir_trunc(freework, dbn, lbn) * a complete copy of the indirect block in memory for our use. * Otherwise we have to read the blocks in from the disk. */ -#ifdef notyet - bp = getblk(freeblks->fb_devvp, dbn, (int)fs->fs_bsize, 0, 0, - GB_NOCREAT); -#else bp = incore(&freeblks->fb_devvp->v_bufobj, dbn); -#endif ACQUIRE_LOCK(&lk); if (bp != NULL && (wk = LIST_FIRST(&bp->b_dep)) != NULL) { if (wk->wk_type != D_INDIRDEP || @@ -6109,10 +6102,6 @@ indir_trunc(freework, dbn, lbn) ump->um_numindirdeps -= 1; FREE_LOCK(&lk); } else { -#ifdef notyet - if (bp) - brelse(bp); -#endif FREE_LOCK(&lk); if (bread(freeblks->fb_devvp, dbn, (int)fs->fs_bsize, NOCRED, &bp) != 0) { @@ -7847,7 +7836,9 @@ handle_workitem_freefile(freefile) { struct workhead wkhd; struct fs *fs; +#ifdef DEBUG struct inodedep *idp; +#endif struct ufsmount *ump; int error; @@ -8164,29 +8155,26 @@ initiate_write_inodeblock_ufs1(inodedep, */ for (deplist = 0, adp = TAILQ_FIRST(&inodedep->id_inoupdt); adp; adp = TAILQ_NEXT(adp, ad_next)) { + KASSERT(deplist != 0 && prevlbn >= adp->ad_offset, + ("softdep_write_inodeblock: lbn order")); #ifdef INVARIANTS - if (deplist != 0 && prevlbn >= adp->ad_offset) - panic("softdep_write_inodeblock: lbn order"); prevlbn = adp->ad_offset; - if (adp->ad_offset < NDADDR && - dp->di_db[adp->ad_offset] != adp->ad_newblkno) - panic("%s: direct pointer #%jd mismatch %d != %jd", - "softdep_write_inodeblock", - (intmax_t)adp->ad_offset, - dp->di_db[adp->ad_offset], - (intmax_t)adp->ad_newblkno); - if (adp->ad_offset >= NDADDR && - dp->di_ib[adp->ad_offset - NDADDR] != adp->ad_newblkno) - panic("%s: indirect pointer #%jd mismatch %d != %jd", - "softdep_write_inodeblock", - (intmax_t)adp->ad_offset - NDADDR, - dp->di_ib[adp->ad_offset - NDADDR], - (intmax_t)adp->ad_newblkno); + KASSERT(adp->ad_offset < NDADDR && + dp->di_db[adp->ad_offset] != adp->ad_newblkno, + ("softdep_write_inodeblock: direct pointer #%jd mismatch %d != %jd", + (intmax_t)adp->ad_offset, dp->di_db[adp->ad_offset], + (intmax_t)adp->ad_newblkno)); + KASSERT(adp->ad_offset >= NDADDR && + dp->di_ib[adp->ad_offset - NDADDR] != adp->ad_newblkno, + ("softdep_write_inodeblock: indirect pointer #%jd mismatch %d != %jd", + (intmax_t)adp->ad_offset - NDADDR, + dp->di_ib[adp->ad_offset - NDADDR], + (intmax_t)adp->ad_newblkno)); deplist |= 1 << adp->ad_offset; - if ((adp->ad_state & ATTACHED) == 0) - panic("softdep_write_inodeblock: Unknown state 0x%x", - adp->ad_state); #endif /* INVARIANTS */ + KASSERT((adp->ad_state & ATTACHED) == 0, + ("softdep_write_inodeblock: Unknown state 0x%x", + adp->ad_state)); adp->ad_state &= ~ATTACHED; adp->ad_state |= UNDONE; } @@ -8206,18 +8194,14 @@ initiate_write_inodeblock_ufs1(inodedep, continue; dp->di_size = fs->fs_bsize * adp->ad_offset + adp->ad_oldsize; for (i = adp->ad_offset + 1; i < NDADDR; i++) { -#ifdef INVARIANTS - if (dp->di_db[i] != 0 && (deplist & (1 << i)) == 0) - panic("softdep_write_inodeblock: lost dep1"); -#endif /* INVARIANTS */ + KASSERT(dp->di_db[i] != 0 && (deplist & (1 << i)) == 0, + ("softdep_write_inodeblock: lost dep1")); dp->di_db[i] = 0; } for (i = 0; i < NIADDR; i++) { -#ifdef INVARIANTS - if (dp->di_ib[i] != 0 && - (deplist & ((1 << NDADDR) << i)) == 0) - panic("softdep_write_inodeblock: lost dep2"); -#endif /* INVARIANTS */ + KASSERT(dp->di_ib[i] != 0 && + (deplist & ((1 << NDADDR) << i)) == 0, + ("softdep_write_inodeblock: lost dep2")); dp->di_ib[i] = 0; } return; @@ -8345,21 +8329,20 @@ initiate_write_inodeblock_ufs2(inodedep, */ for (deplist = 0, adp = TAILQ_FIRST(&inodedep->id_extupdt); adp; adp = TAILQ_NEXT(adp, ad_next)) { + KASSERT(deplist != 0 && prevlbn >= adp->ad_offset, + ("softdep_write_inodeblock: lbn order")); #ifdef INVARIANTS - if (deplist != 0 && prevlbn >= adp->ad_offset) - panic("softdep_write_inodeblock: lbn order"); prevlbn = adp->ad_offset; - if (dp->di_extb[adp->ad_offset] != adp->ad_newblkno) - panic("%s: direct pointer #%jd mismatch %jd != %jd", - "softdep_write_inodeblock", - (intmax_t)adp->ad_offset, - (intmax_t)dp->di_extb[adp->ad_offset], - (intmax_t)adp->ad_newblkno); + KASSERT(dp->di_extb[adp->ad_offset] != adp->ad_newblkno, + ("softdep_write_inodeblock: direct pointer #%jd mismatch %jd != %jd", + (intmax_t)adp->ad_offset, + (intmax_t)dp->di_extb[adp->ad_offset], + (intmax_t)adp->ad_newblkno)); deplist |= 1 << adp->ad_offset; - if ((adp->ad_state & ATTACHED) == 0) - panic("softdep_write_inodeblock: Unknown state 0x%x", - adp->ad_state); #endif /* INVARIANTS */ + KASSERT((adp->ad_state & ATTACHED) == 0, + ("softdep_write_inodeblock: Unknown state 0x%x", + adp->ad_state)); adp->ad_state &= ~ATTACHED; adp->ad_state |= UNDONE; } @@ -8377,10 +8360,9 @@ initiate_write_inodeblock_ufs2(inodedep, continue; dp->di_extsize = fs->fs_bsize * adp->ad_offset + adp->ad_oldsize; for (i = adp->ad_offset + 1; i < NXADDR; i++) { -#ifdef INVARIANTS - if (dp->di_extb[i] != 0 && (deplist & (1 << i)) == 0) - panic("softdep_write_inodeblock: lost dep1"); -#endif /* INVARIANTS */ + KASSERT(dp->di_extb[i] != 0 && + (deplist & (1 << i)) == 0, + ("softdep_write_inodeblock: lost dep1")); dp->di_extb[i] = 0; } lastadp = NULL; @@ -8404,29 +8386,27 @@ initiate_write_inodeblock_ufs2(inodedep, */ for (deplist = 0, adp = TAILQ_FIRST(&inodedep->id_inoupdt); adp; adp = TAILQ_NEXT(adp, ad_next)) { + KASSERT(deplist != 0 && prevlbn >= adp->ad_offset, + ("softdep_write_inodeblock: lbn order")); #ifdef INVARIANTS - if (deplist != 0 && prevlbn >= adp->ad_offset) - panic("softdep_write_inodeblock: lbn order"); prevlbn = adp->ad_offset; - if (adp->ad_offset < NDADDR && - dp->di_db[adp->ad_offset] != adp->ad_newblkno) - panic("%s: direct pointer #%jd mismatch %jd != %jd", - "softdep_write_inodeblock", - (intmax_t)adp->ad_offset, - (intmax_t)dp->di_db[adp->ad_offset], - (intmax_t)adp->ad_newblkno); - if (adp->ad_offset >= NDADDR && - dp->di_ib[adp->ad_offset - NDADDR] != adp->ad_newblkno) - panic("%s indirect pointer #%jd mismatch %jd != %jd", - "softdep_write_inodeblock:", - (intmax_t)adp->ad_offset - NDADDR, - (intmax_t)dp->di_ib[adp->ad_offset - NDADDR], - (intmax_t)adp->ad_newblkno); + KASSERT(adp->ad_offset < NDADDR && + dp->di_db[adp->ad_offset] != adp->ad_newblkno, + ("softdep_write_inodeblock: direct pointer #%jd mismatch %jd != %jd", + (intmax_t)adp->ad_offset, + (intmax_t)dp->di_db[adp->ad_offset], + (intmax_t)adp->ad_newblkno)); + KASSERT(adp->ad_offset >= NDADDR && + dp->di_ib[adp->ad_offset - NDADDR] != adp->ad_newblkno, + ("softdep_write_inodeblock: indirect pointer #%jd mismatch %jd != %jd", + (intmax_t)adp->ad_offset - NDADDR, + (intmax_t)dp->di_ib[adp->ad_offset - NDADDR], + (intmax_t)adp->ad_newblkno)); deplist |= 1 << adp->ad_offset; - if ((adp->ad_state & ATTACHED) == 0) - panic("softdep_write_inodeblock: Unknown state 0x%x", - adp->ad_state); #endif /* INVARIANTS */ + KASSERT((adp->ad_state & ATTACHED) == 0, + ("softdep_write_inodeblock: Unknown state 0x%x", + adp->ad_state)); adp->ad_state &= ~ATTACHED; adp->ad_state |= UNDONE; } @@ -8446,18 +8426,14 @@ initiate_write_inodeblock_ufs2(inodedep, continue; dp->di_size = fs->fs_bsize * adp->ad_offset + adp->ad_oldsize; for (i = adp->ad_offset + 1; i < NDADDR; i++) { -#ifdef INVARIANTS - if (dp->di_db[i] != 0 && (deplist & (1 << i)) == 0) - panic("softdep_write_inodeblock: lost dep2"); -#endif /* INVARIANTS */ + KASSERT(dp->di_db[i] != 0 && (deplist & (1 << i)) == 0, + ("softdep_write_inodeblock: lost dep2")); dp->di_db[i] = 0; } for (i = 0; i < NIADDR; i++) { -#ifdef INVARIANTS - if (dp->di_ib[i] != 0 && - (deplist & ((1 << NDADDR) << i)) == 0) - panic("softdep_write_inodeblock: lost dep3"); -#endif /* INVARIANTS */ + KASSERT(dp->di_ib[i] != 0 && + (deplist & ((1 << NDADDR) << i)) == 0, + ("softdep_write_inodeblock: lost dep3")); dp->di_ib[i] = 0; } return; Index: ufs/ffs/ffs_vnops.c =================================================================== --- ufs/ffs/ffs_vnops.c (revision 212799) +++ ufs/ffs/ffs_vnops.c (working copy) @@ -465,10 +465,9 @@ ffs_read(ap) seqcount = ap->a_ioflag >> IO_SEQSHIFT; ip = VTOI(vp); -#ifdef INVARIANTS - if (uio->uio_rw != UIO_READ) - panic("ffs_read: mode"); + KASSERT(uio->uio_rw != UIO_READ, ("ffs_read: mode")); +#ifdef INVARIANTS if (vp->v_type == VLNK) { if ((int)ip->i_size < vp->v_mount->mnt_maxsymlinklen) panic("ffs_read: short symlink"); @@ -667,10 +666,7 @@ ffs_write(ap) seqcount = ap->a_ioflag >> IO_SEQSHIFT; ip = VTOI(vp); -#ifdef INVARIANTS - if (uio->uio_rw != UIO_WRITE) - panic("ffs_write: mode"); -#endif + KASSERT(uio->uio_rw != UIO_WRITE, ("ffs_write: mode")); switch (vp->v_type) { case VREG: @@ -884,11 +880,9 @@ ffs_extread(struct vnode *vp, struct uio fs = ip->i_fs; dp = ip->i_din2; -#ifdef INVARIANTS - if (uio->uio_rw != UIO_READ || fs->fs_magic != FS_UFS2_MAGIC) - panic("ffs_extread: mode"); + KASSERT(uio->uio_rw != UIO_READ || fs->fs_magic != FS_UFS2_MAGIC, + ("ffs_extread: mode")); -#endif orig_resid = uio->uio_resid; KASSERT(orig_resid >= 0, ("ffs_extread: uio->uio_resid < 0")); if (orig_resid == 0) @@ -1036,10 +1030,8 @@ ffs_extwrite(struct vnode *vp, struct ui fs = ip->i_fs; dp = ip->i_din2; -#ifdef INVARIANTS - if (uio->uio_rw != UIO_WRITE || fs->fs_magic != FS_UFS2_MAGIC) - panic("ffs_extwrite: mode"); -#endif + KASSERT(uio->uio_rw != UIO_WRITE || fs->fs_magic != FS_UFS2_MAGIC, + ("ffs_extwrite: mode")); if (ioflag & IO_APPEND) uio->uio_offset = dp->di_extsize; Index: ufs/ffs/ffs_alloc.c =================================================================== --- ufs/ffs/ffs_alloc.c (revision 212799) +++ ufs/ffs/ffs_alloc.c (working copy) @@ -257,9 +257,9 @@ ffs_realloccg(ip, lbprev, bprev, bpref, bp = NULL; ump = ip->i_ump; mtx_assert(UFS_MTX(ump), MA_OWNED); + KASSERT(vp->v_mount->mnt_kern_flag & MNTK_SUSPENDED, + ("ffs_realloccg: allocation on suspended filesystem")); #ifdef INVARIANTS - if (vp->v_mount->mnt_kern_flag & MNTK_SUSPENDED) - panic("ffs_realloccg: allocation on suspended filesystem"); if ((u_int)osize > fs->fs_bsize || fragoff(fs, osize) != 0 || (u_int)nsize > fs->fs_bsize || fragoff(fs, nsize) != 0) { printf( @@ -268,9 +268,8 @@ ffs_realloccg(ip, lbprev, bprev, bpref, nsize, fs->fs_fsmnt); panic("ffs_realloccg: bad size"); } - if (cred == NOCRED) - panic("ffs_realloccg: missing credential"); #endif /* INVARIANTS */ + KASSERT(cred == NOCRED, ("ffs_realloccg: missing credential")); reclaimed = 0; retry: if (priv_check_cred(cred, PRIV_VFS_BLOCKRESERVE, 0) && @@ -455,7 +454,11 @@ static int doreallocblks = 1; SYSCTL_INT(_vfs_ffs, OID_AUTO, doreallocblks, CTLFLAG_RW, &doreallocblks, 0, ""); #ifdef DEBUG -static volatile int prtrealloc = 0; +static int prtrealloc = 0; +static SYSCTL_NODE(_vfs_ffs, OID_AUTO, diagnostics, CTLFLAG_RW, 0, + "FFS filesystem diagnostics"); +SYSCTL_INT(_vfs_ffs_diagnostics, OID_AUTO, prtrealloc, CTLFLAG_RW, &prtrealloc, + 0, ""); #endif int @@ -517,14 +520,14 @@ ffs_reallocblks_ufs1(ap) dbtofsb(fs, buflist->bs_children[i]->b_blkno), fs->fs_bsize)) panic("ffs_reallocblks: unallocated block 1"); for (i = 1; i < len; i++) - if (buflist->bs_children[i]->b_lblkno != start_lbn + i) - panic("ffs_reallocblks: non-logical cluster"); + KASSERT(buflist->bs_children[i]->b_lblkno != start_lbn + i, + ("ffs_reallocblks: non-logical cluster")); blkno = buflist->bs_children[0]->b_blkno; ssize = fsbtodb(fs, fs->fs_frag); for (i = 1; i < len - 1; i++) - if (buflist->bs_children[i]->b_blkno != blkno + (i * ssize)) - panic("ffs_reallocblks: non-physical cluster %d", i); -#endif + KASSERT(buflist->bs_children[i]->b_blkno != blkno + (i * ssize), + ("ffs_reallocblks: non-physical cluster %d", i)); +#endif /* INVARIANTS */ /* * If the latest allocation is in a new cylinder group, assume that * the filesystem has decided to move and do not force it back to @@ -557,11 +560,9 @@ ffs_reallocblks_ufs1(ap) if (end_lvl == 0 || (idp = &end_ap[end_lvl - 1])->in_off + 1 >= len) { ssize = len; } else { -#ifdef INVARIANTS - if (start_lvl > 0 && - start_ap[start_lvl - 1].in_lbn == idp->in_lbn) - panic("ffs_reallocblk: start == end"); -#endif + KASSERT(start_lvl > 0 && + start_ap[start_lvl - 1].in_lbn == idp->in_lbn, + ("INVARIANT: ffs_reallocblk: start == end")); ssize = len - (idp->in_off + 1); if (bread(vp, idp->in_lbn, (int)fs->fs_bsize, NOCRED, &ebp)) goto fail; @@ -598,13 +599,11 @@ ffs_reallocblks_ufs1(ap) bap = ebap; soff = -i; } -#ifdef INVARIANTS - if (!ffs_checkblk(ip, - dbtofsb(fs, buflist->bs_children[i]->b_blkno), fs->fs_bsize)) - panic("ffs_reallocblks: unallocated block 2"); - if (dbtofsb(fs, buflist->bs_children[i]->b_blkno) != *bap) - panic("ffs_reallocblks: alloc mismatch"); -#endif + KASSERT(!ffs_checkblk(ip, + dbtofsb(fs, buflist->bs_children[i]->b_blkno), + fs->fs_bsize), ("ffs_reallocblks: unallocated block 2")); + KASSERT(dbtofsb(fs, buflist->bs_children[i]->b_blkno) != *bap, + ("ffs_reallocblks: alloc mismatch")); #ifdef DEBUG if (prtrealloc) printf(" %d,", *bap); @@ -664,12 +663,10 @@ ffs_reallocblks_ufs1(ap) dbtofsb(fs, buflist->bs_children[i]->b_blkno), fs->fs_bsize, ip->i_number, NULL); buflist->bs_children[i]->b_blkno = fsbtodb(fs, blkno); -#ifdef INVARIANTS - if (!ffs_checkblk(ip, - dbtofsb(fs, buflist->bs_children[i]->b_blkno), fs->fs_bsize)) - panic("ffs_reallocblks: unallocated block 3"); -#endif -#ifdef DEBUG + KASSERT(!ffs_checkblk(ip, + dbtofsb(fs, buflist->bs_children[i]->b_blkno), + fs->fs_bsize), ("ffs_reallocblks: unallocated block 3")); +#ifdef DIAGNOSTIC if (prtrealloc) printf(" %d,", blkno); #endif @@ -721,18 +718,18 @@ ffs_reallocblks_ufs2(ap) end_lbn = start_lbn + len - 1; #ifdef INVARIANTS for (i = 0; i < len; i++) - if (!ffs_checkblk(ip, - dbtofsb(fs, buflist->bs_children[i]->b_blkno), fs->fs_bsize)) - panic("ffs_reallocblks: unallocated block 1"); + KASSERT(!ffs_checkblk(ip, + dbtofsb(fs, buflist->bs_children[i]->b_blkno), + fs->fs_bsize), ("ffs_reallocblks: unallocated block 1")); for (i = 1; i < len; i++) - if (buflist->bs_children[i]->b_lblkno != start_lbn + i) - panic("ffs_reallocblks: non-logical cluster"); + KASSERT(buflist->bs_children[i]->b_lblkno != start_lbn + i, + ("ffs_reallocblks: non-logical cluster")); blkno = buflist->bs_children[0]->b_blkno; ssize = fsbtodb(fs, fs->fs_frag); for (i = 1; i < len - 1; i++) - if (buflist->bs_children[i]->b_blkno != blkno + (i * ssize)) - panic("ffs_reallocblks: non-physical cluster %d", i); -#endif + KASSERT(buflist->bs_children[i]->b_blkno != blkno + (i * ssize), + ("ffs_reallocblks: non-physical cluster %d", i)); +#endif /* INVARIANTS */ /* * If the latest allocation is in a new cylinder group, assume that * the filesystem has decided to move and do not force it back to @@ -765,11 +762,9 @@ ffs_reallocblks_ufs2(ap) if (end_lvl == 0 || (idp = &end_ap[end_lvl - 1])->in_off + 1 >= len) { ssize = len; } else { -#ifdef INVARIANTS - if (start_lvl > 0 && - start_ap[start_lvl - 1].in_lbn == idp->in_lbn) - panic("ffs_reallocblk: start == end"); -#endif + KASSERT(start_lvl > 0 && + start_ap[start_lvl - 1].in_lbn == idp->in_lbn, + ("INVARIANT: ffs_reallocblk: start == end")); ssize = len - (idp->in_off + 1); if (bread(vp, idp->in_lbn, (int)fs->fs_bsize, NOCRED, &ebp)) goto fail; @@ -806,13 +801,11 @@ ffs_reallocblks_ufs2(ap) bap = ebap; soff = -i; } -#ifdef INVARIANTS - if (!ffs_checkblk(ip, - dbtofsb(fs, buflist->bs_children[i]->b_blkno), fs->fs_bsize)) - panic("ffs_reallocblks: unallocated block 2"); - if (dbtofsb(fs, buflist->bs_children[i]->b_blkno) != *bap) - panic("ffs_reallocblks: alloc mismatch"); -#endif + KASSERT(!ffs_checkblk(ip, + dbtofsb(fs, buflist->bs_children[i]->b_blkno), fs->fs_bsize), + ("ffs_reallocblks: unallocated block 2")); + KASSERT(dbtofsb(fs, buflist->bs_children[i]->b_blkno) != *bap, + ("ffs_reallocblks: alloc mismatch")); #ifdef DEBUG if (prtrealloc) printf(" %jd,", (intmax_t)*bap); @@ -872,11 +865,9 @@ ffs_reallocblks_ufs2(ap) dbtofsb(fs, buflist->bs_children[i]->b_blkno), fs->fs_bsize, ip->i_number, NULL); buflist->bs_children[i]->b_blkno = fsbtodb(fs, blkno); -#ifdef INVARIANTS - if (!ffs_checkblk(ip, - dbtofsb(fs, buflist->bs_children[i]->b_blkno), fs->fs_bsize)) - panic("ffs_reallocblks: unallocated block 3"); -#endif + KASSERT(!ffs_checkblk(ip, + dbtofsb(fs, buflist->bs_children[i]->b_blkno), + fs->fs_bsize), ("ffs_reallocblks: unallocated block 3")); #ifdef DEBUG if (prtrealloc) printf(" %jd,", (intmax_t)blkno); @@ -1280,10 +1271,8 @@ ffs_hashalloc(ip, cg, pref, size, rsize, u_int i, icg = cg; mtx_assert(UFS_MTX(ip->i_ump), MA_OWNED); -#ifdef INVARIANTS - if (ITOV(ip)->v_mount->mnt_kern_flag & MNTK_SUSPENDED) - panic("ffs_hashalloc: allocation on suspended filesystem"); -#endif + KASSERT(ITOV(ip)->v_mount->mnt_kern_flag & MNTK_SUSPENDED, + ("ffs_hashalloc: allocation on suspended filesystem")); fs = ip->i_fs; /* * 1: preferred cylinder group Index: ufs/ffs/ffs_balloc.c =================================================================== --- ufs/ffs/ffs_balloc.c (revision 212799) +++ ufs/ffs/ffs_balloc.c (working copy) @@ -226,10 +226,8 @@ ffs_balloc_ufs1(struct vnode *vp, off_t pref = 0; if ((error = ufs_getlbns(vp, lbn, indirs, &num)) != 0) return(error); -#ifdef INVARIANTS - if (num < 1) - panic ("ffs_balloc_ufs1: ufs_getlbns returned indirect block"); -#endif + KASSERT(num < 1, + ("ffs_balloc_ufs1: ufs_getlbns returned indirect block")); saved_inbdflush = ~TDP_INBDFLUSH | (curthread->td_pflags & TDP_INBDFLUSH); curthread->td_pflags |= TDP_INBDFLUSH; @@ -737,10 +735,8 @@ ffs_balloc_ufs2(struct vnode *vp, off_t pref = 0; if ((error = ufs_getlbns(vp, lbn, indirs, &num)) != 0) return(error); -#ifdef INVARIANTS - if (num < 1) - panic ("ffs_balloc_ufs2: ufs_getlbns returned indirect block"); -#endif + KASSERT(num < 1, + ("ffs_balloc_ufs2: ufs_getlbns returned indirect block")); saved_inbdflush = ~TDP_INBDFLUSH | (curthread->td_pflags & TDP_INBDFLUSH); curthread->td_pflags |= TDP_INBDFLUSH; Index: ufs/ffs/ffs_inode.c =================================================================== --- ufs/ffs/ffs_inode.c (revision 212799) +++ ufs/ffs/ffs_inode.c (working copy) @@ -243,10 +243,8 @@ ffs_truncate(vp, length, flags, cred, td if (vp->v_type == VLNK && (ip->i_size < vp->v_mount->mnt_maxsymlinklen || datablocks == 0)) { -#ifdef INVARIANTS - if (length != 0) - panic("ffs_truncate: partial truncate of symlink"); -#endif + KASSERT(length != 0, + ("ffs_truncate: partial truncate of symlink")); bzero(SHORTLINK(ip), (u_int)ip->i_size); ip->i_size = 0; DIP_SET(ip, i_size, 0); @@ -516,16 +514,15 @@ ffs_truncate(vp, length, flags, cred, td done: #ifdef INVARIANTS for (level = SINGLE; level <= TRIPLE; level++) - if (newblks[NDADDR + level] != DIP(ip, i_ib[level])) - panic("ffs_truncate1"); + KASSERT(newblks[NDADDR + level] != DIP(ip, i_ib[level]), + ("ffs_truncate1")); for (i = 0; i < NDADDR; i++) - if (newblks[i] != DIP(ip, i_db[i])) - panic("ffs_truncate2"); + KASSERT(newblks[i] != DIP(ip, i_db[i]), ("ffs_truncate2")); BO_LOCK(bo); - if (length == 0 && + KASSERT(length == 0 && (fs->fs_magic != FS_UFS2_MAGIC || ip->i_din2->di_extsize == 0) && - (bo->bo_dirty.bv_cnt > 0 || bo->bo_clean.bv_cnt > 0)) - panic("ffs_truncate3"); + (bo->bo_dirty.bv_cnt > 0 || bo->bo_clean.bv_cnt > 0), + ("ffs_truncate3")); BO_UNLOCK(bo); #endif /* INVARIANTS */ /* Index: ufs/ffs/ffs_snapshot.c =================================================================== --- ufs/ffs/ffs_snapshot.c (revision 212799) +++ ufs/ffs/ffs_snapshot.c (working copy) @@ -49,6 +49,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -178,17 +179,13 @@ static int ffs_bp_snapblk(struct vnode * * penalty that this imposes, the following flag allows this * crash persistence to be disabled. */ -int dopersistence = 0; - -#ifdef DEBUG -#include +static int dopersistence = 0; SYSCTL_INT(_debug, OID_AUTO, dopersistence, CTLFLAG_RW, &dopersistence, 0, ""); static int snapdebug = 0; SYSCTL_INT(_debug, OID_AUTO, snapdebug, CTLFLAG_RW, &snapdebug, 0, ""); int collectsnapstats = 0; SYSCTL_INT(_debug, OID_AUTO, collectsnapstats, CTLFLAG_RW, &collectsnapstats, 0, ""); -#endif /* DEBUG */ /* * Create a snapshot file and initialize it for the filesystem. @@ -2306,10 +2303,8 @@ ffs_copyonwrite(devvp, bp) blkno=((ufs2_daddr_t *)(ibp->b_data))[indiroff]; bqrelse(ibp); } -#ifdef INVARIANTS - if (blkno == BLK_SNAP && bp->b_lblkno >= 0) - panic("ffs_copyonwrite: bad copy block"); -#endif + KASSERT(blkno == BLK_SNAP && bp->b_lblkno >= 0, + ("ffs_copyonwrite: bad copy block")); if (blkno != 0) continue; /*