Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 16 Mar 2017 09:17:14 +0000 (UTC)
From:      Mateusz Guzik <mjg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r315401 - stable/11/sys/kern
Message-ID:  <201703160917.v2G9HERO049674@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mjg
Date: Thu Mar 16 09:17:14 2017
New Revision: 315401
URL: https://svnweb.freebsd.org/changeset/base/315401

Log:
  MFC r312600,r312601,r312602,r312606,r312646:
  
  vfs: refactor _vn_lock
  
  Stop testing for LK_RETRY and error multiple times. Also postpone the
  VI_DOOMED until after LK_RETRY was seen as it reads from the vnode.
  
  No functional changes.
  
  ==
  
  vfs: fix whitespace damage in r312600
  
  While here wrap the previously overly long line so that it fits 80 chars.
  
  ==
  
  vfs: __predict_false the need to handle F_HASLOCK
  
  Also reorder the check with DTYPE_VNODE. Passed files are vnodes vast
  majority of the time, so it is typically true.
  
  ==
  
  vfs: fix LK_RETRY logic braino in r312600
  
  ==
  
  More style cleanup.  Use ANSI C definition for vn_closefile().  Switch
  to VNASSERT in _vn_lock(), simplify messages.

Modified:
  stable/11/sys/kern/vfs_vnops.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/kern/vfs_vnops.c
==============================================================================
--- stable/11/sys/kern/vfs_vnops.c	Thu Mar 16 08:51:30 2017	(r315400)
+++ stable/11/sys/kern/vfs_vnops.c	Thu Mar 16 09:17:14 2017	(r315401)
@@ -1549,28 +1549,21 @@ _vn_lock(struct vnode *vp, int flags, ch
 	int error;
 
 	VNASSERT((flags & LK_TYPE_MASK) != 0, vp,
-	    ("vn_lock called with no locktype."));
-	do {
-#ifdef DEBUG_VFS_LOCKS
-		KASSERT(vp->v_holdcnt != 0,
-		    ("vn_lock %p: zero hold count", vp));
-#endif
-		error = VOP_LOCK1(vp, flags, file, line);
-		flags &= ~LK_INTERLOCK;	/* Interlock is always dropped. */
-		KASSERT((flags & LK_RETRY) == 0 || error == 0,
-		    ("LK_RETRY set with incompatible flags (0x%x) or an error occurred (%d)",
-		    flags, error));
-		/*
-		 * Callers specify LK_RETRY if they wish to get dead vnodes.
-		 * If RETRY is not set, we return ENOENT instead.
-		 */
-		if (error == 0 && vp->v_iflag & VI_DOOMED &&
-		    (flags & LK_RETRY) == 0) {
+	    ("vn_lock: no locktype"));
+	VNASSERT(vp->v_holdcnt != 0, vp, ("vn_lock: zero hold count"));
+retry:
+	error = VOP_LOCK1(vp, flags, file, line);
+	flags &= ~LK_INTERLOCK;	/* Interlock is always dropped. */
+	KASSERT((flags & LK_RETRY) == 0 || error == 0,
+	    ("vn_lock: error %d incompatible with flags %#x", error, flags));
+
+	if ((flags & LK_RETRY) == 0) {
+		if (error == 0 && (vp->v_iflag & VI_DOOMED) != 0) {
 			VOP_UNLOCK(vp, 0);
 			error = ENOENT;
-			break;
 		}
-	} while (flags & LK_RETRY && error != 0);
+	} else if (error != 0)
+		goto retry;
 	return (error);
 }
 
@@ -1578,9 +1571,7 @@ _vn_lock(struct vnode *vp, int flags, ch
  * File table vnode close routine.
  */
 static int
-vn_closefile(fp, td)
-	struct file *fp;
-	struct thread *td;
+vn_closefile(struct file *fp, struct thread *td)
 {
 	struct vnode *vp;
 	struct flock lf;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201703160917.v2G9HERO049674>