Module Name:    src
Committed By:   hannken
Date:           Sun May  7 08:26:58 UTC 2017

Modified Files:
        src/sys/kern: vfs_mount.c vfs_subr.c vfs_syscalls.c

Log Message:
Enter fstrans from _vfs_busy() and leave from vfs_unbusy().

Adapt sched_sync() and do_sys_sync().


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/sys/kern/vfs_mount.c
cvs rdiff -u -r1.463 -r1.464 src/sys/kern/vfs_subr.c
cvs rdiff -u -r1.514 -r1.515 src/sys/kern/vfs_syscalls.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/vfs_mount.c
diff -u src/sys/kern/vfs_mount.c:1.60 src/sys/kern/vfs_mount.c:1.61
--- src/sys/kern/vfs_mount.c:1.60	Sun May  7 08:24:20 2017
+++ src/sys/kern/vfs_mount.c	Sun May  7 08:26:58 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_mount.c,v 1.60 2017/05/07 08:24:20 hannken Exp $	*/
+/*	$NetBSD: vfs_mount.c,v 1.61 2017/05/07 08:26:58 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1997-2011 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.60 2017/05/07 08:24:20 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.61 2017/05/07 08:26:58 hannken Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -324,12 +324,19 @@ _vfs_busy(struct mount *mp, bool wait)
 	KASSERT(mp->mnt_refcnt > 0);
 
 	if (wait) {
+		fstrans_start(mp, FSTRANS_SHARED);
 		mutex_enter(&mp->mnt_unmounting);
-	} else if (!mutex_tryenter(&mp->mnt_unmounting)) {
-		return EBUSY;
+	} else {
+		if (fstrans_start_nowait(mp, FSTRANS_SHARED))
+			return EBUSY;
+		if (!mutex_tryenter(&mp->mnt_unmounting)) {
+			fstrans_done(mp);
+			return EBUSY;
+		}
 	}
 	if (__predict_false((mp->mnt_iflag & IMNT_GONE) != 0)) {
 		mutex_exit(&mp->mnt_unmounting);
+		fstrans_done(mp);
 		return ENOENT;
 	}
 	++mp->mnt_busynest;
@@ -368,6 +375,7 @@ vfs_unbusy(struct mount *mp)
 	KASSERT(mp->mnt_busynest != 0);
 	mp->mnt_busynest--;
 	mutex_exit(&mp->mnt_unmounting);
+	fstrans_done(mp);
 	vfs_rele(mp);
 }
 

Index: src/sys/kern/vfs_subr.c
diff -u src/sys/kern/vfs_subr.c:1.463 src/sys/kern/vfs_subr.c:1.464
--- src/sys/kern/vfs_subr.c:1.463	Mon Apr 17 08:34:27 2017
+++ src/sys/kern/vfs_subr.c	Sun May  7 08:26:58 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_subr.c,v 1.463 2017/04/17 08:34:27 hannken Exp $	*/
+/*	$NetBSD: vfs_subr.c,v 1.464 2017/05/07 08:26:58 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998, 2004, 2005, 2007, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.463 2017/04/17 08:34:27 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.464 2017/05/07 08:26:58 hannken Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -781,10 +781,7 @@ sched_sync(void *arg)
 				continue;
 			}
 			mp->mnt_synclist_slot = sync_delay_slot(sync_delay(mp));
-			if (fstrans_start_nowait(mp, FSTRANS_SHARED) == 0) {
-				VFS_SYNC(mp, MNT_LAZY, curlwp->l_cred);
-				fstrans_done(mp);
-			}
+			VFS_SYNC(mp, MNT_LAZY, curlwp->l_cred);
 		}
 		mountlist_iterator_destroy(iter);
 

Index: src/sys/kern/vfs_syscalls.c
diff -u src/sys/kern/vfs_syscalls.c:1.514 src/sys/kern/vfs_syscalls.c:1.515
--- src/sys/kern/vfs_syscalls.c:1.514	Sun May  7 08:25:54 2017
+++ src/sys/kern/vfs_syscalls.c	Sun May  7 08:26:58 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_syscalls.c,v 1.514 2017/05/07 08:25:54 hannken Exp $	*/
+/*	$NetBSD: vfs_syscalls.c,v 1.515 2017/05/07 08:26:58 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.514 2017/05/07 08:25:54 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.515 2017/05/07 08:26:58 hannken Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_fileassoc.h"
@@ -641,7 +641,6 @@ do_sys_sync(struct lwp *l)
 
 	mountlist_iterator_init(&iter);
 	while ((mp = mountlist_iterator_next(iter)) != NULL) {
-		fstrans_start(mp, FSTRANS_SHARED);
 		mutex_enter(&mp->mnt_updating);
 		if ((mp->mnt_flag & MNT_RDONLY) == 0) {
 			asyncflag = mp->mnt_flag & MNT_ASYNC;
@@ -651,7 +650,6 @@ do_sys_sync(struct lwp *l)
 				 mp->mnt_flag |= MNT_ASYNC;
 		}
 		mutex_exit(&mp->mnt_updating);
-		fstrans_done(mp);
 	}
 	mountlist_iterator_destroy(iter);
 #ifdef DEBUG

Reply via email to