diff options
author | Eivind Eklund <eivind@FreeBSD.org> | 1999-01-08 17:31:30 +0000 |
---|---|---|
committer | Eivind Eklund <eivind@FreeBSD.org> | 1999-01-08 17:31:30 +0000 |
commit | 5526d2d920eb17b1507499f35b275b486f7fe8d0 (patch) | |
tree | c3aa8110c730b536d4b76b776fd65a60d1a70818 /sys/kern | |
parent | 95ddc5daa5374332a4bc16c64c498099fa823adf (diff) | |
download | src-5526d2d920eb17b1507499f35b275b486f7fe8d0.tar.gz src-5526d2d920eb17b1507499f35b275b486f7fe8d0.zip |
Split DIAGNOSTIC -> DIAGNOSTIC, INVARIANTS, and INVARIANT_SUPPORT as
discussed on -hackers.
Introduce 'KASSERT(assertion, ("panic message", args))' for simple
check + panic.
Reviewed by: msmith
Notes
Notes:
svn path=/head/; revision=42408
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/kern_descrip.c | 4 | ||||
-rw-r--r-- | sys/kern/kern_lock.c | 11 | ||||
-rw-r--r-- | sys/kern/kern_malloc.c | 43 | ||||
-rw-r--r-- | sys/kern/kern_proc.c | 24 | ||||
-rw-r--r-- | sys/kern/kern_sig.c | 14 | ||||
-rw-r--r-- | sys/kern/kern_subr.c | 24 | ||||
-rw-r--r-- | sys/kern/kern_synch.c | 41 | ||||
-rw-r--r-- | sys/kern/subr_autoconf.c | 8 | ||||
-rw-r--r-- | sys/kern/subr_rlist.c | 16 | ||||
-rw-r--r-- | sys/kern/tty.c | 8 | ||||
-rw-r--r-- | sys/kern/tty_snoop.c | 11 | ||||
-rw-r--r-- | sys/kern/uipc_socket.c | 19 | ||||
-rw-r--r-- | sys/kern/vfs_bio.c | 50 | ||||
-rw-r--r-- | sys/kern/vfs_cluster.c | 27 | ||||
-rw-r--r-- | sys/kern/vfs_export.c | 41 | ||||
-rw-r--r-- | sys/kern/vfs_lookup.c | 31 | ||||
-rw-r--r-- | sys/kern/vfs_subr.c | 41 |
17 files changed, 134 insertions, 279 deletions
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index 8fc26b20f486..1d18a86d98a2 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)kern_descrip.c 8.6 (Berkeley) 4/19/94 - * $Id: kern_descrip.c,v 1.56 1998/11/11 10:03:54 truckman Exp $ + * $Id: kern_descrip.c,v 1.57 1998/11/11 10:55:56 truckman Exp $ */ #include "opt_compat.h" @@ -845,7 +845,7 @@ ffree(fp) { LIST_REMOVE(fp, f_list); crfree(fp->f_cred); -#ifdef DIAGNOSTIC +#if defined(DIAGNOSTIC) || defined(INVARIANTS) fp->f_count = 0; #endif nfiles--; diff --git a/sys/kern/kern_lock.c b/sys/kern/kern_lock.c index f411f145fdfc..0bf31d07c601 100644 --- a/sys/kern/kern_lock.c +++ b/sys/kern/kern_lock.c @@ -38,7 +38,7 @@ * SUCH DAMAGE. * * @(#)kern_lock.c 8.18 (Berkeley) 5/21/95 - * $Id: kern_lock.c,v 1.19 1998/04/17 04:53:44 bde Exp $ + * $Id: kern_lock.c,v 1.20 1998/11/26 18:50:23 eivind Exp $ */ #include "opt_lint.h" @@ -83,14 +83,7 @@ sharelock(struct lock *lkp, int incr) { static LOCK_INLINE void shareunlock(struct lock *lkp, int decr) { -#if defined(DIAGNOSTIC) - if (lkp->lk_sharecount < decr) -#if defined(DDB) - Debugger("shareunlock: count < decr"); -#else - panic("shareunlock: count < decr"); -#endif -#endif + KASSERT(lkp->lk_sharecount >= decr, ("shareunlock: count < decr")); if (lkp->lk_sharecount == decr) { lkp->lk_flags &= ~LK_SHARE_NONZERO; diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c index 1ced96aa210f..4cd7b7317665 100644 --- a/sys/kern/kern_malloc.c +++ b/sys/kern/kern_malloc.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)kern_malloc.c 8.3 (Berkeley) 1/4/94 - * $Id: kern_malloc.c,v 1.48 1998/10/25 17:44:51 phk Exp $ + * $Id: kern_malloc.c,v 1.49 1998/11/10 08:46:24 peter Exp $ */ #include "opt_vm.h" @@ -64,7 +64,7 @@ static char *kmembase; static char *kmemlimit; static int vm_kmem_size; -#ifdef DIAGNOSTIC +#if defined(INVARIANTS) /* * This structure provides a set of masks to catch unaligned frees. */ @@ -94,11 +94,11 @@ struct freelist { long spare1; caddr_t next; }; -#else /* !DIAGNOSTIC */ +#else /* !INVARIANTS */ struct freelist { caddr_t next; }; -#endif /* DIAGNOSTIC */ +#endif /* INVARIANTS */ /* * Allocate a block of memory @@ -115,7 +115,7 @@ malloc(size, type, flags) long indx, npg, allocsize; int s; caddr_t va, cp, savedlist; -#ifdef DIAGNOSTIC +#ifdef INVARIANTS long *end, *lp; int copysize; char *savedtype; @@ -138,7 +138,7 @@ malloc(size, type, flags) tsleep((caddr_t)ksp, PSWP+2, type->ks_shortdesc, 0); } ksp->ks_size |= 1 << indx; -#ifdef DIAGNOSTIC +#ifdef INVARIANTS copysize = 1 << indx < MAX_COPY ? 1 << indx : MAX_COPY; #endif if (kbp->kb_next == NULL) { @@ -174,7 +174,7 @@ malloc(size, type, flags) kbp->kb_next = cp = va + (npg * PAGE_SIZE) - allocsize; for (;;) { freep = (struct freelist *)cp; -#ifdef DIAGNOSTIC +#ifdef INVARIANTS /* * Copy in known text to detect modification * after freeing. @@ -183,7 +183,7 @@ malloc(size, type, flags) for (lp = (long *)cp; lp < end; lp++) *lp = WEIRD_ADDR; freep->type = M_FREE; -#endif /* DIAGNOSTIC */ +#endif /* INVARIANTS */ if (cp <= va) break; cp -= allocsize; @@ -195,7 +195,7 @@ malloc(size, type, flags) } va = kbp->kb_next; kbp->kb_next = ((struct freelist *)va)->next; -#ifdef DIAGNOSTIC +#ifdef INVARIANTS freep = (struct freelist *)va; savedtype = (char *) type->ks_shortdesc; #if BYTE_ORDER == BIG_ENDIAN @@ -219,7 +219,7 @@ malloc(size, type, flags) break; } freep->spare0 = 0; -#endif /* DIAGNOSTIC */ +#endif /* INVARIANTS */ kup = btokup(va); if (kup->ku_indx != indx) panic("malloc: wrong bucket"); @@ -251,7 +251,7 @@ free(addr, type) register struct freelist *freep; long size; int s; -#ifdef DIAGNOSTIC +#ifdef INVARIANTS struct freelist *fp; long *end, *lp, alloc, copysize; #endif @@ -260,16 +260,13 @@ free(addr, type) if (!type->ks_next) panic("freeing with unknown type (%s)", type->ks_shortdesc); -#ifdef DIAGNOSTIC - if ((char *)addr < kmembase || (char *)addr >= kmemlimit) { - panic("free: address %p out of range", (void *)addr); - } -#endif + KASSERT(kmembase <= (char *)addr && (char *)addr < kmemlimit, + ("free: address %p out of range", (void *)addr)); kup = btokup(addr); size = 1 << kup->ku_indx; kbp = &bucket[kup->ku_indx]; s = splmem(); -#ifdef DIAGNOSTIC +#ifdef INVARIANTS /* * Check for returns of data that do not point to the * beginning of the allocation. @@ -281,7 +278,7 @@ free(addr, type) if (((uintptr_t)(void *)addr & alloc) != 0) panic("free: unaligned addr %p, size %ld, type %s, mask %ld", (void *)addr, size, type->ks_shortdesc, alloc); -#endif /* DIAGNOSTIC */ +#endif /* INVARIANTS */ if (size > MAXALLOCSAVE) { kmem_free(kmem_map, (vm_offset_t)addr, ctob(kup->ku_pagecnt)); size = kup->ku_pagecnt << PAGE_SHIFT; @@ -297,7 +294,7 @@ free(addr, type) return; } freep = (struct freelist *)addr; -#ifdef DIAGNOSTIC +#ifdef INVARIANTS /* * Check for multiple frees. Use a quick check to see if * it looks free before laboriously searching the freelist. @@ -306,11 +303,9 @@ free(addr, type) fp = (struct freelist *)kbp->kb_next; while (fp) { if (fp->spare0 != WEIRD_ADDR) { - printf("trashed free item %p\n", fp); - panic("free: free item modified"); + panic("free: free item %p modified", fp); } else if (addr == (caddr_t)fp) { - printf("multiple freed item %p\n", addr); - panic("free: multiple free"); + panic("free: multiple freed item %p", addr); } fp = (struct freelist *)fp->next; } @@ -326,7 +321,7 @@ free(addr, type) for (lp = (long *)addr; lp < end; lp++) *lp = WEIRD_ADDR; freep->type = type; -#endif /* DIAGNOSTIC */ +#endif /* INVARIANTS */ kup->ku_freecnt++; if (kup->ku_freecnt >= kbp->kb_elmpercl) if (kup->ku_freecnt > kbp->kb_elmpercl) diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c index 9f046a31e1fe..313a9e7fd01d 100644 --- a/sys/kern/kern_proc.c +++ b/sys/kern/kern_proc.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)kern_proc.c 8.7 (Berkeley) 2/14/95 - * $Id: kern_proc.c,v 1.39 1998/11/11 10:03:55 truckman Exp $ + * $Id: kern_proc.c,v 1.40 1998/11/11 10:55:56 truckman Exp $ */ #include <sys/param.h> @@ -195,22 +195,18 @@ enterpgrp(p, pgid, mksess) { register struct pgrp *pgrp = pgfind(pgid); -#ifdef DIAGNOSTIC - if (pgrp != NULL && mksess) /* firewalls */ - panic("enterpgrp: setsid into non-empty pgrp"); - if (SESS_LEADER(p)) - panic("enterpgrp: session leader attempted setpgrp"); -#endif + KASSERT(pgrp == NULL || !mksess, + ("enterpgrp: setsid into non-empty pgrp")); + KASSERT(!SESS_LEADER(p), + ("enterpgrp: session leader attempted setpgrp")); if (pgrp == NULL) { pid_t savepid = p->p_pid; struct proc *np; /* * new process group */ -#ifdef DIAGNOSTIC - if (p->p_pid != pgid) - panic("enterpgrp: new pgrp and pid != pgid"); -#endif + KASSERT(p->p_pid == pgid, + ("enterpgrp: new pgrp and pid != pgid")); MALLOC(pgrp, struct pgrp *, sizeof(struct pgrp), M_PGRP, M_WAITOK); if ((np = pfind(savepid)) == NULL || np != p) @@ -232,10 +228,8 @@ enterpgrp(p, pgid, mksess) sizeof(sess->s_login)); p->p_flag &= ~P_CONTROLT; pgrp->pg_session = sess; -#ifdef DIAGNOSTIC - if (p != curproc) - panic("enterpgrp: mksession and p != curproc"); -#endif + KASSERT(p == curproc, + ("enterpgrp: mksession and p != curproc")); } else { pgrp->pg_session = p->p_session; pgrp->pg_session->s_count++; diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c index dd4a4318ae3d..e9a51d4c76f3 100644 --- a/sys/kern/kern_sig.c +++ b/sys/kern/kern_sig.c @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)kern_sig.c 8.7 (Berkeley) 4/18/94 - * $Id: kern_sig.c,v 1.50 1998/12/02 01:53:48 eivind Exp $ + * $Id: kern_sig.c,v 1.51 1998/12/19 02:55:33 julian Exp $ */ #include "opt_compat.h" @@ -1183,10 +1183,8 @@ postsig(signum) register sig_t action; int code, mask, returnmask; -#ifdef DIAGNOSTIC - if (signum == 0) - panic("postsig"); -#endif + KASSERT(signum != 0, ("postsig")); + mask = sigmask(signum); p->p_siglist &= ~mask; action = ps->ps_sigact[signum]; @@ -1214,10 +1212,8 @@ postsig(signum) /* * If we get here, the signal must be caught. */ -#ifdef DIAGNOSTIC - if (action == SIG_IGN || (p->p_sigmask & mask)) - panic("postsig action"); -#endif + KASSERT(action != SIG_IGN && (p->p_sigmask & mask) == 0, + ("postsig action")); /* * Set the new mask value and also defer further * occurences of this signal. diff --git a/sys/kern/kern_subr.c b/sys/kern/kern_subr.c index 548cd20e1c8b..d775d970a5ce 100644 --- a/sys/kern/kern_subr.c +++ b/sys/kern/kern_subr.c @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)kern_subr.c 8.3 (Berkeley) 1/21/94 - * $Id: kern_subr.c,v 1.21 1998/07/15 02:32:10 bde Exp $ + * $Id: kern_subr.c,v 1.22 1998/08/04 09:21:04 phk Exp $ */ #include <sys/param.h> @@ -61,12 +61,11 @@ uiomove(cp, n, uio) u_int cnt; int error; -#ifdef DIAGNOSTIC - if (uio->uio_rw != UIO_READ && uio->uio_rw != UIO_WRITE) - panic("uiomove: mode"); - if (uio->uio_segflg == UIO_USERSPACE && uio->uio_procp != curproc) - panic("uiomove proc"); -#endif + KASSERT(uio->uio_rw == UIO_READ || uio->uio_rw == UIO_WRITE, + ("uiomove: mode")); + KASSERT(uio->uio_segflg != UIO_USERSPACE || uio->uio_procp == curproc, + ("uiomove proc")); + while (n > 0 && uio->uio_resid) { iov = uio->uio_iov; cnt = iov->iov_len; @@ -120,12 +119,11 @@ uiomoveco(cp, n, uio, obj) u_int cnt; int error; -#ifdef DIAGNOSTIC - if (uio->uio_rw != UIO_READ && uio->uio_rw != UIO_WRITE) - panic("uiomove: mode"); - if (uio->uio_segflg == UIO_USERSPACE && uio->uio_procp != curproc) - panic("uiomove proc"); -#endif + KASSERT(uio->uio_rw == UIO_READ || uio->uio_rw == UIO_WRITE, + ("uiomoveco: mode")); + KASSERT(uio->uio_segflg != UIO_USERSPACE || uio->uio_procp == curproc, + ("uiomoveco proc")); + while (n > 0 && uio->uio_resid) { iov = uio->uio_iov; cnt = iov->iov_len; diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c index 17b2a947db19..3a9391de88c2 100644 --- a/sys/kern/kern_synch.c +++ b/sys/kern/kern_synch.c @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)kern_synch.c 8.9 (Berkeley) 5/19/95 - * $Id: kern_synch.c,v 1.69 1998/11/27 11:44:22 dg Exp $ + * $Id: kern_synch.c,v 1.70 1998/12/21 07:41:51 dillon Exp $ */ #include "opt_ktrace.h" @@ -401,20 +401,11 @@ tsleep(ident, priority, wmesg, timo) splx(s); return (0); } -#ifdef DIAGNOSTIC - if(p == NULL) - panic("tsleep1"); - if (ident == NULL || p->p_stat != SRUN) - panic("tsleep"); - /* XXX This is not exhaustive, just the most common case */ -#ifdef NOTDEF - /* - * This can happen legitimately now with asleep()/await() - */ - if ((p->p_procq.tqe_prev != NULL) && (*p->p_procq.tqe_prev == p)) - panic("sleeping process already on another queue"); -#endif -#endif + + KASSERT(p != NULL, ("tsleep1")); + KASSERT(ident != NULL && p->p_stat == SRUN, + ("tsleep")); + /* * Process may be sitting on a slpque if asleep() was called, remove * it before re-adding. @@ -706,16 +697,6 @@ wakeup(ident) qp = &slpque[LOOKUP(ident)]; restart: for (p = qp->tqh_first; p != NULL; p = p->p_procq.tqe_next) { -#ifdef DIAGNOSTIC -#ifdef NOTDEF - /* - * The process can legitimately be running now with - * asleep()/await(). - */ - if (p->p_stat != SSLEEP && p->p_stat != SSTOP) - panic("wakeup"); -#endif -#endif if (p->p_wchan == ident) { TAILQ_REMOVE(qp, p, p_procq); p->p_wchan = 0; @@ -757,16 +738,6 @@ wakeup_one(ident) qp = &slpque[LOOKUP(ident)]; for (p = qp->tqh_first; p != NULL; p = p->p_procq.tqe_next) { -#ifdef DIAGNOSTIC -#ifdef NOTDEF - /* - * The process can legitimately be running now with - * asleep()/await(). - */ - if (p->p_stat != SSLEEP && p->p_stat != SSTOP) - panic("wakeup_one"); -#endif -#endif if (p->p_wchan == ident) { TAILQ_REMOVE(qp, p, p_procq); p->p_wchan = 0; diff --git a/sys/kern/subr_autoconf.c b/sys/kern/subr_autoconf.c index 8dfba39421c9..92347324ec60 100644 --- a/sys/kern/subr_autoconf.c +++ b/sys/kern/subr_autoconf.c @@ -41,7 +41,7 @@ * * @(#)subr_autoconf.c 8.1 (Berkeley) 6/10/93 * - * $Id: subr_autoconf.c,v 1.6 1997/11/18 12:43:41 bde Exp $ + * $Id: subr_autoconf.c,v 1.7 1998/12/04 22:54:51 archie Exp $ */ #include <sys/param.h> @@ -334,10 +334,8 @@ evcnt_attach(dev, name, ev) { static struct evcnt **nextp = &allevents; -#ifdef DIAGNOSTIC - if (strlen(name) >= sizeof(ev->ev_name)) - panic("evcnt_attach"); -#endif + KASSERT(strlen(name) < sizeof(ev->ev_name), ("evcnt_attach")); + /* ev->ev_next = NULL; */ ev->ev_dev = dev; /* ev->ev_count = 0; */ diff --git a/sys/kern/subr_rlist.c b/sys/kern/subr_rlist.c index 33ac63289046..c3fdabf51a65 100644 --- a/sys/kern/subr_rlist.c +++ b/sys/kern/subr_rlist.c @@ -54,7 +54,7 @@ * functioning of this software, nor does the author assume any responsibility * for damages incurred with its use. * - * $Id: subr_rlist.c,v 1.26 1998/04/15 17:46:25 bde Exp $ + * $Id: subr_rlist.c,v 1.27 1998/08/05 14:06:04 dg Exp $ */ #include <sys/param.h> @@ -137,16 +137,14 @@ rlist_free(rlh, start, end) while (cur_rlp != NULL) { if (start < cur_rlp->rl_start) break; -#ifdef DIAGNOSTIC if (prev_rlp) { - if (prev_rlp->rl_end + 1 == cur_rlp->rl_start) - panic("rlist_free: missed coalesce opportunity"); - if (prev_rlp->rl_end == cur_rlp->rl_start) - panic("rlist_free: entries overlap"); - if (prev_rlp->rl_end > cur_rlp->rl_start) - panic("entries out of order"); + KASSERT(prev_rlp->rl_end + 1 != cur_rlp->rl_start, + ("rlist_free: missed coalesce opportunity")); + KASSERT(prev_rlp->rl_end != cur_rlp->rl_start, + ("rlist_free: entries overlap")); + KASSERT(prev_rlp->rl_end <= cur_rlp->rl_start, + ("entries out of order")); } -#endif prev_rlp = cur_rlp; cur_rlp = cur_rlp->rl_next; } diff --git a/sys/kern/tty.c b/sys/kern/tty.c index 4d7dfacb865c..1adf784ddfe1 100644 --- a/sys/kern/tty.c +++ b/sys/kern/tty.c @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)tty.c 8.8 (Berkeley) 1/21/94 - * $Id: tty.c,v 1.109 1998/12/07 07:59:20 ache Exp $ + * $Id: tty.c,v 1.110 1998/12/08 10:22:07 bde Exp $ */ /*- @@ -1310,10 +1310,8 @@ ttrstrt(tp_arg) struct tty *tp; int s; -#ifdef DIAGNOSTIC - if (tp_arg == NULL) - panic("ttrstrt"); -#endif + KASSERT(tp_arg != NULL, ("ttrstrt")); + tp = tp_arg; s = spltty(); diff --git a/sys/kern/tty_snoop.c b/sys/kern/tty_snoop.c index c4b13e575e25..06f17dd6e71e 100644 --- a/sys/kern/tty_snoop.c +++ b/sys/kern/tty_snoop.c @@ -135,10 +135,8 @@ snpread(dev, uio, flag) caddr_t from; char *nbuf; -#ifdef DIAGNOSTIC - if ((snp->snp_len + snp->snp_base) > snp->snp_blen) - panic("snoop buffer error"); -#endif + KASSERT(snp->snp_len + snp->snp_base <= snp->snp_blen, + ("snoop buffer error")); if (snp->snp_tty == NULL) return (EIO); @@ -212,10 +210,9 @@ snpin(snp, buf, n) if (n == 0) return 0; -#ifdef DIAGNOSTIC - if (n < 0) - panic("bad snoop char count"); + KASSERT(n > 0, ("negative snoop char count")); +#ifdef DIAGNOSTIC if (!(snp->snp_flags & SNOOP_OPEN)) { printf("Snoop: data coming to closed device.\n"); return 0; diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index b1f64fe2a247..f7fe5a705cef 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)uipc_socket.c 8.3 (Berkeley) 4/15/94 - * $Id: uipc_socket.c,v 1.46 1998/11/11 10:03:56 truckman Exp $ + * $Id: uipc_socket.c,v 1.47 1998/12/07 21:58:29 archie Exp $ */ #include <sys/param.h> @@ -637,10 +637,7 @@ restart: (so->so_rcv.sb_cc < so->so_rcv.sb_lowat || ((flags & MSG_WAITALL) && uio->uio_resid <= so->so_rcv.sb_hiwat)) && m->m_nextpkt == 0 && (pr->pr_flags & PR_ATOMIC) == 0)) { -#ifdef DIAGNOSTIC - if (m == 0 && so->so_rcv.sb_cc) - panic("receive 1"); -#endif + KASSERT(m != 0 || !so->so_rcv.sb_cc, ("receive 1")); if (so->so_error) { if (m) goto dontblock; @@ -683,10 +680,7 @@ dontblock: uio->uio_procp->p_stats->p_ru.ru_msgrcv++; nextrecord = m->m_nextpkt; if (pr->pr_flags & PR_ADDR) { -#ifdef DIAGNOSTIC - if (m->m_type != MT_SONAME) - panic("receive 1a"); -#endif + KASSERT(m->m_type == MT_SONAME, ("receive 1a")); orig_resid = 0; if (psa) *psa = dup_sockaddr(mtod(m, struct sockaddr *), @@ -740,10 +734,9 @@ dontblock: break; } else if (type == MT_OOBDATA) break; -#ifdef DIAGNOSTIC - else if (m->m_type != MT_DATA && m->m_type != MT_HEADER) - panic("receive 3"); -#endif + else + KASSERT(m->m_type == MT_DATA || m->m_type == MT_HEADER, + ("receive 3")); so->so_state &= ~SS_RCVATMARK; len = uio->uio_resid; if (so->so_oobmark && len > so->so_oobmark - offset) diff --git a/sys/kern/vfs_bio.c b/sys/kern/vfs_bio.c index a84f06363c52..28d8a03868a2 100644 --- a/sys/kern/vfs_bio.c +++ b/sys/kern/vfs_bio.c @@ -11,7 +11,7 @@ * 2. Absolutely no warranty of function or purpose is made by the author * John S. Dyson. * - * $Id: vfs_bio.c,v 1.188 1998/12/22 14:43:58 luoqi Exp $ + * $Id: vfs_bio.c,v 1.189 1998/12/22 18:57:30 dillon Exp $ */ /* @@ -692,10 +692,7 @@ brelse(struct buf * bp) int poffset = foff & PAGE_MASK; int presid = resid > (PAGE_SIZE - poffset) ? (PAGE_SIZE - poffset) : resid; -#ifdef DIAGNOSTIC - if (presid < 0) - panic("brelse: extra page"); -#endif + KASSERT(presid >= 0, ("brelse: extra page")); vm_page_set_invalid(m, poffset, presid); } resid -= PAGE_SIZE - (foff & PAGE_MASK); @@ -1002,11 +999,8 @@ trytofreespace: return (0); } -#if defined(DIAGNOSTIC) - if (bp->b_flags & B_BUSY) { - panic("getnewbuf: busy buffer on free list\n"); - } -#endif + KASSERT(!(bp->b_flags & B_BUSY), + ("getnewbuf: busy buffer on free list\n")); /* * We are fairly aggressive about freeing VMIO buffers, but since @@ -1460,10 +1454,8 @@ loop: } } -#ifdef DIAGNOSTIC - if (bp->b_offset == NOOFFSET) - panic("getblk: no buffer offset"); -#endif + KASSERT(bp->b_offset != NOOFFSET, + ("getblk: no buffer offset")); /* * Check that the constituted buffer really deserves for the @@ -1711,10 +1703,8 @@ allocbuf(struct buf * bp, int size) * is the responsibility of vnode_pager_setsize */ m = bp->b_pages[i]; -#if defined(DIAGNOSTIC) - if (m == bogus_page) - panic("allocbuf: bogus page found"); -#endif + KASSERT(m != bogus_page, + ("allocbuf: bogus page found")); vm_page_sleep(m, "biodep", &m->busy); bp->b_pages[i] = NULL; @@ -1747,10 +1737,8 @@ allocbuf(struct buf * bp, int size) tinc = PAGE_SIZE; off = bp->b_offset; -#ifdef DIAGNOSTIC - if (bp->b_offset == NOOFFSET) - panic("allocbuf: no buffer offset"); -#endif + KASSERT(bp->b_offset != NOOFFSET, + ("allocbuf: no buffer offset")); curbpnpages = bp->b_npages; doretry: @@ -1938,10 +1926,8 @@ biodone(register struct buf * bp) #endif foff = bp->b_offset; -#ifdef DIAGNOSTIC - if (bp->b_offset == NOOFFSET) - panic("biodone: no buffer offset"); -#endif + KASSERT(bp->b_offset != NOOFFSET, + ("biodone: no buffer offset")); #if !defined(MAX_PERF) if (!obj) { @@ -2213,10 +2199,8 @@ vfs_busy_pages(struct buf * bp, int clear_modify) vm_ooffset_t foff; foff = bp->b_offset; -#ifdef DIAGNOSTIC - if (bp->b_offset == NOOFFSET) - panic("vfs_busy_pages: no buffer offset"); -#endif + KASSERT(bp->b_offset != NOOFFSET, + ("vfs_busy_pages: no buffer offset")); vfs_setdirty(bp); @@ -2266,10 +2250,8 @@ vfs_clean_pages(struct buf * bp) vm_ooffset_t foff; foff = bp->b_offset; -#ifdef DIAGNOSTIC - if (bp->b_offset == NOOFFSET) - panic("vfs_clean_pages: no buffer offset"); -#endif + KASSERT(bp->b_offset != NOOFFSET, + ("vfs_clean_pages: no buffer offset")); for (i = 0; i < bp->b_npages; i++) { vm_page_t m = bp->b_pages[i]; diff --git a/sys/kern/vfs_cluster.c b/sys/kern/vfs_cluster.c index 1e4d7b87fd63..07434ce1d485 100644 --- a/sys/kern/vfs_cluster.c +++ b/sys/kern/vfs_cluster.c @@ -33,7 +33,7 @@ * SUCH DAMAGE. * * @(#)vfs_cluster.c 8.7 (Berkeley) 2/13/94 - * $Id: vfs_cluster.c,v 1.74 1998/11/17 00:31:12 mckusick Exp $ + * $Id: vfs_cluster.c,v 1.75 1998/12/05 06:12:14 mckusick Exp $ */ #include "opt_debug_cluster.h" @@ -168,10 +168,8 @@ cluster_read(vp, filesize, lblkno, size, cred, totread, seqcount, bpp) } else { off_t firstread; firstread = bp->b_offset; -#ifdef DIAGNOSTIC - if (bp->b_offset == NOOFFSET) - panic("cluster_read: no buffer offset"); -#endif + KASSERT(bp->b_offset != NOOFFSET, + ("cluster_read: no buffer offset")); if (firstread + totread > filesize) totread = filesize - firstread; if (totread > size) { @@ -312,11 +310,9 @@ cluster_rbuild(vp, filesize, lbn, blkno, size, run, fbp) daddr_t bn; int i, inc, j; -#ifdef DIAGNOSTIC - if (size != vp->v_mount->mnt_stat.f_iosize) - panic("cluster_rbuild: size %ld != filesize %ld\n", - size, vp->v_mount->mnt_stat.f_iosize); -#endif + KASSERT(size == vp->v_mount->mnt_stat.f_iosize, + ("cluster_rbuild: size %ld != filesize %ld\n", + size, vp->v_mount->mnt_stat.f_iosize)); /* * avoid a division */ @@ -350,10 +346,8 @@ cluster_rbuild(vp, filesize, lbn, blkno, size, run, fbp) bp->b_blkno = blkno; bp->b_lblkno = lbn; bp->b_offset = tbp->b_offset; -#ifdef DIAGNOSTIC - if (bp->b_offset == NOOFFSET) - panic("cluster_rbuild: no buffer offset"); -#endif + KASSERT(bp->b_offset != NOOFFSET, + ("cluster_rbuild: no buffer offset")); pbgetvp(vp, bp); TAILQ_INIT(&bp->b_cluster.cluster_head); @@ -517,10 +511,7 @@ cluster_write(bp, filesize) } lbn = bp->b_lblkno; -#ifdef DIAGNOSTIC - if (bp->b_offset == NOOFFSET) - panic("cluster_write: no buffer offset"); -#endif + KASSERT(bp->b_offset != NOOFFSET, ("cluster_write: no buffer offset")); /* Initialize vnode to beginning of file. */ if (lbn == 0) diff --git a/sys/kern/vfs_export.c b/sys/kern/vfs_export.c index 0d5bbdc29fe9..92a8710e9734 100644 --- a/sys/kern/vfs_export.c +++ b/sys/kern/vfs_export.c @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)vfs_subr.c 8.31 (Berkeley) 5/26/95 - * $Id: vfs_subr.c,v 1.179 1999/01/05 18:12:29 eivind Exp $ + * $Id: vfs_subr.c,v 1.180 1999/01/05 18:49:53 eivind Exp $ */ /* @@ -466,7 +466,7 @@ getnewvnode(tag, mp, vops, vpp) simple_unlock(&vp->v_interlock); } -#ifdef DIAGNOSTIC +#ifdef INVARIANTS { int s; @@ -796,10 +796,7 @@ bgetvp(vp, bp) { int s; -#if defined(DIAGNOSTIC) - if (bp->b_vp) - panic("bgetvp: not free"); -#endif + KASSERT(bp->b_vp == NULL, ("bgetvp: not free")); vhold(vp); bp->b_vp = vp; if (vp->v_type == VBLK || vp->v_type == VCHR) @@ -827,10 +824,7 @@ brelvp(bp) struct buflists *listheadp; int s; -#if defined(DIAGNOSTIC) - if (bp->b_vp == (struct vnode *) 0) - panic("brelvp: NULL"); -#endif + KASSERT(bp->b_vp != NULL, ("brelvp: NULL")); /* * Delete from old vnode list, if on one. @@ -996,10 +990,8 @@ pbgetvp(vp, bp) register struct vnode *vp; register struct buf *bp; { -#if defined(DIAGNOSTIC) - if (bp->b_vp) - panic("pbgetvp: not free"); -#endif + KASSERT(bp->b_vp == NULL, ("pbgetvp: not free")); + bp->b_vp = vp; if (vp->v_type == VBLK || vp->v_type == VCHR) bp->b_dev = vp->v_rdev; @@ -1015,10 +1007,7 @@ pbrelvp(bp) register struct buf *bp; { -#if defined(DIAGNOSTIC) - if (bp->b_vp == (struct vnode *) 0) - panic("pbrelvp: NULL"); -#endif + KASSERT(bp->b_vp != NULL, ("pbrelvp: NULL")); bp->b_vp = (struct vnode *) 0; } @@ -1313,10 +1302,8 @@ vrele(vp) { struct proc *p = curproc; /* XXX */ -#ifdef DIAGNOSTIC - if (vp == NULL) - panic("vrele: null vp"); -#endif + KASSERT(vp, ("vrele: null vp")); + simple_lock(&vp->v_interlock); if (vp->v_usecount > 1) { @@ -1356,10 +1343,7 @@ vput(vp) { struct proc *p = curproc; /* XXX */ -#ifdef DIAGNOSTIC - if (vp == NULL) - panic("vput: null vp"); -#endif + KASSERT(vp != NULL, ("vput: null vp")); simple_lock(&vp->v_interlock); @@ -1646,10 +1630,7 @@ vop_revoke(ap) struct vnode *vp, *vq; struct proc *p = curproc; /* XXX */ -#ifdef DIAGNOSTIC - if ((ap->a_flags & REVOKEALL) == 0) - panic("vop_revoke"); -#endif + KASSERT((ap->a_flags & REVOKEALL) != 0, ("vop_revoke")); vp = ap->a_vp; simple_lock(&vp->v_interlock); diff --git a/sys/kern/vfs_lookup.c b/sys/kern/vfs_lookup.c index 3a005578a54b..e6e8a6fff1bc 100644 --- a/sys/kern/vfs_lookup.c +++ b/sys/kern/vfs_lookup.c @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)vfs_lookup.c 8.4 (Berkeley) 2/16/94 - * $Id: vfs_lookup.c,v 1.28 1998/06/07 17:11:45 dfr Exp $ + * $Id: vfs_lookup.c,v 1.29 1999/01/05 18:49:52 eivind Exp $ */ #include "opt_ktrace.h" @@ -89,14 +89,11 @@ namei(ndp) struct proc *p = cnp->cn_proc; ndp->ni_cnd.cn_cred = ndp->ni_cnd.cn_proc->p_ucred; -#ifdef DIAGNOSTIC - if (!cnp->cn_cred || !cnp->cn_proc) - panic ("namei: bad cred/proc"); - if (cnp->cn_nameiop & (~OPMASK)) - panic ("namei: nameiop contaminated with flags"); - if (cnp->cn_flags & OPMASK) - panic ("namei: flags contaminated with nameiops"); -#endif + KASSERT(cnp->cn_cred && cnp->cn_proc, ("namei: bad cred/proc")); + KASSERT((cnp->cn_nameiop & (~OPMASK)) == 0, + ("namei: nameiop contaminated with flags")); + KASSERT((cnp->cn_flags & OPMASK) == 0, + ("namei: flags contaminated with nameiops")); fdp = cnp->cn_proc->p_fd; /* @@ -418,10 +415,7 @@ unionlookup: ndp->ni_vp = NULL; ASSERT_VOP_LOCKED(dp, "lookup"); if (error = VOP_LOOKUP(dp, &ndp->ni_vp, cnp)) { -#ifdef DIAGNOSTIC - if (ndp->ni_vp != NULL) - panic("leaf should be empty"); -#endif + KASSERT(ndp->ni_vp == NULL, ("leaf should be empty")); #ifdef NAMEI_DIAGNOSTIC printf("not found\n"); #endif @@ -649,10 +643,7 @@ relookup(dvp, vpp, cnp) * We now have a segment name to search for, and a directory to search. */ if (error = VOP_LOOKUP(dp, vpp, cnp)) { -#ifdef DIAGNOSTIC - if (*vpp != NULL) - panic("leaf should be empty"); -#endif + KASSERT(*vpp == NULL, ("leaf should be empty")); if (error != EJUSTRETURN) goto bad; /* @@ -675,13 +666,11 @@ relookup(dvp, vpp, cnp) } dp = *vpp; -#ifdef DIAGNOSTIC /* * Check for symbolic link */ - if (dp->v_type == VLNK && (cnp->cn_flags & FOLLOW)) - panic ("relookup: symlink found.\n"); -#endif + KASSERT(dp->v_type != VLNK || !(cnp->cn_flags & FOLLOW), + ("relookup: symlink found.\n")); /* * Disallow directory write attempts on read-only file systems. diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c index 0d5bbdc29fe9..92a8710e9734 100644 --- a/sys/kern/vfs_subr.c +++ b/sys/kern/vfs_subr.c @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)vfs_subr.c 8.31 (Berkeley) 5/26/95 - * $Id: vfs_subr.c,v 1.179 1999/01/05 18:12:29 eivind Exp $ + * $Id: vfs_subr.c,v 1.180 1999/01/05 18:49:53 eivind Exp $ */ /* @@ -466,7 +466,7 @@ getnewvnode(tag, mp, vops, vpp) simple_unlock(&vp->v_interlock); } -#ifdef DIAGNOSTIC +#ifdef INVARIANTS { int s; @@ -796,10 +796,7 @@ bgetvp(vp, bp) { int s; -#if defined(DIAGNOSTIC) - if (bp->b_vp) - panic("bgetvp: not free"); -#endif + KASSERT(bp->b_vp == NULL, ("bgetvp: not free")); vhold(vp); bp->b_vp = vp; if (vp->v_type == VBLK || vp->v_type == VCHR) @@ -827,10 +824,7 @@ brelvp(bp) struct buflists *listheadp; int s; -#if defined(DIAGNOSTIC) - if (bp->b_vp == (struct vnode *) 0) - panic("brelvp: NULL"); -#endif + KASSERT(bp->b_vp != NULL, ("brelvp: NULL")); /* * Delete from old vnode list, if on one. @@ -996,10 +990,8 @@ pbgetvp(vp, bp) register struct vnode *vp; register struct buf *bp; { -#if defined(DIAGNOSTIC) - if (bp->b_vp) - panic("pbgetvp: not free"); -#endif + KASSERT(bp->b_vp == NULL, ("pbgetvp: not free")); + bp->b_vp = vp; if (vp->v_type == VBLK || vp->v_type == VCHR) bp->b_dev = vp->v_rdev; @@ -1015,10 +1007,7 @@ pbrelvp(bp) register struct buf *bp; { -#if defined(DIAGNOSTIC) - if (bp->b_vp == (struct vnode *) 0) - panic("pbrelvp: NULL"); -#endif + KASSERT(bp->b_vp != NULL, ("pbrelvp: NULL")); bp->b_vp = (struct vnode *) 0; } @@ -1313,10 +1302,8 @@ vrele(vp) { struct proc *p = curproc; /* XXX */ -#ifdef DIAGNOSTIC - if (vp == NULL) - panic("vrele: null vp"); -#endif + KASSERT(vp, ("vrele: null vp")); + simple_lock(&vp->v_interlock); if (vp->v_usecount > 1) { @@ -1356,10 +1343,7 @@ vput(vp) { struct proc *p = curproc; /* XXX */ -#ifdef DIAGNOSTIC - if (vp == NULL) - panic("vput: null vp"); -#endif + KASSERT(vp != NULL, ("vput: null vp")); simple_lock(&vp->v_interlock); @@ -1646,10 +1630,7 @@ vop_revoke(ap) struct vnode *vp, *vq; struct proc *p = curproc; /* XXX */ -#ifdef DIAGNOSTIC - if ((ap->a_flags & REVOKEALL) == 0) - panic("vop_revoke"); -#endif + KASSERT((ap->a_flags & REVOKEALL) != 0, ("vop_revoke")); vp = ap->a_vp; simple_lock(&vp->v_interlock); |