Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 12 Jan 2018 13:39:02 +0000 (UTC)
From:      Mateusz Guzik <mjg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r327874 - head/sys/kern
Message-ID:  <201801121339.w0CDd2ml046528@repo.freebsd.org>

Next in thread | Raw E-Mail | Index | Archive | Help
Author: mjg
Date: Fri Jan 12 13:39:02 2018
New Revision: 327874
URL: https://svnweb.freebsd.org/changeset/base/327874

Log:
  vfs: tidy up vdrop
  
  Skip vfs_refcount_release_if_not_last if the interlock is held and just
  go straight to refcount_release.
  
  While here do cosmetic rearrangement of _vhold to better show it contains
  equivalent behaviour.

Modified:
  head/sys/kern/vfs_subr.c

Modified: head/sys/kern/vfs_subr.c
==============================================================================
--- head/sys/kern/vfs_subr.c	Fri Jan 12 12:14:52 2018	(r327873)
+++ head/sys/kern/vfs_subr.c	Fri Jan 12 13:39:02 2018	(r327874)
@@ -2840,14 +2840,14 @@ _vhold(struct vnode *vp, bool locked)
 	else
 		ASSERT_VI_UNLOCKED(vp, __func__);
 	CTR2(KTR_VFS, "%s: vp %p", __func__, vp);
-	if (!locked && vfs_refcount_acquire_if_not_zero(&vp->v_holdcnt)) {
-		VNASSERT((vp->v_iflag & VI_FREE) == 0, vp,
-		    ("_vhold: vnode with holdcnt is free"));
-		return;
-	}
-
-	if (!locked)
+	if (!locked) {
+		if (vfs_refcount_acquire_if_not_zero(&vp->v_holdcnt)) {
+			VNASSERT((vp->v_iflag & VI_FREE) == 0, vp,
+			    ("_vhold: vnode with holdcnt is free"));
+			return;
+		}
 		VI_LOCK(vp);
+	}
 	if ((vp->v_iflag & VI_FREE) == 0) {
 		refcount_acquire(&vp->v_holdcnt);
 		if (!locked)
@@ -2911,14 +2911,11 @@ _vdrop(struct vnode *vp, bool locked)
 	CTR2(KTR_VFS, "%s: vp %p", __func__, vp);
 	if ((int)vp->v_holdcnt <= 0)
 		panic("vdrop: holdcnt %d", vp->v_holdcnt);
-	if (vfs_refcount_release_if_not_last(&vp->v_holdcnt)) {
-		if (locked)
-			VI_UNLOCK(vp);
-		return;
-	}
-
-	if (!locked)
+	if (!locked) {
+		if (vfs_refcount_release_if_not_last(&vp->v_holdcnt))
+			return;
 		VI_LOCK(vp);
+	}
 	if (refcount_release(&vp->v_holdcnt) == 0) {
 		VI_UNLOCK(vp);
 		return;



Want to link to this message? Use this URL: <http://docs.FreeBSD.org/cgi/mid.cgi?201801121339.w0CDd2ml046528>