CVS commit: src/external/cddl/osnet/lib/libzfs

2019-01-12 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sat Jan 12 10:44:05 UTC 2019

Modified Files:
src/external/cddl/osnet/lib/libzfs: zmount.c

Log Message:
Pass unmount flags down to syscall, "zfs unmount -f" now works.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/external/cddl/osnet/lib/libzfs/zmount.c

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

Modified files:

Index: src/external/cddl/osnet/lib/libzfs/zmount.c
diff -u src/external/cddl/osnet/lib/libzfs/zmount.c:1.1 src/external/cddl/osnet/lib/libzfs/zmount.c:1.2
--- src/external/cddl/osnet/lib/libzfs/zmount.c:1.1	Fri Aug  7 20:57:56 2009
+++ src/external/cddl/osnet/lib/libzfs/zmount.c	Sat Jan 12 10:44:05 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: zmount.c,v 1.1 2009/08/07 20:57:56 haad Exp $	*/
+/*	$NetBSD: zmount.c,v 1.2 2019/01/12 10:44:05 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -69,5 +69,5 @@ int
 umount2(const char *spec, int mflag)
 {
 
-	return unmount(spec, 0);
+	return unmount(spec, mflag);
 }



CVS commit: src/external/cddl/osnet/dist/uts/common/fs/zfs

2019-01-12 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sat Jan 12 10:43:33 UTC 2019

Modified Files:
src/external/cddl/osnet/dist/uts/common/fs/zfs: zfs_ioctl.c
zfs_onexit.c

Log Message:
The ZFS onexit routines expect opening ZFS_DEV with O_EXCL to return
a cloned device with an unique minor number.

Use fd_clone() on this condition to return a cloned device descriptor.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ioctl.c
cvs rdiff -u -r1.2 -r1.3 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_onexit.c

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

Modified files:

Index: src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ioctl.c
diff -u src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ioctl.c:1.14 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ioctl.c:1.15
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ioctl.c:1.14	Tue Jan  1 10:08:01 2019
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ioctl.c	Sat Jan 12 10:43:33 2019
@@ -6205,6 +6205,8 @@ zfs_ctldev_init(dev_t *devp)
 
 #ifdef __FreeBSD__
 	devfs_set_cdevpriv((void *)(uintptr_t)minor, zfsdev_close);
+#else
+	*devp = makedev(major(*devp), minor);
 #endif
 
 	zs = ddi_get_soft_state(zfsdev_state, minor);
@@ -6973,11 +6975,52 @@ MODULE_DEPEND(zfsctrl, acl_nfs4, 1, 1, 1
 
 MODULE(MODULE_CLASS_DRIVER, zfs, "solaris");
 
+static const struct fileops zfs_fileops;
+
+static int
+nb_zfsdev_fioctl(struct file *fp,  u_long cmd, void *argp)
+{
+	dev_t dev = (dev_t)(uintptr_t)fp->f_data;
+	int rval;
+
+	return zfsdev_ioctl(dev, cmd, (intptr_t)argp, fp->f_flag,
+	kauth_cred_get(), );
+}
+
+static int
+nb_zfsdev_fclose(struct file *fp)
+{
+	dev_t dev = (dev_t)(uintptr_t)fp->f_data;
+	int error;
+
+	return zfsdev_close(dev, fp->f_flag, OTYPCHR, fp->f_cred);
+}
+
 static int
 nb_zfsdev_copen(dev_t dev, int flag, int mode, lwp_t *l)
 {
+	const bool must_clone = (getminor(dev) == 0 && (flag & FEXCL) != 0);
+	struct file *fp;
+	int error, fd;
+
+	if (must_clone) {
+		error = fd_allocfile(, );
+		if (error)
+			return error;
+	}
+
+	error = zfsdev_open(, flag, OTYPCHR, kauth_cred_get());
 
-	return zfsdev_open(, flag, OTYPCHR, kauth_cred_get());
+	if (must_clone) {
+		if (error) {
+			fd_abort(curproc, fp, fd);
+			return error;
+		}
+		return fd_clone(fp, fd, flag, _fileops,
+		(void *)(uintptr_t)dev);
+	}
+
+	return error;
 }
 
 static int
@@ -7031,6 +7074,19 @@ nb_zvol_strategy(struct buf *bp)
 	(void) zvol_strategy(bp);
 }
 
+static const struct fileops zfs_fileops = {
+	.fo_name = "zfs",
+	.fo_read = fbadop_read,
+	.fo_write = fbadop_write,
+	.fo_ioctl = nb_zfsdev_fioctl,
+	.fo_fcntl = fnullop_fcntl,
+	.fo_poll = fnullop_poll,
+	.fo_stat = fbadop_stat,
+	.fo_close = nb_zfsdev_fclose,
+	.fo_kqfilter = fnullop_kqfilter,
+	.fo_restart = fnullop_restart,
+};
+
 const struct bdevsw zfs_bdevsw = {
 	.d_open = nb_zfsdev_bopen,
 	.d_close = nb_zfsdev_bclose,

Index: src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_onexit.c
diff -u src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_onexit.c:1.2 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_onexit.c:1.3
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_onexit.c:1.2	Mon May 28 21:05:07 2018
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_onexit.c	Sat Jan 12 10:43:33 2019
@@ -146,7 +146,8 @@ zfs_onexit_fd_hold(int fd, minor_t *mino
 	if (fp == NULL)
 		return (SET_ERROR(EBADF));
 
-	*minorp = getminor(fp->f_vnode->v_rdev);
+	ASSERT(strcmp(fp->f_ops->fo_name, "zfs") == 0);
+	*minorp = minor((dev_t)(uintptr_t)fp->f_data);
 #endif
 
 	return (zfs_onexit_minor_to_state(*minorp, ));



CVS commit: src/external/cddl/osnet/dist/uts/common/fs/zfs

2019-01-12 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sat Jan 12 10:42:09 UTC 2019

Modified Files:
src/external/cddl/osnet/dist/uts/common/fs/zfs: dmu_send.c

Log Message:
Need FOF_UPDATE_OFFSET to update the offset on plain files.

Running "zfs send" to plain files no longer writes garbage.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/dmu_send.c

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

Modified files:

Index: src/external/cddl/osnet/dist/uts/common/fs/zfs/dmu_send.c
diff -u src/external/cddl/osnet/dist/uts/common/fs/zfs/dmu_send.c:1.2 src/external/cddl/osnet/dist/uts/common/fs/zfs/dmu_send.c:1.3
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/dmu_send.c:1.2	Mon May 28 21:05:07 2018
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/dmu_send.c	Sat Jan 12 10:42:09 2019
@@ -72,6 +72,8 @@ static int
 fo_write(struct file *fp, struct uio *uio, cred_t *cred, int flags, kthread_t *thr)
 {
 
+	if (fp->f_type == DTYPE_VNODE)
+		flags |= FOF_UPDATE_OFFSET;
 	return (*fp->f_ops->fo_write)(fp, >f_offset, uio, cred, flags);
 }
 
@@ -79,6 +81,8 @@ static int
 fo_read(struct file *fp, struct uio *uio, cred_t *cred, int flags, kthread_t *thr)
 {
 
+	if (fp->f_type == DTYPE_VNODE)
+		flags |= FOF_UPDATE_OFFSET;
 	return (*fp->f_ops->fo_read)(fp, >f_offset, uio, cred, flags);
 }
 #endif



CVS commit: src/external/cddl/osnet/sys/kern

2019-01-12 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sat Jan 12 10:42:40 UTC 2019

Modified Files:
src/external/cddl/osnet/sys/kern: taskq.c

Log Message:
Disable valid assertion "!(flags & TQ_NOQUEUE)" as "zfs send" triggers it.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/external/cddl/osnet/sys/kern/taskq.c

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

Modified files:

Index: src/external/cddl/osnet/sys/kern/taskq.c
diff -u src/external/cddl/osnet/sys/kern/taskq.c:1.7 src/external/cddl/osnet/sys/kern/taskq.c:1.8
--- src/external/cddl/osnet/sys/kern/taskq.c:1.7	Mon May 28 21:05:09 2018
+++ src/external/cddl/osnet/sys/kern/taskq.c	Sat Jan 12 10:42:40 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: taskq.c,v 1.7 2018/05/28 21:05:09 chs Exp $	*/
+/*	$NetBSD: taskq.c,v 1.8 2019/01/12 10:42:40 hannken Exp $	*/
 
 /*
  * CDDL HEADER START
@@ -1001,7 +1001,9 @@ taskq_dispatch(taskq_t *tq, task_func_t 
 		/*
 		 * TQ_NOQUEUE flag can't be used with non-dynamic task queues.
 		 */
+#ifdef notyet
 		ASSERT(!(flags & TQ_NOQUEUE));
+#endif
 		/*
 		 * Enqueue the task to the underlying queue.
 		 */



CVS commit: src/external/cddl/osnet/dev/dtrace/amd64

2019-01-12 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sat Jan 12 10:41:31 UTC 2019

Modified Files:
src/external/cddl/osnet/dev/dtrace/amd64: dtrace_subr.c

Log Message:
There is no such function read_rflags(), probably meant x86_read_flags().


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 \
src/external/cddl/osnet/dev/dtrace/amd64/dtrace_subr.c

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

Modified files:

Index: src/external/cddl/osnet/dev/dtrace/amd64/dtrace_subr.c
diff -u src/external/cddl/osnet/dev/dtrace/amd64/dtrace_subr.c:1.11 src/external/cddl/osnet/dev/dtrace/amd64/dtrace_subr.c:1.12
--- src/external/cddl/osnet/dev/dtrace/amd64/dtrace_subr.c:1.11	Thu Aug 16 14:14:51 2018
+++ src/external/cddl/osnet/dev/dtrace/amd64/dtrace_subr.c	Sat Jan 12 10:41:31 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: dtrace_subr.c,v 1.11 2018/08/16 14:14:51 christos Exp $	*/
+/*	$NetBSD: dtrace_subr.c,v 1.12 2019/01/12 10:41:31 hannken Exp $	*/
 
 /*
  * CDDL HEADER START
@@ -412,7 +412,7 @@ dtrace_trap(struct trapframe *frame, u_i
 	 */
 	nofault = (cpu_core[cpuid].cpuc_dtrace_flags & CPU_DTRACE_NOFAULT) != 0;
 	if (nofault) {
-		KASSERTMSG((read_rflags() & PSL_I) == 0, "interrupts enabled");
+		KASSERTMSG((x86_read_flags() & PSL_I) == 0, "interrupts enabled");
 
 		/*
 		 * There are only a couple of trap types that are expected.



CVS commit: src/external/cddl/osnet/dist/uts/common/fs/zfs

2019-01-05 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sat Jan  5 09:20:29 UTC 2019

Modified Files:
src/external/cddl/osnet/dist/uts/common/fs/zfs: zfs_vnops.c

Log Message:
Even though zfs_netbsd_putpages() cannot use ZFS_ENTER() it has
to respect the teardown lock.

Enter z_teardown_lock as reader and ZFS_EXIT().

Instead of ZFS_VERIFY_ZP() return without writing and without
error from zfs_putapage() if "z_sa_hdl == NULL".


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_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/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c
diff -u src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.41 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.42
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.41	Tue Jan  1 10:09:26 2019
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c	Sat Jan  5 09:20:29 2019
@@ -5863,6 +5863,11 @@ zfs_putapage(vnode_t *vp, page_t **pp, i
 	struct uvm_object *uobj = >v_uobj;
 	kmutex_t *mtx = uobj->vmobjlock;
 
+	if (zp->z_sa_hdl == NULL) {
+		err = 0;
+		goto out_unbusy;
+	}
+
 	off = pp[0]->offset;
 	len = count * PAGESIZE;
 	KASSERT(off + len <= round_page(zp->z_size));
@@ -5914,6 +5919,7 @@ zfs_putapage(vnode_t *vp, page_t **pp, i
 	}
 	dmu_tx_commit(tx);
 
+out_unbusy:
 	mutex_enter(mtx);
 	mutex_enter(_pageqlock);
 	uvm_page_unbusy(pp, count);
@@ -5994,6 +6000,12 @@ zfs_netbsd_putpages(void *v)
 return 0;
 			}
 		}
+		/*
+		 * Cannot use ZFS_ENTER() here as it returns with error
+		 * if z_unmounted.  The next statement is equivalent.
+		 */
+		rrm_enter(>z_teardown_lock, RW_READER, FTAG);
+
 		rl = zfs_range_lock(zp, offlo, len, RL_WRITER);
 		mutex_enter(vp->v_interlock);
 		tsd_set(zfs_putpage_key, );
@@ -6011,6 +6023,7 @@ zfs_netbsd_putpages(void *v)
 		if (cleaned)
 		if (!async || zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
 			zil_commit(zfsvfs->z_log, zp->z_id);
+		ZFS_EXIT(zfsvfs);
 		fstrans_done(vp->v_mount);
 	}
 	return error;



CVS commit: src/external/cddl/osnet/dist/uts/common/fs/zfs

2019-01-01 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Tue Jan  1 10:08:42 UTC 2019

Modified Files:
src/external/cddl/osnet/dist/uts/common/fs/zfs: zfs_vnops.c

Log Message:
As already noted in XXX comment do a zil_commit() on reclaim.


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_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/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c
diff -u src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.39 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.40
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.39	Thu Dec 13 10:20:51 2018
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c	Tue Jan  1 10:08:42 2019
@@ -5663,11 +5663,6 @@ zfs_netbsd_reclaim(void *v)
 	/*
 	 * Process a deferred atime update.
 	 */
-	/*
-	 * XXXNETBSD I don't think this actually works.
-	 * We are dirtying the znode again after the vcache layer cleaned it,
-	 * so we would need to zil_commit() again here.
-	 */
 	if (zp->z_atime_dirty && zp->z_unlinked == 0) {
 		dmu_tx_t *tx = dmu_tx_create(zfsvfs->z_os);
 
@@ -5684,6 +5679,8 @@ zfs_netbsd_reclaim(void *v)
 		}
 	}
 
+	zil_commit(zfsvfs->z_log, zp->z_id);
+
 	if (zp->z_sa_hdl == NULL)
 		zfs_znode_free(zp);
 	else



CVS commit: src/external/cddl/osnet/dist/uts/common/fs/zfs

2019-01-01 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Tue Jan  1 10:09:27 UTC 2019

Modified Files:
src/external/cddl/osnet/dist/uts/common/fs/zfs: zfs_vnops.c

Log Message:
Cannot use ZFS_ENTER() / ZFS_EXIT() as zfs_netbsd_putpages() is used
during vnode reclaim.

Add missing protection with fstrans.


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_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/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c
diff -u src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.40 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.41
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.40	Tue Jan  1 10:08:42 2019
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c	Tue Jan  1 10:09:26 2019
@@ -84,6 +84,7 @@
 #include 
 #include 
 #include 
+#include 
 
 uint_t zfs_putpage_key;
 #endif
@@ -5972,9 +5973,6 @@ zfs_netbsd_putpages(void *v)
 	bool async = (flags & PGO_SYNCIO) == 0;
 	bool cleaning = (flags & PGO_CLEANIT) != 0;
 
-	ZFS_ENTER(zfsvfs);
-	ZFS_VERIFY_ZP(zp);
-
 	if (cleaning) {
 		ASSERT((offlo & PAGE_MASK) == 0 && (offhi & PAGE_MASK) == 0);
 		ASSERT(offlo < offhi || offhi == 0);
@@ -5983,25 +5981,38 @@ zfs_netbsd_putpages(void *v)
 		else
 			len = offhi - offlo;
 		mutex_exit(vp->v_interlock);
+		if (curlwp == uvm.pagedaemon_lwp) {
+			error = fstrans_start_nowait(vp->v_mount);
+			if (error)
+return error;
+		} else {
+			vfs_t *mp = vp->v_mount;
+			fstrans_start(mp);
+			if (vp->v_mount != mp) {
+fstrans_done(mp);
+ASSERT(!vn_has_cached_data(vp));
+return 0;
+			}
+		}
 		rl = zfs_range_lock(zp, offlo, len, RL_WRITER);
 		mutex_enter(vp->v_interlock);
 		tsd_set(zfs_putpage_key, );
 	}
 	error = genfs_putpages(v);
-	if (rl) {
+	if (cleaning) {
 		tsd_set(zfs_putpage_key, NULL);
 		zfs_range_unlock(rl);
-	}
 
-	/*
-	 * Only zil_commit() if we cleaned something.
-	 * This avoids deadlock if we're called from zfs_netbsd_setsize().
-	 */
+		/*
+		 * Only zil_commit() if we cleaned something.  This avoids 
+		 * deadlock if we're called from zfs_netbsd_setsize().
+		 */
 
-	if (cleaned)
-	if (!async || zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
-		zil_commit(zfsvfs->z_log, zp->z_id);
-	ZFS_EXIT(zfsvfs);
+		if (cleaned)
+		if (!async || zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
+			zil_commit(zfsvfs->z_log, zp->z_id);
+		fstrans_done(vp->v_mount);
+	}
 	return error;
 }
 



CVS commit: src/external/cddl/osnet/dist/uts/common/fs/zfs

2019-01-01 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Tue Jan  1 10:08:01 UTC 2019

Modified Files:
src/external/cddl/osnet/dist/uts/common/fs/zfs: zfs_ioctl.c
zfs_vfsops.c zfs_znode.c
src/external/cddl/osnet/dist/uts/common/fs/zfs/sys: zfs_znode.h

Log Message:
Cannot hold zfs object across call to vcache_get() as it might
deadlock with another reclaim.

Add vfs operation zfs_newvnode() to create a new zfs node and
hold the zfs object in zfs_loadvnode() and zfs_newvnode() only.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ioctl.c
cvs rdiff -u -r1.17 -r1.18 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vfsops.c
cvs rdiff -u -r1.23 -r1.24 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c
cvs rdiff -u -r1.8 -r1.9 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/sys/zfs_znode.h

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

Modified files:

Index: src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ioctl.c
diff -u src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ioctl.c:1.13 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ioctl.c:1.14
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ioctl.c:1.13	Mon Aug 20 06:47:16 2018
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ioctl.c	Tue Jan  1 10:08:01 2019
@@ -7120,7 +7120,6 @@ zfs_modcmd(modcmd_t cmd, void *arg)
 	uint64_t availrmem;
 
 	extern struct vfsops zfs_vfsops;
-	extern uint_t zfs_loadvnode_key;
 	extern uint_t zfs_putpage_key;
 
 	switch (cmd) {
@@ -7144,7 +7143,6 @@ zfs_modcmd(modcmd_t cmd, void *arg)
 		tsd_create(_fsyncer_key, NULL);
 		tsd_create(_tsd_key, rrw_tsd_destroy);
 		tsd_create(_allow_log_key, zfs_allow_log_destroy);
-		tsd_create(_loadvnode_key, zfs_loadvnode_destroy);
 		tsd_create(_putpage_key, NULL);
 
 		spa_init(FREAD | FWRITE);
@@ -7179,7 +7177,6 @@ attacherr:
 		spa_fini();
 
 		tsd_destroy(_putpage_key);
-		tsd_destroy(_loadvnode_key);
 		tsd_destroy(_fsyncer_key);
 		tsd_destroy(_tsd_key);
 		tsd_destroy(_allow_log_key);

Index: src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vfsops.c
diff -u src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vfsops.c:1.17 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vfsops.c:1.18
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vfsops.c:1.17	Sun Sep 16 06:09:01 2018
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vfsops.c	Tue Jan  1 10:08:01 2019
@@ -163,6 +163,7 @@ struct vfsops zfs_vfsops = {
 	.vfs_sync = zfs_netbsd_sync,
 	.vfs_vget = zfs_vget,
 	.vfs_loadvnode = zfs_loadvnode,
+	.vfs_newvnode = zfs_newvnode,
 	.vfs_init = zfs_init,
 	.vfs_done = zfs_fini,
 	.vfs_start = (void *)nullop,

Index: src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c
diff -u src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c:1.23 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c:1.24
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c:1.23	Thu Dec  6 09:58:52 2018
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c	Tue Jan  1 10:08:01 2019
@@ -60,15 +60,6 @@ extern int (**zfs_vnodeop_p)(void *);
 extern int (**zfs_fifoop_p)(void *);
 extern int (**zfs_specop_p)(void *);
 
-struct zfs_loadvnode_args {
-	dmu_buf_t		*db;
-	int			blksz;
-	dmu_object_type_t	obj_type;
-	void			*sa_hdl;
-};
-
-uint_t zfs_loadvnode_key;
-
 #endif
 #endif /* _KERNEL */
 
@@ -621,6 +612,7 @@ zfs_vnode_forget(vnode_t *vp)
 	vgone(vp);
 	vput(vp);
 }
+#endif /* __FreeBSD__ */
 
 /*
  * Construct a new znode/vnode and intialize.
@@ -630,11 +622,18 @@ zfs_vnode_forget(vnode_t *vp)
  * return the znode
  */
 static znode_t *
+#ifdef __NetBSD__
+zfs_znode_alloc(zfsvfs_t *zfsvfs, dmu_buf_t *db, int blksz,
+dmu_object_type_t obj_type, sa_handle_t *hdl, vnode_t *vp)
+#else
 zfs_znode_alloc(zfsvfs_t *zfsvfs, dmu_buf_t *db, int blksz,
 dmu_object_type_t obj_type, sa_handle_t *hdl)
+#endif
 {
 	znode_t	*zp;
+#ifndef __NetBSD__
 	vnode_t *vp;
+#endif
 	uint64_t mode;
 	uint64_t parent;
 	sa_bulk_attr_t bulk[9];
@@ -643,6 +642,7 @@ zfs_znode_alloc(zfsvfs_t *zfsvfs, dmu_bu
 
 	zp = kmem_cache_alloc(znode_cache, KM_SLEEP);
 
+#ifndef __NetBSD__
 	KASSERT(curthread->td_vp_reserv > 0,
 	("zfs_znode_alloc: getnewvnode without any vnodes reserved"));
 	error = getnewvnode("zfs", zfsvfs->z_parent->z_vfs, _vnodeops, );
@@ -650,6 +650,7 @@ zfs_znode_alloc(zfsvfs_t *zfsvfs, dmu_bu
 		kmem_cache_free(znode_cache, zp);
 		return (NULL);
 	}
+#endif
 	zp->z_vnode = vp;
 	vp->v_data = zp;
 
@@ -669,6 +670,12 @@ zfs_znode_alloc(zfsvfs_t *zfsvfs, dmu_bu
 	zp->z_seq = 0x7A4653;
 	zp->z_sync_cnt = 0;
 
+#ifdef __NetBSD__
+	vp->v_op = zfs_vnodeop_p;
+	vp->v_tag = VT_ZFS;
+	zp->z_lockf = NULL;
+#endif
+
 	vp = ZTOV(zp);
 
 	zfs_znode_sa_init(zfsvfs, zp, db, obj_type, hdl);
@@ -692,7 +699,9 @@ zfs_znode_alloc(zfsvfs_t *zfsvfs, dmu_bu
 	if (sa_bulk_lookup(zp->z_sa_hdl, bulk, 

CVS commit: src

2019-01-01 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Tue Jan  1 10:06:55 UTC 2019

Modified Files:
src/share/man/man9: vfsops.9 vnode.9
src/sys/fs/tmpfs: tmpfs_subr.c tmpfs_vfsops.c
src/sys/fs/udf: udf_subr.c
src/sys/kern: vfs_subr.c vfs_vnode.c
src/sys/miscfs/deadfs: dead_vfsops.c
src/sys/sys: mount.h param.h vnode.h
src/sys/ufs/ext2fs: ext2fs_vfsops.c ext2fs_vnops.c
src/sys/ufs/ffs: ffs_vfsops.c ffs_wapbl.c
src/sys/ufs/lfs: lfs_rfw.c lfs_vfsops.c lfs_vnops.c
src/sys/ufs/ufs: ufs_vnops.c

Log Message:
Add "void *extra" argument to vcache_new() so a file system may
pass more information about the file to create.

Welcome to 8.99.30


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/share/man/man9/vfsops.9
cvs rdiff -u -r1.81 -r1.82 src/share/man/man9/vnode.9
cvs rdiff -u -r1.103 -r1.104 src/sys/fs/tmpfs/tmpfs_subr.c
cvs rdiff -u -r1.73 -r1.74 src/sys/fs/tmpfs/tmpfs_vfsops.c
cvs rdiff -u -r1.144 -r1.145 src/sys/fs/udf/udf_subr.c
cvs rdiff -u -r1.470 -r1.471 src/sys/kern/vfs_subr.c
cvs rdiff -u -r1.100 -r1.101 src/sys/kern/vfs_vnode.c
cvs rdiff -u -r1.8 -r1.9 src/sys/miscfs/deadfs/dead_vfsops.c
cvs rdiff -u -r1.233 -r1.234 src/sys/sys/mount.h
cvs rdiff -u -r1.574 -r1.575 src/sys/sys/param.h
cvs rdiff -u -r1.280 -r1.281 src/sys/sys/vnode.h
cvs rdiff -u -r1.212 -r1.213 src/sys/ufs/ext2fs/ext2fs_vfsops.c
cvs rdiff -u -r1.128 -r1.129 src/sys/ufs/ext2fs/ext2fs_vnops.c
cvs rdiff -u -r1.360 -r1.361 src/sys/ufs/ffs/ffs_vfsops.c
cvs rdiff -u -r1.43 -r1.44 src/sys/ufs/ffs/ffs_wapbl.c
cvs rdiff -u -r1.33 -r1.34 src/sys/ufs/lfs/lfs_rfw.c
cvs rdiff -u -r1.363 -r1.364 src/sys/ufs/lfs/lfs_vfsops.c
cvs rdiff -u -r1.322 -r1.323 src/sys/ufs/lfs/lfs_vnops.c
cvs rdiff -u -r1.241 -r1.242 src/sys/ufs/ufs/ufs_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/share/man/man9/vfsops.9
diff -u src/share/man/man9/vfsops.9:1.48 src/share/man/man9/vfsops.9:1.49
--- src/share/man/man9/vfsops.9:1.48	Mon Jul  3 21:28:48 2017
+++ src/share/man/man9/vfsops.9	Tue Jan  1 10:06:54 2019
@@ -1,4 +1,4 @@
-.\" $NetBSD: vfsops.9,v 1.48 2017/07/03 21:28:48 wiz Exp $
+.\" $NetBSD: vfsops.9,v 1.49 2019/01/01 10:06:54 hannken Exp $
 .\"
 .\" Copyright (c) 2001 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 July 12, 2015
+.Dd January 1, 2019
 .Dt VFSOPS 9
 .Os
 .Sh NAME
@@ -72,7 +72,7 @@
 .Ft int
 .Fn VFS_LOADVNODE "struct mount *mp" "struct vnode *vp" "const void *key" "size_t key_len" "const void **new_key"
 .Ft int
-.Fn VFS_NEWVNODE "struct mount *mp" "struct vnode *dvp" "struct vnode *vp" "struct vattr *vap" "kauth_cred_t cred" "size_t *key_len" "const void **new_key"
+.Fn VFS_NEWVNODE "struct mount *mp" "struct vnode *dvp" "struct vnode *vp" "struct vattr *vap" "kauth_cred_t cred" "void *extra" "size_t *key_len" "const void **new_key"
 .Ft int
 .Fn VFS_FHTOVP "struct mount *mp" "struct fid *fhp" "struct vnode **vpp"
 .Ft int
@@ -378,6 +378,10 @@ The argument
 .Fa cred
 holds the credentials for the file to create.
 .Pp
+The argument
+.Fa extra
+allows the caller to pass more information about the file to create.
+.Pp
 The key for the file is returned in the addresses specified by
 .Fa key_len
 and

Index: src/share/man/man9/vnode.9
diff -u src/share/man/man9/vnode.9:1.81 src/share/man/man9/vnode.9:1.82
--- src/share/man/man9/vnode.9:1.81	Mon Jul  3 21:28:48 2017
+++ src/share/man/man9/vnode.9	Tue Jan  1 10:06:54 2019
@@ -1,4 +1,4 @@
-.\" $NetBSD: vnode.9,v 1.81 2017/07/03 21:28:48 wiz Exp $
+.\" $NetBSD: vnode.9,v 1.82 2019/01/01 10:06:54 hannken Exp $
 .\"
 .\" Copyright (c) 2001, 2005, 2006 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 May 28, 2017
+.Dd January 1, 2019
 .Dt VNODE 9
 .Os
 .Sh NAME
@@ -76,7 +76,7 @@
 .Ft int
 .Fn vcache_get "struct mount *mp" "const void *key" "size_t key_len" "struct vnode **vpp"
 .Ft int
-.Fn vcache_new "struct mount *mp" "struct vnode *dvp" "struct vattr *vap" "kauth_cred_t cred" "struct vnode **vpp"
+.Fn vcache_new "struct mount *mp" "struct vnode *dvp" "struct vattr *vap" "kauth_cred_t cred" "void *extra" "struct vnode **vpp"
 .Ft int
 .Fn vcache_rekey_enter "struct mount *mp" "struct vnode *vp" "const void *old_key" "size_t old_key_len" "const void *new_key" "size_t new_key_len"
 .Ft void
@@ -578,6 +578,10 @@ The argument
 .Fa cred
 holds the credentials for the file to create.
 .Pp
+The argument
+.Fa extra
+allows the caller to pass more information about the file to create.
+.Pp
 If a vnode is successfully created zero is returned, otherwise an
 appropriate error code is returned.
 .It Fn 

CVS commit: src/tests/fs

2018-12-16 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sun Dec 16 14:04:14 UTC 2018

Modified Files:
src/tests/fs/common: fstest_zfs.c
src/tests/fs/zfs: t_zpool.sh

Log Message:
Have to hijack sysctl() and modctl() for zfs commands.

Should fix PR kern/53422


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/fs/common/fstest_zfs.c
cvs rdiff -u -r1.3 -r1.4 src/tests/fs/zfs/t_zpool.sh

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

Modified files:

Index: src/tests/fs/common/fstest_zfs.c
diff -u src/tests/fs/common/fstest_zfs.c:1.1 src/tests/fs/common/fstest_zfs.c:1.2
--- src/tests/fs/common/fstest_zfs.c:1.1	Mon Aug 20 16:37:35 2012
+++ src/tests/fs/common/fstest_zfs.c	Sun Dec 16 14:04:14 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: fstest_zfs.c,v 1.1 2012/08/20 16:37:35 pooka Exp $	*/
+/*	$NetBSD: fstest_zfs.c,v 1.2 2018/12/16 14:04:14 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2010, 2011  The NetBSD Foundation, Inc.
@@ -104,8 +104,8 @@ zfs_fstest_mount(const atf_tc_t *tc, voi
 
 	/* set up the hijack env for running zpool */
 	setenv("RUMP_SERVER", SRVURL, 1);
-	snprintf(tmpbuf, sizeof(tmpbuf)-1, "blanket=/dev/zfs:%s:%s",
-	ZFSDEV, path);
+	snprintf(tmpbuf, sizeof(tmpbuf)-1,
+	"blanket=/dev/zfs:%s:%s,sysctl=yes,modctl=yes", ZFSDEV, path);
 	setenv("RUMPHIJACK", tmpbuf, 1);
 	setenv("LD_PRELOAD", "/usr/lib/librumphijack.so", 1);
 

Index: src/tests/fs/zfs/t_zpool.sh
diff -u src/tests/fs/zfs/t_zpool.sh:1.3 src/tests/fs/zfs/t_zpool.sh:1.4
--- src/tests/fs/zfs/t_zpool.sh:1.3	Tue Dec  6 18:18:59 2011
+++ src/tests/fs/zfs/t_zpool.sh	Sun Dec 16 14:04:14 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: t_zpool.sh,v 1.3 2011/12/06 18:18:59 njoly Exp $
+#	$NetBSD: t_zpool.sh,v 1.4 2018/12/16 14:04:14 hannken Exp $
 #
 # Copyright (c) 2011 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -46,7 +46,7 @@ create_body()
 	atf_check -s exit:0 -o ignore -e ignore ${server} ${RUMP_SERVER}
 
 	export LD_PRELOAD=/usr/lib/librumphijack.so
-	export RUMPHIJACK=blanket=/dev/zfs:/dk:/jippo
+	export RUMPHIJACK=blanket=/dev/zfs:/dk:/jippo,sysctl=yes,modctl=yes
 	atf_check -s exit:0 zpool create jippo /dk
 
 	export RUMPHIJACK=vfs=all



CVS commit: src/lib/librumphijack

2018-12-16 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sun Dec 16 14:03:37 UTC 2018

Modified Files:
src/lib/librumphijack: hijack.c rumphijack.3

Log Message:
Add an option "modctl" to capture modctl().


To generate a diff of this commit:
cvs rdiff -u -r1.125 -r1.126 src/lib/librumphijack/hijack.c
cvs rdiff -u -r1.12 -r1.13 src/lib/librumphijack/rumphijack.3

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

Modified files:

Index: src/lib/librumphijack/hijack.c
diff -u src/lib/librumphijack/hijack.c:1.125 src/lib/librumphijack/hijack.c:1.126
--- src/lib/librumphijack/hijack.c:1.125	Thu Jun 28 06:20:36 2018
+++ src/lib/librumphijack/hijack.c	Sun Dec 16 14:03:37 2018
@@ -1,4 +1,4 @@
-/*  $NetBSD: hijack.c,v 1.125 2018/06/28 06:20:36 ozaki-r Exp $	*/
+/*  $NetBSD: hijack.c,v 1.126 2018/12/16 14:03:37 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2011 Antti Kantee.  All Rights Reserved.
@@ -34,7 +34,7 @@
 #include 
 
 #if !defined(lint)
-__RCSID("$NetBSD: hijack.c,v 1.125 2018/06/28 06:20:36 ozaki-r Exp $");
+__RCSID("$NetBSD: hijack.c,v 1.126 2018/12/16 14:03:37 hannken Exp $");
 #endif
 
 #include 
@@ -138,6 +138,7 @@ enum dualcall {
 
 #ifdef __NetBSD__
 	DUALCALL___SYSCTL,
+	DUALCALL_MODCTL,
 #endif
 
 #ifdef __NetBSD__
@@ -351,6 +352,7 @@ struct sysnames {
 
 #ifdef __NetBSD__
 	{ DUALCALL___SYSCTL,	"__sysctl",	RSYS_NAME(__SYSCTL)	},
+	{ DUALCALL_MODCTL,	"modctl",	RSYS_NAME(MODCTL)	},
 #endif
 
 #ifdef __NetBSD__
@@ -814,6 +816,30 @@ sysctlparser(char *buf)
 	errx(1, "sysctl value should be y(es)/n(o), gave: %s", buf);
 }
 
+static bool rumpmodctl = false;
+
+static void
+modctlparser(char *buf)
+{
+
+	if (buf == NULL) {
+		rumpmodctl = true;
+		return;
+	}
+
+	if (strcasecmp(buf, "y") == 0 || strcasecmp(buf, "yes") == 0 ||
+	strcasecmp(buf, "yep") == 0 || strcasecmp(buf, "tottakai") == 0) {
+		rumpmodctl = true;
+		return;
+	}
+	if (strcasecmp(buf, "n") == 0 || strcasecmp(buf, "no") == 0) {
+		rumpmodctl = false;
+		return;
+	}
+
+	errx(1, "modctl value should be y(es)/n(o), gave: %s", buf);
+}
+
 static void
 fdoffparser(char *buf)
 {
@@ -841,6 +867,7 @@ static struct {
 	{ blanketparser, "blanket", true },
 	{ vfsparser, "vfs", true },
 	{ sysctlparser, "sysctl", false },
+	{ modctlparser, "modctl", false },
 	{ fdoffparser, "fdoff", true },
 	{ NULL, NULL, false },
 };
@@ -2334,6 +2361,20 @@ __sysctl(const int *name, unsigned int n
 
 	return op___sysctl(name, namelen, old, oldlenp, new, newlen);
 }
+int modctl(int, void *);
+int
+modctl(int operation, void *argp)
+{
+	int (*op_modctl)(int operation, void *argp);
+
+	if (rumpmodctl) {
+		op_modctl = GETSYSCALL(rump, MODCTL);
+	} else {
+		op_modctl = GETSYSCALL(host, MODCTL);
+	}
+
+	return op_modctl(operation, argp);
+}
 #endif
 
 /*

Index: src/lib/librumphijack/rumphijack.3
diff -u src/lib/librumphijack/rumphijack.3:1.12 src/lib/librumphijack/rumphijack.3:1.13
--- src/lib/librumphijack/rumphijack.3:1.12	Mon Mar 14 15:21:22 2011
+++ src/lib/librumphijack/rumphijack.3	Sun Dec 16 14:03:37 2018
@@ -1,4 +1,4 @@
-.\" $NetBSD: rumphijack.3,v 1.12 2011/03/14 15:21:22 pooka Exp $
+.\" $NetBSD: rumphijack.3,v 1.13 2018/12/16 14:03:37 hannken Exp $
 .\"
 .\" Copyright (c) 2011 Antti Kantee.  All rights reserved.
 .\"
@@ -23,7 +23,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd March 14, 2011
+.Dd December 16, 2018
 .Dt RUMPHIJACK 3
 .Os
 .Sh NAME
@@ -173,6 +173,15 @@ Acceptable values are
 and
 .Dq no ,
 meaning to call the rump or the host kernel, respectively.
+.It Dq modctl
+Direct the
+.Fn modctl
+call to the rump kernel.
+Acceptable values are
+.Dq yes
+and
+.Dq no ,
+meaning to call the rump or the host kernel, respectively.
 .It Dq fdoff
 Adjust the library's fd offset to the specified value.
 All rump kernel descriptors have the offset added to them



CVS commit: src/external/cddl/osnet/dist/uts/common/fs/zfs

2018-12-13 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Thu Dec 13 10:20:51 UTC 2018

Modified Files:
src/external/cddl/osnet/dist/uts/common/fs/zfs: zfs_vnops.c

Log Message:
Drop v_interlock for zfs_range_lock(), another thread might hold part
of this range and wait for v_interlock.


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_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/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c
diff -u src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.38 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.39
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.38	Thu Dec 13 10:20:20 2018
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c	Thu Dec 13 10:20:51 2018
@@ -5985,7 +5985,9 @@ zfs_netbsd_putpages(void *v)
 			len = UINT64_MAX;
 		else
 			len = offhi - offlo;
+		mutex_exit(vp->v_interlock);
 		rl = zfs_range_lock(zp, offlo, len, RL_WRITER);
+		mutex_enter(vp->v_interlock);
 		tsd_set(zfs_putpage_key, );
 	}
 	error = genfs_putpages(v);



CVS commit: src/external/cddl/osnet/dist/uts/common/fs/zfs

2018-12-13 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Thu Dec 13 10:20:20 UTC 2018

Modified Files:
src/external/cddl/osnet/dist/uts/common/fs/zfs: zfs_vnops.c

Log Message:
Operation zfs_range_lock() needs range as (offset,length), not as (low,high).


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_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/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c
diff -u src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.37 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.38
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.37	Thu Dec  6 10:00:40 2018
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c	Thu Dec 13 10:20:20 2018
@@ -5968,6 +5968,7 @@ zfs_netbsd_putpages(void *v)
 	znode_t *zp = VTOZ(vp);
 	zfsvfs_t *zfsvfs = zp->z_zfsvfs;
 	rl_t *rl = NULL;
+	uint64_t len;
 	int error;
 	bool cleaned = false;
 
@@ -5978,7 +5979,13 @@ zfs_netbsd_putpages(void *v)
 	ZFS_VERIFY_ZP(zp);
 
 	if (cleaning) {
-		rl = zfs_range_lock(zp, offlo, offhi, RL_WRITER);
+		ASSERT((offlo & PAGE_MASK) == 0 && (offhi & PAGE_MASK) == 0);
+		ASSERT(offlo < offhi || offhi == 0);
+		if (offhi == 0)
+			len = UINT64_MAX;
+		else
+			len = offhi - offlo;
+		rl = zfs_range_lock(zp, offlo, len, RL_WRITER);
 		tsd_set(zfs_putpage_key, );
 	}
 	error = genfs_putpages(v);



CVS commit: src/external/cddl/osnet/sys/kern

2018-12-13 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Thu Dec 13 10:19:47 UTC 2018

Modified Files:
src/external/cddl/osnet/sys/kern: mod.c

Log Message:
Don't allow module to init before mp_online.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/external/cddl/osnet/sys/kern/mod.c

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

Modified files:

Index: src/external/cddl/osnet/sys/kern/mod.c
diff -u src/external/cddl/osnet/sys/kern/mod.c:1.3 src/external/cddl/osnet/sys/kern/mod.c:1.4
--- src/external/cddl/osnet/sys/kern/mod.c:1.3	Mon May 28 21:05:09 2018
+++ src/external/cddl/osnet/sys/kern/mod.c	Thu Dec 13 10:19:47 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: mod.c,v 1.3 2018/05/28 21:05:09 chs Exp $	*/
+/*	$NetBSD: mod.c,v 1.4 2018/12/13 10:19:47 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mod.c,v 1.3 2018/05/28 21:05:09 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mod.c,v 1.4 2018/12/13 10:19:47 hannken Exp $");
 
 #include 
 #include 
@@ -49,6 +49,9 @@ solaris_modcmd(modcmd_t cmd, void *arg)
 
 	switch (cmd) {
 	case MODULE_CMD_INIT:
+		if (!mp_online)
+			return EAGAIN;
+
 		opensolaris_utsname_init();
 		callb_init(NULL);
 		taskq_init();



CVS commit: src/sys/dev

2018-12-10 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Mon Dec 10 15:22:35 UTC 2018

Modified Files:
src/sys/dev: vnd.c

Log Message:
Operation handle_with_strategy() also needs the
fstrans_start_lazy() / fstrans_done() bracket.

PR kern/53624 (dom0 freeze on domU exit)


To generate a diff of this commit:
cvs rdiff -u -r1.269 -r1.270 src/sys/dev/vnd.c

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

Modified files:

Index: src/sys/dev/vnd.c
diff -u src/sys/dev/vnd.c:1.269 src/sys/dev/vnd.c:1.270
--- src/sys/dev/vnd.c:1.269	Sun Oct  7 12:00:07 2018
+++ src/sys/dev/vnd.c	Mon Dec 10 15:22:35 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: vnd.c,v 1.269 2018/10/07 12:00:07 mlelstv Exp $	*/
+/*	$NetBSD: vnd.c,v 1.270 2018/12/10 15:22:35 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2008 The NetBSD Foundation, Inc.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vnd.c,v 1.269 2018/10/07 12:00:07 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vnd.c,v 1.270 2018/12/10 15:22:35 hannken Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_vnd.h"
@@ -733,12 +733,17 @@ vndthread(void *arg)
 		bp->b_bcount = obp->b_bcount;
 		BIO_COPYPRIO(bp, obp);
 
+		/* Make sure the request succeeds while suspending this fs. */
+		fstrans_start_lazy(vnd->sc_vp->v_mount);
+
 		/* Handle the request using the appropriate operations. */
 		if ((vnd->sc_flags & VNF_USE_VN_RDWR) == 0)
 			handle_with_strategy(vnd, obp, bp);
 		else
 			handle_with_rdwr(vnd, obp, bp);
 
+		fstrans_done(vnd->sc_vp->v_mount);
+
 		s = splbio();
 		continue;
 
@@ -804,9 +809,6 @@ 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,
@@ -828,8 +830,6 @@ handle_with_rdwr(struct vnd_softc *vnd, 
 	else
 		mutex_exit(vp->v_interlock);
 
-	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) {



CVS commit: src/external/cddl/osnet/dist/uts/common/fs/zfs

2018-12-06 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Thu Dec  6 10:00:40 UTC 2018

Modified Files:
src/external/cddl/osnet/dist/uts/common/fs/zfs: zfs_vnops.c

Log Message:
We have component names as counted strings (cn_nameptr, cn_namelen) but
ZFS expects a null-terminated name.

Always create a copy with PNBUF_GET()/strlcpy()/PNBUF_PUT().

For LOOKUP use a small buffer on stack and allocate/free compomnent names
longer than 30 chars.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_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/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c
diff -u src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.36 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.37
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.36	Fri Nov 30 09:53:40 2018
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c	Thu Dec  6 10:00:40 2018
@@ -3847,8 +3847,13 @@ zfs_rename_relock(struct vnode *sdvp, st
 	zfsvfs_t	*zfsvfs;
 	struct vnode	*nvp, *svp, *tvp;
 	znode_t		*sdzp, *tdzp, *szp, *tzp;
+#ifdef __FreeBSD__
 	const char	*snm = scnp->cn_nameptr;
 	const char	*tnm = tcnp->cn_nameptr;
+#endif
+#ifdef __NetBSD__
+	char *snm, *tnm;
+#endif
 	int error;
 
 #ifdef __FreeBSD__
@@ -3918,7 +3923,15 @@ relock:
 	 * Re-resolve svp to be certain it still exists and fetch the
 	 * correct vnode.
 	 */
+#ifdef __NetBSD__
+	/* ZFS wants a null-terminated name. */
+	snm = PNBUF_GET();
+	strlcpy(snm, scnp->cn_nameptr, scnp->cn_namelen + 1);
+#endif
 	error = zfs_dirent_lookup(sdzp, snm, , ZEXISTS);
+#ifdef __NetBSD__
+	PNBUF_PUT(snm);
+#endif
 	if (error != 0) {
 		/* Source entry invalid or not there. */
 		ZFS_EXIT(zfsvfs);
@@ -3937,7 +3950,15 @@ relock:
 	/*
 	 * Re-resolve tvp, if it disappeared we just carry on.
 	 */
+#ifdef __NetBSD__
+	/* ZFS wants a null-terminated name. */
+	tnm = PNBUF_GET();
+	strlcpy(tnm, tcnp->cn_nameptr, tcnp->cn_namelen + 1);
+#endif
 	error = zfs_dirent_lookup(tdzp, tnm, , 0);
+#ifdef __NetBSD__
+	PNBUF_PUT(tnm);
+#endif
 	if (error != 0) {
 		ZFS_EXIT(zfsvfs);
 		VOP_UNLOCK(sdvp, 0);
@@ -4138,8 +4159,13 @@ zfs_rename(vnode_t *sdvp, vnode_t **svpp
 	znode_t		*sdzp, *tdzp, *szp, *tzp;
 	zilog_t		*zilog = NULL;
 	dmu_tx_t	*tx;
+#ifdef __FreeBSD__
 	char		*snm = __UNCONST(scnp->cn_nameptr);
 	char		*tnm = __UNCONST(tcnp->cn_nameptr);
+#endif
+#ifdef __NetBSD__
+	char *snm, *tnm;
+#endif
 	int		error = 0;
 
 	/* Reject renames across filesystems. */
@@ -4167,6 +4193,13 @@ zfs_rename(vnode_t *sdvp, vnode_t **svpp
 	sdzp = VTOZ(sdvp);
 	zfsvfs = tdzp->z_zfsvfs;
 	zilog = zfsvfs->z_log;
+#ifdef __NetBSD__
+	/* ZFS wants a null-terminated name. */
+	snm = PNBUF_GET();
+	strlcpy(snm, scnp->cn_nameptr, scnp->cn_namelen + 1);
+	tnm = PNBUF_GET();
+	strlcpy(tnm, tcnp->cn_nameptr, tcnp->cn_namelen + 1);
+#endif
 
 	/*
 	 * After we re-enter ZFS_ENTER() we will have to revalidate all
@@ -4388,6 +4421,10 @@ unlockout:			/* all 4 vnodes are locked,
 
 	VOP_UNLOCK(*svpp, 0);
 	VOP_UNLOCK(sdvp, 0);
+#ifdef __NetBSD__
+	PNBUF_PUT(snm);
+	PNBUF_PUT(tnm);
+#endif
 
 	if (*tvpp != sdvp && *tvpp != *svpp)
 	if (*tvpp != NULL)
@@ -5060,12 +5097,11 @@ zfs_netbsd_lookup(void *v)
 	struct vnode *dvp = ap->a_dvp;
 	struct vnode **vpp = ap->a_vpp;
 	struct componentname *cnp = ap->a_cnp;
-	char nm[NAME_MAX + 1];
+	char *nm, short_nm[31];
 	int error;
 	int iswhiteout;
 
 	KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE);
-	KASSERT(cnp->cn_namelen < sizeof nm);
 
 	*vpp = NULL;
 
@@ -5095,11 +5131,19 @@ zfs_netbsd_lookup(void *v)
 	 * zfs_lookup wants a null-terminated component name, but namei
 	 * gives us a pointer into the full pathname.
 	 */
+	ASSERT(cnp->cn_namelen < PATH_MAX - 1);
+	if (cnp->cn_namelen + 1 > sizeof(short_nm))
+		nm = PNBUF_GET();
+	else
+		nm = short_nm;
 	(void)strlcpy(nm, cnp->cn_nameptr, cnp->cn_namelen + 1);
 
 	error = zfs_lookup(dvp, nm, vpp, NULL, 0, NULL, cnp->cn_cred, NULL,
 	NULL, NULL);
 
+	if (nm != short_nm)
+		PNBUF_PUT(nm);
+
 	/*
 	 * Translate errors to match our namei insanity.  Also, if the
 	 * caller wants to create an entry here, it's apparently our
@@ -5174,6 +5218,7 @@ zfs_netbsd_create(void *v)
 	struct vnode **vpp = ap->a_vpp;
 	struct componentname *cnp = ap->a_cnp;
 	struct vattr *vap = ap->a_vap;
+	char *nm;
 	int mode;
 	int error;
 
@@ -5182,9 +5227,14 @@ zfs_netbsd_create(void *v)
 	vattr_init_mask(vap);
 	mode = vap->va_mode & ALLPERMS;
 
+	/* ZFS wants a null-terminated name. */
+	nm = PNBUF_GET();
+	(void)strlcpy(nm, cnp->cn_nameptr, cnp->cn_namelen + 1);
+
 	/* XXX !EXCL is wrong here...  */
-	error = zfs_create(dvp, __UNCONST(cnp->cn_nameptr), vap, !EXCL, mode,
-	vpp, cnp->cn_cred, NULL);
+	error = zfs_create(dvp, nm, vap, !EXCL, mode, vpp, cnp->cn_cred, NULL);
+
+	PNBUF_PUT(nm);
 
 	KASSERT((error == 0) == (*vpp 

CVS commit: src/external/cddl/osnet/dist/uts/common/fs/zfs

2018-12-06 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Thu Dec  6 09:58:52 UTC 2018

Modified Files:
src/external/cddl/osnet/dist/uts/common/fs/zfs: zfs_znode.c

Log Message:
Add missing ZFS_OBJ_HOLD_ENTER() / ZFS_OBJ_HOLD_EXIT() to zfs_zget_cleaner().


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c

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

Modified files:

Index: src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c
diff -u src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c:1.22 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c:1.23
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c:1.22	Wed Nov 28 09:55:36 2018
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c	Thu Dec  6 09:58:52 2018
@@ -1188,8 +1188,11 @@ zfs_zget_cleaner(zfsvfs_t *zfsvfs, uint6
 	znode_t *zp;
 	int err;
 
+	ZFS_OBJ_HOLD_ENTER(zfsvfs, obj_num);
+
 	err = sa_buf_hold(zfsvfs->z_os, obj_num, NULL, );
 	if (err) {
+		ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
 		return (SET_ERROR(err));
 	}
 
@@ -1199,12 +1202,15 @@ zfs_zget_cleaner(zfsvfs_t *zfsvfs, uint6
 	(doi.doi_bonus_type == DMU_OT_ZNODE &&
 	doi.doi_bonus_size < sizeof (znode_phys_t {
 		sa_buf_rele(db, NULL);
+		ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
 		return (SET_ERROR(EINVAL));
 	}
 	hdl = dmu_buf_get_user(db);
-	KASSERT(hdl != NULL);
+	ASSERT3P(hdl, !=, NULL);
 	zp = sa_get_userdata(hdl);
+	ASSERT3U(zp->z_id, ==, obj_num);
 	sa_buf_rele(db, NULL);
+	ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
 	*zpp = zp;
 	return (0);
 }



CVS commit: src/external/cddl/osnet

2018-11-30 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Fri Nov 30 09:53:41 UTC 2018

Modified Files:
src/external/cddl/osnet/dist/uts/common/fs/zfs: zfs_vnops.c
src/external/cddl/osnet/sys/sys: uio.h

Log Message:
Zfs_write() may hide write errors if uiomove() succeeds but a
further dmu_tx_assign() fails because over quota or no space.

Use the emulated uiocopy() and uioskip() like illumos does.

Fix the uiocopy() emulation to not clobber the iovecs.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c
cvs rdiff -u -r1.11 -r1.12 src/external/cddl/osnet/sys/sys/uio.h

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

Modified files:

Index: src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c
diff -u src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.35 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.36
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.35	Wed Nov 28 10:01:28 2018
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c	Fri Nov 30 09:53:40 2018
@@ -1182,7 +1182,7 @@ zfs_write(vnode_t *vp, uio_t *uio, int i
 			 * holding up the transaction if the data copy hangs
 			 * up on a pagefault (e.g., from an NFS server mapping).
 			 */
-#ifdef illumos
+#if defined(illumos) || defined(__NetBSD__)
 			size_t cbytes;
 #endif
 
@@ -1190,7 +1190,7 @@ zfs_write(vnode_t *vp, uio_t *uio, int i
 			max_blksz);
 			ASSERT(abuf != NULL);
 			ASSERT(arc_buf_size(abuf) == max_blksz);
-#ifdef illumos
+#if defined(illumos) || defined(__NetBSD__)
 			if (error = uiocopy(abuf->b_data, max_blksz,
 			UIO_WRITE, uio, )) {
 dmu_return_arcbuf(abuf);
@@ -1209,17 +1209,6 @@ zfs_write(vnode_t *vp, uio_t *uio, int i
 break;
 			}
 #endif
-#ifdef __NetBSD__
-			ssize_t resid = uio->uio_resid;
-
-			error = uiomove(abuf->b_data, max_blksz, UIO_WRITE, uio);
-			if (error != 0) {
-uio->uio_offset -= resid - uio->uio_resid;
-uio->uio_resid = resid;
-dmu_return_arcbuf(abuf);
-break;
-			}
-#endif
 		}
 
 		/*
@@ -1297,7 +1286,7 @@ zfs_write(vnode_t *vp, uio_t *uio, int i
 dmu_assign_arcbuf(sa_get_db(zp->z_sa_hdl),
 woff, abuf, tx);
 			}
-#ifdef illumos
+#if defined(illumos) || defined(__NetBSD__)
 			ASSERT(tx_bytes <= uio->uio_resid);
 			uioskip(uio, tx_bytes);
 #endif

Index: src/external/cddl/osnet/sys/sys/uio.h
diff -u src/external/cddl/osnet/sys/sys/uio.h:1.11 src/external/cddl/osnet/sys/sys/uio.h:1.12
--- src/external/cddl/osnet/sys/sys/uio.h:1.11	Mon May 28 21:05:10 2018
+++ src/external/cddl/osnet/sys/sys/uio.h	Fri Nov 30 09:53:40 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: uio.h,v 1.11 2018/05/28 21:05:10 chs Exp $	*/
+/*	$NetBSD: uio.h,v 1.12 2018/11/30 09:53:40 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -107,24 +107,36 @@ zfs_uiomove(void *cp, size_t n, enum uio
 	return (uiomove(cp, n, uio));
 }
 
+#define	ZFS_MIN(a,b)	((/*CONSTCOND*/(a)<(b))?(a):(b))
+
 static __inline int
 zfs_uiocopy(void *cp, size_t n, enum uio_rw dir, uio_t *uio, size_t *cbytes)
 {
-	uio_t uio2;
-	int err;
-	
-	memcpy(, uio, sizeof(*uio));
-	assert(uio->uio_rw == dir);
-	if ((err = uiomove(cp, n, )) != 0)
-		return err;
-
-	*cbytes = (size_t)(uio->uio_resid - uio2.uio_resid);
+	uio_t auio;
+	struct iovec aiov;
+	size_t cnt;
+	int i, error;
+
+	*cbytes = 0;
+	memcpy(, uio, sizeof(*uio));
+	for (i = 0; i < uio->uio_iovcnt && n > 0; i++) {
+		auio.uio_iov = 
+		auio.uio_iovcnt = 1;
+		aiov = uio->uio_iov[i];
+		cnt = ZFS_MIN(aiov.iov_len, n);
+		if (cnt == 0)
+			continue;
+		error = uiomove(cp, cnt, );
+		if (error)
+			return error;
+		cp = (char *)cp + cnt;
+		n -= cnt;
+		*cbytes += cnt;
+	}
 
-	return (0);
+	return 0;
 }
 
-#define	ZFS_MIN(a,b)	((/*CONSTCOND*/(a)<(b))?(a):(b))
-
 static __inline void
 zfs_uioskip(uio_t *uiop, size_t n)
 {



CVS commit: src/tests/fs/vfs

2018-11-30 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Fri Nov 30 09:52:39 UTC 2018

Modified Files:
src/tests/fs/vfs: t_full.c

Log Message:
Skip zfs, it does not GOP_ALLOC.

PR kern/47656 test zfs_fillfs.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/tests/fs/vfs/t_full.c

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

Modified files:

Index: src/tests/fs/vfs/t_full.c
diff -u src/tests/fs/vfs/t_full.c:1.9 src/tests/fs/vfs/t_full.c:1.10
--- src/tests/fs/vfs/t_full.c:1.9	Fri Jan 13 21:30:40 2017
+++ src/tests/fs/vfs/t_full.c	Fri Nov 30 09:52:39 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_full.c,v 1.9 2017/01/13 21:30:40 christos Exp $	*/
+/*	$NetBSD: t_full.c,v 1.10 2018/11/30 09:52:39 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -56,7 +56,8 @@ fillfs(const atf_tc_t *tc, const char *m
 	size_t bonus;
 	int fd, i = 0;
 
-	if (FSTYPE_P2K_FFS(tc) || FSTYPE_PUFFS(tc) || FSTYPE_RUMPFS(tc)) {
+	if (FSTYPE_P2K_FFS(tc) || FSTYPE_PUFFS(tc) || FSTYPE_RUMPFS(tc) ||
+	FSTYPE_ZFS(tc)) {
 		atf_tc_skip("fs does not support explicit block allocation "
 		"(GOP_ALLOC)");
 	}
@@ -77,8 +78,6 @@ fillfs(const atf_tc_t *tc, const char *m
 		if (n == -1)
 			break;
 	}
-	if (FSTYPE_ZFS(tc))
-		atf_tc_expect_fail("PR kern/47656: Test known to be broken");
 	if (n == -1) {
 		if (errno != ENOSPC)
 			atf_tc_fail_errno("write");



CVS commit: src

2018-11-28 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed Nov 28 10:01:28 UTC 2018

Modified Files:
src/external/cddl/osnet/dist/uts/common/fs/zfs: zfs_vnops.c
src/tests/fs/vfs: t_unpriv.c

Log Message:
Redo the access check for setting va_flags in zfs_netbsd_setattr().

Use user flag UF_NODUMP instead of UF_IMMUTABLE for the test as it
is the only user flag supported by all tested file systems.

PR kern/47656 test zfs_flags.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c
cvs rdiff -u -r1.15 -r1.16 src/tests/fs/vfs/t_unpriv.c

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

Modified files:

Index: src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c
diff -u src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.34 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.35
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.34	Wed Nov 28 09:58:58 2018
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c	Wed Nov 28 10:01:28 2018
@@ -5345,9 +5345,11 @@ zfs_netbsd_setattr(void *v)
 	cred_t *cred = ap->a_cred;
 	znode_t *zp = VTOZ(vp);
 	xvattr_t xvap;
-	u_long fflags;
+	kauth_action_t action;
+	u_long fflags, sfflags = 0;
 	uint64_t zflags;
 	int error, flags = 0;
+	bool changing_sysflags;
 
 	vattr_init_mask(vap);
 	vap->va_mask &= ~AT_NOSET;
@@ -5365,40 +5367,14 @@ zfs_netbsd_setattr(void *v)
 		fflags = vap->va_flags;
 		if ((fflags & ~(SF_IMMUTABLE|SF_APPEND|SF_NOUNLINK|UF_NODUMP)) != 0)
 			return (EOPNOTSUPP);
-		/*
-		 * Callers may only modify the file flags on objects they
-		 * have VADMIN rights for.
-		 */
-		if ((error = VOP_ACCESS(vp, VWRITE, cred)) != 0)
-			return (error);
-		/*
-		 * Unprivileged processes are not permitted to unset system
-		 * flags, or modify flags if any system flags are set.
-		 * Privileged non-jail processes may not modify system flags
-		 * if securelevel > 0 and any existing system flags are set.
-		 * Privileged jail processes behave like privileged non-jail
-		 * processes if the security.jail.chflags_allowed sysctl is
-		 * is non-zero; otherwise, they behave like unprivileged
-		 * processes.
-		 */
-		if (kauth_authorize_system(cred, KAUTH_SYSTEM_CHSYSFLAGS, 0,
-			NULL, NULL, NULL) != 0) {
-
-			if (zflags &
-			(ZFS_IMMUTABLE | ZFS_APPENDONLY | ZFS_NOUNLINK)) {
-return (EPERM);
-			}
-			if (fflags &
-			(SF_IMMUTABLE | SF_APPEND | SF_NOUNLINK)) {
-return (EPERM);
-			}
-		}
 
 #define	FLAG_CHANGE(fflag, zflag, xflag, xfield)	do {		\
 	if (((fflags & (fflag)) && !(zflags & (zflag))) ||		\
 	((zflags & (zflag)) && !(fflags & (fflag {		\
 		XVA_SET_REQ(, (xflag));\
 		(xfield) = ((fflags & (fflag)) != 0);			\
+		if (((fflag) & SF_SETTABLE) != 0)			\
+			sfflags |= (fflag);\
 	}\
 } while (0)
 		/* Convert chflags into ZFS-type flags. */
@@ -5412,6 +5388,23 @@ zfs_netbsd_setattr(void *v)
 		FLAG_CHANGE(UF_NODUMP, ZFS_NODUMP, XAT_NODUMP,
 		xvap.xva_xoptattrs.xoa_nodump);
 #undef	FLAG_CHANGE
+
+		action = KAUTH_VNODE_WRITE_FLAGS;
+		changing_sysflags = false;
+
+		if (zflags & (ZFS_IMMUTABLE|ZFS_APPENDONLY|ZFS_NOUNLINK)) {
+			action |= KAUTH_VNODE_HAS_SYSFLAGS;
+		}
+		if (sfflags != 0) {
+			action |= KAUTH_VNODE_WRITE_SYSFLAGS;
+			changing_sysflags = true;
+		}
+
+		error = kauth_authorize_vnode(cred, action, vp, NULL,
+		genfs_can_chflags(cred, vp->v_type, zp->z_uid,
+		changing_sysflags));
+		if (error)
+			return error;
 	}
 
 	if (vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL ||

Index: src/tests/fs/vfs/t_unpriv.c
diff -u src/tests/fs/vfs/t_unpriv.c:1.15 src/tests/fs/vfs/t_unpriv.c:1.16
--- src/tests/fs/vfs/t_unpriv.c:1.15	Wed Nov 28 09:58:58 2018
+++ src/tests/fs/vfs/t_unpriv.c	Wed Nov 28 10:01:28 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_unpriv.c,v 1.15 2018/11/28 09:58:58 hannken Exp $	*/
+/*	$NetBSD: t_unpriv.c,v 1.16 2018/11/28 10:01:28 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -187,20 +187,18 @@ flags(const atf_tc_t *tc, const char *mp
 
 	if (rump_sys_stat(name, ) == -1)
 		atf_tc_fail_errno("stat");
-	if (FSTYPE_ZFS(tc))
-		atf_tc_expect_fail("PR kern/47656: Test known to be broken");
 	if (rump_sys_chflags(name, st.st_flags) == -1) {
 		if (errno == EOPNOTSUPP)
 			atf_tc_skip("file flags not supported by file system");
 		atf_tc_fail_errno("chflags");
 	}
 
-	fflags = st.st_flags | UF_IMMUTABLE;
+	fflags = st.st_flags | UF_NODUMP;
 
 	rump_pub_lwproc_rfork(RUMP_RFCFDG);
 	if (rump_sys_setuid(1) == -1)
 		atf_tc_fail_errno("setuid");
-	fflags |= UF_IMMUTABLE;
+	fflags |= UF_NODUMP;
 	if (rump_sys_chflags(name, fflags) != -1 || errno != EPERM)
 		atf_tc_fail_errno("chflags");
 	rump_pub_lwproc_releaselwp();
@@ -208,7 +206,7 @@ flags(const atf_tc_t *tc, const char *mp
 	if (rump_sys_chflags(name, fflags) == -1)
 		atf_tc_fail_errno("chflags");
 

CVS commit: src

2018-11-28 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed Nov 28 09:58:58 UTC 2018

Modified Files:
src/external/cddl/osnet/dist/uts/common/fs/zfs: zfs_vnops.c
src/tests/fs/vfs: t_unpriv.c

Log Message:
Add missing access check for REMOVE into zfs_netbsd_lookup().

PR kern/47656 test zfs_dirperms.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c
cvs rdiff -u -r1.14 -r1.15 src/tests/fs/vfs/t_unpriv.c

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

Modified files:

Index: src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c
diff -u src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.33 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.34
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.33	Wed Nov 28 09:57:59 2018
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c	Wed Nov 28 09:58:58 2018
@@ -5128,8 +5128,15 @@ zfs_netbsd_lookup(void *v)
 error = EJUSTRETURN;
 break;
 			}
-			/* FALLTHROUGH */
+			break;
 		case DELETE:
+			if (error == 0) {
+error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred);
+if (error) {
+	VN_RELE(*vpp);
+	*vpp = NULL;
+}
+			}
 			break;
 		}
 	}

Index: src/tests/fs/vfs/t_unpriv.c
diff -u src/tests/fs/vfs/t_unpriv.c:1.14 src/tests/fs/vfs/t_unpriv.c:1.15
--- src/tests/fs/vfs/t_unpriv.c:1.14	Wed Nov 28 09:57:59 2018
+++ src/tests/fs/vfs/t_unpriv.c	Wed Nov 28 09:58:58 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_unpriv.c,v 1.14 2018/11/28 09:57:59 hannken Exp $	*/
+/*	$NetBSD: t_unpriv.c,v 1.15 2018/11/28 09:58:58 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -94,8 +94,6 @@ dirperms(const atf_tc_t *tc, const char 
 	rump_pub_lwproc_rfork(RUMP_RFCFDG);
 	if (rump_sys_setuid(1) == -1)
 		atf_tc_fail_errno("setuid");
-	if (FSTYPE_ZFS(tc))
-		atf_tc_expect_fail("PR kern/47656: Test known to be broken");
 if (rump_sys_open(name, O_RDWR|O_CREAT, 0666) != -1 || errno != EACCES)
 		atf_tc_fail_errno("open");
 	rump_pub_lwproc_releaselwp();



CVS commit: src

2018-11-28 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed Nov 28 09:57:59 UTC 2018

Modified Files:
src/external/cddl/osnet/dist/uts/common/fs/zfs: zfs_vnops.c
src/tests/fs/vfs: t_unpriv.c

Log Message:
Add missing access check for setting va_Xtime into zfs_netbsd_setattr().

PR kern/47656 test zfs_times.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c
cvs rdiff -u -r1.13 -r1.14 src/tests/fs/vfs/t_unpriv.c

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

Modified files:

Index: src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c
diff -u src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.32 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.33
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.32	Wed Nov 28 09:57:16 2018
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c	Wed Nov 28 09:57:59 2018
@@ -5336,10 +5336,11 @@ zfs_netbsd_setattr(void *v)
 	vnode_t *vp = ap->a_vp;
 	vattr_t *vap = ap->a_vap;
 	cred_t *cred = ap->a_cred;
+	znode_t *zp = VTOZ(vp);
 	xvattr_t xvap;
 	u_long fflags;
 	uint64_t zflags;
-	int flags = 0;
+	int error, flags = 0;
 
 	vattr_init_mask(vap);
 	vap->va_mask &= ~AT_NOSET;
@@ -5405,6 +5406,16 @@ zfs_netbsd_setattr(void *v)
 		xvap.xva_xoptattrs.xoa_nodump);
 #undef	FLAG_CHANGE
 	}
+
+	if (vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL ||
+	vap->va_birthtime.tv_sec != VNOVAL) {
+		error = kauth_authorize_vnode(cred, KAUTH_VNODE_WRITE_TIMES, vp,
+		 NULL, genfs_can_chtimes(vp, vap->va_vaflags, zp->z_uid,
+		 cred));
+		if (error)
+			return error;
+	}
+
 	return (zfs_setattr(vp, (vattr_t *), flags, cred, NULL));
 }
 

Index: src/tests/fs/vfs/t_unpriv.c
diff -u src/tests/fs/vfs/t_unpriv.c:1.13 src/tests/fs/vfs/t_unpriv.c:1.14
--- src/tests/fs/vfs/t_unpriv.c:1.13	Fri Jan 13 21:30:40 2017
+++ src/tests/fs/vfs/t_unpriv.c	Wed Nov 28 09:57:59 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_unpriv.c,v 1.13 2017/01/13 21:30:40 christos Exp $	*/
+/*	$NetBSD: t_unpriv.c,v 1.14 2018/11/28 09:57:59 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -144,8 +144,6 @@ times(const atf_tc_t *tc, const char *mp
 	rump_pub_lwproc_rfork(RUMP_RFCFDG);
 	if (rump_sys_setuid(1) == -1)
 		atf_tc_fail_errno("setuid");
-	if (FSTYPE_ZFS(tc))
-		atf_tc_expect_fail("PR kern/47656: Test known to be broken");
 	if (rump_sys_utimes(name, NULL) != -1 || errno != EACCES)
 		atf_tc_fail_errno("utimes");
 	rump_pub_lwproc_releaselwp();



CVS commit: src/external/cddl/osnet/dist/uts/common/fs/zfs

2018-11-28 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed Nov 28 09:57:16 UTC 2018

Modified Files:
src/external/cddl/osnet/dist/uts/common/fs/zfs: zfs_vnops.c

Log Message:
We expect VOP_ACCESS() to return EACCESS as general error.

Change zfs_netbsd_access() to translate the common EPERM to EACCES.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_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/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c
diff -u src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.31 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.32
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.31	Wed Nov 28 09:56:40 2018
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c	Wed Nov 28 09:57:16 2018
@@ -5053,6 +5053,10 @@ zfs_netbsd_access(void *v)
 	KASSERT(VOP_ISLOCKED(vp));
 	error = zfs_access(vp, zfs_mode, 0, cred, NULL);
 
+	/* We expect EACCES as common error. */
+	if (error == EPERM)
+		error = EACCES;
+
 	return (error);
 }
 



CVS commit: src/external/cddl/osnet/dist/uts/common/fs/zfs

2018-11-28 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed Nov 28 09:56:40 UTC 2018

Modified Files:
src/external/cddl/osnet/dist/uts/common/fs/zfs: zfs_vnops.c

Log Message:
Don't try to release a NULL vnode in zfs_netbsd_rename().


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_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/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c
diff -u src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.30 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.31
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.30	Wed Nov 28 09:56:09 2018
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c	Wed Nov 28 09:56:40 2018
@@ -5467,7 +5467,8 @@ zfs_netbsd_rename(void *v)
 
 	VN_RELE(fdvp);
 	VN_RELE(tdvp);
-	VN_RELE(fvp);
+	if (fvp != NULL)
+		VN_RELE(fvp);
 	if (tvp != NULL)
 		VN_RELE(tvp);
 



CVS commit: src/external/cddl/osnet/dist/uts/common/fs/zfs

2018-11-28 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed Nov 28 09:56:09 UTC 2018

Modified Files:
src/external/cddl/osnet/dist/uts/common/fs/zfs: zfs_vnops.c

Log Message:
Remove an early test for "source and target are equal" from zfs_rename()
that broke BSD semantics.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_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/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c
diff -u src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.29 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.30
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.29	Wed Nov 28 09:55:06 2018
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c	Wed Nov 28 09:56:09 2018
@@ -4191,11 +4191,13 @@ zfs_rename(vnode_t *sdvp, vnode_t **svpp
 		goto unlockout;
 	}
 
+#ifndef __NetBSD__
 	/* If source and target are the same file, there is nothing to do. */
 	if ((*svpp) == (*tvpp)) {
 		error = 0;
 		goto unlockout;
 	}
+#endif
 
 	if (((*svpp)->v_type == VDIR && (*svpp)->v_mountedhere != NULL) ||
 	((*tvpp) != NULL && (*tvpp)->v_type == VDIR &&



CVS commit: src/external/cddl/osnet/dist/uts/common/fs/zfs

2018-11-28 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed Nov 28 09:55:36 UTC 2018

Modified Files:
src/external/cddl/osnet/dist/uts/common/fs/zfs: zfs_znode.c

Log Message:
Add missing sa_buf_rele() into zfs_zget_cleaner().


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c

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

Modified files:

Index: src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c
diff -u src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c:1.21 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c:1.22
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c:1.21	Tue Jul 31 09:33:50 2018
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c	Wed Nov 28 09:55:36 2018
@@ -1204,6 +1204,7 @@ zfs_zget_cleaner(zfsvfs_t *zfsvfs, uint6
 	hdl = dmu_buf_get_user(db);
 	KASSERT(hdl != NULL);
 	zp = sa_get_userdata(hdl);
+	sa_buf_rele(db, NULL);
 	*zpp = zp;
 	return (0);
 }



CVS commit: src/external/cddl/osnet/dist/uts/common/fs/zfs

2018-11-28 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed Nov 28 09:55:06 UTC 2018

Modified Files:
src/external/cddl/osnet/dist/uts/common/fs/zfs: zfs_vnops.c

Log Message:
Always unbusy pages in zfs_putapage() after the data has been written
into the DMU.  Running fsx no longer hangs the kernel.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_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/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c
diff -u src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.28 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.29
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.28	Thu Nov 15 04:55:49 2018
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c	Wed Nov 28 09:55:06 2018
@@ -5826,13 +5826,11 @@ zfs_putapage(vnode_t *vp, page_t **pp, i
 	}
 	dmu_tx_commit(tx);
 
-	if (async) {
-		mutex_enter(mtx);
-		mutex_enter(_pageqlock);
-		uvm_page_unbusy(pp, count);
-		mutex_exit(_pageqlock);
-		mutex_exit(mtx);
-	}
+	mutex_enter(mtx);
+	mutex_enter(_pageqlock);
+	uvm_page_unbusy(pp, count);
+	mutex_exit(_pageqlock);
+	mutex_exit(mtx);
 
 out:
 	return (err);



CVS commit: src/external/bsd/nsd/dist

2018-11-20 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Tue Nov 20 10:03:39 UTC 2018

Modified Files:
src/external/bsd/nsd/dist: server.c

Log Message:
Fix NSD when built with --enable-recvmmsg:

When resetting a query with query_reset(queries[i], ...) always restore the
corresponding msgs[i].msg_hdr.msg_namelen from queries[i]->addrlen.

After receiving a message set queries[i]->addrlen to the received msg_namelen.

Reported upstream, will be fixed for 4.1.26


To generate a diff of this commit:
cvs rdiff -u -r1.1.1.3 -r1.2 src/external/bsd/nsd/dist/server.c

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

Modified files:

Index: src/external/bsd/nsd/dist/server.c
diff -u src/external/bsd/nsd/dist/server.c:1.1.1.3 src/external/bsd/nsd/dist/server.c:1.2
--- src/external/bsd/nsd/dist/server.c:1.1.1.3	Mon Sep  3 11:29:15 2018
+++ src/external/bsd/nsd/dist/server.c	Tue Nov 20 10:03:39 2018
@@ -2209,6 +2209,7 @@ handle_udp(int fd, short event, void* ar
 	for (i = 0; i < recvcount; i++) {
 	loopstart:
 		received = msgs[i].msg_len;
+		queries[i]->addrlen = msgs[i].msg_hdr.msg_namelen;
 		q = queries[i];
 		if (received == -1) {
 			log_msg(LOG_ERR, "recvmmsg %d failed %s", i, strerror(
@@ -2217,6 +2218,7 @@ handle_udp(int fd, short event, void* ar
 			/* No zone statup */
 			query_reset(queries[i], UDP_MAX_MESSAGE_LEN, 0);
 			iovecs[i].iov_len = buffer_remaining(q->packet);
+			msgs[i].msg_hdr.msg_namelen = queries[i]->addrlen;
 			goto swap_drop;
 		}
 
@@ -2264,6 +2266,7 @@ handle_udp(int fd, short event, void* ar
 		} else {
 			query_reset(queries[i], UDP_MAX_MESSAGE_LEN, 0);
 			iovecs[i].iov_len = buffer_remaining(q->packet);
+			msgs[i].msg_hdr.msg_namelen = queries[i]->addrlen;
 		swap_drop:
 			STATUP(data->nsd, dropped);
 			ZTATUP(data->nsd, q->zone, dropped);
@@ -2304,6 +2307,7 @@ handle_udp(int fd, short event, void* ar
 	for(i=0; ipacket);
+		msgs[i].msg_hdr.msg_namelen = queries[i]->addrlen;
 	}
 }
 
@@ -2344,13 +2348,15 @@ handle_udp(int fd, short event, void* ar
 	}
 	for (i = 0; i < recvcount; i++) {
 		received = msgs[i].msg_len;
-		msgs[i].msg_hdr.msg_namelen = queries[i]->addrlen;
+		queries[i]->addrlen = msgs[i].msg_hdr.msg_namelen;
 		if (received == -1) {
 			log_msg(LOG_ERR, "recvmmsg failed");
 			STATUP(data->nsd, rxerr);
 			/* No zone statup */
 			/* the error can be found in msgs[i].msg_hdr.msg_flags */
 			query_reset(queries[i], UDP_MAX_MESSAGE_LEN, 0);
+			iovecs[i].iov_len = buffer_remaining(queries[i]->packet);
+			msgs[i].msg_hdr.msg_namelen = queries[i]->addrlen;
 			continue;
 		}
 		q = queries[i];
@@ -2442,6 +2448,8 @@ handle_udp(int fd, short event, void* ar
 #ifndef NONBLOCKING_IS_BROKEN
 #ifdef HAVE_RECVMMSG
 		query_reset(queries[i], UDP_MAX_MESSAGE_LEN, 0);
+		iovecs[i].iov_len = buffer_remaining(queries[i]->packet);
+		msgs[i].msg_hdr.msg_namelen = queries[i]->addrlen;
 #endif
 	}
 #endif



CVS commit: src/sys/compat

2018-11-14 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed Nov 14 17:51:37 UTC 2018

Modified Files:
src/sys/compat/linux/common: linux_socket.c
src/sys/compat/netbsd32: netbsd32_socket.c

Log Message:
Apply the recent fixes to {send,recv}mmsg() to their compat variants.


To generate a diff of this commit:
cvs rdiff -u -r1.142 -r1.143 src/sys/compat/linux/common/linux_socket.c
cvs rdiff -u -r1.48 -r1.49 src/sys/compat/netbsd32/netbsd32_socket.c

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

Modified files:

Index: src/sys/compat/linux/common/linux_socket.c
diff -u src/sys/compat/linux/common/linux_socket.c:1.142 src/sys/compat/linux/common/linux_socket.c:1.143
--- src/sys/compat/linux/common/linux_socket.c:1.142	Thu May 10 01:32:24 2018
+++ src/sys/compat/linux/common/linux_socket.c	Wed Nov 14 17:51:37 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_socket.c,v 1.142 2018/05/10 01:32:24 ozaki-r Exp $	*/
+/*	$NetBSD: linux_socket.c,v 1.143 2018/11/14 17:51:37 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1995, 1998, 2008 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_socket.c,v 1.142 2018/05/10 01:32:24 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_socket.c,v 1.143 2018/11/14 17:51:37 hannken Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -1801,14 +1801,11 @@ linux_sys_sendmmsg(struct lwp *l, const 
 	}
 
 	*retval = dg;
-	if (error)
-		so->so_error = error;
 
 	fd_putfile(s);
 
 	/*
-	 * If we succeeded at least once, return 0, hopefully so->so_error
-	 * will catch it next time.
+	 * If we succeeded at least once, return 0.
 	 */
 	if (dg)
 		return 0;
@@ -1849,6 +1846,16 @@ linux_sys_recvmmsg(struct lwp *l, const 
 	if ((error = fd_getsock(s, )) != 0)
 		return error;
 
+	/*
+	 * If so->so_rerror holds a deferred error return it now.
+	 */
+	if (so->so_rerror) {
+		error = so->so_rerror;
+		so->so_rerror = 0;
+		fd_putfile(s);
+		return error;
+	}
+
 	vlen = SCARG(uap, vlen);
 	if (vlen > 1024)
 		vlen = 1024;
@@ -1919,17 +1926,17 @@ linux_sys_recvmmsg(struct lwp *l, const 
 		m_free(from);
 
 	*retval = dg;
-	if (error)
-		so->so_error = error;
-
-	fd_putfile(s);
 
 	/*
-	 * If we succeeded at least once, return 0, hopefully so->so_error
+	 * If we succeeded at least once, return 0, hopefully so->so_rerror
 	 * will catch it next time.
 	 */
-	if (dg)
-		return 0;
+	if (error && dg > 0) {
+		so->so_rerror = error;
+		error = 0;
+	}
+
+	fd_putfile(s);
 
 	return error;
 }

Index: src/sys/compat/netbsd32/netbsd32_socket.c
diff -u src/sys/compat/netbsd32/netbsd32_socket.c:1.48 src/sys/compat/netbsd32/netbsd32_socket.c:1.49
--- src/sys/compat/netbsd32/netbsd32_socket.c:1.48	Mon Nov 12 06:53:43 2018
+++ src/sys/compat/netbsd32/netbsd32_socket.c	Wed Nov 14 17:51:37 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_socket.c,v 1.48 2018/11/12 06:53:43 maxv Exp $	*/
+/*	$NetBSD: netbsd32_socket.c,v 1.49 2018/11/14 17:51:37 hannken Exp $	*/
 
 /*
  * Copyright (c) 1998, 2001 Matthew R. Green
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_socket.c,v 1.48 2018/11/12 06:53:43 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_socket.c,v 1.49 2018/11/14 17:51:37 hannken Exp $");
 
 #include 
 #include 
@@ -289,6 +289,16 @@ netbsd32_recvmmsg(struct lwp *l, const s
 	if ((error = fd_getsock(s, )) != 0)
 		return error;
 
+	/*
+	 * If so->so_rerror holds a deferred error return it now.
+	 */
+	if (so->so_rerror) {
+		error = so->so_rerror;
+		so->so_rerror = 0;
+		fd_putfile(s);
+		return error;
+	}
+
 	vlen = SCARG(uap, vlen);
 	if (vlen > 1024)
 		vlen = 1024;
@@ -350,17 +360,17 @@ netbsd32_recvmmsg(struct lwp *l, const s
 		m_free(from);
 
 	*retval = dg;
-	if (error)
-		so->so_error = error;
-
-	fd_putfile(s);
 
 	/*
-	 * If we succeeded at least once, return 0, hopefully so->so_error
+	 * If we succeeded at least once, return 0, hopefully so->so_rerror
 	 * will catch it next time.
 	 */
-	if (dg)
-		return 0;
+	if (error && dg > 0) {
+		so->so_rerror = error;
+		error = 0;
+	}
+
+	fd_putfile(s);
 
 	return error;
 }
@@ -597,14 +607,11 @@ netbsd32_sendmmsg(struct lwp *l, const s
 	}
 
 	*retval = dg;
-	if (error)
-		so->so_error = error;
 
 	fd_putfile(s);
 
 	/*
-	 * If we succeeded at least once, return 0, hopefully so->so_error
-	 * will catch it next time.
+	 * If we succeeded at least once, return 0.
 	 */
 	if (dg)
 		return 0;



CVS commit: src/external/bsd/nsd/include

2018-11-12 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Mon Nov 12 09:21:45 UTC 2018

Modified Files:
src/external/bsd/nsd/include: config.h

Log Message:
Re-enable {send,recv}mmsg now they are working.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/external/bsd/nsd/include/config.h

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

Modified files:

Index: src/external/bsd/nsd/include/config.h
diff -u src/external/bsd/nsd/include/config.h:1.4 src/external/bsd/nsd/include/config.h:1.5
--- src/external/bsd/nsd/include/config.h:1.4	Thu Nov  1 19:11:31 2018
+++ src/external/bsd/nsd/include/config.h	Mon Nov 12 09:21:45 2018
@@ -233,13 +233,11 @@
 /* Define to 1 if you have the `reallocarray' function. */
 #define HAVE_REALLOCARRAY 1
 
-#ifdef notyet
 /* Define if recvmmsg is implemented */
 #define HAVE_RECVMMSG 1
 
 /* Define if sendmmsg is implemented */
 #define HAVE_SENDMMSG 1
-#endif
 
 /* Define to 1 if you have the `setregid' function. */
 #define HAVE_SETREGID 1



CVS commit: src/sys/kern

2018-11-12 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Mon Nov 12 09:21:13 UTC 2018

Modified Files:
src/sys/kern: uipc_syscalls.c

Log Message:
sys_recvmmsg: don't defer an error that already gets returned.


To generate a diff of this commit:
cvs rdiff -u -r1.198 -r1.199 src/sys/kern/uipc_syscalls.c

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

Modified files:

Index: src/sys/kern/uipc_syscalls.c
diff -u src/sys/kern/uipc_syscalls.c:1.198 src/sys/kern/uipc_syscalls.c:1.199
--- src/sys/kern/uipc_syscalls.c:1.198	Wed Nov  7 09:59:12 2018
+++ src/sys/kern/uipc_syscalls.c	Mon Nov 12 09:21:13 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: uipc_syscalls.c,v 1.198 2018/11/07 09:59:12 hannken Exp $	*/
+/*	$NetBSD: uipc_syscalls.c,v 1.199 2018/11/12 09:21:13 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.198 2018/11/07 09:59:12 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.199 2018/11/12 09:21:13 hannken Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_pipe.h"
@@ -1124,17 +1124,16 @@ sys_recvmmsg(struct lwp *l, const struct
 
 	*retval = dg;
 
-	if (error)
-		so->so_rerror = error;
-
-	fd_putfile(s);
-
 	/*
 	 * If we succeeded at least once, return 0, hopefully so->so_rerror
 	 * will catch it next time.
 	 */
-	if (dg)
-		return 0;
+	if (error && dg > 0) {
+		so->so_rerror = error;
+		error = 0;
+	}
+
+	fd_putfile(s);
 
 	return error;
 }



CVS commit: src/sys/kern

2018-11-07 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed Nov  7 09:59:12 UTC 2018

Modified Files:
src/sys/kern: uipc_syscalls.c

Log Message:
Don't defer errors from sendmmsg().  This matches the linux manpage.

Defer errors from recvmmsg() through so_rerror and
tests and return a deferred error on entry.

Ok: christos@


To generate a diff of this commit:
cvs rdiff -u -r1.197 -r1.198 src/sys/kern/uipc_syscalls.c

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

Modified files:

Index: src/sys/kern/uipc_syscalls.c
diff -u src/sys/kern/uipc_syscalls.c:1.197 src/sys/kern/uipc_syscalls.c:1.198
--- src/sys/kern/uipc_syscalls.c:1.197	Mon Sep  3 16:29:35 2018
+++ src/sys/kern/uipc_syscalls.c	Wed Nov  7 09:59:12 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: uipc_syscalls.c,v 1.197 2018/09/03 16:29:35 riastradh Exp $	*/
+/*	$NetBSD: uipc_syscalls.c,v 1.198 2018/11/07 09:59:12 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.197 2018/09/03 16:29:35 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.198 2018/11/07 09:59:12 hannken Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_pipe.h"
@@ -806,14 +806,11 @@ sys_sendmmsg(struct lwp *l, const struct
 	}
 
 	*retval = dg;
-	if (error)
-		so->so_error = error;
 
 	fd_putfile(s);
 
 	/*
-	 * If we succeeded at least once, return 0, hopefully so->so_error
-	 * will catch it next time.
+	 * If we succeeded at least once, return 0.
 	 */
 	if (dg)
 		return 0;
@@ -1052,6 +1049,16 @@ sys_recvmmsg(struct lwp *l, const struct
 	if ((error = fd_getsock(s, )) != 0)
 		return error;
 
+	/*
+	 * If so->so_rerror holds a deferred error return it now.
+	 */
+	if (so->so_rerror) {
+		error = so->so_rerror;
+		so->so_rerror = 0;
+		fd_putfile(s);
+		return error;
+	}
+
 	vlen = SCARG(uap, vlen);
 	if (vlen > 1024)
 		vlen = 1024;
@@ -1116,13 +1123,14 @@ sys_recvmmsg(struct lwp *l, const struct
 		m_free(from);
 
 	*retval = dg;
+
 	if (error)
-		so->so_error = error;
+		so->so_rerror = error;
 
 	fd_putfile(s);
 
 	/*
-	 * If we succeeded at least once, return 0, hopefully so->so_error
+	 * If we succeeded at least once, return 0, hopefully so->so_rerror
 	 * will catch it next time.
 	 */
 	if (dg)



CVS commit: src/sys/kern

2018-11-07 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed Nov  7 09:58:19 UTC 2018

Modified Files:
src/sys/kern: uipc_socket.c

Log Message:
Update getsockopt(SO_ERROR) to behave like soreceive() and
return and clear so->so_rerror if so->so_error is zero.

Ok: christos@


To generate a diff of this commit:
cvs rdiff -u -r1.266 -r1.267 src/sys/kern/uipc_socket.c

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

Modified files:

Index: src/sys/kern/uipc_socket.c
diff -u src/sys/kern/uipc_socket.c:1.266 src/sys/kern/uipc_socket.c:1.267
--- src/sys/kern/uipc_socket.c:1.266	Sun Nov  4 16:30:29 2018
+++ src/sys/kern/uipc_socket.c	Wed Nov  7 09:58:19 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: uipc_socket.c,v 1.266 2018/11/04 16:30:29 christos Exp $	*/
+/*	$NetBSD: uipc_socket.c,v 1.267 2018/11/07 09:58:19 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -71,7 +71,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.266 2018/11/04 16:30:29 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.267 2018/11/07 09:58:19 hannken Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -1974,6 +1974,10 @@ sogetopt1(struct socket *so, struct sock
 		break;
 
 	case SO_ERROR:
+		if (so->so_error == 0) {
+			so->so_error = so->so_rerror;
+			so->so_rerror = 0;
+		}
 		error = sockopt_setint(sopt, so->so_error);
 		so->so_error = 0;
 		break;



CVS commit: src/external/bsd/nsd

2018-10-12 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Fri Oct 12 09:43:59 UTC 2018

Modified Files:
src/external/bsd/nsd: Makefile.inc

Log Message:
Fix obvious typo: add missing equal sign.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/external/bsd/nsd/Makefile.inc

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

Modified files:

Index: src/external/bsd/nsd/Makefile.inc
diff -u src/external/bsd/nsd/Makefile.inc:1.4 src/external/bsd/nsd/Makefile.inc:1.5
--- src/external/bsd/nsd/Makefile.inc:1.4	Fri Feb  9 17:13:27 2018
+++ src/external/bsd/nsd/Makefile.inc	Fri Oct 12 09:43:59 2018
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.inc,v 1.4 2018/02/09 17:13:27 christos Exp $
+# $NetBSD: Makefile.inc,v 1.5 2018/10/12 09:43:59 hannken Exp $
 
 .include 
 
@@ -15,7 +15,7 @@ CPPFLAGS+=  -DINET6
 .endif
 
 .if ${HAVE_OPENSSL} < 11
-CPPFLAGS+=	-DOPENSSL_API_COMPAT 0x1010L
+CPPFLAGS+=	-DOPENSSL_API_COMPAT=0x1010L
 .endif
 
 DPLIBS+= event ${NETBSDSRCDIR}/external/bsd/libevent/lib/libevent



CVS commit: src

2018-10-05 Thread Juergen Hannken-Illjes
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.compcomp-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 

CVS commit: src/sbin/fsck_ffs

2018-10-05 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Fri Oct  5 09:49:23 UTC 2018

Modified Files:
src/sbin/fsck_ffs: setup.c

Log Message:
Add a test for duplicate inodes on the persistent snapshot list.


To generate a diff of this commit:
cvs rdiff -u -r1.101 -r1.102 src/sbin/fsck_ffs/setup.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_ffs/setup.c
diff -u src/sbin/fsck_ffs/setup.c:1.101 src/sbin/fsck_ffs/setup.c:1.102
--- src/sbin/fsck_ffs/setup.c:1.101	Wed Feb  8 16:11:40 2017
+++ src/sbin/fsck_ffs/setup.c	Fri Oct  5 09:49:23 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: setup.c,v 1.101 2017/02/08 16:11:40 rin Exp $	*/
+/*	$NetBSD: setup.c,v 1.102 2018/10/05 09:49:23 hannken Exp $	*/
 
 /*
  * Copyright (c) 1980, 1986, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)setup.c	8.10 (Berkeley) 5/9/95";
 #else
-__RCSID("$NetBSD: setup.c,v 1.101 2017/02/08 16:11:40 rin Exp $");
+__RCSID("$NetBSD: setup.c,v 1.102 2018/10/05 09:49:23 hannken Exp $");
 #endif
 #endif /* not lint */
 
@@ -73,6 +73,7 @@ static int readsb(int);
 #ifndef NO_APPLE_UFS
 static int readappleufs(void);
 #endif
+static int check_snapinum(void);
 
 int16_t sblkpostbl[256];
 
@@ -341,6 +342,14 @@ setup(const char *dev, const char *origd
 			dirty();
 		}
 	}
+	if (check_snapinum()) {
+		if (preen)
+			printf(" (FIXED)\n");
+		if (preen || reply("FIX") == 1) {
+			sbdirty();
+			dirty();
+		}
+	}
 	if (is_ufs2 || sblock->fs_old_inodefmt >= FS_44INODEFMT) {
 		if (sblock->fs_maxfilesize != maxfilesize) {
 			pwarn("INCORRECT MAXFILESIZE=%lld IN SUPERBLOCK",
@@ -1094,3 +1103,42 @@ calcsb(const char *dev, int devfd, struc
 	}
 	return (1);
 }
+
+/*
+ * Test the list of snapshot inode numbers for duplicates and repair.
+ */
+static int
+check_snapinum(void)
+{
+	int loc, loc2, res;
+	int *snapinum = >fs_snapinum[0];
+
+	res = 0;
+ 
+	if (isappleufs)
+		return 0;
+
+	for (loc = 0; loc < FSMAXSNAP; loc++) {
+		if (snapinum[loc] == 0)
+			break;
+		for (loc2 = loc + 1; loc2 < FSMAXSNAP; loc2++) {
+			if (snapinum[loc2] == 0 ||
+			snapinum[loc2] == snapinum[loc])
+break;
+		}
+		if (loc2 >= FSMAXSNAP || snapinum[loc2] == 0)
+			continue;
+		pwarn("SNAPSHOT INODE %u ALREADY ON LIST%s", snapinum[loc2],
+		(res ? "" : "\n"));
+		res = 1;
+		for (loc2 = loc + 1; loc2 < FSMAXSNAP; loc2++) {
+			if (snapinum[loc2] == 0)
+break;
+			snapinum[loc2 - 1] = snapinum[loc2];
+		}
+		snapinum[loc2 - 1] = 0;
+		loc--;
+	}
+
+	return res;
+}



CVS commit: src/sys/dev

2018-08-29 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed Aug 29 09:04:40 UTC 2018

Modified Files:
src/sys/dev: fss.c fssvar.h

Log Message:
Add two new states FSS_CREATING and FSS_DESTROYING and use them
while creating or destroying a snapshot.

Remove now unneeded sc_lock that made fss_ioctl mutually exclusive.

Fss_ioctl no longer blocks forever because a snapshot gets
created or destroyed.

Serialize snapshot creation and make it interruptible.


To generate a diff of this commit:
cvs rdiff -u -r1.105 -r1.106 src/sys/dev/fss.c
cvs rdiff -u -r1.30 -r1.31 src/sys/dev/fssvar.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/dev/fss.c
diff -u src/sys/dev/fss.c:1.105 src/sys/dev/fss.c:1.106
--- src/sys/dev/fss.c:1.105	Wed Aug 29 09:04:03 2018
+++ src/sys/dev/fss.c	Wed Aug 29 09:04:40 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: fss.c,v 1.105 2018/08/29 09:04:03 hannken Exp $	*/
+/*	$NetBSD: fss.c,v 1.106 2018/08/29 09:04:40 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fss.c,v 1.105 2018/08/29 09:04:03 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fss.c,v 1.106 2018/08/29 09:04:40 hannken Exp $");
 
 #include 
 #include 
@@ -93,6 +93,8 @@ static int fss_bs_io(struct fss_softc *,
 static u_int32_t *fss_bs_indir(struct fss_softc *, u_int32_t);
 
 static kmutex_t fss_device_lock;	/* Protect all units. */
+static kcondvar_t fss_device_cv;	/* Serialize snapshot creation. */
+static bool fss_creating = false;	/* Currently creating a snapshot. */
 static int fss_num_attached = 0;	/* Number of attached devices. */
 static struct vfs_hooks fss_vfs_hooks = {
 	.vh_unmount = fss_unmount_hook
@@ -136,6 +138,7 @@ fssattach(int num)
 {
 
 	mutex_init(_device_lock, MUTEX_DEFAULT, IPL_NONE);
+	cv_init(_device_cv, "snapwait");
 	if (config_cfattach_attach(fss_cd.cd_name, _ca))
 		aprint_error("%s: unable to register\n", fss_cd.cd_name);
 }
@@ -154,7 +157,6 @@ fss_attach(device_t parent, device_t sel
 	sc->sc_dev = self;
 	sc->sc_bdev = NODEV;
 	mutex_init(>sc_slock, MUTEX_DEFAULT, IPL_NONE);
-	mutex_init(>sc_lock, MUTEX_DEFAULT, IPL_NONE);
 	cv_init(>sc_work_cv, "fssbs");
 	cv_init(>sc_cache_cv, "cowwait");
 	bufq_alloc(>sc_bufq, "fcfs", 0);
@@ -185,7 +187,6 @@ fss_detach(device_t self, int flags)
 
 	pmf_device_deregister(self);
 	mutex_destroy(>sc_slock);
-	mutex_destroy(>sc_lock);
 	cv_destroy(>sc_work_cv);
 	cv_destroy(>sc_cache_cv);
 	bufq_drain(sc->sc_bufq);
@@ -341,36 +342,83 @@ fss_ioctl(dev_t dev, u_long cmd, void *d
 		fss->fss_flags = 0;
 		/* Fall through */
 	case FSSIOCSET:
-		mutex_enter(>sc_lock);
+		mutex_enter(>sc_slock);
 		if ((flag & FWRITE) == 0)
 			error = EPERM;
-		mutex_enter(>sc_slock);
-		if (error == 0 && sc->sc_state != FSS_IDLE)
+		if (error == 0 && sc->sc_state != FSS_IDLE) {
 			error = EBUSY;
+		} else {
+			sc->sc_state = FSS_CREATING;
+			copyinstr(fss->fss_mount, sc->sc_mntname,
+			sizeof(sc->sc_mntname), NULL);
+			memset(>sc_time, 0, sizeof(sc->sc_time));
+			sc->sc_clshift = 0;
+		}
 		mutex_exit(>sc_slock);
-		if (error == 0)
-			error = fss_create_snapshot(sc, fss, l);
-		if (error == 0)
+		if (error)
+			break;
+
+		/*
+		 * Serialize snapshot creation.
+		 */
+		mutex_enter(_device_lock);
+		while (fss_creating) {
+			error = cv_wait_sig(_device_cv, _device_lock);
+			if (error) {
+mutex_enter(>sc_slock);
+KASSERT(sc->sc_state == FSS_CREATING);
+sc->sc_state = FSS_IDLE;
+mutex_exit(>sc_slock);
+mutex_exit(_device_lock);
+break;
+			}
+		}
+		fss_creating = true;
+		mutex_exit(_device_lock);
+
+		error = fss_create_snapshot(sc, fss, l);
+		mutex_enter(>sc_slock);
+		if (error == 0) {
+			KASSERT(sc->sc_state == FSS_ACTIVE);
 			sc->sc_uflags = fss->fss_flags;
-		mutex_exit(>sc_lock);
+		} else {
+			KASSERT(sc->sc_state == FSS_CREATING);
+			sc->sc_state = FSS_IDLE;
+		}
+		mutex_exit(>sc_slock);
+
+		mutex_enter(_device_lock);
+		fss_creating = false;
+		cv_broadcast(_device_cv);
+		mutex_exit(_device_lock);
+
 		break;
 
 	case FSSIOCCLR:
-		mutex_enter(>sc_lock);
-		if ((flag & FWRITE) == 0)
+		mutex_enter(>sc_slock);
+		if ((flag & FWRITE) == 0) {
 			error = EPERM;
+		} else if (sc->sc_state != FSS_ACTIVE &&
+		sc->sc_state != FSS_ERROR) {
+			error = EBUSY;
+		} else {
+			sc->sc_state = FSS_DESTROYING;
+		}
+		mutex_exit(>sc_slock);
+		if (error)
+			break;
+
+		error = fss_delete_snapshot(sc, l);
 		mutex_enter(>sc_slock);
-		if (error == 0 && sc->sc_state == FSS_IDLE)
-			error = ENXIO;
+		if (error)
+			fss_error(sc, "Failed to delete snapshot");
+		else
+			KASSERT(sc->sc_state == FSS_IDLE);
 		mutex_exit(>sc_slock);
-		if (error == 0)
-			error = fss_delete_snapshot(sc, l);
-		mutex_exit(>sc_lock);
 		break;
 
 #ifndef _LP64
 	case FSSIOCGET50:
-		mutex_enter(>sc_lock);
 		mutex_enter(>sc_slock);
 		if (sc->sc_state == FSS_IDLE) {
 			error = 

CVS commit: src/sys/kern

2018-08-29 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed Aug 29 09:05:17 UTC 2018

Modified Files:
src/sys/kern: vfs_bio.c

Log Message:
Make sure getnewbuf() runs bawrite() inside fstrans.
Use fstrans_start_nowait() to skip buffers that would block.


To generate a diff of this commit:
cvs rdiff -u -r1.276 -r1.277 src/sys/kern/vfs_bio.c

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

Modified files:

Index: src/sys/kern/vfs_bio.c
diff -u src/sys/kern/vfs_bio.c:1.276 src/sys/kern/vfs_bio.c:1.277
--- src/sys/kern/vfs_bio.c:1.276	Sat Oct 28 00:37:11 2017
+++ src/sys/kern/vfs_bio.c	Wed Aug 29 09:05:17 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_bio.c,v 1.276 2017/10/28 00:37:11 pgoyette Exp $	*/
+/*	$NetBSD: vfs_bio.c,v 1.277 2018/08/29 09:05:17 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -123,7 +123,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_bio.c,v 1.276 2017/10/28 00:37:11 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_bio.c,v 1.277 2018/08/29 09:05:17 hannken Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_bufcache.h"
@@ -1360,11 +1360,12 @@ allocbuf(buf_t *bp, int size, int preser
  * Called with the buffer queues locked.
  * Return buffer locked.
  */
-buf_t *
+static buf_t *
 getnewbuf(int slpflag, int slptimeo, int from_bufq)
 {
 	buf_t *bp;
 	struct vnode *vp;
+	struct mount *transmp = NULL;
 
  start:
 	KASSERT(mutex_owned(_lock));
@@ -1389,8 +1390,21 @@ getnewbuf(int slpflag, int slptimeo, int
 	}
 
 	KASSERT(mutex_owned(_lock));
-	if ((bp = TAILQ_FIRST([BQ_AGE].bq_queue)) != NULL ||
-	(bp = TAILQ_FIRST([BQ_LRU].bq_queue)) != NULL) {
+	if ((bp = TAILQ_FIRST([BQ_AGE].bq_queue)) != NULL) {
+		KASSERT(!ISSET(bp->b_oflags, BO_DELWRI));
+	} else {
+		TAILQ_FOREACH(bp, [BQ_LRU].bq_queue, b_freelist) {
+			if (ISSET(bp->b_cflags, BC_VFLUSH) ||
+			!ISSET(bp->b_oflags, BO_DELWRI))
+break;
+			if (fstrans_start_nowait(bp->b_vp->v_mount) == 0) {
+KASSERT(transmp == NULL);
+transmp = bp->b_vp->v_mount;
+break;
+			}
+		}
+	}
+	if (bp != NULL) {
 		KASSERT(!ISSET(bp->b_cflags, BC_BUSY) || ISSET(bp->b_cflags, BC_VFLUSH));
 		bremfree(bp);
 
@@ -1444,10 +1458,14 @@ getnewbuf(int slpflag, int slptimeo, int
 		SET(bp->b_cflags, BC_AGE);
 		mutex_exit(_lock);
 		bawrite(bp);
+		KASSERT(transmp != NULL);
+		fstrans_done(transmp);
 		mutex_enter(_lock);
 		return (NULL);
 	}
 
+	KASSERT(transmp == NULL);
+
 	vp = bp->b_vp;
 
 	/* clear out various other fields */



CVS commit: src/sys/dev

2018-08-29 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed Aug 29 09:04:03 UTC 2018

Modified Files:
src/sys/dev: fss.c fssvar.h

Log Message:
Convert flags FSS_ACTIVE and FSS_ERROR into new member sc_state
with states FSS_IDLE, FSS_ACTIVE and FSS_ERROR.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.104 -r1.105 src/sys/dev/fss.c
cvs rdiff -u -r1.29 -r1.30 src/sys/dev/fssvar.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/dev/fss.c
diff -u src/sys/dev/fss.c:1.104 src/sys/dev/fss.c:1.105
--- src/sys/dev/fss.c:1.104	Tue Jan 23 22:42:29 2018
+++ src/sys/dev/fss.c	Wed Aug 29 09:04:03 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: fss.c,v 1.104 2018/01/23 22:42:29 pgoyette Exp $	*/
+/*	$NetBSD: fss.c,v 1.105 2018/08/29 09:04:03 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fss.c,v 1.104 2018/01/23 22:42:29 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fss.c,v 1.105 2018/08/29 09:04:03 hannken Exp $");
 
 #include 
 #include 
@@ -173,8 +173,12 @@ fss_detach(device_t self, int flags)
 {
 	struct fss_softc *sc = device_private(self);
 
-	if (sc->sc_flags & FSS_ACTIVE)
+	mutex_enter(>sc_slock);
+	if (sc->sc_state != FSS_IDLE) {
+		mutex_exit(>sc_slock);
 		return EBUSY;
+	}
+	mutex_exit(>sc_slock);
 
 	if (--fss_num_attached == 0)
 		vfs_hooks_detach(_vfs_hooks);
@@ -215,6 +219,7 @@ fss_open(dev_t dev, int flags, int mode,
 			mutex_exit(_device_lock);
 			return ENOMEM;
 		}
+		sc->sc_state = FSS_IDLE;
 	}
 
 	mutex_enter(>sc_slock);
@@ -246,20 +251,20 @@ restart:
 		mutex_exit(_device_lock);
 		return 0;
 	}
-	if ((sc->sc_flags & FSS_ACTIVE) != 0 &&
+	if (sc->sc_state != FSS_IDLE &&
 	(sc->sc_uflags & FSS_UNCONFIG_ON_CLOSE) != 0) {
 		sc->sc_uflags &= ~FSS_UNCONFIG_ON_CLOSE;
 		mutex_exit(>sc_slock);
 		error = fss_ioctl(dev, FSSIOCCLR, NULL, FWRITE, l);
 		goto restart;
 	}
-	if ((sc->sc_flags & FSS_ACTIVE) != 0) {
+	if (sc->sc_state != FSS_IDLE) {
 		mutex_exit(>sc_slock);
 		mutex_exit(_device_lock);
 		return error;
 	}
 
-	KASSERT((sc->sc_flags & FSS_ACTIVE) == 0);
+	KASSERT(sc->sc_state == FSS_IDLE);
 	KASSERT((sc->sc_flags & (FSS_CDEV_OPEN|FSS_BDEV_OPEN)) == mflag);
 	mutex_exit(>sc_slock);
 	cf = device_cfdata(sc->sc_dev);
@@ -279,7 +284,7 @@ fss_strategy(struct buf *bp)
 
 	mutex_enter(>sc_slock);
 
-	if (write || !FSS_ISVALID(sc)) {
+	if (write || sc->sc_state != FSS_ACTIVE) {
 		bp->b_error = (write ? EROFS : ENXIO);
 		goto done;
 	}
@@ -317,7 +322,7 @@ fss_write(dev_t dev, struct uio *uio, in
 int
 fss_ioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
 {
-	int error;
+	int error = 0;
 	struct fss_softc *sc = device_lookup_private(_cd, minor(dev));
 	struct fss_set _fss;
 	struct fss_set *fss = (struct fss_set *)data;
@@ -339,9 +344,11 @@ fss_ioctl(dev_t dev, u_long cmd, void *d
 		mutex_enter(>sc_lock);
 		if ((flag & FWRITE) == 0)
 			error = EPERM;
-		else if ((sc->sc_flags & FSS_ACTIVE) != 0)
+		mutex_enter(>sc_slock);
+		if (error == 0 && sc->sc_state != FSS_IDLE)
 			error = EBUSY;
-		else
+		mutex_exit(>sc_slock);
+		if (error == 0)
 			error = fss_create_snapshot(sc, fss, l);
 		if (error == 0)
 			sc->sc_uflags = fss->fss_flags;
@@ -352,9 +359,11 @@ fss_ioctl(dev_t dev, u_long cmd, void *d
 		mutex_enter(>sc_lock);
 		if ((flag & FWRITE) == 0)
 			error = EPERM;
-		else if ((sc->sc_flags & FSS_ACTIVE) == 0)
+		mutex_enter(>sc_slock);
+		if (error == 0 && sc->sc_state == FSS_IDLE)
 			error = ENXIO;
-		else
+		mutex_exit(>sc_slock);
+		if (error == 0)
 			error = fss_delete_snapshot(sc, l);
 		mutex_exit(>sc_lock);
 		break;
@@ -362,54 +371,50 @@ fss_ioctl(dev_t dev, u_long cmd, void *d
 #ifndef _LP64
 	case FSSIOCGET50:
 		mutex_enter(>sc_lock);
-		switch (sc->sc_flags & (FSS_PERSISTENT | FSS_ACTIVE)) {
-		case FSS_ACTIVE:
+		mutex_enter(>sc_slock);
+		if (sc->sc_state == FSS_IDLE) {
+			error = ENXIO;
+		} else if ((sc->sc_flags & FSS_PERSISTENT) == 0) {
 			memcpy(fsg50->fsg_mount, sc->sc_mntname, MNAMELEN);
 			fsg50->fsg_csize = FSS_CLSIZE(sc);
 			timeval_to_timeval50(>sc_time, >fsg_time);
 			fsg50->fsg_mount_size = sc->sc_clcount;
 			fsg50->fsg_bs_size = sc->sc_clnext;
 			error = 0;
-			break;
-		case FSS_PERSISTENT | FSS_ACTIVE:
+		} else {
 			memcpy(fsg50->fsg_mount, sc->sc_mntname, MNAMELEN);
 			fsg50->fsg_csize = 0;
 			timeval_to_timeval50(>sc_time, >fsg_time);
 			fsg50->fsg_mount_size = 0;
 			fsg50->fsg_bs_size = 0;
 			error = 0;
-			break;
-		default:
-			error = ENXIO;
-			break;
 		}
+		mutex_exit(>sc_slock);
 		mutex_exit(>sc_lock);
 		break;
 #endif /* _LP64 */
 
 	case FSSIOCGET:
 		mutex_enter(>sc_lock);
-		switch (sc->sc_flags & (FSS_PERSISTENT | FSS_ACTIVE)) {
-		case FSS_ACTIVE:
+		mutex_enter(>sc_slock);
+		if (sc->sc_state == FSS_IDLE) {
+			error = ENXIO;
+		} else if ((sc->sc_flags & FSS_PERSISTENT) == 0) {
 		

CVS commit: src/external/cddl/osnet/dist/uts/common/fs/zfs

2018-07-31 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Tue Jul 31 09:33:50 UTC 2018

Modified Files:
src/external/cddl/osnet/dist/uts/common/fs/zfs: zfs_znode.c

Log Message:
Initialize z_lockf for new znodes.

Ok: Chuck Silvers


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c

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

Modified files:

Index: src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c
diff -u src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c:1.20 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c:1.21
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c:1.20	Mon May 28 21:05:07 2018
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c	Tue Jul 31 09:33:50 2018
@@ -1309,6 +1309,7 @@ skip_lookup:
 	zp->z_blksz = blksz;
 	zp->z_seq = 0x7A4653;
 	zp->z_sync_cnt = 0;
+	zp->z_lockf = NULL;
 
 	zfs_znode_sa_init(zfsvfs, zp, db, obj_type, hdl);
 



CVS commit: src/sys/nfs

2018-05-03 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Thu May  3 07:28:44 UTC 2018

Modified Files:
src/sys/nfs: nfs_serv.c

Log Message:
nfsrv_readlink: stop attaching a zero-length mbuf for zero length symlinks.


To generate a diff of this commit:
cvs rdiff -u -r1.173 -r1.174 src/sys/nfs/nfs_serv.c

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

Modified files:

Index: src/sys/nfs/nfs_serv.c
diff -u src/sys/nfs/nfs_serv.c:1.173 src/sys/nfs/nfs_serv.c:1.174
--- src/sys/nfs/nfs_serv.c:1.173	Wed Apr 26 03:02:49 2017
+++ src/sys/nfs/nfs_serv.c	Thu May  3 07:28:43 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: nfs_serv.c,v 1.173 2017/04/26 03:02:49 riastradh Exp $	*/
+/*	$NetBSD: nfs_serv.c,v 1.174 2018/05/03 07:28:43 hannken Exp $	*/
 
 /*
  * Copyright (c) 1989, 1993
@@ -55,7 +55,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nfs_serv.c,v 1.173 2017/04/26 03:02:49 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nfs_serv.c,v 1.174 2018/05/03 07:28:43 hannken Exp $");
 
 #include 
 #include 
@@ -600,7 +600,10 @@ out:
 	}
 	len -= uiop->uio_resid;
 	padlen = nfsm_padlen(len);
-	if (uiop->uio_resid || padlen)
+	if (len == 0) {
+		m_freem(mp3);
+		mp3 = NULL;
+	} else if (uiop->uio_resid || padlen)
 		nfs_zeropad(mp3, uiop->uio_resid, padlen);
 	nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);
 	*tl = txdr_unsigned(len);



CVS commit: src/sys/miscfs/procfs

2018-04-16 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Mon Apr 16 20:27:38 UTC 2018

Modified Files:
src/sys/miscfs/procfs: procfs_subr.c

Log Message:
Change procfs_revoke_vnodes() to use vrecycle()/vgone() instead
of VOP_REVOKE().

Gets rid of a bunch of suspensions on /proc as vrecycle() will
succeed most time and we suspend at most once per call.


To generate a diff of this commit:
cvs rdiff -u -r1.111 -r1.112 src/sys/miscfs/procfs/procfs_subr.c

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

Modified files:

Index: src/sys/miscfs/procfs/procfs_subr.c
diff -u src/sys/miscfs/procfs/procfs_subr.c:1.111 src/sys/miscfs/procfs/procfs_subr.c:1.112
--- src/sys/miscfs/procfs/procfs_subr.c:1.111	Sun Dec 31 03:29:18 2017
+++ src/sys/miscfs/procfs/procfs_subr.c	Mon Apr 16 20:27:38 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: procfs_subr.c,v 1.111 2017/12/31 03:29:18 christos Exp $	*/
+/*	$NetBSD: procfs_subr.c,v 1.112 2018/04/16 20:27:38 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -102,13 +102,14 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: procfs_subr.c,v 1.111 2017/12/31 03:29:18 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: procfs_subr.c,v 1.112 2018/04/16 20:27:38 hannken Exp $");
 
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -368,6 +369,8 @@ procfs_revoke_selector(void *arg, struct
 void
 procfs_revoke_vnodes(struct proc *p, void *arg)
 {
+	int error;
+	bool suspended;
 	struct vnode *vp;
 	struct vnode_iterator *marker;
 	struct mount *mp = (struct mount *)arg;
@@ -375,14 +378,29 @@ procfs_revoke_vnodes(struct proc *p, voi
 	if (!(p->p_flag & PK_SUGID))
 		return;
 
+	suspended = false;
 	vfs_vnode_iterator_init(mp, );
 
 	while ((vp = vfs_vnode_iterator_next(marker,
 	procfs_revoke_selector, p)) != NULL) {
-		VOP_REVOKE(vp, REVOKEALL);
-		vrele(vp);
+		if (vrecycle(vp))
+			continue;
+		/* Vnode is busy, we have to suspend the mount for vgone(). */
+		while (! suspended) {
+			error = vfs_suspend(mp, 0);
+			if (error == 0) {
+suspended = true;
+			} else if (error != EINTR && error != ERESTART) {
+KASSERT(error == EOPNOTSUPP);
+break;
+			}
+		}
+		vgone(vp);
 	}
 
+	if (suspended)
+		vfs_resume(mp);
+
 	vfs_vnode_iterator_destroy(marker);
 }
 



CVS commit: src/sys/kern

2018-04-16 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Mon Apr 16 20:25:21 UTC 2018

Modified Files:
src/sys/kern: subr_pserialize.c

Log Message:
Function pserialize_perform() usually succeeds after two cross calls
so defer kpause() to iterations three and above.

Speeds up VOP_REVOKE() on /proc/XXX/status by a factor of ~12.

Ok: core@


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/kern/subr_pserialize.c

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

Modified files:

Index: src/sys/kern/subr_pserialize.c
diff -u src/sys/kern/subr_pserialize.c:1.10 src/sys/kern/subr_pserialize.c:1.11
--- src/sys/kern/subr_pserialize.c:1.10	Thu Dec 28 03:39:48 2017
+++ src/sys/kern/subr_pserialize.c	Mon Apr 16 20:25:21 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_pserialize.c,v 1.10 2017/12/28 03:39:48 msaitoh Exp $	*/
+/*	$NetBSD: subr_pserialize.c,v 1.11 2018/04/16 20:25:21 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: subr_pserialize.c,v 1.10 2017/12/28 03:39:48 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_pserialize.c,v 1.11 2018/04/16 20:25:21 hannken Exp $");
 
 #include 
 
@@ -146,6 +146,7 @@ pserialize_destroy(pserialize_t psz)
 void
 pserialize_perform(pserialize_t psz)
 {
+	int n;
 	uint64_t xc;
 
 	KASSERT(!cpu_intr_p());
@@ -176,6 +177,7 @@ pserialize_perform(pserialize_t psz)
 	TAILQ_INSERT_TAIL(_queue0, psz, psz_chain);
 	psz_work_todo++;
 
+	n = 0;
 	do {
 		mutex_spin_exit(_lock);
 
@@ -183,9 +185,10 @@ pserialize_perform(pserialize_t psz)
 		 * Force some context switch activity on every CPU, as
 		 * the system may not be busy.  Pause to not flood.
 		 */
+		if (n++ > 1)
+			kpause("psrlz", false, 1, NULL);
 		xc = xc_broadcast(XC_HIGHPRI, (xcfunc_t)nullop, NULL, NULL);
 		xc_wait(xc);
-		kpause("psrlz", false, 1, NULL);
 
 		mutex_spin_enter(_lock);
 	} while (!kcpuset_iszero(psz->psz_target));



CVS commit: src/sys/miscfs/procfs

2018-04-07 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sat Apr  7 13:42:42 UTC 2018

Modified Files:
src/sys/miscfs/procfs: procfs_vnops.c

Log Message:
Lock the target cwdi and take an additional reference to the
vnode we are interested in to prevent it from disappearing
before getcwd_common().

Should fix PR kern/53096 (netbsd-8 crash on heavy disk I/O)


To generate a diff of this commit:
cvs rdiff -u -r1.202 -r1.203 src/sys/miscfs/procfs/procfs_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/sys/miscfs/procfs/procfs_vnops.c
diff -u src/sys/miscfs/procfs/procfs_vnops.c:1.202 src/sys/miscfs/procfs/procfs_vnops.c:1.203
--- src/sys/miscfs/procfs/procfs_vnops.c:1.202	Sun Dec 31 03:02:23 2017
+++ src/sys/miscfs/procfs/procfs_vnops.c	Sat Apr  7 13:42:42 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: procfs_vnops.c,v 1.202 2017/12/31 03:02:23 christos Exp $	*/
+/*	$NetBSD: procfs_vnops.c,v 1.203 2018/04/07 13:42:42 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -105,7 +105,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: procfs_vnops.c,v 1.202 2017/12/31 03:02:23 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: procfs_vnops.c,v 1.203 2018/04/07 13:42:42 hannken Exp $");
 
 #include 
 #include 
@@ -545,11 +545,10 @@ procfs_symlink(void *v)
 }
 
 /*
- * Works out the path to (and vnode of) the target process's current
+ * Works out the path to the target process's current
  * working directory or chroot.  If the caller is in a chroot and
  * can't "reach" the target's cwd or root (or some other error
- * occurs), a "/" is returned for the path and a NULL pointer is
- * returned for the vnode.
+ * occurs), a "/" is returned for the path.
  */
 static void
 procfs_dir(pfstype t, struct lwp *caller, struct proc *target, char **bpp,
@@ -559,12 +558,12 @@ procfs_dir(pfstype t, struct lwp *caller
 	struct vnode *vp, *rvp;
 	char *bp;
 
-	cwdi = caller->l_proc->p_cwdi;
-	rw_enter(>cwdi_lock, RW_READER);
-
-	rvp = cwdi->cwdi_rdir;
-	bp = bpp ? *bpp : NULL;
-
+	/*
+	 * Lock target cwdi and take a reference to the vnode
+	 * we are interested in to prevent it from disappearing
+	 * before getcwd_common() below.
+	 */
+	rw_enter(>p_cwdi->cwdi_lock, RW_READER);
 	switch (t) {
 	case PFScwd:
 		vp = target->p_cwdi->cwdi_cdir;
@@ -573,9 +572,18 @@ procfs_dir(pfstype t, struct lwp *caller
 		vp = target->p_cwdi->cwdi_rdir;
 		break;
 	default:
-		rw_exit(>cwdi_lock);
+		rw_exit(>p_cwdi->cwdi_lock);
 		return;
 	}
+	if (vp != NULL)
+		vref(vp);
+	rw_exit(>p_cwdi->cwdi_lock);
+
+	cwdi = caller->l_proc->p_cwdi;
+	rw_enter(>cwdi_lock, RW_READER);
+
+	rvp = cwdi->cwdi_rdir;
+	bp = bpp ? *bpp : NULL;
 
 	/*
 	 * XXX: this horrible kludge avoids locking panics when
@@ -586,6 +594,7 @@ procfs_dir(pfstype t, struct lwp *caller
 			*--bp = '/';
 			*bpp = bp;
 		}
+		vrele(vp);
 		rw_exit(>cwdi_lock);
 		return;
 	}
@@ -594,7 +603,6 @@ procfs_dir(pfstype t, struct lwp *caller
 		rvp = rootvnode;
 	if (vp == NULL || getcwd_common(vp, rvp, bp ?  : NULL, path,
 	len / 2, 0, caller) != 0) {
-		vp = NULL;
 		if (bpp) {
 			bp = *bpp;
 			*--bp = '/';
@@ -604,6 +612,8 @@ procfs_dir(pfstype t, struct lwp *caller
 	if (bpp)
 		*bpp = bp;
 
+	if (vp != NULL)
+		vrele(vp);
 	rw_exit(>cwdi_lock);
 }
 



CVS commit: src/sbin/fsck_ffs

2018-02-13 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Tue Feb 13 11:20:08 UTC 2018

Modified Files:
src/sbin/fsck_ffs: pass1.c

Log Message:
Treat an inode with "mode == 0" and "blocks != 0" as partially allocated
and clear it as ffs_newvnode() tests for "blocks == 0".


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/sbin/fsck_ffs/pass1.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_ffs/pass1.c
diff -u src/sbin/fsck_ffs/pass1.c:1.57 src/sbin/fsck_ffs/pass1.c:1.58
--- src/sbin/fsck_ffs/pass1.c:1.57	Wed Feb  8 16:11:40 2017
+++ src/sbin/fsck_ffs/pass1.c	Tue Feb 13 11:20:08 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: pass1.c,v 1.57 2017/02/08 16:11:40 rin Exp $	*/
+/*	$NetBSD: pass1.c,v 1.58 2018/02/13 11:20:08 hannken Exp $	*/
 
 /*
  * Copyright (c) 1980, 1986, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)pass1.c	8.6 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: pass1.c,v 1.57 2017/02/08 16:11:40 rin Exp $");
+__RCSID("$NetBSD: pass1.c,v 1.58 2018/02/13 11:20:08 hannken Exp $");
 #endif
 #endif /* not lint */
 
@@ -253,8 +253,9 @@ checkinode(ino_t inumber, struct inodesc
 		(memcmp(dp->dp1.di_db, ufs1_zino.di_db,
 			UFS_NDADDR * sizeof(int32_t)) ||
 		memcmp(dp->dp1.di_ib, ufs1_zino.di_ib,
-			UFS_NIADDR * sizeof(int32_t ||
-		mode || size) {
+			UFS_NIADDR * sizeof(int32_t
+		||
+		mode || size || DIP(dp, blocks)) {
 			pfatal("PARTIALLY ALLOCATED INODE I=%llu",
 			(unsigned long long)inumber);
 			if (reply("CLEAR") == 1) {



CVS commit: src/sys/ufs/ffs

2018-01-28 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sun Jan 28 10:02:01 UTC 2018

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
Prevent use-after-free where genfs_node_destroy() would destroy
a lock residing in the just freed inode data.


To generate a diff of this commit:
cvs rdiff -u -r1.355 -r1.356 src/sys/ufs/ffs/ffs_vfsops.c

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

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.355 src/sys/ufs/ffs/ffs_vfsops.c:1.356
--- src/sys/ufs/ffs/ffs_vfsops.c:1.355	Wed Nov 15 21:21:18 2017
+++ src/sys/ufs/ffs/ffs_vfsops.c	Sun Jan 28 10:02:00 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.355 2017/11/15 21:21:18 christos Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.356 2018/01/28 10:02:00 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.355 2017/11/15 21:21:18 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.356 2018/01/28 10:02:00 hannken Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -2024,14 +2024,14 @@ ffs_deinit_vnode(struct ufsmount *ump, s
 {
 	struct inode *ip = VTOI(vp);
 
+	genfs_node_destroy(vp);
+	vp->v_data = NULL;
+
 	if (ump->um_fstype == UFS1)
 		pool_cache_put(ffs_dinode1_cache, ip->i_din.ffs1_din);
 	else
 		pool_cache_put(ffs_dinode2_cache, ip->i_din.ffs2_din);
 	pool_cache_put(ffs_inode_cache, ip);
-
-	genfs_node_destroy(vp);
-	vp->v_data = NULL;
 }
 
 /*



CVS commit: src/sys/ufs/ufs

2018-01-28 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sun Jan 28 10:01:18 UTC 2018

Modified Files:
src/sys/ufs/ufs: ufs_inode.c

Log Message:
Make sure inode blocks and size are zero when VOP_INACTIVE()
finalises a now unlinked inode.
Counterpart of the check in ffs_newvnode().


To generate a diff of this commit:
cvs rdiff -u -r1.102 -r1.103 src/sys/ufs/ufs/ufs_inode.c

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

Modified files:

Index: src/sys/ufs/ufs/ufs_inode.c
diff -u src/sys/ufs/ufs/ufs_inode.c:1.102 src/sys/ufs/ufs/ufs_inode.c:1.103
--- src/sys/ufs/ufs/ufs_inode.c:1.102	Sat Oct 28 00:37:13 2017
+++ src/sys/ufs/ufs/ufs_inode.c	Sun Jan 28 10:01:18 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_inode.c,v 1.102 2017/10/28 00:37:13 pgoyette Exp $	*/
+/*	$NetBSD: ufs_inode.c,v 1.103 2018/01/28 10:01:18 hannken Exp $	*/
 
 /*
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ufs_inode.c,v 1.102 2017/10/28 00:37:13 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_inode.c,v 1.103 2018/01/28 10:01:18 hannken Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -149,6 +149,15 @@ out:
 	 */
 	*ap->a_recycle = (ip->i_mode == 0);
 
+	if (ip->i_mode == 0 && (DIP(ip, size) != 0 || DIP(ip, blocks) != 0)) {
+		printf("%s: unlinked ino %" PRId64 " on \"%s\" has"
+		" non zero size %" PRIx64 " or blocks %" PRIx64
+		" with allerror %d\n",
+		__func__, ip->i_number, mp->mnt_stat.f_mntonname,
+		DIP(ip, size), DIP(ip, blocks), allerror);
+		panic("%s: dirty filesystem?", __func__);
+	}
+
 	return (allerror);
 }
 



CVS commit: src/usr.sbin/fssconfig

2017-12-21 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Thu Dec 21 15:52:19 UTC 2017

Modified Files:
src/usr.sbin/fssconfig: fssconfig.c

Log Message:
Use stat() information to decide if the backing store is a directory.
Depending on open() returning EISDIR fails for mount points.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/usr.sbin/fssconfig/fssconfig.c

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

Modified files:

Index: src/usr.sbin/fssconfig/fssconfig.c
diff -u src/usr.sbin/fssconfig/fssconfig.c:1.12 src/usr.sbin/fssconfig/fssconfig.c:1.13
--- src/usr.sbin/fssconfig/fssconfig.c:1.12	Sun Jul 31 02:13:26 2016
+++ src/usr.sbin/fssconfig/fssconfig.c	Thu Dec 21 15:52:19 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: fssconfig.c,v 1.12 2016/07/31 02:13:26 pgoyette Exp $	*/
+/*	$NetBSD: fssconfig.c,v 1.13 2017/12/21 15:52:19 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -130,16 +130,19 @@ config(int argc, char **argv)
 	prog_stat(argv[1], ) != 0)
 		err(1, "stat %s", argv[1]);
 	mountdev = sbuf.st_dev;
-	if (stat(argv[2], ) == 0 &&
-	S_ISREG(sbuf.st_mode) &&
-	sbuf.st_dev == mountdev) {
-		if ((sbuf.st_flags & SF_SNAPSHOT) == 0)
-			errx(1, "%s: exists and is not a snapshot", argv[2]);
-		if (argc != 3)
-			usage();
-		isreg = ispersistent = 1;
+	if (stat(argv[2], ) == 0) {
+		if (S_ISREG(sbuf.st_mode) && sbuf.st_dev == mountdev) {
+			if ((sbuf.st_flags & SF_SNAPSHOT) == 0)
+errx(1, "%s: exists and is not a snapshot",
+argv[2]);
+			if (argc != 3)
+usage();
+			isreg = ispersistent = 1;
 
-		goto configure;
+			goto configure;
+		} else if (S_ISDIR(sbuf.st_mode)) {
+			istmp = 1;
+		}
 	}
 
 	if (argc > 5)
@@ -155,18 +158,17 @@ config(int argc, char **argv)
 		bssize = (off_t)fsbuf.f_blocks*fsbuf.f_frsize;
 
 	/*
-	 * Create the backing store. If it is a directory, create a temporary
-	 * file and set the unlink flag.
+	 * Create the backing store.
 	 */
-	fd = prog_open(fss.fss_bstore, O_CREAT|O_TRUNC|O_WRONLY, 0600);
-	if (fd < 0) {
-		if (errno != EISDIR)
-			err(1, "create: %s", fss.fss_bstore);
-		snprintf(path, sizeof(path), "%s/XX", fss.fss_bstore);
-		if ((fd = mkstemp(path)) < 0)
-			err(1, "mkstemp: %s", path);
+	if (istmp) {
+		snprintf(path, sizeof(path), "%s/XX", argv[2]);
 		fss.fss_bstore = path;
-		istmp = 1;
+		fd = mkstemp(fss.fss_bstore);
+	} else {
+		fd = prog_open(fss.fss_bstore, O_CREAT|O_TRUNC|O_WRONLY, 0600);
+	}
+	if (fd < 0) {
+		err(1, "create: %s", fss.fss_bstore);
 	}
 	if (prog_fstat(fd, ) < 0)
 		err(1, "stat: %s", fss.fss_bstore);



CVS commit: src/sys/dev

2017-12-21 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Thu Dec 21 15:51:39 UTC 2017

Modified Files:
src/sys/dev: fss.c

Log Message:
Pass residual back to b_resid for persistent snapshots.


To generate a diff of this commit:
cvs rdiff -u -r1.102 -r1.103 src/sys/dev/fss.c

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

Modified files:

Index: src/sys/dev/fss.c
diff -u src/sys/dev/fss.c:1.102 src/sys/dev/fss.c:1.103
--- src/sys/dev/fss.c:1.102	Thu Dec 21 15:51:07 2017
+++ src/sys/dev/fss.c	Thu Dec 21 15:51:39 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: fss.c,v 1.102 2017/12/21 15:51:07 hannken Exp $	*/
+/*	$NetBSD: fss.c,v 1.103 2017/12/21 15:51:39 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fss.c,v 1.102 2017/12/21 15:51:07 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fss.c,v 1.103 2017/12/21 15:51:39 hannken Exp $");
 
 #include 
 #include 
@@ -89,7 +89,7 @@ static void fss_softc_free(struct fss_so
 static int fss_read_cluster(struct fss_softc *, u_int32_t);
 static void fss_bs_thread(void *);
 static int fss_bs_io(struct fss_softc *, fss_io_type,
-u_int32_t, off_t, int, void *);
+u_int32_t, off_t, int, void *, size_t *);
 static u_int32_t *fss_bs_indir(struct fss_softc *, u_int32_t);
 
 static kmutex_t fss_device_lock;	/* Protect all units. */
@@ -1009,7 +1009,7 @@ restart:
  */
 static int
 fss_bs_io(struct fss_softc *sc, fss_io_type rw,
-u_int32_t cl, off_t off, int len, void *data)
+u_int32_t cl, off_t off, int len, void *data, size_t *resid)
 {
 	int error;
 
@@ -1020,7 +1020,7 @@ fss_bs_io(struct fss_softc *sc, fss_io_t
 	error = vn_rdwr((rw == FSS_READ ? UIO_READ : UIO_WRITE), sc->sc_bs_vp,
 	data, len, off, UIO_SYSSPACE,
 	IO_ADV_ENCODE(POSIX_FADV_NOREUSE) | IO_NODELOCKED,
-	sc->sc_bs_lwp->l_cred, NULL, NULL);
+	sc->sc_bs_lwp->l_cred, resid, NULL);
 	if (error == 0) {
 		mutex_enter(sc->sc_bs_vp->v_interlock);
 		error = VOP_PUTPAGES(sc->sc_bs_vp, trunc_page(off),
@@ -1049,7 +1049,7 @@ fss_bs_indir(struct fss_softc *sc, u_int
 
 	if (sc->sc_indir_dirty) {
 		if (fss_bs_io(sc, FSS_WRITE, sc->sc_indir_cur, 0,
-		FSS_CLSIZE(sc), (void *)sc->sc_indir_data) != 0)
+		FSS_CLSIZE(sc), (void *)sc->sc_indir_data, NULL) != 0)
 			return NULL;
 		setbit(sc->sc_indir_valid, sc->sc_indir_cur);
 	}
@@ -1059,7 +1059,7 @@ fss_bs_indir(struct fss_softc *sc, u_int
 
 	if (isset(sc->sc_indir_valid, sc->sc_indir_cur)) {
 		if (fss_bs_io(sc, FSS_READ, sc->sc_indir_cur, 0,
-		FSS_CLSIZE(sc), (void *)sc->sc_indir_data) != 0)
+		FSS_CLSIZE(sc), (void *)sc->sc_indir_data, NULL) != 0)
 			return NULL;
 	} else
 		memset(sc->sc_indir_data, 0, FSS_CLSIZE(sc));
@@ -1080,6 +1080,7 @@ fss_bs_thread(void *arg)
 	long off;
 	char *addr;
 	u_int32_t c, cl, ch, *indirp;
+	size_t resid;
 	struct buf *bp, *nbp;
 	struct fss_softc *sc;
 	struct fss_cache *scp, *scl;
@@ -1116,14 +1117,18 @@ fss_bs_thread(void *arg)
 disk_busy(sc->sc_dkdev);
 error = fss_bs_io(sc, FSS_READ, 0,
 dbtob(bp->b_blkno), bp->b_bcount,
-bp->b_data);
+bp->b_data, );
+if (error)
+	resid = bp->b_bcount;
 disk_unbusy(sc->sc_dkdev,
 (error ? 0 : bp->b_bcount), is_read);
-			} else
+			} else {
 error = ENXIO;
+resid = bp->b_bcount;
+			}
 
 			bp->b_error = error;
-			bp->b_resid = (error ? bp->b_bcount : 0);
+			bp->b_resid = resid;
 			biodone(bp);
 
 			mutex_enter(>sc_slock);
@@ -1144,7 +1149,7 @@ fss_bs_thread(void *arg)
 			indirp = fss_bs_indir(sc, scp->fc_cluster);
 			if (indirp != NULL) {
 error = fss_bs_io(sc, FSS_WRITE, sc->sc_clnext,
-0, FSS_CLSIZE(sc), scp->fc_data);
+0, FSS_CLSIZE(sc), scp->fc_data, NULL);
 			} else
 error = EIO;
 
@@ -1265,8 +1270,8 @@ fss_bs_thread(void *arg)
 			/*
 			 * Read from backing store.
 			 */
-			error =
-			fss_bs_io(sc, FSS_READ, *indirp, off, len, addr);
+			error = fss_bs_io(sc, FSS_READ,
+			*indirp, off, len, addr, NULL);
 
 			mutex_enter(>sc_slock);
 			if (error) {



CVS commit: src/sys/dev

2017-12-21 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Thu Dec 21 15:51:07 UTC 2017

Modified Files:
src/sys/dev: fss.c

Log Message:
Bounds check against media size for non-persistent snapshots.


To generate a diff of this commit:
cvs rdiff -u -r1.101 -r1.102 src/sys/dev/fss.c

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

Modified files:

Index: src/sys/dev/fss.c
diff -u src/sys/dev/fss.c:1.101 src/sys/dev/fss.c:1.102
--- src/sys/dev/fss.c:1.101	Thu Dec 21 15:50:33 2017
+++ src/sys/dev/fss.c	Thu Dec 21 15:51:07 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: fss.c,v 1.101 2017/12/21 15:50:33 hannken Exp $	*/
+/*	$NetBSD: fss.c,v 1.102 2017/12/21 15:51:07 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fss.c,v 1.101 2017/12/21 15:50:33 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fss.c,v 1.102 2017/12/21 15:51:07 hannken Exp $");
 
 #include 
 #include 
@@ -280,20 +280,26 @@ fss_strategy(struct buf *bp)
 	mutex_enter(>sc_slock);
 
 	if (write || !FSS_ISVALID(sc)) {
-
-		mutex_exit(>sc_slock);
-
 		bp->b_error = (write ? EROFS : ENXIO);
-		bp->b_resid = bp->b_bcount;
-		biodone(bp);
-		return;
+		goto done;
 	}
+	/* Check bounds for non-persistent snapshots. */
+	if ((sc->sc_flags & FSS_PERSISTENT) == 0 &&
+	bounds_check_with_mediasize(bp, DEV_BSIZE,
+	btodb(FSS_CLTOB(sc, sc->sc_clcount - 1) + sc->sc_clresid)) <= 0)
+		goto done;
 
 	bp->b_rawblkno = bp->b_blkno;
 	bufq_put(sc->sc_bufq, bp);
 	cv_signal(>sc_work_cv);
 
 	mutex_exit(>sc_slock);
+	return;
+
+done:
+	mutex_exit(>sc_slock);
+	bp->b_resid = bp->b_bcount;
+	biodone(bp);
 }
 
 int



CVS commit: src/sys/dev

2017-12-21 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Thu Dec 21 15:50:33 UTC 2017

Modified Files:
src/sys/dev: fss.c

Log Message:
Treat partial read from backing store as I/O error.


To generate a diff of this commit:
cvs rdiff -u -r1.100 -r1.101 src/sys/dev/fss.c

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

Modified files:

Index: src/sys/dev/fss.c
diff -u src/sys/dev/fss.c:1.100 src/sys/dev/fss.c:1.101
--- src/sys/dev/fss.c:1.100	Sun Dec 17 22:09:47 2017
+++ src/sys/dev/fss.c	Thu Dec 21 15:50:33 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: fss.c,v 1.100 2017/12/17 22:09:47 pgoyette Exp $	*/
+/*	$NetBSD: fss.c,v 1.101 2017/12/21 15:50:33 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fss.c,v 1.100 2017/12/17 22:09:47 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fss.c,v 1.101 2017/12/21 15:50:33 hannken Exp $");
 
 #include 
 #include 
@@ -980,6 +980,8 @@ restart:
 		todo -= len;
 	}
 	error = biowait(mbp);
+	if (error == 0 && mbp->b_resid != 0)
+		error = EIO;
 	putiobuf(mbp);
 
 	mutex_enter(>sc_slock);
@@ -1204,6 +1206,8 @@ fss_bs_thread(void *arg)
 			bdev_strategy(nbp);
 
 			error = biowait(nbp);
+			if (error == 0 && nbp->b_resid != 0)
+error = EIO;
 			if (error != 0) {
 bp->b_resid = bp->b_bcount;
 bp->b_error = nbp->b_error;



CVS commit: src/sys/arch/i386/conf

2017-12-10 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sun Dec 10 17:52:13 UTC 2017

Modified Files:
src/sys/arch/i386/conf: ALL

Log Message:
Add option XHCI_DEBUG.


To generate a diff of this commit:
cvs rdiff -u -r1.432 -r1.433 src/sys/arch/i386/conf/ALL

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

Modified files:

Index: src/sys/arch/i386/conf/ALL
diff -u src/sys/arch/i386/conf/ALL:1.432 src/sys/arch/i386/conf/ALL:1.433
--- src/sys/arch/i386/conf/ALL:1.432	Sun Dec 10 17:19:48 2017
+++ src/sys/arch/i386/conf/ALL	Sun Dec 10 17:52:13 2017
@@ -1,4 +1,4 @@
-# $NetBSD: ALL,v 1.432 2017/12/10 17:19:48 bouyer Exp $
+# $NetBSD: ALL,v 1.433 2017/12/10 17:52:13 hannken Exp $
 # From NetBSD: GENERIC,v 1.787 2006/10/01 18:37:54 bouyer Exp
 #
 # ALL machine description file
@@ -17,7 +17,7 @@ include 	"arch/i386/conf/std.i386"
 
 options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
 
-#ident		"ALL-$Revision: 1.432 $"
+#ident		"ALL-$Revision: 1.433 $"
 
 maxusers	64		# estimated number of users
 
@@ -2531,6 +2531,7 @@ options XENNET_DEBUG
 options XENNET_DEBUG_DUMP
 options XEN_CLOCK_DEBUG
 options XE_DEBUG
+options XHCI_DEBUG
 options ENDEBUG_LOW
 options XYC_DEBUG
 options ZSKBD_DEBUG



CVS commit: src/sys/dev/usb

2017-12-10 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sun Dec 10 17:50:01 UTC 2017

Modified Files:
src/sys/dev/usb: xhci.c

Log Message:
Use USB_DEBUG, not XHCI_DEBUG to protect `dci', DPRINTFN() always uses it.


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 src/sys/dev/usb/xhci.c

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

Modified files:

Index: src/sys/dev/usb/xhci.c
diff -u src/sys/dev/usb/xhci.c:1.80 src/sys/dev/usb/xhci.c:1.81
--- src/sys/dev/usb/xhci.c:1.80	Sat Dec  9 00:54:31 2017
+++ src/sys/dev/usb/xhci.c	Sun Dec 10 17:50:01 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: xhci.c,v 1.80 2017/12/09 00:54:31 christos Exp $	*/
+/*	$NetBSD: xhci.c,v 1.81 2017/12/10 17:50:01 hannken Exp $	*/
 
 /*
  * Copyright (c) 2013 Jonathan A. Kollasch
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.80 2017/12/09 00:54:31 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.81 2017/12/10 17:50:01 hannken Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -1341,7 +1341,7 @@ xhci_configure_endpoint(struct usbd_pipe
 {
 	struct xhci_softc * const sc = XHCI_PIPE2SC(pipe);
 	struct xhci_slot * const xs = pipe->up_dev->ud_hcpriv;
-#ifdef XHCI_DEBUG
+#ifdef USB_DEBUG
 	const u_int dci = xhci_ep_get_dci(pipe->up_endpoint->ue_edesc);
 #endif
 	struct xhci_trb trb;



CVS commit: src/sys

2017-08-21 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Mon Aug 21 09:00:21 UTC 2017

Modified Files:
src/sys/kern: vfs_mount.c vfs_vnode.c
src/sys/sys: vnode_impl.h

Log Message:
Change forced unmount to revert open device vnodes to anonymous devices.


To generate a diff of this commit:
cvs rdiff -u -r1.66 -r1.67 src/sys/kern/vfs_mount.c
cvs rdiff -u -r1.97 -r1.98 src/sys/kern/vfs_vnode.c
cvs rdiff -u -r1.15 -r1.16 src/sys/sys/vnode_impl.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/vfs_mount.c
diff -u src/sys/kern/vfs_mount.c:1.66 src/sys/kern/vfs_mount.c:1.67
--- src/sys/kern/vfs_mount.c:1.66	Sun Jun  4 08:05:42 2017
+++ src/sys/kern/vfs_mount.c	Mon Aug 21 09:00:21 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_mount.c,v 1.66 2017/06/04 08:05:42 hannken Exp $	*/
+/*	$NetBSD: vfs_mount.c,v 1.67 2017/08/21 09:00:21 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1997-2011 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.66 2017/06/04 08:05:42 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.67 2017/08/21 09:00:21 hannken Exp $");
 
 #include 
 #include 
@@ -558,9 +558,16 @@ vflush_one(vnode_t *vp, vnode_t *skipvp,
 		return 0;
 	/*
 	 * If FORCECLOSE is set, forcibly close the vnode.
+	 * For block or character devices, revert to an
+	 * anonymous device.  For all other files, just
+	 * kill them.
 	 */
 	if (flags & FORCECLOSE) {
-		vgone(vp);
+		if (vp->v_usecount > 1 &&
+		(vp->v_type == VBLK || vp->v_type == VCHR))
+			vcache_make_anon(vp);
+		else
+			vgone(vp);
 		return 0;
 	}
 	vrele(vp);

Index: src/sys/kern/vfs_vnode.c
diff -u src/sys/kern/vfs_vnode.c:1.97 src/sys/kern/vfs_vnode.c:1.98
--- src/sys/kern/vfs_vnode.c:1.97	Mon Aug 21 08:56:45 2017
+++ src/sys/kern/vfs_vnode.c	Mon Aug 21 09:00:21 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_vnode.c,v 1.97 2017/08/21 08:56:45 hannken Exp $	*/
+/*	$NetBSD: vfs_vnode.c,v 1.98 2017/08/21 09:00:21 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1997-2011 The NetBSD Foundation, Inc.
@@ -156,7 +156,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.97 2017/08/21 08:56:45 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.98 2017/08/21 09:00:21 hannken Exp $");
 
 #include 
 #include 
@@ -225,6 +225,7 @@ static void		vnpanic(vnode_t *, const ch
 /* Routines having to do with the management of the vnode table. */
 extern struct mount	*dead_rootmount;
 extern int		(**dead_vnodeop_p)(void *);
+extern int		(**spec_vnodeop_p)(void *);
 extern struct vfsops	dead_vfsops;
 
 /* Vnode state operations and diagnostics. */
@@ -1650,6 +1651,72 @@ vcache_reclaim(vnode_t *vp)
 }
 
 /*
+ * Disassociate the underlying file system from an open device vnode
+ * and make it anonymous.
+ *
+ * Vnode unlocked on entry, drops a reference to the vnode.
+ */
+void
+vcache_make_anon(vnode_t *vp)
+{
+	vnode_impl_t *vip = VNODE_TO_VIMPL(vp);
+	uint32_t hash;
+	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));
+	VSTATE_ASSERT_UNLOCKED(vp, VS_ACTIVE);
+
+	/* Remove from vnode cache. */
+	hash = vcache_hash(>vi_key);
+	mutex_enter(_lock);
+	KASSERT(vip == vcache_hash_lookup(>vi_key, hash));
+	SLIST_REMOVE(_hashtab[hash & vcache_hashmask],
+	vip, vnode_impl, vi_hash);
+	vip->vi_key.vk_mount = dead_rootmount;
+	vip->vi_key.vk_key_len = 0;
+	vip->vi_key.vk_key = NULL;
+	mutex_exit(_lock);
+
+	/*
+	 * Disassociate the underlying file system from the vnode.
+	 * VOP_INACTIVE leaves the vnode locked; VOP_RECLAIM unlocks
+	 * the vnode, and may destroy the vnode so that VOP_UNLOCK
+	 * would no longer function.
+	 */
+	if (vn_lock(vp, LK_EXCLUSIVE)) {
+		vnpanic(vp, "%s: cannot lock", __func__);
+	}
+	VOP_INACTIVE(vp, );
+	KASSERT((vp->v_vflag & VV_LOCKSWORK) == 0 ||
+	VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
+	if (VOP_RECLAIM(vp)) {
+		vnpanic(vp, "%s: cannot reclaim", __func__);
+	}
+
+	/* Purge name cache. */
+	cache_purge(vp);
+
+	/* Done with purge, change operations vector. */
+	mutex_enter(vp->v_interlock);
+	vp->v_op = spec_vnodeop_p;
+	vp->v_vflag |= VV_MPSAFE;
+	vp->v_vflag &= ~VV_LOCKSWORK;
+	mutex_exit(vp->v_interlock);
+
+	/*
+	 * Move to dead mount.  Must be after changing the operations
+	 * vector as vnode operations enter the mount before using the
+	 * operations vector.  See sys/kern/vnode_if.c.
+	 */
+	vfs_ref(dead_rootmount);
+	vfs_insmntque(vp, dead_rootmount);
+
+	vrele(vp);
+}
+
+/*
  * Update outstanding I/O count and do wakeup if requested.
  */
 void

Index: src/sys/sys/vnode_impl.h
diff -u src/sys/sys/vnode_impl.h:1.15 src/sys/sys/vnode_impl.h:1.16
--- src/sys/sys/vnode_impl.h:1.15	Sun Jun  4 08:02:26 2017
+++ src/sys/sys/vnode_impl.h	Mon Aug 21 09:00:21 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: vnode_impl.h,v 1.15 2017/06/04 08:02:26 hannken Exp $	*/
+/*	

CVS commit: src/sys

2017-08-21 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Mon Aug 21 08:56:45 UTC 2017

Modified Files:
src/sys/kern: vfs_vnode.c
src/sys/miscfs/deadfs: dead_vfsops.c

Log Message:
No need to cache anonymous device vnodes, they will never be looked up.

Set key to (dead_rootmount, 0, NULL) and add assertions.


To generate a diff of this commit:
cvs rdiff -u -r1.96 -r1.97 src/sys/kern/vfs_vnode.c
cvs rdiff -u -r1.7 -r1.8 src/sys/miscfs/deadfs/dead_vfsops.c

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

Modified files:

Index: src/sys/kern/vfs_vnode.c
diff -u src/sys/kern/vfs_vnode.c:1.96 src/sys/kern/vfs_vnode.c:1.97
--- src/sys/kern/vfs_vnode.c:1.96	Sun Jun  4 08:05:42 2017
+++ src/sys/kern/vfs_vnode.c	Mon Aug 21 08:56:45 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_vnode.c,v 1.96 2017/06/04 08:05:42 hannken Exp $	*/
+/*	$NetBSD: vfs_vnode.c,v 1.97 2017/08/21 08:56:45 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1997-2011 The NetBSD Foundation, Inc.
@@ -156,7 +156,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.96 2017/06/04 08:05:42 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.97 2017/08/21 08:56:45 hannken Exp $");
 
 #include 
 #include 
@@ -1028,6 +1028,8 @@ vcache_hash(const struct vcache_key *key
 {
 	uint32_t hash = HASH32_BUF_INIT;
 
+	KASSERT(key->vk_key_len > 0);
+
 	hash = hash32_buf(>vk_mount, sizeof(struct mount *), hash);
 	hash = hash32_buf(key->vk_key, key->vk_key_len, hash);
 	return hash;
@@ -1381,23 +1383,29 @@ vcache_new(struct mount *mp, struct vnod
 		KASSERT(*vpp == NULL);
 		return error;
 	}
-	KASSERT(vip->vi_key.vk_key != NULL);
 	KASSERT(vp->v_op != NULL);
-	hash = vcache_hash(>vi_key);
+	KASSERT((vip->vi_key.vk_key_len == 0) == (mp == dead_rootmount));
+	if (vip->vi_key.vk_key_len > 0) {
+		KASSERT(vip->vi_key.vk_key != NULL);
+		hash = vcache_hash(>vi_key);
 
-	/* Wait for previous instance to be reclaimed, then insert new node. */
-	mutex_enter(_lock);
-	while ((ovip = vcache_hash_lookup(>vi_key, hash))) {
-		ovp = VIMPL_TO_VNODE(ovip);
-		mutex_enter(ovp->v_interlock);
-		mutex_exit(_lock);
-		error = vcache_vget(ovp);
-		KASSERT(error == ENOENT);
+		/*
+		 * Wait for previous instance to be reclaimed,
+		 * then insert new node.
+		 */
 		mutex_enter(_lock);
+		while ((ovip = vcache_hash_lookup(>vi_key, hash))) {
+			ovp = VIMPL_TO_VNODE(ovip);
+			mutex_enter(ovp->v_interlock);
+			mutex_exit(_lock);
+			error = vcache_vget(ovp);
+			KASSERT(error == ENOENT);
+			mutex_enter(_lock);
+		}
+		SLIST_INSERT_HEAD(_hashtab[hash & vcache_hashmask],
+		vip, vi_hash);
+		mutex_exit(_lock);
 	}
-	SLIST_INSERT_HEAD(_hashtab[hash & vcache_hashmask],
-	vip, vi_hash);
-	mutex_exit(_lock);
 	vfs_insmntque(vp, mp);
 	if ((mp->mnt_iflag & IMNT_MPSAFE) != 0)
 		vp->v_vflag |= VV_MPSAFE;
@@ -1556,10 +1564,12 @@ vcache_reclaim(vnode_t *vp)
 	} else {
 		temp_key = temp_buf;
 	}
-	mutex_enter(_lock);
-	memcpy(temp_key, vip->vi_key.vk_key, temp_key_len);
-	vip->vi_key.vk_key = temp_key;
-	mutex_exit(_lock);
+	if (vip->vi_key.vk_key_len > 0) {
+		mutex_enter(_lock);
+		memcpy(temp_key, vip->vi_key.vk_key, temp_key_len);
+		vip->vi_key.vk_key = temp_key;
+		mutex_exit(_lock);
+	}
 
 	fstrans_start(mp);
 
@@ -1604,13 +1614,15 @@ vcache_reclaim(vnode_t *vp)
 	/* Purge name cache. */
 	cache_purge(vp);
 
+	if (vip->vi_key.vk_key_len > 0) {
 	/* Remove from vnode cache. */
-	hash = vcache_hash(>vi_key);
-	mutex_enter(_lock);
-	KASSERT(vip == vcache_hash_lookup(>vi_key, hash));
-	SLIST_REMOVE(_hashtab[hash & vcache_hashmask],
-	vip, vnode_impl, vi_hash);
-	mutex_exit(_lock);
+		hash = vcache_hash(>vi_key);
+		mutex_enter(_lock);
+		KASSERT(vip == vcache_hash_lookup(>vi_key, hash));
+		SLIST_REMOVE(_hashtab[hash & vcache_hashmask],
+		vip, vnode_impl, vi_hash);
+		mutex_exit(_lock);
+	}
 	if (temp_key != temp_buf)
 		kmem_free(temp_key, temp_key_len);
 

Index: src/sys/miscfs/deadfs/dead_vfsops.c
diff -u src/sys/miscfs/deadfs/dead_vfsops.c:1.7 src/sys/miscfs/deadfs/dead_vfsops.c:1.8
--- src/sys/miscfs/deadfs/dead_vfsops.c:1.7	Wed Jul  1 08:13:53 2015
+++ src/sys/miscfs/deadfs/dead_vfsops.c	Mon Aug 21 08:56:45 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: dead_vfsops.c,v 1.7 2015/07/01 08:13:53 hannken Exp $	*/
+/*	$NetBSD: dead_vfsops.c,v 1.8 2017/08/21 08:56:45 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dead_vfsops.c,v 1.7 2015/07/01 08:13:53 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dead_vfsops.c,v 1.8 2017/08/21 08:56:45 hannken Exp $");
 
 #include 
 #include 
@@ -108,8 +108,8 @@ dead_newvnode(struct mount *mp, struct v
 	uvm_vnp_setsize(vp, 0);
 	spec_node_init(vp, vap->va_rdev);
 
-	*key_len = sizeof(vp->v_interlock);
-	*new_key = >v_interlock;
+	*key_len = 0;
+	*new_key = NULL;
 
 	return 0;
 }



CVS commit: src/distrib/sparc64/xminiroot

2017-07-17 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Mon Jul 17 14:36:13 UTC 2017

Modified Files:
src/distrib/sparc64/xminiroot: Makefile

Log Message:
Bump image size.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/distrib/sparc64/xminiroot/Makefile

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

Modified files:

Index: src/distrib/sparc64/xminiroot/Makefile
diff -u src/distrib/sparc64/xminiroot/Makefile:1.33 src/distrib/sparc64/xminiroot/Makefile:1.34
--- src/distrib/sparc64/xminiroot/Makefile:1.33	Sun Aug 10 14:42:33 2014
+++ src/distrib/sparc64/xminiroot/Makefile	Mon Jul 17 14:36:13 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.33 2014/08/10 14:42:33 martin Exp $
+#	$NetBSD: Makefile,v 1.34 2017/07/17 14:36:13 hannken Exp $
 
 .include 
 .include "${NETBSDSRCDIR}/distrib/common/Makefile.distrib"
@@ -7,7 +7,7 @@
 
 .include "${.CURDIR}/../instfs/Makefile.instfs"
 IMAGE=		miniroot.fs
-NUMCYLS=	13 	# size of image in MB, tune this if we need more space
+NUMCYLS=	14 	# size of image in MB, tune this if we need more space
 SECSPERCYL=	2048
 CYLSIZE=	$$(( ${SECSPERCYL} * 512 ))
 IMAGESIZE=	$$(( ${NUMCYLS} * ${CYLSIZE} ))



CVS commit: src/sys/fs/union

2017-07-17 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Mon Jul 17 09:22:36 UTC 2017

Modified Files:
src/sys/fs/union: union.h union_subr.c

Log Message:
Make union_newlower() ans union_newupper() local to union_subr.c,
expand and remove union_updatevp() and take care to transfer the
vnode lock from the union vnode to its new upper vnode without
breaking the fstrans state.

Add assertions that un_lowervp and un_uppervp never change from
non-NULL to non-NULL.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/fs/union/union.h
cvs rdiff -u -r1.75 -r1.76 src/sys/fs/union/union_subr.c

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

Modified files:

Index: src/sys/fs/union/union.h
diff -u src/sys/fs/union/union.h:1.28 src/sys/fs/union/union.h:1.29
--- src/sys/fs/union/union.h:1.28	Mon Feb 16 10:22:00 2015
+++ src/sys/fs/union/union.h	Mon Jul 17 09:22:36 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: union.h,v 1.28 2015/02/16 10:22:00 hannken Exp $	*/
+/*	$NetBSD: union.h,v 1.29 2017/07/17 09:22:36 hannken Exp $	*/
 
 /*
  * Copyright (c) 1994 The Regents of the University of California.
@@ -158,8 +158,6 @@ extern int union_cn_close(struct vnode *
 struct lwp *);
 extern void union_removed_upper(struct union_node *un);
 extern struct vnode *union_lowervp(struct vnode *);
-extern void union_newlower(struct union_node *, struct vnode *);
-extern void union_newupper(struct union_node *, struct vnode *);
 extern void union_newsize(struct vnode *, off_t, off_t);
 int union_readdirhook(struct vnode **, struct file *, struct lwp *);
 

Index: src/sys/fs/union/union_subr.c
diff -u src/sys/fs/union/union_subr.c:1.75 src/sys/fs/union/union_subr.c:1.76
--- src/sys/fs/union/union_subr.c:1.75	Thu Jun  1 02:45:13 2017
+++ src/sys/fs/union/union_subr.c	Mon Jul 17 09:22:36 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: union_subr.c,v 1.75 2017/06/01 02:45:13 chs Exp $	*/
+/*	$NetBSD: union_subr.c,v 1.76 2017/07/17 09:22:36 hannken Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -72,7 +72,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: union_subr.c,v 1.75 2017/06/01 02:45:13 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: union_subr.c,v 1.76 2017/07/17 09:22:36 hannken Exp $");
 
 #include 
 #include 
@@ -104,7 +104,8 @@ static u_long uhash_mask;		/* size of ha
 
 static kmutex_t uhash_lock;
 
-void union_updatevp(struct union_node *, struct vnode *, struct vnode *);
+static void union_newupper(struct union_node *, struct vnode *);
+static void union_newlower(struct union_node *, struct vnode *);
 static void union_ref(struct union_node *);
 static void union_rele(struct union_node *);
 static int union_do_lookup(struct vnode *, struct componentname *, kauth_cred_t,const char *);
@@ -160,71 +161,28 @@ union_done(void)
 }
 
 void
-union_updatevp(struct union_node *un, struct vnode *uppervp,
-	struct vnode *lowervp)
+union_newlower(struct union_node *un, struct vnode *lowervp)
 {
 	int ohash = UNION_HASH(un->un_uppervp, un->un_lowervp);
-	int nhash = UNION_HASH(uppervp, lowervp);
-	int docache = (lowervp != NULLVP || uppervp != NULLVP);
-	bool un_unlock;
+	int nhash = UNION_HASH(un->un_uppervp, lowervp);
+
+	if (un->un_lowervp == lowervp)
+		return;
 
 	KASSERT(VOP_ISLOCKED(UNIONTOV(un)) == LK_EXCLUSIVE);
+	KASSERT(un->un_lowervp == NULL);
 
 	mutex_enter(_lock);
 
-	if (!docache || ohash != nhash) {
-		if (un->un_cflags & UN_CACHED) {
-			un->un_cflags &= ~UN_CACHED;
-			LIST_REMOVE(un, un_cache);
-		}
-	}
-
-	if (un->un_lowervp != lowervp) {
-		if (un->un_lowervp) {
-			vrele(un->un_lowervp);
-			if (un->un_path) {
-free(un->un_path, M_TEMP);
-un->un_path = 0;
-			}
-			if (un->un_dirvp) {
-vrele(un->un_dirvp);
-un->un_dirvp = NULLVP;
-			}
-		}
-		un->un_lowervp = lowervp;
-		mutex_enter(>un_lock);
-		un->un_lowersz = VNOVAL;
-		mutex_exit(>un_lock);
-	}
-
-	if (un->un_uppervp != uppervp) {
-		if (un->un_uppervp) {
-			un_unlock = false;
-			vrele(un->un_uppervp);
-		} else
-			un_unlock = true;
-
-		mutex_enter(>un_lock);
-		un->un_uppervp = uppervp;
-		mutex_exit(>un_lock);
-		if (un_unlock) {
-			struct vop_unlock_args ap;
-
-			ap.a_vp = UNIONTOV(un);
-			genfs_unlock();
-		}
-		mutex_enter(>un_lock);
-		un->un_uppersz = VNOVAL;
-		mutex_exit(>un_lock);
-		/* Update union vnode interlock. */
-		if (uppervp != NULL) {
-			mutex_obj_hold(uppervp->v_interlock);
-			uvm_obj_setlock((un)->v_uobj,
-			uppervp->v_interlock);
-		}
+	if (ohash != nhash && (un->un_cflags & UN_CACHED)) {
+		un->un_cflags &= ~UN_CACHED;
+		LIST_REMOVE(un, un_cache);
 	}
-
-	if (docache && (ohash != nhash)) {
+	mutex_enter(>un_lock);
+	un->un_lowervp = lowervp;
+	un->un_lowersz = VNOVAL;
+	mutex_exit(>un_lock);
+	if (ohash != nhash) {
 		LIST_INSERT_HEAD([nhash], un, un_cache);
 		un->un_cflags |= UN_CACHED;
 	}
@@ -233,17 +191,57 @@ union_updatevp(struct union_node *un, st
 }
 
 void
-union_newlower(struct union_node *un, struct vnode *lowervp)

CVS commit: src/sys

2017-07-12 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed Jul 12 09:32:00 UTC 2017

Modified Files:
src/sys/kern: vnode_if.c
src/sys/rump/include/rump: rumpvnode_if.h
src/sys/rump/librump/rumpvfs: rumpvnode_if.c
src/sys/sys: vnode_if.h

Log Message:
Regen.


To generate a diff of this commit:
cvs rdiff -u -r1.106 -r1.107 src/sys/kern/vnode_if.c
cvs rdiff -u -r1.30 -r1.31 src/sys/rump/include/rump/rumpvnode_if.h
cvs rdiff -u -r1.30 -r1.31 src/sys/rump/librump/rumpvfs/rumpvnode_if.c
cvs rdiff -u -r1.101 -r1.102 src/sys/sys/vnode_if.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/vnode_if.c
diff -u src/sys/kern/vnode_if.c:1.106 src/sys/kern/vnode_if.c:1.107
--- src/sys/kern/vnode_if.c:1.106	Sun Jun  4 08:05:42 2017
+++ src/sys/kern/vnode_if.c	Wed Jul 12 09:31:59 2017
@@ -1,11 +1,11 @@
-/*	$NetBSD: vnode_if.c,v 1.106 2017/06/04 08:05:42 hannken Exp $	*/
+/*	$NetBSD: vnode_if.c,v 1.107 2017/07/12 09:31:59 hannken Exp $	*/
 
 /*
  * Warning: DO NOT EDIT! This file is automatically generated!
  * (Modifications made here may easily be lost!)
  *
  * Created from the file:
- *	NetBSD: vnode_if.src,v 1.76 2017/06/04 07:59:17 hannken Exp
+ *	NetBSD: vnode_if.src,v 1.77 2017/07/12 09:31:07 hannken Exp
  * by the script:
  *	NetBSD: vnode_if.sh,v 1.66 2017/06/04 08:03:26 hannken Exp
  */
@@ -40,7 +40,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vnode_if.c,v 1.106 2017/06/04 08:05:42 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vnode_if.c,v 1.107 2017/07/12 09:31:59 hannken Exp $");
 
 #include 
 #include 
@@ -1510,11 +1510,11 @@ VOP_ADVLOCK(struct vnode *vp,
 	a.a_op = op;
 	a.a_fl = fl;
 	a.a_flags = flags;
-	error = vop_pre(vp, , , FST_YES);
+	error = vop_pre(vp, , , FST_NO);
 	if (error)
 		return error;
 	error = (VCALL(vp, VOFFSET(vop_advlock), ));
-	vop_post(vp, mp, mpsafe, FST_YES);
+	vop_post(vp, mp, mpsafe, FST_NO);
 	return error;
 }
 

Index: src/sys/rump/include/rump/rumpvnode_if.h
diff -u src/sys/rump/include/rump/rumpvnode_if.h:1.30 src/sys/rump/include/rump/rumpvnode_if.h:1.31
--- src/sys/rump/include/rump/rumpvnode_if.h:1.30	Sun Jun  4 08:05:42 2017
+++ src/sys/rump/include/rump/rumpvnode_if.h	Wed Jul 12 09:31:59 2017
@@ -1,11 +1,11 @@
-/*	$NetBSD: rumpvnode_if.h,v 1.30 2017/06/04 08:05:42 hannken Exp $	*/
+/*	$NetBSD: rumpvnode_if.h,v 1.31 2017/07/12 09:31:59 hannken Exp $	*/
 
 /*
  * Warning: DO NOT EDIT! This file is automatically generated!
  * (Modifications made here may easily be lost!)
  *
  * Created from the file:
- *	NetBSD: vnode_if.src,v 1.76 2017/06/04 07:59:17 hannken Exp
+ *	NetBSD: vnode_if.src,v 1.77 2017/07/12 09:31:07 hannken Exp
  * by the script:
  *	NetBSD: vnode_if.sh,v 1.66 2017/06/04 08:03:26 hannken Exp
  */

Index: src/sys/rump/librump/rumpvfs/rumpvnode_if.c
diff -u src/sys/rump/librump/rumpvfs/rumpvnode_if.c:1.30 src/sys/rump/librump/rumpvfs/rumpvnode_if.c:1.31
--- src/sys/rump/librump/rumpvfs/rumpvnode_if.c:1.30	Sun Jun  4 08:05:42 2017
+++ src/sys/rump/librump/rumpvfs/rumpvnode_if.c	Wed Jul 12 09:31:59 2017
@@ -1,11 +1,11 @@
-/*	$NetBSD: rumpvnode_if.c,v 1.30 2017/06/04 08:05:42 hannken Exp $	*/
+/*	$NetBSD: rumpvnode_if.c,v 1.31 2017/07/12 09:31:59 hannken Exp $	*/
 
 /*
  * Warning: DO NOT EDIT! This file is automatically generated!
  * (Modifications made here may easily be lost!)
  *
  * Created from the file:
- *	NetBSD: vnode_if.src,v 1.76 2017/06/04 07:59:17 hannken Exp
+ *	NetBSD: vnode_if.src,v 1.77 2017/07/12 09:31:07 hannken Exp
  * by the script:
  *	NetBSD: vnode_if.sh,v 1.66 2017/06/04 08:03:26 hannken Exp
  */
@@ -40,7 +40,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: rumpvnode_if.c,v 1.30 2017/06/04 08:05:42 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rumpvnode_if.c,v 1.31 2017/07/12 09:31:59 hannken Exp $");
 
 #include 
 #include 

Index: src/sys/sys/vnode_if.h
diff -u src/sys/sys/vnode_if.h:1.101 src/sys/sys/vnode_if.h:1.102
--- src/sys/sys/vnode_if.h:1.101	Sun Jun  4 08:05:42 2017
+++ src/sys/sys/vnode_if.h	Wed Jul 12 09:32:00 2017
@@ -1,11 +1,11 @@
-/*	$NetBSD: vnode_if.h,v 1.101 2017/06/04 08:05:42 hannken Exp $	*/
+/*	$NetBSD: vnode_if.h,v 1.102 2017/07/12 09:32:00 hannken Exp $	*/
 
 /*
  * Warning: DO NOT EDIT! This file is automatically generated!
  * (Modifications made here may easily be lost!)
  *
  * Created from the file:
- *	NetBSD: vnode_if.src,v 1.76 2017/06/04 07:59:17 hannken Exp
+ *	NetBSD: vnode_if.src,v 1.77 2017/07/12 09:31:07 hannken Exp
  * by the script:
  *	NetBSD: vnode_if.sh,v 1.66 2017/06/04 08:03:26 hannken Exp
  */



CVS commit: src/sys/kern

2017-07-12 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed Jul 12 09:31:07 UTC 2017

Modified Files:
src/sys/kern: vnode_if.src

Log Message:
As VOP_ADVLOCK() may block indefinitely we cannot take fstrans here.

Fixes PR kern/52364: System hangs not much before showing the login prompt


To generate a diff of this commit:
cvs rdiff -u -r1.76 -r1.77 src/sys/kern/vnode_if.src

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/vnode_if.src
diff -u src/sys/kern/vnode_if.src:1.76 src/sys/kern/vnode_if.src:1.77
--- src/sys/kern/vnode_if.src:1.76	Sun Jun  4 07:59:17 2017
+++ src/sys/kern/vnode_if.src	Wed Jul 12 09:31:07 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: vnode_if.src,v 1.76 2017/06/04 07:59:17 hannken Exp $
+#	$NetBSD: vnode_if.src,v 1.77 2017/07/12 09:31:07 hannken Exp $
 #
 # Copyright (c) 1992, 1993
 #	The Regents of the University of California.  All rights reserved.
@@ -468,6 +468,7 @@ vop_pathconf {
 #% advlockvp  U U U
 #
 vop_advlock {
+	FSTRANS=NO
 	IN LOCKED=NO struct vnode *vp;
 	IN void *id;
 	IN int op;



CVS commit: src/sys/ufs/ffs

2017-07-12 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed Jul 12 09:30:16 UTC 2017

Modified Files:
src/sys/ufs/ffs: ffs_alloc.c

Log Message:
When initializing more inodes make sure to write them to disk
before writing the cylinder group with updated cg_initediblk.


To generate a diff of this commit:
cvs rdiff -u -r1.156 -r1.157 src/sys/ufs/ffs/ffs_alloc.c

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

Modified files:

Index: src/sys/ufs/ffs/ffs_alloc.c
diff -u src/sys/ufs/ffs/ffs_alloc.c:1.156 src/sys/ufs/ffs/ffs_alloc.c:1.157
--- src/sys/ufs/ffs/ffs_alloc.c:1.156	Sat Mar 18 05:20:04 2017
+++ src/sys/ufs/ffs/ffs_alloc.c	Wed Jul 12 09:30:16 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_alloc.c,v 1.156 2017/03/18 05:20:04 riastradh Exp $	*/
+/*	$NetBSD: ffs_alloc.c,v 1.157 2017/07/12 09:30:16 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.156 2017/03/18 05:20:04 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.157 2017/07/12 09:30:16 hannken Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -1379,8 +1379,8 @@ gotit:
 	}
 	mutex_exit(>um_lock);
 	if (ibp != NULL) {
+		bwrite(ibp);
 		bwrite(bp);
-		bawrite(ibp);
 	} else
 		bdwrite(bp);
 	return (cg * fs->fs_ipg + ipref);



CVS commit: src/sys/miscfs/genfs

2017-06-27 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Tue Jun 27 08:40:53 UTC 2017

Modified Files:
src/sys/miscfs/genfs: genfs_io.c

Log Message:
Add missing check for dead or dying vnode to the entry of genfs_getpages().


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 src/sys/miscfs/genfs/genfs_io.c

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

Modified files:

Index: src/sys/miscfs/genfs/genfs_io.c
diff -u src/sys/miscfs/genfs/genfs_io.c:1.69 src/sys/miscfs/genfs/genfs_io.c:1.70
--- src/sys/miscfs/genfs/genfs_io.c:1.69	Sun Jun  4 08:05:42 2017
+++ src/sys/miscfs/genfs/genfs_io.c	Tue Jun 27 08:40:53 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: genfs_io.c,v 1.69 2017/06/04 08:05:42 hannken Exp $	*/
+/*	$NetBSD: genfs_io.c,v 1.70 2017/06/27 08:40:53 hannken Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: genfs_io.c,v 1.69 2017/06/04 08:05:42 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: genfs_io.c,v 1.70 2017/06/27 08:40:53 hannken Exp $");
 
 #include 
 #include 
@@ -139,6 +139,13 @@ genfs_getpages(void *v)
 	KASSERT(vp->v_type == VREG || vp->v_type == VDIR ||
 	vp->v_type == VLNK || vp->v_type == VBLK);
 
+	error = vdead_check(vp, VDEAD_NOWAIT);
+	if (error) {
+		if ((flags & PGO_LOCKED) == 0)
+			mutex_exit(uobj->vmobjlock);
+		return error;
+	}
+
 startover:
 	error = 0;
 	const voff_t origvsize = vp->v_size;



CVS commit: src/sys/miscfs/specfs

2017-06-24 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sat Jun 24 12:14:21 UTC 2017

Modified Files:
src/sys/miscfs/specfs: spec_vnops.c

Log Message:
Refuse to open a block device with zero open count when it has
a mountpoint set.  This may happen after forced detach or unplug
of a mounted block device.


To generate a diff of this commit:
cvs rdiff -u -r1.173 -r1.174 src/sys/miscfs/specfs/spec_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/sys/miscfs/specfs/spec_vnops.c
diff -u src/sys/miscfs/specfs/spec_vnops.c:1.173 src/sys/miscfs/specfs/spec_vnops.c:1.174
--- src/sys/miscfs/specfs/spec_vnops.c:1.173	Thu Jun  1 02:45:14 2017
+++ src/sys/miscfs/specfs/spec_vnops.c	Sat Jun 24 12:14:21 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: spec_vnops.c,v 1.173 2017/06/01 02:45:14 chs Exp $	*/
+/*	$NetBSD: spec_vnops.c,v 1.174 2017/06/24 12:14:21 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -58,7 +58,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: spec_vnops.c,v 1.173 2017/06/01 02:45:14 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spec_vnops.c,v 1.174 2017/06/24 12:14:21 hannken Exp $");
 
 #include 
 #include 
@@ -580,13 +580,16 @@ spec_open(void *v)
 		 * For block devices, permit only one open.  The buffer
 		 * cache cannot remain self-consistent with multiple
 		 * vnodes holding a block device open.
+		 *
+		 * Treat zero opencnt with non-NULL mountpoint as open.
+		 * This may happen after forced detach of a mounted device.
 		 */
 		mutex_enter(_lock);
 		if (sn->sn_gone) {
 			mutex_exit(_lock);
 			return (EBADF);
 		}
-		if (sd->sd_opencnt != 0) {
+		if (sd->sd_opencnt != 0 || sd->sd_mountpoint != NULL) {
 			mutex_exit(_lock);
 			return EBUSY;
 		}



CVS commit: src/sys/fs/udf

2017-06-24 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sat Jun 24 12:13:16 UTC 2017

Modified Files:
src/sys/fs/udf: udf_vfsops.c

Log Message:
No need to call vflush from failing udf_mount().  If the system nodes
really have to disappear we should change vrele() to vrecycle() here.


To generate a diff of this commit:
cvs rdiff -u -r1.75 -r1.76 src/sys/fs/udf/udf_vfsops.c

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

Modified files:

Index: src/sys/fs/udf/udf_vfsops.c
diff -u src/sys/fs/udf/udf_vfsops.c:1.75 src/sys/fs/udf/udf_vfsops.c:1.76
--- src/sys/fs/udf/udf_vfsops.c:1.75	Sat Apr  1 19:35:56 2017
+++ src/sys/fs/udf/udf_vfsops.c	Sat Jun 24 12:13:16 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: udf_vfsops.c,v 1.75 2017/04/01 19:35:56 riastradh Exp $ */
+/* $NetBSD: udf_vfsops.c,v 1.76 2017/06/24 12:13:16 hannken Exp $ */
 
 /*
  * Copyright (c) 2006, 2008 Reinoud Zandijk
@@ -28,7 +28,7 @@
 
 #include 
 #ifndef lint
-__KERNEL_RCSID(0, "$NetBSD: udf_vfsops.c,v 1.75 2017/04/01 19:35:56 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: udf_vfsops.c,v 1.76 2017/06/24 12:13:16 hannken Exp $");
 #endif /* not lint */
 
 
@@ -277,7 +277,6 @@ static void
 udf_release_system_nodes(struct mount *mp)
 {
 	struct udf_mount *ump = VFSTOUDF(mp);
-	int error;
 
 	/* if we haven't even got an ump, dont bother */
 	if (!ump)
@@ -294,10 +293,6 @@ udf_release_system_nodes(struct mount *m
 		vrele(ump->metadatamirror_node->vnode);
 	if (ump->metadatabitmap_node)
 		vrele(ump->metadatabitmap_node->vnode);
-
-	/* This flush should NOT write anything nor allow any node to remain */
-	if ((error = vflush(ump->vfs_mountp, NULLVP, 0)) != 0)
-		panic("Failure to flush UDF system vnodes\n");
 }
 
 
@@ -520,6 +515,10 @@ udf_unmount(struct mount *mp, int mntfla
 	/* NOTE release system nodes should NOT write anything */
 	udf_release_system_nodes(mp);
 
+	/* This flush should NOT write anything nor allow any node to remain */
+	if ((error = vflush(ump->vfs_mountp, NULLVP, 0)) != 0)
+		panic("Failure to flush UDF system vnodes\n");
+
 	/* finalise disc strategy */
 	udf_discstrat_finish(ump);
 



CVS commit: src/sys/kern

2017-06-18 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sun Jun 18 14:00:18 UTC 2017

Modified Files:
src/sys/kern: vfs_trans.c

Log Message:
Make the fast path of fstrans_get_lwp_info() "static inline".


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/sys/kern/vfs_trans.c

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

Modified files:

Index: src/sys/kern/vfs_trans.c
diff -u src/sys/kern/vfs_trans.c:1.47 src/sys/kern/vfs_trans.c:1.48
--- src/sys/kern/vfs_trans.c:1.47	Sun Jun 18 13:59:45 2017
+++ src/sys/kern/vfs_trans.c	Sun Jun 18 14:00:17 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_trans.c,v 1.47 2017/06/18 13:59:45 hannken Exp $	*/
+/*	$NetBSD: vfs_trans.c,v 1.48 2017/06/18 14:00:17 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_trans.c,v 1.47 2017/06/18 13:59:45 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_trans.c,v 1.48 2017/06/18 14:00:17 hannken Exp $");
 
 /*
  * File system transaction operations.
@@ -93,7 +93,9 @@ static inline struct mount *fstrans_norm
 static void fstrans_lwp_dtor(void *);
 static void fstrans_mount_dtor(struct mount *);
 static void fstrans_clear_lwp_info(void);
-static struct fstrans_lwp_info *fstrans_get_lwp_info(struct mount *, bool);
+static inline struct fstrans_lwp_info *
+fstrans_get_lwp_info(struct mount *, bool);
+static struct fstrans_lwp_info *fstrans_alloc_lwp_info(struct mount *);
 static inline int _fstrans_start(struct mount *, enum fstrans_lock_type, int);
 static bool grant_lock(const enum fstrans_state, const enum fstrans_lock_type);
 static bool state_change_done(const struct mount *);
@@ -249,29 +251,19 @@ fstrans_clear_lwp_info(void)
 }
 
 /*
- * Retrieve the per lwp info for this mount allocating if necessary.
+ * Allocate and return per lwp info for this mount.
  */
 static struct fstrans_lwp_info *
-fstrans_get_lwp_info(struct mount *mp, bool do_alloc)
+fstrans_alloc_lwp_info(struct mount *mp)
 {
 	struct fstrans_lwp_info *fli;
 	struct fstrans_mount_info *fmi;
 
 	/*
-	 * Scan our list for a match.
-	 */
-	for (fli = lwp_getspecific(lwp_data_key); fli; fli = fli->fli_succ) {
-		if (fli->fli_mount == mp)
-			return fli;
-	}
-
-	if (! do_alloc)
-		return NULL;
-
-	/*
 	 * Try to reuse a cleared entry or allocate a new one.
 	 */
 	for (fli = lwp_getspecific(lwp_data_key); fli; fli = fli->fli_succ) {
+		KASSERT(fli->fli_mount != mp);
 		if (fli->fli_mount == NULL) {
 			KASSERT(fli->fli_trans_cnt == 0);
 			KASSERT(fli->fli_cow_cnt == 0);
@@ -321,6 +313,25 @@ fstrans_get_lwp_info(struct mount *mp, b
 }
 
 /*
+ * Retrieve the per lwp info for this mount allocating if necessary.
+ */
+static inline struct fstrans_lwp_info *
+fstrans_get_lwp_info(struct mount *mp, bool do_alloc)
+{
+	struct fstrans_lwp_info *fli;
+
+	/*
+	 * Scan our list for a match.
+	 */
+	for (fli = lwp_getspecific(lwp_data_key); fli; fli = fli->fli_succ) {
+		if (fli->fli_mount == mp)
+			return fli;
+	}
+
+	return (do_alloc ? fstrans_alloc_lwp_info(mp) : NULL);
+}
+
+/*
  * Check if this lock type is granted at this state.
  */
 static bool



CVS commit: src/sys/kern

2017-06-18 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sun Jun 18 13:59:45 UTC 2017

Modified Files:
src/sys/kern: vfs_trans.c

Log Message:
Clear fstrans entries whose mount is gone from the last fstrans_done() only.


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 src/sys/kern/vfs_trans.c

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

Modified files:

Index: src/sys/kern/vfs_trans.c
diff -u src/sys/kern/vfs_trans.c:1.46 src/sys/kern/vfs_trans.c:1.47
--- src/sys/kern/vfs_trans.c:1.46	Sun Jun  4 08:05:42 2017
+++ src/sys/kern/vfs_trans.c	Sun Jun 18 13:59:45 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_trans.c,v 1.46 2017/06/04 08:05:42 hannken Exp $	*/
+/*	$NetBSD: vfs_trans.c,v 1.47 2017/06/18 13:59:45 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_trans.c,v 1.46 2017/06/04 08:05:42 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_trans.c,v 1.47 2017/06/18 13:59:45 hannken Exp $");
 
 /*
  * File system transaction operations.
@@ -92,6 +92,7 @@ static LIST_HEAD(fstrans_lwp_head, fstra
 static inline struct mount *fstrans_normalize_mount(struct mount *);
 static void fstrans_lwp_dtor(void *);
 static void fstrans_mount_dtor(struct mount *);
+static void fstrans_clear_lwp_info(void);
 static struct fstrans_lwp_info *fstrans_get_lwp_info(struct mount *, bool);
 static inline int _fstrans_start(struct mount *, enum fstrans_lock_type, int);
 static bool grant_lock(const enum fstrans_state, const enum fstrans_lock_type);
@@ -227,31 +228,42 @@ fstrans_unmount(struct mount *mp)
 }
 
 /*
- * Retrieve the per lwp info for this mount allocating if necessary.
+ * Clear mount entries whose mount is gone.
  */
-static struct fstrans_lwp_info *
-fstrans_get_lwp_info(struct mount *mp, bool do_alloc)
+static void
+fstrans_clear_lwp_info(void)
 {
-	struct fstrans_lwp_info *fli, *res;
-	struct fstrans_mount_info *fmi;
+	struct fstrans_lwp_info *fli;
 
 	/*
-	 * Scan our list for a match clearing entries whose mount is gone.
+	 * Scan our list clearing entries whose mount is gone.
 	 */
-	res = NULL;
 	for (fli = lwp_getspecific(lwp_data_key); fli; fli = fli->fli_succ) {
-		if (fli->fli_mount == mp) {
-			KASSERT(res == NULL);
-			res = fli;
-		} else if (fli->fli_mount != NULL &&
+		if (fli->fli_mount != NULL &&
 		(fli->fli_mount->mnt_iflag & IMNT_GONE) != 0 &&
 		fli->fli_trans_cnt == 0 && fli->fli_cow_cnt == 0) {
 			fstrans_mount_dtor(fli->fli_mount);
 			fli->fli_mount = NULL;
 		}
 	}
-	if (__predict_true(res != NULL))
-		return res;
+}
+
+/*
+ * Retrieve the per lwp info for this mount allocating if necessary.
+ */
+static struct fstrans_lwp_info *
+fstrans_get_lwp_info(struct mount *mp, bool do_alloc)
+{
+	struct fstrans_lwp_info *fli;
+	struct fstrans_mount_info *fmi;
+
+	/*
+	 * Scan our list for a match.
+	 */
+	for (fli = lwp_getspecific(lwp_data_key); fli; fli = fli->fli_succ) {
+		if (fli->fli_mount == mp)
+			return fli;
+	}
 
 	if (! do_alloc)
 		return NULL;
@@ -421,6 +433,8 @@ fstrans_done(struct mount *mp)
 		return;
 	}
 
+	fstrans_clear_lwp_info();
+
 	s = pserialize_read_enter();
 	fmi = mp->mnt_transinfo;
 	if (__predict_true(fmi->fmi_state == FSTRANS_NORMAL)) {



CVS commit: src

2017-06-04 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sun Jun  4 08:05:42 UTC 2017

Modified Files:
src/share/man/man9: fstrans.9
src/sys/kern: vfs_mount.c vfs_trans.c vfs_vnode.c vnode_if.c
src/sys/miscfs/genfs: genfs_io.c layer_vnops.c
src/sys/rump/include/rump: rumpvnode_if.h
src/sys/rump/librump/rumpkern: emul.c
src/sys/rump/librump/rumpvfs: rumpvnode_if.c
src/sys/sys: fstrans.h vnode_if.h
src/sys/ufs/lfs: lfs_pages.c

Log Message:
Operations fstrans_start() and fstrans_start_nowait() now always
use FSTRANS_SHARED as lock type so remove the lock type argument.

File system state FSTRANS_SUSPENDING is now unused so remove it.

Regen vnode_if files.

Ride 8.99.1 less than a hour ago.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/share/man/man9/fstrans.9
cvs rdiff -u -r1.65 -r1.66 src/sys/kern/vfs_mount.c
cvs rdiff -u -r1.45 -r1.46 src/sys/kern/vfs_trans.c
cvs rdiff -u -r1.95 -r1.96 src/sys/kern/vfs_vnode.c
cvs rdiff -u -r1.105 -r1.106 src/sys/kern/vnode_if.c
cvs rdiff -u -r1.68 -r1.69 src/sys/miscfs/genfs/genfs_io.c
cvs rdiff -u -r1.66 -r1.67 src/sys/miscfs/genfs/layer_vnops.c
cvs rdiff -u -r1.29 -r1.30 src/sys/rump/include/rump/rumpvnode_if.h
cvs rdiff -u -r1.181 -r1.182 src/sys/rump/librump/rumpkern/emul.c
cvs rdiff -u -r1.29 -r1.30 src/sys/rump/librump/rumpvfs/rumpvnode_if.c
cvs rdiff -u -r1.10 -r1.11 src/sys/sys/fstrans.h
cvs rdiff -u -r1.100 -r1.101 src/sys/sys/vnode_if.h
cvs rdiff -u -r1.11 -r1.12 src/sys/ufs/lfs/lfs_pages.c

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

Modified files:

Index: src/share/man/man9/fstrans.9
diff -u src/share/man/man9/fstrans.9:1.24 src/share/man/man9/fstrans.9:1.25
--- src/share/man/man9/fstrans.9:1.24	Mon May 29 08:03:13 2017
+++ src/share/man/man9/fstrans.9	Sun Jun  4 08:05:41 2017
@@ -1,4 +1,4 @@
-.\" $NetBSD: fstrans.9,v 1.24 2017/05/29 08:03:13 wiz Exp $
+.\" $NetBSD: fstrans.9,v 1.25 2017/06/04 08:05:41 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 May 29, 2017
+.Dd June 4, 2017
 .Dt FSTRANS 9
 .Os
 .Sh NAME
@@ -46,9 +46,9 @@
 .In sys/mount.h
 .In sys/fstrans.h
 .Ft void
-.Fn fstrans_start "struct mount *mp" "enum fstrans_lock_type lock_type"
+.Fn fstrans_start "struct mount *mp"
 .Ft int
-.Fn fstrans_start_nowait "struct mount *mp" "enum fstrans_lock_type lock_type"
+.Fn fstrans_start_nowait "struct mount *mp"
 .Ft void
 .Fn fstrans_done "struct mount *mp"
 .Ft int
@@ -81,17 +81,6 @@ in a
 transaction, which is blocked by suspending the file system and while
 it is suspended.
 .Pp
-Operations needed to sync the file system to its backing store must be
-bracketed by
-.Fn fstrans_start
-and
-.Fn fstrans_done
-in a
-.Em lazy
-transaction, which is allowed while suspending the file system in order
-to sync it to its backing store, 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
@@ -108,12 +97,8 @@ to:
 .Bl -dash
 .It
 enter the
-.Dv FSTRANS_SUSPENDING
-to suspend all normal operations but allow syncing,
-.It
-enter the
 .Dv FSTRANS_SUSPENDED
-state to suspend all operations once synced, and
+state to suspend all operations, and
 .It
 restore to the
 .Dv FSTRANS_NORMAL
@@ -140,24 +125,14 @@ The copy-on-write callback must be dises
 when the file system is done with it.
 .Sh FUNCTIONS
 .Bl -tag -width abcd
-.It Fn fstrans_start "mp" "lock_type"
-Enter a transaction of type
-.Fa lock_type
-on the file system
+.It Fn fstrans_start "mp"
+Enter a transaction on the file system
 .Fa mp
 in the current thread.
 If the file system is in a state that blocks such transactions, wait
 until it changes state to one that does not.
-.Bl -tag -width FSTRANS_SHARED
-.It Dv FSTRANS_SHARED
-If the file system is suspending or suspended, wait until it is
-resumed.
-Intended for normal file system operations.
-.It Dv FSTRANS_LAZY
+.Pp
 If the file system is suspended, wait until it is resumed.
-Intended for operations needed to sync the file system to its backing
-store in order to suspend it.
-.El
 .Pp
 However, if the current thread is already in a transaction on
 .Fa mp ,
@@ -166,14 +141,12 @@ will enter a nested transaction and retu
 waiting.
 .Pp
 May sleep.
-.It Fn fstrans_start_nowait "mp" "lock_type"
+.It Fn fstrans_start_nowait "mp"
 Like
 .Fn fstrans_start ,
 but return
 .Dv EBUSY
-immediately if
-.Fa lock_type
-transactions are blocked in its current state.
+immediately if transactions are blocked in its current state.
 .Pp
 May sleep nevertheless on internal locks.
 .It Fn fstrans_done "mp"
@@ -192,15 +165,9 @@ to
 and wait for all transactions not allowed in
 .Fa new_state
 

CVS commit: src/sys/kern

2017-06-04 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sun Jun  4 08:03:26 UTC 2017

Modified Files:
src/sys/kern: vnode_if.sh

Log Message:
Operations fstrans_start() and fstrans_start_nowait() now always
use FSTRANS_SHARED as lock type so remove the lock type argument.


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/sys/kern/vnode_if.sh

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/vnode_if.sh
diff -u src/sys/kern/vnode_if.sh:1.65 src/sys/kern/vnode_if.sh:1.66
--- src/sys/kern/vnode_if.sh:1.65	Sun Jun  4 07:59:17 2017
+++ src/sys/kern/vnode_if.sh	Sun Jun  4 08:03:26 2017
@@ -29,7 +29,7 @@ copyright="\
  * SUCH DAMAGE.
  */
 "
-SCRIPT_ID='$NetBSD: vnode_if.sh,v 1.65 2017/06/04 07:59:17 hannken Exp $'
+SCRIPT_ID='$NetBSD: vnode_if.sh,v 1.66 2017/06/04 08:03:26 hannken Exp $'
 
 # Script to produce VFS front-end sugar.
 #
@@ -335,7 +335,7 @@ vop_pre(vnode_t *vp, struct mount **mp, 
 		for (;;) {
 			*mp = vp->v_mount;
 			if (op == FST_TRY) {
-error = fstrans_start_nowait(*mp, FSTRANS_SHARED);
+error = fstrans_start_nowait(*mp);
 if (error) {
 	if (!*mpsafe) {
 		KERNEL_UNLOCK_ONE(curlwp);
@@ -343,7 +343,7 @@ vop_pre(vnode_t *vp, struct mount **mp, 
 	return error;
 }
 			} else {
-fstrans_start(*mp, FSTRANS_SHARED);
+fstrans_start(*mp);
 			}
 			if (__predict_true(*mp == vp->v_mount))
 break;



CVS commit: src/sys

2017-06-04 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sun Jun  4 08:02:26 UTC 2017

Modified Files:
src/sys/kern: vfs_vnode.c
src/sys/miscfs/genfs: genfs_vnops.c layer_extern.h layer_vfsops.c
src/sys/miscfs/nullfs: null_vnops.c
src/sys/miscfs/overlay: overlay_vnops.c
src/sys/miscfs/umapfs: umap_vnops.c
src/sys/sys: vnode.h vnode_impl.h

Log Message:
Locking a layer vnode using the regular bypass routine is no longer
racy.  Undo the change from 2017-03-30 11:16:52, commitid eurqbzuGxGRlryLz
and make vi_lock a krwlock_t again.


To generate a diff of this commit:
cvs rdiff -u -r1.94 -r1.95 src/sys/kern/vfs_vnode.c
cvs rdiff -u -r1.196 -r1.197 src/sys/miscfs/genfs/genfs_vnops.c
cvs rdiff -u -r1.39 -r1.40 src/sys/miscfs/genfs/layer_extern.h
cvs rdiff -u -r1.50 -r1.51 src/sys/miscfs/genfs/layer_vfsops.c
cvs rdiff -u -r1.41 -r1.42 src/sys/miscfs/nullfs/null_vnops.c
cvs rdiff -u -r1.23 -r1.24 src/sys/miscfs/overlay/overlay_vnops.c
cvs rdiff -u -r1.59 -r1.60 src/sys/miscfs/umapfs/umap_vnops.c
cvs rdiff -u -r1.277 -r1.278 src/sys/sys/vnode.h
cvs rdiff -u -r1.14 -r1.15 src/sys/sys/vnode_impl.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/vfs_vnode.c
diff -u src/sys/kern/vfs_vnode.c:1.94 src/sys/kern/vfs_vnode.c:1.95
--- src/sys/kern/vfs_vnode.c:1.94	Sun Jun  4 07:58:29 2017
+++ src/sys/kern/vfs_vnode.c	Sun Jun  4 08:02:26 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_vnode.c,v 1.94 2017/06/04 07:58:29 hannken Exp $	*/
+/*	$NetBSD: vfs_vnode.c,v 1.95 2017/06/04 08:02:26 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1997-2011 The NetBSD Foundation, Inc.
@@ -156,7 +156,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.94 2017/06/04 07:58:29 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.95 2017/06/04 08:02:26 hannken Exp $");
 
 #include 
 #include 
@@ -424,21 +424,6 @@ vnis_marker(vnode_t *vp)
 }
 
 /*
- * Set vnode to share another vnodes lock.
- */
-void
-vshare_lock(vnode_t *vp, vnode_t *src_vp)
-{
-	vnode_impl_t *vip = VNODE_TO_VIMPL(vp);
-	vnode_impl_t *src_vip = VNODE_TO_VIMPL(src_vp);
-	krwlock_t *oldlock = vip->vi_lock;
-
-	rw_obj_hold(src_vip->vi_lock);
-	vip->vi_lock = src_vip->vi_lock;
-	rw_obj_free(oldlock);
-}
-
-/*
  * Return the lru list this node should be on.
  */
 static vnodelst_t *
@@ -1123,7 +1108,7 @@ vcache_alloc(void)
 	vip = pool_cache_get(vcache_pool, PR_WAITOK);
 	memset(vip, 0, sizeof(*vip));
 
-	vip->vi_lock = rw_obj_alloc();
+	rw_init(>vi_lock);
 	/* SLIST_INIT(>vi_hash); */
 	/* LIST_INIT(>vi_nclist); */
 	/* LIST_INIT(>vi_dnclist); */
@@ -1185,7 +1170,7 @@ vcache_free(vnode_impl_t *vip)
 	if (vp->v_type == VBLK || vp->v_type == VCHR)
 		spec_node_destroy(vp);
 
-	rw_obj_free(vip->vi_lock);
+	rw_destroy(>vi_lock);
 	uvm_obj_destroy(>v_uobj, true);
 	cv_destroy(>v_cv);
 	pool_cache_put(vcache_pool, vip);

Index: src/sys/miscfs/genfs/genfs_vnops.c
diff -u src/sys/miscfs/genfs/genfs_vnops.c:1.196 src/sys/miscfs/genfs/genfs_vnops.c:1.197
--- src/sys/miscfs/genfs/genfs_vnops.c:1.196	Sun Jun  4 08:01:33 2017
+++ src/sys/miscfs/genfs/genfs_vnops.c	Sun Jun  4 08:02:26 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: genfs_vnops.c,v 1.196 2017/06/04 08:01:33 hannken Exp $	*/
+/*	$NetBSD: genfs_vnops.c,v 1.197 2017/06/04 08:02:26 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -57,7 +57,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: genfs_vnops.c,v 1.196 2017/06/04 08:01:33 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: genfs_vnops.c,v 1.197 2017/06/04 08:02:26 hannken Exp $");
 
 #include 
 #include 
@@ -294,10 +294,10 @@ genfs_deadlock(void *v)
 
 	op = (ISSET(flags, LK_EXCLUSIVE) ? RW_WRITER : RW_READER);
 	if (ISSET(flags, LK_NOWAIT)) {
-		if (! rw_tryenter(vip->vi_lock, op))
+		if (! rw_tryenter(>vi_lock, op))
 			return EBUSY;
 	} else {
-		rw_enter(vip->vi_lock, op);
+		rw_enter(>vi_lock, op);
 	}
 	VSTATE_ASSERT_UNLOCKED(vp, VS_RECLAIMED);
 	return 0;
@@ -315,7 +315,7 @@ genfs_deadunlock(void *v)
 	vnode_t *vp = ap->a_vp;
 	vnode_impl_t *vip = VNODE_TO_VIMPL(vp);
 
-	rw_exit(vip->vi_lock);
+	rw_exit(>vi_lock);
 
 	return 0;
 }
@@ -337,10 +337,10 @@ genfs_lock(void *v)
 
 	op = (ISSET(flags, LK_EXCLUSIVE) ? RW_WRITER : RW_READER);
 	if (ISSET(flags, LK_NOWAIT)) {
-		if (! rw_tryenter(vip->vi_lock, op))
+		if (! rw_tryenter(>vi_lock, op))
 			return EBUSY;
 	} else {
-		rw_enter(vip->vi_lock, op);
+		rw_enter(>vi_lock, op);
 	}
 	VSTATE_ASSERT_UNLOCKED(vp, VS_ACTIVE);
 	return 0;
@@ -358,7 +358,7 @@ genfs_unlock(void *v)
 	vnode_t *vp = ap->a_vp;
 	vnode_impl_t *vip = VNODE_TO_VIMPL(vp);
 
-	rw_exit(vip->vi_lock);
+	rw_exit(>vi_lock);
 
 	return 0;
 }
@@ -375,10 +375,10 @@ genfs_islocked(void *v)
 	vnode_t *vp = ap->a_vp;
 	vnode_impl_t *vip = VNODE_TO_VIMPL(vp);
 
-	if (rw_write_held(vip->vi_lock))
+	if (rw_write_held(>vi_lock))
 		return LK_EXCLUSIVE;
 
-	if (rw_read_held(vip->vi_lock))
+	if 

CVS commit: src/sys/miscfs/genfs

2017-06-04 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sun Jun  4 08:01:33 UTC 2017

Modified Files:
src/sys/miscfs/genfs: genfs_vnops.c

Log Message:
Now that FSTRANS is part of VOP_*LOCK() remove FSTRANS and vdead_check()
from genfs_.*lock() and assert the vnode state once the vnode is locked.


To generate a diff of this commit:
cvs rdiff -u -r1.195 -r1.196 src/sys/miscfs/genfs/genfs_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/sys/miscfs/genfs/genfs_vnops.c
diff -u src/sys/miscfs/genfs/genfs_vnops.c:1.195 src/sys/miscfs/genfs/genfs_vnops.c:1.196
--- src/sys/miscfs/genfs/genfs_vnops.c:1.195	Tue Apr 11 14:29:32 2017
+++ src/sys/miscfs/genfs/genfs_vnops.c	Sun Jun  4 08:01:33 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: genfs_vnops.c,v 1.195 2017/04/11 14:29:32 riastradh Exp $	*/
+/*	$NetBSD: genfs_vnops.c,v 1.196 2017/06/04 08:01:33 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -57,7 +57,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: genfs_vnops.c,v 1.195 2017/04/11 14:29:32 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: genfs_vnops.c,v 1.196 2017/06/04 08:01:33 hannken Exp $");
 
 #include 
 #include 
@@ -288,41 +288,18 @@ genfs_deadlock(void *v)
 	vnode_impl_t *vip = VNODE_TO_VIMPL(vp);
 	int flags = ap->a_flags;
 	krw_t op;
-	int error;
+
+	if (! ISSET(flags, LK_RETRY))
+		return ENOENT;
 
 	op = (ISSET(flags, LK_EXCLUSIVE) ? RW_WRITER : RW_READER);
 	if (ISSET(flags, LK_NOWAIT)) {
 		if (! rw_tryenter(vip->vi_lock, op))
 			return EBUSY;
-		if (mutex_tryenter(vp->v_interlock)) {
-			error = vdead_check(vp, VDEAD_NOWAIT);
-			if (error == ENOENT && ISSET(flags, LK_RETRY))
-error = 0;
-			mutex_exit(vp->v_interlock);
-		} else
-			error = EBUSY;
-		if (error)
-			rw_exit(vip->vi_lock);
-		return error;
-	}
-
-	rw_enter(vip->vi_lock, op);
-	mutex_enter(vp->v_interlock);
-	error = vdead_check(vp, VDEAD_NOWAIT);
-	if (error == EBUSY) {
-		rw_exit(vip->vi_lock);
-		error = vdead_check(vp, 0);
-		KASSERT(error == ENOENT);
-		mutex_exit(vp->v_interlock);
+	} else {
 		rw_enter(vip->vi_lock, op);
-		mutex_enter(vp->v_interlock);
-	}
-	KASSERT(error == ENOENT);
-	mutex_exit(vp->v_interlock);
-	if (! ISSET(flags, LK_RETRY)) {
-		rw_exit(vip->vi_lock);
-		return ENOENT;
 	}
+	VSTATE_ASSERT_UNLOCKED(vp, VS_RECLAIMED);
 	return 0;
 }
 
@@ -355,43 +332,18 @@ genfs_lock(void *v)
 	} */ *ap = v;
 	vnode_t *vp = ap->a_vp;
 	vnode_impl_t *vip = VNODE_TO_VIMPL(vp);
-	struct mount *mp = vp->v_mount;
 	int flags = ap->a_flags;
 	krw_t op;
-	int error;
 
 	op = (ISSET(flags, LK_EXCLUSIVE) ? RW_WRITER : RW_READER);
 	if (ISSET(flags, LK_NOWAIT)) {
-		if (fstrans_start_nowait(mp, FSTRANS_SHARED))
-			return EBUSY;
-		if (! rw_tryenter(vip->vi_lock, op)) {
-			fstrans_done(mp);
+		if (! rw_tryenter(vip->vi_lock, op))
 			return EBUSY;
-		}
-		if (mutex_tryenter(vp->v_interlock)) {
-			error = vdead_check(vp, VDEAD_NOWAIT);
-			mutex_exit(vp->v_interlock);
-		} else
-			error = EBUSY;
-		if (error) {
-			rw_exit(vip->vi_lock);
-			fstrans_done(mp);
-		}
-		return error;
-	}
-
-	fstrans_start(mp, FSTRANS_SHARED);
-	rw_enter(vip->vi_lock, op);
-	mutex_enter(vp->v_interlock);
-	error = vdead_check(vp, VDEAD_NOWAIT);
-	if (error) {
-		rw_exit(vip->vi_lock);
-		fstrans_done(mp);
-		error = vdead_check(vp, 0);
-		KASSERT(error == ENOENT);
+	} else {
+		rw_enter(vip->vi_lock, op);
 	}
-	mutex_exit(vp->v_interlock);
-	return error;
+	VSTATE_ASSERT_UNLOCKED(vp, VS_ACTIVE);
+	return 0;
 }
 
 /*
@@ -405,10 +357,8 @@ genfs_unlock(void *v)
 	} */ *ap = v;
 	vnode_t *vp = ap->a_vp;
 	vnode_impl_t *vip = VNODE_TO_VIMPL(vp);
-	struct mount *mp = vp->v_mount;
 
 	rw_exit(vip->vi_lock);
-	fstrans_done(mp);
 
 	return 0;
 }



CVS commit: src/sys

2017-06-04 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sun Jun  4 08:00:27 UTC 2017

Modified Files:
src/sys/kern: vnode_if.c
src/sys/rump/include/rump: rumpvnode_if.h
src/sys/rump/librump/rumpvfs: rumpvnode_if.c
src/sys/sys: vnode_if.h

Log Message:
Regen.


To generate a diff of this commit:
cvs rdiff -u -r1.104 -r1.105 src/sys/kern/vnode_if.c
cvs rdiff -u -r1.28 -r1.29 src/sys/rump/include/rump/rumpvnode_if.h
cvs rdiff -u -r1.28 -r1.29 src/sys/rump/librump/rumpvfs/rumpvnode_if.c
cvs rdiff -u -r1.99 -r1.100 src/sys/sys/vnode_if.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/vnode_if.c
diff -u src/sys/kern/vnode_if.c:1.104 src/sys/kern/vnode_if.c:1.105
--- src/sys/kern/vnode_if.c:1.104	Fri May 26 14:21:54 2017
+++ src/sys/kern/vnode_if.c	Sun Jun  4 08:00:27 2017
@@ -1,13 +1,13 @@
-/*	$NetBSD: vnode_if.c,v 1.104 2017/05/26 14:21:54 riastradh Exp $	*/
+/*	$NetBSD: vnode_if.c,v 1.105 2017/06/04 08:00:27 hannken Exp $	*/
 
 /*
  * Warning: DO NOT EDIT! This file is automatically generated!
  * (Modifications made here may easily be lost!)
  *
  * Created from the file:
- *	NetBSD: vnode_if.src,v 1.75 2017/05/26 14:21:00 riastradh Exp
+ *	NetBSD: vnode_if.src,v 1.76 2017/06/04 07:59:17 hannken Exp
  * by the script:
- *	NetBSD: vnode_if.sh,v 1.64 2017/04/16 17:18:28 riastradh Exp
+ *	NetBSD: vnode_if.sh,v 1.65 2017/06/04 07:59:17 hannken Exp
  */
 
 /*
@@ -40,7 +40,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vnode_if.c,v 1.104 2017/05/26 14:21:54 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vnode_if.c,v 1.105 2017/06/04 08:00:27 hannken Exp $");
 
 #include 
 #include 
@@ -49,6 +49,57 @@ __KERNEL_RCSID(0, "$NetBSD: vnode_if.c,v
 #include 
 #include 
 
+enum fst_op { FST_NO, FST_YES, FST_TRY };
+
+static inline int
+vop_pre(vnode_t *vp, struct mount **mp, bool *mpsafe, enum fst_op op)
+{
+	int error;
+
+	*mpsafe = (vp->v_vflag & VV_MPSAFE);
+
+	if (!*mpsafe) {
+		KERNEL_LOCK(1, curlwp);
+	}
+
+	if (op == FST_YES || op == FST_TRY) {
+		for (;;) {
+			*mp = vp->v_mount;
+			if (op == FST_TRY) {
+error = fstrans_start_nowait(*mp, FSTRANS_SHARED);
+if (error) {
+	if (!*mpsafe) {
+		KERNEL_UNLOCK_ONE(curlwp);
+	}
+	return error;
+}
+			} else {
+fstrans_start(*mp, FSTRANS_SHARED);
+			}
+			if (__predict_true(*mp == vp->v_mount))
+break;
+			fstrans_done(*mp);
+		}
+	} else {
+		*mp = vp->v_mount;
+	}
+
+	return 0;
+}
+
+static inline void
+vop_post(vnode_t *vp, struct mount *mp, bool mpsafe, enum fst_op op)
+{
+
+	if (op == FST_YES) {
+		fstrans_done(mp);
+	}
+
+	if (!mpsafe) {
+		KERNEL_UNLOCK_ONE(curlwp);
+	}
+}
+
 const struct vnodeop_desc vop_default_desc = {
 	0,
 	"default",
@@ -80,16 +131,15 @@ VOP_BWRITE(struct vnode *vp,
 	int error;
 	bool mpsafe;
 	struct vop_bwrite_args a;
-	struct mount *mp = vp->v_mount;
+	struct mount *mp;
 	a.a_desc = VDESC(vop_bwrite);
 	a.a_vp = vp;
 	a.a_bp = bp;
-	mpsafe = (vp->v_vflag & VV_MPSAFE);
-	if (!mpsafe) { KERNEL_LOCK(1, curlwp); }
-	fstrans_start(mp, FSTRANS_SHARED);
+	error = vop_pre(vp, , , FST_YES);
+	if (error)
+		return error;
 	error = (VCALL(vp, VOFFSET(vop_bwrite), ));
-	fstrans_done(mp);
-	if (!mpsafe) { KERNEL_UNLOCK_ONE(curlwp); }
+	vop_post(vp, mp, mpsafe, FST_YES);
 	return error;
 }
 
@@ -114,14 +164,16 @@ VOP_LOOKUP(struct vnode *dvp,
 	int error;
 	bool mpsafe;
 	struct vop_lookup_v2_args a;
+	struct mount *mp;
 	a.a_desc = VDESC(vop_lookup);
 	a.a_dvp = dvp;
 	a.a_vpp = vpp;
 	a.a_cnp = cnp;
-	mpsafe = (dvp->v_vflag & VV_MPSAFE);
-	if (!mpsafe) { KERNEL_LOCK(1, curlwp); }
+	error = vop_pre(dvp, , , FST_NO);
+	if (error)
+		return error;
 	error = (VCALL(dvp, VOFFSET(vop_lookup), ));
-	if (!mpsafe) { KERNEL_UNLOCK_ONE(curlwp); }
+	vop_post(dvp, mp, mpsafe, FST_NO);
 #ifdef DIAGNOSTIC
 	if (error == 0)
 		KASSERT((*vpp)->v_size != VSIZENOTSET
@@ -152,15 +204,17 @@ VOP_CREATE(struct vnode *dvp,
 	int error;
 	bool mpsafe;
 	struct vop_create_v3_args a;
+	struct mount *mp;
 	a.a_desc = VDESC(vop_create);
 	a.a_dvp = dvp;
 	a.a_vpp = vpp;
 	a.a_cnp = cnp;
 	a.a_vap = vap;
-	mpsafe = (dvp->v_vflag & VV_MPSAFE);
-	if (!mpsafe) { KERNEL_LOCK(1, curlwp); }
+	error = vop_pre(dvp, , , FST_NO);
+	if (error)
+		return error;
 	error = (VCALL(dvp, VOFFSET(vop_create), ));
-	if (!mpsafe) { KERNEL_UNLOCK_ONE(curlwp); }
+	vop_post(dvp, mp, mpsafe, FST_NO);
 #ifdef DIAGNOSTIC
 	if (error == 0)
 		KASSERT((*vpp)->v_size != VSIZENOTSET
@@ -191,15 +245,17 @@ VOP_MKNOD(struct vnode *dvp,
 	int error;
 	bool mpsafe;
 	struct vop_mknod_v3_args a;
+	struct mount *mp;
 	a.a_desc = VDESC(vop_mknod);
 	a.a_dvp = dvp;
 	a.a_vpp = vpp;
 	a.a_cnp = cnp;
 	a.a_vap = vap;
-	mpsafe = (dvp->v_vflag & VV_MPSAFE);
-	if (!mpsafe) { KERNEL_LOCK(1, curlwp); }
+	error = vop_pre(dvp, , , FST_NO);
+	if (error)
+		return error;
 	error = (VCALL(dvp, VOFFSET(vop_mknod), ));
-	if (!mpsafe) { 

CVS commit: src/sys/kern

2017-06-04 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sun Jun  4 07:59:17 UTC 2017

Modified Files:
src/sys/kern: vnode_if.sh vnode_if.src

Log Message:
Add "FSTRANS=LOCK" and "FSTRANS=UNLOCK" to vop_lock and vop_unlock.

Add two "static inline" functions to vnode_if.c to handle MPSAFE
and FSTRANS before and after the "VCALL()".

Take FSTRANS and handle error before "VCALL(...vop_lock...)" and
release it after "VCALL(...vop_unlock...)".


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 src/sys/kern/vnode_if.sh
cvs rdiff -u -r1.75 -r1.76 src/sys/kern/vnode_if.src

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/vnode_if.sh
diff -u src/sys/kern/vnode_if.sh:1.64 src/sys/kern/vnode_if.sh:1.65
--- src/sys/kern/vnode_if.sh:1.64	Sun Apr 16 17:18:28 2017
+++ src/sys/kern/vnode_if.sh	Sun Jun  4 07:59:17 2017
@@ -29,7 +29,7 @@ copyright="\
  * SUCH DAMAGE.
  */
 "
-SCRIPT_ID='$NetBSD: vnode_if.sh,v 1.64 2017/04/16 17:18:28 riastradh Exp $'
+SCRIPT_ID='$NetBSD: vnode_if.sh,v 1.65 2017/06/04 07:59:17 hannken Exp $'
 
 # Script to produce VFS front-end sugar.
 #
@@ -100,7 +100,7 @@ awk_parser='
 	args_name=$1;
 	argc=0;
 	willmake=-1;
-	fstrans=0;
+	fstrans="";
 	next;
 }
 # Last line of description
@@ -113,11 +113,9 @@ awk_parser='
 	if ($1 == "VERSION") {
 		args_name=args_name "_v" $2;
 		next;
-	} else if ($1 == "FSTRANS=YES") {
-		fstrans = 1;
-		next;
-	} else if ($1 == "FSTRANS=NO") {
-		fstrans = -1;
+	} else if ($1 ~ "^FSTRANS=") {
+		fstrans = $1;
+		sub("FSTRANS=", "", fstrans);
 		next;
 	}
 
@@ -147,8 +145,12 @@ awk_parser='
 		willmake=argc;
 		i++;
 	}
-	if (argc == 0 && fstrans == 0 && lockstate[0] != 1)
-		fstrans = 1;
+	if (argc == 0 && fstrans == "") {
+		if (lockstate[0] == 1)
+			fstrans = "NO";
+		else
+			fstrans = "YES";
+	}
 
 	# XXX: replace non-portable types for rump.  We should really
 	# nuke the types from the kernel, but that is a battle for
@@ -316,6 +318,57 @@ echo '
 
 if [ -z "${rump}" ] ; then
 	echo "
+enum fst_op { FST_NO, FST_YES, FST_TRY };
+
+static inline int
+vop_pre(vnode_t *vp, struct mount **mp, bool *mpsafe, enum fst_op op)
+{
+	int error;
+
+	*mpsafe = (vp->v_vflag & VV_MPSAFE);
+
+	if (!*mpsafe) {
+		KERNEL_LOCK(1, curlwp);
+	}
+
+	if (op == FST_YES || op == FST_TRY) {
+		for (;;) {
+			*mp = vp->v_mount;
+			if (op == FST_TRY) {
+error = fstrans_start_nowait(*mp, FSTRANS_SHARED);
+if (error) {
+	if (!*mpsafe) {
+		KERNEL_UNLOCK_ONE(curlwp);
+	}
+	return error;
+}
+			} else {
+fstrans_start(*mp, FSTRANS_SHARED);
+			}
+			if (__predict_true(*mp == vp->v_mount))
+break;
+			fstrans_done(*mp);
+		}
+	} else {
+		*mp = vp->v_mount;
+	}
+
+	return 0;
+}
+
+static inline void
+vop_post(vnode_t *vp, struct mount *mp, bool mpsafe, enum fst_op op)
+{
+
+	if (op == FST_YES) {
+		fstrans_done(mp);
+	}
+
+	if (!mpsafe) {
+		KERNEL_UNLOCK_ONE(curlwp);
+	}
+}
+
 const struct vnodeop_desc vop_default_desc = {"
 echo '	0,
 	"default",
@@ -402,8 +455,7 @@ function bodyrump() {
 function bodynorm() {
 	printf("{\n\tint error;\n\tbool mpsafe;\n\tstruct %s_args a;\n",
 		args_name);
-	if (fstrans == 1)
-		printf("\tstruct mount *mp = %s->v_mount;\n", argname[0]);
+	printf("\tstruct mount *mp;\n");
 	if (lockdebug) {
 		printf("#ifdef VNODE_LOCKDEBUG\n");
 		for (i=0; iv_vflag & VV_MPSAFE);\n", argname[0]);
-	printf("\tif (!mpsafe) { KERNEL_LOCK(1, curlwp); }\n");
-	if (fstrans == 1)
-		printf("\tfstrans_start(mp, FSTRANS_SHARED);\n");
+	if (fstrans == "LOCK")
+		printf("\terror = vop_pre(%s, , , %s);\n",
+			argname[0], "(flags & LK_NOWAIT ? FST_TRY : FST_YES)");
+	else if (fstrans == "UNLOCK")
+		printf("\terror = vop_pre(%s, , , FST_%s);\n",
+			argname[0], "NO");
+	else
+		printf("\terror = vop_pre(%s, , , FST_%s);\n",
+			argname[0], fstrans);
+	printf("\tif (error)\n\t\treturn error;\n");
 	printf("\terror = (VCALL(%s, VOFFSET(%s), ));\n",
 		argname[0], name);
-	if (fstrans == 1)
-		printf("\tfstrans_done(mp);\n");
-	printf("\tif (!mpsafe) { KERNEL_UNLOCK_ONE(curlwp); }\n");
+	if (fstrans == "LOCK")
+		printf("\tvop_post(%s, mp, mpsafe, %s);\n",
+			argname[0], "(error ? FST_YES : FST_NO)");
+	else if (fstrans == "UNLOCK")
+		printf("\tvop_post(%s, mp, mpsafe, FST_%s);\n",
+			argname[0], "YES");
+	else
+		printf("\tvop_post(%s, mp, mpsafe, FST_%s);\n",
+			argname[0], fstrans);
 	if (willmake != -1) {
 		printf("#ifdef DIAGNOSTIC\n");
 		printf("\tif (error == 0)\n"\

Index: src/sys/kern/vnode_if.src
diff -u src/sys/kern/vnode_if.src:1.75 src/sys/kern/vnode_if.src:1.76
--- src/sys/kern/vnode_if.src:1.75	Fri May 26 14:21:00 2017
+++ src/sys/kern/vnode_if.src	Sun Jun  4 07:59:17 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: vnode_if.src,v 1.75 2017/05/26 14:21:00 riastradh Exp $
+#	$NetBSD: vnode_if.src,v 1.76 

CVS commit: src/sys

2017-06-04 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sun Jun  4 07:58:30 UTC 2017

Modified Files:
src/sys/kern: vfs_subr.c vfs_vnode.c
src/sys/sys: vnode_impl.h

Log Message:
A vnode is usually called "active", if it has an associated file system
node and a usecount greater zero.  Therefore rename state "VS_ACTIVE"
to "VS_LOADED" and add a new synthetic state "VS_ACTIVE" for VSTATE_ASSERT()
to assert an active vnode.

Add VSTATE_ASSERT_UNLOCKED() to be used with v_interlock unheld and
move the state assertion macros to sys/vnode_impl.h.


To generate a diff of this commit:
cvs rdiff -u -r1.467 -r1.468 src/sys/kern/vfs_subr.c
cvs rdiff -u -r1.93 -r1.94 src/sys/kern/vfs_vnode.c
cvs rdiff -u -r1.13 -r1.14 src/sys/sys/vnode_impl.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/vfs_subr.c
diff -u src/sys/kern/vfs_subr.c:1.467 src/sys/kern/vfs_subr.c:1.468
--- src/sys/kern/vfs_subr.c:1.467	Fri May 26 14:34:19 2017
+++ src/sys/kern/vfs_subr.c	Sun Jun  4 07:58:29 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_subr.c,v 1.467 2017/05/26 14:34:19 riastradh Exp $	*/
+/*	$NetBSD: vfs_subr.c,v 1.468 2017/06/04 07:58:29 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998, 2004, 2005, 2007, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.467 2017/05/26 14:34:19 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.468 2017/06/04 07:58:29 hannken Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -1055,12 +1055,14 @@ vstate_name(enum vnode_state state)
 {
 
 	switch (state) {
+	case VS_ACTIVE:
+		return "ACTIVE";
 	case VS_MARKER:
 		return "MARKER";
 	case VS_LOADING:
 		return "LOADING";
-	case VS_ACTIVE:
-		return "ACTIVE";
+	case VS_LOADED:
+		return "LOADED";
 	case VS_BLOCKED:
 		return "BLOCKED";
 	case VS_RECLAIMING:

Index: src/sys/kern/vfs_vnode.c
diff -u src/sys/kern/vfs_vnode.c:1.93 src/sys/kern/vfs_vnode.c:1.94
--- src/sys/kern/vfs_vnode.c:1.93	Sun May 28 16:39:41 2017
+++ src/sys/kern/vfs_vnode.c	Sun Jun  4 07:58:29 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_vnode.c,v 1.93 2017/05/28 16:39:41 hannken Exp $	*/
+/*	$NetBSD: vfs_vnode.c,v 1.94 2017/06/04 07:58:29 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1997-2011 The NetBSD Foundation, Inc.
@@ -100,7 +100,7 @@
  *			will never change its state.
  *	- LOADING	Vnode is associating underlying file system and not
  *			yet ready to use.
- *	- ACTIVE	Vnode has associated underlying file system and is
+ *	- LOADED	Vnode has associated underlying file system and is
  *			ready to use.
  *	- BLOCKED	Vnode is active but cannot get new references.
  *	- RECLAIMING	Vnode is disassociating from the underlying file
@@ -109,19 +109,19 @@
  *			and is dead.
  *
  *	Valid state changes are:
- *	LOADING -> ACTIVE
+ *	LOADING -> LOADED
  *			Vnode has been initialised in vcache_get() or
  *			vcache_new() and is ready to use.
- *	ACTIVE -> RECLAIMING
+ *	LOADED -> RECLAIMING
  *			Vnode starts disassociation from underlying file
  *			system in vcache_reclaim().
  *	RECLAIMING -> RECLAIMED
  *			Vnode finished disassociation from underlying file
  *			system in vcache_reclaim().
- *	ACTIVE -> BLOCKED
+ *	LOADED -> BLOCKED
  *			Either vcache_rekey*() is changing the vnode key or
  *			vrelel() is about to call VOP_INACTIVE().
- *	BLOCKED -> ACTIVE
+ *	BLOCKED -> LOADED
  *			The block condition is over.
  *	LOADING -> RECLAIMED
  *			Either vcache_get() or vcache_new() failed to
@@ -156,7 +156,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.93 2017/05/28 16:39:41 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.94 2017/06/04 07:58:29 hannken Exp $");
 
 #include 
 #include 
@@ -231,26 +231,30 @@ extern struct vfsops	dead_vfsops;
 
 #if defined(DIAGNOSTIC)
 
+#define VSTATE_VALID(state) \
+	((state) != VS_ACTIVE && (state) != VS_MARKER)
 #define VSTATE_GET(vp) \
 	vstate_assert_get((vp), __func__, __LINE__)
 #define VSTATE_CHANGE(vp, from, to) \
 	vstate_assert_change((vp), (from), (to), __func__, __LINE__)
 #define VSTATE_WAIT_STABLE(vp) \
 	vstate_assert_wait_stable((vp), __func__, __LINE__)
-#define VSTATE_ASSERT(vp, state) \
-	vstate_assert((vp), (state), __func__, __LINE__)
 
-static void
-vstate_assert(vnode_t *vp, enum vnode_state state, const char *func, int line)
+void
+_vstate_assert(vnode_t *vp, enum vnode_state state, const char *func, int line)
 {
 	vnode_impl_t *vip = VNODE_TO_VIMPL(vp);
 
 	KASSERTMSG(mutex_owned(vp->v_interlock), "at %s:%d", func, line);
 
-	if (__predict_true(vip->vi_state == state))
+	if (state == VS_ACTIVE && vp->v_usecount > 0 &&
+	(vip->vi_state == VS_LOADED || vip->vi_state == VS_BLOCKED))
 		return;
-	vnpanic(vp, "state is %s, expected %s at %s:%d",
-	vstate_name(vip->vi_state), vstate_name(state), func, line);
+	if (vip->vi_state == state)
+		return;
+	vnpanic(vp, "state is %s, usecount %d, expected %s at 

CVS commit: src

2017-05-28 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sun May 28 16:39:42 UTC 2017

Modified Files:
src/share/man/man9: vnode.9
src/sys/kern: vfs_vnode.c
src/sys/sys: param.h

Log Message:
Restrict vgone() to suspended file systems only.

Welcome to 7.99.75, old file system modules would cause a diagnostic
assertion with new kernel.


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 src/share/man/man9/vnode.9
cvs rdiff -u -r1.92 -r1.93 src/sys/kern/vfs_vnode.c
cvs rdiff -u -r1.541 -r1.542 src/sys/sys/param.h

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

Modified files:

Index: src/share/man/man9/vnode.9
diff -u src/share/man/man9/vnode.9:1.79 src/share/man/man9/vnode.9:1.80
--- src/share/man/man9/vnode.9:1.79	Mon Jan 23 11:49:03 2017
+++ src/share/man/man9/vnode.9	Sun May 28 16:39:41 2017
@@ -1,4 +1,4 @@
-.\" $NetBSD: vnode.9,v 1.79 2017/01/23 11:49:03 abhinav Exp $
+.\" $NetBSD: vnode.9,v 1.80 2017/05/28 16:39:41 hannken Exp $
 .\"
 .\" Copyright (c) 2001, 2005, 2006 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 January 11, 2017
+.Dd May 28, 2017
 .Dt VNODE 9
 .Os
 .Sh NAME
@@ -617,6 +617,9 @@ is a null operation if the reference cou
 Eliminate all activity associated with the unlocked vnode
 .Fa vp
 in preparation for recycling.
+This operation is restricted to suspended file systems.
+See
+.Xr vfs_suspend 9 .
 .It Fn vgonel "vp" "p"
 Eliminate all activity associated with the locked vnode
 .Fa vp

Index: src/sys/kern/vfs_vnode.c
diff -u src/sys/kern/vfs_vnode.c:1.92 src/sys/kern/vfs_vnode.c:1.93
--- src/sys/kern/vfs_vnode.c:1.92	Sun May 28 16:35:47 2017
+++ src/sys/kern/vfs_vnode.c	Sun May 28 16:39:41 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_vnode.c,v 1.92 2017/05/28 16:35:47 hannken Exp $	*/
+/*	$NetBSD: vfs_vnode.c,v 1.93 2017/05/28 16:39:41 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1997-2011 The NetBSD Foundation, Inc.
@@ -156,7 +156,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.92 2017/05/28 16:35:47 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.93 2017/05/28 16:39:41 hannken Exp $");
 
 #include 
 #include 
@@ -1018,6 +1018,9 @@ void
 vgone(vnode_t *vp)
 {
 
+	KASSERT((vp->v_mount->mnt_iflag & IMNT_HAS_TRANS) == 0 ||
+	fstrans_is_owner(vp->v_mount));
+
 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
 	mutex_enter(vp->v_interlock);
 	VSTATE_WAIT_STABLE(vp);

Index: src/sys/sys/param.h
diff -u src/sys/sys/param.h:1.541 src/sys/sys/param.h:1.542
--- src/sys/sys/param.h:1.541	Fri May 26 14:22:53 2017
+++ src/sys/sys/param.h	Sun May 28 16:39:42 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: param.h,v 1.541 2017/05/26 14:22:53 riastradh Exp $	*/
+/*	$NetBSD: param.h,v 1.542 2017/05/28 16:39:42 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -67,7 +67,7 @@
  *	2.99.9		(299000900)
  */
 
-#define	__NetBSD_Version__	799007400	/* NetBSD 7.99.74 */
+#define	__NetBSD_Version__	799007500	/* NetBSD 7.99.75 */
 
 #define __NetBSD_Prereq__(M,m,p) (M) * 1) + \
 (m) * 100) + (p) * 100) <= __NetBSD_Version__)



CVS commit: src/sys/ufs/ext2fs

2017-05-28 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sun May 28 16:38:55 UTC 2017

Modified Files:
src/sys/ufs/ext2fs: ext2fs_alloc.c ext2fs_extern.h ext2fs_vfsops.c
ext2fs_vnops.c

Log Message:
Change ext2fs to use vcache_new like we did for ffs:
- Change ext2fs_valloc to return an inode number.
- Make ext2fs_makeinode private to ext2fs_vnops.c and
  pass vattr instead of mode.


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 src/sys/ufs/ext2fs/ext2fs_alloc.c
cvs rdiff -u -r1.55 -r1.56 src/sys/ufs/ext2fs/ext2fs_extern.h
cvs rdiff -u -r1.208 -r1.209 src/sys/ufs/ext2fs/ext2fs_vfsops.c
cvs rdiff -u -r1.127 -r1.128 src/sys/ufs/ext2fs/ext2fs_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/sys/ufs/ext2fs/ext2fs_alloc.c
diff -u src/sys/ufs/ext2fs/ext2fs_alloc.c:1.51 src/sys/ufs/ext2fs/ext2fs_alloc.c:1.52
--- src/sys/ufs/ext2fs/ext2fs_alloc.c:1.51	Sat Aug 20 19:53:43 2016
+++ src/sys/ufs/ext2fs/ext2fs_alloc.c	Sun May 28 16:38:55 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ext2fs_alloc.c,v 1.51 2016/08/20 19:53:43 jdolecek Exp $	*/
+/*	$NetBSD: ext2fs_alloc.c,v 1.52 2017/05/28 16:38:55 hannken Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ext2fs_alloc.c,v 1.51 2016/08/20 19:53:43 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ext2fs_alloc.c,v 1.52 2017/05/28 16:38:55 hannken Exp $");
 
 #include 
 #include 
@@ -167,16 +167,13 @@ nospace:
  *	  available inode is located.
  */
 int
-ext2fs_valloc(struct vnode *pvp, int mode, kauth_cred_t cred,
-struct vnode **vpp)
+ext2fs_valloc(struct vnode *pvp, int mode, kauth_cred_t cred, ino_t *inop)
 {
 	struct inode *pip;
 	struct m_ext2fs *fs;
-	struct inode *ip;
 	ino_t ino, ipref;
-	int cg, error;
+	int cg;
 
-	*vpp = NULL;
 	pip = VTOI(pvp);
 	fs = pip->i_e2fs;
 	if (fs->e2fs.e2fs_ficount == 0)
@@ -190,32 +187,10 @@ ext2fs_valloc(struct vnode *pvp, int mod
 	ino = (ino_t)ext2fs_hashalloc(pip, cg, (long)ipref, mode, ext2fs_nodealloccg);
 	if (ino == 0)
 		goto noinodes;
-	error = VFS_VGET(pvp->v_mount, ino, vpp);
-	if (error) {
-		ext2fs_vfree(pvp, ino, mode);
-		return error;
-	}
-	ip = VTOI(*vpp);
-
-	KASSERT(!E2FS_HAS_GD_CSUM(fs) || (fs->e2fs_gd[ino_to_cg(fs, ino)].ext2bgd_flags & h2fs16(E2FS_BG_INODE_ZEROED)) != 0);
-
-	/* check for already used inode; makes sense only for ZEROED itable */
-	if (__predict_false(ip->i_e2fs_mode && ip->i_e2fs_nlink != 0)) {
-		printf("mode = 0%o, nlinks %d, inum = %llu, fs = %s\n",
-		ip->i_e2fs_mode, ip->i_e2fs_nlink,
-		(unsigned long long)ip->i_number, fs->e2fs_fsmnt);
-		panic("ext2fs_valloc: dup alloc");
-	}
-
-	memset(ip->i_din.e2fs_din, 0, EXT2_DINODE_SIZE(fs));
 
-	/*
-	 * Set up a new generation number for this inode.
-	 */
-	if (++ext2gennumber < time_second)
-		ext2gennumber = time_second;
-	ip->i_e2fs_gen = ext2gennumber;
+	*inop = ino;
 	return 0;
+
 noinodes:
 	ext2fs_fserr(fs, kauth_cred_geteuid(cred), "out of inodes");
 	uprintf("\n%s: create/symlink failed, no inodes free\n", fs->e2fs_fsmnt);

Index: src/sys/ufs/ext2fs/ext2fs_extern.h
diff -u src/sys/ufs/ext2fs/ext2fs_extern.h:1.55 src/sys/ufs/ext2fs/ext2fs_extern.h:1.56
--- src/sys/ufs/ext2fs/ext2fs_extern.h:1.55	Sat Aug 20 19:47:44 2016
+++ src/sys/ufs/ext2fs/ext2fs_extern.h	Sun May 28 16:38:55 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ext2fs_extern.h,v 1.55 2016/08/20 19:47:44 jdolecek Exp $	*/
+/*	$NetBSD: ext2fs_extern.h,v 1.56 2017/05/28 16:38:55 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993, 1994
@@ -95,7 +95,7 @@ int ext2fs_alloc(struct inode *, daddr_t
 		   daddr_t *);
 int ext2fs_realloccg(struct inode *, daddr_t, daddr_t, int, int ,
 			  kauth_cred_t, struct buf **);
-int ext2fs_valloc(struct vnode *, int, kauth_cred_t, struct vnode **);
+int ext2fs_valloc(struct vnode *, int, kauth_cred_t, ino_t *);
 /* XXX ondisk32 */
 daddr_t ext2fs_blkpref(struct inode *, daddr_t, int, int32_t *);
 void ext2fs_blkfree(struct inode *, daddr_t);
@@ -176,8 +176,6 @@ int ext2fs_advlock(void *);
 int ext2fs_fsync(void *);
 int ext2fs_vinit(struct mount *, int (**specops)(void *),
 		  int (**fifoops)(void *), struct vnode **);
-int ext2fs_makeinode(int, struct vnode *, struct vnode **,
-			  struct componentname *cnp, int);
 int ext2fs_reclaim(void *);
 
 /* ext2fs_hash.c */

Index: src/sys/ufs/ext2fs/ext2fs_vfsops.c
diff -u src/sys/ufs/ext2fs/ext2fs_vfsops.c:1.208 src/sys/ufs/ext2fs/ext2fs_vfsops.c:1.209
--- src/sys/ufs/ext2fs/ext2fs_vfsops.c:1.208	Mon Apr 17 08:32:01 2017
+++ src/sys/ufs/ext2fs/ext2fs_vfsops.c	Sun May 28 16:38:55 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ext2fs_vfsops.c,v 1.208 2017/04/17 08:32:01 hannken Exp $	*/
+/*	$NetBSD: ext2fs_vfsops.c,v 1.209 2017/05/28 16:38:55 hannken Exp $	*/
 
 /*
  * Copyright (c) 1989, 1991, 1993, 1994
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ext2fs_vfsops.c,v 1.208 2017/04/17 08:32:01 

CVS commit: src/sys/ufs/ffs

2017-05-28 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sun May 28 16:37:55 UTC 2017

Modified Files:
src/sys/ufs/ffs: ffs_wapbl.c

Log Message:
No need to call vgone() on the just created in file system log vnode,
vput() is sufficient.


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/sys/ufs/ffs/ffs_wapbl.c

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

Modified files:

Index: src/sys/ufs/ffs/ffs_wapbl.c
diff -u src/sys/ufs/ffs/ffs_wapbl.c:1.40 src/sys/ufs/ffs/ffs_wapbl.c:1.41
--- src/sys/ufs/ffs/ffs_wapbl.c:1.40	Wed Mar 22 21:30:59 2017
+++ src/sys/ufs/ffs/ffs_wapbl.c	Sun May 28 16:37:55 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_wapbl.c,v 1.40 2017/03/22 21:30:59 jdolecek Exp $	*/
+/*	$NetBSD: ffs_wapbl.c,v 1.41 2017/05/28 16:37:55 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2003,2006,2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_wapbl.c,v 1.40 2017/03/22 21:30:59 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_wapbl.c,v 1.41 2017/05/28 16:37:55 hannken Exp $");
 
 #define WAPBL_INTERNAL
 
@@ -686,8 +686,7 @@ wapbl_create_infs_log(struct mount *mp, 
 		 */
 		ip->i_nlink = 0;
 		DIP_ASSIGN(ip, nlink, 0);
-		VOP_UNLOCK(vp);
-		vgone(vp);
+		vput(vp);
 
 		return error;
 	}
@@ -696,8 +695,7 @@ wapbl_create_infs_log(struct mount *mp, 
 	 * Now that we have the place-holder inode for the journal,
 	 * we don't need the vnode ever again.
 	 */
-	VOP_UNLOCK(vp);
-	vgone(vp);
+	vput(vp);
 
 	return 0;
 }



CVS commit: src/sys/rump/librump/rumpvfs

2017-05-28 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sun May 28 16:37:16 UTC 2017

Modified Files:
src/sys/rump/librump/rumpvfs: rumpfs.c

Log Message:
Suspend file system for vgone().


To generate a diff of this commit:
cvs rdiff -u -r1.149 -r1.150 src/sys/rump/librump/rumpvfs/rumpfs.c

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

Modified files:

Index: src/sys/rump/librump/rumpvfs/rumpfs.c
diff -u src/sys/rump/librump/rumpvfs/rumpfs.c:1.149 src/sys/rump/librump/rumpvfs/rumpfs.c:1.150
--- src/sys/rump/librump/rumpvfs/rumpfs.c:1.149	Fri May 26 14:21:00 2017
+++ src/sys/rump/librump/rumpvfs/rumpfs.c	Sun May 28 16:37:16 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: rumpfs.c,v 1.149 2017/05/26 14:21:00 riastradh Exp $	*/
+/*	$NetBSD: rumpfs.c,v 1.150 2017/05/28 16:37:16 hannken Exp $	*/
 
 /*
  * Copyright (c) 2009, 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: rumpfs.c,v 1.149 2017/05/26 14:21:00 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rumpfs.c,v 1.150 2017/05/28 16:37:16 hannken Exp $");
 
 #include 
 #include 
@@ -46,6 +46,7 @@ __KERNEL_RCSID(0, "$NetBSD: rumpfs.c,v 1
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -491,8 +492,12 @@ etfsremove(const char *key)
 			mp = NULL;
 		}
 		mutex_exit();
-		if (mp && vcache_get(mp, , sizeof(rn), ) == 0)
+		if (mp && vcache_get(mp, , sizeof(rn), ) == 0) {
+			rv = vfs_suspend(mp, 0);
+			KASSERT(rv == 0);
 			vgone(vp);
+			vfs_resume(mp);
+		}
 	}
 
 	if (et->et_rn->rn_hostpath != NULL)



CVS commit: src/sys/fs/smbfs

2017-05-28 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sun May 28 16:36:37 UTC 2017

Modified Files:
src/sys/fs/smbfs: smbfs_node.c smbfs_node.h smbfs_vnops.c

Log Message:
When a vnode has an invalid type because the type changed on the
server replace vgone() with new operation smbfs_uncache() that
removes the vnode from the name cache and changes the vcache key
to an unique and illegal key to prevent further lookups.


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/sys/fs/smbfs/smbfs_node.c
cvs rdiff -u -r1.15 -r1.16 src/sys/fs/smbfs/smbfs_node.h
cvs rdiff -u -r1.94 -r1.95 src/sys/fs/smbfs/smbfs_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/sys/fs/smbfs/smbfs_node.c
diff -u src/sys/fs/smbfs/smbfs_node.c:1.57 src/sys/fs/smbfs/smbfs_node.c:1.58
--- src/sys/fs/smbfs/smbfs_node.c:1.57	Fri May 26 14:34:20 2017
+++ src/sys/fs/smbfs/smbfs_node.c	Sun May 28 16:36:37 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: smbfs_node.c,v 1.57 2017/05/26 14:34:20 riastradh Exp $	*/
+/*	$NetBSD: smbfs_node.c,v 1.58 2017/05/28 16:36:37 hannken Exp $	*/
 
 /*
  * Copyright (c) 2000-2001 Boris Popov
@@ -35,10 +35,11 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: smbfs_node.c,v 1.57 2017/05/26 14:34:20 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: smbfs_node.c,v 1.58 2017/05/28 16:36:37 hannken Exp $");
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -191,7 +192,8 @@ retry:
 		if ((vp->v_type == VDIR && (np->n_dosattr & SMB_FA_DIR) == 0) ||
 		(vp->v_type == VREG && (np->n_dosattr & SMB_FA_DIR) != 0)) {
 			mutex_exit(>n_lock);
-			vgone(vp);
+			vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
+			smbfs_uncache(vp);
 			goto retry;
  		}
 	}
@@ -207,6 +209,54 @@ out:
 }
 
 /*
+ * Remove vnode that changed its type on the server from
+ * the vnode cache and the name cache.
+ */
+void
+smbfs_uncache(struct vnode *vp)
+{
+	static uint32_t gen = 0;
+	int error __diagused;
+	char newname[10];
+	struct mount *mp = vp->v_mount;
+	struct smbnode *np = VTOSMB(vp);
+	struct smbkey *key = np->n_key, *oldkey, *newkey;
+	int key_len = SMBFS_KEYSIZE(key->k_nmlen), newkey_len;
+
+	/* Setup old key as current key. */
+	oldkey = kmem_alloc(key_len, KM_SLEEP);
+	memcpy(oldkey, key, key_len);
+
+	/* Setup new key as unique and illegal name with colon. */
+	snprintf(newname, sizeof(newname), ":%08x", atomic_inc_uint_nv());
+	newkey = kmem_alloc(SMBFS_KEYSIZE(strlen(newname)), KM_SLEEP);
+	newkey->k_parent = NULL;
+	newkey->k_nmlen = strlen(newname);
+	memcpy(newkey->k_name, newname, newkey->k_nmlen);
+	newkey_len = SMBFS_KEYSIZE(newkey->k_nmlen);
+
+	/* Release parent and mark as gone. */
+	if (np->n_parent && (np->n_flag & NREFPARENT)) {
+		vrele(np->n_parent);
+		np->n_flag &= ~NREFPARENT;
+	}
+	np->n_flag |= NGONE;
+
+	/* Rekey the node. */
+	error = vcache_rekey_enter(mp, vp, oldkey, key_len, newkey, newkey_len);
+	KASSERT(error == 0);
+	np->n_key = newkey;
+	vcache_rekey_exit(mp, vp, oldkey, key_len, newkey, newkey_len);
+
+	/* Purge from name cache and cleanup. */
+	cache_purge(vp);
+	kmem_free(key, key_len);
+	kmem_free(oldkey, key_len);
+
+	vput(vp);
+}
+
+/*
  * Free smbnode, and give vnode back to system
  */
 int

Index: src/sys/fs/smbfs/smbfs_node.h
diff -u src/sys/fs/smbfs/smbfs_node.h:1.15 src/sys/fs/smbfs/smbfs_node.h:1.16
--- src/sys/fs/smbfs/smbfs_node.h:1.15	Fri Jan  2 09:48:01 2015
+++ src/sys/fs/smbfs/smbfs_node.h	Sun May 28 16:36:37 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: smbfs_node.h,v 1.15 2015/01/02 09:48:01 martin Exp $	*/
+/*	$NetBSD: smbfs_node.h,v 1.16 2017/05/28 16:36:37 hannken Exp $	*/
 
 /*
  * Copyright (c) 2000-2001, Boris Popov
@@ -97,6 +97,7 @@ int smbfs_loadvnode(struct mount *, stru
 const void *, size_t, const void **);
 int smbfs_nget(struct mount *, struct vnode *, const char *, int,
 struct smbfattr *, struct vnode **);
+void smbfs_uncache(struct vnode *);
 
 int  smbfs_readvnode(struct vnode *, struct uio *, kauth_cred_t);
 int  smbfs_writevnode(struct vnode *, struct uio *, kauth_cred_t, int);

Index: src/sys/fs/smbfs/smbfs_vnops.c
diff -u src/sys/fs/smbfs/smbfs_vnops.c:1.94 src/sys/fs/smbfs/smbfs_vnops.c:1.95
--- src/sys/fs/smbfs/smbfs_vnops.c:1.94	Wed Apr 26 03:02:48 2017
+++ src/sys/fs/smbfs/smbfs_vnops.c	Sun May 28 16:36:37 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: smbfs_vnops.c,v 1.94 2017/04/26 03:02:48 riastradh Exp $	*/
+/*	$NetBSD: smbfs_vnops.c,v 1.95 2017/05/28 16:36:37 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: smbfs_vnops.c,v 1.94 2017/04/26 03:02:48 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: smbfs_vnops.c,v 1.95 2017/05/28 16:36:37 hannken Exp $");
 
 #include 
 #include 
@@ -1269,8 +1269,7 @@ smbfs_lookup(void *v)
 		cache_purge(newvp);
 		if (newvp != dvp) {
 			if (killit) {
-VOP_UNLOCK(newvp);
-vgone(newvp);
+smbfs_uncache(newvp);
 			} 

CVS commit: src/sys/kern

2017-05-28 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sun May 28 16:35:47 UTC 2017

Modified Files:
src/sys/kern: vfs_vnode.c

Log Message:
Add a helper to propagate file system suspension for vrevoke().

Take care to retry suspension on interrupt as vrevoke must succeed.


To generate a diff of this commit:
cvs rdiff -u -r1.91 -r1.92 src/sys/kern/vfs_vnode.c

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

Modified files:

Index: src/sys/kern/vfs_vnode.c
diff -u src/sys/kern/vfs_vnode.c:1.91 src/sys/kern/vfs_vnode.c:1.92
--- src/sys/kern/vfs_vnode.c:1.91	Fri May 26 14:40:09 2017
+++ src/sys/kern/vfs_vnode.c	Sun May 28 16:35:47 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_vnode.c,v 1.91 2017/05/26 14:40:09 riastradh Exp $	*/
+/*	$NetBSD: vfs_vnode.c,v 1.92 2017/05/28 16:35:47 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1997-2011 The NetBSD Foundation, Inc.
@@ -156,7 +156,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.91 2017/05/26 14:40:09 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.92 2017/05/28 16:35:47 hannken Exp $");
 
 #include 
 #include 
@@ -944,13 +944,42 @@ vrecycle(vnode_t *vp)
 }
 
 /*
+ * Helper for vrevoke() to propagate suspension from lastmp
+ * to thismp.  Both args may be NULL.
+ * Returns the currently suspended file system or NULL.
+ */
+static struct mount *
+vrevoke_suspend_next(struct mount *lastmp, struct mount *thismp)
+{
+	int error;
+
+	if (lastmp == thismp)
+		return thismp;
+
+	if (lastmp != NULL)
+		vfs_resume(lastmp);
+
+	if (thismp == NULL)
+		return NULL;
+
+	do {
+		error = vfs_suspend(thismp, 0);
+	} while (error == EINTR || error == ERESTART);
+
+	if (error == 0)
+		return thismp;
+
+	KASSERT(error == EOPNOTSUPP);
+	return NULL;
+}
+
+/*
  * Eliminate all activity associated with the requested vnode
  * and with all vnodes aliased to the requested vnode.
  */
 void
 vrevoke(vnode_t *vp)
 {
-	int error;
 	struct mount *mp;
 	vnode_t *vq;
 	enum vtype type;
@@ -958,11 +987,7 @@ vrevoke(vnode_t *vp)
 
 	KASSERT(vp->v_usecount > 0);
 
-	mp = vp->v_mount;
-	error = vfs_suspend(mp, 0);
-	KASSERT(error == 0 || error == EOPNOTSUPP);
-	if (error)
-		mp = NULL;
+	mp = vrevoke_suspend_next(NULL, vp->v_mount);
 
 	mutex_enter(vp->v_interlock);
 	VSTATE_WAIT_STABLE(vp);
@@ -978,20 +1003,11 @@ vrevoke(vnode_t *vp)
 		mutex_exit(vp->v_interlock);
 
 		while (spec_node_lookup_by_dev(type, dev, ) == 0) {
-			if (mp != vq->v_mount) {
-if (mp)
-	vfs_resume(mp);
-mp = vp->v_mount;
-error = vfs_suspend(mp, 0);
-KASSERT(error == 0 || error == EOPNOTSUPP);
-if (error)
-	mp = NULL;
-			}
+			mp = vrevoke_suspend_next(mp, vq->v_mount);
 			vgone(vq);
 		}
 	}
-	if (mp)
-		vfs_resume(mp);
+	vrevoke_suspend_next(mp, NULL);
 }
 
 /*



CVS commit: src/sys/fs/union

2017-05-24 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed May 24 09:55:19 UTC 2017

Modified Files:
src/sys/fs/union: union_vnops.c

Log Message:
Use VCALL() to lock or unlock the lower node.


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 src/sys/fs/union/union_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/sys/fs/union/union_vnops.c
diff -u src/sys/fs/union/union_vnops.c:1.68 src/sys/fs/union/union_vnops.c:1.69
--- src/sys/fs/union/union_vnops.c:1.68	Sun May  7 08:22:40 2017
+++ src/sys/fs/union/union_vnops.c	Wed May 24 09:55:18 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: union_vnops.c,v 1.68 2017/05/07 08:22:40 hannken Exp $	*/
+/*	$NetBSD: union_vnops.c,v 1.69 2017/05/24 09:55:18 hannken Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993, 1994, 1995
@@ -72,7 +72,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: union_vnops.c,v 1.68 2017/05/07 08:22:40 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: union_vnops.c,v 1.69 2017/05/24 09:55:18 hannken Exp $");
 
 #include 
 #include 
@@ -1600,12 +1600,14 @@ union_lock1(struct vnode *vp, struct vno
 {
 	struct vop_lock_args ap;
 
-	if (lockvp == vp) {
-		ap.a_vp = vp;
-		ap.a_flags = flags;
+	ap.a_desc = VDESC(vop_lock);
+	ap.a_vp = lockvp;
+	ap.a_flags = flags;
+
+	if (lockvp == vp)
 		return genfs_lock();
-	} else
-		return VOP_LOCK(lockvp, flags);
+	else
+		return VCALL(ap.a_vp, VOFFSET(vop_lock), );
 }
 
 static int
@@ -1613,11 +1615,13 @@ union_unlock1(struct vnode *vp, struct v
 {
 	struct vop_unlock_args ap;
 
-	if (lockvp == vp) {
-		ap.a_vp = vp;
+	ap.a_desc = VDESC(vop_unlock);
+	ap.a_vp = lockvp;
+
+	if (lockvp == vp)
 		return genfs_unlock();
-	} else
-		return VOP_UNLOCK(lockvp);
+	else
+		return VCALL(ap.a_vp, VOFFSET(vop_unlock), );
 }
 
 int



CVS commit: src/sys/miscfs/genfs

2017-05-24 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed May 24 09:54:40 UTC 2017

Modified Files:
src/sys/miscfs/genfs: layer_vnops.c

Log Message:
Protect layer_getpages against vnodes disappearing during a
forced unmount.


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 src/sys/miscfs/genfs/layer_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/sys/miscfs/genfs/layer_vnops.c
diff -u src/sys/miscfs/genfs/layer_vnops.c:1.64 src/sys/miscfs/genfs/layer_vnops.c:1.65
--- src/sys/miscfs/genfs/layer_vnops.c:1.64	Sun May  7 08:21:57 2017
+++ src/sys/miscfs/genfs/layer_vnops.c	Wed May 24 09:54:40 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: layer_vnops.c,v 1.64 2017/05/07 08:21:57 hannken Exp $	*/
+/*	$NetBSD: layer_vnops.c,v 1.65 2017/05/24 09:54:40 hannken Exp $	*/
 
 /*
  * Copyright (c) 1999 National Aeronautics & Space Administration
@@ -170,7 +170,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: layer_vnops.c,v 1.64 2017/05/07 08:21:57 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: layer_vnops.c,v 1.65 2017/05/24 09:54:40 hannken Exp $");
 
 #include 
 #include 
@@ -183,6 +183,7 @@ __KERNEL_RCSID(0, "$NetBSD: layer_vnops.
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -790,6 +791,8 @@ layer_getpages(void *v)
 		int a_flags;
 	} */ *ap = v;
 	struct vnode *vp = ap->a_vp;
+	struct mount *mp = vp->v_mount;
+	int error;
 
 	KASSERT(mutex_owned(vp->v_interlock));
 
@@ -800,7 +803,19 @@ layer_getpages(void *v)
 	KASSERT(vp->v_interlock == ap->a_vp->v_interlock);
 
 	/* Just pass the request on to the underlying layer. */
-	return VCALL(ap->a_vp, VOFFSET(vop_getpages), ap);
+	mutex_exit(vp->v_interlock);
+	fstrans_start(mp, FSTRANS_SHARED);
+	mutex_enter(vp->v_interlock);
+	if (mp == vp->v_mount) {
+		/* Will release the interlock. */
+		error = VCALL(ap->a_vp, VOFFSET(vop_getpages), ap);
+	} else {
+		mutex_exit(vp->v_interlock);
+		error = ENOENT;
+	}
+	fstrans_done(mp);
+
+	return error;
 }
 
 int



CVS commit: src/sys

2017-05-24 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed May 24 09:53:55 UTC 2017

Modified Files:
src/sys/kern: vfs_mount.c vfs_subr.c
src/sys/miscfs/genfs: genfs_vfsops.c
src/sys/sys: mount.h param.h

Log Message:
With dounmount() working on a suspended file system remove no longer
needed fields mnt_busynest and mnt_unmounting from struct mount.

Welcome to 7.99.73


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/sys/kern/vfs_mount.c
cvs rdiff -u -r1.465 -r1.466 src/sys/kern/vfs_subr.c
cvs rdiff -u -r1.6 -r1.7 src/sys/miscfs/genfs/genfs_vfsops.c
cvs rdiff -u -r1.227 -r1.228 src/sys/sys/mount.h
cvs rdiff -u -r1.539 -r1.540 src/sys/sys/param.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/vfs_mount.c
diff -u src/sys/kern/vfs_mount.c:1.63 src/sys/kern/vfs_mount.c:1.64
--- src/sys/kern/vfs_mount.c:1.63	Wed May 24 09:52:59 2017
+++ src/sys/kern/vfs_mount.c	Wed May 24 09:53:55 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_mount.c,v 1.63 2017/05/24 09:52:59 hannken Exp $	*/
+/*	$NetBSD: vfs_mount.c,v 1.64 2017/05/24 09:53:55 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1997-2011 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.63 2017/05/24 09:52:59 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.64 2017/05/24 09:53:55 hannken Exp $");
 
 #include 
 #include 
@@ -158,7 +158,6 @@ vfs_mountalloc(struct vfsops *vfsops, vn
 	mp->mnt_op = vfsops;
 	mp->mnt_refcnt = 1;
 	TAILQ_INIT(>mnt_vnodelist);
-	mutex_init(>mnt_unmounting, MUTEX_DEFAULT, IPL_NONE);
 	mutex_init(>mnt_renamelock, MUTEX_DEFAULT, IPL_NONE);
 	mutex_init(>mnt_updating, MUTEX_DEFAULT, IPL_NONE);
 	mp->mnt_vnodecovered = vp;
@@ -298,7 +297,6 @@ vfs_rele(struct mount *mp)
 	 */
 	KASSERT(mp->mnt_refcnt == 0);
 	specificdata_fini(mount_specificdata_domain, >mnt_specdataref);
-	mutex_destroy(>mnt_unmounting);
 	mutex_destroy(>mnt_updating);
 	mutex_destroy(>mnt_renamelock);
 	if (mp->mnt_op != NULL) {
@@ -325,23 +323,14 @@ _vfs_busy(struct mount *mp, bool wait)
 
 	if (wait) {
 		fstrans_start(mp, FSTRANS_SHARED);
-		mutex_enter(>mnt_unmounting);
 	} else {
 		if (fstrans_start_nowait(mp, FSTRANS_SHARED))
 			return EBUSY;
-		if (!mutex_tryenter(>mnt_unmounting)) {
-			fstrans_done(mp);
-			return EBUSY;
-		}
 	}
 	if (__predict_false((mp->mnt_iflag & IMNT_GONE) != 0)) {
-		mutex_exit(>mnt_unmounting);
 		fstrans_done(mp);
 		return ENOENT;
 	}
-	++mp->mnt_busynest;
-	KASSERT(mp->mnt_busynest != 0);
-	mutex_exit(>mnt_unmounting);
 	vfs_ref(mp);
 	return 0;
 }
@@ -371,10 +360,6 @@ vfs_unbusy(struct mount *mp)
 
 	KASSERT(mp->mnt_refcnt > 0);
 
-	mutex_enter(>mnt_unmounting);
-	KASSERT(mp->mnt_busynest != 0);
-	mp->mnt_busynest--;
-	mutex_exit(>mnt_unmounting);
 	fstrans_done(mp);
 	vfs_rele(mp);
 }
@@ -874,23 +859,7 @@ dounmount(struct mount *mp, int flags, s
 		return error;
 	}
 
-	/*
-	 * Abort unmount attempt when the filesystem is in use
-	 */
-	mutex_enter(>mnt_unmounting);
-	if (mp->mnt_busynest != 0) {
-		mutex_exit(>mnt_unmounting);
-		vfs_resume(mp);
-		return EBUSY;
-	}
-
-	/*
-	 * Abort unmount attempt when the filesystem is not mounted
-	 */
-	if ((mp->mnt_iflag & IMNT_GONE) != 0) {
-		mutex_exit(>mnt_unmounting);
-		return ENOENT;
-	}
+	KASSERT((mp->mnt_iflag & IMNT_GONE) == 0);
 
 	used_syncer = (mp->mnt_iflag & IMNT_ONWORKLIST) != 0;
 	used_extattr = mp->mnt_flag & MNT_EXTATTR;
@@ -911,7 +880,6 @@ dounmount(struct mount *mp, int flags, s
 	}
 	if (error) {
 		mp->mnt_iflag &= ~IMNT_UNMOUNT;
-		mutex_exit(>mnt_unmounting);
 		if ((mp->mnt_flag & (MNT_RDONLY | MNT_ASYNC)) == 0)
 			vfs_syncer_add_to_worklist(mp);
 		mp->mnt_flag |= async;
@@ -928,15 +896,11 @@ dounmount(struct mount *mp, int flags, s
 	mutex_exit(>mnt_updating);
 
 	/*
-	 * release mnt_umounting lock here, because other code calls
-	 * vfs_busy() while holding the mountlist_lock.
-	 *
 	 * mark filesystem as gone to prevent further umounts
 	 * after mnt_umounting lock is gone, this also prevents
 	 * vfs_busy() from succeeding.
 	 */
 	mp->mnt_iflag |= IMNT_GONE;
-	mutex_exit(>mnt_unmounting);
 	vfs_resume(mp);
 
 	if ((coveredvp = mp->mnt_vnodecovered) != NULLVP) {

Index: src/sys/kern/vfs_subr.c
diff -u src/sys/kern/vfs_subr.c:1.465 src/sys/kern/vfs_subr.c:1.466
--- src/sys/kern/vfs_subr.c:1.465	Wed May 24 09:52:59 2017
+++ src/sys/kern/vfs_subr.c	Wed May 24 09:53:55 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_subr.c,v 1.465 2017/05/24 09:52:59 hannken Exp $	*/
+/*	$NetBSD: vfs_subr.c,v 1.466 2017/05/24 09:53:55 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998, 2004, 2005, 2007, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.465 2017/05/24 09:52:59 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.466 2017/05/24 09:53:55 hannken Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ 

CVS commit: src/sys

2017-05-24 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed May 24 09:53:00 UTC 2017

Modified Files:
src/sys/kern: vfs_mount.c vfs_subr.c
src/sys/sys: mount.h

Log Message:
Remove the syncer dance from dounmount().  The syncer skips
unmounting file systems as they are suspended.

Remove now unused syncer_mutex.


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 src/sys/kern/vfs_mount.c
cvs rdiff -u -r1.464 -r1.465 src/sys/kern/vfs_subr.c
cvs rdiff -u -r1.226 -r1.227 src/sys/sys/mount.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/vfs_mount.c
diff -u src/sys/kern/vfs_mount.c:1.62 src/sys/kern/vfs_mount.c:1.63
--- src/sys/kern/vfs_mount.c:1.62	Wed May 17 12:45:03 2017
+++ src/sys/kern/vfs_mount.c	Wed May 24 09:52:59 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_mount.c,v 1.62 2017/05/17 12:45:03 hannken Exp $	*/
+/*	$NetBSD: vfs_mount.c,v 1.63 2017/05/24 09:52:59 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1997-2011 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.62 2017/05/17 12:45:03 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.63 2017/05/24 09:52:59 hannken Exp $");
 
 #include 
 #include 
@@ -869,15 +869,8 @@ dounmount(struct mount *mp, int flags, s
 	}
 	mountlist_iterator_destroy(iter);
 
-	/*
-	 * XXX Freeze syncer.  Must do this before locking the
-	 * mount point.  See dounmount() for details.
-	 */
-	mutex_enter(_mutex);
-
 	error = vfs_suspend(mp, 0);
 	if (error) {
-		mutex_exit(_mutex);
 		return error;
 	}
 
@@ -887,7 +880,6 @@ dounmount(struct mount *mp, int flags, s
 	mutex_enter(>mnt_unmounting);
 	if (mp->mnt_busynest != 0) {
 		mutex_exit(>mnt_unmounting);
-		mutex_exit(_mutex);
 		vfs_resume(mp);
 		return EBUSY;
 	}
@@ -897,28 +889,12 @@ dounmount(struct mount *mp, int flags, s
 	 */
 	if ((mp->mnt_iflag & IMNT_GONE) != 0) {
 		mutex_exit(>mnt_unmounting);
-		mutex_exit(_mutex);
 		return ENOENT;
 	}
 
 	used_syncer = (mp->mnt_iflag & IMNT_ONWORKLIST) != 0;
 	used_extattr = mp->mnt_flag & MNT_EXTATTR;
 
-	/*
-	 * XXX Syncer must be frozen when we get here.  This should really
-	 * be done on a per-mountpoint basis, but the syncer doesn't work
-	 * like that.
-	 *
-	 * The caller of dounmount() must acquire syncer_mutex because
-	 * the syncer itself acquires locks in syncer_mutex -> vfs_busy
-	 * order, and we must preserve that order to avoid deadlock.
-	 *
-	 * So, if the file system did not use the syncer, now is
-	 * the time to release the syncer_mutex.
-	 */
-	if (used_syncer == 0) {
-		mutex_exit(_mutex);
-	}
 	mp->mnt_iflag |= IMNT_UNMOUNT;
 	mutex_enter(>mnt_updating);
 	async = mp->mnt_flag & MNT_ASYNC;
@@ -941,8 +917,6 @@ dounmount(struct mount *mp, int flags, s
 		mp->mnt_flag |= async;
 		mutex_exit(>mnt_updating);
 		vfs_resume(mp);
-		if (used_syncer)
-			mutex_exit(_mutex);
 		if (used_extattr) {
 			if (start_extattr(mp) != 0)
 mp->mnt_flag &= ~MNT_EXTATTR;
@@ -973,8 +947,6 @@ dounmount(struct mount *mp, int flags, s
 	mountlist_remove(mp);
 	if (TAILQ_FIRST(>mnt_vnodelist) != NULL)
 		panic("unmount: dangling vnode");
-	if (used_syncer)
-		mutex_exit(_mutex);
 	vfs_hooks_unmount(mp);
 
 	fstrans_unmount(mp);

Index: src/sys/kern/vfs_subr.c
diff -u src/sys/kern/vfs_subr.c:1.464 src/sys/kern/vfs_subr.c:1.465
--- src/sys/kern/vfs_subr.c:1.464	Sun May  7 08:26:58 2017
+++ src/sys/kern/vfs_subr.c	Wed May 24 09:52:59 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_subr.c,v 1.464 2017/05/07 08:26:58 hannken Exp $	*/
+/*	$NetBSD: vfs_subr.c,v 1.465 2017/05/24 09:52:59 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998, 2004, 2005, 2007, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.464 2017/05/07 08:26:58 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.465 2017/05/24 09:52:59 hannken Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -568,7 +568,6 @@ time_t dirdelay  = 15;			/* time to dela
 time_t metadelay = 10;			/* time to delay syncing metadata */
 time_t lockdelay = 1;			/* time to delay if locking fails */
 
-kmutex_t		syncer_mutex;	/* used to freeze syncer, long term */
 static kmutex_t		syncer_data_lock; /* short term lock on data structs */
 
 static int		syncer_delayno = 0;
@@ -590,7 +589,6 @@ vn_initialize_syncerd(void)
 	for (i = 0; i < syncer_last; i++)
 		TAILQ_INIT(_workitem_pending[i]);
 
-	mutex_init(_mutex, MUTEX_DEFAULT, IPL_NONE);
 	mutex_init(_data_lock, MUTEX_DEFAULT, IPL_NONE);
 }
 
@@ -767,8 +765,6 @@ sched_sync(void *arg)
 	bool synced;
 
 	for (;;) {
-		mutex_enter(_mutex);
-
 		starttime = time_second;
 
 		/*
@@ -830,7 +826,6 @@ sched_sync(void *arg)
 synced ? syncdelay : lockdelay);
 			}
 		}
-		mutex_exit(_mutex);
 
 		/*
 		 * If it has taken us less than a second to process the

Index: src/sys/sys/mount.h
diff -u src/sys/sys/mount.h:1.226 

CVS commit: src/sys/kern

2017-05-17 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed May 17 12:46:14 UTC 2017

Modified Files:
src/sys/kern: vfs_vnode.c

Log Message:
Suspend file system while revoking a vnode.  This way no operations run
on the mounted file system during revoke and all operations see
the state before or after the revoke.


To generate a diff of this commit:
cvs rdiff -u -r1.87 -r1.88 src/sys/kern/vfs_vnode.c

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

Modified files:

Index: src/sys/kern/vfs_vnode.c
diff -u src/sys/kern/vfs_vnode.c:1.87 src/sys/kern/vfs_vnode.c:1.88
--- src/sys/kern/vfs_vnode.c:1.87	Mon Apr 17 08:32:01 2017
+++ src/sys/kern/vfs_vnode.c	Wed May 17 12:46:14 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_vnode.c,v 1.87 2017/04/17 08:32:01 hannken Exp $	*/
+/*	$NetBSD: vfs_vnode.c,v 1.88 2017/05/17 12:46:14 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1997-2011 The NetBSD Foundation, Inc.
@@ -156,7 +156,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.87 2017/04/17 08:32:01 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.88 2017/05/17 12:46:14 hannken Exp $");
 
 #include 
 #include 
@@ -950,31 +950,48 @@ vrecycle(vnode_t *vp)
 void
 vrevoke(vnode_t *vp)
 {
+	int error;
+	struct mount *mp;
 	vnode_t *vq;
 	enum vtype type;
 	dev_t dev;
 
 	KASSERT(vp->v_usecount > 0);
 
+	mp = vp->v_mount;
+	error = vfs_suspend(mp, 0);
+	KASSERT(error == 0 || error == EOPNOTSUPP);
+	if (error)
+		mp = NULL;
+
 	mutex_enter(vp->v_interlock);
 	VSTATE_WAIT_STABLE(vp);
 	if (VSTATE_GET(vp) == VS_RECLAIMED) {
 		mutex_exit(vp->v_interlock);
-		return;
 	} else if (vp->v_type != VBLK && vp->v_type != VCHR) {
 		atomic_inc_uint(>v_usecount);
 		mutex_exit(vp->v_interlock);
 		vgone(vp);
-		return;
 	} else {
 		dev = vp->v_rdev;
 		type = vp->v_type;
 		mutex_exit(vp->v_interlock);
-	}
 
-	while (spec_node_lookup_by_dev(type, dev, ) == 0) {
-		vgone(vq);
+		while (spec_node_lookup_by_dev(type, dev, ) == 0) {
+			if (mp != vq->v_mount) {
+if (mp)
+	vfs_resume(mp);
+mp = vp->v_mount;
+error = vfs_suspend(mp, 0);
+KASSERT(error == 0 || error == EOPNOTSUPP);
+if (error)
+	mp = NULL;
+			}
+			vgone(vq);
+		}
 	}
+	if (mp)
+		vfs_resume(mp);
 }
 
 /*



CVS commit: src/sys/kern

2017-05-17 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed May 17 12:45:03 UTC 2017

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

Log Message:
Suspend file system while unmounting.  This way no operations run
on the mounted file system during unmount and all operations see
the state before or after the (possibly failed) unmount.


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 src/sys/kern/vfs_mount.c

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

Modified files:

Index: src/sys/kern/vfs_mount.c
diff -u src/sys/kern/vfs_mount.c:1.61 src/sys/kern/vfs_mount.c:1.62
--- src/sys/kern/vfs_mount.c:1.61	Sun May  7 08:26:58 2017
+++ src/sys/kern/vfs_mount.c	Wed May 17 12:45:03 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_mount.c,v 1.61 2017/05/07 08:26:58 hannken Exp $	*/
+/*	$NetBSD: vfs_mount.c,v 1.62 2017/05/17 12:45:03 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1997-2011 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.61 2017/05/07 08:26:58 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.62 2017/05/17 12:45:03 hannken Exp $");
 
 #include 
 #include 
@@ -599,7 +599,7 @@ vflush(struct mount *mp, vnode_t *skipvp
 		 * First, flush out any vnode references from the
 		 * deferred vrele list.
 		 */
-		vfs_drainvnodes();
+		vrele_flush(mp);
 
 		vfs_vnode_iterator_init(mp, );
 
@@ -875,6 +875,12 @@ dounmount(struct mount *mp, int flags, s
 	 */
 	mutex_enter(_mutex);
 
+	error = vfs_suspend(mp, 0);
+	if (error) {
+		mutex_exit(_mutex);
+		return error;
+	}
+
 	/*
 	 * Abort unmount attempt when the filesystem is in use
 	 */
@@ -882,6 +888,7 @@ dounmount(struct mount *mp, int flags, s
 	if (mp->mnt_busynest != 0) {
 		mutex_exit(>mnt_unmounting);
 		mutex_exit(_mutex);
+		vfs_resume(mp);
 		return EBUSY;
 	}
 
@@ -933,6 +940,7 @@ dounmount(struct mount *mp, int flags, s
 			vfs_syncer_add_to_worklist(mp);
 		mp->mnt_flag |= async;
 		mutex_exit(>mnt_updating);
+		vfs_resume(mp);
 		if (used_syncer)
 			mutex_exit(_mutex);
 		if (used_extattr) {
@@ -955,6 +963,7 @@ dounmount(struct mount *mp, int flags, s
 	 */
 	mp->mnt_iflag |= IMNT_GONE;
 	mutex_exit(>mnt_unmounting);
+	vfs_resume(mp);
 
 	if ((coveredvp = mp->mnt_vnodecovered) != NULLVP) {
 		vn_lock(coveredvp, LK_EXCLUSIVE | LK_RETRY);



CVS commit: src/sys/kern

2017-05-07 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sun May  7 08:26:58 UTC 2017

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

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

Adapt sched_sync() and do_sys_sync().


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

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

Modified files:

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

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

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



CVS commit: src/sys

2017-05-07 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sun May  7 08:25:54 UTC 2017

Modified Files:
src/sys/kern: vfs_syscalls.c
src/sys/miscfs/genfs: genfs_vfsops.c

Log Message:
Return ENOENT if trying to suspend an unmounted file system.


To generate a diff of this commit:
cvs rdiff -u -r1.513 -r1.514 src/sys/kern/vfs_syscalls.c
cvs rdiff -u -r1.5 -r1.6 src/sys/miscfs/genfs/genfs_vfsops.c

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

Modified files:

Index: src/sys/kern/vfs_syscalls.c
diff -u src/sys/kern/vfs_syscalls.c:1.513 src/sys/kern/vfs_syscalls.c:1.514
--- src/sys/kern/vfs_syscalls.c:1.513	Wed Apr 26 03:02:49 2017
+++ src/sys/kern/vfs_syscalls.c	Sun May  7 08:25:54 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_syscalls.c,v 1.513 2017/04/26 03:02:49 riastradh Exp $	*/
+/*	$NetBSD: vfs_syscalls.c,v 1.514 2017/05/07 08:25:54 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.513 2017/04/26 03:02:49 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.514 2017/05/07 08:25:54 hannken Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_fileassoc.h"
@@ -282,11 +282,6 @@ mount_update(struct lwp *l, struct vnode
 	if (error)
 		goto out;
 
-	if (vfs_busy(mp)) {
-		error = EPERM;
-		goto out;
-	}
-
 	error = vfs_suspend(mp, 0);
 	if (error)
 		goto out;
@@ -345,7 +340,6 @@ mount_update(struct lwp *l, struct vnode
 	}
 	mutex_exit(>mnt_updating);
 	vfs_resume(mp);
-	vfs_unbusy(mp);
 
 	if ((error == 0) && !(saved_flags & MNT_EXTATTR) && 
 	(flags & MNT_EXTATTR)) {

Index: src/sys/miscfs/genfs/genfs_vfsops.c
diff -u src/sys/miscfs/genfs/genfs_vfsops.c:1.5 src/sys/miscfs/genfs/genfs_vfsops.c:1.6
--- src/sys/miscfs/genfs/genfs_vfsops.c:1.5	Thu Mar 30 09:12:21 2017
+++ src/sys/miscfs/genfs/genfs_vfsops.c	Sun May  7 08:25:54 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: genfs_vfsops.c,v 1.5 2017/03/30 09:12:21 hannken Exp $	*/
+/*	$NetBSD: genfs_vfsops.c,v 1.6 2017/05/07 08:25:54 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: genfs_vfsops.c,v 1.5 2017/03/30 09:12:21 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: genfs_vfsops.c,v 1.6 2017/05/07 08:25:54 hannken Exp $");
 
 #include 
 #include 
@@ -75,18 +75,30 @@ genfs_renamelock_exit(struct mount *mp)
 int
 genfs_suspendctl(struct mount *mp, int cmd)
 {
-	int error __diagused;
+	int error;
+	int error2 __diagused;
 
 	if ((mp->mnt_iflag & IMNT_HAS_TRANS) == 0)
 		return EOPNOTSUPP;
 
 	switch (cmd) {
 	case SUSPEND_SUSPEND:
-		return fstrans_setstate(mp, FSTRANS_SUSPENDED);
+		error = fstrans_setstate(mp, FSTRANS_SUSPENDED);
+		if (error == 0) {
+			mutex_enter(>mnt_unmounting);
+			if ((mp->mnt_iflag & IMNT_GONE) != 0)
+error = ENOENT;
+			mutex_exit(>mnt_unmounting);
+			if (error) {
+error2 = fstrans_setstate(mp, FSTRANS_NORMAL);
+KASSERT(error2 == 0);
+			}
+		}
+		return error;
 
 	case SUSPEND_RESUME:
-		error = fstrans_setstate(mp, FSTRANS_NORMAL);
-		KASSERT(error == 0);
+		error2 = fstrans_setstate(mp, FSTRANS_NORMAL);
+		KASSERT(error2 == 0);
 		return 0;
 
 	default:



CVS commit: src/sys/kern

2017-05-07 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sun May  7 08:24:20 UTC 2017

Modified Files:
src/sys/kern: vfs_mount.c vfs_trans.c

Log Message:
Move fstrans initialization to vfs_mountalloc().


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/sys/kern/vfs_mount.c
cvs rdiff -u -r1.44 -r1.45 src/sys/kern/vfs_trans.c

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

Modified files:

Index: src/sys/kern/vfs_mount.c
diff -u src/sys/kern/vfs_mount.c:1.59 src/sys/kern/vfs_mount.c:1.60
--- src/sys/kern/vfs_mount.c:1.59	Sun May  7 08:21:08 2017
+++ src/sys/kern/vfs_mount.c	Sun May  7 08:24:20 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_mount.c,v 1.59 2017/05/07 08:21:08 hannken Exp $	*/
+/*	$NetBSD: vfs_mount.c,v 1.60 2017/05/07 08:24:20 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1997-2011 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.59 2017/05/07 08:21:08 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.60 2017/05/07 08:24:20 hannken Exp $");
 
 #include 
 #include 
@@ -148,6 +148,8 @@ struct mount *
 vfs_mountalloc(struct vfsops *vfsops, vnode_t *vp)
 {
 	struct mount *mp;
+	int error __diagused;
+	extern struct vfsops dead_vfsops;
 
 	mp = kmem_zalloc(sizeof(*mp), KM_SLEEP);
 	if (mp == NULL)
@@ -161,6 +163,10 @@ vfs_mountalloc(struct vfsops *vfsops, vn
 	mutex_init(>mnt_updating, MUTEX_DEFAULT, IPL_NONE);
 	mp->mnt_vnodecovered = vp;
 	mount_initspecific(mp);
+	if (vfsops != _vfsops) {
+		error = fstrans_mount(mp);
+		KASSERT(error == 0);
+	}
 
 	mutex_enter(_lock);
 	mp->mnt_gen = mountgen++;
@@ -735,11 +741,6 @@ mount_domount(struct lwp *l, vnode_t **v
 		return ENOMEM;
 	}
 
-	if ((error = fstrans_mount(mp)) != 0) {
-		vfs_rele(mp);
-		return error;
-	}
-
 	mp->mnt_stat.f_owner = kauth_cred_geteuid(l->l_cred);
 
 	/*
@@ -1271,8 +1272,6 @@ done:
 
 		mp->mnt_flag |= MNT_ROOTFS;
 		mp->mnt_op->vfs_refcount++;
-		error = fstrans_mount(mp);
-		KASSERT(error == 0);
 
 		/*
 		 * Get the vnode for '/'.  Set cwdi0.cwdi_cdir to

Index: src/sys/kern/vfs_trans.c
diff -u src/sys/kern/vfs_trans.c:1.44 src/sys/kern/vfs_trans.c:1.45
--- src/sys/kern/vfs_trans.c:1.44	Sun May  7 08:23:28 2017
+++ src/sys/kern/vfs_trans.c	Sun May  7 08:24:20 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_trans.c,v 1.44 2017/05/07 08:23:28 hannken Exp $	*/
+/*	$NetBSD: vfs_trans.c,v 1.45 2017/05/07 08:24:20 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_trans.c,v 1.44 2017/05/07 08:23:28 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_trans.c,v 1.45 2017/05/07 08:24:20 hannken Exp $");
 
 /*
  * File system transaction operations.
@@ -188,12 +188,8 @@ fstrans_mount_dtor(struct mount *mp)
 int
 fstrans_mount(struct mount *mp)
 {
-	int error;
 	struct fstrans_mount_info *newfmi;
 
-	error = vfs_busy(mp);
-	if (error)
-		return error;
 	newfmi = kmem_alloc(sizeof(*newfmi), KM_SLEEP);
 	newfmi->fmi_state = FSTRANS_NORMAL;
 	newfmi->fmi_ref_cnt = 1;
@@ -206,7 +202,6 @@ fstrans_mount(struct mount *mp)
 	mutex_exit(_mount_lock);
 
 	vfs_ref(mp);
-	vfs_unbusy(mp);
 
 	return 0;
 }



CVS commit: src/sys/kern

2017-05-07 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sun May  7 08:23:28 UTC 2017

Modified Files:
src/sys/kern: vfs_trans.c

Log Message:
Handle the case where the mount is gone and its mnt_transinfo is NULL.


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/sys/kern/vfs_trans.c

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

Modified files:

Index: src/sys/kern/vfs_trans.c
diff -u src/sys/kern/vfs_trans.c:1.43 src/sys/kern/vfs_trans.c:1.44
--- src/sys/kern/vfs_trans.c:1.43	Mon Apr 17 08:32:01 2017
+++ src/sys/kern/vfs_trans.c	Sun May  7 08:23:28 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_trans.c,v 1.43 2017/04/17 08:32:01 hannken Exp $	*/
+/*	$NetBSD: vfs_trans.c,v 1.44 2017/05/07 08:23:28 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_trans.c,v 1.43 2017/04/17 08:32:01 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_trans.c,v 1.44 2017/05/07 08:23:28 hannken Exp $");
 
 /*
  * File system transaction operations.
@@ -293,13 +293,16 @@ fstrans_get_lwp_info(struct mount *mp, b
 	}
 
 	/*
-	 * Attach the entry to the mount.
+	 * Attach the entry to the mount if its mnt_transinfo is valid.
 	 */
 	mutex_enter(_mount_lock);
 	fmi = mp->mnt_transinfo;
-	KASSERT(fmi != NULL);
-	fli->fli_mount = mp;
-	fmi->fmi_ref_cnt += 1;
+	if (__predict_true(fmi != NULL)) {
+		fli->fli_mount = mp;
+		fmi->fmi_ref_cnt += 1;
+	} else {
+		fli = NULL;
+	}
 	mutex_exit(_mount_lock);
 
 	return fli;
@@ -346,7 +349,6 @@ _fstrans_start(struct mount *mp, enum fs
 	 */
 	for (lmp = mp; lmp->mnt_lower; lmp = lmp->mnt_lower) {
 		fli = fstrans_get_lwp_info(lmp, true);
-		KASSERT(fli != NULL);
 	}
 
 	if ((fli = fstrans_get_lwp_info(lmp, true)) == NULL)
@@ -395,8 +397,8 @@ fstrans_done(struct mount *mp)
 
 	if ((mp = fstrans_normalize_mount(mp)) == NULL)
 		return;
-	fli = fstrans_get_lwp_info(mp, false);
-	KASSERT(fli != NULL);
+	if ((fli = fstrans_get_lwp_info(mp, false)) == NULL)
+		return;
 	KASSERT(fli->fli_trans_cnt > 0);
 
 	if (fli->fli_trans_cnt > 1) {



CVS commit: src/sys/fs/union

2017-05-07 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sun May  7 08:22:40 UTC 2017

Modified Files:
src/sys/fs/union: union_vnops.c

Log Message:
Move v_writecount adjustment from revoke to reclaim.


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 src/sys/fs/union/union_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/sys/fs/union/union_vnops.c
diff -u src/sys/fs/union/union_vnops.c:1.67 src/sys/fs/union/union_vnops.c:1.68
--- src/sys/fs/union/union_vnops.c:1.67	Wed Apr 26 03:02:48 2017
+++ src/sys/fs/union/union_vnops.c	Sun May  7 08:22:40 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: union_vnops.c,v 1.67 2017/04/26 03:02:48 riastradh Exp $	*/
+/*	$NetBSD: union_vnops.c,v 1.68 2017/05/07 08:22:40 hannken Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993, 1994, 1995
@@ -72,7 +72,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: union_vnops.c,v 1.67 2017/04/26 03:02:48 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: union_vnops.c,v 1.68 2017/05/07 08:22:40 hannken Exp $");
 
 #include 
 #include 
@@ -1064,13 +1064,8 @@ union_revoke(void *v)
 	} */ *ap = v;
 	struct vnode *vp = ap->a_vp;
 
-	if (UPPERVP(vp)) {
-		mutex_enter(UPPERVP(vp)->v_interlock);
-		KASSERT(vp->v_interlock == UPPERVP(vp)->v_interlock);
-		UPPERVP(vp)->v_writecount -= vp->v_writecount;
-		mutex_exit(UPPERVP(vp)->v_interlock);
+	if (UPPERVP(vp))
 		VOP_REVOKE(UPPERVP(vp), ap->a_flags);
-	}
 	if (LOWERVP(vp))
 		VOP_REVOKE(LOWERVP(vp), ap->a_flags);
 	vgone(vp);	/* XXXAD?? */
@@ -1585,8 +1580,17 @@ union_reclaim(void *v)
 	struct vop_reclaim_args /* {
 		struct vnode *a_vp;
 	} */ *ap = v;
+	struct vnode *vp = ap->a_vp;
+	struct vnode *uvp = UPPERVP(vp);
+
+	if (uvp != NULL) {
+		mutex_enter(uvp->v_interlock);
+		KASSERT(vp->v_interlock == uvp->v_interlock);
+		uvp->v_writecount -= vp->v_writecount;
+		mutex_exit(uvp->v_interlock);
+	}
 
-	union_freevp(ap->a_vp);
+	union_freevp(vp);
 
 	return (0);
 }



CVS commit: src/sys/miscfs/genfs

2017-05-07 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sun May  7 08:21:57 UTC 2017

Modified Files:
src/sys/miscfs/genfs: layer_vnops.c

Log Message:
Move v_writecount adjustment from revoke to reclaim.


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/sys/miscfs/genfs/layer_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/sys/miscfs/genfs/layer_vnops.c
diff -u src/sys/miscfs/genfs/layer_vnops.c:1.63 src/sys/miscfs/genfs/layer_vnops.c:1.64
--- src/sys/miscfs/genfs/layer_vnops.c:1.63	Wed Apr 26 03:02:49 2017
+++ src/sys/miscfs/genfs/layer_vnops.c	Sun May  7 08:21:57 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: layer_vnops.c,v 1.63 2017/04/26 03:02:49 riastradh Exp $	*/
+/*	$NetBSD: layer_vnops.c,v 1.64 2017/05/07 08:21:57 hannken Exp $	*/
 
 /*
  * Copyright (c) 1999 National Aeronautics & Space Administration
@@ -170,7 +170,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: layer_vnops.c,v 1.63 2017/04/26 03:02:49 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: layer_vnops.c,v 1.64 2017/05/07 08:21:57 hannken Exp $");
 
 #include 
 #include 
@@ -693,15 +693,8 @@ layer_revoke(void *v)
 	 * We will most likely end up in vclean which uses the v_usecount
 	 * to determine if a vnode is active.  Take an extra reference on
 	 * the lower vnode so it will always close and inactivate.
-	 * Remove our writecount from the lower vnode.
 	 */
 	vref(lvp);
-
-	mutex_enter(vp->v_interlock);
-	KASSERT(vp->v_interlock == lvp->v_interlock);
-	lvp->v_writecount -= vp->v_writecount;
-	mutex_exit(vp->v_interlock);
-
 	error = LAYERFS_DO_BYPASS(vp, ap);
 	vrele(lvp);
 
@@ -734,6 +727,12 @@ layer_reclaim(void *v)
 		 */
 		lmp->layerm_rootvp = NULL;
 	}
+
+	mutex_enter(vp->v_interlock);
+	KASSERT(vp->v_interlock == lowervp->v_interlock);
+	lowervp->v_writecount -= vp->v_writecount;
+	mutex_exit(vp->v_interlock);
+
 	/* After this assignment, this node will not be re-used. */
 	xp->layer_lowervp = NULL;
 	kmem_free(vp->v_data, lmp->layerm_size);



CVS commit: src/sys/kern

2017-05-07 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sun May  7 08:21:08 UTC 2017

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

Log Message:
Remove now invalid comment.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/sys/kern/vfs_mount.c

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

Modified files:

Index: src/sys/kern/vfs_mount.c
diff -u src/sys/kern/vfs_mount.c:1.58 src/sys/kern/vfs_mount.c:1.59
--- src/sys/kern/vfs_mount.c:1.58	Mon Apr 17 08:34:27 2017
+++ src/sys/kern/vfs_mount.c	Sun May  7 08:21:08 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_mount.c,v 1.58 2017/04/17 08:34:27 hannken Exp $	*/
+/*	$NetBSD: vfs_mount.c,v 1.59 2017/05/07 08:21:08 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1997-2011 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.58 2017/04/17 08:34:27 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.59 2017/05/07 08:21:08 hannken Exp $");
 
 #include 
 #include 
@@ -351,9 +351,6 @@ vfs_trybusy(struct mount *mp)
  * Unbusy a busy filesystem.
  *
  * Every successful vfs_busy() call must be undone by a vfs_unbusy() call.
- *
- * => If keepref is true, preserve reference added by vfs_busy().
- * => If nextp != NULL, acquire mountlist_lock.
  */
 void
 vfs_unbusy(struct mount *mp)



CVS commit: src/sys/sys

2017-04-17 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Mon Apr 17 08:34:58 UTC 2017

Modified Files:
src/sys/sys: param.h

Log Message:
Welcome to 7.99.70


To generate a diff of this commit:
cvs rdiff -u -r1.536 -r1.537 src/sys/sys/param.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/sys/param.h
diff -u src/sys/sys/param.h:1.536 src/sys/sys/param.h:1.537
--- src/sys/sys/param.h:1.536	Thu Apr 13 16:32:00 2017
+++ src/sys/sys/param.h	Mon Apr 17 08:34:58 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: param.h,v 1.536 2017/04/13 16:32:00 christos Exp $	*/
+/*	$NetBSD: param.h,v 1.537 2017/04/17 08:34:58 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -67,7 +67,7 @@
  *	2.99.9		(299000900)
  */
 
-#define	__NetBSD_Version__	799006900	/* NetBSD 7.99.69 */
+#define	__NetBSD_Version__	799007000	/* NetBSD 7.99.70 */
 
 #define __NetBSD_Prereq__(M,m,p) (M) * 1) + \
 (m) * 100) + (p) * 100) <= __NetBSD_Version__)



CVS commit: src/sys

2017-04-17 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Mon Apr 17 08:34:27 UTC 2017

Modified Files:
src/sys/kern: vfs_mount.c vfs_subr.c
src/sys/sys: mount.h

Log Message:
Add vfs_trybusy() and mountlist_iterator_trynext() and use it for the syncer.


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/sys/kern/vfs_mount.c
cvs rdiff -u -r1.462 -r1.463 src/sys/kern/vfs_subr.c
cvs rdiff -u -r1.225 -r1.226 src/sys/sys/mount.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/vfs_mount.c
diff -u src/sys/kern/vfs_mount.c:1.57 src/sys/kern/vfs_mount.c:1.58
--- src/sys/kern/vfs_mount.c:1.57	Mon Apr 17 08:32:55 2017
+++ src/sys/kern/vfs_mount.c	Mon Apr 17 08:34:27 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_mount.c,v 1.57 2017/04/17 08:32:55 hannken Exp $	*/
+/*	$NetBSD: vfs_mount.c,v 1.58 2017/04/17 08:34:27 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1997-2011 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.57 2017/04/17 08:32:55 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.58 2017/04/17 08:34:27 hannken Exp $");
 
 #include 
 #include 
@@ -311,13 +311,17 @@ vfs_rele(struct mount *mp)
  * => The caller must hold a pre-existing reference to the mount.
  * => Will fail if the file system is being unmounted, or is unmounted.
  */
-int
-vfs_busy(struct mount *mp)
+static inline int
+_vfs_busy(struct mount *mp, bool wait)
 {
 
 	KASSERT(mp->mnt_refcnt > 0);
 
-	mutex_enter(>mnt_unmounting);
+	if (wait) {
+		mutex_enter(>mnt_unmounting);
+	} else if (!mutex_tryenter(>mnt_unmounting)) {
+		return EBUSY;
+	}
 	if (__predict_false((mp->mnt_iflag & IMNT_GONE) != 0)) {
 		mutex_exit(>mnt_unmounting);
 		return ENOENT;
@@ -329,6 +333,20 @@ vfs_busy(struct mount *mp)
 	return 0;
 }
 
+int
+vfs_busy(struct mount *mp)
+{
+
+	return _vfs_busy(mp, true);
+}
+
+int
+vfs_trybusy(struct mount *mp)
+{
+
+	return _vfs_busy(mp, false);
+}
+
 /*
  * Unbusy a busy filesystem.
  *
@@ -1524,11 +1542,12 @@ mountlist_iterator_destroy(mount_iterato
  * Return the next mount or NULL for this iterator.
  * Mark it busy on success.
  */
-struct mount *
-mountlist_iterator_next(mount_iterator_t *mi)
+static inline struct mount *
+_mountlist_iterator_next(mount_iterator_t *mi, bool wait)
 {
 	struct mountlist_entry *me, *marker = >mi_entry;
 	struct mount *mp;
+	int error;
 
 	if (marker->me_mount != NULL) {
 		vfs_unbusy(marker->me_mount);
@@ -1559,7 +1578,11 @@ mountlist_iterator_next(mount_iterator_t
 		mutex_exit(_lock);
 
 		/* Try to mark this mount busy and return on success. */
-		if (vfs_busy(mp) == 0) {
+		if (wait)
+			error = vfs_busy(mp);
+		else
+			error = vfs_trybusy(mp);
+		if (error == 0) {
 			vfs_rele(mp);
 			marker->me_mount = mp;
 			return mp;
@@ -1569,6 +1592,20 @@ mountlist_iterator_next(mount_iterator_t
 	}
 }
 
+struct mount *
+mountlist_iterator_next(mount_iterator_t *mi)
+{
+
+	return _mountlist_iterator_next(mi, true);
+}
+
+struct mount *
+mountlist_iterator_trynext(mount_iterator_t *mi)
+{
+
+	return _mountlist_iterator_next(mi, false);
+}
+
 /*
  * Attach new mount to the end of the mount list.
  */

Index: src/sys/kern/vfs_subr.c
diff -u src/sys/kern/vfs_subr.c:1.462 src/sys/kern/vfs_subr.c:1.463
--- src/sys/kern/vfs_subr.c:1.462	Wed Apr 12 10:26:33 2017
+++ src/sys/kern/vfs_subr.c	Mon Apr 17 08:34:27 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_subr.c,v 1.462 2017/04/12 10:26:33 hannken Exp $	*/
+/*	$NetBSD: vfs_subr.c,v 1.463 2017/04/17 08:34:27 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998, 2004, 2005, 2007, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.462 2017/04/12 10:26:33 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.463 2017/04/17 08:34:27 hannken Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -775,7 +775,7 @@ sched_sync(void *arg)
 		 * Sync mounts whose dirty time has expired.
 		 */
 		mountlist_iterator_init();
-		while ((mp = mountlist_iterator_next(iter)) != NULL) {
+		while ((mp = mountlist_iterator_trynext(iter)) != NULL) {
 			if ((mp->mnt_iflag & IMNT_ONWORKLIST) == 0 ||
 			mp->mnt_synclist_slot != syncer_delayno) {
 continue;

Index: src/sys/sys/mount.h
diff -u src/sys/sys/mount.h:1.225 src/sys/sys/mount.h:1.226
--- src/sys/sys/mount.h:1.225	Mon Apr 17 08:32:01 2017
+++ src/sys/sys/mount.h	Mon Apr 17 08:34:27 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: mount.h,v 1.225 2017/04/17 08:32:01 hannken Exp $	*/
+/*	$NetBSD: mount.h,v 1.226 2017/04/17 08:34:27 hannken Exp $	*/
 
 /*
  * Copyright (c) 1989, 1991, 1993
@@ -417,6 +417,7 @@ bool	vfs_unmountall(struct lwp *);	/
 bool	vfs_unmountall1(struct lwp *, bool, bool);
 bool	vfs_unmount_forceone(struct lwp *);
 int 	vfs_busy(struct mount *);
+int 	vfs_trybusy(struct mount *);
 int	vfs_rootmountalloc(const char *, const char *, struct mount **);
 void	

CVS commit: src/share/man/man9

2017-04-17 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Mon Apr 17 08:33:40 UTC 2017

Modified Files:
src/share/man/man9: vfssubr.9

Log Message:
Update vfs_busy(), vfs_unbusy(), vfs_mountalloc() and vfs_rootmountalloc().


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/share/man/man9/vfssubr.9

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

Modified files:

Index: src/share/man/man9/vfssubr.9
diff -u src/share/man/man9/vfssubr.9:1.25 src/share/man/man9/vfssubr.9:1.26
--- src/share/man/man9/vfssubr.9:1.25	Sat May 24 17:14:02 2014
+++ src/share/man/man9/vfssubr.9	Mon Apr 17 08:33:40 2017
@@ -1,4 +1,4 @@
-.\" $NetBSD: vfssubr.9,v 1.25 2014/05/24 17:14:02 wiz Exp $
+.\" $NetBSD: vfssubr.9,v 1.26 2017/04/17 08:33:40 hannken Exp $
 .\"
 .\" Copyright (c) 2003, 2005, 2006 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 May 24, 2014
+.Dd Apr 17, 2017
 .Dt VFSSUBR 9
 .Os
 .Sh NAME
@@ -77,9 +77,9 @@
 .Ft void
 .Fn vfs_unmountall  "struct lwp *l"
 .Ft int
-.Fn vfs_busy "struct mount *mp" "struct mount **nextp"
+.Fn vfs_busy "struct mount *mp"
 .Ft void
-.Fn vfs_unbusy "struct mount *mp" "bool keepref" "struct mount **nextp"
+.Fn vfs_unbusy "struct mount *mp"
 .Ft struct mount *
 .Fn vfs_mountalloc "struct vfsops *vfs" "struct vnode *vp"
 .Ft int
@@ -139,42 +139,17 @@ by the vnode
 Mount the root file system.
 .It Fn vfs_unmountall "l"
 Unmount all file systems.
-.It Fn vfs_busy "mp" "nextp"
+.It Fn vfs_busy "mp"
 Mark the mount point specified by
 .Fa mp
 as busy and get a reference to it.
 This function is used to synchronize access and to delay unmounting.
 The caller must hold a pre-existing reference to the mount.
-If
-.Fa nextp
-is not
-.Dv NULL ,
-the caller must hold the
-.Em mountlist_lock
-and
-.Fa nextp
-will receive the next mount from mount list on error.
-The
-.Em mountlist_lock
-is released on return.
-.It Fn vfs_unbusy "mp" "keepref" "nextp"
+.It Fn vfs_unbusy "mp"
 Undo a
 .Fn vfs_busy
 on the mount point specified by
 .Fa mp .
-If
-.Fa keepref
-is true, preserve the reference added by
-.Fn vfs_busy .
-If
-.Fa nextp
-is not
-.Dv NULL ,
-the
-.Em mountlist_lock
-will be aquired and
-.Fa nextp
-will receive the next mount from mount list.
 .It Fn vfs_mountalloc "vfsops" "vp"
 Allocate and initialise a mount structure, setting
 .Em mnt_vnodecovered
@@ -184,14 +159,15 @@ and
 .Em mnt_op
 to
 .Fa vfsops .
-On success, mark the mount structure as busy and return its address.
+On success return the address of the mount structure.
 Otherwise, return
 .Dv NULL .
 .It Fn vfs_rootmountalloc "fstypename" "devname" "mpp"
 Lookup a file system type specified by the name
 .Fa fstypename
 and if found allocate and initialise a mount structure for it.
-The allocated mount structure is returned in the address specified by
+The allocated mount structure is marked as busy and returned in the
+address specified by
 .Fa mpp .
 The device the root file system was mounted from is specified by the
 argument



CVS commit: src/sys/kern

2017-04-17 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Mon Apr 17 08:32:55 UTC 2017

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

Log Message:
No need to keep a not yet visible mount busy.  Move vfs_busy()
from vfs_mountalloc() to vfs_rootmountalloc().

XXX: Do we really need to vfs_busy() for vfs_mountroot?


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/sys/kern/vfs_mount.c

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

Modified files:

Index: src/sys/kern/vfs_mount.c
diff -u src/sys/kern/vfs_mount.c:1.56 src/sys/kern/vfs_mount.c:1.57
--- src/sys/kern/vfs_mount.c:1.56	Mon Apr 17 08:32:01 2017
+++ src/sys/kern/vfs_mount.c	Mon Apr 17 08:32:55 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_mount.c,v 1.56 2017/04/17 08:32:01 hannken Exp $	*/
+/*	$NetBSD: vfs_mount.c,v 1.57 2017/04/17 08:32:55 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1997-2011 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.56 2017/04/17 08:32:01 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.57 2017/04/17 08:32:55 hannken Exp $");
 
 #include 
 #include 
@@ -148,7 +148,6 @@ struct mount *
 vfs_mountalloc(struct vfsops *vfsops, vnode_t *vp)
 {
 	struct mount *mp;
-	int error __diagused;
 
 	mp = kmem_zalloc(sizeof(*mp), KM_SLEEP);
 	if (mp == NULL)
@@ -160,8 +159,6 @@ vfs_mountalloc(struct vfsops *vfsops, vn
 	mutex_init(>mnt_unmounting, MUTEX_DEFAULT, IPL_NONE);
 	mutex_init(>mnt_renamelock, MUTEX_DEFAULT, IPL_NONE);
 	mutex_init(>mnt_updating, MUTEX_DEFAULT, IPL_NONE);
-	error = vfs_busy(mp);
-	KASSERT(error == 0);
 	mp->mnt_vnodecovered = vp;
 	mount_initspecific(mp);
 
@@ -184,6 +181,7 @@ vfs_rootmountalloc(const char *fstypenam
 {
 	struct vfsops *vfsp = NULL;
 	struct mount *mp;
+	int error __diagused;
 
 	mutex_enter(_list_lock);
 	LIST_FOREACH(vfsp, _list, vfs_list)
@@ -199,6 +197,8 @@ vfs_rootmountalloc(const char *fstypenam
 
 	if ((mp = vfs_mountalloc(vfsp, NULL)) == NULL)
 		return ENOMEM;
+	error = vfs_busy(mp);
+	KASSERT(error == 0);
 	mp->mnt_flag = MNT_RDONLY;
 	(void)strlcpy(mp->mnt_stat.f_fstypename, vfsp->vfs_name,
 	sizeof(mp->mnt_stat.f_fstypename));
@@ -721,7 +721,6 @@ mount_domount(struct lwp *l, vnode_t **v
 	}
 
 	if ((error = fstrans_mount(mp)) != 0) {
-		vfs_unbusy(mp);
 		vfs_rele(mp);
 		return error;
 	}
@@ -789,7 +788,6 @@ mount_domount(struct lwp *l, vnode_t **v
 
 	/* Hold an additional reference to the mount across VFS_START(). */
 	vfs_ref(mp);
-	vfs_unbusy(mp);
 	(void) VFS_STATVFS(mp, >mnt_stat);
 	error = VFS_START(mp, 0);
if (error) {
@@ -810,7 +808,6 @@ err_unmounted:
 	vp->v_mountedhere = NULL;
 	mutex_exit(>mnt_updating);
 	fstrans_unmount(mp);
-	vfs_unbusy(mp);
 	vfs_rele(mp);
 
 	return error;



CVS commit: src/sys

2017-04-17 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Mon Apr 17 08:32:02 UTC 2017

Modified Files:
src/sys/fs/cd9660: cd9660_vfsops.c
src/sys/fs/filecorefs: filecore_vfsops.c
src/sys/fs/msdosfs: msdosfs_vfsops.c
src/sys/fs/ntfs: ntfs_vfsops.c
src/sys/fs/union: union_vnops.c
src/sys/fs/v7fs: v7fs_vfsops.c
src/sys/kern: vfs_lookup.c vfs_mount.c vfs_syscalls.c vfs_trans.c
vfs_vnode.c
src/sys/nfs: nfs_export.c nfs_vfsops.c
src/sys/rump/librump/rumpvfs: rumpfs.c
src/sys/sys: mount.h
src/sys/ufs/ext2fs: ext2fs_vfsops.c
src/sys/ufs/ffs: ffs_vfsops.c
src/sys/ufs/lfs: lfs_bio.c lfs_syscalls.c lfs_vfsops.c ulfs_vfsops.c
src/sys/ufs/mfs: mfs_vfsops.c
src/sys/ufs/ufs: ufs_vfsops.c

Log Message:
Remove unused argument "nextp" from vfs_busy() and vfs_unbusy().
Remove argument "keepref" from vfs_unbusy() and add vfs_ref() where needed.


To generate a diff of this commit:
cvs rdiff -u -r1.92 -r1.93 src/sys/fs/cd9660/cd9660_vfsops.c
cvs rdiff -u -r1.80 -r1.81 src/sys/fs/filecorefs/filecore_vfsops.c
cvs rdiff -u -r1.126 -r1.127 src/sys/fs/msdosfs/msdosfs_vfsops.c
cvs rdiff -u -r1.106 -r1.107 src/sys/fs/ntfs/ntfs_vfsops.c
cvs rdiff -u -r1.65 -r1.66 src/sys/fs/union/union_vnops.c
cvs rdiff -u -r1.14 -r1.15 src/sys/fs/v7fs/v7fs_vfsops.c
cvs rdiff -u -r1.205 -r1.206 src/sys/kern/vfs_lookup.c
cvs rdiff -u -r1.55 -r1.56 src/sys/kern/vfs_mount.c
cvs rdiff -u -r1.511 -r1.512 src/sys/kern/vfs_syscalls.c
cvs rdiff -u -r1.42 -r1.43 src/sys/kern/vfs_trans.c
cvs rdiff -u -r1.86 -r1.87 src/sys/kern/vfs_vnode.c
cvs rdiff -u -r1.59 -r1.60 src/sys/nfs/nfs_export.c
cvs rdiff -u -r1.234 -r1.235 src/sys/nfs/nfs_vfsops.c
cvs rdiff -u -r1.146 -r1.147 src/sys/rump/librump/rumpvfs/rumpfs.c
cvs rdiff -u -r1.224 -r1.225 src/sys/sys/mount.h
cvs rdiff -u -r1.207 -r1.208 src/sys/ufs/ext2fs/ext2fs_vfsops.c
cvs rdiff -u -r1.352 -r1.353 src/sys/ufs/ffs/ffs_vfsops.c
cvs rdiff -u -r1.138 -r1.139 src/sys/ufs/lfs/lfs_bio.c
cvs rdiff -u -r1.173 -r1.174 src/sys/ufs/lfs/lfs_syscalls.c
cvs rdiff -u -r1.358 -r1.359 src/sys/ufs/lfs/lfs_vfsops.c
cvs rdiff -u -r1.12 -r1.13 src/sys/ufs/lfs/ulfs_vfsops.c
cvs rdiff -u -r1.112 -r1.113 src/sys/ufs/mfs/mfs_vfsops.c
cvs rdiff -u -r1.54 -r1.55 src/sys/ufs/ufs/ufs_vfsops.c

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

Modified files:

Index: src/sys/fs/cd9660/cd9660_vfsops.c
diff -u src/sys/fs/cd9660/cd9660_vfsops.c:1.92 src/sys/fs/cd9660/cd9660_vfsops.c:1.93
--- src/sys/fs/cd9660/cd9660_vfsops.c:1.92	Mon Apr 17 08:31:01 2017
+++ src/sys/fs/cd9660/cd9660_vfsops.c	Mon Apr 17 08:32:00 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: cd9660_vfsops.c,v 1.92 2017/04/17 08:31:01 hannken Exp $	*/
+/*	$NetBSD: cd9660_vfsops.c,v 1.93 2017/04/17 08:32:00 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1994
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cd9660_vfsops.c,v 1.92 2017/04/17 08:31:01 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cd9660_vfsops.c,v 1.93 2017/04/17 08:32:00 hannken Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_compat_netbsd.h"
@@ -191,13 +191,13 @@ cd9660_mountroot(void)
 
 	args.flags = ISOFSMNT_ROOT;
 	if ((error = iso_mountfs(rootvp, mp, l, )) != 0) {
-		vfs_unbusy(mp, false, NULL);
+		vfs_unbusy(mp);
 		vfs_rele(mp);
 		return (error);
 	}
 	mountlist_append(mp);
 	(void)cd9660_statvfs(mp, >mnt_stat);
-	vfs_unbusy(mp, false, NULL);
+	vfs_unbusy(mp);
 	return (0);
 }
 

Index: src/sys/fs/filecorefs/filecore_vfsops.c
diff -u src/sys/fs/filecorefs/filecore_vfsops.c:1.80 src/sys/fs/filecorefs/filecore_vfsops.c:1.81
--- src/sys/fs/filecorefs/filecore_vfsops.c:1.80	Mon Apr 17 08:31:01 2017
+++ src/sys/fs/filecorefs/filecore_vfsops.c	Mon Apr 17 08:32:00 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: filecore_vfsops.c,v 1.80 2017/04/17 08:31:01 hannken Exp $	*/
+/*	$NetBSD: filecore_vfsops.c,v 1.81 2017/04/17 08:32:00 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1994 The Regents of the University of California.
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: filecore_vfsops.c,v 1.80 2017/04/17 08:31:01 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: filecore_vfsops.c,v 1.81 2017/04/17 08:32:00 hannken Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_compat_netbsd.h"
@@ -201,13 +201,13 @@ filecore_mountroot(void)
 
 	args.flags = FILECOREMNT_ROOT;
 	if ((error = filecore_mountfs(rootvp, mp, p, )) != 0) {
-		vfs_unbusy(mp, false, NULL);
+		vfs_unbusy(mp);
 		vfs_rele(mp);
 		return (error);
 	}
 	mountlist_append(mp);
 	(void)filecore_statvfs(mp, >mnt_stat, p);
-	vfs_unbusy(mp, false, NULL);
+	vfs_unbusy(mp);
 	return (0);
 }
 #endif

Index: src/sys/fs/msdosfs/msdosfs_vfsops.c
diff -u src/sys/fs/msdosfs/msdosfs_vfsops.c:1.126 src/sys/fs/msdosfs/msdosfs_vfsops.c:1.127
--- src/sys/fs/msdosfs/msdosfs_vfsops.c:1.126	Mon Apr 17 08:31:01 2017
+++ src/sys/fs/msdosfs/msdosfs_vfsops.c	Mon Apr 17 08:32:00 2017
@@ -1,4 

CVS commit: src/sys

2017-04-17 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Mon Apr 17 08:31:02 UTC 2017

Modified Files:
src/sys/fs/cd9660: cd9660_vfsops.c
src/sys/fs/filecorefs: filecore_vfsops.c
src/sys/fs/msdosfs: msdosfs_vfsops.c
src/sys/fs/ntfs: ntfs_vfsops.c
src/sys/fs/puffs: puffs_msgif.c
src/sys/fs/v7fs: v7fs_vfsops.c
src/sys/kern: vfs_mount.c vfs_syscalls.c vfs_trans.c vfs_vnode.c
src/sys/nfs: nfs_vfsops.c
src/sys/sys: mount.h
src/sys/ufs/ext2fs: ext2fs_vfsops.c
src/sys/ufs/ffs: ffs_vfsops.c
src/sys/ufs/lfs: lfs_vfsops.c
src/sys/ufs/mfs: mfs_vfsops.c

Log Message:
Add vfs_ref(mp) and vfs_rele(mp) to add or remove a reference to
struct mount.  Rename vfs_destroy(mp) to vfs_rele(mp) and replace
incrementing mp->mnt_refcnt with vfs_ref(mp).


To generate a diff of this commit:
cvs rdiff -u -r1.91 -r1.92 src/sys/fs/cd9660/cd9660_vfsops.c
cvs rdiff -u -r1.79 -r1.80 src/sys/fs/filecorefs/filecore_vfsops.c
cvs rdiff -u -r1.125 -r1.126 src/sys/fs/msdosfs/msdosfs_vfsops.c
cvs rdiff -u -r1.105 -r1.106 src/sys/fs/ntfs/ntfs_vfsops.c
cvs rdiff -u -r1.100 -r1.101 src/sys/fs/puffs/puffs_msgif.c
cvs rdiff -u -r1.13 -r1.14 src/sys/fs/v7fs/v7fs_vfsops.c
cvs rdiff -u -r1.54 -r1.55 src/sys/kern/vfs_mount.c
cvs rdiff -u -r1.510 -r1.511 src/sys/kern/vfs_syscalls.c
cvs rdiff -u -r1.41 -r1.42 src/sys/kern/vfs_trans.c
cvs rdiff -u -r1.85 -r1.86 src/sys/kern/vfs_vnode.c
cvs rdiff -u -r1.233 -r1.234 src/sys/nfs/nfs_vfsops.c
cvs rdiff -u -r1.223 -r1.224 src/sys/sys/mount.h
cvs rdiff -u -r1.206 -r1.207 src/sys/ufs/ext2fs/ext2fs_vfsops.c
cvs rdiff -u -r1.351 -r1.352 src/sys/ufs/ffs/ffs_vfsops.c
cvs rdiff -u -r1.357 -r1.358 src/sys/ufs/lfs/lfs_vfsops.c
cvs rdiff -u -r1.111 -r1.112 src/sys/ufs/mfs/mfs_vfsops.c

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

Modified files:

Index: src/sys/fs/cd9660/cd9660_vfsops.c
diff -u src/sys/fs/cd9660/cd9660_vfsops.c:1.91 src/sys/fs/cd9660/cd9660_vfsops.c:1.92
--- src/sys/fs/cd9660/cd9660_vfsops.c:1.91	Fri Feb 17 08:31:24 2017
+++ src/sys/fs/cd9660/cd9660_vfsops.c	Mon Apr 17 08:31:01 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: cd9660_vfsops.c,v 1.91 2017/02/17 08:31:24 hannken Exp $	*/
+/*	$NetBSD: cd9660_vfsops.c,v 1.92 2017/04/17 08:31:01 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1994
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cd9660_vfsops.c,v 1.91 2017/02/17 08:31:24 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cd9660_vfsops.c,v 1.92 2017/04/17 08:31:01 hannken Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_compat_netbsd.h"
@@ -192,7 +192,7 @@ cd9660_mountroot(void)
 	args.flags = ISOFSMNT_ROOT;
 	if ((error = iso_mountfs(rootvp, mp, l, )) != 0) {
 		vfs_unbusy(mp, false, NULL);
-		vfs_destroy(mp);
+		vfs_rele(mp);
 		return (error);
 	}
 	mountlist_append(mp);

Index: src/sys/fs/filecorefs/filecore_vfsops.c
diff -u src/sys/fs/filecorefs/filecore_vfsops.c:1.79 src/sys/fs/filecorefs/filecore_vfsops.c:1.80
--- src/sys/fs/filecorefs/filecore_vfsops.c:1.79	Fri Feb 17 08:31:24 2017
+++ src/sys/fs/filecorefs/filecore_vfsops.c	Mon Apr 17 08:31:01 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: filecore_vfsops.c,v 1.79 2017/02/17 08:31:24 hannken Exp $	*/
+/*	$NetBSD: filecore_vfsops.c,v 1.80 2017/04/17 08:31:01 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1994 The Regents of the University of California.
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: filecore_vfsops.c,v 1.79 2017/02/17 08:31:24 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: filecore_vfsops.c,v 1.80 2017/04/17 08:31:01 hannken Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_compat_netbsd.h"
@@ -202,7 +202,7 @@ filecore_mountroot(void)
 	args.flags = FILECOREMNT_ROOT;
 	if ((error = filecore_mountfs(rootvp, mp, p, )) != 0) {
 		vfs_unbusy(mp, false, NULL);
-		vfs_destroy(mp);
+		vfs_rele(mp);
 		return (error);
 	}
 	mountlist_append(mp);

Index: src/sys/fs/msdosfs/msdosfs_vfsops.c
diff -u src/sys/fs/msdosfs/msdosfs_vfsops.c:1.125 src/sys/fs/msdosfs/msdosfs_vfsops.c:1.126
--- src/sys/fs/msdosfs/msdosfs_vfsops.c:1.125	Sat Apr  1 19:35:56 2017
+++ src/sys/fs/msdosfs/msdosfs_vfsops.c	Mon Apr 17 08:31:01 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: msdosfs_vfsops.c,v 1.125 2017/04/01 19:35:56 riastradh Exp $	*/
+/*	$NetBSD: msdosfs_vfsops.c,v 1.126 2017/04/17 08:31:01 hannken Exp $	*/
 
 /*-
  * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
@@ -48,7 +48,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: msdosfs_vfsops.c,v 1.125 2017/04/01 19:35:56 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: msdosfs_vfsops.c,v 1.126 2017/04/17 08:31:01 hannken Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_compat_netbsd.h"
@@ -248,14 +248,14 @@ msdosfs_mountroot(void)
 
 	if ((error = msdosfs_mountfs(rootvp, mp, l, )) != 0) {
 		vfs_unbusy(mp, false, NULL);
-		vfs_destroy(mp);
+		vfs_rele(mp);
 		return (error);
 	}
 
 	if ((error = update_mp(mp, )) != 0) {
 		

CVS commit: src

2017-04-17 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Mon Apr 17 08:29:58 UTC 2017

Modified Files:
src/sys/kern: vfs_mount.c
src/sys/sys: mount.h
src/usr.sbin/pstat: pstat.c

Log Message:
Cleanup after mountlist iterator:
- remove now unused field mnt_list.
- rename mount_list to mountlist and make it local to vfs_mount.c.
- make mountlist_lock local to vfs_mount.c.

Change pstat.c to retrieve vnodes by lru lists.


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 src/sys/kern/vfs_mount.c
cvs rdiff -u -r1.222 -r1.223 src/sys/sys/mount.h
cvs rdiff -u -r1.126 -r1.127 src/usr.sbin/pstat/pstat.c

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

Modified files:

Index: src/sys/kern/vfs_mount.c
diff -u src/sys/kern/vfs_mount.c:1.53 src/sys/kern/vfs_mount.c:1.54
--- src/sys/kern/vfs_mount.c:1.53	Wed Apr 12 10:35:10 2017
+++ src/sys/kern/vfs_mount.c	Mon Apr 17 08:29:58 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_mount.c,v 1.53 2017/04/12 10:35:10 hannken Exp $	*/
+/*	$NetBSD: vfs_mount.c,v 1.54 2017/04/17 08:29:58 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1997-2011 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.53 2017/04/12 10:35:10 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.54 2017/04/17 08:29:58 hannken Exp $");
 
 #include 
 #include 
@@ -108,8 +108,6 @@ struct mount_iterator {
 	struct mountlist_entry mi_entry;
 };
 
-static TAILQ_HEAD(mountlist, mountlist_entry) mount_list;
-
 static struct vnode *vfs_vnode_iterator_next1(struct vnode_iterator *,
 bool (*)(void *, struct vnode *), void *, bool);
 
@@ -117,10 +115,10 @@ static struct vnode *vfs_vnode_iterator_
 vnode_t *			rootvnode;
 
 /* Mounted filesystem list. */
-struct mntlist			mountlist;
-kmutex_t			mountlist_lock;
-int vnode_offset_next_by_mount	/* XXX: ugly hack for pstat.c */
-= offsetof(vnode_impl_t, vi_mntvnodes.tqe_next);
+static TAILQ_HEAD(mountlist, mountlist_entry) mountlist;
+static kmutex_t			mountlist_lock;
+int vnode_offset_next_by_lru	/* XXX: ugly hack for pstat.c */
+= offsetof(vnode_impl_t, vi_lrulist.tqe_next);
 
 kmutex_t			mntvnode_lock;
 kmutex_t			vfs_list_lock;
@@ -135,7 +133,6 @@ void
 vfs_mount_sysinit(void)
 {
 
-	TAILQ_INIT(_list);
 	TAILQ_INIT();
 	mutex_init(_lock, MUTEX_DEFAULT, IPL_NONE);
 	mutex_init(_lock, MUTEX_DEFAULT, IPL_NONE);
@@ -308,21 +305,16 @@ vfs_busy(struct mount *mp, struct mount 
 
 	KASSERT(mp->mnt_refcnt > 0);
 
+	KASSERT(nextp == NULL);
+
 	mutex_enter(>mnt_unmounting);
 	if (__predict_false((mp->mnt_iflag & IMNT_GONE) != 0)) {
 		mutex_exit(>mnt_unmounting);
-		if (nextp != NULL) {
-			KASSERT(mutex_owned(_lock));
-			*nextp = TAILQ_NEXT(mp, mnt_list);
-		}
 		return ENOENT;
 	}
 	++mp->mnt_busynest;
 	KASSERT(mp->mnt_busynest != 0);
 	mutex_exit(>mnt_unmounting);
-	if (nextp != NULL) {
-		mutex_exit(_lock);
-	}
 	atomic_inc_uint(>mnt_refcnt);
 	return 0;
 }
@@ -341,9 +333,8 @@ vfs_unbusy(struct mount *mp, bool keepre
 
 	KASSERT(mp->mnt_refcnt > 0);
 
-	if (nextp != NULL) {
-		mutex_enter(_lock);
-	}
+	KASSERT(nextp == NULL);
+
 	mutex_enter(>mnt_unmounting);
 	KASSERT(mp->mnt_busynest != 0);
 	mp->mnt_busynest--;
@@ -351,10 +342,6 @@ vfs_unbusy(struct mount *mp, bool keepre
 	if (!keepref) {
 		vfs_destroy(mp);
 	}
-	if (nextp != NULL) {
-		KASSERT(mutex_owned(_lock));
-		*nextp = TAILQ_NEXT(mp, mnt_list);
-	}
 }
 
 struct vnode_iterator {
@@ -1508,7 +1495,7 @@ mountlist_iterator_init(mount_iterator_t
 
 	me = mountlist_alloc(ME_MARKER, NULL);
 	mutex_enter(_lock);
-	TAILQ_INSERT_HEAD(_list, me, me_list);
+	TAILQ_INSERT_HEAD(, me, me_list);
 	mutex_exit(_lock);
 	*mip = (mount_iterator_t *)me;
 }
@@ -1522,7 +1509,7 @@ mountlist_iterator_destroy(mount_iterato
 		vfs_unbusy(marker->me_mount, false, NULL);
 
 	mutex_enter(_lock);
-	TAILQ_REMOVE(_list, marker, me_list);
+	TAILQ_REMOVE(, marker, me_list);
 	mutex_exit(_lock);
 
 	mountlist_free(marker);
@@ -1554,8 +1541,8 @@ mountlist_iterator_next(mount_iterator_t
 			mutex_exit(_lock);
 			return NULL;
 		}
-		TAILQ_REMOVE(_list, marker, me_list);
-		TAILQ_INSERT_AFTER(_list, me, marker, me_list);
+		TAILQ_REMOVE(, marker, me_list);
+		TAILQ_INSERT_AFTER(, me, marker, me_list);
 
 		/* Skip other markers. */
 		if (me->me_type != ME_MOUNT)
@@ -1588,8 +1575,7 @@ mountlist_append(struct mount *mp)
 
 	me = mountlist_alloc(ME_MOUNT, mp);
 	mutex_enter(_lock);
-	TAILQ_INSERT_TAIL(_list, me, me_list);
-	TAILQ_INSERT_TAIL(, mp, mnt_list);
+	TAILQ_INSERT_TAIL(, me, me_list);
 	mutex_exit(_lock);
 }
 
@@ -1601,12 +1587,11 @@ mountlist_remove(struct mount *mp)
 	struct mountlist_entry *me;
 
 	mutex_enter(_lock);
-	TAILQ_FOREACH(me, _list, me_list)
+	TAILQ_FOREACH(me, , me_list)
 		if (me->me_type == ME_MOUNT && me->me_mount == mp)
 			break;
 	KASSERT(me != NULL);
-	TAILQ_REMOVE(_list, me, me_list);
-	TAILQ_REMOVE(, mp, mnt_list);
+	TAILQ_REMOVE(, me, me_list);
 	

CVS commit: src/sys/ufs/lfs

2017-04-13 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Thu Apr 13 09:57:28 UTC 2017

Modified Files:
src/sys/ufs/lfs: lfs_bio.c lfs_vfsops.c

Log Message:
Switch lfs_flush() and lfs_writerd() to mountlist iterator.


To generate a diff of this commit:
cvs rdiff -u -r1.137 -r1.138 src/sys/ufs/lfs/lfs_bio.c
cvs rdiff -u -r1.356 -r1.357 src/sys/ufs/lfs/lfs_vfsops.c

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

Modified files:

Index: src/sys/ufs/lfs/lfs_bio.c
diff -u src/sys/ufs/lfs/lfs_bio.c:1.137 src/sys/ufs/lfs/lfs_bio.c:1.138
--- src/sys/ufs/lfs/lfs_bio.c:1.137	Sat Apr  1 17:34:21 2017
+++ src/sys/ufs/lfs/lfs_bio.c	Thu Apr 13 09:57:28 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_bio.c,v 1.137 2017/04/01 17:34:21 maya Exp $	*/
+/*	$NetBSD: lfs_bio.c,v 1.138 2017/04/13 09:57:28 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2008 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_bio.c,v 1.137 2017/04/01 17:34:21 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_bio.c,v 1.138 2017/04/13 09:57:28 hannken Exp $");
 
 #include 
 #include 
@@ -514,7 +514,8 @@ void
 lfs_flush(struct lfs *fs, int flags, int only_onefs)
 {
 	extern u_int64_t locked_fakequeue_count;
-	struct mount *mp, *nmp;
+	mount_iterator_t *iter;
+	struct mount *mp;
 	struct lfs *tfs;
 
 	KASSERT(mutex_owned(_lock));
@@ -543,12 +544,8 @@ lfs_flush(struct lfs *fs, int flags, int
 		vfs_unbusy(fs->lfs_ivnode->v_mount, false, NULL);
 	} else {
 		locked_fakequeue_count = 0;
-		mutex_enter(_lock);
-		for (mp = TAILQ_FIRST(); mp != NULL; mp = nmp) {
-			if (vfs_busy(mp, )) {
-DLOG((DLOG_FLUSH, "lfs_flush: fs vfs_busy\n"));
-continue;
-			}
+		mountlist_iterator_init();
+		while ((mp = mountlist_iterator_next(iter)) != NULL) {
 			if (strncmp(>mnt_stat.f_fstypename[0], MOUNT_LFS,
 			sizeof(mp->mnt_stat.f_fstypename)) == 0) {
 tfs = VFSTOULFS(mp)->um_lfs;
@@ -556,9 +553,8 @@ lfs_flush(struct lfs *fs, int flags, int
 lfs_flush_fs(tfs, flags);
 mutex_exit(_lock);
 			}
-			vfs_unbusy(mp, false, );
 		}
-		mutex_exit(_lock);
+		mountlist_iterator_destroy(iter);
 	}
 	LFS_DEBUG_COUNTLOCKED("flush");
 	wakeup(_subsys_pages);

Index: src/sys/ufs/lfs/lfs_vfsops.c
diff -u src/sys/ufs/lfs/lfs_vfsops.c:1.356 src/sys/ufs/lfs/lfs_vfsops.c:1.357
--- src/sys/ufs/lfs/lfs_vfsops.c:1.356	Sat Apr  1 17:34:21 2017
+++ src/sys/ufs/lfs/lfs_vfsops.c	Thu Apr 13 09:57:28 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_vfsops.c,v 1.356 2017/04/01 17:34:21 maya Exp $	*/
+/*	$NetBSD: lfs_vfsops.c,v 1.357 2017/04/13 09:57:28 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007, 2007
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_vfsops.c,v 1.356 2017/04/01 17:34:21 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_vfsops.c,v 1.357 2017/04/13 09:57:28 hannken Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_lfs.h"
@@ -387,11 +387,11 @@ struct pool lfs_lbnentry_pool;
 static void
 lfs_writerd(void *arg)
 {
- 	struct mount *mp, *nmp;
+	mount_iterator_t *iter;
+ 	struct mount *mp;
  	struct lfs *fs;
 	struct vfsops *vfs = NULL;
  	int fsflags;
-	int skipc;
 	int lfsc;
 	int wrote_something = 0;
  
@@ -446,14 +446,9 @@ lfs_writerd(void *arg)
  		 * Look through the list of LFSs to see if any of them
  		 * have requested pageouts.
  		 */
- 		mutex_enter(_lock);
+ 		mountlist_iterator_init();
 		lfsc = 0;
-		skipc = 0;
- 		for (mp = TAILQ_FIRST(); mp != NULL; mp = nmp) {
- 			if (vfs_busy(mp, )) {
-++skipc;
- continue;
- 			}
+		while ((mp = mountlist_iterator_next(iter)) != NULL) {
 			KASSERT(!mutex_owned(_lock));
  			if (strncmp(mp->mnt_stat.f_fstypename, MOUNT_LFS,
  			sizeof(mp->mnt_stat.f_fstypename)) == 0) {
@@ -468,7 +463,6 @@ lfs_writerd(void *arg)
 if (lfs_sb_getnextseg(fs) < lfs_sb_getcurseg(fs) && fs->lfs_nowrap) {
 	/* Don't try to write if we're suspended */
 	mutex_exit(_lock);
-	vfs_unbusy(mp, false, );
 	continue;
 }
 if (LFS_STARVED_FOR_SEGS(fs)) {
@@ -476,7 +470,6 @@ lfs_writerd(void *arg)
 
 	DLOG((DLOG_FLUSH, "lfs_writerd: need cleaning before writing possible\n"));
 	lfs_wakeup_cleaner(fs);
-	vfs_unbusy(mp, false, );
 	continue;
 }
 
@@ -503,21 +496,19 @@ lfs_writerd(void *arg)
 mutex_exit(_lock);
  			}
 			KASSERT(!mutex_owned(_lock));
- 			vfs_unbusy(mp, false, );
  		}
-		if (lfsc + skipc == 0) {
+		if (lfsc == 0) {
 			mutex_enter(_lock);
 			lfs_writer_daemon = NULL;
 			mutex_exit(_lock);
-			mutex_exit(_lock);
+			mountlist_iterator_destroy(iter);
 			break;
 		}
- 		mutex_exit(_lock);
+ 		mountlist_iterator_destroy(iter);
  
  		mutex_enter(_lock);
  	}
 	KASSERT(!mutex_owned(_lock));
-	KASSERT(!mutex_owned(_lock));
 
 	/* Give up our extra reference so the module can be unloaded. */
 	mutex_enter(_list_lock);



<    1   2   3   4   5   6   7   >