Module Name:    src
Committed By:   hannken
Date:           Wed Feb 20 10:07:27 UTC 2019

Modified Files:
        src/sys/kern: init_main.c vfs_mount.c vfs_trans.c vfs_vnode.c
        src/sys/miscfs/genfs: genfs_vfsops.c
        src/sys/rump/librump/rumpvfs: rump_vfs.c
        src/sys/sys: fstypes.h

Log Message:
Attach "mnt_transinfo" to "dead_rootmount" so every mount has a
valid "mnt_transinfo" and remove now unneeded flag IMNT_HAS_TRANS.

Run fstrans_start()/fstrans_done() on dead_rootmount if FSTRANS_DEAD_ENABLED.
Should become the default for DIAGNOSTIC in the future.


To generate a diff of this commit:
cvs rdiff -u -r1.502 -r1.503 src/sys/kern/init_main.c
cvs rdiff -u -r1.68 -r1.69 src/sys/kern/vfs_mount.c
cvs rdiff -u -r1.51 -r1.52 src/sys/kern/vfs_trans.c
cvs rdiff -u -r1.102 -r1.103 src/sys/kern/vfs_vnode.c
cvs rdiff -u -r1.8 -r1.9 src/sys/miscfs/genfs/genfs_vfsops.c
cvs rdiff -u -r1.87 -r1.88 src/sys/rump/librump/rumpvfs/rump_vfs.c
cvs rdiff -u -r1.36 -r1.37 src/sys/sys/fstypes.h

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/init_main.c
diff -u src/sys/kern/init_main.c:1.502 src/sys/kern/init_main.c:1.503
--- src/sys/kern/init_main.c:1.502	Wed Jan 23 13:38:30 2019
+++ src/sys/kern/init_main.c	Wed Feb 20 10:07:27 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: init_main.c,v 1.502 2019/01/23 13:38:30 kamil Exp $	*/
+/*	$NetBSD: init_main.c,v 1.503 2019/02/20 10:07:27 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.502 2019/01/23 13:38:30 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.503 2019/02/20 10:07:27 hannken Exp $");
 
 #include "opt_ddb.h"
 #include "opt_inet.h"
@@ -466,12 +466,13 @@ main(void)
 	if (usevnodes > desiredvnodes)
 		desiredvnodes = usevnodes;
 #endif
-	vfsinit();
-	lf_init();
 
 	/* Initialize fstrans. */
 	fstrans_init();
 
+	vfsinit();
+	lf_init();
+
 	/* Initialize the file descriptor system. */
 	fd_sys_init();
 

Index: src/sys/kern/vfs_mount.c
diff -u src/sys/kern/vfs_mount.c:1.68 src/sys/kern/vfs_mount.c:1.69
--- src/sys/kern/vfs_mount.c:1.68	Tue Feb  5 09:49:44 2019
+++ src/sys/kern/vfs_mount.c	Wed Feb 20 10:07:27 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_mount.c,v 1.68 2019/02/05 09:49:44 hannken Exp $	*/
+/*	$NetBSD: vfs_mount.c,v 1.69 2019/02/20 10:07:27 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.68 2019/02/05 09:49:44 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.69 2019/02/20 10:07:27 hannken Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -149,7 +149,6 @@ vfs_mountalloc(struct vfsops *vfsops, vn
 {
 	struct mount *mp;
 	int error __diagused;
-	extern struct vfsops dead_vfsops;
 
 	mp = kmem_zalloc(sizeof(*mp), KM_SLEEP);
 	mp->mnt_op = vfsops;
@@ -159,10 +158,9 @@ vfs_mountalloc(struct vfsops *vfsops, vn
 	mutex_init(&mp->mnt_updating, MUTEX_DEFAULT, IPL_NONE);
 	mp->mnt_vnodecovered = vp;
 	mount_initspecific(mp);
-	if (vfsops != &dead_vfsops) {
-		error = fstrans_mount(mp);
-		KASSERT(error == 0);
-	}
+
+	error = fstrans_mount(mp);
+	KASSERT(error == 0);
 
 	mutex_enter(&mountgen_lock);
 	mp->mnt_gen = mountgen++;

Index: src/sys/kern/vfs_trans.c
diff -u src/sys/kern/vfs_trans.c:1.51 src/sys/kern/vfs_trans.c:1.52
--- src/sys/kern/vfs_trans.c:1.51	Fri Oct  5 09:51:55 2018
+++ src/sys/kern/vfs_trans.c	Wed Feb 20 10:07:27 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_trans.c,v 1.51 2018/10/05 09:51:55 hannken Exp $	*/
+/*	$NetBSD: vfs_trans.c,v 1.52 2019/02/20 10:07:27 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.51 2018/10/05 09:51:55 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_trans.c,v 1.52 2019/02/20 10:07:27 hannken Exp $");
 
 /*
  * File system transaction operations.
@@ -104,6 +104,8 @@ static bool cow_state_change_done(const 
 static void cow_change_enter(const struct mount *);
 static void cow_change_done(const struct mount *);
 
+extern struct mount *dead_rootmount;
+
 /*
  * Initialize.
  */
@@ -136,8 +138,6 @@ fstrans_normalize_mount(struct mount *mp
 		mp = mp->mnt_lower;
 	if (mp == NULL)
 		return NULL;
-	if ((mp->mnt_iflag & IMNT_HAS_TRANS) == 0)
-		return NULL;
 	return mp;
 }
 
@@ -182,7 +182,6 @@ fstrans_mount_dtor(struct mount *mp)
 	KASSERT(fmi->fmi_state == FSTRANS_NORMAL);
 	KASSERT(LIST_FIRST(&fmi->fmi_cow_handler) == NULL);
 
-	mp->mnt_iflag &= ~IMNT_HAS_TRANS;
 	mp->mnt_transinfo = NULL;
 
 	mutex_exit(&fstrans_mount_lock);
@@ -207,7 +206,6 @@ fstrans_mount(struct mount *mp)
 
 	mutex_enter(&fstrans_mount_lock);
 	mp->mnt_transinfo = newfmi;
-	mp->mnt_iflag |= IMNT_HAS_TRANS;
 	mutex_exit(&fstrans_mount_lock);
 
 	vfs_ref(mp);
@@ -222,9 +220,6 @@ void
 fstrans_unmount(struct mount *mp)
 {
 
-	if ((mp->mnt_iflag & IMNT_HAS_TRANS) == 0)
-		return;
-
 	KASSERT(mp->mnt_transinfo != NULL);
 
 	fstrans_mount_dtor(mp);
@@ -361,6 +356,11 @@ _fstrans_start(struct mount *mp, enum fs
 	struct fstrans_lwp_info *fli;
 	struct fstrans_mount_info *fmi;
 
+#ifndef FSTRANS_DEAD_ENABLED
+	if (mp == dead_rootmount)
+		return 0;
+#endif
+
 	if ((lmp = fstrans_normalize_mount(mp)) == NULL)
 		return 0;
 
@@ -444,6 +444,11 @@ fstrans_done(struct mount *mp)
 	struct fstrans_lwp_info *fli;
 	struct fstrans_mount_info *fmi;
 
+#ifndef FSTRANS_DEAD_ENABLED
+	if (mp == dead_rootmount)
+		return;
+#endif
+
 	if ((mp = fstrans_normalize_mount(mp)) == NULL)
 		return;
 	if ((fli = fstrans_get_lwp_info(mp, false)) == NULL)
@@ -482,6 +487,8 @@ fstrans_is_owner(struct mount *mp)
 {
 	struct fstrans_lwp_info *fli;
 
+	KASSERT(mp != dead_rootmount);
+
 	if ((mp = fstrans_normalize_mount(mp)) == NULL)
 		return 0;
 	if ((fli = fstrans_get_lwp_info(mp, false)) == NULL)
@@ -532,6 +539,8 @@ fstrans_setstate(struct mount *mp, enum 
 	enum fstrans_state old_state;
 	struct fstrans_mount_info *fmi;
 
+	KASSERT(mp != dead_rootmount);
+
 	fmi = mp->mnt_transinfo;
 	old_state = fmi->fmi_state;
 	if (old_state == new_state)
@@ -574,6 +583,8 @@ fstrans_getstate(struct mount *mp)
 {
 	struct fstrans_mount_info *fmi;
 
+	KASSERT(mp != dead_rootmount);
+
 	fmi = mp->mnt_transinfo;
 	KASSERT(fmi != NULL);
 
@@ -588,6 +599,8 @@ vfs_suspend(struct mount *mp, int nowait
 {
 	int error;
 
+	KASSERT(mp != dead_rootmount);
+
 	if ((mp = fstrans_normalize_mount(mp)) == NULL)
 		return EOPNOTSUPP;
 	if (nowait) {
@@ -609,6 +622,8 @@ void
 vfs_resume(struct mount *mp)
 {
 
+	KASSERT(mp != dead_rootmount);
+
 	mp = fstrans_normalize_mount(mp);
 	KASSERT(mp != NULL);
 		
@@ -702,8 +717,7 @@ fscow_establish(struct mount *mp, int (*
 	struct fstrans_mount_info *fmi;
 	struct fscow_handler *newch;
 
-	if ((mp->mnt_iflag & IMNT_HAS_TRANS) == 0)
-		return EINVAL;
+	KASSERT(mp != dead_rootmount);
 
 	fmi = mp->mnt_transinfo;
 	KASSERT(fmi != NULL);
@@ -729,8 +743,7 @@ fscow_disestablish(struct mount *mp, int
 	struct fstrans_mount_info *fmi;
 	struct fscow_handler *hp = NULL;
 
-	if ((mp->mnt_iflag & IMNT_HAS_TRANS) == 0)
-		return EINVAL;
+	KASSERT(mp != dead_rootmount);
 
 	fmi = mp->mnt_transinfo;
 	KASSERT(fmi != NULL);
@@ -773,7 +786,7 @@ fscow_run(struct buf *bp, bool data_vali
 		mp = spec_node_getmountedfs(bp->b_vp);
 	else
 		mp = bp->b_vp->v_mount;
-	if (mp == NULL || (mp->mnt_iflag & IMNT_HAS_TRANS) == 0) {
+	if (mp == NULL || mp == dead_rootmount) {
 		bp->b_flags |= B_COWDONE;
 		return 0;
 	}

Index: src/sys/kern/vfs_vnode.c
diff -u src/sys/kern/vfs_vnode.c:1.102 src/sys/kern/vfs_vnode.c:1.103
--- src/sys/kern/vfs_vnode.c:1.102	Wed Feb 20 10:06:33 2019
+++ src/sys/kern/vfs_vnode.c	Wed Feb 20 10:07:27 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_vnode.c,v 1.102 2019/02/20 10:06:33 hannken Exp $	*/
+/*	$NetBSD: vfs_vnode.c,v 1.103 2019/02/20 10:07:27 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1997-2011 The NetBSD Foundation, Inc.
@@ -156,7 +156,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.102 2019/02/20 10:06:33 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.103 2019/02/20 10:07:27 hannken Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -382,7 +382,7 @@ vfs_vnode_sysinit(void)
 
 	dead_rootmount = vfs_mountalloc(&dead_vfsops, NULL);
 	KASSERT(dead_rootmount != NULL);
-	dead_rootmount->mnt_iflag = IMNT_MPSAFE;
+	dead_rootmount->mnt_iflag |= IMNT_MPSAFE;
 
 	mutex_init(&vdrain_lock, MUTEX_DEFAULT, IPL_NONE);
 	TAILQ_INIT(&lru_free_list);
@@ -1030,8 +1030,7 @@ void
 vgone(vnode_t *vp)
 {
 
-	KASSERT((vp->v_mount->mnt_iflag & IMNT_HAS_TRANS) == 0 ||
-	    fstrans_is_owner(vp->v_mount));
+	KASSERT(vp->v_mount == dead_rootmount || fstrans_is_owner(vp->v_mount));
 
 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
 	mutex_enter(vp->v_interlock);
@@ -1684,8 +1683,7 @@ vcache_make_anon(vnode_t *vp)
 	bool recycle;
 
 	KASSERT(vp->v_type == VBLK || vp->v_type == VCHR);
-	KASSERT((vp->v_mount->mnt_iflag & IMNT_HAS_TRANS) == 0 ||
-	    fstrans_is_owner(vp->v_mount));
+	KASSERT(vp->v_mount == dead_rootmount || fstrans_is_owner(vp->v_mount));
 	VSTATE_ASSERT_UNLOCKED(vp, VS_ACTIVE);
 
 	/* Remove from vnode cache. */

Index: src/sys/miscfs/genfs/genfs_vfsops.c
diff -u src/sys/miscfs/genfs/genfs_vfsops.c:1.8 src/sys/miscfs/genfs/genfs_vfsops.c:1.9
--- src/sys/miscfs/genfs/genfs_vfsops.c:1.8	Fri Oct  5 09:51:55 2018
+++ src/sys/miscfs/genfs/genfs_vfsops.c	Wed Feb 20 10:07:27 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: genfs_vfsops.c,v 1.8 2018/10/05 09:51:55 hannken Exp $	*/
+/*	$NetBSD: genfs_vfsops.c,v 1.9 2019/02/20 10:07:27 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.8 2018/10/05 09:51:55 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: genfs_vfsops.c,v 1.9 2019/02/20 10:07:27 hannken Exp $");
 
 #include <sys/types.h>
 #include <sys/mount.h>
@@ -78,9 +78,6 @@ genfs_suspendctl(struct mount *mp, int c
 	int error;
 	int error2 __diagused;
 
-	if ((mp->mnt_iflag & IMNT_HAS_TRANS) == 0)
-		return EOPNOTSUPP;
-
 	switch (cmd) {
 	case SUSPEND_SUSPEND:
 		error = fstrans_setstate(mp, FSTRANS_SUSPENDING);

Index: src/sys/rump/librump/rumpvfs/rump_vfs.c
diff -u src/sys/rump/librump/rumpvfs/rump_vfs.c:1.87 src/sys/rump/librump/rumpvfs/rump_vfs.c:1.88
--- src/sys/rump/librump/rumpvfs/rump_vfs.c:1.87	Sat Apr  1 19:35:57 2017
+++ src/sys/rump/librump/rumpvfs/rump_vfs.c	Wed Feb 20 10:07:27 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: rump_vfs.c,v 1.87 2017/04/01 19:35:57 riastradh Exp $	*/
+/*	$NetBSD: rump_vfs.c,v 1.88 2019/02/20 10:07:27 hannken Exp $	*/
 
 /*
  * Copyright (c) 2008 Antti Kantee.  All Rights Reserved.
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rump_vfs.c,v 1.87 2017/04/01 19:35:57 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rump_vfs.c,v 1.88 2019/02/20 10:07:27 hannken Exp $");
 
 #include <sys/param.h>
 #include <sys/buf.h>
@@ -122,12 +122,12 @@ RUMP_COMPONENT(RUMP__FACTION_VFS)
 	}
 
 	bufq_init();
+	fstrans_init();
 	vfsinit();
 	bufinit();
 	cwd_sys_init();
 	lf_init();
 	spec_init();
-	fstrans_init();
 
 	root_device = &rump_rootdev;
 

Index: src/sys/sys/fstypes.h
diff -u src/sys/sys/fstypes.h:1.36 src/sys/sys/fstypes.h:1.37
--- src/sys/sys/fstypes.h:1.36	Tue Jan  9 03:31:13 2018
+++ src/sys/sys/fstypes.h	Wed Feb 20 10:07:27 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: fstypes.h,v 1.36 2018/01/09 03:31:13 christos Exp $	*/
+/*	$NetBSD: fstypes.h,v 1.37 2019/02/20 10:07:27 hannken Exp $	*/
 
 /*
  * Copyright (c) 1989, 1991, 1993
@@ -221,7 +221,6 @@ typedef struct fhandle	fhandle_t;
 #define	IMNT_WANTRDWR	0x00000004	/* upgrade to read/write requested */
 #define	IMNT_WANTRDONLY	0x00000008	/* upgrade to readonly requested */
 #define	IMNT_DTYPE	0x00000040	/* returns d_type fields */
-#define	IMNT_HAS_TRANS	0x00000080	/* supports transactions */
 #define	IMNT_MPSAFE	0x00000100	/* file system code MP safe */
 #define	IMNT_CAN_RWTORO	0x00000200	/* can downgrade fs to from rw to r/o */
 #define	IMNT_ONWORKLIST	0x00000400	/* on syncer worklist */
@@ -272,7 +271,6 @@ typedef struct fhandle	fhandle_t;
 	"\13IMNT_ONWORKLIST" \
 	"\12IMNT_CAN_RWTORO" \
 	"\11IMNT_MPSAFE" \
-	"\10IMNT_HAS_TRANS" \
 	"\07IMNT_DTYPE" \
 	"\04IMNT_WANTRDONLY" \
 	"\03IMNT_WANTRDWR" \

Reply via email to