From owner-freebsd-fs@FreeBSD.ORG Sat Jun 12 21:33:48 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 8F522106564A for ; Sat, 12 Jun 2010 21:33:48 +0000 (UTC) (envelope-from to.my.trociny@gmail.com) Received: from mail-bw0-f54.google.com (mail-bw0-f54.google.com [209.85.214.54]) by mx1.freebsd.org (Postfix) with ESMTP id E21C48FC1A for ; Sat, 12 Jun 2010 21:33:47 +0000 (UTC) Received: by bwz2 with SMTP id 2so1569795bwz.13 for ; Sat, 12 Jun 2010 14:33:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:references :x-comment-to:date:in-reply-to:message-id:user-agent:mime-version :content-type; bh=1n/t+5IAfsVr1RwhpqW8Ksnip3bkG9Z90+eqDI7aeOk=; b=NTYRCZRvIYvV98wYzW1Cw9pNIxChcketOpNJ2v2oEeTEt/6nNQh7StVI4E2jWke5HB eh6wNK+Etn1UEnDqNwt5t4ISA8S5vjIuEBd03UlFaUvtN/eYuh4pIStA4CMRMeue6+4l alfYAoukOiRbTraeQbPjwQPEKvw+7O1xKq3Uw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:references:x-comment-to:date:in-reply-to :message-id:user-agent:mime-version:content-type; b=gr4v7PeLm1NIweSPHgtPNsir2xNbu1yfmuwpyzi6LJ7MONaXVlez9iMiTU2kzKTbIN a2C9R3VfVJqxGRdQZ4C39tb4or1bRx3BLk1v8wIi/7S1P4K4HtTiUUwV70IXXIAG08pM LkmgEoEBrFrv3f+goSwv14MyBQCCDvD61azGY= Received: by 10.204.132.211 with SMTP id c19mr2640088bkt.184.1276378426515; Sat, 12 Jun 2010 14:33:46 -0700 (PDT) Received: from localhost ([95.69.160.52]) by mx.google.com with ESMTPS id z17sm11478440bkx.12.2010.06.12.14.33.45 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sat, 12 Jun 2010 14:33:45 -0700 (PDT) From: Mikolaj Golub To: Kostik Belousov References: <86mxv22ji7.fsf@zhuzha.ua1> <20100611191059.GF13238@deviant.kiev.zoral.com.ua> <86mxv0cb9z.fsf@kopusha.home.net> <20100612194022.GP13238@deviant.kiev.zoral.com.ua> X-Comment-To: Kostik Belousov Date: Sun, 13 Jun 2010 00:33:43 +0300 In-Reply-To: <20100612194022.GP13238@deviant.kiev.zoral.com.ua> (Kostik Belousov's message of "Sat, 12 Jun 2010 22:40:22 +0300") Message-ID: <86eigcc4w8.fsf@kopusha.home.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (berkeley-unix) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Cc: freebsd-fs@freebsd.org Subject: Re: '#ifndef DIAGNOSTIC' in nfsclient code looks like a typo X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 12 Jun 2010 21:33:48 -0000 --=-=-= On Sat, 12 Jun 2010 22:40:22 +0300 Kostik Belousov wrote: KB> Almost there. According to style(9), the values should be explicitely KB> compared with 0, unless the value is of the boolean type. I suggest KB> you to change e.g. KB> + KASSERT(uiop->uio_iovcnt == 1 && KB> + !(uio_uio_resid(uiop) & (DIRBLKSIZ - 1)), KB> to KB> + KASSERT(uiop->uio_iovcnt == 1 && KB> + (uio_uio_resid(uiop) & (DIRBLKSIZ - 1)) == 0, KB> and change KB> + KASSERT((tcnp->cn_flags & HASBUF) && (fcnp->cn_flags & HASBUF), KB> + ("nfs_rename: no name")); KB> to KB> + KASSERT((tcnp->cn_flags & HASBUF) != 0 && (fcnp->cn_flags & HASBUF) != 0, KB> + ("nfs_rename: no name")); Updated. -- Mikolaj Golub --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=nfs.KASSERT.patch Index: sys/nfsclient/nfs_vnops.c =================================================================== --- sys/nfsclient/nfs_vnops.c (revision 208960) +++ sys/nfsclient/nfs_vnops.c (working copy) @@ -1348,10 +1348,7 @@ int v3 = NFS_ISV3(vp), committed = NFSV3WRITE_FILESYNC; int wsize; -#ifndef DIAGNOSTIC - if (uiop->uio_iovcnt != 1) - panic("nfs: writerpc iovcnt > 1"); -#endif + KASSERT(uiop->uio_iovcnt == 1, ("nfs: writerpc iovcnt > 1")); *must_commit = 0; tsiz = uiop->uio_resid; mtx_lock(&nmp->nm_mtx); @@ -1708,12 +1705,8 @@ 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 && @@ -1814,11 +1807,9 @@ struct componentname *fcnp = ap->a_fcnp; 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))) { @@ -2277,11 +2268,10 @@ int attrflag; int v3 = NFS_ISV3(vp); -#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. @@ -2482,11 +2472,10 @@ #ifndef nolint dp = NULL; #endif -#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")); ndp->ni_dvp = vp; newvp = NULLVP; @@ -2752,10 +2741,7 @@ 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")); sp = malloc(sizeof (struct sillyrename), M_NFSREQ, M_WAITOK); sp->s_cred = crhold(cnp->cn_cred); Index: sys/nfsclient/nfs_bio.c =================================================================== --- sys/nfsclient/nfs_bio.c (revision 208960) +++ sys/nfsclient/nfs_bio.c (working copy) @@ -453,10 +453,7 @@ int seqcount; int nra, error = 0, n = 0, on = 0; -#ifdef DIAGNOSTIC - if (uio->uio_rw != UIO_READ) - panic("nfs_read mode"); -#endif + KASSERT(uio->uio_rw == UIO_READ, ("nfs_read mode")); if (uio->uio_resid == 0) return (0); if (uio->uio_offset < 0) /* XXX VDIR cookies can be negative */ @@ -875,12 +872,9 @@ int bcount; int n, on, error = 0; -#ifdef DIAGNOSTIC - if (uio->uio_rw != UIO_WRITE) - panic("nfs_write mode"); - if (uio->uio_segflg == UIO_USERSPACE && uio->uio_td != curthread) - panic("nfs_write proc"); -#endif + KASSERT(uio->uio_rw == UIO_WRITE, ("nfs_write mode")); + KASSERT(uio->uio_segflg != UIO_USERSPACE || uio->uio_td == curthread, + ("nfs_write proc")); if (vp->v_type != VREG) return (EIO); mtx_lock(&np->n_mtx); Index: sys/nfsclient/nfs_subs.c =================================================================== --- sys/nfsclient/nfs_subs.c (revision 208960) +++ sys/nfsclient/nfs_subs.c (working copy) @@ -199,10 +199,7 @@ int uiosiz, clflg, rem; char *cp; -#ifdef DIAGNOSTIC - if (uiop->uio_iovcnt != 1) - panic("nfsm_uiotombuf: iovcnt != 1"); -#endif + KASSERT(uiop->uio_iovcnt == 1, ("nfsm_uiotombuf: iovcnt != 1")); if (siz > MLEN) /* or should it >= MCLBYTES ?? */ clflg = 1; @@ -789,10 +786,7 @@ 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--; @@ -843,10 +837,7 @@ { 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")); nfs_dircookie_lock(np); np->n_direofoffset = 0; np->n_cookieverf.nfsuquad[0] = 0; Index: sys/fs/nfsclient/nfs_clbio.c =================================================================== --- sys/fs/nfsclient/nfs_clbio.c (revision 208960) +++ sys/fs/nfsclient/nfs_clbio.c (working copy) @@ -453,10 +453,7 @@ 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 @@ 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); Index: sys/fs/nfsclient/nfs_clcomsubs.c =================================================================== --- sys/fs/nfsclient/nfs_clcomsubs.c (revision 208960) +++ sys/fs/nfsclient/nfs_clcomsubs.c (working copy) @@ -194,10 +194,7 @@ 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 @@ 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--; Index: sys/fs/nfsclient/nfs_clsubs.c =================================================================== --- sys/fs/nfsclient/nfs_clsubs.c (revision 208960) +++ sys/fs/nfsclient/nfs_clsubs.c (working copy) @@ -282,10 +282,7 @@ 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 @@ { 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; Index: sys/fs/nfsclient/nfs_clvnops.c =================================================================== --- sys/fs/nfsclient/nfs_clvnops.c (revision 208960) +++ sys/fs/nfsclient/nfs_clvnops.c (working copy) @@ -1564,12 +1564,8 @@ 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,9 @@ 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 +2131,10 @@ 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 +2191,10 @@ 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 +2256,7 @@ 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); Index: sys/fs/nfsclient/nfs_clrpcops.c =================================================================== --- sys/fs/nfsclient/nfs_clrpcops.c (revision 208960) +++ sys/fs/nfsclient/nfs_clrpcops.c (working copy) @@ -1445,10 +1445,7 @@ 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 @@ 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 @@ 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; Index: sys/fs/nfsserver/nfs_nfsdsocket.c =================================================================== --- sys/fs/nfsserver/nfs_nfsdsocket.c (revision 208960) +++ sys/fs/nfsserver/nfs_nfsdsocket.c (working copy) @@ -364,10 +364,7 @@ * 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. --=-=-=--