Module Name:    src
Committed By:   snj
Date:           Mon Oct 30 09:29:04 UTC 2017

Modified Files:
        src/sbin/fsck_lfs [netbsd-8]: inode.c lfs.c pass6.c segwrite.c
        src/sys/ufs/lfs [netbsd-8]: lfs.h lfs_accessors.h lfs_alloc.c
            lfs_balloc.c lfs_bio.c lfs_extern.h lfs_inode.c lfs_inode.h
            lfs_itimes.c lfs_pages.c lfs_rename.c lfs_segment.c lfs_subr.c
            lfs_syscalls.c lfs_vfsops.c lfs_vnops.c ulfs_inode.c ulfs_inode.h
            ulfs_lookup.c ulfs_quota2.c ulfs_readwrite.c ulfs_vnops.c

Log Message:
Pull up following revision(s) (requested by maya in ticket #330):
        sbin/fsck_lfs/inode.c: 1.69
        sbin/fsck_lfs/lfs.c: 1.73
        sbin/fsck_lfs/pass6.c: 1.50
        sbin/fsck_lfs/segwrite.c: 1.46
        sys/ufs/lfs/lfs.h: 1.202-1.203
        sys/ufs/lfs/lfs_accessors.h: 1.48
        sys/ufs/lfs/lfs_alloc.c: 1.136-1.137
        sys/ufs/lfs/lfs_balloc.c: 1.94
        sys/ufs/lfs/lfs_bio.c: 1.141
        sys/ufs/lfs/lfs_extern.h: 1.113
        sys/ufs/lfs/lfs_inode.c: 1.156-1.157
        sys/ufs/lfs/lfs_inode.h: 1.20, 1.21, 1.23
        sys/ufs/lfs/lfs_itimes.c: 1.20
        sys/ufs/lfs/lfs_pages.c: 1.13-1.15
        sys/ufs/lfs/lfs_rename.c: 1.22
        sys/ufs/lfs/lfs_segment.c: 1.270-1.275
        sys/ufs/lfs/lfs_subr.c: 1.94-1.97
        sys/ufs/lfs/lfs_syscalls.c: 1.175
        sys/ufs/lfs/lfs_vfsops.c: 1.360
        sys/ufs/lfs/lfs_vnops.c: 1.316-1.321
        sys/ufs/lfs/ulfs_inode.c: 1.20
        sys/ufs/lfs/ulfs_inode.h: 1.24
        sys/ufs/lfs/ulfs_lookup.c: 1.41
        sys/ufs/lfs/ulfs_quota2.c: 1.31
        sys/ufs/lfs/ulfs_readwrite.c: 1.24
        sys/ufs/lfs/ulfs_vnops.c: 1.49-1.50
Update inode member i_flag --> i_state to keep up with kernel changes
Move definition of IN_ALLMOD near the flag it's a mask for.
Now we can see that it doesn't match all the flags, but changing that will
require more careful thought.
Correct confusion between i_flag and i_flags
These will have to be renamed.
Spotted by Riastradh, thanks!
Add an XXX about the missing flags so it's not buried in a commit
message.
now the XXX count for LFS is 260
Rename i_flag to i_state.
The similarity to i_flags has previously caused errors.
Use continue to denote the no-op loop to match netbsd style
newline for extra clarity.
It isn't safe to drain dirops with seglock held, it'll deadlock if there
are any dirops. drain before grabbing seglock.
lfs_dirops == 0 is always true (as we already drained dirops), so omit
that part of the comparison.
Fixes a lot of LFS deadlocks. PR kern/52301
Many thanks to dholland for help analyzing coredumps
Ifdef out KDASSERT which fires on my machine.
Deduplicate sanity check that seglock is held on segunlock
Revert r1.272 fix to PR kern/52301, the performance hit is making things
unusable.
change lfs_nextsegsleep and lfs_allclean_wakeup to use condvar
XXX had to use lfs_lock in lfs_segwait, removed kernel_lock, is this
appropriate?
fix buffer overflow/KASSERT when cookies are supplied
lfs no longer uses the ffs-style struct direct, use the correct minimum
size
from dholland
XXX more wrong
Consistently use {,UN}MARK_VNODE macros rather than function calls.
Not much point doing anything after a panic call
Ask some question about the code in a XXX comment
XXX question our double-flushing of dirops
Fix typo in comment


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.68.8.1 src/sbin/fsck_lfs/inode.c
cvs rdiff -u -r1.72 -r1.72.6.1 src/sbin/fsck_lfs/lfs.c
cvs rdiff -u -r1.49 -r1.49.8.1 src/sbin/fsck_lfs/pass6.c
cvs rdiff -u -r1.45 -r1.45.8.1 src/sbin/fsck_lfs/segwrite.c
cvs rdiff -u -r1.201 -r1.201.6.1 src/sys/ufs/lfs/lfs.h
cvs rdiff -u -r1.47 -r1.47.8.1 src/sys/ufs/lfs/lfs_accessors.h
cvs rdiff -u -r1.135 -r1.135.6.1 src/sys/ufs/lfs/lfs_alloc.c
cvs rdiff -u -r1.92 -r1.92.6.1 src/sys/ufs/lfs/lfs_balloc.c \
    src/sys/ufs/lfs/lfs_subr.c
cvs rdiff -u -r1.139 -r1.139.4.1 src/sys/ufs/lfs/lfs_bio.c
cvs rdiff -u -r1.111 -r1.111.10.1 src/sys/ufs/lfs/lfs_extern.h
cvs rdiff -u -r1.155 -r1.155.6.1 src/sys/ufs/lfs/lfs_inode.c
cvs rdiff -u -r1.19 -r1.19.6.1 src/sys/ufs/lfs/lfs_inode.h
cvs rdiff -u -r1.19 -r1.19.10.1 src/sys/ufs/lfs/lfs_itimes.c
cvs rdiff -u -r1.11.6.1 -r1.11.6.2 src/sys/ufs/lfs/lfs_pages.c
cvs rdiff -u -r1.21 -r1.21.10.1 src/sys/ufs/lfs/lfs_rename.c
cvs rdiff -u -r1.269 -r1.269.6.1 src/sys/ufs/lfs/lfs_segment.c
cvs rdiff -u -r1.174 -r1.174.4.1 src/sys/ufs/lfs/lfs_syscalls.c
cvs rdiff -u -r1.359 -r1.359.4.1 src/sys/ufs/lfs/lfs_vfsops.c
cvs rdiff -u -r1.315 -r1.315.2.1 src/sys/ufs/lfs/lfs_vnops.c
cvs rdiff -u -r1.19 -r1.19.2.1 src/sys/ufs/lfs/ulfs_inode.c
cvs rdiff -u -r1.22 -r1.22.10.1 src/sys/ufs/lfs/ulfs_inode.h
cvs rdiff -u -r1.40 -r1.40.6.1 src/sys/ufs/lfs/ulfs_lookup.c
cvs rdiff -u -r1.30 -r1.30.6.1 src/sys/ufs/lfs/ulfs_quota2.c
cvs rdiff -u -r1.23 -r1.23.6.1 src/sys/ufs/lfs/ulfs_readwrite.c
cvs rdiff -u -r1.48 -r1.48.4.1 src/sys/ufs/lfs/ulfs_vnops.c

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

Modified files:

Index: src/sbin/fsck_lfs/inode.c
diff -u src/sbin/fsck_lfs/inode.c:1.68 src/sbin/fsck_lfs/inode.c:1.68.8.1
--- src/sbin/fsck_lfs/inode.c:1.68	Mon Sep 21 01:24:23 2015
+++ src/sbin/fsck_lfs/inode.c	Mon Oct 30 09:29:04 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: inode.c,v 1.68 2015/09/21 01:24:23 dholland Exp $	 */
+/* $NetBSD: inode.c,v 1.68.8.1 2017/10/30 09:29:04 snj Exp $	 */
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -436,7 +436,7 @@ inocleanup(void)
 void
 inodirty(struct inode *ip)
 {
-	ip->i_flag |= IN_MODIFIED;
+	ip->i_state |= IN_MODIFIED;
 }
 
 void

Index: src/sbin/fsck_lfs/lfs.c
diff -u src/sbin/fsck_lfs/lfs.c:1.72 src/sbin/fsck_lfs/lfs.c:1.72.6.1
--- src/sbin/fsck_lfs/lfs.c:1.72	Fri Sep 16 11:13:47 2016
+++ src/sbin/fsck_lfs/lfs.c	Mon Oct 30 09:29:04 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: lfs.c,v 1.72 2016/09/16 11:13:47 christos Exp $ */
+/* $NetBSD: lfs.c,v 1.72.6.1 2017/10/30 09:29:04 snj Exp $ */
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -366,7 +366,7 @@ lfs_raw_vget(struct lfs * fs, ino_t ino,
 	ip->i_number = ino;
 	ip->i_lockf = 0;
 	ip->i_lfs_effnblks = 0;
-	ip->i_flag = 0;
+	ip->i_state = 0;
 
 	/* Load inode block and find inode */
 	if (daddr > 0) {
@@ -952,7 +952,7 @@ extend_ifile(struct lfs *fs)
 	lfs_balloc(vp, lfs_dino_getsize(fs, ip->i_din), lfs_sb_getbsize(fs), &bp);
 	lfs_dino_setsize(fs, ip->i_din,
 	    lfs_dino_getsize(fs, ip->i_din) + lfs_sb_getbsize(fs));
-	ip->i_flag |= IN_MODIFIED;
+	ip->i_state |= IN_MODIFIED;
 	
 	i = (blkno - lfs_sb_getsegtabsz(fs) - lfs_sb_getcleansz(fs)) *
 		lfs_sb_getifpb(fs);
@@ -1058,7 +1058,7 @@ lfs_balloc(struct uvnode *vp, off_t star
 						    (bpp ? &bp : NULL))))
 				return (error);
 			lfs_dino_setsize(fs, ip->i_din, (lastblock + 1) * lfs_sb_getbsize(fs));
-			ip->i_flag |= IN_CHANGE | IN_UPDATE;
+			ip->i_state |= IN_CHANGE | IN_UPDATE;
 			if (bpp)
 				(void) VOP_BWRITE(bp);
 		}
@@ -1252,7 +1252,7 @@ lfs_fragextend(struct uvnode *vp, int os
 
 	lfs_sb_subbfree(fs, frags);
 	ip->i_lfs_effnblks += frags;
-	ip->i_flag |= IN_CHANGE | IN_UPDATE;
+	ip->i_state |= IN_CHANGE | IN_UPDATE;
 
 	if (bpp) {
 		(*bpp)->b_data = erealloc((*bpp)->b_data, nsize);

Index: src/sbin/fsck_lfs/pass6.c
diff -u src/sbin/fsck_lfs/pass6.c:1.49 src/sbin/fsck_lfs/pass6.c:1.49.8.1
--- src/sbin/fsck_lfs/pass6.c:1.49	Sat Oct  3 08:29:21 2015
+++ src/sbin/fsck_lfs/pass6.c	Mon Oct 30 09:29:04 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: pass6.c,v 1.49 2015/10/03 08:29:21 dholland Exp $	 */
+/* $NetBSD: pass6.c,v 1.49.8.1 2017/10/30 09:29:04 snj Exp $	 */
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -88,7 +88,7 @@ rfw_update_single(struct uvnode *vp, dad
 	u_int32_t oldsn, sn;
 
 	ip = VTOI(vp);
-	ip->i_flag |= IN_MODIFIED;
+	ip->i_state |= IN_MODIFIED;
 
 	error = ulfs_bmaparray(fs, vp, lbn, &daddr, a, &num);
 	if (error)

Index: src/sbin/fsck_lfs/segwrite.c
diff -u src/sbin/fsck_lfs/segwrite.c:1.45 src/sbin/fsck_lfs/segwrite.c:1.45.8.1
--- src/sbin/fsck_lfs/segwrite.c:1.45	Sat Oct  3 08:28:15 2015
+++ src/sbin/fsck_lfs/segwrite.c	Mon Oct 30 09:29:04 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: segwrite.c,v 1.45 2015/10/03 08:28:15 dholland Exp $ */
+/* $NetBSD: segwrite.c,v 1.45.8.1 2017/10/30 09:29:04 snj Exp $ */
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -1027,7 +1027,7 @@ lfs_writevnodes(struct lfs *fs, struct s
 		/*
 		 * Write the inode/file if dirty and it's not the IFILE.
 		 */
-		if (ip->i_flag & IN_ALLMOD || !LIST_EMPTY(&vp->v_dirtyblkhd)) {
+		if (ip->i_state & IN_ALLMOD || !LIST_EMPTY(&vp->v_dirtyblkhd)) {
 			if (ip->i_number != LFS_IFILE_INUM)
 				lfs_writefile(fs, sp, vp);
 			(void) lfs_writeinode(fs, sp, ip);

Index: src/sys/ufs/lfs/lfs.h
diff -u src/sys/ufs/lfs/lfs.h:1.201 src/sys/ufs/lfs/lfs.h:1.201.6.1
--- src/sys/ufs/lfs/lfs.h:1.201	Sat Apr  1 14:43:00 2017
+++ src/sys/ufs/lfs/lfs.h	Mon Oct 30 09:29:04 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs.h,v 1.201 2017/04/01 14:43:00 maya Exp $	*/
+/*	$NetBSD: lfs.h,v 1.201.6.1 2017/10/30 09:29:04 snj Exp $	*/
 
 /*  from NetBSD: dinode.h,v 1.25 2016/01/22 23:06:10 dholland Exp  */
 /*  from NetBSD: dir.h,v 1.25 2015/09/01 06:16:03 dholland Exp  */
@@ -511,13 +511,6 @@ union lfs_dinode {
 #define LFS_UNUSED_LBN	-1
 
 /*
- * "struct inode" associated definitions
- */
-
-/* For convenience */
-#define IN_ALLMOD (IN_MODIFIED|IN_ACCESS|IN_CHANGE|IN_UPDATE|IN_MODIFY|IN_ACCESSED|IN_CLEANING)
-
-/*
  * On-disk and in-memory checkpoint segment usage structure.
  */
 typedef struct segusage SEGUSE;
@@ -1054,7 +1047,7 @@ struct lfs {
 	/* XXX: should be replaced with a condvar */
 	int lfs_availsleep;
 	/* This one replaces &lfs_nextseg... all ditto */
-	int lfs_nextsegsleep;
+	kcondvar_t lfs_nextsegsleep;
 
 	/* Cleaner lwp, set on first bmapv syscall. */
 	struct lwp *lfs_cleaner_thread;

Index: src/sys/ufs/lfs/lfs_accessors.h
diff -u src/sys/ufs/lfs/lfs_accessors.h:1.47 src/sys/ufs/lfs/lfs_accessors.h:1.47.8.1
--- src/sys/ufs/lfs/lfs_accessors.h:1.47	Thu Jan 12 18:40:02 2017
+++ src/sys/ufs/lfs/lfs_accessors.h	Mon Oct 30 09:29:04 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_accessors.h,v 1.47 2017/01/12 18:40:02 christos Exp $	*/
+/*	$NetBSD: lfs_accessors.h,v 1.47.8.1 2017/10/30 09:29:04 snj Exp $	*/
 
 /*  from NetBSD: lfs.h,v 1.165 2015/07/24 06:59:32 dholland Exp  */
 /*  from NetBSD: dinode.h,v 1.25 2016/01/22 23:06:10 dholland Exp  */
@@ -619,31 +619,31 @@ lfs_iblock_set(STRUCT_LFS *fs, void *blo
  * "struct inode" associated definitions
  */
 
-#define LFS_SET_UINO(ip, flags) do {					\
-	if (((flags) & IN_ACCESSED) && !((ip)->i_flag & IN_ACCESSED))	\
+#define LFS_SET_UINO(ip, states) do {					\
+	if (((states) & IN_ACCESSED) && !((ip)->i_state & IN_ACCESSED))	\
 		lfs_sb_adduinodes((ip)->i_lfs, 1);			\
-	if (((flags) & IN_CLEANING) && !((ip)->i_flag & IN_CLEANING))	\
+	if (((states) & IN_CLEANING) && !((ip)->i_state & IN_CLEANING))	\
 		lfs_sb_adduinodes((ip)->i_lfs, 1);			\
-	if (((flags) & IN_MODIFIED) && !((ip)->i_flag & IN_MODIFIED))	\
+	if (((states) & IN_MODIFIED) && !((ip)->i_state & IN_MODIFIED))	\
 		lfs_sb_adduinodes((ip)->i_lfs, 1);			\
-	(ip)->i_flag |= (flags);					\
+	(ip)->i_state |= (states);					\
 } while (0)
 
-#define LFS_CLR_UINO(ip, flags) do {					\
-	if (((flags) & IN_ACCESSED) && ((ip)->i_flag & IN_ACCESSED))	\
+#define LFS_CLR_UINO(ip, states) do {					\
+	if (((states) & IN_ACCESSED) && ((ip)->i_state & IN_ACCESSED))	\
 		lfs_sb_subuinodes((ip)->i_lfs, 1);			\
-	if (((flags) & IN_CLEANING) && ((ip)->i_flag & IN_CLEANING))	\
+	if (((states) & IN_CLEANING) && ((ip)->i_state & IN_CLEANING))	\
 		lfs_sb_subuinodes((ip)->i_lfs, 1);			\
-	if (((flags) & IN_MODIFIED) && ((ip)->i_flag & IN_MODIFIED))	\
+	if (((states) & IN_MODIFIED) && ((ip)->i_state & IN_MODIFIED))	\
 		lfs_sb_subuinodes((ip)->i_lfs, 1);			\
-	(ip)->i_flag &= ~(flags);					\
+	(ip)->i_state &= ~(states);					\
 	if (lfs_sb_getuinodes((ip)->i_lfs) < 0) {			\
 		panic("lfs_uinodes < 0");				\
 	}								\
 } while (0)
 
 #define LFS_ITIMES(ip, acc, mod, cre) \
-	while ((ip)->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE | IN_MODIFY)) \
+	while ((ip)->i_state & (IN_ACCESS | IN_CHANGE | IN_UPDATE | IN_MODIFY)) \
 		lfs_itimes(ip, acc, mod, cre)
 
 /*
@@ -672,7 +672,7 @@ lfs_iblock_set(STRUCT_LFS *fs, void *blo
 #define	LFS_SEGENTRY(SP, F, IN, BP) do {				\
 	int _e;								\
 	SHARE_IFLOCK(F);						\
-	VTOI((F)->lfs_ivnode)->i_flag |= IN_ACCESS;			\
+	VTOI((F)->lfs_ivnode)->i_state |= IN_ACCESS;			\
 	if ((_e = bread((F)->lfs_ivnode,				\
 	    ((IN) / lfs_sb_getsepb(F)) + lfs_sb_getcleansz(F),		\
 	    lfs_sb_getbsize(F), 0, &(BP))) != 0)			\
@@ -825,7 +825,7 @@ lfs_ii_setblock(STRUCT_LFS *fs, IINFO *i
 #define	LFS_IENTRY(IP, F, IN, BP) do {					\
 	int _e;								\
 	SHARE_IFLOCK(F);						\
-	VTOI((F)->lfs_ivnode)->i_flag |= IN_ACCESS;			\
+	VTOI((F)->lfs_ivnode)->i_state |= IN_ACCESS;			\
 	if ((_e = bread((F)->lfs_ivnode,				\
 	(IN) / lfs_sb_getifpb(F) + lfs_sb_getcleansz(F) + lfs_sb_getsegtabsz(F), \
 	lfs_sb_getbsize(F), 0, &(BP))) != 0)				\
@@ -941,7 +941,7 @@ lfs_ci_shiftdirtytoclean(STRUCT_LFS *fs,
 #define LFS_CLEANERINFO(CP, F, BP) do {					\
 	int _e;								\
 	SHARE_IFLOCK(F);						\
-	VTOI((F)->lfs_ivnode)->i_flag |= IN_ACCESS;			\
+	VTOI((F)->lfs_ivnode)->i_state |= IN_ACCESS;			\
 	_e = bread((F)->lfs_ivnode,					\
 	    (daddr_t)0, lfs_sb_getbsize(F), 0, &(BP));			\
 	if (_e)								\

Index: src/sys/ufs/lfs/lfs_alloc.c
diff -u src/sys/ufs/lfs/lfs_alloc.c:1.135 src/sys/ufs/lfs/lfs_alloc.c:1.135.6.1
--- src/sys/ufs/lfs/lfs_alloc.c:1.135	Mon Mar 13 20:15:50 2017
+++ src/sys/ufs/lfs/lfs_alloc.c	Mon Oct 30 09:29:04 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_alloc.c,v 1.135 2017/03/13 20:15:50 maya Exp $	*/
+/*	$NetBSD: lfs_alloc.c,v 1.135.6.1 2017/10/30 09:29:04 snj Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_alloc.c,v 1.135 2017/03/13 20:15:50 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_alloc.c,v 1.135.6.1 2017/10/30 09:29:04 snj Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_quota.h"
@@ -506,11 +506,11 @@ lfs_vfree(struct vnode *vp, ino_t ino, i
 	/*
 	 * If the inode was in a dirop, it isn't now.
 	 *
-	 * XXX: why are (v_uflag & VU_DIROP) and (ip->i_flag & IN_ADIROP)
+	 * XXX: why are (v_uflag & VU_DIROP) and (ip->i_state & IN_ADIROP)
 	 * not updated together in one function? (and why do both exist,
 	 * anyway?)
 	 */
-	lfs_unmark_vnode(vp);
+	UNMARK_VNODE(vp);
 
 	mutex_enter(&lfs_lock);
 	if (vp->v_uflag & VU_DIROP) {
@@ -551,7 +551,7 @@ lfs_vfree(struct vnode *vp, ino_t ino, i
 	mutex_exit(&lfs_lock);
 
 	/* Turn off all inode modification flags */
-	ip->i_flag &= ~IN_ALLMOD;
+	ip->i_state &= ~IN_ALLMOD;
 
 	/* Mark it deleted */
 	ip->i_lfs_iflags |= LFSI_DELETED;

Index: src/sys/ufs/lfs/lfs_balloc.c
diff -u src/sys/ufs/lfs/lfs_balloc.c:1.92 src/sys/ufs/lfs/lfs_balloc.c:1.92.6.1
--- src/sys/ufs/lfs/lfs_balloc.c:1.92	Thu Apr  6 02:38:08 2017
+++ src/sys/ufs/lfs/lfs_balloc.c	Mon Oct 30 09:29:04 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_balloc.c,v 1.92 2017/04/06 02:38:08 maya Exp $	*/
+/*	$NetBSD: lfs_balloc.c,v 1.92.6.1 2017/10/30 09:29:04 snj Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_balloc.c,v 1.92 2017/04/06 02:38:08 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_balloc.c,v 1.92.6.1 2017/10/30 09:29:04 snj Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_quota.h"
@@ -194,7 +194,7 @@ lfs_balloc(struct vnode *vp, off_t start
 			ip->i_size = (lastblock + 1) * lfs_sb_getbsize(fs);
 			lfs_dino_setsize(fs, ip->i_din, ip->i_size);
 			uvm_vnp_setsize(vp, ip->i_size);
-			ip->i_flag |= IN_CHANGE | IN_UPDATE;
+			ip->i_state |= IN_CHANGE | IN_UPDATE;
 			/* if we got a buffer for this, write it out now */
 			if (bpp)
 				(void) VOP_BWRITE(bp->b_vp, bp);
@@ -580,7 +580,7 @@ lfs_fragextend(struct vnode *vp, int osi
 	/* increase the file's effective block count */
 	ip->i_lfs_effnblks += frags;
 	/* mark the inode dirty */
-	ip->i_flag |= IN_CHANGE | IN_UPDATE;
+	ip->i_state |= IN_CHANGE | IN_UPDATE;
 
 	if (bpp) {
 		obufsize = (*bpp)->b_bufsize;
Index: src/sys/ufs/lfs/lfs_subr.c
diff -u src/sys/ufs/lfs/lfs_subr.c:1.92 src/sys/ufs/lfs/lfs_subr.c:1.92.6.1
--- src/sys/ufs/lfs/lfs_subr.c:1.92	Thu Apr  6 03:21:01 2017
+++ src/sys/ufs/lfs/lfs_subr.c	Mon Oct 30 09:29:04 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_subr.c,v 1.92 2017/04/06 03:21:01 maya Exp $	*/
+/*	$NetBSD: lfs_subr.c,v 1.92.6.1 2017/10/30 09:29:04 snj Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_subr.c,v 1.92 2017/04/06 03:21:01 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_subr.c,v 1.92.6.1 2017/10/30 09:29:04 snj Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -261,10 +261,12 @@ lfs_free(struct lfs *fs, void *p, int ty
 		}
 	}
 
+#ifdef notyet /* XXX this assert fires */
 	for (int i = 0; i < LFS_N_TOTAL; i++) {
 		KDASSERTMSG(fs->lfs_resblk[i].p == p,
 		    "lfs_free: inconsistent reserved block");
 	}
+#endif
 
 	mutex_exit(&lfs_lock);
 
@@ -355,7 +357,7 @@ lfs_unmark_dirop(struct lfs *fs)
 	for (ip = TAILQ_FIRST(&fs->lfs_dchainhd); ip != NULL; ip = nip) {
 		nip = TAILQ_NEXT(ip, i_lfs_dchain);
 		vp = ITOV(ip);
-		if ((ip->i_flag & (IN_ADIROP | IN_CDIROP)) == IN_CDIROP) {
+		if ((ip->i_state & (IN_ADIROP | IN_CDIROP)) == IN_CDIROP) {
 			--lfs_dirvcount;
 			--fs->lfs_dirvcount;
 			vp->v_uflag &= ~VU_DIROP;
@@ -366,7 +368,7 @@ lfs_unmark_dirop(struct lfs *fs)
 			vrele(vp);
 			mutex_enter(&lfs_lock);
 			fs->lfs_unlockvp = NULL;
-			ip->i_flag &= ~IN_CDIROP;
+			ip->i_state &= ~IN_CDIROP;
 		}
 	}
 
@@ -428,7 +430,10 @@ lfs_segunlock(struct lfs *fs)
 	sp = fs->lfs_sp;
 
 	mutex_enter(&lfs_lock);
-	KASSERT(LFS_SEGLOCK_HELD(fs));
+
+	if (!LFS_SEGLOCK_HELD(fs))
+		panic("lfs seglock not held");
+
 	if (fs->lfs_seglock == 1) {
 		if ((sp->seg_flags & (SEGM_PROT | SEGM_CLEAN)) == 0)
 			do_unmark_dirop = 1;
@@ -534,9 +539,6 @@ lfs_segunlock(struct lfs *fs)
 		rw_exit(&fs->lfs_fraglock);
 		if (do_unmark_dirop)
 			lfs_unmark_dirop(fs);
-	} else if (fs->lfs_seglock == 0) {
-		mutex_exit(&lfs_lock);
-		panic ("Seglock not held");
 	} else {
 		--fs->lfs_seglock;
 		mutex_exit(&lfs_lock);
@@ -649,6 +651,6 @@ lfs_wakeup_cleaner(struct lfs *fs)
 	if (fs->lfs_nowrap > 0)
 		return;
 
-	wakeup(&fs->lfs_nextsegsleep);
-	wakeup(&lfs_allclean_wakeup);
+	cv_broadcast(&fs->lfs_nextsegsleep);
+	cv_broadcast(&lfs_allclean_wakeup);
 }

Index: src/sys/ufs/lfs/lfs_bio.c
diff -u src/sys/ufs/lfs/lfs_bio.c:1.139 src/sys/ufs/lfs/lfs_bio.c:1.139.4.1
--- src/sys/ufs/lfs/lfs_bio.c:1.139	Mon Apr 17 08:32:01 2017
+++ src/sys/ufs/lfs/lfs_bio.c	Mon Oct 30 09:29:04 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_bio.c,v 1.139 2017/04/17 08:32:01 hannken Exp $	*/
+/*	$NetBSD: lfs_bio.c,v 1.139.4.1 2017/10/30 09:29:04 snj Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2008 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_bio.c,v 1.139 2017/04/17 08:32:01 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_bio.c,v 1.139.4.1 2017/10/30 09:29:04 snj Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -159,7 +159,7 @@ lfs_reservebuf(struct lfs *fs, struct vn
 	KASSERT(locked_queue_rcount >= 0);
 	KASSERT(locked_queue_rbytes >= 0);
 
-	cantwait = (VTOI(vp)->i_flag & IN_ADIROP) || fs->lfs_unlockvp == vp;
+	cantwait = (VTOI(vp)->i_state & IN_ADIROP) || fs->lfs_unlockvp == vp;
 	mutex_enter(&lfs_lock);
 	while (!cantwait && n > 0 && !lfs_fits_buf(fs, n, bytes)) {
 		int error;
@@ -214,7 +214,7 @@ lfs_reserveavail(struct lfs *fs, struct 
 	ASSERT_MAYBE_SEGLOCK(fs);
 	slept = 0;
 	mutex_enter(&lfs_lock);
-	cantwait = (VTOI(vp)->i_flag & IN_ADIROP) || fs->lfs_unlockvp == vp;
+	cantwait = (VTOI(vp)->i_state & IN_ADIROP) || fs->lfs_unlockvp == vp;
 	while (!cantwait && fsb > 0 &&
 	       !lfs_fits(fs, fsb + fs->lfs_ravail + fs->lfs_favail)) {
 		mutex_exit(&lfs_lock);
@@ -589,7 +589,7 @@ lfs_check(struct vnode *vp, daddr_t blkn
 	if (ip->i_number == LFS_IFILE_INUM)
 		return 0;
 	/* If we're being called from inside a dirop, don't sleep */
-	if (ip->i_flag & IN_ADIROP)
+	if (ip->i_state & IN_ADIROP)
 		return 0;
 
 	fs = ip->i_lfs;

Index: src/sys/ufs/lfs/lfs_extern.h
diff -u src/sys/ufs/lfs/lfs_extern.h:1.111 src/sys/ufs/lfs/lfs_extern.h:1.111.10.1
--- src/sys/ufs/lfs/lfs_extern.h:1.111	Mon Jun 20 03:29:52 2016
+++ src/sys/ufs/lfs/lfs_extern.h	Mon Oct 30 09:29:04 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_extern.h,v 1.111 2016/06/20 03:29:52 dholland Exp $	*/
+/*	$NetBSD: lfs_extern.h,v 1.111.10.1 2017/10/30 09:29:04 snj Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -109,7 +109,7 @@ __BEGIN_DECLS
 
 #if defined(_KERNEL)
 
-extern int lfs_allclean_wakeup;
+extern kcondvar_t lfs_allclean_wakeup;
 extern struct pool lfs_inode_pool;		/* memory pool for inodes */
 extern struct pool lfs_dinode_pool;		/* memory pool for dinodes */
 extern struct pool lfs_inoext_pool;	/* memory pool for inode extension */

Index: src/sys/ufs/lfs/lfs_inode.c
diff -u src/sys/ufs/lfs/lfs_inode.c:1.155 src/sys/ufs/lfs/lfs_inode.c:1.155.6.1
--- src/sys/ufs/lfs/lfs_inode.c:1.155	Sat Apr  1 00:40:42 2017
+++ src/sys/ufs/lfs/lfs_inode.c	Mon Oct 30 09:29:04 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_inode.c,v 1.155 2017/04/01 00:40:42 maya Exp $	*/
+/*	$NetBSD: lfs_inode.c,v 1.155.6.1 2017/10/30 09:29:04 snj Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_inode.c,v 1.155 2017/04/01 00:40:42 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_inode.c,v 1.155.6.1 2017/10/30 09:29:04 snj Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_quota.h"
@@ -156,9 +156,9 @@ lfs_update(struct vnode *vp, const struc
 	mutex_exit(vp->v_interlock);
 	LFS_ITIMES(ip, acc, mod, NULL);
 	if (updflags & UPDATE_CLOSE)
-		flags = ip->i_flag & (IN_MODIFIED | IN_ACCESSED | IN_CLEANING);
+		flags = ip->i_state & (IN_MODIFIED | IN_ACCESSED | IN_CLEANING);
 	else
-		flags = ip->i_flag & (IN_MODIFIED | IN_CLEANING);
+		flags = ip->i_state & (IN_MODIFIED | IN_CLEANING);
 	if (flags == 0)
 		return (0);
 
@@ -170,10 +170,10 @@ lfs_update(struct vnode *vp, const struc
 		while (vp->v_uflag & VU_DIROP) {
 			DLOG((DLOG_DIROP, "lfs_update: sleeping on inode %llu "
 			      "(dirops)\n", (unsigned long long) ip->i_number));
-			DLOG((DLOG_DIROP, "lfs_update: vflags 0x%x, iflags"
+			DLOG((DLOG_DIROP, "lfs_update: vflags 0x%x, i_state"
 			      " 0x%x\n",
 			      vp->v_iflag | vp->v_vflag | vp->v_uflag,
-			      ip->i_flag));
+			      ip->i_state));
 			if (fs->lfs_dirops == 0)
 				lfs_flush_fs(fs, SEGM_SYNC);
 			else
@@ -239,13 +239,13 @@ lfs_truncate(struct vnode *ovp, off_t le
 		memset((char *)SHORTLINK(oip), 0, (u_int)oip->i_size);
 		oip->i_size = 0;
 		lfs_dino_setsize(fs, oip->i_din, 0);
-		oip->i_flag |= IN_CHANGE | IN_UPDATE;
+		oip->i_state |= IN_CHANGE | IN_UPDATE;
 		return (lfs_update(ovp, NULL, NULL, 0));
 	}
 	if (oip->i_size == length) {
 		/* still do a uvm_vnp_setsize() as writesize may be larger */
 		uvm_vnp_setsize(ovp, length);
-		oip->i_flag |= IN_CHANGE | IN_UPDATE;
+		oip->i_state |= IN_CHANGE | IN_UPDATE;
 		return (lfs_update(ovp, NULL, NULL, 0));
 	}
 	lfs_imtime(fs);
@@ -296,7 +296,7 @@ lfs_truncate(struct vnode *ovp, off_t le
 				return error;
 			}
 			uvm_vnp_setsize(ovp, length);
-			oip->i_flag |= IN_CHANGE | IN_UPDATE;
+			oip->i_state |= IN_CHANGE | IN_UPDATE;
 			KASSERT(ovp->v_size == oip->i_size);
 			oip->i_lfs_hiblk = lfs_lblkno(fs, oip->i_size + lfs_sb_getbsize(fs) - 1) - 1;
 			return (lfs_update(ovp, NULL, NULL, 0));
@@ -315,7 +315,7 @@ lfs_truncate(struct vnode *ovp, off_t le
 			lfs_dino_setsize(fs, oip->i_din, oip->i_size);
 			uvm_vnp_setsize(ovp, length);
 			(void) VOP_BWRITE(bp->b_vp, bp);
-			oip->i_flag |= IN_CHANGE | IN_UPDATE;
+			oip->i_state |= IN_CHANGE | IN_UPDATE;
 			oip->i_lfs_hiblk = lfs_lblkno(fs, oip->i_size + lfs_sb_getbsize(fs) - 1) - 1;
 			return (lfs_update(ovp, NULL, NULL, 0));
 		}
@@ -592,13 +592,13 @@ done:
 	/*
 	 * If we truncated to zero, take us off the paging queue.
 	 */
-	if (oip->i_size == 0 && oip->i_flags & IN_PAGING) {
-		oip->i_flags &= ~IN_PAGING;
+	if (oip->i_size == 0 && oip->i_state & IN_PAGING) {
+		oip->i_state &= ~IN_PAGING;
 		TAILQ_REMOVE(&fs->lfs_pchainhd, oip, i_lfs_pchain);
 	}
 	mutex_exit(&lfs_lock);
 
-	oip->i_flag |= IN_CHANGE;
+	oip->i_state |= IN_CHANGE;
 #if defined(LFS_QUOTA) || defined(LFS_QUOTA2)
 	(void) lfs_chkdq(oip, -blocksreleased, NOCRED, 0);
 #endif

Index: src/sys/ufs/lfs/lfs_inode.h
diff -u src/sys/ufs/lfs/lfs_inode.h:1.19 src/sys/ufs/lfs/lfs_inode.h:1.19.6.1
--- src/sys/ufs/lfs/lfs_inode.h:1.19	Thu Apr  6 03:21:01 2017
+++ src/sys/ufs/lfs/lfs_inode.h	Mon Oct 30 09:29:04 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_inode.h,v 1.19 2017/04/06 03:21:01 maya Exp $	*/
+/*	$NetBSD: lfs_inode.h,v 1.19.6.1 2017/10/30 09:29:04 snj Exp $	*/
 /*  from NetBSD: ulfs_inode.h,v 1.5 2013/06/06 00:51:50 dholland Exp  */
 /*  from NetBSD: inode.h,v 1.72 2016/06/03 15:36:03 christos Exp  */
 
@@ -107,7 +107,26 @@ struct inode {
 	struct	vnode *i_vnode;	/* Vnode associated with this inode. */
 	struct  ulfsmount *i_ump; /* Mount point associated with this inode. */
 	struct	vnode *i_devvp;	/* Vnode for block I/O. */
-	uint32_t i_flag;	/* flags, see below */
+
+	uint32_t i_state;	/* state */
+#define	IN_ACCESS	0x0001		/* Access time update request. */
+#define	IN_CHANGE	0x0002		/* Inode change time update request. */
+#define	IN_UPDATE	0x0004		/* Inode was written to; update mtime. */
+#define	IN_MODIFY	0x2000		/* Modification time update request. */
+#define	IN_MODIFIED	0x0008		/* Inode has been modified. */
+#define	IN_ACCESSED	0x0010		/* Inode has been accessed. */
+/* 	   unused	0x0020 */	/* was IN_RENAME */
+#define	IN_SHLOCK	0x0040		/* File has shared lock. */
+#define	IN_EXLOCK	0x0080		/* File has exclusive lock. */
+#define	IN_CLEANING	0x0100		/* LFS: file is being cleaned */
+#define	IN_ADIROP	0x0200		/* LFS: dirop in progress */
+/* 	   unused	0x0400 */	/* was FFS-only IN_SPACECOUNTED */
+#define	IN_PAGING       0x1000		/* LFS: file is on paging queue */
+#define IN_CDIROP       0x4000          /* LFS: dirop completed pending i/o */
+
+/* XXX this is missing some of the flags */
+#define IN_ALLMOD (IN_MODIFIED|IN_ACCESS|IN_CHANGE|IN_UPDATE|IN_MODIFY|IN_ACCESSED|IN_CLEANING)
+
 	dev_t	  i_dev;	/* Device associated with the inode. */
 	ino_t	  i_number;	/* The identity of the inode. */
 
@@ -154,22 +173,6 @@ struct inode {
 	union lfs_dinode *i_din;
 };
 
-/* These flags are kept in i_flag. */
-#define	IN_ACCESS	0x0001		/* Access time update request. */
-#define	IN_CHANGE	0x0002		/* Inode change time update request. */
-#define	IN_UPDATE	0x0004		/* Inode was written to; update mtime. */
-#define	IN_MODIFY	0x2000		/* Modification time update request. */
-#define	IN_MODIFIED	0x0008		/* Inode has been modified. */
-#define	IN_ACCESSED	0x0010		/* Inode has been accessed. */
-/* 	   unused	0x0020 */	/* was IN_RENAME */
-#define	IN_SHLOCK	0x0040		/* File has shared lock. */
-#define	IN_EXLOCK	0x0080		/* File has exclusive lock. */
-#define	IN_CLEANING	0x0100		/* LFS: file is being cleaned */
-#define	IN_ADIROP	0x0200		/* LFS: dirop in progress */
-/* 	   unused	0x0400 */	/* was FFS-only IN_SPACECOUNTED */
-#define	IN_PAGING       0x1000		/* LFS: file is on paging queue */
-#define IN_CDIROP       0x4000          /* LFS: dirop completed pending i/o */
-
 /*
  * LFS inode extensions.
  */

Index: src/sys/ufs/lfs/lfs_itimes.c
diff -u src/sys/ufs/lfs/lfs_itimes.c:1.19 src/sys/ufs/lfs/lfs_itimes.c:1.19.10.1
--- src/sys/ufs/lfs/lfs_itimes.c:1.19	Tue Sep  1 06:08:37 2015
+++ src/sys/ufs/lfs/lfs_itimes.c	Mon Oct 30 09:29:04 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_itimes.c,v 1.19 2015/09/01 06:08:37 dholland Exp $	*/
+/*	$NetBSD: lfs_itimes.c,v 1.19.10.1 2017/10/30 09:29:04 snj Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_itimes.c,v 1.19 2015/09/01 06:08:37 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_itimes.c,v 1.19.10.1 2017/10/30 09:29:04 snj Exp $");
 
 #include <sys/param.h>
 #include <sys/time.h>
@@ -61,12 +61,12 @@ lfs_itimes(struct inode *ip, const struc
 #ifdef _KERNEL
 	struct timespec now;
 
-	KASSERT(ip->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE | IN_MODIFY));
+	KASSERT(ip->i_state & (IN_ACCESS | IN_CHANGE | IN_UPDATE | IN_MODIFY));
 
 	vfs_timestamp(&now);
 #endif
 
-	if (ip->i_flag & IN_ACCESS) {
+	if (ip->i_state & IN_ACCESS) {
 #ifdef _KERNEL
 		if (acc == NULL)
 			acc = &now;
@@ -90,8 +90,8 @@ lfs_itimes(struct inode *ip, const struc
 			mutex_exit(&lfs_lock);
 		}
 	}
-	if (ip->i_flag & (IN_CHANGE | IN_UPDATE | IN_MODIFY)) {
-		if (ip->i_flag & (IN_UPDATE | IN_MODIFY)) {
+	if (ip->i_state & (IN_CHANGE | IN_UPDATE | IN_MODIFY)) {
+		if (ip->i_state & (IN_UPDATE | IN_MODIFY)) {
 #ifdef _KERNEL
 			if (mod == NULL)
 				mod = &now;
@@ -100,7 +100,7 @@ lfs_itimes(struct inode *ip, const struc
 			lfs_dino_setmtimensec(fs, ip->i_din, mod->tv_nsec);
 			ip->i_modrev++;
 		}
-		if (ip->i_flag & (IN_CHANGE | IN_MODIFY)) {
+		if (ip->i_state & (IN_CHANGE | IN_MODIFY)) {
 #ifdef _KERNEL
 			if (cre == NULL)
 				cre = &now;
@@ -109,11 +109,11 @@ lfs_itimes(struct inode *ip, const struc
 			lfs_dino_setctimensec(fs, ip->i_din, cre->tv_nsec);
 		}
 		mutex_enter(&lfs_lock);
-		if (ip->i_flag & (IN_CHANGE | IN_UPDATE))
+		if (ip->i_state & (IN_CHANGE | IN_UPDATE))
 			LFS_SET_UINO(ip, IN_MODIFIED);
-		if (ip->i_flag & IN_MODIFY)
+		if (ip->i_state & IN_MODIFY)
 			LFS_SET_UINO(ip, IN_ACCESSED);
 		mutex_exit(&lfs_lock);
 	}
-	ip->i_flag &= ~(IN_ACCESS | IN_CHANGE | IN_UPDATE | IN_MODIFY);
+	ip->i_state &= ~(IN_ACCESS | IN_CHANGE | IN_UPDATE | IN_MODIFY);
 }

Index: src/sys/ufs/lfs/lfs_pages.c
diff -u src/sys/ufs/lfs/lfs_pages.c:1.11.6.1 src/sys/ufs/lfs/lfs_pages.c:1.11.6.2
--- src/sys/ufs/lfs/lfs_pages.c:1.11.6.1	Sun Jun  4 20:35:02 2017
+++ src/sys/ufs/lfs/lfs_pages.c	Mon Oct 30 09:29:04 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_pages.c,v 1.11.6.1 2017/06/04 20:35:02 bouyer Exp $	*/
+/*	$NetBSD: lfs_pages.c,v 1.11.6.2 2017/10/30 09:29:04 snj Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_pages.c,v 1.11.6.1 2017/06/04 20:35:02 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_pages.c,v 1.11.6.2 2017/10/30 09:29:04 snj Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -506,8 +506,8 @@ retry:
 		
 		/* Remove us from paging queue, if we were on it */
 		mutex_enter(&lfs_lock);
-		if (ip->i_flags & IN_PAGING) {
-			ip->i_flags &= ~IN_PAGING;
+		if (ip->i_state & IN_PAGING) {
+			ip->i_state &= ~IN_PAGING;
 			TAILQ_REMOVE(&fs->lfs_pchainhd, ip, i_lfs_pchain);
 		}
 		mutex_exit(&lfs_lock);
@@ -688,8 +688,8 @@ retry:
 	if (pagedaemon) {
 		mutex_exit(vp->v_interlock);
 		mutex_enter(&lfs_lock);
-		if (!(ip->i_flags & IN_PAGING)) {
-			ip->i_flags |= IN_PAGING;
+		if (!(ip->i_state & IN_PAGING)) {
+			ip->i_state |= IN_PAGING;
 			TAILQ_INSERT_TAIL(&fs->lfs_pchainhd, ip, i_lfs_pchain);
 		}
 		cv_broadcast(&lfs_writerd_cv);
@@ -728,8 +728,11 @@ retry:
 		mutex_enter(vp->v_interlock);
 		lfs_writer_leave(fs);
 
-		/* The flush will have cleaned out this vnode as well,
-		   no need to do more to it. */
+		/*
+		 * The flush will have cleaned out this vnode as well,
+		 *  no need to do more to it.
+		 *  XXX then why are we falling through and continuing?
+		 */
 	}
 
 	/*
@@ -898,8 +901,8 @@ retry:
 	 */
 	if (origendoffset == 0 || ap->a_flags & PGO_ALLPAGES) {
 		mutex_enter(&lfs_lock);
-		if (ip->i_flags & IN_PAGING) {
-			ip->i_flags &= ~IN_PAGING;
+		if (ip->i_state & IN_PAGING) {
+			ip->i_state &= ~IN_PAGING;
 			TAILQ_REMOVE(&fs->lfs_pchainhd, ip, i_lfs_pchain);
 		}
 		mutex_exit(&lfs_lock);

Index: src/sys/ufs/lfs/lfs_rename.c
diff -u src/sys/ufs/lfs/lfs_rename.c:1.21 src/sys/ufs/lfs/lfs_rename.c:1.21.10.1
--- src/sys/ufs/lfs/lfs_rename.c:1.21	Mon Jun 20 03:36:09 2016
+++ src/sys/ufs/lfs/lfs_rename.c	Mon Oct 30 09:29:04 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_rename.c,v 1.21 2016/06/20 03:36:09 dholland Exp $	*/
+/*	$NetBSD: lfs_rename.c,v 1.21.10.1 2017/10/30 09:29:04 snj Exp $	*/
 /*  from NetBSD: ufs_rename.c,v 1.12 2015/03/27 17:27:56 riastradh Exp  */
 
 /*-
@@ -89,7 +89,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_rename.c,v 1.21 2016/06/20 03:36:09 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_rename.c,v 1.21.10.1 2017/10/30 09:29:04 snj Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -803,7 +803,7 @@ ulfs_gro_rename(struct mount *mp, kauth_
 	KASSERT((nlink_t)VTOI(fvp)->i_nlink < LINK_MAX);
 	VTOI(fvp)->i_nlink++;
 	DIP_ASSIGN(VTOI(fvp), nlink, VTOI(fvp)->i_nlink);
-	VTOI(fvp)->i_flag |= IN_CHANGE;
+	VTOI(fvp)->i_state |= IN_CHANGE;
 	error = lfs_update(fvp, NULL, NULL, UPDATE_DIROP);
 	if (error)
 		goto whymustithurtsomuch;
@@ -830,7 +830,7 @@ ulfs_gro_rename(struct mount *mp, kauth_
 			KASSERT((nlink_t)VTOI(tdvp)->i_nlink < LINK_MAX);
 			VTOI(tdvp)->i_nlink++;
 			DIP_ASSIGN(VTOI(tdvp), nlink, VTOI(tdvp)->i_nlink);
-			VTOI(tdvp)->i_flag |= IN_CHANGE;
+			VTOI(tdvp)->i_state |= IN_CHANGE;
 			error = lfs_update(tdvp, NULL, NULL, UPDATE_DIROP);
 			if (error) {
 				/*
@@ -841,7 +841,7 @@ ulfs_gro_rename(struct mount *mp, kauth_
 				VTOI(tdvp)->i_nlink--;
 				DIP_ASSIGN(VTOI(tdvp), nlink,
 				    VTOI(tdvp)->i_nlink);
-				VTOI(tdvp)->i_flag |= IN_CHANGE;
+				VTOI(tdvp)->i_state |= IN_CHANGE;
 				goto whymustithurtsomuch;
 			}
 		}
@@ -861,7 +861,7 @@ ulfs_gro_rename(struct mount *mp, kauth_
 				VTOI(tdvp)->i_nlink--;
 				DIP_ASSIGN(VTOI(tdvp), nlink,
 				    VTOI(tdvp)->i_nlink);
-				VTOI(tdvp)->i_flag |= IN_CHANGE;
+				VTOI(tdvp)->i_state |= IN_CHANGE;
 				(void)lfs_update(tdvp, NULL, NULL,
 				    UPDATE_WAIT | UPDATE_DIROP);
 			}
@@ -900,7 +900,7 @@ ulfs_gro_rename(struct mount *mp, kauth_
 			KASSERT(0 < VTOI(tdvp)->i_nlink);
 			VTOI(tdvp)->i_nlink--;
 			DIP_ASSIGN(VTOI(tdvp), nlink, VTOI(tdvp)->i_nlink);
-			VTOI(tdvp)->i_flag |= IN_CHANGE;
+			VTOI(tdvp)->i_state |= IN_CHANGE;
 		}
 
 		if (directory_p) {
@@ -1008,7 +1008,7 @@ whymustithurtsomuch:
 	KASSERT(0 < VTOI(fvp)->i_nlink);
 	VTOI(fvp)->i_nlink--;
 	DIP_ASSIGN(VTOI(fvp), nlink, VTOI(fvp)->i_nlink);
-	VTOI(fvp)->i_flag |= IN_CHANGE;
+	VTOI(fvp)->i_state |= IN_CHANGE;
 
 arghmybrainhurts:
 /*ihateyou:*/

Index: src/sys/ufs/lfs/lfs_segment.c
diff -u src/sys/ufs/lfs/lfs_segment.c:1.269 src/sys/ufs/lfs/lfs_segment.c:1.269.6.1
--- src/sys/ufs/lfs/lfs_segment.c:1.269	Thu Apr  6 03:21:01 2017
+++ src/sys/ufs/lfs/lfs_segment.c	Mon Oct 30 09:29:04 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_segment.c,v 1.269 2017/04/06 03:21:01 maya Exp $	*/
+/*	$NetBSD: lfs_segment.c,v 1.269.6.1 2017/10/30 09:29:04 snj Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,11 +60,11 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_segment.c,v 1.269 2017/04/06 03:21:01 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_segment.c,v 1.269.6.1 2017/10/30 09:29:04 snj Exp $");
 
 #ifdef DEBUG
 # define vndebug(vp, str) do {						\
-	if (VTOI(vp)->i_flag & IN_CLEANING)				\
+	if (VTOI(vp)->i_state & IN_CLEANING)				\
 		DLOG((DLOG_WVNODE, "not writing ino %d because %s (op %d)\n", \
 		     VTOI(vp)->i_number, (str), op));			\
 } while(0)
@@ -145,7 +145,7 @@ int	 lfs_writevnodes(struct lfs *fs, str
 static void lfs_shellsort(struct lfs *, struct buf **, union lfs_blocks *,
 			  int, int);
 
-int	lfs_allclean_wakeup;		/* Cleaner wakeup address. */
+kcondvar_t	lfs_allclean_wakeup;	/* Cleaner wakeup address. */
 int	lfs_writeindir = 1;		/* whether to flush indir on non-ckp */
 int	lfs_clean_vnhead = 0;		/* Allow freeing to head of vn list */
 int	lfs_dirvcount = 0;		/* # active dirops */
@@ -208,7 +208,7 @@ lfs_vflush(struct vnode *vp)
 	KASSERT(mutex_owned(&lfs_lock) == false);
 	KASSERT(mutex_owned(&bufcache_lock) == false);
 	ASSERT_NO_SEGLOCK(fs);
-	if (ip->i_flag & IN_CLEANING) {
+	if (ip->i_state & IN_CLEANING) {
 		ivndebug(vp,"vflush/in_cleaning");
 		mutex_enter(&lfs_lock);
 		LFS_CLR_UINO(ip, IN_CLEANING);
@@ -333,7 +333,7 @@ lfs_vflush(struct vnode *vp)
 		mutex_exit(&bufcache_lock);
 		LFS_CLR_UINO(ip, IN_CLEANING);
 		LFS_CLR_UINO(ip, IN_MODIFIED | IN_ACCESSED);
-		ip->i_flag &= ~IN_ALLMOD;
+		ip->i_state &= ~IN_ALLMOD;
 		DLOG((DLOG_VNODE, "lfs_vflush: done not flushing ino %d\n",
 		      ip->i_number));
 		lfs_segunlock(fs);
@@ -367,13 +367,13 @@ lfs_vflush(struct vnode *vp)
 	if (VPISEMPTY(vp)) {
 		lfs_writevnodes(fs, vp->v_mount, sp, VN_EMPTY);
 		++flushed;
-	} else if ((ip->i_flag & IN_CLEANING) &&
+	} else if ((ip->i_state & IN_CLEANING) &&
 		  (fs->lfs_sp->seg_flags & SEGM_CLEAN)) {
 		ivndebug(vp,"vflush/clean");
 		lfs_writevnodes(fs, vp->v_mount, sp, VN_CLEAN);
 		++flushed;
 	} else if (lfs_dostats) {
-		if (!VPISEMPTY(vp) || (VTOI(vp)->i_flag & IN_ALLMOD))
+		if (!VPISEMPTY(vp) || (VTOI(vp)->i_state & IN_ALLMOD))
 			++lfs_stats.vflush_invoked;
 		ivndebug(vp,"vflush");
 	}
@@ -502,7 +502,7 @@ lfs_writevnodes_selector(void *cl, struc
 		return false;;
 	}
 	if (op == VN_CLEAN && ip->i_number != LFS_IFILE_INUM &&
-	    vp != c->fs->lfs_flushvp && !(ip->i_flag & IN_CLEANING)) {
+	    vp != c->fs->lfs_flushvp && !(ip->i_state & IN_CLEANING)) {
 		vndebug(vp,"cleaning");
 		return false;
 	}
@@ -543,7 +543,7 @@ lfs_writevnodes(struct lfs *fs, struct m
 		/*
 		 * Write the inode/file if dirty and it's not the IFILE.
 		 */
-		if (((ip->i_flag & IN_ALLMOD) || !VPISEMPTY(vp)) &&
+		if (((ip->i_state & IN_ALLMOD) || !VPISEMPTY(vp)) &&
 		    ip->i_number != LFS_IFILE_INUM) {
 			error = lfs_writefile(fs, sp, vp);
 			if (error) {
@@ -560,7 +560,7 @@ lfs_writevnodes(struct lfs *fs, struct m
 					lfs_writeseg(fs, sp);
 					if (!VPISEMPTY(vp) &&
 					    !WRITEINPROG(vp) &&
-					    !(ip->i_flag & IN_ALLMOD)) {
+					    !(ip->i_state & IN_ALLMOD)) {
 						mutex_enter(&lfs_lock);
 						LFS_SET_UINO(ip, IN_MODIFIED);
 						mutex_exit(&lfs_lock);
@@ -574,7 +574,7 @@ lfs_writevnodes(struct lfs *fs, struct m
 			if (!VPISEMPTY(vp)) {
 				if (WRITEINPROG(vp)) {
 					ivndebug(vp,"writevnodes/write2");
-				} else if (!(ip->i_flag & IN_ALLMOD)) {
+				} else if (!(ip->i_state & IN_ALLMOD)) {
 					mutex_enter(&lfs_lock);
 					LFS_SET_UINO(ip, IN_MODIFIED);
 					mutex_exit(&lfs_lock);
@@ -661,7 +661,11 @@ lfs_segwrite(struct mount *mp, int flags
 				error = lfs_writevnodes(fs, mp, sp, VN_DIROP);
 				if (um_error == 0)
 					um_error = error;
-				/* In case writevnodes errored out */
+				/*
+				 * In case writevnodes errored out
+				 * XXX why are we always doing this and not
+				 * just on error?
+				 */
 				lfs_flush_dirops(fs);
 				ssp = (SEGSUM *)(sp->segsum);
 				lfs_ss_setflags(fs, ssp,
@@ -753,7 +757,7 @@ lfs_segwrite(struct mount *mp, int flags
 				lfs_writefile(fs, sp, vp);
 			}
 
-			if (ip->i_flag & IN_ALLMOD)
+			if (ip->i_state & IN_ALLMOD)
 				++did_ckp;
 #if 0
 			redo = (do_ckp ? lfs_writeinode(fs, sp, ip) : 0);
@@ -1041,7 +1045,7 @@ lfs_writeinode(struct lfs *fs, struct se
 	SEGSUM *ssp;
 
 	ASSERT_SEGLOCK(fs);
-	if (!(ip->i_flag & IN_ALLMOD) && !(vp->v_uflag & VU_DIROP))
+	if (!(ip->i_state & IN_ALLMOD) && !(vp->v_uflag & VU_DIROP))
 		return (0);
 
 	/* Can't write ifile when writer is not set */
@@ -1160,7 +1164,7 @@ lfs_writeinode(struct lfs *fs, struct se
 	 */
 	if (vp->v_uflag & VU_DIROP) {
 		if (!(sp->seg_flags & SEGM_CLEAN))
-			ip->i_flag |= IN_CDIROP;
+			ip->i_state |= IN_CDIROP;
 		else {
 			DLOG((DLOG_DIROP, "lfs_writeinode: not clearing dirop for cleaned ino %d\n", (int)ip->i_number));
 		}
@@ -1249,7 +1253,7 @@ lfs_writeinode(struct lfs *fs, struct se
 	}
 #endif /* DIAGNOSTIC */
 
-	if (ip->i_flag & IN_CLEANING)
+	if (ip->i_state & IN_CLEANING)
 		LFS_CLR_UINO(ip, IN_CLEANING);
 	else {
 		/* XXX IN_ALLMOD */
@@ -1381,7 +1385,8 @@ loop:
 	for (bp = LIST_FIRST(&vp->v_dirtyblkhd);
 	     bp && LIST_NEXT(bp, b_vnbufs) != NULL;
 	     bp = LIST_NEXT(bp, b_vnbufs))
-		/* nothing */;
+		continue;
+
 	for (; bp && bp != BEG_OF_LIST; bp = nbp) {
 		nbp = BACK_BUF(bp);
 #else /* LFS_NO_BACKBUF_HACK */

Index: src/sys/ufs/lfs/lfs_syscalls.c
diff -u src/sys/ufs/lfs/lfs_syscalls.c:1.174 src/sys/ufs/lfs/lfs_syscalls.c:1.174.4.1
--- src/sys/ufs/lfs/lfs_syscalls.c:1.174	Mon Apr 17 08:32:01 2017
+++ src/sys/ufs/lfs/lfs_syscalls.c	Mon Oct 30 09:29:04 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_syscalls.c,v 1.174 2017/04/17 08:32:01 hannken Exp $	*/
+/*	$NetBSD: lfs_syscalls.c,v 1.174.4.1 2017/10/30 09:29:04 snj Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007, 2007, 2008
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_syscalls.c,v 1.174 2017/04/17 08:32:01 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_syscalls.c,v 1.174.4.1 2017/10/30 09:29:04 snj Exp $");
 
 #ifndef LFS
 # define LFS		/* for prototypes in syscallargs.h */
@@ -899,7 +899,7 @@ lfs_segwait(fsid_t *fsidp, struct timeva
 	u_long timeout;
 	int error;
 
-	KERNEL_LOCK(1, NULL);
+	mutex_enter(&lfs_lock);
 	if (fsidp == NULL || (mntp = vfs_getvfs(fsidp)) == NULL)
 		addr = &lfs_allclean_wakeup;
 	else
@@ -909,8 +909,8 @@ lfs_segwait(fsid_t *fsidp, struct timeva
 	 * XXX IS THAT WHAT IS INTENDED?
 	 */
 	timeout = tvtohz(tv);
-	error = tsleep(addr, PCATCH | PVFS, "segment", timeout);
-	KERNEL_UNLOCK_ONE(NULL);
+	error = cv_timedwait_sig(addr, &lfs_lock, timeout);
+	mutex_exit(&lfs_lock);
 	return (error == ERESTART ? EINTR : 0);
 }
 

Index: src/sys/ufs/lfs/lfs_vfsops.c
diff -u src/sys/ufs/lfs/lfs_vfsops.c:1.359 src/sys/ufs/lfs/lfs_vfsops.c:1.359.4.1
--- src/sys/ufs/lfs/lfs_vfsops.c:1.359	Mon Apr 17 08:32:01 2017
+++ src/sys/ufs/lfs/lfs_vfsops.c	Mon Oct 30 09:29:04 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_vfsops.c,v 1.359 2017/04/17 08:32:01 hannken Exp $	*/
+/*	$NetBSD: lfs_vfsops.c,v 1.359.4.1 2017/10/30 09:29:04 snj Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007, 2007
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_vfsops.c,v 1.359 2017/04/17 08:32:01 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_vfsops.c,v 1.359.4.1 2017/10/30 09:29:04 snj Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_lfs.h"
@@ -860,6 +860,7 @@ lfs_checkmagic(struct lfs *fs)
 int
 lfs_mountfs(struct vnode *devvp, struct mount *mp, struct lwp *l)
 {
+	static bool lfs_mounted_once = false;
 	struct lfs *primarysb, *altsb, *thesb;
 	struct buf *primarybuf, *altbuf;
 	struct lfs *fs;
@@ -1091,6 +1092,13 @@ lfs_mountfs(struct vnode *devvp, struct 
 	cv_init(&fs->lfs_sleeperscv, "lfs_slp");
 	cv_init(&fs->lfs_diropscv, "lfs_dirop");
 	cv_init(&fs->lfs_stopcv, "lfsstop");
+	cv_init(&fs->lfs_nextsegsleep, "segment");
+
+	/* Initialize values for all LFS mounts */
+	if (!lfs_mounted_once) {
+		cv_init(&lfs_allclean_wakeup, "segment");
+		lfs_mounted_once = true;
+	}
 
 	/* Set the file system readonly/modify bits. */
 	fs->lfs_ronly = ronly;
@@ -1409,6 +1417,8 @@ lfs_unmount(struct mount *mp, int mntfla
 	cv_destroy(&fs->lfs_sleeperscv);
 	cv_destroy(&fs->lfs_diropscv);
 	cv_destroy(&fs->lfs_stopcv);
+	cv_destroy(&fs->lfs_nextsegsleep);
+
 	rw_destroy(&fs->lfs_fraglock);
 	rw_destroy(&fs->lfs_iflock);
 

Index: src/sys/ufs/lfs/lfs_vnops.c
diff -u src/sys/ufs/lfs/lfs_vnops.c:1.315 src/sys/ufs/lfs/lfs_vnops.c:1.315.2.1
--- src/sys/ufs/lfs/lfs_vnops.c:1.315	Fri May 26 14:21:02 2017
+++ src/sys/ufs/lfs/lfs_vnops.c	Mon Oct 30 09:29:04 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_vnops.c,v 1.315 2017/05/26 14:21:02 riastradh Exp $	*/
+/*	$NetBSD: lfs_vnops.c,v 1.315.2.1 2017/10/30 09:29:04 snj Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -125,7 +125,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.315 2017/05/26 14:21:02 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.315.2.1 2017/10/30 09:29:04 snj Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -374,10 +374,10 @@ lfs_makeinode(struct vattr *vap, struct 
 		vrele(tvp);
 		return error;
 	}
-	lfs_mark_vnode(tvp);
+	MARK_VNODE(tvp);
 	*vpp = tvp;
 	ip = VTOI(tvp);
-	ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
+	ip->i_state |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
 	ip->i_nlink = 1;
 	DIP_ASSIGN(ip, nlink, 1);
 
@@ -417,9 +417,9 @@ lfs_makeinode(struct vattr *vap, struct 
 	 */
 	ip->i_nlink = 0;
 	DIP_ASSIGN(ip, nlink, 0);
-	ip->i_flag |= IN_CHANGE;
+	ip->i_state |= IN_CHANGE;
 	/* If IN_ADIROP, account for it */
-	lfs_unmark_vnode(tvp);
+	UNMARK_VNODE(tvp);
 	vput(tvp);
 	return (error);
 }
@@ -461,8 +461,8 @@ lfs_fsync(void *v)
 	if (ap->a_flags & FSYNC_LAZY) {
 		if (lfs_ignore_lazy_sync == 0) {
 			mutex_enter(&lfs_lock);
-			if (!(ip->i_flags & IN_PAGING)) {
-				ip->i_flags |= IN_PAGING;
+			if (!(ip->i_state & IN_PAGING)) {
+				ip->i_state |= IN_PAGING;
 				TAILQ_INSERT_TAIL(&fs->lfs_pchainhd, ip,
 						  i_lfs_pchain);
 			}
@@ -473,11 +473,11 @@ lfs_fsync(void *v)
 	}
 
 	/*
-	 * If a vnode is bring cleaned, flush it out before we try to
+	 * If a vnode is being cleaned, flush it out before we try to
 	 * reuse it.  This prevents the cleaner from writing files twice
 	 * in the same partial segment, causing an accounting underflow.
 	 */
-	if (ap->a_flags & FSYNC_RECLAIM && ip->i_flags & IN_CLEANING) {
+	if (ap->a_flags & FSYNC_RECLAIM && ip->i_state & IN_CLEANING) {
 		lfs_vflush(vp);
 	}
 
@@ -526,7 +526,7 @@ lfs_inactive(void *v)
 
 	KASSERT(VOP_ISLOCKED(ap->a_vp) == LK_EXCLUSIVE);
 
-	lfs_unmark_vnode(ap->a_vp);
+	UNMARK_VNODE(ap->a_vp);
 
 	/*
 	 * The Ifile is only ever inactivated on unmount.
@@ -657,7 +657,7 @@ lfs_mark_vnode(struct vnode *vp)
 	struct lfs *fs = ip->i_lfs;
 
 	mutex_enter(&lfs_lock);
-	if (!(ip->i_flag & IN_ADIROP)) {
+	if (!(ip->i_state & IN_ADIROP)) {
 		if (!(vp->v_uflag & VU_DIROP)) {
 			mutex_exit(&lfs_lock);
 			vref(vp);
@@ -668,8 +668,8 @@ lfs_mark_vnode(struct vnode *vp)
 			vp->v_uflag |= VU_DIROP;
 		}
 		++fs->lfs_nadirop;
-		ip->i_flag &= ~IN_CDIROP;
-		ip->i_flag |= IN_ADIROP;
+		ip->i_state &= ~IN_CDIROP;
+		ip->i_state |= IN_ADIROP;
 	} else
 		KASSERT(vp->v_uflag & VU_DIROP);
 	mutex_exit(&lfs_lock);
@@ -681,10 +681,10 @@ lfs_unmark_vnode(struct vnode *vp)
 	struct inode *ip = VTOI(vp);
 
 	mutex_enter(&lfs_lock);
-	if (ip && (ip->i_flag & IN_ADIROP)) {
+	if (ip && (ip->i_state & IN_ADIROP)) {
 		KASSERT(vp->v_uflag & VU_DIROP);
 		--ip->i_lfs->lfs_nadirop;
-		ip->i_flag &= ~IN_ADIROP;
+		ip->i_state &= ~IN_ADIROP;
 	}
 	mutex_exit(&lfs_lock);
 }
@@ -750,9 +750,9 @@ lfs_symlink(void *v)
 		ip->i_size = len;
 		DIP_ASSIGN(ip, size, len);
 		uvm_vnp_setsize(*vpp, ip->i_size);
-		ip->i_flag |= IN_CHANGE | IN_UPDATE;
+		ip->i_state |= IN_CHANGE | IN_UPDATE;
 		if ((*vpp)->v_mount->mnt_flag & MNT_RELATIME)
-			ip->i_flag |= IN_ACCESS;
+			ip->i_state |= IN_ACCESS;
 	} else {
 		error = ulfs_bufio(UIO_WRITE, *vpp, ap->a_target, len, (off_t)0,
 		    IO_NODELOCKED | IO_JOURNALLOCKED, ap->a_cnp->cn_cred, NULL,
@@ -832,7 +832,7 @@ lfs_mknod(void *v)
 	VN_KNOTE(dvp, NOTE_WRITE);
 	ip = VTOI(*vpp);
 	ino = ip->i_number;
-	ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
+	ip->i_state |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
 
 	/*
 	 * Call fsync to write the vnode so that we don't have to deal with
@@ -989,9 +989,9 @@ lfs_mkdir(void *v)
 	}
 
 	tvp = *ap->a_vpp;
-	lfs_mark_vnode(tvp);
+	MARK_VNODE(tvp);
 	ip = VTOI(tvp);
-	ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
+	ip->i_state |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
 	ip->i_nlink = 2;
 	DIP_ASSIGN(ip, nlink, 2);
 	if (cnp->cn_flags & ISWHITEOUT) {
@@ -1004,7 +1004,7 @@ lfs_mkdir(void *v)
 	 */
 	dp->i_nlink++;
 	DIP_ASSIGN(dp, nlink, dp->i_nlink);
-	dp->i_flag |= IN_CHANGE;
+	dp->i_state |= IN_CHANGE;
 	if ((error = lfs_update(dvp, NULL, NULL, UPDATE_DIROP)) != 0)
 		goto bad;
 
@@ -1018,7 +1018,7 @@ lfs_mkdir(void *v)
 		goto bad;
 	ip->i_size = dirblksiz;
 	DIP_ASSIGN(ip, size, dirblksiz);
-	ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
+	ip->i_state |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
 	uvm_vnp_setsize(tvp, ip->i_size);
 	dirp = bp->b_data;
 
@@ -1055,16 +1055,16 @@ lfs_mkdir(void *v)
 	} else {
 		dp->i_nlink--;
 		DIP_ASSIGN(dp, nlink, dp->i_nlink);
-		dp->i_flag |= IN_CHANGE;
+		dp->i_state |= IN_CHANGE;
 		/*
 		 * No need to do an explicit lfs_truncate here, vrele will
 		 * do this for us because we set the link count to 0.
 		 */
 		ip->i_nlink = 0;
 		DIP_ASSIGN(ip, nlink, 0);
-		ip->i_flag |= IN_CHANGE;
+		ip->i_state |= IN_CHANGE;
 		/* If IN_ADIROP, account for it */
-		lfs_unmark_vnode(tvp);
+		UNMARK_VNODE(tvp);
 		vput(tvp);
 	}
 
@@ -1305,8 +1305,7 @@ lfs_wrapgo(struct lfs *fs, struct inode 
 		lfs_wakeup_cleaner(fs);
 	}
 	if (waitfor) {
-		mtsleep(&fs->lfs_nextsegsleep, PCATCH | PUSER, "segment",
-		    0, &lfs_lock);
+		cv_wait_sig(&fs->lfs_nextsegsleep, &lfs_lock);
 	}
 
 	return 0;
@@ -1446,17 +1445,14 @@ lfs_reclaim(void *v)
 	 * We shouldn't be on them.
 	 */
 	mutex_enter(&lfs_lock);
-	if (ip->i_flags & IN_PAGING) {
+	if (ip->i_state & IN_PAGING) {
 		log(LOG_WARNING, "%s: reclaimed vnode is IN_PAGING\n",
 		    lfs_sb_getfsmnt(fs));
-		ip->i_flags &= ~IN_PAGING;
+		ip->i_state &= ~IN_PAGING;
 		TAILQ_REMOVE(&fs->lfs_pchainhd, ip, i_lfs_pchain);
 	}
-	if (vp->v_uflag & VU_DIROP) {
+	if (vp->v_uflag & VU_DIROP)
 		panic("reclaimed vnode is VU_DIROP");
-		vp->v_uflag &= ~VU_DIROP;
-		TAILQ_REMOVE(&fs->lfs_dchainhd, ip, i_lfs_dchain);
-	}
 	mutex_exit(&lfs_lock);
 
 	pool_put(&lfs_dinode_pool, ip->i_din);
@@ -1655,7 +1651,7 @@ lfs_flush_dirops(struct lfs *fs)
 		vp = ITOV(ip);
 		mutex_enter(vp->v_interlock);
 
-		KASSERT((ip->i_flag & IN_ADIROP) == 0);
+		KASSERT((ip->i_state & IN_ADIROP) == 0);
 		KASSERT(vp->v_uflag & VU_DIROP);
 		KASSERT(vdead_check(vp, VDEAD_NOWAIT) == 0);
 
@@ -1677,10 +1673,10 @@ lfs_flush_dirops(struct lfs *fs)
 		 * waslocked = VOP_ISLOCKED(vp);
 		 */
 		if (vp->v_type != VREG &&
-		    ((ip->i_flag & IN_ALLMOD) || !VPISEMPTY(vp))) {
+		    ((ip->i_state & IN_ALLMOD) || !VPISEMPTY(vp))) {
 			error = lfs_writefile(fs, sp, vp);
 			if (!VPISEMPTY(vp) && !WRITEINPROG(vp) &&
-			    !(ip->i_flag & IN_ALLMOD)) {
+			    !(ip->i_state & IN_ALLMOD)) {
 			    	mutex_enter(&lfs_lock);
 				LFS_SET_UINO(ip, IN_MODIFIED);
 			    	mutex_exit(&lfs_lock);
@@ -1776,7 +1772,7 @@ lfs_flush_pchain(struct lfs *fs)
 
 		nip = TAILQ_NEXT(ip, i_lfs_pchain);
 
-		if (!(ip->i_flags & IN_PAGING))
+		if (!(ip->i_state & IN_PAGING))
 			goto top;
 
 		mutex_exit(&lfs_lock);
@@ -1792,7 +1788,7 @@ lfs_flush_pchain(struct lfs *fs)
 		ip = VTOI(vp);
 		mutex_enter(&lfs_lock);
 		if ((vp->v_uflag & VU_DIROP) != 0 || vp->v_type != VREG ||
-		    !(ip->i_flags & IN_PAGING)) {
+		    !(ip->i_state & IN_PAGING)) {
 			mutex_exit(&lfs_lock);
 			vput(vp);
 			mutex_enter(&lfs_lock);
@@ -1802,7 +1798,7 @@ lfs_flush_pchain(struct lfs *fs)
 
 		error = lfs_writefile(fs, sp, vp);
 		if (!VPISEMPTY(vp) && !WRITEINPROG(vp) &&
-		    !(ip->i_flag & IN_ALLMOD)) {
+		    !(ip->i_state & IN_ALLMOD)) {
 		    	mutex_enter(&lfs_lock);
 			LFS_SET_UINO(ip, IN_MODIFIED);
 		    	mutex_exit(&lfs_lock);

Index: src/sys/ufs/lfs/ulfs_inode.c
diff -u src/sys/ufs/lfs/ulfs_inode.c:1.19 src/sys/ufs/lfs/ulfs_inode.c:1.19.2.1
--- src/sys/ufs/lfs/ulfs_inode.c:1.19	Fri May 26 14:34:20 2017
+++ src/sys/ufs/lfs/ulfs_inode.c	Mon Oct 30 09:29:04 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ulfs_inode.c,v 1.19 2017/05/26 14:34:20 riastradh Exp $	*/
+/*	$NetBSD: ulfs_inode.c,v 1.19.2.1 2017/10/30 09:29:04 snj Exp $	*/
 /*  from NetBSD: ufs_inode.c,v 1.95 2015/06/13 14:56:45 hannken Exp  */
 
 /*
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ulfs_inode.c,v 1.19 2017/05/26 14:34:20 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ulfs_inode.c,v 1.19.2.1 2017/10/30 09:29:04 snj Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_lfs.h"
@@ -106,13 +106,13 @@ ulfs_inactive(void *v)
 		ip->i_mode = 0;
 		ip->i_omode = mode;
 		DIP_ASSIGN(ip, mode, 0);
-		ip->i_flag |= IN_CHANGE | IN_UPDATE;
+		ip->i_state |= IN_CHANGE | IN_UPDATE;
 		/*
 		 * Defer final inode free and update to ulfs_reclaim().
 		 */
 	}
 
-	if (ip->i_flag & (IN_CHANGE | IN_UPDATE | IN_MODIFIED)) {
+	if (ip->i_state & (IN_CHANGE | IN_UPDATE | IN_MODIFIED)) {
 		lfs_update(vp, NULL, NULL, 0);
 	}
 

Index: src/sys/ufs/lfs/ulfs_inode.h
diff -u src/sys/ufs/lfs/ulfs_inode.h:1.22 src/sys/ufs/lfs/ulfs_inode.h:1.22.10.1
--- src/sys/ufs/lfs/ulfs_inode.h:1.22	Tue Jun 21 06:14:40 2016
+++ src/sys/ufs/lfs/ulfs_inode.h	Mon Oct 30 09:29:04 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ulfs_inode.h,v 1.22 2016/06/21 06:14:40 dholland Exp $	*/
+/*	$NetBSD: ulfs_inode.h,v 1.22.10.1 2017/10/30 09:29:04 snj Exp $	*/
 /*  from NetBSD: inode.h,v 1.72 2016/06/03 15:36:03 christos Exp  */
 
 /*
@@ -175,7 +175,7 @@ struct lfid {
 
 #define WRITEINPROG(vp) ((vp)->v_numoutput > 0 ||			\
 	(!LIST_EMPTY(&(vp)->v_dirtyblkhd) &&				\
-	 !(VTOI(vp)->i_flag & (IN_MODIFIED | IN_ACCESSED | IN_CLEANING))))
+	 !(VTOI(vp)->i_state & (IN_MODIFIED | IN_ACCESSED | IN_CLEANING))))
 
 
 

Index: src/sys/ufs/lfs/ulfs_lookup.c
diff -u src/sys/ufs/lfs/ulfs_lookup.c:1.40 src/sys/ufs/lfs/ulfs_lookup.c:1.40.6.1
--- src/sys/ufs/lfs/ulfs_lookup.c:1.40	Thu Mar 30 09:10:08 2017
+++ src/sys/ufs/lfs/ulfs_lookup.c	Mon Oct 30 09:29:04 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ulfs_lookup.c,v 1.40 2017/03/30 09:10:08 hannken Exp $	*/
+/*	$NetBSD: ulfs_lookup.c,v 1.40.6.1 2017/10/30 09:29:04 snj Exp $	*/
 /*  from NetBSD: ufs_lookup.c,v 1.135 2015/07/11 11:04:48 mlelstv  */
 
 /*
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ulfs_lookup.c,v 1.40 2017/03/30 09:10:08 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ulfs_lookup.c,v 1.40.6.1 2017/10/30 09:29:04 snj Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_lfs.h"
@@ -478,7 +478,7 @@ notfound:
 		}
 		results->ulr_endoff = roundup(enduseful, dirblksiz);
 #if 0 /* commented out by dbj. none of the on disk fields changed */
-		dp->i_flag |= IN_CHANGE | IN_UPDATE;
+		dp->i_state |= IN_CHANGE | IN_UPDATE;
 #endif
 		/*
 		 * We return with the directory locked, so that
@@ -516,7 +516,7 @@ found:
 		dp->i_size =
 		    results->ulr_offset + LFS_DIRSIZ(fs, ep);
 		DIP_ASSIGN(dp, size, dp->i_size);
-		dp->i_flag |= IN_CHANGE | IN_UPDATE;
+		dp->i_state |= IN_CHANGE | IN_UPDATE;
 	}
 	brelse(bp, 0);
 
@@ -795,7 +795,7 @@ ulfs_direnter(struct vnode *dvp, const s
 		}
 		dp->i_size = ulr->ulr_offset + dirblksiz;
 		DIP_ASSIGN(dp, size, dp->i_size);
-		dp->i_flag |= IN_CHANGE | IN_UPDATE;
+		dp->i_state |= IN_CHANGE | IN_UPDATE;
 		uvm_vnp_setsize(dvp, dp->i_size);
 		lfs_blkoff = ulr->ulr_offset & (ump->um_mountp->mnt_stat.f_iosize - 1);
 		ep = (LFS_DIRHEADER *)((char *)bp->b_data + lfs_blkoff);
@@ -840,7 +840,7 @@ ulfs_direnter(struct vnode *dvp, const s
 #endif
 		dp->i_size = ulr->ulr_offset + ulr->ulr_count;
 		DIP_ASSIGN(dp, size, dp->i_size);
-		dp->i_flag |= IN_CHANGE | IN_UPDATE;
+		dp->i_state |= IN_CHANGE | IN_UPDATE;
 	}
 	/*
 	 * Get the block containing the space for the new directory entry.
@@ -931,7 +931,7 @@ ulfs_direnter(struct vnode *dvp, const s
 		    ulr->ulr_offset & ~(dirblksiz - 1));
 #endif
 	error = VOP_BWRITE(bp->b_vp, bp);
-	dp->i_flag |= IN_CHANGE | IN_UPDATE;
+	dp->i_state |= IN_CHANGE | IN_UPDATE;
 	/*
 	 * If all went well, and the directory can be shortened, proceed
 	 * with the truncation. Note that we have to unlock the inode for
@@ -1047,7 +1047,7 @@ out:
 	if (ip) {
 		ip->i_nlink--;
 		DIP_ASSIGN(ip, nlink, ip->i_nlink);
-		ip->i_flag |= IN_CHANGE;
+		ip->i_state |= IN_CHANGE;
 	}
 	/*
 	 * XXX did it ever occur to anyone that it might be a good
@@ -1057,7 +1057,7 @@ out:
 	 * definitely do not take this into account.
 	 */
 	error = VOP_BWRITE(bp->b_vp, bp);
-	dp->i_flag |= IN_CHANGE | IN_UPDATE;
+	dp->i_state |= IN_CHANGE | IN_UPDATE;
 	/*
 	 * If the last named reference to a snapshot goes away,
 	 * drop its snapshot reference so that it will be reclaimed
@@ -1103,9 +1103,9 @@ ulfs_dirrewrite(struct inode *dp, off_t 
 	lfs_dir_settype(fs, ep, newtype);
 	oip->i_nlink--;
 	DIP_ASSIGN(oip, nlink, oip->i_nlink);
-	oip->i_flag |= IN_CHANGE;
+	oip->i_state |= IN_CHANGE;
 	error = VOP_BWRITE(bp->b_vp, bp);
-	dp->i_flag |= iflags;
+	dp->i_state |= iflags;
 	/*
 	 * If the last named reference to a snapshot goes away,
 	 * drop its snapshot reference so that it will be reclaimed

Index: src/sys/ufs/lfs/ulfs_quota2.c
diff -u src/sys/ufs/lfs/ulfs_quota2.c:1.30 src/sys/ufs/lfs/ulfs_quota2.c:1.30.6.1
--- src/sys/ufs/lfs/ulfs_quota2.c:1.30	Thu Mar 30 09:10:08 2017
+++ src/sys/ufs/lfs/ulfs_quota2.c	Mon Oct 30 09:29:04 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ulfs_quota2.c,v 1.30 2017/03/30 09:10:08 hannken Exp $	*/
+/*	$NetBSD: ulfs_quota2.c,v 1.30.6.1 2017/10/30 09:29:04 snj Exp $	*/
 /*  from NetBSD: ufs_quota2.c,v 1.40 2015/03/28 19:24:05 maxv Exp Exp  */
 /*  from NetBSD: ffs_quota2.c,v 1.5 2015/02/22 14:12:48 maxv Exp  */
 
@@ -29,7 +29,7 @@
   */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ulfs_quota2.c,v 1.30 2017/03/30 09:10:08 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ulfs_quota2.c,v 1.30.6.1 2017/10/30 09:29:04 snj Exp $");
 
 #include <sys/buf.h>
 #include <sys/param.h>
@@ -322,7 +322,7 @@ quota2_q2ealloc(struct ulfsmount *ump, i
 		KASSERT((ip->i_size % ump->umq2_bsize) == 0);
 		ip->i_size += ump->umq2_bsize;
 		DIP_ASSIGN(ip, size, ip->i_size);
-		ip->i_flag |= IN_CHANGE | IN_UPDATE;
+		ip->i_state |= IN_CHANGE | IN_UPDATE;
 		uvm_vnp_setsize(vp, ip->i_size);
 		lfsquota2_addfreeq2e(q2h, bp->b_data, size, ump->umq2_bsize,
 		    needswap);

Index: src/sys/ufs/lfs/ulfs_readwrite.c
diff -u src/sys/ufs/lfs/ulfs_readwrite.c:1.23 src/sys/ufs/lfs/ulfs_readwrite.c:1.23.6.1
--- src/sys/ufs/lfs/ulfs_readwrite.c:1.23	Thu Mar 30 09:10:08 2017
+++ src/sys/ufs/lfs/ulfs_readwrite.c	Mon Oct 30 09:29:04 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ulfs_readwrite.c,v 1.23 2017/03/30 09:10:08 hannken Exp $	*/
+/*	$NetBSD: ulfs_readwrite.c,v 1.23.6.1 2017/10/30 09:29:04 snj Exp $	*/
 /*  from NetBSD: ufs_readwrite.c,v 1.120 2015/04/12 22:48:38 riastradh Exp  */
 
 /*-
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: ulfs_readwrite.c,v 1.23 2017/03/30 09:10:08 hannken Exp $");
+__KERNEL_RCSID(1, "$NetBSD: ulfs_readwrite.c,v 1.23.6.1 2017/10/30 09:29:04 snj Exp $");
 
 #ifdef LFS_READWRITE
 #define	FS			struct lfs
@@ -228,7 +228,7 @@ ulfs_post_read_update(struct vnode *vp, 
 	int error = oerror;
 
 	if (!(vp->v_mount->mnt_flag & MNT_NOATIME)) {
-		ip->i_flag |= IN_ACCESS;
+		ip->i_state |= IN_ACCESS;
 		if ((ioflag & IO_SYNC) == IO_SYNC) {
 			error = lfs_update(vp, NULL, NULL, UPDATE_WAIT);
 		}
@@ -580,9 +580,9 @@ ulfs_post_write_update(struct vnode *vp,
 	int error = oerror;
 
 	/* Trigger ctime and mtime updates, and atime if MNT_RELATIME.  */
-	ip->i_flag |= IN_CHANGE | IN_UPDATE;
+	ip->i_state |= IN_CHANGE | IN_UPDATE;
 	if (vp->v_mount->mnt_flag & MNT_RELATIME)
-		ip->i_flag |= IN_ACCESS;
+		ip->i_state |= IN_ACCESS;
 
 	/*
 	 * If we successfully wrote any data and we are not the superuser,

Index: src/sys/ufs/lfs/ulfs_vnops.c
diff -u src/sys/ufs/lfs/ulfs_vnops.c:1.48 src/sys/ufs/lfs/ulfs_vnops.c:1.48.4.1
--- src/sys/ufs/lfs/ulfs_vnops.c:1.48	Wed Apr 26 03:02:49 2017
+++ src/sys/ufs/lfs/ulfs_vnops.c	Mon Oct 30 09:29:04 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ulfs_vnops.c,v 1.48 2017/04/26 03:02:49 riastradh Exp $	*/
+/*	$NetBSD: ulfs_vnops.c,v 1.48.4.1 2017/10/30 09:29:04 snj Exp $	*/
 /*  from NetBSD: ufs_vnops.c,v 1.232 2016/05/19 18:32:03 riastradh Exp  */
 
 /*-
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ulfs_vnops.c,v 1.48 2017/04/26 03:02:49 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ulfs_vnops.c,v 1.48.4.1 2017/10/30 09:29:04 snj Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_lfs.h"
@@ -305,7 +305,7 @@ ulfs_setattr(void *v)
 			ip->i_flags |= (vap->va_flags & UF_SETTABLE);
 			DIP_ASSIGN(ip, flags, ip->i_flags);
 		}
-		ip->i_flag |= IN_CHANGE;
+		ip->i_state |= IN_CHANGE;
 		if (vap->va_flags & (IMMUTABLE | APPEND)) {
 			error = 0;
 			goto out;
@@ -376,11 +376,11 @@ ulfs_setattr(void *v)
 			goto out;
 		if (vap->va_atime.tv_sec != VNOVAL)
 			if (!(vp->v_mount->mnt_flag & MNT_NOATIME))
-				ip->i_flag |= IN_ACCESS;
+				ip->i_state |= IN_ACCESS;
 		if (vap->va_mtime.tv_sec != VNOVAL) {
-			ip->i_flag |= IN_CHANGE | IN_UPDATE;
+			ip->i_state |= IN_CHANGE | IN_UPDATE;
 			if (vp->v_mount->mnt_flag & MNT_RELATIME)
-				ip->i_flag |= IN_ACCESS;
+				ip->i_state |= IN_ACCESS;
 		}
 		if (vap->va_birthtime.tv_sec != VNOVAL) {
 			lfs_dino_setbirthtime(fs, ip->i_din,
@@ -430,7 +430,7 @@ ulfs_chmod(struct vnode *vp, int mode, k
 
 	ip->i_mode &= ~ALLPERMS;
 	ip->i_mode |= (mode & ALLPERMS);
-	ip->i_flag |= IN_CHANGE;
+	ip->i_state |= IN_CHANGE;
 	DIP_ASSIGN(ip, mode, ip->i_mode);
 	return (0);
 }
@@ -493,7 +493,7 @@ ulfs_chown(struct vnode *vp, uid_t uid, 
 	return (error);
  good:
 #endif /* LFS_QUOTA || LFS_QUOTA2 */
-	ip->i_flag |= IN_CHANGE;
+	ip->i_state |= IN_CHANGE;
 	return (0);
 }
 
@@ -588,7 +588,7 @@ ulfs_link(void *v)
 	}
 	ip->i_nlink++;
 	DIP_ASSIGN(ip, nlink, ip->i_nlink);
-	ip->i_flag |= IN_CHANGE;
+	ip->i_state |= IN_CHANGE;
 	error = lfs_update(vp, NULL, NULL, UPDATE_DIROP);
 	if (!error) {
 		error = ulfs_direnter(dvp, ulr, vp,
@@ -597,7 +597,7 @@ ulfs_link(void *v)
 	if (error) {
 		ip->i_nlink--;
 		DIP_ASSIGN(ip, nlink, ip->i_nlink);
-		ip->i_flag |= IN_CHANGE;
+		ip->i_state |= IN_CHANGE;
 	}
  out1:
 	VOP_UNLOCK(vp);
@@ -737,10 +737,10 @@ ulfs_rmdir(void *v)
 	 */
 	dp->i_nlink--;
 	DIP_ASSIGN(dp, nlink, dp->i_nlink);
-	dp->i_flag |= IN_CHANGE;
+	dp->i_state |= IN_CHANGE;
 	ip->i_nlink--;
 	DIP_ASSIGN(ip, nlink, ip->i_nlink);
-	ip->i_flag |= IN_CHANGE;
+	ip->i_state |= IN_CHANGE;
 	error = lfs_truncate(vp, (off_t)0, IO_SYNC, cnp->cn_cred);
 	cache_purge(vp);
 #ifdef LFS_DIRHASH
@@ -826,7 +826,7 @@ ulfs_readdir(void *v)
 
 	off = uio->uio_offset;
 	if (ap->a_cookies) {
-		ccount = rcount / _DIRENT_RECLEN(ndp, 1);
+		ccount = rcount / LFS_DIRECTSIZ(fs, 1);
 		ccp = *(ap->a_cookies) = malloc(ccount * sizeof(*ccp),
 		    M_TEMP, M_WAITOK);
 	} else {
@@ -948,7 +948,7 @@ ulfs_print(void *v)
 	    (unsigned long long)major(ip->i_dev),
 	    (unsigned long long)minor(ip->i_dev));
 	printf(" flags 0x%x, nlink %d\n",
-	    ip->i_flag, ip->i_nlink);
+	    ip->i_state, ip->i_nlink);
 	printf("\tmode 0%o, owner %d, group %d, size %qd",
 	    ip->i_mode, ip->i_uid, ip->i_gid,
 	    (long long)ip->i_size);
@@ -977,7 +977,7 @@ ulfsspec_read(void *v)
 	 * Set access flag.
 	 */
 	if ((ap->a_vp->v_mount->mnt_flag & MNT_NODEVMTIME) == 0)
-		VTOI(ap->a_vp)->i_flag |= IN_ACCESS;
+		VTOI(ap->a_vp)->i_state |= IN_ACCESS;
 	return (VOCALL (spec_vnodeop_p, VOFFSET(vop_read), ap));
 }
 
@@ -1000,7 +1000,7 @@ ulfsspec_write(void *v)
 	 * Set update and change flags.
 	 */
 	if ((ap->a_vp->v_mount->mnt_flag & MNT_NODEVMTIME) == 0)
-		VTOI(ap->a_vp)->i_flag |= IN_MODIFY;
+		VTOI(ap->a_vp)->i_state |= IN_MODIFY;
 	return (VOCALL (spec_vnodeop_p, VOFFSET(vop_write), ap));
 }
 
@@ -1022,7 +1022,7 @@ ulfsfifo_read(void *v)
 	/*
 	 * Set access flag.
 	 */
-	VTOI(ap->a_vp)->i_flag |= IN_ACCESS;
+	VTOI(ap->a_vp)->i_state |= IN_ACCESS;
 	return (VOCALL (fifo_vnodeop_p, VOFFSET(vop_read), ap));
 }
 
@@ -1044,7 +1044,7 @@ ulfsfifo_write(void *v)
 	/*
 	 * Set update and change flags.
 	 */
-	VTOI(ap->a_vp)->i_flag |= IN_MODIFY;
+	VTOI(ap->a_vp)->i_state |= IN_MODIFY;
 	return (VOCALL (fifo_vnodeop_p, VOFFSET(vop_write), ap));
 }
 
@@ -1235,7 +1235,7 @@ ulfs_gop_markupdate(struct vnode *vp, in
 	if (mask) {
 		struct inode *ip = VTOI(vp);
 
-		ip->i_flag |= mask;
+		ip->i_state |= mask;
 	}
 }
 

Reply via email to