Module Name: src
Committed By: martin
Date: Tue Oct 9 09:58:09 UTC 2018
Modified Files:
src/distrib/sets/lists/comp [netbsd-8]: mi
src/share/man/man9 [netbsd-8]: Makefile fstrans.9
src/sys/dev [netbsd-8]: vnd.c
src/sys/kern [netbsd-8]: vfs_trans.c
src/sys/miscfs/genfs [netbsd-8]: genfs_vfsops.c
src/sys/rump/librump/rumpkern [netbsd-8]: emul.c
src/sys/sys [netbsd-8]: fstrans.h
Log Message:
Pull up following revision(s) (requested by hannken in ticket #1052):
sys/kern/vfs_trans.c: revision 1.51
distrib/sets/lists/comp/mi: revision 1.2233
share/man/man9/fstrans.9: revision 1.27
share/man/man9/Makefile: revision 1.431
sys/sys/fstrans.h: revision 1.12
sys/rump/librump/rumpkern/emul.c: revision 1.187
sys/dev/vnd.c: revision 1.266
sys/miscfs/genfs/genfs_vfsops.c: revision 1.8
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.2138.2.6 -r1.2138.2.7 src/distrib/sets/lists/comp/mi
cvs rdiff -u -r1.414.2.1 -r1.414.2.2 src/share/man/man9/Makefile
cvs rdiff -u -r1.24.2.1 -r1.24.2.2 src/share/man/man9/fstrans.9
cvs rdiff -u -r1.259.6.1 -r1.259.6.2 src/sys/dev/vnd.c
cvs rdiff -u -r1.45.2.2 -r1.45.2.3 src/sys/kern/vfs_trans.c
cvs rdiff -u -r1.7 -r1.7.2.1 src/sys/miscfs/genfs/genfs_vfsops.c
cvs rdiff -u -r1.181.6.2 -r1.181.6.3 src/sys/rump/librump/rumpkern/emul.c
cvs rdiff -u -r1.10.60.1 -r1.10.60.2 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.2138.2.6 src/distrib/sets/lists/comp/mi:1.2138.2.7
--- src/distrib/sets/lists/comp/mi:1.2138.2.6 Thu Jun 7 18:24:15 2018
+++ src/distrib/sets/lists/comp/mi Tue Oct 9 09:58:08 2018
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.2138.2.6 2018/06/07 18:24:15 martin Exp $
+# $NetBSD: mi,v 1.2138.2.7 2018/10/09 09:58:08 martin Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
./etc/mtree/set.comp comp-sys-root
@@ -10567,6 +10567,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
@@ -18033,6 +18034,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
@@ -25645,6 +25647,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.414.2.1 src/share/man/man9/Makefile:1.414.2.2
--- src/share/man/man9/Makefile:1.414.2.1 Thu Jun 7 18:24:15 2018
+++ src/share/man/man9/Makefile Tue Oct 9 09:58:09 2018
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.414.2.1 2018/06/07 18:24:15 martin Exp $
+# $NetBSD: Makefile,v 1.414.2.2 2018/10/09 09:58:09 martin Exp $
# Makefile for section 9 (kernel function and variable) manual pages.
@@ -356,6 +356,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.24.2.1 src/share/man/man9/fstrans.9:1.24.2.2
--- src/share/man/man9/fstrans.9:1.24.2.1 Sun Jun 4 20:35:01 2017
+++ src/share/man/man9/fstrans.9 Tue Oct 9 09:58:09 2018
@@ -1,4 +1,4 @@
-.\" $NetBSD: fstrans.9,v 1.24.2.1 2017/06/04 20:35:01 bouyer Exp $
+.\" $NetBSD: fstrans.9,v 1.24.2.2 2018/10/09 09:58:09 martin 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.259.6.1 src/sys/dev/vnd.c:1.259.6.2
--- src/sys/dev/vnd.c:1.259.6.1 Tue Aug 8 16:12:56 2017
+++ src/sys/dev/vnd.c Tue Oct 9 09:58:09 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: vnd.c,v 1.259.6.1 2017/08/08 16:12:56 martin Exp $ */
+/* $NetBSD: vnd.c,v 1.259.6.2 2018/10/09 09:58:09 martin 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.259.6.1 2017/08/08 16:12:56 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vnd.c,v 1.259.6.2 2018/10/09 09:58:09 martin Exp $");
#if defined(_KERNEL_OPT)
#include "opt_vnd.h"
@@ -114,6 +114,7 @@ __KERNEL_RCSID(0, "$NetBSD: vnd.c,v 1.25
#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>
@@ -805,6 +806,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,
@@ -816,6 +820,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.45.2.2 src/sys/kern/vfs_trans.c:1.45.2.3
--- src/sys/kern/vfs_trans.c:1.45.2.2 Wed Jun 21 18:24:26 2017
+++ src/sys/kern/vfs_trans.c Tue Oct 9 09:58:08 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: vfs_trans.c,v 1.45.2.2 2017/06/21 18:24:26 snj Exp $ */
+/* $NetBSD: vfs_trans.c,v 1.45.2.3 2018/10/09 09:58:08 martin 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.45.2.2 2017/06/21 18:24:26 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_trans.c,v 1.45.2.3 2018/10/09 09:58:08 martin 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.7.2.1
--- src/sys/miscfs/genfs/genfs_vfsops.c:1.7 Wed May 24 09:53:55 2017
+++ src/sys/miscfs/genfs/genfs_vfsops.c Tue Oct 9 09:58:09 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.7.2.1 2018/10/09 09:58:09 martin 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.7.2.1 2018/10/09 09:58:09 martin 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.181.6.2 src/sys/rump/librump/rumpkern/emul.c:1.181.6.3
--- src/sys/rump/librump/rumpkern/emul.c:1.181.6.2 Thu Nov 30 14:40:46 2017
+++ src/sys/rump/librump/rumpkern/emul.c Tue Oct 9 09:58:09 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: emul.c,v 1.181.6.2 2017/11/30 14:40:46 martin Exp $ */
+/* $NetBSD: emul.c,v 1.181.6.3 2018/10/09 09:58:09 martin 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.181.6.2 2017/11/30 14:40:46 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: emul.c,v 1.181.6.3 2018/10/09 09:58:09 martin Exp $");
#include <sys/param.h>
#include <sys/cprng.h>
@@ -273,6 +273,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.10.60.1 src/sys/sys/fstrans.h:1.10.60.2
--- src/sys/sys/fstrans.h:1.10.60.1 Sun Jun 4 20:35:01 2017
+++ src/sys/sys/fstrans.h Tue Oct 9 09:58:09 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: fstrans.h,v 1.10.60.1 2017/06/04 20:35:01 bouyer Exp $ */
+/* $NetBSD: fstrans.h,v 1.10.60.2 2018/10/09 09:58:09 martin 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 *);