Module Name:    src
Committed By:   hannken
Date:           Fri Oct  5 09:51:56 UTC 2018

Modified Files:
        src/distrib/sets/lists/comp: mi
        src/share/man/man9: Makefile fstrans.9
        src/sys/dev: vnd.c
        src/sys/kern: vfs_trans.c
        src/sys/miscfs/genfs: genfs_vfsops.c
        src/sys/rump/librump/rumpkern: emul.c
        src/sys/sys: fstrans.h

Log Message:
Bring back three state file system suspension:

  NORMAL -> SUSPENDING -> SUSPENDED

and add operation fstrans_start_lazy() that only blocks while SUSPENDED.

Change vndthread() support operation handle_with_rdwr() to bracket
its file system operations by fstrans_start_lazy() and fstrans_done().

PR kern/53624 (dom0 freeze on domU exit)


To generate a diff of this commit:
cvs rdiff -u -r1.2232 -r1.2233 src/distrib/sets/lists/comp/mi
cvs rdiff -u -r1.430 -r1.431 src/share/man/man9/Makefile
cvs rdiff -u -r1.26 -r1.27 src/share/man/man9/fstrans.9
cvs rdiff -u -r1.265 -r1.266 src/sys/dev/vnd.c
cvs rdiff -u -r1.50 -r1.51 src/sys/kern/vfs_trans.c
cvs rdiff -u -r1.7 -r1.8 src/sys/miscfs/genfs/genfs_vfsops.c
cvs rdiff -u -r1.186 -r1.187 src/sys/rump/librump/rumpkern/emul.c
cvs rdiff -u -r1.11 -r1.12 src/sys/sys/fstrans.h

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

Modified files:

Index: src/distrib/sets/lists/comp/mi
diff -u src/distrib/sets/lists/comp/mi:1.2232 src/distrib/sets/lists/comp/mi:1.2233
--- src/distrib/sets/lists/comp/mi:1.2232	Wed Sep 26 12:59:37 2018
+++ src/distrib/sets/lists/comp/mi	Fri Oct  5 09:51:55 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: mi,v 1.2232 2018/09/26 12:59:37 rin Exp $
+#	$NetBSD: mi,v 1.2233 2018/10/05 09:51:55 hannken Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 ./etc/mtree/set.comp				comp-sys-root
@@ -10988,6 +10988,7 @@
 ./usr/share/man/cat9/fstrans_is_owner.0		comp-sys-catman		.cat
 ./usr/share/man/cat9/fstrans_setstate.0		comp-sys-catman		.cat
 ./usr/share/man/cat9/fstrans_start.0		comp-sys-catman		.cat
+./usr/share/man/cat9/fstrans_start_lazy.0	comp-sys-catman		.cat
 ./usr/share/man/cat9/fstrans_start_nowait.0	comp-sys-catman		.cat
 ./usr/share/man/cat9/fubyte.0			comp-sys-catman		.cat
 ./usr/share/man/cat9/fuibyte.0			comp-sys-catman		.cat
@@ -18801,6 +18802,7 @@
 ./usr/share/man/html9/fstrans_is_owner.html	comp-sys-htmlman	html
 ./usr/share/man/html9/fstrans_setstate.html	comp-sys-htmlman	html
 ./usr/share/man/html9/fstrans_start.html	comp-sys-htmlman	html
+./usr/share/man/html9/fstrans_start_lazy.html	comp-sys-htmlman	html
 ./usr/share/man/html9/fstrans_start_nowait.html comp-sys-htmlman	html
 ./usr/share/man/html9/fubyte.html		comp-sys-htmlman	html
 ./usr/share/man/html9/fuibyte.html		comp-sys-htmlman	html
@@ -26760,6 +26762,7 @@
 ./usr/share/man/man9/fstrans_is_owner.9		comp-sys-man		.man
 ./usr/share/man/man9/fstrans_setstate.9		comp-sys-man		.man
 ./usr/share/man/man9/fstrans_start.9		comp-sys-man		.man
+./usr/share/man/man9/fstrans_start_lazy.9	comp-sys-man		.man
 ./usr/share/man/man9/fstrans_start_nowait.9	comp-sys-man		.man
 ./usr/share/man/man9/fubyte.9			comp-sys-man		.man
 ./usr/share/man/man9/fuibyte.9			comp-sys-man		.man

Index: src/share/man/man9/Makefile
diff -u src/share/man/man9/Makefile:1.430 src/share/man/man9/Makefile:1.431
--- src/share/man/man9/Makefile:1.430	Thu Sep 20 06:54:36 2018
+++ src/share/man/man9/Makefile	Fri Oct  5 09:51:55 2018
@@ -1,4 +1,4 @@
-#       $NetBSD: Makefile,v 1.430 2018/09/20 06:54:36 rin Exp $
+#       $NetBSD: Makefile,v 1.431 2018/10/05 09:51:55 hannken Exp $
 
 #	Makefile for section 9 (kernel function and variable) manual pages.
 
@@ -357,6 +357,7 @@ MLINKS+=fstrans.9 fstrans_done.9 \
 	fstrans.9 fstrans_getstate.9 \
 	fstrans.9 fstrans_setstate.9 \
 	fstrans.9 fstrans_start.9 \
+	fstrans.9 fstrans_start_lazy.9 \
 	fstrans.9 fstrans_start_nowait.9 \
 	fstrans.9 fscow_establish.9 \
 	fstrans.9 fscow_disestablish.9 \

Index: src/share/man/man9/fstrans.9
diff -u src/share/man/man9/fstrans.9:1.26 src/share/man/man9/fstrans.9:1.27
--- src/share/man/man9/fstrans.9:1.26	Mon Jul  3 21:28:48 2017
+++ src/share/man/man9/fstrans.9	Fri Oct  5 09:51:55 2018
@@ -1,4 +1,4 @@
-.\"     $NetBSD: fstrans.9,v 1.26 2017/07/03 21:28:48 wiz Exp $
+.\"     $NetBSD: fstrans.9,v 1.27 2018/10/05 09:51:55 hannken Exp $
 .\"
 .\" Copyright (c) 2007 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,7 +27,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd June 4, 2017
+.Dd October 4, 2018
 .Dt FSTRANS 9
 .Os
 .Sh NAME
@@ -36,6 +36,7 @@
 .Nm fstrans_getstate ,
 .Nm fstrans_start ,
 .Nm fstrans_start_nowait ,
+.Nm fstrans_start_lazy ,
 .Nm fstrans_done ,
 .Nm fstrans_is_owner ,
 .Nm fscow_establish ,
@@ -50,6 +51,8 @@
 .Ft int
 .Fn fstrans_start_nowait "struct mount *mp"
 .Ft void
+.Fn fstrans_start_lazy "struct mount *mp"
+.Ft void
 .Fn fstrans_done "struct mount *mp"
 .Ft int
 .Fn fstrans_setstate "struct mount *mp" "enum fstrans_state new_state"
@@ -81,6 +84,15 @@ in a
 transaction, which is blocked by suspending the file system and while
 it is suspended.
 .Pp
+Operations needed while suspending the file system  must be bracketed by
+.Fn fstrans_start_lazy
+and
+.Fn fstrans_done
+in a
+.Em lazy
+transaction, which is allowed while suspending the file system, but
+blocked while the file system is suspended.
+.Pp
 Transactions are per-thread and nestable: if a thread is already in a
 transaction, it can enter another transaction without blocking.
 Each
@@ -97,6 +109,10 @@ to:
 .Bl -dash
 .It
 enter the
+.Dv FSTRANS_SUSPENDING
+to suspend all normal operations but allow lazy transactions,
+.It
+enter the
 .Dv FSTRANS_SUSPENDED
 state to suspend all operations, and
 .It
@@ -149,6 +165,12 @@ but return
 immediately if transactions are blocked in its current state.
 .Pp
 May sleep nevertheless on internal locks.
+.It Fn fstrans_start_lazy "mp"
+Like
+.Fn fstrans_start ,
+but will not block while suspending.
+.Pp
+May sleep.
 .It Fn fstrans_done "mp"
 End the current transaction on
 .Fa mp .
@@ -165,9 +187,15 @@ to
 and wait for all transactions not allowed in
 .Fa new_state
 to complete.
-.Bl -tag -width FSTRANS_SUSPENDED
+.Bl -tag -width FSTRANS_SUSPENDING
 .It Dv FSTRANS_NORMAL
 Allow all transactions.
+.It Dv FSTRANS_SUSPENDING
+Block
+.Dv FSTRANS_SHARED
+transactions but allow
+.Dv FSTRANS_LAZY
+transactions.
 .It Dv FSTRANS_SUSPENDED
 Block all transactions.
 .El
@@ -244,6 +272,9 @@ xxx_suspendctl(struct mount *mp, int cmd
 
 	switch (cmd) {
 	case SUSPEND_SUSPEND:
+		error = fstrans_setstate(mp, FSTRANS_SUSPENDING);
+		if (error)
+			return error;
 		return fstrans_setstate(mp, FSTRANS_SUSPENDED);
 
 	case SUSPEND_RESUME:

Index: src/sys/dev/vnd.c
diff -u src/sys/dev/vnd.c:1.265 src/sys/dev/vnd.c:1.266
--- src/sys/dev/vnd.c:1.265	Thu Sep 20 07:18:38 2018
+++ src/sys/dev/vnd.c	Fri Oct  5 09:51:55 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: vnd.c,v 1.265 2018/09/20 07:18:38 mlelstv Exp $	*/
+/*	$NetBSD: vnd.c,v 1.266 2018/10/05 09:51:55 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2008 The NetBSD Foundation, Inc.
@@ -91,7 +91,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vnd.c,v 1.265 2018/09/20 07:18:38 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vnd.c,v 1.266 2018/10/05 09:51:55 hannken Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_vnd.h"
@@ -114,6 +114,7 @@ __KERNEL_RCSID(0, "$NetBSD: vnd.c,v 1.26
 #include <sys/stat.h>
 #include <sys/mount.h>
 #include <sys/vnode.h>
+#include <sys/fstrans.h>
 #include <sys/file.h>
 #include <sys/uio.h>
 #include <sys/conf.h>
@@ -802,6 +803,9 @@ handle_with_rdwr(struct vnd_softc *vnd, 
 		    bp->b_bcount);
 #endif
 
+	/* Make sure the request succeeds while suspending this fs. */
+	fstrans_start_lazy(vp->v_mount);
+
 	/* Issue the read or write operation. */
 	bp->b_error =
 	    vn_rdwr(doread ? UIO_READ : UIO_WRITE,
@@ -813,6 +817,8 @@ handle_with_rdwr(struct vnd_softc *vnd, 
 	(void) VOP_PUTPAGES(vp, 0, 0,
 	    PGO_ALLPAGES | PGO_CLEANIT | PGO_FREE | PGO_SYNCIO);
 
+	fstrans_done(vp->v_mount);
+
 	/* We need to increase the number of outputs on the vnode if
 	 * there was any write to it. */
 	if (!doread) {

Index: src/sys/kern/vfs_trans.c
diff -u src/sys/kern/vfs_trans.c:1.50 src/sys/kern/vfs_trans.c:1.51
--- src/sys/kern/vfs_trans.c:1.50	Fri Oct  5 01:25:38 2018
+++ src/sys/kern/vfs_trans.c	Fri Oct  5 09:51:55 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_trans.c,v 1.50 2018/10/05 01:25:38 manu Exp $	*/
+/*	$NetBSD: vfs_trans.c,v 1.51 2018/10/05 09:51:55 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_trans.c,v 1.50 2018/10/05 01:25:38 manu Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_trans.c,v 1.51 2018/10/05 09:51:55 hannken Exp $");
 
 /*
  * File system transaction operations.
@@ -54,6 +54,7 @@ __KERNEL_RCSID(0, "$NetBSD: vfs_trans.c,
 #include <miscfs/specfs/specdev.h>
 
 enum fstrans_lock_type {
+	FSTRANS_LAZY,			/* Granted while not suspended */
 	FSTRANS_SHARED,			/* Granted while not suspending */
 	FSTRANS_EXCL			/* Internal: exclusive lock */
 };
@@ -342,6 +343,8 @@ grant_lock(const enum fstrans_state stat
 		return true;
 	if (type == FSTRANS_EXCL)
 		return true;
+	if  (state == FSTRANS_SUSPENDING && type == FSTRANS_LAZY)
+		return true;
 
 	return false;
 }
@@ -422,6 +425,15 @@ fstrans_start_nowait(struct mount *mp)
 	return _fstrans_start(mp, FSTRANS_SHARED, 0);
 }
 
+void
+fstrans_start_lazy(struct mount *mp)
+{
+	int error __diagused;
+
+	error = _fstrans_start(mp, FSTRANS_LAZY, 1);
+	KASSERT(error == 0);
+}
+
 /*
  * Finish a transaction.
  */
@@ -849,6 +861,9 @@ fstrans_print_lwp(struct proc *p, struct
 			printf(" -");
 		} else {
 			switch (fli->fli_lock_type) {
+			case FSTRANS_LAZY:
+				printf(" lazy");
+				break;
 			case FSTRANS_SHARED:
 				printf(" shared");
 				break;
@@ -883,6 +898,9 @@ fstrans_print_mount(struct mount *mp, in
 	case FSTRANS_NORMAL:
 		printf("state normal\n");
 		break;
+	case FSTRANS_SUSPENDING:
+		printf("state suspending\n");
+		break;
 	case FSTRANS_SUSPENDED:
 		printf("state suspended\n");
 		break;

Index: src/sys/miscfs/genfs/genfs_vfsops.c
diff -u src/sys/miscfs/genfs/genfs_vfsops.c:1.7 src/sys/miscfs/genfs/genfs_vfsops.c:1.8
--- src/sys/miscfs/genfs/genfs_vfsops.c:1.7	Wed May 24 09:53:55 2017
+++ src/sys/miscfs/genfs/genfs_vfsops.c	Fri Oct  5 09:51:55 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: genfs_vfsops.c,v 1.7 2017/05/24 09:53:55 hannken Exp $	*/
+/*	$NetBSD: genfs_vfsops.c,v 1.8 2018/10/05 09:51:55 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: genfs_vfsops.c,v 1.7 2017/05/24 09:53:55 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: genfs_vfsops.c,v 1.8 2018/10/05 09:51:55 hannken Exp $");
 
 #include <sys/types.h>
 #include <sys/mount.h>
@@ -83,6 +83,9 @@ genfs_suspendctl(struct mount *mp, int c
 
 	switch (cmd) {
 	case SUSPEND_SUSPEND:
+		error = fstrans_setstate(mp, FSTRANS_SUSPENDING);
+		if (error)
+			return error;
 		error = fstrans_setstate(mp, FSTRANS_SUSPENDED);
 		if (error == 0) {
 			if ((mp->mnt_iflag & IMNT_GONE) != 0)

Index: src/sys/rump/librump/rumpkern/emul.c
diff -u src/sys/rump/librump/rumpkern/emul.c:1.186 src/sys/rump/librump/rumpkern/emul.c:1.187
--- src/sys/rump/librump/rumpkern/emul.c:1.186	Fri Aug 10 21:44:59 2018
+++ src/sys/rump/librump/rumpkern/emul.c	Fri Oct  5 09:51:55 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: emul.c,v 1.186 2018/08/10 21:44:59 pgoyette Exp $	*/
+/*	$NetBSD: emul.c,v 1.187 2018/10/05 09:51:55 hannken Exp $	*/
 
 /*
  * Copyright (c) 2007-2011 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: emul.c,v 1.186 2018/08/10 21:44:59 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: emul.c,v 1.187 2018/10/05 09:51:55 hannken Exp $");
 
 #include <sys/param.h>
 #include <sys/cprng.h>
@@ -275,6 +275,15 @@ rump_fstrans_start_nowait(struct mount *
 }
 __weak_alias(fstrans_start_nowait,rump_fstrans_start_nowait);
 
+void rump_fstrans_start_lazy(struct mount *);
+void
+rump_fstrans_start_lazy(struct mount *mp)
+{
+
+}
+__weak_alias(fstrans_start_lazy,rump_fstrans_start_lazy);
+
+
 void rump_fstrans_done(struct mount *);
 void
 rump_fstrans_done(struct mount *mp)

Index: src/sys/sys/fstrans.h
diff -u src/sys/sys/fstrans.h:1.11 src/sys/sys/fstrans.h:1.12
--- src/sys/sys/fstrans.h:1.11	Sun Jun  4 08:05:42 2017
+++ src/sys/sys/fstrans.h	Fri Oct  5 09:51:56 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: fstrans.h,v 1.11 2017/06/04 08:05:42 hannken Exp $	*/
+/*	$NetBSD: fstrans.h,v 1.12 2018/10/05 09:51:56 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -43,12 +43,14 @@
 
 enum fstrans_state {
 	FSTRANS_NORMAL,
-	FSTRANS_SUSPENDED
+	FSTRANS_SUSPENDED,
+	FSTRANS_SUSPENDING
 };
 
 void	fstrans_init(void);
 void	fstrans_start(struct mount *);
 int	fstrans_start_nowait(struct mount *);
+void	fstrans_start_lazy(struct mount *);
 void	fstrans_done(struct mount *);
 int	fstrans_is_owner(struct mount *);
 int	fstrans_mount(struct mount *);

Reply via email to