#if DIAGNOSTIC panic ---> KASSERT

This commit is contained in:
riastradh 2017-03-18 05:20:04 +00:00
parent 0ccb325ddd
commit 1644321e4e
3 changed files with 47 additions and 39 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: ffs_alloc.c,v 1.155 2017/03/01 10:42:45 hannken Exp $ */
/* $NetBSD: ffs_alloc.c,v 1.156 2017/03/18 05:20:04 riastradh Exp $ */
/*-
* Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@ -70,7 +70,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.155 2017/03/01 10:42:45 hannken Exp $");
__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.156 2017/03/18 05:20:04 riastradh Exp $");
#if defined(_KERNEL_OPT)
#include "opt_ffs.h"
@ -226,15 +226,15 @@ ffs_alloc(struct inode *ip, daddr_t lbn, daddr_t bpref, int size,
#endif
*bnp = 0;
#ifdef DIAGNOSTIC
if (cred == NOCRED)
panic("%s: missing credential", __func__);
if ((u_int)size > fs->fs_bsize || ffs_fragoff(fs, size) != 0) {
panic("%s: bad size: dev = 0x%llx, bsize = %d, size = %d, "
"fs = %s", __func__, (unsigned long long)ip->i_dev,
fs->fs_bsize, size, fs->fs_fsmnt);
}
#endif /* DIAGNOSTIC */
KASSERTMSG((cred != NOCRED), "missing credential");
KASSERTMSG(((u_int)size <= fs->fs_bsize),
"bad size: dev = 0x%llx, bsize = %d, size = %d, fs = %s",
(unsigned long long)ip->i_dev, fs->fs_bsize, size, fs->fs_fsmnt);
KASSERTMSG((ffs_fragoff(fs, size) == 0),
"bad size: dev = 0x%llx, bsize = %d, size = %d, fs = %s",
(unsigned long long)ip->i_dev, fs->fs_bsize, size, fs->fs_fsmnt);
if (size == fs->fs_bsize && fs->fs_cstotal.cs_nbfree == 0)
goto nospace;
if (freespace(fs, fs->fs_minfree) <= 0 &&
@ -344,17 +344,24 @@ ffs_realloccg(struct inode *ip, daddr_t lbprev, daddr_t bpref, int osize,
}
#endif
#ifdef DIAGNOSTIC
if (cred == NOCRED)
panic("%s: missing credential", __func__);
if ((u_int)osize > fs->fs_bsize || ffs_fragoff(fs, osize) != 0 ||
(u_int)nsize > fs->fs_bsize || ffs_fragoff(fs, nsize) != 0) {
panic("%s: bad size: dev = 0x%llx, bsize = %d, osize = %d, "
"nsize = %d, fs = %s", __func__,
(unsigned long long)ip->i_dev, fs->fs_bsize, osize, nsize,
fs->fs_fsmnt);
}
#endif /* DIAGNOSTIC */
KASSERTMSG((cred != NOCRED), "missing credential");
KASSERTMSG(((u_int)osize <= fs->fs_bsize),
"bad size: dev=0x%llx, bsize=%d, osize=%d, nsize=%d, fs=%s",
(unsigned long long)ip->i_dev, fs->fs_bsize, osize, nsize,
fs->fs_fsmnt);
KASSERTMSG((ffs_fragoff(fs, osize) == 0),
"bad size: dev=0x%llx, bsize=%d, osize=%d, nsize=%d, fs=%s",
(unsigned long long)ip->i_dev, fs->fs_bsize, osize, nsize,
fs->fs_fsmnt);
KASSERTMSG(((u_int)nsize <= fs->fs_bsize),
"bad size: dev=0x%llx, bsize=%d, osize=%d, nsize=%d, fs=%s",
(unsigned long long)ip->i_dev, fs->fs_bsize, osize, nsize,
fs->fs_fsmnt);
KASSERTMSG((ffs_fragoff(fs, nsize) == 0),
"bad size: dev=0x%llx, bsize=%d, osize=%d, nsize=%d, fs=%s",
(unsigned long long)ip->i_dev, fs->fs_bsize, osize, nsize,
fs->fs_fsmnt);
if (freespace(fs, fs->fs_minfree) <= 0 &&
kauth_authorize_system(cred, KAUTH_SYSTEM_FS_RESERVEDSPACE, 0, NULL,
NULL, NULL) != 0) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: ffs_inode.c,v 1.123 2016/11/11 10:50:16 hannken Exp $ */
/* $NetBSD: ffs_inode.c,v 1.124 2017/03/18 05:26:40 riastradh Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@ -61,7 +61,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ffs_inode.c,v 1.123 2016/11/11 10:50:16 hannken Exp $");
__KERNEL_RCSID(0, "$NetBSD: ffs_inode.c,v 1.124 2017/03/18 05:26:40 riastradh Exp $");
#if defined(_KERNEL_OPT)
#include "opt_ffs.h"
@ -527,17 +527,19 @@ ffs_truncate(struct vnode *ovp, off_t length, int ioflag, kauth_cred_t cred)
}
done:
#ifdef DIAGNOSTIC
for (level = SINGLE; level <= TRIPLE; level++)
if (blks[UFS_NDADDR + level] != DIP(oip, ib[level]))
panic("itrunc1");
KASSERTMSG((blks[UFS_NDADDR + level] == DIP(oip, ib[level])),
"itrunc1 blk mismatch: %jx != %jx",
(uintmax_t)blks[UFS_NDADDR + level],
(uintmax_t)DIP(oip, ib[level]));
for (i = 0; i < UFS_NDADDR; i++)
if (blks[i] != DIP(oip, db[i]))
panic("itrunc2");
if (length == 0 &&
(!LIST_EMPTY(&ovp->v_cleanblkhd) || !LIST_EMPTY(&ovp->v_dirtyblkhd)))
panic("itrunc3");
#endif /* DIAGNOSTIC */
KASSERTMSG((blks[i] == DIP(oip, db[i])),
"itrunc2 blk mismatch: %jx != %jx",
(uintmax_t)blks[i], (uintmax_t)DIP(oip, db[i]));
KASSERTMSG((length != 0 || LIST_EMPTY(&ovp->v_cleanblkhd)),
"itrunc3: zero length and nonempty cleanblkhd");
KASSERTMSG((length != 0 || LIST_EMPTY(&ovp->v_dirtyblkhd)),
"itrunc3: zero length and nonempty dirtyblkhd");
out:
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: ffs_snapshot.c,v 1.146 2017/03/01 10:42:45 hannken Exp $ */
/* $NetBSD: ffs_snapshot.c,v 1.147 2017/03/18 05:29:16 riastradh Exp $ */
/*
* Copyright 2000 Marshall Kirk McKusick. All Rights Reserved.
@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ffs_snapshot.c,v 1.146 2017/03/01 10:42:45 hannken Exp $");
__KERNEL_RCSID(0, "$NetBSD: ffs_snapshot.c,v 1.147 2017/03/18 05:29:16 riastradh Exp $");
#if defined(_KERNEL_OPT)
#include "opt_ffs.h"
@ -1993,10 +1993,9 @@ retry:
if (gen != si->si_gen)
goto retry;
}
#ifdef DIAGNOSTIC
if (blkno == BLK_SNAP && bp->b_lblkno >= 0)
panic("ffs_copyonwrite: bad copy block");
#endif
KASSERTMSG((blkno != BLK_SNAP || bp->b_lblkno < 0),
"ffs_copyonwrite: bad copy block: blkno %jd, lblkno %jd",
(intmax_t)blkno, (intmax_t)bp->b_lblkno);
if (blkno != 0)
continue;