Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 27 May 2015 09:21:48 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r283601 - in head/sys: kern sys
Message-ID:  <201505270921.t4R9LmY0064978@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Wed May 27 09:21:47 2015
New Revision: 283601
URL: https://svnweb.freebsd.org/changeset/base/283601

Log:
  Add V_MNTREF flag to the vn_start_write(9) and
  vn_start_secondary_write(9) functions.  The flag indicates that the
  caller already owns a reference on the mount point, and the functions
  can consume it.  The reference is released by vn_finished_write(9) and
  vn_finished_secondary_write(9) in due course.
  
  Tested by:	pho
  Sponsored by:	The FreeBSD Foundation
  MFC after:	2 weeks

Modified:
  head/sys/kern/vfs_vnops.c
  head/sys/sys/vnode.h

Modified: head/sys/kern/vfs_vnops.c
==============================================================================
--- head/sys/kern/vfs_vnops.c	Wed May 27 09:20:42 2015	(r283600)
+++ head/sys/kern/vfs_vnops.c	Wed May 27 09:21:47 2015	(r283601)
@@ -1646,16 +1646,18 @@ unlock:
 }
 
 int
-vn_start_write(vp, mpp, flags)
-	struct vnode *vp;
-	struct mount **mpp;
-	int flags;
+vn_start_write(struct vnode *vp, struct mount **mpp, int flags)
 {
 	struct mount *mp;
 	int error;
 
-	if (!vn_suspendable(vp, mpp))
+	KASSERT((flags & V_MNTREF) == 0 || (*mpp != NULL && vp == NULL),
+	    ("V_MNTREF requires mp"));
+	if (!vn_suspendable(vp, mpp)) {
+		if ((flags & V_MNTREF) != 0)
+			vfs_rel(*mpp);
 		return (0);
+	}
 
 	error = 0;
 	/*
@@ -1681,7 +1683,7 @@ vn_start_write(vp, mpp, flags)
 	 * emulate a vfs_ref().
 	 */
 	MNT_ILOCK(mp);
-	if (vp == NULL)
+	if (vp == NULL && (flags & V_MNTREF) == 0)
 		MNT_REF(mp);
 
 	return (vn_start_write_locked(mp, flags));
@@ -1695,16 +1697,18 @@ vn_start_write(vp, mpp, flags)
  * time, these operations are halted until the suspension is over.
  */
 int
-vn_start_secondary_write(vp, mpp, flags)
-	struct vnode *vp;
-	struct mount **mpp;
-	int flags;
+vn_start_secondary_write(struct vnode *vp, struct mount **mpp, int flags)
 {
 	struct mount *mp;
 	int error;
 
-	if (!vn_suspendable(vp, mpp))
+	KASSERT((flags & V_MNTREF) == 0 || (*mpp != NULL && vp == NULL),
+	    ("V_MNTREF requires mp"));
+	if (!vn_suspendable(vp, mpp)) {
+		if ((flags & V_MNTREF) != 0)
+			vfs_rel(*mpp);
 		return (0);
+	}
 
  retry:
 	if (vp != NULL) {
@@ -1730,7 +1734,7 @@ vn_start_secondary_write(vp, mpp, flags)
 	 * emulate a vfs_ref().
 	 */
 	MNT_ILOCK(mp);
-	if (vp == NULL)
+	if (vp == NULL && (flags & V_MNTREF) == 0)
 		MNT_REF(mp);
 	if ((mp->mnt_kern_flag & (MNTK_SUSPENDED | MNTK_SUSPEND2)) == 0) {
 		mp->mnt_secondary_writes++;

Modified: head/sys/sys/vnode.h
==============================================================================
--- head/sys/sys/vnode.h	Wed May 27 09:20:42 2015	(r283600)
+++ head/sys/sys/vnode.h	Wed May 27 09:21:47 2015	(r283601)
@@ -397,6 +397,7 @@ extern int		vttoif_tab[];
 #define	V_WAIT		0x0001	/* vn_start_write: sleep for suspend */
 #define	V_NOWAIT	0x0002	/* vn_start_write: don't sleep for suspend */
 #define	V_XSLEEP	0x0004	/* vn_start_write: just return after sleep */
+#define	V_MNTREF	0x0010	/* vn_start_write: mp is already ref-ed */
 
 #define	VR_START_WRITE	0x0001	/* vfs_write_resume: start write atomically */
 #define	VR_NO_SUSPCLR	0x0002	/* vfs_write_resume: do not clear suspension */



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