Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/ufs/lfs #if DIAGNOSTIC panic ---> KASSERT
details: https://anonhg.NetBSD.org/src/rev/6888b5ef5e01
branches: trunk
changeset: 352058:6888b5ef5e01
user: riastradh <riastradh%NetBSD.org@localhost>
date: Mon Mar 13 14:24:20 2017 +0000
description:
#if DIAGNOSTIC panic ---> KASSERT
Replace some #if DEBUG by this too. DEBUG is only for expensive
assertions; these are not.
diffstat:
sys/ufs/lfs/lfs_alloc.c | 38 ++++---------
sys/ufs/lfs/lfs_bio.c | 33 +++-------
sys/ufs/lfs/lfs_segment.c | 129 +++++++++++++++++---------------------------
sys/ufs/lfs/lfs_syscalls.c | 19 +----
sys/ufs/lfs/lfs_vfsops.c | 18 ++----
sys/ufs/lfs/ulfs_bmap.c | 19 ++----
sys/ufs/lfs/ulfs_vnops.c | 16 ++---
7 files changed, 96 insertions(+), 176 deletions(-)
diffs (truncated from 553 to 300 lines):
diff -r e1cbefc218fc -r 6888b5ef5e01 sys/ufs/lfs/lfs_alloc.c
--- a/sys/ufs/lfs/lfs_alloc.c Mon Mar 13 13:45:53 2017 +0000
+++ b/sys/ufs/lfs/lfs_alloc.c Mon Mar 13 14:24:20 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lfs_alloc.c,v 1.133 2016/08/07 05:09:12 dholland Exp $ */
+/* $NetBSD: lfs_alloc.c,v 1.134 2017/03/13 14:24:20 riastradh Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_alloc.c,v 1.133 2016/08/07 05:09:12 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_alloc.c,v 1.134 2017/03/13 14:24:20 riastradh Exp $");
#if defined(_KERNEL_OPT)
#include "opt_quota.h"
@@ -168,10 +168,8 @@
*/
LFS_GET_HEADFREE(fs, cip, cbp, &oldlast);
LFS_PUT_HEADFREE(fs, cip, cbp, i);
-#ifdef DIAGNOSTIC
- if (lfs_sb_getfreehd(fs) == LFS_UNUSED_INUM)
- panic("inode 0 allocated [2]");
-#endif /* DIAGNOSTIC */
+ KASSERTMSG((lfs_sb_getfreehd(fs) != LFS_UNUSED_INUM),
+ "inode 0 allocated [2]");
/* inode number to stop at (XXX: why *x*max?) */
xmax = i + lfs_sb_getifpb(fs);
@@ -298,10 +296,8 @@
return error;
}
}
-#ifdef DIAGNOSTIC
- if (lfs_sb_getfreehd(fs) == LFS_UNUSED_INUM)
- panic("inode 0 allocated [3]");
-#endif /* DIAGNOSTIC */
+ KASSERTMSG((lfs_sb_getfreehd(fs) != LFS_UNUSED_INUM),
+ "inode 0 allocated [3]");
/* Set superblock modified bit */
mutex_enter(&lfs_lock);
@@ -667,12 +663,8 @@
}
}
}
-#ifdef DIAGNOSTIC
/* XXX: shouldn't this check be further up *before* we trash the fs? */
- if (ino == LFS_UNUSED_INUM) {
- panic("inode 0 freed");
- }
-#endif /* DIAGNOSTIC */
+ KASSERTMSG((ino != LFS_UNUSED_INUM), "inode 0 freed");
/*
* Update the segment summary for the segment where the on-disk
@@ -681,18 +673,12 @@
if (old_iaddr != LFS_UNUSED_DADDR) {
/* load it */
LFS_SEGENTRY(sup, fs, lfs_dtosn(fs, old_iaddr), bp);
-#ifdef DIAGNOSTIC
/* the number of bytes in the segment should not become < 0 */
- if (sup->su_nbytes < DINOSIZE(fs)) {
- printf("lfs_vfree: negative byte count"
- " (segment %" PRIu32 " short by %d)\n",
- lfs_dtosn(fs, old_iaddr),
- (int)DINOSIZE(fs) -
- sup->su_nbytes);
- panic("lfs_vfree: negative byte count");
- sup->su_nbytes = DINOSIZE(fs);
- }
-#endif
+ KASSERTMSG((sup->su_nbytes >= DINOSIZE(fs)),
+ "lfs_vfree: negative byte count"
+ " (segment %" PRIu32 " short by %d)\n",
+ lfs_dtosn(fs, old_iaddr),
+ (int)DINOSIZE(fs) - sup->su_nbytes);
/* update the number of bytes in the segment */
sup->su_nbytes -= DINOSIZE(fs);
/* write the segment entry */
diff -r e1cbefc218fc -r 6888b5ef5e01 sys/ufs/lfs/lfs_bio.c
--- a/sys/ufs/lfs/lfs_bio.c Mon Mar 13 13:45:53 2017 +0000
+++ b/sys/ufs/lfs/lfs_bio.c Mon Mar 13 14:24:20 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lfs_bio.c,v 1.135 2015/10/03 09:31:29 hannken Exp $ */
+/* $NetBSD: lfs_bio.c,v 1.136 2017/03/13 14:24:20 riastradh Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2002, 2003, 2008 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_bio.c,v 1.135 2015/10/03 09:31:29 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_bio.c,v 1.136 2017/03/13 14:24:20 riastradh Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -315,11 +315,9 @@
} */ *ap = v;
struct buf *bp = ap->a_bp;
-#ifdef DIAGNOSTIC
- if (VTOI(bp->b_vp)->i_lfs->lfs_ronly == 0 && (bp->b_flags & B_ASYNC)) {
- panic("bawrite LFS buffer");
- }
-#endif /* DIAGNOSTIC */
+ KASSERTMSG((VTOI(bp->b_vp)->i_lfs->lfs_ronly ||
+ !(bp->b_flags & B_ASYNC)),
+ "bawrite LFS buffer");
return lfs_bwrite_ext(bp, 0);
}
@@ -385,10 +383,7 @@
#endif
lfs_wakeup_cleaner(fs);
-#ifdef DIAGNOSTIC
- if (LFS_SEGLOCK_HELD(fs))
- panic("lfs_availwait: deadlock");
-#endif
+ KASSERTMSG(!LFS_SEGLOCK_HELD(fs), "lfs_availwait: deadlock");
error = tsleep(&fs->lfs_availsleep, PCATCH | PUSER,
"cleaner", 0);
if (error)
@@ -717,12 +712,8 @@
bp->b_data = lfs_malloc(fs, nbytes, type);
/* memset(bp->b_data, 0, nbytes); */
}
-#ifdef DIAGNOSTIC
- if (vp == NULL)
- panic("vp is NULL in lfs_newbuf");
- if (bp == NULL)
- panic("bp is NULL after malloc in lfs_newbuf");
-#endif
+ KASSERT(vp != NULL);
+ KASSERT(bp != NULL);
bp->b_bufsize = size;
bp->b_bcount = size;
@@ -778,11 +769,9 @@
KASSERT(bp->b_iodone == NULL);
n++;
size += bp->b_bufsize;
-#ifdef DIAGNOSTIC
- if (n > nbuf)
- panic("lfs_countlocked: this can't happen: more"
- " buffers locked than exist");
-#endif
+ KASSERTMSG((n <= nbuf),
+ "lfs_countlocked: this can't happen: more"
+ " buffers locked than exist");
}
/*
* Theoretically this function never really does anything.
diff -r e1cbefc218fc -r 6888b5ef5e01 sys/ufs/lfs/lfs_segment.c
--- a/sys/ufs/lfs/lfs_segment.c Mon Mar 13 13:45:53 2017 +0000
+++ b/sys/ufs/lfs/lfs_segment.c Mon Mar 13 14:24:20 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lfs_segment.c,v 1.263 2015/10/19 04:21:48 dholland Exp $ */
+/* $NetBSD: lfs_segment.c,v 1.264 2017/03/13 14:24:20 riastradh Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_segment.c,v 1.263 2015/10/19 04:21:48 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_segment.c,v 1.264 2017/03/13 14:24:20 riastradh Exp $");
#ifdef DEBUG
# define vndebug(vp, str) do { \
@@ -906,10 +906,8 @@
ip->i_lfs_fragsize[i] < lfs_sb_getbsize(fs))
++frag;
}
-#ifdef DIAGNOSTIC
- if (frag > 1)
- panic("lfs_writefile: more than one fragment!");
-#endif
+ KASSERTMSG((frag <= 1),
+ "lfs_writefile: more than one fragment! frag=%d", frag);
if (IS_FLUSHING(fs, vp) ||
(frag == 0 && (lfs_writeindir || (sp->seg_flags & SEGM_CKP)))) {
lfs_gather(fs, sp, vp, lfs_match_indir);
@@ -992,27 +990,21 @@
*/
if (daddr != LFS_UNUSED_DADDR) {
u_int32_t oldsn = lfs_dtosn(fs, daddr);
-#ifdef DIAGNOSTIC
- int ndupino = (sp->seg_number == oldsn) ? sp->ndupino : 0;
-#endif
+ int ndupino __diagused =
+ (sp->seg_number == oldsn) ? sp->ndupino : 0;
LFS_SEGENTRY(sup, fs, oldsn, bp);
-#ifdef DIAGNOSTIC
- if (sup->su_nbytes + DINOSIZE(fs) * ndupino < DINOSIZE(fs)) {
- printf("lfs_writeinode: negative bytes "
- "(segment %" PRIu32 " short by %d, "
- "oldsn=%" PRIu32 ", cursn=%" PRIu32
- ", daddr=%" PRId64 ", su_nbytes=%u, "
- "ndupino=%d)\n",
- lfs_dtosn(fs, daddr),
- (int)DINOSIZE(fs) *
- (1 - sp->ndupino) - sup->su_nbytes,
- oldsn, sp->seg_number, daddr,
- (unsigned int)sup->su_nbytes,
- sp->ndupino);
- panic("lfs_writeinode: negative bytes");
- sup->su_nbytes = DINOSIZE(fs);
- }
-#endif
+ KASSERTMSG(((sup->su_nbytes + DINOSIZE(fs)*ndupino)
+ >= DINOSIZE(fs)),
+ "lfs_writeinode: negative bytes "
+ "(segment %" PRIu32 " short by %d, "
+ "oldsn=%" PRIu32 ", cursn=%" PRIu32
+ ", daddr=%" PRId64 ", su_nbytes=%u, "
+ "ndupino=%d)\n",
+ lfs_dtosn(fs, daddr),
+ (int)DINOSIZE(fs) * (1 - sp->ndupino) - sup->su_nbytes,
+ oldsn, sp->seg_number, daddr,
+ (unsigned int)sup->su_nbytes,
+ sp->ndupino);
DLOG((DLOG_SU, "seg %d -= %d for ino %d inode\n",
lfs_dtosn(fs, daddr), DINOSIZE(fs), ino));
sup->su_nbytes -= DINOSIZE(fs);
@@ -1313,10 +1305,8 @@
* If full, finish this segment. We may be doing I/O, so
* release and reacquire the splbio().
*/
-#ifdef DIAGNOSTIC
- if (sp->vp == NULL)
- panic ("lfs_gatherblock: Null vp in segment");
-#endif
+ KASSERTMSG((sp->vp != NULL),
+ "lfs_gatherblock: Null vp in segment");
fs = sp->fs;
blksinblk = howmany(bp->b_bcount, lfs_sb_getbsize(fs));
if (sp->sum_bytes_left < sizeof(int32_t) * blksinblk ||
@@ -1545,37 +1535,26 @@
*/
if (daddr > 0) {
u_int32_t oldsn = lfs_dtosn(fs, daddr);
-#ifdef DIAGNOSTIC
- int ndupino;
+ int ndupino __diagused = (sp && sp->seg_number == oldsn ?
+ sp->ndupino : 0);
- if (sp && sp->seg_number == oldsn) {
- ndupino = sp->ndupino;
- } else {
- ndupino = 0;
- }
-#endif
KASSERT(oldsn < lfs_sb_getnseg(fs));
if (lbn >= 0 && lbn < ULFS_NDADDR)
osize = ip->i_lfs_fragsize[lbn];
else
osize = lfs_sb_getbsize(fs);
LFS_SEGENTRY(sup, fs, oldsn, bp);
-#ifdef DIAGNOSTIC
- if (sup->su_nbytes + DINOSIZE(fs) * ndupino < osize) {
- printf("lfs_updatemeta: negative bytes "
- "(segment %" PRIu32 " short by %" PRId64
- ")\n", lfs_dtosn(fs, daddr),
- (int64_t)osize -
- (DINOSIZE(fs) * ndupino + sup->su_nbytes));
- printf("lfs_updatemeta: ino %llu, lbn %" PRId64
- ", addr = 0x%" PRIx64 "\n",
- (unsigned long long)ip->i_number, lbn, daddr);
- printf("lfs_updatemeta: ndupino=%d\n", ndupino);
- panic("lfs_updatemeta: negative bytes");
- sup->su_nbytes = osize -
- DINOSIZE(fs) * ndupino;
- }
-#endif
+ KASSERTMSG(((sup->su_nbytes + DINOSIZE(fs)*ndupino) >= osize),
+ "lfs_updatemeta: negative bytes "
+ "(segment %" PRIu32 " short by %" PRId64
+ ")\n"
+ "lfs_updatemeta: ino %llu, lbn %" PRId64
+ ", addr = 0x%" PRIx64 "\n"
+ "lfs_updatemeta: ndupino=%d",
+ lfs_dtosn(fs, daddr),
+ (int64_t)osize - (DINOSIZE(fs) * ndupino + sup->su_nbytes),
+ (unsigned long long)ip->i_number, lbn, daddr,
+ ndupino);
DLOG((DLOG_SU, "seg %" PRIu32 " -= %d for ino %d lbn %" PRId64
" db 0x%" PRIx64 "\n",
lfs_dtosn(fs, daddr), osize,
@@ -2292,15 +2271,13 @@
cbp->b_cflags |= BC_BUSY;
cbp->b_bcount = 0;
-#if defined(DEBUG) && defined(DIAGNOSTIC)
- if (bpp - sp->bpp > (lfs_sb_getsumsize(fs) - SEGSUM_SIZE(fs))
Home |
Main Index |
Thread Index |
Old Index