svn commit: r352636 - in head/sys/fs: nfs nfsclient

Rick Macklem rmacklem at FreeBSD.org
Tue Sep 24 01:58:56 UTC 2019


Author: rmacklem
Date: Tue Sep 24 01:58:54 2019
New Revision: 352636
URL: https://svnweb.freebsd.org/changeset/base/352636

Log:
  Replace all mtx_lock()/mtx_unlock() on n_mtx with the macros.
  
  For a long time, some places in the NFS code have locked/unlocked the
  NFS node lock with the macros NFSLOCKNODE()/NFSUNLOCKNODE() whereas
  others have simply used mtx_lock()/mtx_unlock().
  Since the NFS node mutex needs to change to an sx lock so it can be held when
  vnode_pager_setsize() is called, replace all occurrences of mtx_lock/mtx_unlock
  with the macros to simply making the change to an sx lock in future commit.
  There is no semantic change as a result of this commit.
  
  I am not sure if the change to an sx lock will be MFC'd soon, so I put
  an MFC of 1 week on this commit so that it could be MFC'd with that commit.
  
  Suggested by:	kib
  MFC after:	1 week

Modified:
  head/sys/fs/nfs/nfsport.h
  head/sys/fs/nfsclient/nfs_clbio.c
  head/sys/fs/nfsclient/nfs_clnode.c
  head/sys/fs/nfsclient/nfs_clport.c
  head/sys/fs/nfsclient/nfs_clrpcops.c
  head/sys/fs/nfsclient/nfs_clsubs.c
  head/sys/fs/nfsclient/nfs_clvnops.c

Modified: head/sys/fs/nfs/nfsport.h
==============================================================================
--- head/sys/fs/nfs/nfsport.h	Tue Sep 24 01:56:27 2019	(r352635)
+++ head/sys/fs/nfs/nfsport.h	Tue Sep 24 01:58:54 2019	(r352636)
@@ -855,11 +855,11 @@ MALLOC_DECLARE(M_NEWNFSDSESSION);
 #define	NFSWRITERPC_SETTIME(w, n, a, v4)				\
 	do {								\
 		if (w) {						\
-			mtx_lock(&((n)->n_mtx));			\
+			NFSLOCKNODE(n);					\
 			(n)->n_mtime = (a)->na_mtime;			\
 			if (v4)						\
 				(n)->n_change = (a)->na_filerev;	\
-			mtx_unlock(&((n)->n_mtx));			\
+			NFSUNLOCKNODE(n);				\
 		}							\
 	} while (0)
 

Modified: head/sys/fs/nfsclient/nfs_clbio.c
==============================================================================
--- head/sys/fs/nfsclient/nfs_clbio.c	Tue Sep 24 01:56:27 2019	(r352635)
+++ head/sys/fs/nfsclient/nfs_clbio.c	Tue Sep 24 01:58:54 2019	(r352636)
@@ -101,9 +101,9 @@ ncl_gbp_getblksz(struct vnode *vp, daddr_t lbn)
 	int biosize, bcount;
 
 	np = VTONFS(vp);
-	mtx_lock(&np->n_mtx);
+	NFSLOCKNODE(np);
 	nsize = np->n_size;
-	mtx_unlock(&np->n_mtx);
+	NFSUNLOCKNODE(np);
 
 	biosize = vp->v_bufobj.bo_bsize;
 	bcount = biosize;
@@ -144,13 +144,13 @@ ncl_getpages(struct vop_getpages_args *ap)
 	}
 
 	if (newnfs_directio_enable && !newnfs_directio_allow_mmap) {
-		mtx_lock(&np->n_mtx);
+		NFSLOCKNODE(np);
 		if ((np->n_flag & NNONCACHE) && (vp->v_type == VREG)) {
-			mtx_unlock(&np->n_mtx);
+			NFSUNLOCKNODE(np);
 			printf("ncl_getpages: called on non-cacheable vnode\n");
 			return (VM_PAGER_ERROR);
 		} else
-			mtx_unlock(&np->n_mtx);
+			NFSUNLOCKNODE(np);
 	}
 
 	mtx_lock(&nmp->nm_mtx);
@@ -301,12 +301,12 @@ ncl_putpages(struct vop_putpages_args *ap)
 	} else
 		mtx_unlock(&nmp->nm_mtx);
 
-	mtx_lock(&np->n_mtx);
+	NFSLOCKNODE(np);
 	if (newnfs_directio_enable && !newnfs_directio_allow_mmap &&
 	    (np->n_flag & NNONCACHE) && (vp->v_type == VREG)) {
-		mtx_unlock(&np->n_mtx);
+		NFSUNLOCKNODE(np);
 		printf("ncl_putpages: called on noncache-able vnode\n");
-		mtx_lock(&np->n_mtx);
+		NFSLOCKNODE(np);
 	}
 	/*
 	 * When putting pages, do not extend file past EOF.
@@ -316,7 +316,7 @@ ncl_putpages(struct vop_putpages_args *ap)
 		if (count < 0)
 			count = 0;
 	}
-	mtx_unlock(&np->n_mtx);
+	NFSUNLOCKNODE(np);
 
 	for (i = 0; i < npages; i++)
 		rtvals[i] = VM_PAGER_ERROR;
@@ -374,9 +374,9 @@ nfs_bioread_check_cons(struct vnode *vp, struct thread
 	 * whether the cache is consistent.
 	 */
 	old_lock = ncl_excl_start(vp);
-	mtx_lock(&np->n_mtx);
+	NFSLOCKNODE(np);
 	if (np->n_flag & NMODIFIED) {
-		mtx_unlock(&np->n_mtx);
+		NFSUNLOCKNODE(np);
 		if (vp->v_type != VREG) {
 			if (vp->v_type != VDIR)
 				panic("nfs: bioread, not dir");
@@ -390,28 +390,28 @@ nfs_bioread_check_cons(struct vnode *vp, struct thread
 		error = VOP_GETATTR(vp, &vattr, cred);
 		if (error)
 			goto out;
-		mtx_lock(&np->n_mtx);
+		NFSLOCKNODE(np);
 		np->n_mtime = vattr.va_mtime;
-		mtx_unlock(&np->n_mtx);
+		NFSUNLOCKNODE(np);
 	} else {
-		mtx_unlock(&np->n_mtx);
+		NFSUNLOCKNODE(np);
 		error = VOP_GETATTR(vp, &vattr, cred);
 		if (error)
 			goto out;
-		mtx_lock(&np->n_mtx);
+		NFSLOCKNODE(np);
 		if ((np->n_flag & NSIZECHANGED)
 		    || (NFS_TIMESPEC_COMPARE(&np->n_mtime, &vattr.va_mtime))) {
-			mtx_unlock(&np->n_mtx);
+			NFSUNLOCKNODE(np);
 			if (vp->v_type == VDIR)
 				ncl_invaldir(vp);
 			error = ncl_vinvalbuf(vp, V_SAVE | V_ALLOWCLEAN, td, 1);
 			if (error != 0)
 				goto out;
-			mtx_lock(&np->n_mtx);
+			NFSLOCKNODE(np);
 			np->n_mtime = vattr.va_mtime;
 			np->n_flag &= ~NSIZECHANGED;
 		}
-		mtx_unlock(&np->n_mtx);
+		NFSUNLOCKNODE(np);
 	}
 out:
 	ncl_excl_finish(vp, old_lock);
@@ -474,9 +474,9 @@ ncl_bioread(struct vnode *vp, struct uio *uio, int iof
 	do {
 	    u_quad_t nsize;
 
-	    mtx_lock(&np->n_mtx);
+	    NFSLOCKNODE(np);
 	    nsize = np->n_size;
-	    mtx_unlock(&np->n_mtx);
+	    NFSUNLOCKNODE(np);
 
 	    switch (vp->v_type) {
 	    case VREG:
@@ -883,13 +883,13 @@ ncl_write(struct vop_write_args *ap)
 	    ("ncl_write proc"));
 	if (vp->v_type != VREG)
 		return (EIO);
-	mtx_lock(&np->n_mtx);
+	NFSLOCKNODE(np);
 	if (np->n_flag & NWRITEERR) {
 		np->n_flag &= ~NWRITEERR;
-		mtx_unlock(&np->n_mtx);
+		NFSUNLOCKNODE(np);
 		return (np->n_error);
 	} else
-		mtx_unlock(&np->n_mtx);
+		NFSUNLOCKNODE(np);
 	mtx_lock(&nmp->nm_mtx);
 	if ((nmp->nm_flag & NFSMNT_NFSV3) != 0 &&
 	    (nmp->nm_state & NFSSTA_GOTFSINFO) == 0) {
@@ -906,9 +906,9 @@ ncl_write(struct vop_write_args *ap)
 	 * mode or if we are appending.
 	 */
 	if (ioflag & (IO_APPEND | IO_SYNC)) {
-		mtx_lock(&np->n_mtx);
+		NFSLOCKNODE(np);
 		if (np->n_flag & NMODIFIED) {
-			mtx_unlock(&np->n_mtx);
+			NFSUNLOCKNODE(np);
 #ifdef notyet /* Needs matching nonblock semantics elsewhere, too. */
 			/*
 			 * Require non-blocking, synchronous writes to
@@ -925,13 +925,13 @@ ncl_write(struct vop_write_args *ap)
 			if (error != 0)
 				return (error);
 		} else
-			mtx_unlock(&np->n_mtx);
+			NFSUNLOCKNODE(np);
 	}
 
 	orig_resid = uio->uio_resid;
-	mtx_lock(&np->n_mtx);
+	NFSLOCKNODE(np);
 	orig_size = np->n_size;
-	mtx_unlock(&np->n_mtx);
+	NFSUNLOCKNODE(np);
 
 	/*
 	 * If IO_APPEND then load uio_offset.  We restart here if we cannot
@@ -943,9 +943,9 @@ ncl_write(struct vop_write_args *ap)
 		error = VOP_GETATTR(vp, &vattr, cred);
 		if (error)
 			return (error);
-		mtx_lock(&np->n_mtx);
+		NFSLOCKNODE(np);
 		uio->uio_offset = np->n_size;
-		mtx_unlock(&np->n_mtx);
+		NFSUNLOCKNODE(np);
 	}
 
 	if (uio->uio_offset < 0)
@@ -979,9 +979,9 @@ ncl_write(struct vop_write_args *ap)
 	if (!(ioflag & IO_SYNC)) {
 		int nflag;
 
-		mtx_lock(&np->n_mtx);
+		NFSLOCKNODE(np);
 		nflag = np->n_flag;
-		mtx_unlock(&np->n_mtx);
+		NFSUNLOCKNODE(np);
 		if (nflag & NMODIFIED) {
 			BO_LOCK(&vp->v_bufobj);
 			if (vp->v_bufobj.bo_dirty.bv_cnt != 0) {
@@ -1018,7 +1018,7 @@ again:
 		 * Handle direct append and file extension cases, calculate
 		 * unaligned buffer size.
 		 */
-		mtx_lock(&np->n_mtx);
+		NFSLOCKNODE(np);
 		if ((np->n_flag & NHASBEENLOCKED) == 0 &&
 		    (nmp->nm_flag & NFSMNT_NONCONTIGWR) != 0)
 			noncontig_write = 1;
@@ -1028,7 +1028,7 @@ again:
 		    (noncontig_write != 0 &&
 		    lbn == (np->n_size / biosize) &&
 		    uio->uio_offset + n > np->n_size)) && n) {
-			mtx_unlock(&np->n_mtx);
+			NFSUNLOCKNODE(np);
 			/*
 			 * Get the buffer (in its pre-append state to maintain
 			 * B_CACHE if it was previously set).  Resize the
@@ -1041,11 +1041,11 @@ again:
 			if (bp != NULL) {
 				long save;
 
-				mtx_lock(&np->n_mtx);
+				NFSLOCKNODE(np);
 				np->n_size = uio->uio_offset + n;
 				np->n_flag |= NMODIFIED;
 				vnode_pager_setsize(vp, np->n_size);
-				mtx_unlock(&np->n_mtx);
+				NFSUNLOCKNODE(np);
 
 				save = bp->b_flags & B_CACHE;
 				bcount = on + n;
@@ -1067,15 +1067,15 @@ again:
 				else
 					bcount = np->n_size - (off_t)lbn * biosize;
 			}
-			mtx_unlock(&np->n_mtx);
+			NFSUNLOCKNODE(np);
 			bp = nfs_getcacheblk(vp, lbn, bcount, td);
-			mtx_lock(&np->n_mtx);
+			NFSLOCKNODE(np);
 			if (uio->uio_offset + n > np->n_size) {
 				np->n_size = uio->uio_offset + n;
 				np->n_flag |= NMODIFIED;
 				vnode_pager_setsize(vp, np->n_size);
 			}
-			mtx_unlock(&np->n_mtx);
+			NFSUNLOCKNODE(np);
 		}
 
 		if (!bp) {
@@ -1124,9 +1124,9 @@ again:
 		}
 		if (bp->b_wcred == NOCRED)
 			bp->b_wcred = crhold(cred);
-		mtx_lock(&np->n_mtx);
+		NFSLOCKNODE(np);
 		np->n_flag |= NMODIFIED;
-		mtx_unlock(&np->n_mtx);
+		NFSUNLOCKNODE(np);
 
 		/*
 		 * If dirtyend exceeds file size, chop it down.  This should
@@ -1369,13 +1369,13 @@ ncl_vinvalbuf(struct vnode *vp, int flags, struct thre
 		 * Invalidate the attribute cache, since writes to a DS
 		 * won't update the size attribute.
 		 */
-		mtx_lock(&np->n_mtx);
+		NFSLOCKNODE(np);
 		np->n_attrstamp = 0;
 	} else
-		mtx_lock(&np->n_mtx);
+		NFSLOCKNODE(np);
 	if (np->n_directio_asyncwr == 0)
 		np->n_flag &= ~NMODIFIED;
-	mtx_unlock(&np->n_mtx);
+	NFSUNLOCKNODE(np);
 out:
 	ncl_excl_finish(vp, old_lock);
 	return error;
@@ -1517,10 +1517,10 @@ again:
 		TAILQ_INSERT_TAIL(&nmp->nm_bufq, bp, b_freelist);
 		nmp->nm_bufqlen++;
 		if ((bp->b_flags & B_DIRECT) && bp->b_iocmd == BIO_WRITE) {
-			mtx_lock(&(VTONFS(bp->b_vp))->n_mtx);
+			NFSLOCKNODE(VTONFS(bp->b_vp));
 			VTONFS(bp->b_vp)->n_flag |= NMODIFIED;
 			VTONFS(bp->b_vp)->n_directio_asyncwr++;
-			mtx_unlock(&(VTONFS(bp->b_vp))->n_mtx);
+			NFSUNLOCKNODE(VTONFS(bp->b_vp));
 		}
 		mtx_unlock(&ncl_iod_mutex);
 		return (0);
@@ -1552,7 +1552,7 @@ ncl_doio_directwrite(struct buf *bp)
 	free(uiop, M_NFSDIRECTIO);
 	if ((bp->b_flags & B_DIRECT) && bp->b_iocmd == BIO_WRITE) {
 		struct nfsnode *np = VTONFS(bp->b_vp);
-		mtx_lock(&np->n_mtx);
+		NFSLOCKNODE(np);
 		if (NFSHASPNFS(VFSTONFS(vnode_mount(bp->b_vp)))) {
 			/*
 			 * Invalidate the attribute cache, since writes to a DS
@@ -1568,7 +1568,7 @@ ncl_doio_directwrite(struct buf *bp)
 				wakeup((caddr_t)&np->n_directio_asyncwr);
 			}
 		}
-		mtx_unlock(&np->n_mtx);
+		NFSUNLOCKNODE(np);
 	}
 	bp->b_vp = NULL;
 	uma_zfree(ncl_pbuf_zone, bp);
@@ -1640,14 +1640,14 @@ ncl_doio(struct vnode *vp, struct buf *bp, struct ucre
 		}
 		/* ASSERT_VOP_LOCKED(vp, "ncl_doio"); */
 		if (p && vp->v_writecount <= -1) {
-			mtx_lock(&np->n_mtx);
+			NFSLOCKNODE(np);
 			if (NFS_TIMESPEC_COMPARE(&np->n_mtime, &np->n_vattr.na_mtime)) {
-				mtx_unlock(&np->n_mtx);
+				NFSUNLOCKNODE(np);
 				PROC_LOCK(p);
 				killproc(p, "text file modification");
 				PROC_UNLOCK(p);
 			} else
-				mtx_unlock(&np->n_mtx);
+				NFSUNLOCKNODE(np);
 		}
 		break;
 	    case VLNK:
@@ -1706,10 +1706,10 @@ ncl_doio(struct vnode *vp, struct buf *bp, struct ucre
 	    /*
 	     * Setup for actual write
 	     */
-	    mtx_lock(&np->n_mtx);
+	    NFSLOCKNODE(np);
 	    if ((off_t)bp->b_blkno * DEV_BSIZE + bp->b_dirtyend > np->n_size)
 		bp->b_dirtyend = np->n_size - (off_t)bp->b_blkno * DEV_BSIZE;
-	    mtx_unlock(&np->n_mtx);
+	    NFSUNLOCKNODE(np);
 
 	    if (bp->b_dirtyend > bp->b_dirtyoff) {
 		io.iov_len = uiop->uio_resid = bp->b_dirtyend
@@ -1802,11 +1802,11 @@ ncl_doio(struct vnode *vp, struct buf *bp, struct ucre
 			bp->b_ioflags |= BIO_ERROR;
 			bp->b_flags |= B_INVAL;
 			bp->b_error = np->n_error = error;
-			mtx_lock(&np->n_mtx);
+			NFSLOCKNODE(np);
 			np->n_flag |= NWRITEERR;
 			np->n_attrstamp = 0;
 			KDTRACE_NFS_ATTRCACHE_FLUSH_DONE(vp);
-			mtx_unlock(&np->n_mtx);
+			NFSUNLOCKNODE(np);
 		    }
 		    bp->b_dirtyoff = bp->b_dirtyend = 0;
 		}
@@ -1839,10 +1839,10 @@ ncl_meta_setsize(struct vnode *vp, struct thread *td, 
 	int biosize = vp->v_bufobj.bo_bsize;
 	int error = 0;
 
-	mtx_lock(&np->n_mtx);
+	NFSLOCKNODE(np);
 	tsize = np->n_size;
 	np->n_size = nsize;
-	mtx_unlock(&np->n_mtx);
+	NFSUNLOCKNODE(np);
 
 	if (nsize < tsize) {
 		struct buf *bp;

Modified: head/sys/fs/nfsclient/nfs_clnode.c
==============================================================================
--- head/sys/fs/nfsclient/nfs_clnode.c	Tue Sep 24 01:56:27 2019	(r352635)
+++ head/sys/fs/nfsclient/nfs_clnode.c	Tue Sep 24 01:58:54 2019	(r352636)
@@ -219,7 +219,7 @@ ncl_releasesillyrename(struct vnode *vp, struct thread
 	} else
 		sp = NULL;
 	if (sp != NULL) {
-		mtx_unlock(&np->n_mtx);
+		NFSUNLOCKNODE(np);
 		(void) ncl_vinvalbuf(vp, 0, td, 1);
 		/*
 		 * Remove the silly file that was rename'd earlier
@@ -228,7 +228,7 @@ ncl_releasesillyrename(struct vnode *vp, struct thread
 		crfree(sp->s_cred);
 		TASK_INIT(&sp->s_task, 0, nfs_freesillyrename, sp);
 		taskqueue_enqueue(taskqueue_thread, &sp->s_task);
-		mtx_lock(&np->n_mtx);
+		NFSLOCKNODE(np);
 	}
 }
 
@@ -260,7 +260,7 @@ ncl_inactive(struct vop_inactive_args *ap)
 	}
 
 	np = VTONFS(vp);
-	mtx_lock(&np->n_mtx);
+	NFSLOCKNODE(np);
 	ncl_releasesillyrename(vp, ap->a_td);
 
 	/*
@@ -271,7 +271,7 @@ ncl_inactive(struct vop_inactive_args *ap)
 	 * None of the other flags are meaningful after the vnode is unused.
 	 */
 	np->n_flag &= (NMODIFIED | NDSCOMMIT);
-	mtx_unlock(&np->n_mtx);
+	NFSUNLOCKNODE(np);
 	return (0);
 }
 
@@ -292,9 +292,9 @@ ncl_reclaim(struct vop_reclaim_args *ap)
 	if (nfs_reclaim_p != NULL)
 		nfs_reclaim_p(ap);
 
-	mtx_lock(&np->n_mtx);
+	NFSLOCKNODE(np);
 	ncl_releasesillyrename(vp, ap->a_td);
-	mtx_unlock(&np->n_mtx);
+	NFSUNLOCKNODE(np);
 
 	if (NFS_ISV4(vp) && vp->v_type == VREG)
 		/*
@@ -348,11 +348,11 @@ ncl_invalcaches(struct vnode *vp)
 	struct nfsnode *np = VTONFS(vp);
 	int i;
 
-	mtx_lock(&np->n_mtx);
+	NFSLOCKNODE(np);
 	for (i = 0; i < NFS_ACCESSCACHESIZE; i++)
 		np->n_accesscache[i].stamp = 0;
 	KDTRACE_NFS_ACCESSCACHE_FLUSH_DONE(vp);
 	np->n_attrstamp = 0;
 	KDTRACE_NFS_ATTRCACHE_FLUSH_DONE(vp);
-	mtx_unlock(&np->n_mtx);
+	NFSUNLOCKNODE(np);
 }

Modified: head/sys/fs/nfsclient/nfs_clport.c
==============================================================================
--- head/sys/fs/nfsclient/nfs_clport.c	Tue Sep 24 01:56:27 2019	(r352635)
+++ head/sys/fs/nfsclient/nfs_clport.c	Tue Sep 24 01:58:54 2019	(r352636)
@@ -742,12 +742,12 @@ nfscl_wcc_data(struct nfsrv_descript *nd, struct vnode
 		if (*tl == newnfs_true) {
 			NFSM_DISSECT(tl, u_int32_t *, 6 * NFSX_UNSIGNED);
 			if (wccflagp != NULL) {
-				mtx_lock(&np->n_mtx);
+				NFSLOCKNODE(np);
 				*wccflagp = (np->n_mtime.tv_sec ==
 				    fxdr_unsigned(u_int32_t, *(tl + 2)) &&
 				    np->n_mtime.tv_nsec ==
 				    fxdr_unsigned(u_int32_t, *(tl + 3)));
-				mtx_unlock(&np->n_mtx);
+				NFSUNLOCKNODE(np);
 			}
 		}
 		error = nfscl_postop_attr(nd, nap, flagp, stuff);
@@ -768,12 +768,12 @@ nfscl_wcc_data(struct nfsrv_descript *nd, struct vnode
 			nd->nd_flag |= ND_NOMOREDATA;
 		if (wccflagp != NULL &&
 		    nfsva.na_vattr.va_mtime.tv_sec != 0) {
-			mtx_lock(&np->n_mtx);
+			NFSLOCKNODE(np);
 			*wccflagp = (np->n_mtime.tv_sec ==
 			    nfsva.na_vattr.va_mtime.tv_sec &&
 			    np->n_mtime.tv_nsec ==
 			    nfsva.na_vattr.va_mtime.tv_sec);
-			mtx_unlock(&np->n_mtx);
+			NFSUNLOCKNODE(np);
 		}
 	}
 nfsmout:

Modified: head/sys/fs/nfsclient/nfs_clrpcops.c
==============================================================================
--- head/sys/fs/nfsclient/nfs_clrpcops.c	Tue Sep 24 01:56:27 2019	(r352635)
+++ head/sys/fs/nfsclient/nfs_clrpcops.c	Tue Sep 24 01:58:54 2019	(r352636)
@@ -5952,9 +5952,9 @@ nfscl_doflayoutio(vnode_t vp, struct uio *uiop, int *i
 				error = EIO;
 		} else {
 			commit_thru_mds = 0;
-			mtx_lock(&np->n_mtx);
+			NFSLOCKNODE(np);
 			np->n_flag |= NDSCOMMIT;
-			mtx_unlock(&np->n_mtx);
+			NFSUNLOCKNODE(np);
 		}
 		if (docommit != 0) {
 			if (error == 0)
@@ -5968,9 +5968,9 @@ nfscl_doflayoutio(vnode_t vp, struct uio *uiop, int *i
 				*eofp = 1;
 				uiop->uio_resid = 0;
 			} else {
-				mtx_lock(&np->n_mtx);
+				NFSLOCKNODE(np);
 				np->n_flag &= ~NDSCOMMIT;
-				mtx_unlock(&np->n_mtx);
+				NFSUNLOCKNODE(np);
 			}
 		} else if (rwflag == NFSV4OPEN_ACCESSREAD)
 			error = nfsrpc_readds(vp, uiop, stateidp, eofp, *dspp,
@@ -6036,9 +6036,9 @@ nfscl_dofflayoutio(vnode_t vp, struct uio *uiop, int *
 			transfer = dp->nfsdi_rsize;
 		else
 			transfer = dp->nfsdi_wsize;
-		mtx_lock(&np->n_mtx);
+		NFSLOCKNODE(np);
 		np->n_flag |= NDSCOMMIT;
-		mtx_unlock(&np->n_mtx);
+		NFSUNLOCKNODE(np);
 		if (len > transfer && docommit == 0)
 			xfer = transfer;
 		else
@@ -6075,9 +6075,9 @@ nfscl_dofflayoutio(vnode_t vp, struct uio *uiop, int *
 				*eofp = 1;
 				uiop->uio_resid = 0;
 			} else {
-				mtx_lock(&np->n_mtx);
+				NFSLOCKNODE(np);
 				np->n_flag &= ~NDSCOMMIT;
-				mtx_unlock(&np->n_mtx);
+				NFSUNLOCKNODE(np);
 			}
 		} else if (rwflag == NFSV4OPEN_ACCESSREAD) {
 			error = nfsrpc_readds(vp, uiop, stateidp, eofp, *dspp,

Modified: head/sys/fs/nfsclient/nfs_clsubs.c
==============================================================================
--- head/sys/fs/nfsclient/nfs_clsubs.c	Tue Sep 24 01:56:27 2019	(r352635)
+++ head/sys/fs/nfsclient/nfs_clsubs.c	Tue Sep 24 01:58:54 2019	(r352636)
@@ -121,20 +121,20 @@ ncl_uninit(struct vfsconf *vfsp)
 void 
 ncl_dircookie_lock(struct nfsnode *np)
 {
-	mtx_lock(&np->n_mtx);
+	NFSLOCKNODE(np);
 	while (np->n_flag & NDIRCOOKIELK)
 		(void) msleep(&np->n_flag, &np->n_mtx, PZERO, "nfsdirlk", 0);
 	np->n_flag |= NDIRCOOKIELK;
-	mtx_unlock(&np->n_mtx);
+	NFSUNLOCKNODE(np);
 }
 
 void 
 ncl_dircookie_unlock(struct nfsnode *np)
 {
-	mtx_lock(&np->n_mtx);
+	NFSLOCKNODE(np);
 	np->n_flag &= ~NDIRCOOKIELK;
 	wakeup(&np->n_flag);
-	mtx_unlock(&np->n_mtx);
+	NFSUNLOCKNODE(np);
 }
 
 bool
@@ -190,7 +190,7 @@ ncl_getattrcache(struct vnode *vp, struct vattr *vaper
 	vap = &np->n_vattr.na_vattr;
 	nmp = VFSTONFS(vp->v_mount);
 	mustflush = nfscl_mustflush(vp);	/* must be before mtx_lock() */
-	mtx_lock(&np->n_mtx);
+	NFSLOCKNODE(np);
 	/* XXX n_mtime doesn't seem to be updated on a miss-and-reload */
 	timeo = (time_second - np->n_mtime.tv_sec) / 10;
 
@@ -225,7 +225,7 @@ ncl_getattrcache(struct vnode *vp, struct vattr *vaper
 	if ((time_second - np->n_attrstamp) >= timeo &&
 	    (mustflush != 0 || np->n_attrstamp == 0)) {
 		nfsstatsv1.attrcache_misses++;
-		mtx_unlock(&np->n_mtx);
+		NFSUNLOCKNODE(np);
 		KDTRACE_NFS_ATTRCACHE_GET_MISS(vp);
 		return( ENOENT);
 	}
@@ -252,7 +252,7 @@ ncl_getattrcache(struct vnode *vp, struct vattr *vaper
 		if (np->n_flag & NUPD)
 			vaper->va_mtime = np->n_mtim;
 	}
-	mtx_unlock(&np->n_mtx);
+	NFSUNLOCKNODE(np);
 	KDTRACE_NFS_ATTRCACHE_GET_HIT(vp, vap);
 	return (0);
 }

Modified: head/sys/fs/nfsclient/nfs_clvnops.c
==============================================================================
--- head/sys/fs/nfsclient/nfs_clvnops.c	Tue Sep 24 01:56:27 2019	(r352635)
+++ head/sys/fs/nfsclient/nfs_clvnops.c	Tue Sep 24 01:58:54 2019	(r352636)
@@ -310,7 +310,7 @@ nfs34_access_otw(struct vnode *vp, int wmode, struct t
 		(void) nfscl_loadattrcache(&vp, &nfsva, NULL, NULL, 0, 1);
 	if (!error) {
 		lrupos = 0;
-		mtx_lock(&np->n_mtx);
+		NFSLOCKNODE(np);
 		for (i = 0; i < NFS_ACCESSCACHESIZE; i++) {
 			if (np->n_accesscache[i].uid == cred->cr_uid) {
 				np->n_accesscache[i].mode = rmode;
@@ -326,7 +326,7 @@ nfs34_access_otw(struct vnode *vp, int wmode, struct t
 			np->n_accesscache[lrupos].mode = rmode;
 			np->n_accesscache[lrupos].stamp = time_second;
 		}
-		mtx_unlock(&np->n_mtx);
+		NFSUNLOCKNODE(np);
 		if (retmode != NULL)
 			*retmode = rmode;
 		KDTRACE_NFS_ACCESSCACHE_LOAD_DONE(vp, cred->cr_uid, rmode, 0);
@@ -421,7 +421,7 @@ nfs_access(struct vop_access_args *ap)
 		 * this request?
 		 */
 		gotahit = 0;
-		mtx_lock(&np->n_mtx);
+		NFSLOCKNODE(np);
 		for (i = 0; i < NFS_ACCESSCACHESIZE; i++) {
 			if (ap->a_cred->cr_uid == np->n_accesscache[i].uid) {
 			    if (time_second < (np->n_accesscache[i].stamp
@@ -433,7 +433,7 @@ nfs_access(struct vop_access_args *ap)
 			    break;
 			}
 		}
-		mtx_unlock(&np->n_mtx);
+		NFSUNLOCKNODE(np);
 #ifdef KDTRACE_HOOKS
 		if (gotahit != 0)
 			KDTRACE_NFS_ACCESSCACHE_GET_HIT(vp,
@@ -465,14 +465,14 @@ nfs_access(struct vop_access_args *ap)
 		 * After calling nfsspec_access, we should have the correct
 		 * file size cached.
 		 */
-		mtx_lock(&np->n_mtx);
+		NFSLOCKNODE(np);
 		if (ap->a_cred->cr_uid == 0 && (ap->a_accmode & VREAD)
 		    && VTONFS(vp)->n_size > 0) {
 			struct iovec aiov;
 			struct uio auio;
 			char buf[1];
 
-			mtx_unlock(&np->n_mtx);
+			NFSUNLOCKNODE(np);
 			aiov.iov_base = buf;
 			aiov.iov_len = 1;
 			auio.uio_iov = &aiov;
@@ -498,7 +498,7 @@ nfs_access(struct vop_access_args *ap)
 			else
 				error = EACCES;
 		} else
-			mtx_unlock(&np->n_mtx);
+			NFSUNLOCKNODE(np);
 		return (error);
 	}
 }
@@ -543,52 +543,52 @@ nfs_open(struct vop_open_args *ap)
 	 * Now, if this Open will be doing reading, re-validate/flush the
 	 * cache, so that Close/Open coherency is maintained.
 	 */
-	mtx_lock(&np->n_mtx);
+	NFSLOCKNODE(np);
 	if (np->n_flag & NMODIFIED) {
-		mtx_unlock(&np->n_mtx);
+		NFSUNLOCKNODE(np);
 		error = ncl_vinvalbuf(vp, V_SAVE, ap->a_td, 1);
 		if (error == EINTR || error == EIO) {
 			if (NFS_ISV4(vp))
 				(void) nfsrpc_close(vp, 0, ap->a_td);
 			return (error);
 		}
-		mtx_lock(&np->n_mtx);
+		NFSLOCKNODE(np);
 		np->n_attrstamp = 0;
 		KDTRACE_NFS_ATTRCACHE_FLUSH_DONE(vp);
 		if (vp->v_type == VDIR)
 			np->n_direofoffset = 0;
-		mtx_unlock(&np->n_mtx);
+		NFSUNLOCKNODE(np);
 		error = VOP_GETATTR(vp, &vattr, ap->a_cred);
 		if (error) {
 			if (NFS_ISV4(vp))
 				(void) nfsrpc_close(vp, 0, ap->a_td);
 			return (error);
 		}
-		mtx_lock(&np->n_mtx);
+		NFSLOCKNODE(np);
 		np->n_mtime = vattr.va_mtime;
 		if (NFS_ISV4(vp))
 			np->n_change = vattr.va_filerev;
 	} else {
-		mtx_unlock(&np->n_mtx);
+		NFSUNLOCKNODE(np);
 		error = VOP_GETATTR(vp, &vattr, ap->a_cred);
 		if (error) {
 			if (NFS_ISV4(vp))
 				(void) nfsrpc_close(vp, 0, ap->a_td);
 			return (error);
 		}
-		mtx_lock(&np->n_mtx);
+		NFSLOCKNODE(np);
 		if ((NFS_ISV4(vp) && np->n_change != vattr.va_filerev) ||
 		    NFS_TIMESPEC_COMPARE(&np->n_mtime, &vattr.va_mtime)) {
 			if (vp->v_type == VDIR)
 				np->n_direofoffset = 0;
-			mtx_unlock(&np->n_mtx);
+			NFSUNLOCKNODE(np);
 			error = ncl_vinvalbuf(vp, V_SAVE, ap->a_td, 1);
 			if (error == EINTR || error == EIO) {
 				if (NFS_ISV4(vp))
 					(void) nfsrpc_close(vp, 0, ap->a_td);
 				return (error);
 			}
-			mtx_lock(&np->n_mtx);
+			NFSLOCKNODE(np);
 			np->n_mtime = vattr.va_mtime;
 			if (NFS_ISV4(vp))
 				np->n_change = vattr.va_filerev;
@@ -601,14 +601,14 @@ nfs_open(struct vop_open_args *ap)
 	if (newnfs_directio_enable && (fmode & O_DIRECT) &&
 	    (vp->v_type == VREG)) {
 		if (np->n_directio_opens == 0) {
-			mtx_unlock(&np->n_mtx);
+			NFSUNLOCKNODE(np);
 			error = ncl_vinvalbuf(vp, V_SAVE, ap->a_td, 1);
 			if (error) {
 				if (NFS_ISV4(vp))
 					(void) nfsrpc_close(vp, 0, ap->a_td);
 				return (error);
 			}
-			mtx_lock(&np->n_mtx);
+			NFSLOCKNODE(np);
 			np->n_flag |= NNONCACHE;
 		}
 		np->n_directio_opens++;
@@ -630,7 +630,7 @@ nfs_open(struct vop_open_args *ap)
 		np->n_writecred = crhold(ap->a_cred);
 	} else
 		cred = NULL;
-	mtx_unlock(&np->n_mtx);
+	NFSUNLOCKNODE(np);
 
 	if (cred != NULL)
 		crfree(cred);
@@ -657,9 +657,9 @@ nfs_open(struct vop_open_args *ap)
 
 		/* And, finally, make sure that n_mtime is up to date. */
 		np = VTONFS(vp);
-		mtx_lock(&np->n_mtx);
+		NFSLOCKNODE(np);
 		np->n_mtime = np->n_vattr.na_mtime;
-		mtx_unlock(&np->n_mtx);
+		NFSUNLOCKNODE(np);
 	}
 	return (0);
 }
@@ -734,9 +734,9 @@ nfs_close(struct vop_close_args *ap)
 		vm_object_page_clean(vp->v_object, 0, 0, 0);
 		VM_OBJECT_WUNLOCK(vp->v_object);
 	    }
-	    mtx_lock(&np->n_mtx);
+	    NFSLOCKNODE(np);
 	    if (np->n_flag & NMODIFIED) {
-		mtx_unlock(&np->n_mtx);
+		NFSUNLOCKNODE(np);
 		if (NFS_ISV3(vp)) {
 		    /*
 		     * Under NFSv3 we have dirty buffers to dispose of.  We
@@ -770,7 +770,7 @@ nfs_close(struct vop_close_args *ap)
 		} else {
 			error = ncl_vinvalbuf(vp, V_SAVE, ap->a_td, 1);
 		}
-		mtx_lock(&np->n_mtx);
+		NFSLOCKNODE(np);
 	    }
  	    /* 
  	     * Invalidate the attribute cache in all cases.
@@ -795,7 +795,7 @@ nfs_close(struct vop_close_args *ap)
 		np->n_flag &= ~NWRITEERR;
 		error = np->n_error;
 	    }
-	    mtx_unlock(&np->n_mtx);
+	    NFSUNLOCKNODE(np);
 	}
 
 	if (NFS_ISV4(vp)) {
@@ -829,13 +829,13 @@ nfs_close(struct vop_close_args *ap)
 			("nfs_close: dirty unflushed (%d) directio buffers\n",
 			 np->n_directio_asyncwr));
 	if (newnfs_directio_enable && (fmode & O_DIRECT) && (vp->v_type == VREG)) {
-		mtx_lock(&np->n_mtx);
+		NFSLOCKNODE(np);
 		KASSERT((np->n_directio_opens > 0), 
 			("nfs_close: unexpectedly value (0) of n_directio_opens\n"));
 		np->n_directio_opens--;
 		if (np->n_directio_opens == 0)
 			np->n_flag &= ~NNONCACHE;
-		mtx_unlock(&np->n_mtx);
+		NFSUNLOCKNODE(np);
 	}
 	if (localcred)
 		NFSFREECRED(cred);
@@ -859,10 +859,10 @@ nfs_getattr(struct vop_getattr_args *ap)
 	/*
 	 * Update local times for special files.
 	 */
-	mtx_lock(&np->n_mtx);
+	NFSLOCKNODE(np);
 	if (np->n_flag & (NACC | NUPD))
 		np->n_flag |= NCHG;
-	mtx_unlock(&np->n_mtx);
+	NFSUNLOCKNODE(np);
 	/*
 	 * First look in the cache.
 	 */
@@ -976,14 +976,14 @@ nfs_setattr(struct vop_setattr_args *ap)
 			 * V_SAVE races that might setsize a lower
 			 * value.
 			 */
-			mtx_lock(&np->n_mtx);
+			NFSLOCKNODE(np);
 			tsize = np->n_size;
-			mtx_unlock(&np->n_mtx);
+			NFSUNLOCKNODE(np);
 			error = ncl_meta_setsize(vp, td, vap->va_size);
-			mtx_lock(&np->n_mtx);
+			NFSLOCKNODE(np);
  			if (np->n_flag & NMODIFIED) {
 			    tsize = np->n_size;
-			    mtx_unlock(&np->n_mtx);
+			    NFSUNLOCKNODE(np);
 			    error = ncl_vinvalbuf(vp, vap->va_size == 0 ?
 			        0 : V_SAVE, td, 1);
 			    if (error != 0) {
@@ -996,34 +996,34 @@ nfs_setattr(struct vop_setattr_args *ap)
 			     */
 			    nfscl_delegmodtime(vp);
  			} else
-			    mtx_unlock(&np->n_mtx);
+			    NFSUNLOCKNODE(np);
 			/*
 			 * np->n_size has already been set to vap->va_size
 			 * in ncl_meta_setsize(). We must set it again since
 			 * nfs_loadattrcache() could be called through
 			 * ncl_meta_setsize() and could modify np->n_size.
 			 */
-			mtx_lock(&np->n_mtx);
+			NFSLOCKNODE(np);
  			np->n_vattr.na_size = np->n_size = vap->va_size;
-			mtx_unlock(&np->n_mtx);
+			NFSUNLOCKNODE(np);
   		}
   	} else {
-		mtx_lock(&np->n_mtx);
+		NFSLOCKNODE(np);
 		if ((vap->va_mtime.tv_sec != VNOVAL || vap->va_atime.tv_sec != VNOVAL) && 
 		    (np->n_flag & NMODIFIED) && vp->v_type == VREG) {
-			mtx_unlock(&np->n_mtx);
+			NFSUNLOCKNODE(np);
 			error = ncl_vinvalbuf(vp, V_SAVE, td, 1);
 			if (error == EINTR || error == EIO)
 				return (error);
 		} else
-			mtx_unlock(&np->n_mtx);
+			NFSUNLOCKNODE(np);
 	}
 	error = nfs_setattrrpc(vp, vap, ap->a_cred, td);
 	if (error && vap->va_size != VNOVAL) {
-		mtx_lock(&np->n_mtx);
+		NFSLOCKNODE(np);
 		np->n_size = np->n_vattr.na_size = tsize;
 		vnode_pager_setsize(vp, tsize);
-		mtx_unlock(&np->n_mtx);
+		NFSUNLOCKNODE(np);
 	}
 	return (error);
 }
@@ -1040,11 +1040,11 @@ nfs_setattrrpc(struct vnode *vp, struct vattr *vap, st
 	struct nfsvattr nfsva;
 
 	if (NFS_ISV34(vp)) {
-		mtx_lock(&np->n_mtx);
+		NFSLOCKNODE(np);
 		for (i = 0; i < NFS_ACCESSCACHESIZE; i++)
 			np->n_accesscache[i].stamp = 0;
 		np->n_flag |= NDELEGMOD;
-		mtx_unlock(&np->n_mtx);
+		NFSUNLOCKNODE(np);
 		KDTRACE_NFS_ACCESSCACHE_FLUSH_DONE(vp);
 	}
 	error = nfsrpc_setattr(vp, vap, NULL, cred, td, &nfsva, &attrflag,
@@ -1092,12 +1092,12 @@ nfs_lookup(struct vop_lookup_args *ap)
 	np = VTONFS(dvp);
 
 	/* For NFSv4, wait until any remove is done. */
-	mtx_lock(&np->n_mtx);
+	NFSLOCKNODE(np);
 	while (NFSHASNFSV4(nmp) && (np->n_flag & NREMOVEINPROG)) {
 		np->n_flag |= NREMOVEWANT;
 		(void) msleep((caddr_t)np, &np->n_mtx, PZERO, "nfslkup", 0);
 	}
-	mtx_unlock(&np->n_mtx);
+	NFSUNLOCKNODE(np);
 
 	if ((error = VOP_ACCESS(dvp, VEXEC, cnp->cn_cred, td)) != 0)
 		return (error);
@@ -1139,10 +1139,10 @@ nfs_lookup(struct vop_lookup_args *ap)
 		if (!(nmp->nm_flag & NFSMNT_NOCTO) &&
 		    (flags & (ISLASTCN | ISOPEN)) == (ISLASTCN | ISOPEN) &&
 		    !(newnp->n_flag & NMODIFIED)) {
-			mtx_lock(&newnp->n_mtx);
+			NFSLOCKNODE(newnp);
 			newnp->n_attrstamp = 0;
 			KDTRACE_NFS_ATTRCACHE_FLUSH_DONE(newvp);
-			mtx_unlock(&newnp->n_mtx);
+			NFSUNLOCKNODE(newnp);
 		}
 		if (nfscl_nodeleg(newvp, 0) == 0 ||
 		    ((u_int)(ticks - ncticks) < (nmp->nm_nametimeo * hz) &&
@@ -1224,14 +1224,14 @@ nfs_lookup(struct vop_lookup_args *ap)
 			 * has changed.  Don't bother adding the entry
 			 * if the directory has already changed.
 			 */
-			mtx_lock(&np->n_mtx);
+			NFSLOCKNODE(np);
 			if (timespeccmp(&np->n_vattr.na_mtime,
 			    &dnfsva.na_mtime, ==)) {
-				mtx_unlock(&np->n_mtx);
+				NFSUNLOCKNODE(np);
 				cache_enter_time(dvp, NULL, cnp,
 				    &dnfsva.na_mtime, NULL);
 			} else
-				mtx_unlock(&np->n_mtx);
+				NFSUNLOCKNODE(np);
 		}
 		return (ENOENT);
 	}
@@ -1319,10 +1319,10 @@ nfs_lookup(struct vop_lookup_args *ap)
 			 * are fetched in nfs_open() since we did not
 			 * fetch attributes from the LOOKUP reply.
 			 */
-			mtx_lock(&np->n_mtx);
+			NFSLOCKNODE(np);
 			np->n_attrstamp = 0;
 			KDTRACE_NFS_ATTRCACHE_FLUSH_DONE(newvp);
-			mtx_unlock(&np->n_mtx);
+			NFSUNLOCKNODE(np);
 		}
 	}
 	if (cnp->cn_nameiop != LOOKUP && (flags & ISLASTCN))
@@ -1516,13 +1516,13 @@ nfs_mknodrpc(struct vnode *dvp, struct vnode **vpp, st
 		    vap->va_gid);
 	}
 	dnp = VTONFS(dvp);
-	mtx_lock(&dnp->n_mtx);
+	NFSLOCKNODE(dnp);
 	dnp->n_flag |= NMODIFIED;
 	if (!dattrflag) {
 		dnp->n_attrstamp = 0;
 		KDTRACE_NFS_ATTRCACHE_FLUSH_DONE(dvp);
 	}
-	mtx_unlock(&dnp->n_mtx);
+	NFSUNLOCKNODE(dnp);
 	return (error);
 }
 
@@ -1593,12 +1593,12 @@ nfs_create(struct vop_create_args *ap)
 	nmp = VFSTONFS(vnode_mount(dvp));
 again:
 	/* For NFSv4, wait until any remove is done. */
-	mtx_lock(&dnp->n_mtx);
+	NFSLOCKNODE(dnp);
 	while (NFSHASNFSV4(nmp) && (dnp->n_flag & NREMOVEINPROG)) {
 		dnp->n_flag |= NREMOVEWANT;
 		(void) msleep((caddr_t)dnp, &dnp->n_mtx, PZERO, "nfscrt", 0);
 	}
-	mtx_unlock(&dnp->n_mtx);
+	NFSUNLOCKNODE(dnp);
 
 	cverf = nfs_get_cverf();
 	error = nfsrpc_create(dvp, cnp->cn_nameptr, cnp->cn_namelen,
@@ -1664,13 +1664,13 @@ again:
 		error = nfscl_maperr(cnp->cn_thread, error, vap->va_uid,
 		    vap->va_gid);
 	}
-	mtx_lock(&dnp->n_mtx);
+	NFSLOCKNODE(dnp);
 	dnp->n_flag |= NMODIFIED;
 	if (!dattrflag) {
 		dnp->n_attrstamp = 0;
 		KDTRACE_NFS_ATTRCACHE_FLUSH_DONE(dvp);
 	}
-	mtx_unlock(&dnp->n_mtx);
+	NFSUNLOCKNODE(dnp);
 	return (error);
 }
 
@@ -1729,9 +1729,9 @@ nfs_remove(struct vop_remove_args *ap)
 			error = 0;
 	} else if (!np->n_sillyrename)
 		error = nfs_sillyrename(dvp, vp, cnp);
-	mtx_lock(&np->n_mtx);
+	NFSLOCKNODE(np);
 	np->n_attrstamp = 0;
-	mtx_unlock(&np->n_mtx);
+	NFSUNLOCKNODE(np);
 	KDTRACE_NFS_ATTRCACHE_FLUSH_DONE(vp);
 	return (error);
 }
@@ -1763,29 +1763,29 @@ nfs_removerpc(struct vnode *dvp, struct vnode *vp, cha
 	struct nfsnode *dnp = VTONFS(dvp);
 	int error = 0, dattrflag;
 
-	mtx_lock(&dnp->n_mtx);
+	NFSLOCKNODE(dnp);
 	dnp->n_flag |= NREMOVEINPROG;
-	mtx_unlock(&dnp->n_mtx);
+	NFSUNLOCKNODE(dnp);
 	error = nfsrpc_remove(dvp, name, namelen, vp, cred, td, &dnfsva,
 	    &dattrflag, NULL);
-	mtx_lock(&dnp->n_mtx);

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***


More information about the svn-src-all mailing list