summaryrefslogtreecommitdiffstats
path: root/sys/fs
diff options
context:
space:
mode:
authorkib <kib@FreeBSD.org>2010-06-13 05:24:27 +0000
committerkib <kib@FreeBSD.org>2010-06-13 05:24:27 +0000
commit9100139edc3976c40b4dd05903c61be5c5fc333d (patch)
tree1577a85dd66937c640490d5a03b9962a2385299f /sys/fs
parent82a6368b8628b24215cb22de6039e60e2fad7aff (diff)
downloadFreeBSD-src-9100139edc3976c40b4dd05903c61be5c5fc333d.zip
FreeBSD-src-9100139edc3976c40b4dd05903c61be5c5fc333d.tar.gz
In NFS clients, instead of inconsistently using #ifdef
DIAGNOSTIC and #ifndef DIAGNOSTIC for debug assertions, prefer KASSERT(). Also change one #ifdef DIAGNOSTIC in the new nfs server. Submitted by: Mikolaj Golub <to.my.trociny gmail com> MFC after: 2 weeks
Diffstat (limited to 'sys/fs')
-rw-r--r--sys/fs/nfsclient/nfs_clbio.c14
-rw-r--r--sys/fs/nfsclient/nfs_clcomsubs.c10
-rw-r--r--sys/fs/nfsclient/nfs_clrpcops.c19
-rw-r--r--sys/fs/nfsclient/nfs_clsubs.c10
-rw-r--r--sys/fs/nfsclient/nfs_clvnops.c38
-rw-r--r--sys/fs/nfsserver/nfs_nfsdsocket.c5
6 files changed, 29 insertions, 67 deletions
diff --git a/sys/fs/nfsclient/nfs_clbio.c b/sys/fs/nfsclient/nfs_clbio.c
index 7d6fcab..a98172f 100644
--- a/sys/fs/nfsclient/nfs_clbio.c
+++ b/sys/fs/nfsclient/nfs_clbio.c
@@ -453,10 +453,7 @@ ncl_bioread(struct vnode *vp, struct uio *uio, int ioflag, struct ucred *cred)
int seqcount;
int nra, error = 0, n = 0, on = 0;
-#ifdef DIAGNOSTIC
- if (uio->uio_rw != UIO_READ)
- panic("ncl_read mode");
-#endif
+ KASSERT(uio->uio_rw == UIO_READ, ("ncl_read mode"));
if (uio->uio_resid == 0)
return (0);
if (uio->uio_offset < 0) /* XXX VDIR cookies can be negative */
@@ -881,12 +878,9 @@ ncl_write(struct vop_write_args *ap)
int bcount;
int n, on, error = 0;
-#ifdef DIAGNOSTIC
- if (uio->uio_rw != UIO_WRITE)
- panic("ncl_write mode");
- if (uio->uio_segflg == UIO_USERSPACE && uio->uio_td != curthread)
- panic("ncl_write proc");
-#endif
+ KASSERT(uio->uio_rw == UIO_WRITE, ("ncl_write mode"));
+ KASSERT(uio->uio_segflg != UIO_USERSPACE || uio->uio_td == curthread,
+ ("ncl_write proc"));
if (vp->v_type != VREG)
return (EIO);
mtx_lock(&np->n_mtx);
diff --git a/sys/fs/nfsclient/nfs_clcomsubs.c b/sys/fs/nfsclient/nfs_clcomsubs.c
index 1c03b5c..b0bc3c3 100644
--- a/sys/fs/nfsclient/nfs_clcomsubs.c
+++ b/sys/fs/nfsclient/nfs_clcomsubs.c
@@ -194,10 +194,7 @@ nfsm_uiombuf(struct nfsrv_descript *nd, struct uio *uiop, int siz)
int uiosiz, clflg, rem;
char *cp, *tcp;
-#ifdef DIAGNOSTIC
- if (uiop->uio_iovcnt != 1)
- panic("nfsm_uiotombuf: iovcnt != 1");
-#endif
+ KASSERT(uiop->uio_iovcnt == 1, ("nfsm_uiotombuf: iovcnt != 1"));
if (siz > ncl_mbuf_mlen) /* or should it >= MCLBYTES ?? */
clflg = 1;
@@ -346,10 +343,7 @@ nfscl_getcookie(struct nfsnode *np, off_t off, int add)
pos = off / NFS_DIRBLKSIZ;
if (pos == 0) {
-#ifdef DIAGNOSTIC
- if (add)
- panic("nfs getcookie add at 0");
-#endif
+ KASSERT(!add, ("nfs getcookie add at 0"));
return (&nfs_nullcookie);
}
pos--;
diff --git a/sys/fs/nfsclient/nfs_clrpcops.c b/sys/fs/nfsclient/nfs_clrpcops.c
index 5d00102..f647810 100644
--- a/sys/fs/nfsclient/nfs_clrpcops.c
+++ b/sys/fs/nfsclient/nfs_clrpcops.c
@@ -1445,10 +1445,7 @@ nfsrpc_writerpc(vnode_t vp, struct uio *uiop, int *iomode,
struct nfsrv_descript *nd = &nfsd;
nfsattrbit_t attrbits;
-#ifdef DIAGNOSTIC
- if (uiop->uio_iovcnt != 1)
- panic("nfs: writerpc iovcnt > 1");
-#endif
+ KASSERT(uiop->uio_iovcnt == 1, ("nfs: writerpc iovcnt > 1"));
*attrflagp = 0;
tsiz = uio_uio_resid(uiop);
NFSLOCKMNT(nmp);
@@ -2501,10 +2498,9 @@ nfsrpc_readdir(vnode_t vp, struct uio *uiop, nfsuint64 *cookiep,
u_int32_t *tl2 = NULL;
size_t tresid;
-#ifdef DIAGNOSTIC
- if (uiop->uio_iovcnt != 1 || (uio_uio_resid(uiop) & (DIRBLKSIZ - 1)))
- panic("nfs readdirrpc bad uio");
-#endif
+ KASSERT(uiop->uio_iovcnt == 1 &&
+ (uio_uio_resid(uiop) & (DIRBLKSIZ - 1)) == 0,
+ ("nfs readdirrpc bad uio"));
/*
* There is no point in reading a lot more than uio_resid, however
@@ -2939,10 +2935,9 @@ nfsrpc_readdirplus(vnode_t vp, struct uio *uiop, nfsuint64 *cookiep,
size_t tresid;
u_int32_t *tl2 = NULL, fakefileno = 0xffffffff, rderr;
-#ifdef DIAGNOSTIC
- if (uiop->uio_iovcnt != 1 || (uio_uio_resid(uiop) & (DIRBLKSIZ - 1)))
- panic("nfs readdirplusrpc bad uio");
-#endif
+ KASSERT(uiop->uio_iovcnt == 1 &&
+ (uio_uio_resid(uiop) & (DIRBLKSIZ - 1)) == 0,
+ ("nfs readdirplusrpc bad uio"));
*attrflagp = 0;
if (eofp != NULL)
*eofp = 0;
diff --git a/sys/fs/nfsclient/nfs_clsubs.c b/sys/fs/nfsclient/nfs_clsubs.c
index 1443278..2863ffd 100644
--- a/sys/fs/nfsclient/nfs_clsubs.c
+++ b/sys/fs/nfsclient/nfs_clsubs.c
@@ -282,10 +282,7 @@ ncl_getcookie(struct nfsnode *np, off_t off, int add)
pos = (uoff_t)off / NFS_DIRBLKSIZ;
if (pos == 0 || off < 0) {
-#ifdef DIAGNOSTIC
- if (add)
- panic("nfs getcookie add at <= 0");
-#endif
+ KASSERT(!add, ("nfs getcookie add at <= 0"));
return (&nfs_nullcookie);
}
pos--;
@@ -336,10 +333,7 @@ ncl_invaldir(struct vnode *vp)
{
struct nfsnode *np = VTONFS(vp);
-#ifdef DIAGNOSTIC
- if (vp->v_type != VDIR)
- panic("nfs: invaldir not dir");
-#endif
+ KASSERT(vp->v_type == VDIR, ("nfs: invaldir not dir"));
ncl_dircookie_lock(np);
np->n_direofoffset = 0;
np->n_cookieverf.nfsuquad[0] = 0;
diff --git a/sys/fs/nfsclient/nfs_clvnops.c b/sys/fs/nfsclient/nfs_clvnops.c
index d53c838..d439500 100644
--- a/sys/fs/nfsclient/nfs_clvnops.c
+++ b/sys/fs/nfsclient/nfs_clvnops.c
@@ -1564,12 +1564,8 @@ nfs_remove(struct vop_remove_args *ap)
int error = 0;
struct vattr vattr;
-#ifndef DIAGNOSTIC
- if ((cnp->cn_flags & HASBUF) == 0)
- panic("nfs_remove: no name");
- if (vrefcnt(vp) < 1)
- panic("nfs_remove: bad v_usecount");
-#endif
+ KASSERT((cnp->cn_flags & HASBUF) != 0, ("nfs_remove: no name"));
+ KASSERT(vrefcnt(vp) > 0, ("nfs_remove: bad v_usecount"));
if (vp->v_type == VDIR)
error = EPERM;
else if (vrefcnt(vp) == 1 || (np->n_sillyrename &&
@@ -1676,11 +1672,8 @@ nfs_rename(struct vop_rename_args *ap)
struct nfsv4node *newv4 = NULL;
int error;
-#ifndef DIAGNOSTIC
- if ((tcnp->cn_flags & HASBUF) == 0 ||
- (fcnp->cn_flags & HASBUF) == 0)
- panic("nfs_rename: no name");
-#endif
+ KASSERT((tcnp->cn_flags & HASBUF) != 0 &&
+ (fcnp->cn_flags & HASBUF) != 0, ("nfs_rename: no name"));
/* Check for cross-device rename */
if ((fvp->v_mount != tdvp->v_mount) ||
(tvp && (fvp->v_mount != tvp->v_mount))) {
@@ -2137,11 +2130,10 @@ ncl_readdirrpc(struct vnode *vp, struct uio *uiop, struct ucred *cred,
struct nfsmount *nmp = VFSTONFS(vp->v_mount);
int error = 0, eof, attrflag;
-#ifndef DIAGNOSTIC
- if (uiop->uio_iovcnt != 1 || (uiop->uio_offset & (DIRBLKSIZ - 1)) ||
- (uiop->uio_resid & (DIRBLKSIZ - 1)))
- panic("nfs readdirrpc bad uio");
-#endif
+ KASSERT(uiop->uio_iovcnt == 1 &&
+ (uiop->uio_offset & (DIRBLKSIZ - 1)) == 0 &&
+ (uiop->uio_resid & (DIRBLKSIZ - 1)) == 0,
+ ("nfs readdirrpc bad uio"));
/*
* If there is no cookie, assume directory was stale.
@@ -2198,11 +2190,10 @@ ncl_readdirplusrpc(struct vnode *vp, struct uio *uiop, struct ucred *cred,
struct nfsmount *nmp = VFSTONFS(vp->v_mount);
int error = 0, attrflag, eof;
-#ifndef DIAGNOSTIC
- if (uiop->uio_iovcnt != 1 || (uiop->uio_offset & (DIRBLKSIZ - 1)) ||
- (uiop->uio_resid & (DIRBLKSIZ - 1)))
- panic("nfs readdirplusrpc bad uio");
-#endif
+ KASSERT(uiop->uio_iovcnt == 1 &&
+ (uiop->uio_offset & (DIRBLKSIZ - 1)) == 0 &&
+ (uiop->uio_resid & (DIRBLKSIZ - 1)) == 0,
+ ("nfs readdirplusrpc bad uio"));
/*
* If there is no cookie, assume directory was stale.
@@ -2264,10 +2255,7 @@ nfs_sillyrename(struct vnode *dvp, struct vnode *vp, struct componentname *cnp)
cache_purge(dvp);
np = VTONFS(vp);
-#ifndef DIAGNOSTIC
- if (vp->v_type == VDIR)
- panic("nfs: sillyrename dir");
-#endif
+ KASSERT(vp->v_type != VDIR, ("nfs: sillyrename dir"));
MALLOC(sp, struct sillyrename *, sizeof (struct sillyrename),
M_NEWNFSREQ, M_WAITOK);
sp->s_cred = crhold(cnp->cn_cred);
diff --git a/sys/fs/nfsserver/nfs_nfsdsocket.c b/sys/fs/nfsserver/nfs_nfsdsocket.c
index fc6e39e..c95fef2 100644
--- a/sys/fs/nfsserver/nfs_nfsdsocket.c
+++ b/sys/fs/nfsserver/nfs_nfsdsocket.c
@@ -364,10 +364,7 @@ nfsrvd_dorpc(struct nfsrv_descript *nd, int isdgram,
* Get a locked vnode for the first file handle
*/
if (!(nd->nd_flag & ND_NFSV4)) {
-#ifdef DIAGNOSTIC
- if (nd->nd_repstat)
- panic("nfsrvd_dorpc");
-#endif
+ KASSERT(nd->nd_repstat == 0, ("nfsrvd_dorpc"));
/*
* For NFSv3, if the malloc/mget allocation is near limits,
* return NFSERR_DELAY.
OpenPOWER on IntegriCloud