CVS commit: src/sys/net

2021-07-17 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sat Jul 17 15:37:04 UTC 2021

Modified Files:
src/sys/net: if_vlan.c

Log Message:
Mark vlan_safe_ifpromisc_locked() as "__unused" to appease LLVM.

Maybe completely remove this short helper?


To generate a diff of this commit:
cvs rdiff -u -r1.160 -r1.161 src/sys/net/if_vlan.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/net/if_vlan.c
diff -u src/sys/net/if_vlan.c:1.160 src/sys/net/if_vlan.c:1.161
--- src/sys/net/if_vlan.c:1.160	Thu Jul 15 04:05:47 2021
+++ src/sys/net/if_vlan.c	Sat Jul 17 15:37:04 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vlan.c,v 1.160 2021/07/15 04:05:47 yamaguchi Exp $	*/
+/*	$NetBSD: if_vlan.c,v 1.161 2021/07/17 15:37:04 hannken Exp $	*/
 
 /*
  * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
@@ -78,7 +78,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.160 2021/07/15 04:05:47 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.161 2021/07/17 15:37:04 hannken Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -246,7 +246,7 @@ vlan_safe_ifpromisc(struct ifnet *ifp, i
 	return e;
 }
 
-static inline int
+__unused static inline int
 vlan_safe_ifpromisc_locked(struct ifnet *ifp, int pswitch)
 {
 	int e;



CVS commit: src/sys/fs/union

2021-07-04 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sun Jul  4 11:24:09 UTC 2021

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

Log Message:
Fix union_parsepath(), either the upper or the lower dvp may be NULL.


To generate a diff of this commit:
cvs rdiff -u -r1.77 -r1.78 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.77 src/sys/fs/union/union_vnops.c:1.78
--- src/sys/fs/union/union_vnops.c:1.77	Tue Jun 29 22:39:20 2021
+++ src/sys/fs/union/union_vnops.c	Sun Jul  4 11:24:09 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: union_vnops.c,v 1.77 2021/06/29 22:39:20 dholland Exp $	*/
+/*	$NetBSD: union_vnops.c,v 1.78 2021/07/04 11:24:09 hannken Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993, 1994, 1995
@@ -72,7 +72,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: union_vnops.c,v 1.77 2021/06/29 22:39:20 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: union_vnops.c,v 1.78 2021/07/04 11:24:09 hannken Exp $");
 
 #include 
 #include 
@@ -213,14 +213,26 @@ union_parsepath(void *v)
 	upperdvp = UPPERVP(ap->a_dvp);
 	lowerdvp = LOWERVP(ap->a_dvp);
 
-	error = VOP_PARSEPATH(upperdvp, ap->a_name, );
-	if (error) {
-		return error;
+	if (upperdvp != NULLVP) {
+		error = VOP_PARSEPATH(upperdvp, ap->a_name, );
+		if (error) {
+			return error;
+		}
+	} else {
+		upper = 0;
 	}
 
-	error = VOP_PARSEPATH(lowerdvp, ap->a_name, );
-	if (error) {
-		return error;
+	if (lowerdvp != NULLVP) {
+		error = VOP_PARSEPATH(lowerdvp, ap->a_name, );
+		if (error) {
+			return error;
+		}
+	} else {
+		lower = 0;
+	}
+
+	if (upper == 0 && lower == 0) {
+		panic("%s: missing both layers", __func__);
 	}
 
 	/*



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

2021-07-04 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sun Jul  4 11:25:07 UTC 2021

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

Log Message:
Add VOP_PARSEPATH to zfs control dir vnode op table.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.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_ctldir.c
diff -u src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c:1.12 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c:1.13
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c:1.12	Sat May 16 18:31:46 2020
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c	Sun Jul  4 11:25:07 2021
@@ -1825,6 +1825,7 @@ sfs_print(void *v)
 
 const struct vnodeopv_entry_desc zfs_sfsop_entries[] = {
 	{ _default_desc,		vn_default_error },
+	{ _parsepath_desc,		genfs_parsepath },
 	{ _lookup_desc,		sfs_lookup },
 	{ _open_desc,		sfs_open },
 	{ _close_desc,		sfs_close },



CVS commit: src/lib/libc/sys

2021-06-08 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Tue Jun  8 10:02:04 UTC 2021

Modified Files:
src/lib/libc/sys: nfssvc.2

Log Message:
Document NFSSVC_REPLACEEXPORTSLIST instead of NFSSVC_SETEXPORTSLIST.

The latter is deprecated and kept only for backwards compatibility.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/lib/libc/sys/nfssvc.2

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

Modified files:

Index: src/lib/libc/sys/nfssvc.2
diff -u src/lib/libc/sys/nfssvc.2:1.24 src/lib/libc/sys/nfssvc.2:1.25
--- src/lib/libc/sys/nfssvc.2:1.24	Tue Mar 10 21:00:47 2009
+++ src/lib/libc/sys/nfssvc.2	Tue Jun  8 10:02:04 2021
@@ -1,4 +1,4 @@
-.\"	$NetBSD: nfssvc.2,v 1.24 2009/03/10 21:00:47 joerg Exp $
+.\"	$NetBSD: nfssvc.2,v 1.25 2021/06/08 10:02:04 hannken Exp $
 .\"
 .\" Copyright (c) 1989, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"	@(#)nfssvc.2	8.1 (Berkeley) 6/9/93
 .\"
-.Dd December 30, 2006
+.Dd June 8, 2021
 .Dt NFSSVC 2
 .Os
 .Sh NAME
@@ -138,10 +138,10 @@ The
 server daemon calls
 .Fn nfssvc
 with the flag
-.Dv NFSSVC_SETEXPORTSLIST
+.Dv NFSSVC_REPLACEEXPORTSLIST
 and a pointer to a
 .Ft struct mountd_exports_list
-object to atomically change the exports lists of a specific file system.
+object to atomically replace the exports lists of a specific file system.
 This structure has the following fields:
 .Bl -tag -width ".Vt const char *mel_path"
 .It Vt const char *mel_path



CVS commit: src/sbin/dump

2021-06-07 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Mon Jun  7 14:07:32 UTC 2021

Modified Files:
src/sbin/dump: tape.c

Log Message:
Bitmaps (TS_BITS and TS_CLRI) dont use the "c_addr" array as they
cannot have holes.  As bitmaps are written without TS_ADDR records
"c_count" may be larger than the "c_addr" size resulting in a
segmentation violation reading "c_addr" beyond its end.

Compute "blks" for TS_INODE and TS_ADDR only -- its used for multi
volume dumps and the bitmaps must both be on the first volume.


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/sbin/dump/tape.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/dump/tape.c
diff -u src/sbin/dump/tape.c:1.55 src/sbin/dump/tape.c:1.56
--- src/sbin/dump/tape.c:1.55	Fri Mar  1 16:42:11 2019
+++ src/sbin/dump/tape.c	Mon Jun  7 14:07:32 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tape.c,v 1.55 2019/03/01 16:42:11 christos Exp $	*/
+/*	$NetBSD: tape.c,v 1.56 2021/06/07 14:07:32 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1980, 1991, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)tape.c	8.4 (Berkeley) 5/1/95";
 #else
-__RCSID("$NetBSD: tape.c,v 1.55 2019/03/01 16:42:11 christos Exp $");
+__RCSID("$NetBSD: tape.c,v 1.56 2021/06/07 14:07:32 hannken Exp $");
 #endif
 #endif /* not lint */
 
@@ -328,7 +328,8 @@ flushtape(void)
 	}
 
 	blks = 0;
-	if (iswap32(spcl.c_type) != TS_END) {
+	if (iswap32(spcl.c_type) == TS_INODE ||
+	iswap32(spcl.c_type) == TS_ADDR) {
 		for (i = 0; i < iswap32(spcl.c_count); i++)
 			if (spcl.c_addr[i] != 0)
 blks++;



CVS commit: src/usr.sbin/mountd

2021-06-05 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sat Jun  5 08:26:34 UTC 2021

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

Log Message:
Fix typo, its the element not the array ...


To generate a diff of this commit:
cvs rdiff -u -r1.136 -r1.137 src/usr.sbin/mountd/mountd.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/mountd/mountd.c
diff -u src/usr.sbin/mountd/mountd.c:1.136 src/usr.sbin/mountd/mountd.c:1.137
--- src/usr.sbin/mountd/mountd.c:1.136	Fri Jun  4 10:46:57 2021
+++ src/usr.sbin/mountd/mountd.c	Sat Jun  5 08:26:34 2021
@@ -1,4 +1,4 @@
-/* 	$NetBSD: mountd.c,v 1.136 2021/06/04 10:46:57 hannken Exp $	 */
+/* 	$NetBSD: mountd.c,v 1.137 2021/06/05 08:26:34 hannken Exp $	 */
 
 /*
  * Copyright (c) 1989, 1993
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 19
 #if 0
 static char sccsid[] = "@(#)mountd.c  8.15 (Berkeley) 5/1/95";
 #else
-__RCSID("$NetBSD: mountd.c,v 1.136 2021/06/04 10:46:57 hannken Exp $");
+__RCSID("$NetBSD: mountd.c,v 1.137 2021/06/05 08:26:34 hannken Exp $");
 #endif
 #endif/* not lint */
 
@@ -1294,7 +1294,7 @@ get_exportlist(int n)
 		(mel->mel_nexports > 0 || errno != EOPNOTSUPP))
 			syslog(LOG_ERR, "Can't update exports for %s (%m)",
 			mel_tab[i].mel_path);
-		for (j = 0; j < (int)mel_tab->mel_nexports; j++) {
+		for (j = 0; j < (int)mel->mel_nexports; j++) {
 			struct export_args *export = >mel_exports[j];
 
 			if (export->ex_indexfile)



CVS commit: src/tests/fs/nfs

2021-06-04 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Fri Jun  4 10:48:07 UTC 2021

Modified Files:
src/tests/fs/nfs: t_mountd.c

Log Message:
Test "mountdhup" has to pass now.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/fs/nfs/t_mountd.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/nfs/t_mountd.c
diff -u src/tests/fs/nfs/t_mountd.c:1.7 src/tests/fs/nfs/t_mountd.c:1.8
--- src/tests/fs/nfs/t_mountd.c:1.7	Tue Jul 16 17:29:17 2019
+++ src/tests/fs/nfs/t_mountd.c	Fri Jun  4 10:48:07 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_mountd.c,v 1.7 2019/07/16 17:29:17 martin Exp $	*/
+/*	$NetBSD: t_mountd.c,v 1.8 2021/06/04 10:48:07 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -105,11 +105,8 @@ ATF_TC_BODY(mountdhup, tc)
 
 	FSTEST_DESTRUCTOR(tc, nfs, voidargs);
 
-	atf_tc_expect_fail("PR kern/5844");
 	if (fail)
 		atf_tc_fail("op failed with EACCES");
-	else
-		atf_tc_fail("race did not trigger this time");
 }
 
 ATF_TP_ADD_TCS(tp)



CVS commit: src/usr.sbin/mountd

2021-06-04 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Fri Jun  4 10:46:57 UTC 2021

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

Log Message:
Change get_exportlist() to collect all exports and emit all
exports for a single mount in one call to nfssvc(2).

Should finally fix PR kern/5844 (NFS server sends "permission denied"
while mound re-read exports).


To generate a diff of this commit:
cvs rdiff -u -r1.135 -r1.136 src/usr.sbin/mountd/mountd.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/mountd/mountd.c
diff -u src/usr.sbin/mountd/mountd.c:1.135 src/usr.sbin/mountd/mountd.c:1.136
--- src/usr.sbin/mountd/mountd.c:1.135	Fri Jun  4 10:46:01 2021
+++ src/usr.sbin/mountd/mountd.c	Fri Jun  4 10:46:57 2021
@@ -1,4 +1,4 @@
-/* 	$NetBSD: mountd.c,v 1.135 2021/06/04 10:46:01 hannken Exp $	 */
+/* 	$NetBSD: mountd.c,v 1.136 2021/06/04 10:46:57 hannken Exp $	 */
 
 /*
  * Copyright (c) 1989, 1993
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 19
 #if 0
 static char sccsid[] = "@(#)mountd.c  8.15 (Berkeley) 5/1/95";
 #else
-__RCSID("$NetBSD: mountd.c,v 1.135 2021/06/04 10:46:01 hannken Exp $");
+__RCSID("$NetBSD: mountd.c,v 1.136 2021/06/04 10:46:57 hannken Exp $");
 #endif
 #endif/* not lint */
 
@@ -235,6 +235,8 @@ static struct uucred def_anon = {
 	0,
 	{ 0 }
 };
+static struct mountd_exports_list *mel_tab;
+static int mel_tab_len;
 
 int  opt_flags;
 static int	have_v6 = 1;
@@ -1207,6 +1209,18 @@ nextline:
 }
 
 /*
+ * Compare two export lists by path.
+ */
+static int
+mel_compare(const void *a, const void *b)
+{
+	const struct mountd_exports_list *mela = a;
+	const struct mountd_exports_list *melb = b;
+
+	return strcmp(mela->mel_path, melb->mel_path);
+}
+
+/*
  * Get the export list
  */
 /* ARGSUSED */
@@ -1216,7 +1230,7 @@ get_exportlist(int n)
 	struct exportlist *ep, *ep2;
 	struct grouplist *grp, *tgrp;
 	struct statvfs *fsp;
-	int num, i;
+	int i, j;
 	FILE *exp_file;
 
 
@@ -1243,20 +1257,14 @@ get_exportlist(int n)
 	 * And delete exports that are in the kernel for all local
 	 * file systems.
 	 */
-	num = getmntinfo(, MNT_NOWAIT);
-	for (i = 0; i < num; i++) {
-		struct mountd_exports_list mel;
-
-		/* Delete all entries from the export list. */
-		mel.mel_path = fsp->f_mntonname;
-		mel.mel_nexports = 0;
-		if (nfssvc(NFSSVC_SETEXPORTSLIST, ) == -1 &&
-		errno != EOPNOTSUPP)
-			syslog(LOG_ERR, "Can't delete exports for %s (%m)",
-			fsp->f_mntonname);
-
-		fsp++;
+	mel_tab_len = getmntinfo(, MNT_NOWAIT);
+	mel_tab = ecalloc(mel_tab_len, sizeof(*mel_tab));
+	for (i = 0; i < mel_tab_len; i++) {
+		mel_tab[i].mel_path = estrdup(fsp[i].f_mntonname);
+		mel_tab[i].mel_nexports = 0;
+		mel_tab[i].mel_exports = NULL;
 	}
+	qsort(mel_tab, mel_tab_len, sizeof(mel_tab[0]), mel_compare);
 
 	/*
 	 * Read in the exports file and build the list, calling
@@ -1278,6 +1286,30 @@ get_exportlist(int n)
 
 		(void)fclose(exp_file);
 	}
+
+	for (i = 0; i < mel_tab_len; i++) {
+		struct mountd_exports_list *mel = _tab[i];
+
+		if (nfssvc(NFSSVC_REPLACEEXPORTSLIST, mel) == -1 &&
+		(mel->mel_nexports > 0 || errno != EOPNOTSUPP))
+			syslog(LOG_ERR, "Can't update exports for %s (%m)",
+			mel_tab[i].mel_path);
+		for (j = 0; j < (int)mel_tab->mel_nexports; j++) {
+			struct export_args *export = >mel_exports[j];
+
+			if (export->ex_indexfile)
+free(export->ex_indexfile);
+			if (export->ex_addr)
+free(export->ex_addr);
+			if (export->ex_mask)
+free(export->ex_mask);
+		}
+		if (mel->mel_nexports > 0)
+			free(mel->mel_exports);
+		free(__UNCONST(mel->mel_path));
+	}
+	free(mel_tab);
+	mel_tab_len = 0;
 }
 
 /*
@@ -1923,31 +1955,39 @@ add_export_arg(const char *path, int exf
 struct sockaddr *addrp, int addrlen, struct sockaddr *maskp, int masklen,
 char *indexfile)
 {
-	struct mountd_exports_list mel;
-	struct export_args export;
-	int error;
+	const struct mountd_exports_list mel_key = { .mel_path = path };
+	struct mountd_exports_list *mel;
+	struct export_args *export;
 
 	if (addrp != NULL && addrp->sa_family == AF_INET6 && have_v6 == 0)
 		return 0;
 
-	mel.mel_path = path;
-	mel.mel_nexports = 1;
-	mel.mel_exports = 
-
-	export.ex_flags = exflags;
-	export.ex_anon = *anoncrp;
-	export.ex_indexfile = indexfile;
-	export.ex_addr = addrp;
-	export.ex_addrlen = addrlen;
-	export.ex_mask = maskp;
-	export.ex_masklen = masklen;
-
-	error = nfssvc(NFSSVC_SETEXPORTSLIST, );
-
-	if (error) {
-		syslog(LOG_ERR, "Can't change attributes for %s: %m", path);
+	mel = bsearch(_key, mel_tab, mel_tab_len, sizeof(mel_tab[0]),
+	mel_compare);
+	if (mel == NULL) {
+		syslog(LOG_ERR, "Can't change attributes for %s: not found",
+		path);
 		return 1;
 	}
+	ereallocarr(>mel_exports, mel->mel_nexports + 1,
+	sizeof(*mel->mel_exports));
+	export = >mel_exports[mel->mel_nexports++];
+	memset(export, 0, sizeof(*export));
+
+	export->ex_flags = 

CVS commit: src/usr.sbin/mountd

2021-06-04 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Fri Jun  4 10:46:01 UTC 2021

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

Log Message:
Restructure do_nfssvc() and simplify the left cases GT_HOST and GT_NET.

Add a helper add_export_arg() that emits a single export_args item and
does the IPv6 check.
Always use the path of the mount point for the export.


To generate a diff of this commit:
cvs rdiff -u -r1.134 -r1.135 src/usr.sbin/mountd/mountd.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/mountd/mountd.c
diff -u src/usr.sbin/mountd/mountd.c:1.134 src/usr.sbin/mountd/mountd.c:1.135
--- src/usr.sbin/mountd/mountd.c:1.134	Tue Feb 16 10:00:27 2021
+++ src/usr.sbin/mountd/mountd.c	Fri Jun  4 10:46:01 2021
@@ -1,4 +1,4 @@
-/* 	$NetBSD: mountd.c,v 1.134 2021/02/16 10:00:27 hannken Exp $	 */
+/* 	$NetBSD: mountd.c,v 1.135 2021/06/04 10:46:01 hannken Exp $	 */
 
 /*
  * Copyright (c) 1989, 1993
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 19
 #if 0
 static char sccsid[] = "@(#)mountd.c  8.15 (Berkeley) 5/1/95";
 #else
-__RCSID("$NetBSD: mountd.c,v 1.134 2021/02/16 10:00:27 hannken Exp $");
+__RCSID("$NetBSD: mountd.c,v 1.135 2021/06/04 10:46:01 hannken Exp $");
 #endif
 #endif/* not lint */
 
@@ -1918,6 +1918,40 @@ get_ht(void)
 	return (hp);
 }
 
+static int
+add_export_arg(const char *path, int exflags, struct uucred *anoncrp,
+struct sockaddr *addrp, int addrlen, struct sockaddr *maskp, int masklen,
+char *indexfile)
+{
+	struct mountd_exports_list mel;
+	struct export_args export;
+	int error;
+
+	if (addrp != NULL && addrp->sa_family == AF_INET6 && have_v6 == 0)
+		return 0;
+
+	mel.mel_path = path;
+	mel.mel_nexports = 1;
+	mel.mel_exports = 
+
+	export.ex_flags = exflags;
+	export.ex_anon = *anoncrp;
+	export.ex_indexfile = indexfile;
+	export.ex_addr = addrp;
+	export.ex_addrlen = addrlen;
+	export.ex_mask = maskp;
+	export.ex_masklen = masklen;
+
+	error = nfssvc(NFSSVC_SETEXPORTSLIST, );
+
+	if (error) {
+		syslog(LOG_ERR, "Can't change attributes for %s: %m", path);
+		return 1;
+	}
+
+	return 0;
+}
+
 /*
  * Do the nfssvc syscall to push the export info into the kernel.
  */
@@ -1930,92 +1964,37 @@ do_nfssvc(const char *line, size_t linen
 	struct sockaddr_storage ss;
 	struct addrinfo *ai;
 	int addrlen;
-	int done;
-	struct export_args export;
 
-	export.ex_flags = exflags;
-	export.ex_anon = *anoncrp;
-	export.ex_indexfile = ep->ex_indexfile;
 	if (grp->gr_type == GT_HOST) {
-		ai = grp->gr_ptr.gt_addrinfo;
-		addrp = ai->ai_addr;
-		addrlen = ai->ai_addrlen;
-	} else {
-		addrp = NULL;
-		ai = NULL;	/* XXXGCC -Wuninitialized */
-		addrlen = 0;	/* XXXGCC -Wuninitialized */
-	}
-	done = FALSE;
-	while (!done) {
-		struct mountd_exports_list mel;
-
-		switch (grp->gr_type) {
-		case GT_HOST:
-			if (addrp != NULL && addrp->sa_family == AF_INET6 &&
-			have_v6 == 0)
-goto skip;
-			export.ex_addr = addrp;
-			export.ex_addrlen = addrlen;
-			export.ex_masklen = 0;
-			break;
-		case GT_NET:
-			export.ex_addr = (struct sockaddr *)
-			>gr_ptr.gt_net.nt_net;
-			if (export.ex_addr->sa_family == AF_INET6 &&
-			have_v6 == 0)
-goto skip;
-			export.ex_addrlen = export.ex_addr->sa_len;
-			memset(, 0, sizeof ss);
-			ss.ss_family = export.ex_addr->sa_family;
-			ss.ss_len = export.ex_addr->sa_len;
-			if (allones(, grp->gr_ptr.gt_net.nt_len) != 0) {
-syslog(LOG_ERR,
-"\"%s\", line %ld: Bad network flag",
-line, (unsigned long)lineno);
-return (1);
-			}
-			export.ex_mask = (struct sockaddr *)
-			export.ex_masklen = ss.ss_len;
-			break;
-		default:
-			syslog(LOG_ERR, "\"%s\", line %ld: Bad netgroup type",
+		for (ai = grp->gr_ptr.gt_addrinfo; ai; ai = ai->ai_next) {
+			addrp = ai->ai_addr;
+			addrlen = ai->ai_addrlen;
+			if (add_export_arg(fsb->f_mntonname, exflags, anoncrp,
+			addrp, addrlen, NULL, 0, ep->ex_indexfile) != 0)
+return 1;
+		}
+	} else if (grp->gr_type == GT_NET) {
+		addrp = (struct sockaddr *)>gr_ptr.gt_net.nt_net;
+		addrlen = addrp->sa_len;
+		memset(, 0, sizeof ss);
+		ss.ss_family = addrp->sa_family;
+		ss.ss_len = addrp->sa_len;
+		if (allones(, grp->gr_ptr.gt_net.nt_len) != 0) {
+			syslog(LOG_ERR, "\"%s\", line %ld: Bad network flag",
 			line, (unsigned long)lineno);
-			return (1);
-		};
-
-		/*
-		 * XXX:
-		 * Maybe I should just use the fsb->f_mntonname path?
-		 */
-
-		mel.mel_path = dirp;
-		mel.mel_nexports = 1;
-		mel.mel_exports = 
-
-		if (nfssvc(NFSSVC_SETEXPORTSLIST, ) != 0) {
-			syslog(LOG_ERR,
-	"\"%s\", line %ld: Can't change attributes for %s to %s: %m",
-			line, (unsigned long)lineno,
-			dirp, (grp->gr_type == GT_HOST) ?
-			grp->gr_ptr.gt_addrinfo->ai_canonname :
-			(grp->gr_type == GT_NET) ?
-			grp->gr_ptr.gt_net.nt_name :
-			"Unknown");
-			return (1);
+			return 1;
 		}
-skip:
-		if (addrp) {
-			ai = 

CVS commit: src/sys/nfs

2021-06-04 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Fri Jun  4 10:44:59 UTC 2021

Modified Files:
src/sys/nfs: nfs.h nfs_export.c nfs_syscalls.c nfs_var.h

Log Message:
Add flag/command NFSSVC_REPLACEEXPORTSLIST to nfssvc(2) system call.

Works like NFSSVC_SETEXPORTSLIST but supports "mel_nexports > 1"
and will atomically update the complete exports list for a file system.


To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.79 src/sys/nfs/nfs.h
cvs rdiff -u -r1.62 -r1.63 src/sys/nfs/nfs_export.c
cvs rdiff -u -r1.162 -r1.163 src/sys/nfs/nfs_syscalls.c
cvs rdiff -u -r1.94 -r1.95 src/sys/nfs/nfs_var.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/nfs/nfs.h
diff -u src/sys/nfs/nfs.h:1.78 src/sys/nfs/nfs.h:1.79
--- src/sys/nfs/nfs.h:1.78	Wed Aug 22 01:05:24 2018
+++ src/sys/nfs/nfs.h	Fri Jun  4 10:44:58 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: nfs.h,v 1.78 2018/08/22 01:05:24 msaitoh Exp $	*/
+/*	$NetBSD: nfs.h,v 1.79 2021/06/04 10:44:58 hannken Exp $	*/
 /*
  * Copyright (c) 1989, 1993, 1995
  *	The Regents of the University of California.  All rights reserved.
@@ -285,6 +285,7 @@ struct nfsstats {
 #define	NFSSVC_AUTHINFAIL 0x080
 #define	NFSSVC_MNTD	0x100
 #define	NFSSVC_SETEXPORTSLIST	0x200
+#define	NFSSVC_REPLACEEXPORTSLIST	0x400
 
 /*
  * fs.nfs sysctl(3) identifiers

Index: src/sys/nfs/nfs_export.c
diff -u src/sys/nfs/nfs_export.c:1.62 src/sys/nfs/nfs_export.c:1.63
--- src/sys/nfs/nfs_export.c:1.62	Fri Jan 17 20:08:09 2020
+++ src/sys/nfs/nfs_export.c	Fri Jun  4 10:44:58 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: nfs_export.c,v 1.62 2020/01/17 20:08:09 ad Exp $	*/
+/*	$NetBSD: nfs_export.c,v 1.63 2021/06/04 10:44:58 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998, 2004, 2005, 2008, 2019 The NetBSD Foundation, Inc.
@@ -77,7 +77,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nfs_export.c,v 1.62 2020/01/17 20:08:09 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nfs_export.c,v 1.63 2021/06/04 10:44:58 hannken Exp $");
 
 #include 
 #include 
@@ -233,17 +233,14 @@ netexport_fini(void)
  * Returns zero on success or an appropriate error code otherwise.
  *
  * Helper function for the nfssvc(2) system call (NFSSVC_SETEXPORTSLIST
- * command).
+ * and NFSSVC_REPLACEEXPORTSLIST command).
  */
 int
 mountd_set_exports_list(const struct mountd_exports_list *mel, struct lwp *l,
-struct mount *nmp)
+struct mount *nmp, int cmd)
 {
 	int error;
-#ifdef notyet
-	/* XXX: See below to see the reason why this is disabled. */
 	size_t i;
-#endif
 	struct mount *mp;
 	struct netexport *ne;
 	struct pathbuf *pb;
@@ -302,31 +299,24 @@ mountd_set_exports_list(const struct mou
 	KASSERT(ne != NULL);
 	KASSERT(ne->ne_mount == mp);
 
-	/*
-	 * XXX: The part marked as 'notyet' works fine from the kernel's
-	 * point of view, in the sense that it is able to atomically update
-	 * the complete exports list for a file system.  However, supporting
-	 * this in mountd(8) requires a lot of work; so, for now, keep the
-	 * old behavior of updating a single entry per call.
-	 *
-	 * When mountd(8) is fixed, just remove the second branch of this
-	 * preprocessor conditional and enable the first one.
-	 */
-#ifdef notyet
-	netexport_clear(ne);
-	for (i = 0; error == 0 && i < mel->mel_nexports; i++)
-		error = export(ne, >mel_exports[i]);
-#else
-	if (mel->mel_nexports == 0)
+	if (cmd == NFSSVC_SETEXPORTSLIST) {
+		if (mel->mel_nexports == 0)
+			netexport_clear(ne);
+		else if (mel->mel_nexports == 1)
+			error = export(ne, >mel_exports[0]);
+		else {
+			printf("%s: Cannot set more than one "
+			"entry at once (unimplemented)\n", __func__);
+			error = EOPNOTSUPP;
+		}
+	} else if (cmd == NFSSVC_REPLACEEXPORTSLIST) {
 		netexport_clear(ne);
-	else if (mel->mel_nexports == 1)
-		error = export(ne, >mel_exports[0]);
-	else {
-		printf("%s: Cannot set more than one "
-		"entry at once (unimplemented)\n", __func__);
+		for (i = 0; error == 0 && i < mel->mel_nexports; i++)
+			error = export(ne, >mel_exports[i]);
+	} else {
+		printf("%s: Command %#x not implemented\n", __func__, cmd);
 		error = EOPNOTSUPP;
 	}
-#endif
 
 out:
 	netexport_wrunlock();
@@ -455,7 +445,7 @@ nfs_export_update_30(struct mount *mp, c
 		mel.mel_exports = (void *)>eargs;
 	}
 
-	return mountd_set_exports_list(, curlwp, mp);
+	return mountd_set_exports_list(, curlwp, mp, NFSSVC_SETEXPORTSLIST);
 }
 
 /*

Index: src/sys/nfs/nfs_syscalls.c
diff -u src/sys/nfs/nfs_syscalls.c:1.162 src/sys/nfs/nfs_syscalls.c:1.163
--- src/sys/nfs/nfs_syscalls.c:1.162	Sat Mar 14 18:08:39 2020
+++ src/sys/nfs/nfs_syscalls.c	Fri Jun  4 10:44:58 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: nfs_syscalls.c,v 1.162 2020/03/14 18:08:39 ad Exp $	*/
+/*	$NetBSD: nfs_syscalls.c,v 1.163 2021/06/04 10:44:58 hannken Exp $	*/
 
 /*
  * Copyright (c) 1989, 1993
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nfs_syscalls.c,v 1.162 2020/03/14 18:08:39 ad Exp $");

CVS commit: src/external/cddl/osnet/dist/common/nvpair

2021-05-21 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Fri May 21 17:32:49 UTC 2021

Modified Files:
src/external/cddl/osnet/dist/common/nvpair: nvpair.c

Log Message:
Replace the Solaris style endian check (exactly one of
_LITTLE_ENDIAN or _BIG_ENDIAN is defined) with standard check
"#if BYTE_ORDER == BIG_ENDIAN" like we do it elseware.

Should fix PR 56191 (ZFS tests fail on sparc64)


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/external/cddl/osnet/dist/common/nvpair/nvpair.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/common/nvpair/nvpair.c
diff -u src/external/cddl/osnet/dist/common/nvpair/nvpair.c:1.5 src/external/cddl/osnet/dist/common/nvpair/nvpair.c:1.6
--- src/external/cddl/osnet/dist/common/nvpair/nvpair.c:1.5	Mon Mar  2 15:45:33 2020
+++ src/external/cddl/osnet/dist/common/nvpair/nvpair.c	Fri May 21 17:32:49 2021
@@ -2255,11 +2255,11 @@ nvlist_common(nvlist_t *nvl, char *buf, 
 	int err = 0;
 	nvstream_t nvs;
 	int nvl_endian;
-#ifdef	_LITTLE_ENDIAN
-	int host_endian = 1;
-#else
+#if BYTE_ORDER == BIG_ENDIAN
 	int host_endian = 0;
-#endif	/* _LITTLE_ENDIAN */
+#else
+	int host_endian = 1;
+#endif	/* BYTE_ORDER */
 	nvs_header_t *nvh = (void *)buf;
 
 	if (buflen == NULL || nvl == NULL ||



CVS commit: src/sys/net/lagg

2021-05-18 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Tue May 18 11:02:58 UTC 2021

Modified Files:
src/sys/net/lagg: if_lagg_lacp.c

Log Message:
Make this compile without DIAGNOSTIC.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/net/lagg/if_lagg_lacp.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/net/lagg/if_lagg_lacp.c
diff -u src/sys/net/lagg/if_lagg_lacp.c:1.1 src/sys/net/lagg/if_lagg_lacp.c:1.2
--- src/sys/net/lagg/if_lagg_lacp.c:1.1	Mon May 17 04:07:43 2021
+++ src/sys/net/lagg/if_lagg_lacp.c	Tue May 18 11:02:58 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg_lacp.c,v 1.1 2021/05/17 04:07:43 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg_lacp.c,v 1.2 2021/05/18 11:02:58 hannken Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-NetBSD
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.1 2021/05/17 04:07:43 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.2 2021/05/18 11:02:58 hannken Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_lagg.h"
@@ -504,7 +504,7 @@ void
 lacp_detach(struct lagg_proto_softc *xlsc)
 {
 	struct lacp_softc *lsc = (struct lacp_softc *)xlsc;
-	struct lagg_softc *sc = lsc->lsc_softc;
+	struct lagg_softc *sc __diagused = lsc->lsc_softc;
 
 	KASSERT(LAGG_LOCKED(lsc->lsc_softc));
 	KASSERT(TAILQ_EMPTY(>lsc_aggregators));
@@ -2149,7 +2149,7 @@ lacp_set_mux(struct lacp_softc *lsc, str
 static void
 lacp_sm_mux(struct lacp_softc *lsc, struct lacp_port *lacpp)
 {
-	struct lacp_aggregator *la;
+	struct lacp_aggregator *la __diagused;
 	enum lacp_mux_state  next_state;
 	enum lacp_selected selected;
 	bool p_sync, p_collecting;



CVS commit: src/sys/kern

2021-05-18 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Tue May 18 08:59:44 UTC 2021

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

Log Message:
Remove a superfluous VOP_GETATTR() from elf_load_interp() and replace
the LK_EXCLUSIVE lock with a LK_SHARED lock.

The attributes requested were not used since Rev 1.25 of exec_elf32.c
from 1997/05/08 when mycroft GCd the va_mode check.


To generate a diff of this commit:
cvs rdiff -u -r1.101 -r1.102 src/sys/kern/exec_elf.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/exec_elf.c
diff -u src/sys/kern/exec_elf.c:1.101 src/sys/kern/exec_elf.c:1.102
--- src/sys/kern/exec_elf.c:1.101	Sun Jan 12 18:30:58 2020
+++ src/sys/kern/exec_elf.c	Tue May 18 08:59:44 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: exec_elf.c,v 1.101 2020/01/12 18:30:58 ad Exp $	*/
+/*	$NetBSD: exec_elf.c,v 1.102 2021/05/18 08:59:44 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1994, 2000, 2005, 2015, 2020 The NetBSD Foundation, Inc.
@@ -57,7 +57,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: exec_elf.c,v 1.101 2020/01/12 18:30:58 ad Exp $");
+__KERNEL_RCSID(1, "$NetBSD: exec_elf.c,v 1.102 2021/05/18 08:59:44 hannken Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_pax.h"
@@ -421,7 +421,6 @@ elf_load_interp(struct lwp *l, struct ex
 {
 	int error, i;
 	struct vnode *vp;
-	struct vattr attr;
 	Elf_Ehdr eh;
 	Elf_Phdr *ph = NULL;
 	const Elf_Phdr *base_ph;
@@ -456,7 +455,7 @@ elf_load_interp(struct lwp *l, struct ex
 	}
 	/* We'll tidy this ourselves - otherwise we have locking issues */
 	epp->ep_interp = NULL;
-	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
+	vn_lock(vp, LK_SHARED | LK_RETRY);
 
 	/*
 	 * Similarly, if it's not marked as executable, or it's not a regular
@@ -469,11 +468,6 @@ elf_load_interp(struct lwp *l, struct ex
 	if ((error = VOP_ACCESS(vp, VEXEC, l->l_cred)) != 0)
 		goto bad;
 
-	/* get attributes */
-	/* XXX VOP_GETATTR() is the only thing that needs LK_EXCLUSIVE ^ */
-	if ((error = VOP_GETATTR(vp, , l->l_cred)) != 0)
-		goto bad;
-
 	/*
 	 * Check mount point.  Though we're not trying to exec this binary,
 	 * we will be executing code from it, so if the mount point



CVS commit: src/sys/fs/ntfs

2021-05-13 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Thu May 13 08:57:29 UTC 2021

Modified Files:
src/sys/fs/ntfs: ntfs_subr.c

Log Message:
ntfs_loadntnode(): Use bread() when ntm_sysvn[NTFS_MFTINO] is NULL.

May happen when loading node 0 (MFT) during mount and some
attributes are stored in another ntnode.

PR kern/56160 (Mount ntfs usb disk)


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/sys/fs/ntfs/ntfs_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/ntfs/ntfs_subr.c
diff -u src/sys/fs/ntfs/ntfs_subr.c:1.63 src/sys/fs/ntfs/ntfs_subr.c:1.64
--- src/sys/fs/ntfs/ntfs_subr.c:1.63	Fri Jan 17 20:08:08 2020
+++ src/sys/fs/ntfs/ntfs_subr.c	Thu May 13 08:57:29 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ntfs_subr.c,v 1.63 2020/01/17 20:08:08 ad Exp $	*/
+/*	$NetBSD: ntfs_subr.c,v 1.64 2021/05/13 08:57:29 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1998, 1999 Semen Ustimenko (sem...@freebsd.org)
@@ -29,7 +29,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ntfs_subr.c,v 1.63 2020/01/17 20:08:08 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ntfs_subr.c,v 1.64 2021/05/13 08:57:29 hannken Exp $");
 
 #include 
 #include 
@@ -267,7 +267,8 @@ ntfs_loadntnode(struct ntfsmount *ntmp, 
 
 	mfrp = malloc(ntfs_bntob(ntmp->ntm_bpmftrec), M_TEMP, M_WAITOK);
 
-	if (ip->i_number < NTFS_SYSNODESNUM) {
+	if (ip->i_number < NTFS_SYSNODESNUM ||
+	ntmp->ntm_sysvn[NTFS_MFTINO] == NULL) {
 		struct buf *bp;
 		daddr_t bn;
 		off_t boff;



CVS commit: src/sys/dev/dm

2021-05-07 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Fri May  7 09:54:43 UTC 2021

Modified Files:
src/sys/dev/dm: device-mapper.c

Log Message:
Track the number of cdev and bdev opens and fail dm_detach()
on open devices unless detach is forced.

PR kern/54969 (Disk cache is no longer flushed on shutdown)


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 src/sys/dev/dm/device-mapper.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/dm/device-mapper.c
diff -u src/sys/dev/dm/device-mapper.c:1.61 src/sys/dev/dm/device-mapper.c:1.62
--- src/sys/dev/dm/device-mapper.c:1.61	Wed Jul  8 15:07:13 2020
+++ src/sys/dev/dm/device-mapper.c	Fri May  7 09:54:43 2021
@@ -1,4 +1,4 @@
-/*$NetBSD: device-mapper.c,v 1.61 2020/07/08 15:07:13 thorpej Exp $ */
+/*$NetBSD: device-mapper.c,v 1.62 2021/05/07 09:54:43 hannken Exp $ */
 
 /*
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -260,8 +260,17 @@ dm_attach(device_t parent, device_t self
 static int
 dm_detach(device_t self, int flags)
 {
+	bool busy;
 	dm_dev_t *dmv;
 
+	dmv = dm_dev_lookup(NULL, NULL, device_unit(self));
+	mutex_enter(>diskp->dk_openlock);
+	busy = (dmv->diskp->dk_openmask != 0 && (flags & DETACH_FORCE) == 0);
+	mutex_exit(>diskp->dk_openlock);
+	dm_dev_unbusy(dmv);
+	if (busy)
+		return EBUSY;
+
 	pmf_device_deregister(self);
 
 	/* Detach device from global device list */
@@ -334,6 +343,25 @@ dmdestroy(void)
 static int
 dmopen(dev_t dev, int flags, int mode, struct lwp *l)
 {
+	dm_dev_t *dmv;
+	struct disk *dk;
+
+	dmv = dm_dev_lookup(NULL, NULL, minor(dev));
+	if (dmv) {
+		dk = dmv->diskp;
+		mutex_enter(>dk_openlock);
+		switch (mode) {
+		case S_IFCHR:
+			dk->dk_copenmask |= 1;
+			break;
+		case S_IFBLK:
+			dk->dk_bopenmask |= 1;
+			break;
+		}
+		dk->dk_openmask = dk->dk_copenmask | dk->dk_bopenmask;
+		mutex_exit(>dk_openlock);
+		dm_dev_unbusy(dmv);
+	}
 
 	aprint_debug("dm open routine called %" PRIu32 "\n", minor(dev));
 	return 0;
@@ -342,8 +370,27 @@ dmopen(dev_t dev, int flags, int mode, s
 static int
 dmclose(dev_t dev, int flags, int mode, struct lwp *l)
 {
+	dm_dev_t *dmv;
+	struct disk *dk;
 
 	aprint_debug("dm close routine called %" PRIu32 "\n", minor(dev));
+
+	dmv = dm_dev_lookup(NULL, NULL, minor(dev));
+	if (dmv) {
+		dk = dmv->diskp;
+		mutex_enter(>dk_openlock);
+		switch (mode) {
+		case S_IFCHR:
+			dk->dk_copenmask &= ~1;
+			break;
+		case S_IFBLK:
+			dk->dk_bopenmask &= ~1;
+			break;
+		}
+		dk->dk_openmask = dk->dk_copenmask | dk->dk_bopenmask;
+		mutex_exit(>dk_openlock);
+		dm_dev_unbusy(dmv);
+	}
 	return 0;
 }
 



CVS commit: src/sys/dev/dm

2021-05-07 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Fri May  7 09:53:39 UTC 2021

Modified Files:
src/sys/dev/dm: dm_ioctl.c

Log Message:
Make sure the unit number of device-mapper devices matches their minor number.


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/sys/dev/dm/dm_ioctl.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/dm/dm_ioctl.c
diff -u src/sys/dev/dm/dm_ioctl.c:1.50 src/sys/dev/dm/dm_ioctl.c:1.51
--- src/sys/dev/dm/dm_ioctl.c:1.50	Wed Jul  8 15:07:13 2020
+++ src/sys/dev/dm/dm_ioctl.c	Fri May  7 09:53:39 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: dm_ioctl.c,v 1.50 2020/07/08 15:07:13 thorpej Exp $  */
+/* $NetBSD: dm_ioctl.c,v 1.51 2021/05/07 09:53:39 hannken Exp $  */
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dm_ioctl.c,v 1.50 2020/07/08 15:07:13 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dm_ioctl.c,v 1.51 2021/05/07 09:53:39 hannken Exp $");
 
 /*
  * Locking is used to synchronise between ioctl calls and between dm_table's
@@ -92,18 +92,12 @@ __KERNEL_RCSID(0, "$NetBSD: dm_ioctl.c,v
 
 #include "netbsd-dm.h"
 #include "dm.h"
+#include "ioconf.h"
 
+extern struct cfattach dm_ca;
 static uint32_t sc_minor_num;
 uint32_t dm_dev_counter;
 
-/* Generic cf_data for device-mapper driver */
-static struct cfdata dm_cfdata = {
-	.cf_name = "dm",
-	.cf_atname = "dm",
-	.cf_fstate = FSTATE_STAR,
-	.cf_unit = 0
-};
-
 #define DM_REMOVE_FLAG(flag, name) do {	\
 	prop_dictionary_get_uint32(dm_dict,DM_IOCTL_FLAGS,);	\
 	flag &= ~name;			\
@@ -196,6 +190,7 @@ dm_dev_create_ioctl(prop_dictionary_t dm
 	int r;
 	uint32_t flags;
 	device_t devt;
+	cfdata_t cf;
 
 	flags = 0;
 	name = NULL;
@@ -214,7 +209,13 @@ dm_dev_create_ioctl(prop_dictionary_t dm
 		dm_dev_unbusy(dmv);
 		return EEXIST;
 	}
-	if ((devt = config_attach_pseudo(_cfdata)) == NULL) {
+	cf = kmem_alloc(sizeof(*cf), KM_SLEEP);
+	cf->cf_name = dm_cd.cd_name;
+	cf->cf_atname = dm_ca.ca_name;
+	cf->cf_unit = atomic_inc_32_nv(_minor_num);
+	cf->cf_fstate = FSTATE_NOTFOUND;
+	if ((devt = config_attach_pseudo(cf)) == NULL) {
+		kmem_free(cf, sizeof(*cf));
 		aprint_error("Unable to attach pseudo device dm/%s\n", name);
 		return (ENOMEM);
 	}
@@ -229,7 +230,7 @@ dm_dev_create_ioctl(prop_dictionary_t dm
 	if (name)
 		strlcpy(dmv->name, name, DM_NAME_LEN);
 
-	dmv->minor = (uint64_t)atomic_inc_32_nv(_minor_num);
+	dmv->minor = cf->cf_unit;
 	dmv->flags = 0;		/* device flags are set when needed */
 	dmv->ref_cnt = 0;
 	dmv->event_nr = 0;
@@ -365,6 +366,8 @@ dm_dev_rename_ioctl(prop_dictionary_t dm
 int
 dm_dev_remove_ioctl(prop_dictionary_t dm_dict)
 {
+	int error;
+	cfdata_t cf;
 	dm_dev_t *dmv;
 	const char *name, *uuid;
 	uint32_t flags, minor;
@@ -398,7 +401,11 @@ dm_dev_remove_ioctl(prop_dictionary_t dm
 	 * This will call dm_detach routine which will actually removes
 	 * device.
 	 */
-	return config_detach(devt, DETACH_QUIET);
+	cf = device_cfdata(devt);
+	error = config_detach(devt, DETACH_QUIET);
+	if (error == 0)
+		kmem_free(cf, sizeof(*cf));
+	return error;
 }
 
 /*



CVS commit: src/sys/miscfs/fdesc

2021-05-01 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sat May  1 15:08:14 UTC 2021

Modified Files:
src/sys/miscfs/fdesc: fdesc_vnops.c

Log Message:
Make sure fdesc_lookup() never returns VNON vnodes.

Should fix PR kern/56130 (fdescfs create nodes with wrong major number)


To generate a diff of this commit:
cvs rdiff -u -r1.134 -r1.135 src/sys/miscfs/fdesc/fdesc_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/fdesc/fdesc_vnops.c
diff -u src/sys/miscfs/fdesc/fdesc_vnops.c:1.134 src/sys/miscfs/fdesc/fdesc_vnops.c:1.135
--- src/sys/miscfs/fdesc/fdesc_vnops.c:1.134	Sat Jun 27 17:29:19 2020
+++ src/sys/miscfs/fdesc/fdesc_vnops.c	Sat May  1 15:08:14 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: fdesc_vnops.c,v 1.134 2020/06/27 17:29:19 christos Exp $	*/
+/*	$NetBSD: fdesc_vnops.c,v 1.135 2021/05/01 15:08:14 hannken Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fdesc_vnops.c,v 1.134 2020/06/27 17:29:19 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdesc_vnops.c,v 1.135 2021/05/01 15:08:14 hannken Exp $");
 
 #include 
 #include 
@@ -295,9 +295,20 @@ bad:
 good:
 	KASSERT(ix != -1);
 	error = vcache_get(dvp->v_mount, , sizeof(ix), vpp);
-	if (error == 0 && ix == FD_CTTY)
+	if (error)
+		return error;
+
+	/*
+	 * Prevent returning VNON nodes.
+	 * Operation fdesc_inactive() will reset the type to VNON.
+	 */
+	if (ix == FD_CTTY)
 		(*vpp)->v_type = VCHR;
-	return error;
+	else if (ix >= FD_DESC)
+		(*vpp)->v_type = VREG;
+	KASSERT((*vpp)->v_type != VNON);
+
+	return 0;
 }
 
 int



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

2021-04-21 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed Apr 21 10:02:34 UTC 2021

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

Log Message:
Prevent blocking l2arc_feed_thread() forever, skip the
cv_timedwait() for negative or zero ticks.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/arc.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/arc.c
diff -u src/external/cddl/osnet/dist/uts/common/fs/zfs/arc.c:1.19 src/external/cddl/osnet/dist/uts/common/fs/zfs/arc.c:1.20
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/arc.c:1.19	Thu Jun 11 19:20:42 2020
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/arc.c	Wed Apr 21 10:02:34 2021
@@ -7246,8 +7246,15 @@ l2arc_feed_thread(void *dummy __unused)
 
 	while (l2arc_thread_exit == 0) {
 		CALLB_CPR_SAFE_BEGIN();
+#ifdef __NetBSD__
+		clock_t now = ddi_get_lbolt();
+		if (next > now)
+			(void) cv_timedwait(_feed_thr_cv,
+			_feed_thr_lock, next - now);
+#else
 		(void) cv_timedwait(_feed_thr_cv, _feed_thr_lock,
 		next - ddi_get_lbolt());
+#endif
 		CALLB_CPR_SAFE_END(, _feed_thr_lock);
 		next = ddi_get_lbolt() + hz;
 



CVS commit: src/sys/uvm

2021-02-19 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Fri Feb 19 13:20:44 UTC 2021

Modified Files:
src/sys/uvm: uvm_swap.c

Log Message:
When turning off swap during reboot we have to lock with LK_RETRY
as regular files got reclaimed during unmount.

Adresses PR kern/54969 (Disk cache is no longer flushed on shutdown)


To generate a diff of this commit:
cvs rdiff -u -r1.201 -r1.202 src/sys/uvm/uvm_swap.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/uvm/uvm_swap.c
diff -u src/sys/uvm/uvm_swap.c:1.201 src/sys/uvm/uvm_swap.c:1.202
--- src/sys/uvm/uvm_swap.c:1.201	Tue Feb 16 09:56:32 2021
+++ src/sys/uvm/uvm_swap.c	Fri Feb 19 13:20:43 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_swap.c,v 1.201 2021/02/16 09:56:32 hannken Exp $	*/
+/*	$NetBSD: uvm_swap.c,v 1.202 2021/02/19 13:20:43 hannken Exp $	*/
 
 /*
  * Copyright (c) 1995, 1996, 1997, 2009 Matthew R. Green
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_swap.c,v 1.201 2021/02/16 09:56:32 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_swap.c,v 1.202 2021/02/19 13:20:43 hannken Exp $");
 
 #include "opt_uvmhist.h"
 #include "opt_compat_netbsd.h"
@@ -1155,14 +1155,11 @@ again:
 			printf("\nturning off swap on %s...", sdp->swd_path);
 #endif
 			/* Have to lock and reference vnode for swap_off(). */
-			if (vn_lock(vp = sdp->swd_vp, LK_EXCLUSIVE)) {
-error = EBUSY;
-			} else {
-vref(vp);
-error = swap_off(l, sdp);
-vput(vp);
-mutex_enter(_swap_data_lock);
-			}
+			vn_lock(vp = sdp->swd_vp, LK_EXCLUSIVE|LK_RETRY);
+			vref(vp);
+			error = swap_off(l, sdp);
+			vput(vp);
+			mutex_enter(_swap_data_lock);
 			if (error) {
 printf("stopping swap on %s failed "
 "with error %d\n", sdp->swd_path, error);



CVS commit: src/etc/rc.d

2021-02-16 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Tue Feb 16 10:02:42 UTC 2021

Modified Files:
src/etc/rc.d: mountall mountd

Log Message:
Enable "/etc/zfs/exports" from "zfs share" in rc.d/mountd and rc.d/mountall.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/etc/rc.d/mountall src/etc/rc.d/mountd

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

Modified files:

Index: src/etc/rc.d/mountall
diff -u src/etc/rc.d/mountall:1.13 src/etc/rc.d/mountall:1.14
--- src/etc/rc.d/mountall:1.13	Sun Mar  1 15:22:55 2020
+++ src/etc/rc.d/mountall	Tue Feb 16 10:02:42 2021
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# $NetBSD: mountall,v 1.13 2020/03/01 15:22:55 roy Exp $
+# $NetBSD: mountall,v 1.14 2021/02/16 10:02:42 hannken Exp $
 #
 
 # REQUIRE: mountcritremote named ypbind
@@ -20,6 +20,7 @@ mountall_start()
 	# may try and null mount paths on ZFS.
 	if checkyesno zfs; then
 		zfs mount -a
+		zfs share -a
 	fi
 
 	# Mount file systems noted in fstab.
@@ -34,6 +35,7 @@ mountall_stop()
 
 	# Unmount ZFS file systems.
 	if checkyesno zfs; then
+		zfs unshare -a
 		zfs unmount -a
 	fi
 }
Index: src/etc/rc.d/mountd
diff -u src/etc/rc.d/mountd:1.13 src/etc/rc.d/mountd:1.14
--- src/etc/rc.d/mountd:1.13	Wed Nov 12 12:35:52 2008
+++ src/etc/rc.d/mountd	Tue Feb 16 10:02:42 2021
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# $NetBSD: mountd,v 1.13 2008/11/12 12:35:52 ad Exp $
+# $NetBSD: mountd,v 1.14 2021/02/16 10:02:42 hannken Exp $
 #
 
 # PROVIDE: mountd
@@ -19,6 +19,12 @@ mountd_precmd()
 {
 	rm -f /var/db/mountdtab
 	( umask 022 ; > /var/db/mountdtab )
+	if checkyesno zfs; then
+		if [ ! -r /etc/zfs/exports ]; then
+			touch /etc/zfs/exports
+		fi
+		rc_flags="${rc_flags} /etc/exports /etc/zfs/exports"
+	fi
 	return 0
 }
 



CVS commit: src/usr.sbin/mountd

2021-02-16 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Tue Feb 16 10:00:27 UTC 2021

Modified Files:
src/usr.sbin/mountd: mountd.8 mountd.c

Log Message:
Add support for multiple exports files. This will be useful for example for
ZFS, where we have an automatically generated /etc/zfs/exports file, which
should not be edited directly.


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/usr.sbin/mountd/mountd.8
cvs rdiff -u -r1.133 -r1.134 src/usr.sbin/mountd/mountd.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/mountd/mountd.8
diff -u src/usr.sbin/mountd/mountd.8:1.38 src/usr.sbin/mountd/mountd.8:1.39
--- src/usr.sbin/mountd/mountd.8:1.38	Sat Dec 24 08:26:57 2016
+++ src/usr.sbin/mountd/mountd.8	Tue Feb 16 10:00:27 2021
@@ -1,4 +1,4 @@
-.\"	$NetBSD: mountd.8,v 1.38 2016/12/24 08:26:57 abhinav Exp $
+.\"	$NetBSD: mountd.8,v 1.39 2021/02/16 10:00:27 hannken Exp $
 .\"
 .\" Copyright (c) 1989, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\" @(#)mountd.8	8.4 (Berkeley) 4/28/95
 .\"
-.Dd November 2, 2011
+.Dd February 16, 2021
 .Dt MOUNTD 8
 .Os
 .Sh NAME
@@ -42,7 +42,7 @@ mount requests
 .Op Fl dN
 .Op Fl P Ar policy
 .Op Fl p Ar port
-.Op Ar exportsfile
+.Op Ar exportsfile ...
 .Sh DESCRIPTION
 .Nm
 is the server for
@@ -101,6 +101,7 @@ The
 .Ar exportsfile
 argument specifies an alternative location
 for the exports file.
+There can many exports files.
 .El
 .Pp
 When

Index: src/usr.sbin/mountd/mountd.c
diff -u src/usr.sbin/mountd/mountd.c:1.133 src/usr.sbin/mountd/mountd.c:1.134
--- src/usr.sbin/mountd/mountd.c:1.133	Tue Feb 16 09:58:35 2021
+++ src/usr.sbin/mountd/mountd.c	Tue Feb 16 10:00:27 2021
@@ -1,4 +1,4 @@
-/* 	$NetBSD: mountd.c,v 1.133 2021/02/16 09:58:35 hannken Exp $	 */
+/* 	$NetBSD: mountd.c,v 1.134 2021/02/16 10:00:27 hannken Exp $	 */
 
 /*
  * Copyright (c) 1989, 1993
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 19
 #if 0
 static char sccsid[] = "@(#)mountd.c  8.15 (Berkeley) 5/1/95";
 #else
-__RCSID("$NetBSD: mountd.c,v 1.133 2021/02/16 09:58:35 hannken Exp $");
+__RCSID("$NetBSD: mountd.c,v 1.134 2021/02/16 10:00:27 hannken Exp $");
 #endif
 #endif/* not lint */
 
@@ -226,7 +226,8 @@ __dead static void no_nfs(int);
 static struct exportlist *exphead;
 static struct mountlist *mlhead;
 static struct grouplist *grphead;
-static const char *exname;
+static char *const exnames_default[] = { __UNCONST(_PATH_EXPORTS), NULL };
+static char *const *exnames;
 static struct uucred def_anon = {
 	1,
 	(uid_t) -2,
@@ -384,15 +385,15 @@ main(int argc, char **argv)
 #ifdef IPSEC
 			" [-P policy]"
 #endif
-			" [-p port] [exportsfile]\n", getprogname());
+			" [-p port] [exportsfile ...]\n", getprogname());
 			exit(1);
 		};
 	argc -= optind;
 	argv += optind;
-	if (argc == 1)
-		exname = *argv;
+	if (argc > 0)
+		exnames = argv;
 	else
-		exname = _PATH_EXPORTS;
+		exnames = exnames_default;
 
 	s = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
 	if (s < 0)
@@ -408,7 +409,7 @@ main(int argc, char **argv)
 
 	sem_init(, 0, 0);
 	pthread_create(, NULL, exportlist_thread, NULL);
-	exname = _PATH_EXPORTS;
+	exnames = exnames_default;
 	have_v6 = 0;
 	(void)signal(SIGHUP, signal_get_exportlist);
 #endif
@@ -1261,20 +1262,22 @@ get_exportlist(int n)
 	 * Read in the exports file and build the list, calling
 	 * mount() as we go along to push the export rules into the kernel.
 	 */
-	if ((exp_file = fopen(exname, "r")) == NULL) {
-		/*
-		 * Don't exit here; we can still reload the config
-		 * after a SIGHUP.
-		 */
-		if (mountd_debug)
-			(void)fprintf(stderr, "Can't open %s: %s\n", exname,
-			strerror(errno));
-		return;
-	}
+	for (i = 0; exnames[i] != NULL; i++) {
+		if ((exp_file = fopen(exnames[i], "r")) == NULL) {
+			/*
+			 * Don't exit here; we can still reload the config
+			 * after a SIGHUP.
+			 */
+			if (mountd_debug)
+(void)fprintf(stderr, "Can't open %s: %s\n",
+exnames[i], strerror(errno));
+			continue;
+		}
 
-	get_exportlist_one(exp_file);
+		get_exportlist_one(exp_file);
 
-	(void)fclose(exp_file);
+		(void)fclose(exp_file);
+	}
 }
 
 /*



CVS commit: src/usr.sbin/mountd

2021-02-16 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Tue Feb 16 09:58:35 UTC 2021

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

Log Message:
Split get_exportlist() into get_exportlist() and get_exportlist_one()
in preparation to support multiple input files.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.132 -r1.133 src/usr.sbin/mountd/mountd.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/mountd/mountd.c
diff -u src/usr.sbin/mountd/mountd.c:1.132 src/usr.sbin/mountd/mountd.c:1.133
--- src/usr.sbin/mountd/mountd.c:1.132	Wed Jun 17 00:16:21 2020
+++ src/usr.sbin/mountd/mountd.c	Tue Feb 16 09:58:35 2021
@@ -1,4 +1,4 @@
-/* 	$NetBSD: mountd.c,v 1.132 2020/06/17 00:16:21 kamil Exp $	 */
+/* 	$NetBSD: mountd.c,v 1.133 2021/02/16 09:58:35 hannken Exp $	 */
 
 /*
  * Copyright (c) 1989, 1993
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 19
 #if 0
 static char sccsid[] = "@(#)mountd.c  8.15 (Berkeley) 5/1/95";
 #else
-__RCSID("$NetBSD: mountd.c,v 1.132 2020/06/17 00:16:21 kamil Exp $");
+__RCSID("$NetBSD: mountd.c,v 1.133 2021/02/16 09:58:35 hannken Exp $");
 #endif
 #endif/* not lint */
 
@@ -1009,81 +1009,22 @@ parse_directory(const char *line, size_t
 }
 
 
-/*
- * Get the export list
- */
-/* ARGSUSED */
-void
-get_exportlist(int n)
+static void
+get_exportlist_one(FILE *exp_file)
 {
 	struct exportlist *ep, *ep2;
 	struct grouplist *grp, *tgrp;
 	struct exportlist **epp;
 	struct dirlist *dirhead;
-	struct statvfs fsb, *fsp;
+	struct statvfs fsb;
 	struct addrinfo *ai;
 	struct uucred anon;
 	char *cp, *endcp, *dirp, savedc;
-	int has_host, exflags, got_nondir, dirplen, num, i;
-	FILE *exp_file;
+	int has_host, exflags, got_nondir, dirplen;
 	char *line;
 	size_t lineno = 0, len;
 
-
-	/*
-	 * First, get rid of the old list
-	 */
-	ep = exphead;
-	while (ep) {
-		ep2 = ep;
-		ep = ep->ex_next;
-		free_exp(ep2);
-	}
-	exphead = NULL;
-
 	dirp = NULL;
-	dirplen = 0;
-	grp = grphead;
-	while (grp) {
-		tgrp = grp;
-		grp = grp->gr_next;
-		free_grp(tgrp);
-	}
-	grphead = NULL;
-
-	/*
-	 * And delete exports that are in the kernel for all local
-	 * file systems.
-	 */
-	num = getmntinfo(, MNT_NOWAIT);
-	for (i = 0; i < num; i++) {
-		struct mountd_exports_list mel;
-
-		/* Delete all entries from the export list. */
-		mel.mel_path = fsp->f_mntonname;
-		mel.mel_nexports = 0;
-		if (nfssvc(NFSSVC_SETEXPORTSLIST, ) == -1 &&
-		errno != EOPNOTSUPP)
-			syslog(LOG_ERR, "Can't delete exports for %s (%m)",
-			fsp->f_mntonname);
-
-		fsp++;
-	}
-
-	/*
-	 * Read in the exports file and build the list, calling
-	 * mount() as we go along to push the export rules into the kernel.
-	 */
-	if ((exp_file = fopen(exname, "r")) == NULL) {
-		/*
-		 * Don't exit here; we can still reload the config
-		 * after a SIGHUP.
-		 */
-		if (mountd_debug)
-			(void)fprintf(stderr, "Can't open %s: %s\n", exname,
-			strerror(errno));
-		return;
-	}
 	dirhead = NULL;
 	while ((line = fparseln(exp_file, , , NULL, 0)) != NULL) {
 		if (mountd_debug)
@@ -1262,6 +1203,77 @@ nextline:
 		}
 		free(line);
 	}
+}
+
+/*
+ * Get the export list
+ */
+/* ARGSUSED */
+void
+get_exportlist(int n)
+{
+	struct exportlist *ep, *ep2;
+	struct grouplist *grp, *tgrp;
+	struct statvfs *fsp;
+	int num, i;
+	FILE *exp_file;
+
+
+	/*
+	 * First, get rid of the old list
+	 */
+	ep = exphead;
+	while (ep) {
+		ep2 = ep;
+		ep = ep->ex_next;
+		free_exp(ep2);
+	}
+	exphead = NULL;
+
+	grp = grphead;
+	while (grp) {
+		tgrp = grp;
+		grp = grp->gr_next;
+		free_grp(tgrp);
+	}
+	grphead = NULL;
+
+	/*
+	 * And delete exports that are in the kernel for all local
+	 * file systems.
+	 */
+	num = getmntinfo(, MNT_NOWAIT);
+	for (i = 0; i < num; i++) {
+		struct mountd_exports_list mel;
+
+		/* Delete all entries from the export list. */
+		mel.mel_path = fsp->f_mntonname;
+		mel.mel_nexports = 0;
+		if (nfssvc(NFSSVC_SETEXPORTSLIST, ) == -1 &&
+		errno != EOPNOTSUPP)
+			syslog(LOG_ERR, "Can't delete exports for %s (%m)",
+			fsp->f_mntonname);
+
+		fsp++;
+	}
+
+	/*
+	 * Read in the exports file and build the list, calling
+	 * mount() as we go along to push the export rules into the kernel.
+	 */
+	if ((exp_file = fopen(exname, "r")) == NULL) {
+		/*
+		 * Don't exit here; we can still reload the config
+		 * after a SIGHUP.
+		 */
+		if (mountd_debug)
+			(void)fprintf(stderr, "Can't open %s: %s\n", exname,
+			strerror(errno));
+		return;
+	}
+
+	get_exportlist_one(exp_file);
+
 	(void)fclose(exp_file);
 }
 



CVS commit: src/sys

2021-02-16 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Tue Feb 16 09:56:32 UTC 2021

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

Log Message:
Reorganize uvm_swap_shutdown() a bit, make sure the vnode gets
locked and referenced across the call to swap_off() and finally
use it from vfs_unmountall1() to remove swap after unmounting
the last file system.

Adresses PR kern/54969 (Disk cache is no longer flushed on shutdown)


To generate a diff of this commit:
cvs rdiff -u -r1.85 -r1.86 src/sys/kern/vfs_mount.c
cvs rdiff -u -r1.200 -r1.201 src/sys/uvm/uvm_swap.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.85 src/sys/kern/vfs_mount.c:1.86
--- src/sys/kern/vfs_mount.c:1.85	Thu Nov 19 10:47:47 2020
+++ src/sys/kern/vfs_mount.c	Tue Feb 16 09:56:32 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_mount.c,v 1.85 2020/11/19 10:47:47 hannken Exp $	*/
+/*	$NetBSD: vfs_mount.c,v 1.86 2021/02/16 09:56:32 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1997-2020 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.85 2020/11/19 10:47:47 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.86 2021/02/16 09:56:32 hannken Exp $");
 
 #include 
 #include 
@@ -94,6 +94,8 @@ __KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,
 #include 
 #include 
 
+#include 
+
 enum mountlist_type {
 	ME_MOUNT,
 	ME_MARKER
@@ -1022,6 +1024,7 @@ bool
 vfs_unmountall1(struct lwp *l, bool force, bool verbose)
 {
 	struct mount *mp;
+	mount_iterator_t *iter;
 	bool any_error = false, progress = false;
 	uint64_t gen;
 	int error;
@@ -1056,6 +1059,13 @@ vfs_unmountall1(struct lwp *l, bool forc
 	if (any_error && verbose) {
 		printf("WARNING: some file systems would not unmount\n");
 	}
+	/* If the mountlist is empty it is time to remove swap. */
+	mountlist_iterator_init();
+	if (mountlist_iterator_next(iter) == NULL) {
+		uvm_swap_shutdown(l);
+	}
+	mountlist_iterator_destroy(iter);
+
 	return progress;
 }
 

Index: src/sys/uvm/uvm_swap.c
diff -u src/sys/uvm/uvm_swap.c:1.200 src/sys/uvm/uvm_swap.c:1.201
--- src/sys/uvm/uvm_swap.c:1.200	Wed Oct  7 17:51:50 2020
+++ src/sys/uvm/uvm_swap.c	Tue Feb 16 09:56:32 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_swap.c,v 1.200 2020/10/07 17:51:50 chs Exp $	*/
+/*	$NetBSD: uvm_swap.c,v 1.201 2021/02/16 09:56:32 hannken Exp $	*/
 
 /*
  * Copyright (c) 1995, 1996, 1997, 2009 Matthew R. Green
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_swap.c,v 1.200 2020/10/07 17:51:50 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_swap.c,v 1.201 2021/02/16 09:56:32 hannken Exp $");
 
 #include "opt_uvmhist.h"
 #include "opt_compat_netbsd.h"
@@ -1152,27 +1152,23 @@ again:
 			if ((sdp->swd_flags & (SWF_INUSE|SWF_ENABLE)) == 0)
 continue;
 #ifdef DEBUG
-			printf("\nturning off swap on %s...",
-			sdp->swd_path);
+			printf("\nturning off swap on %s...", sdp->swd_path);
 #endif
+			/* Have to lock and reference vnode for swap_off(). */
 			if (vn_lock(vp = sdp->swd_vp, LK_EXCLUSIVE)) {
 error = EBUSY;
-vp = NULL;
-			} else
-error = 0;
-			if (!error) {
+			} else {
+vref(vp);
 error = swap_off(l, sdp);
+vput(vp);
 mutex_enter(_swap_data_lock);
 			}
 			if (error) {
 printf("stopping swap on %s failed "
 "with error %d\n", sdp->swd_path, error);
-TAILQ_REMOVE(>spi_swapdev, sdp,
-swd_next);
+TAILQ_REMOVE(>spi_swapdev, sdp, swd_next);
 uvmexp.nswapdev--;
 swaplist_trim();
-if (vp)
-	vput(vp);
 			}
 			goto again;
 		}



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

2021-02-16 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Tue Feb 16 09:54:17 UTC 2021

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

Log Message:
Use the right uid / gid for nobody:nobody like FreeBSD does.

Prevents null pointer dereferences when ZFS replaces this
illegal (according to IS_EPHEMERAL()) id with another
illegal id in operation zfs_fuid_create_cred() and
finally zfs_log_create() dereferences fuidp being NULL.

Adresses PR misc/55042 (Panic when creating a directory on a NFS served ZFS)


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/sys/zfs_context.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/sys/zfs_context.h
diff -u src/external/cddl/osnet/dist/uts/common/fs/zfs/sys/zfs_context.h:1.2 src/external/cddl/osnet/dist/uts/common/fs/zfs/sys/zfs_context.h:1.3
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/sys/zfs_context.h:1.2	Sat Jun 22 09:48:39 2019
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/sys/zfs_context.h	Tue Feb 16 09:54:17 2021
@@ -157,13 +157,13 @@ extern "C" {
 #define fm_panic			panic
 #define getffd_getfile
 #define getminor(a)			minor(a)
-#define GID_NOBODY			(-2)
+#define GID_NOBODY			(39)
 #define issig(x)			(sigispending(curlwp, 0))
 #define kmem_debugging()		0
 #define releasef			fd_putfile
 #define strfree(str)			kmem_free((str), strlen(str)+1)
 #define td_rul_ru
-#define UID_NOBODY			(-2)
+#define UID_NOBODY			(32767)
 #define vnode_pager_setsize(vp, size)	zfs_netbsd_setsize(vp, size)
 #define zone_get_hostid(a)		0
 



CVS commit: src/sys/coda

2020-11-20 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Fri Nov 20 10:08:47 UTC 2020

Modified Files:
src/sys/coda: coda_vfsops.c

Log Message:
When validating the mount device string make sure its length
is below *data_len and below PATH_MAX.

Reported-by: syzbot+2d3af801141509cc8...@syzkaller.appspotmail.com


To generate a diff of this commit:
cvs rdiff -u -r1.88 -r1.89 src/sys/coda/coda_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/coda/coda_vfsops.c
diff -u src/sys/coda/coda_vfsops.c:1.88 src/sys/coda/coda_vfsops.c:1.89
--- src/sys/coda/coda_vfsops.c:1.88	Sat Nov 14 11:41:29 2020
+++ src/sys/coda/coda_vfsops.c	Fri Nov 20 10:08:47 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: coda_vfsops.c,v 1.88 2020/11/14 11:41:29 hannken Exp $	*/
+/*	$NetBSD: coda_vfsops.c,v 1.89 2020/11/20 10:08:47 hannken Exp $	*/
 
 /*
  *
@@ -45,7 +45,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: coda_vfsops.c,v 1.88 2020/11/14 11:41:29 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: coda_vfsops.c,v 1.89 2020/11/20 10:08:47 hannken Exp $");
 
 #include 
 #include 
@@ -197,7 +197,11 @@ coda_mount(struct mount *vfsp,	/* Alloca
  * fixed default size for the filename buffer.
  */
 /* Ensure that namei() doesn't run off the filename buffer */
-((char *)data)[*data_len - 1] = 0;
+if (*data_len < 1 || *data_len > PATH_MAX ||
+	strnlen(data, *data_len) >= *data_len) {
+	MARK_INT_FAIL(CODA_MOUNT_STATS);
+	return EINVAL;
+}
 error = namei_simple_kernel((char *)data, NSM_FOLLOW_NOEMULROOT,
 		);
 



CVS commit: src/sys/kern

2020-11-19 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Thu Nov 19 10:47:47 UTC 2020

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

Log Message:
We have to ignore interrupts when suspending here the same way
we have to do with revoke.

Reported-by: syzbot+0cfb253b382a98364...@syzkaller.appspotmail.com


To generate a diff of this commit:
cvs rdiff -u -r1.84 -r1.85 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.84 src/sys/kern/vfs_mount.c:1.85
--- src/sys/kern/vfs_mount.c:1.84	Tue Oct 13 13:15:39 2020
+++ src/sys/kern/vfs_mount.c	Thu Nov 19 10:47:47 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_mount.c,v 1.84 2020/10/13 13:15:39 hannken Exp $	*/
+/*	$NetBSD: vfs_mount.c,v 1.85 2020/11/19 10:47:47 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1997-2020 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.84 2020/10/13 13:15:39 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.85 2020/11/19 10:47:47 hannken Exp $");
 
 #include 
 #include 
@@ -730,7 +730,7 @@ mount_domount(struct lwp *l, vnode_t **v
 	struct mount *mp;
 	struct pathbuf *pb;
 	struct nameidata nd;
-	int error;
+	int error, error2;
 
 	error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_MOUNT,
 	KAUTH_REQ_SYSTEM_MOUNT_NEW, vp, KAUTH_ARG(flags), data);
@@ -832,11 +832,16 @@ mount_domount(struct lwp *l, vnode_t **v
 	return error;
 
 err_mounted:
-	if (vfs_suspend(mp, 0))
-		panic("Suspending fresh file system failed");
+	do {
+		error2 = vfs_suspend(mp, 0);
+	} while (error2 == EINTR || error2 == ERESTART);
+	KASSERT(error2 == 0 || error2 == EOPNOTSUPP);
+
 	if (VFS_UNMOUNT(mp, MNT_FORCE) != 0)
 		panic("Unmounting fresh file system failed");
-	vfs_resume(mp);
+
+	if (error2 == 0)
+		vfs_resume(mp);
 
 err_unmounted:
 	vp->v_mountedhere = NULL;



CVS commit: src/libexec/httpd

2020-11-19 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Thu Nov 19 10:45:37 UTC 2020

Modified Files:
src/libexec/httpd: bozohttpd.c

Log Message:
Bozohttpd clobbers files greater than 4GB on 32bit archs.

Make sure the alignment mask derived from pagesize is an off_t.


To generate a diff of this commit:
cvs rdiff -u -r1.123 -r1.124 src/libexec/httpd/bozohttpd.c

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

Modified files:

Index: src/libexec/httpd/bozohttpd.c
diff -u src/libexec/httpd/bozohttpd.c:1.123 src/libexec/httpd/bozohttpd.c:1.124
--- src/libexec/httpd/bozohttpd.c:1.123	Thu Oct 15 04:21:53 2020
+++ src/libexec/httpd/bozohttpd.c	Thu Nov 19 10:45:36 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: bozohttpd.c,v 1.123 2020/10/15 04:21:53 mrg Exp $	*/
+/*	$NetBSD: bozohttpd.c,v 1.124 2020/11/19 10:45:36 hannken Exp $	*/
 
 /*	$eterna: bozohttpd.c,v 1.178 2011/11/18 09:21:15 mrg Exp $	*/
 
@@ -907,7 +907,7 @@ mmap_and_write_part(bozohttpd_t *httpd, 
 	 *
 	 * we use the write offset in all writes
 	 */
-	mappedoffset = first_byte_pos & ~(httpd->page_size - 1);
+	mappedoffset = first_byte_pos & ~((off_t)httpd->page_size - 1);
 	mappedsz = (size_t)
 		(first_byte_pos - mappedoffset + sz + httpd->page_size - 1) &
 		~(httpd->page_size - 1);



CVS commit: src/sys/arch/amd64/include

2020-11-18 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed Nov 18 16:13:34 UTC 2020

Modified Files:
src/sys/arch/amd64/include: msan.h

Log Message:
Make this at least compile.
Looks like a missing part from "Round of uvm.h cleanup (2020-09-05 18:30)".


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/amd64/include/msan.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/arch/amd64/include/msan.h
diff -u src/sys/arch/amd64/include/msan.h:1.5 src/sys/arch/amd64/include/msan.h:1.6
--- src/sys/arch/amd64/include/msan.h:1.5	Wed Sep  9 16:29:59 2020
+++ src/sys/arch/amd64/include/msan.h	Wed Nov 18 16:13:34 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: msan.h,v 1.5 2020/09/09 16:29:59 maxv Exp $	*/
+/*	$NetBSD: msan.h,v 1.6 2020/11/18 16:13:34 hannken Exp $	*/
 
 /*
  * Copyright (c) 2019-2020 Maxime Villard, m00nbsd.net
@@ -30,6 +30,8 @@
 
 #include 
 
+#include 
+
 #include 
 #include 
 



CVS commit: src/sys/coda

2020-11-14 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sat Nov 14 11:42:05 UTC 2020

Modified Files:
src/sys/coda: coda_vnops.c coda_vnops.h

Log Message:
Add coda_pathconf() always returning EINVAL.


To generate a diff of this commit:
cvs rdiff -u -r1.112 -r1.113 src/sys/coda/coda_vnops.c
cvs rdiff -u -r1.16 -r1.17 src/sys/coda/coda_vnops.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/coda/coda_vnops.c
diff -u src/sys/coda/coda_vnops.c:1.112 src/sys/coda/coda_vnops.c:1.113
--- src/sys/coda/coda_vnops.c:1.112	Sat May 16 18:31:48 2020
+++ src/sys/coda/coda_vnops.c	Sat Nov 14 11:42:05 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: coda_vnops.c,v 1.112 2020/05/16 18:31:48 christos Exp $	*/
+/*	$NetBSD: coda_vnops.c,v 1.113 2020/11/14 11:42:05 hannken Exp $	*/
 
 /*
  *
@@ -46,7 +46,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: coda_vnops.c,v 1.112 2020/05/16 18:31:48 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: coda_vnops.c,v 1.113 2020/11/14 11:42:05 hannken Exp $");
 
 #include 
 #include 
@@ -134,7 +134,7 @@ const struct vnodeopv_entry_desc coda_vn
 { _strategy_desc, coda_strategy },	/* strategy */
 { _print_desc, coda_vop_error },	/* print */
 { _islocked_desc, coda_islocked },	/* islocked */
-{ _pathconf_desc, coda_vop_error },	/* pathconf */
+{ _pathconf_desc, coda_pathconf },	/* pathconf */
 { _advlock_desc, coda_vop_nop },	/* advlock */
 { _bwrite_desc, coda_vop_error },	/* bwrite */
 { _seek_desc, genfs_seek },		/* seek */
@@ -1739,6 +1739,18 @@ coda_islocked(void *v)
 return genfs_islocked(v);
 }
 
+int
+coda_pathconf(void *v)
+{
+	struct vop_pathconf_args *ap = v;
+
+	switch (ap->a_name) {
+	default:
+		return EINVAL;
+	}
+	/* NOTREACHED */
+}
+
 /*
  * Given a device and inode, obtain a locked vnode.  One reference is
  * obtained and passed back to the caller.

Index: src/sys/coda/coda_vnops.h
diff -u src/sys/coda/coda_vnops.h:1.16 src/sys/coda/coda_vnops.h:1.17
--- src/sys/coda/coda_vnops.h:1.16	Thu Aug  2 16:06:59 2012
+++ src/sys/coda/coda_vnops.h	Sat Nov 14 11:42:05 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: coda_vnops.h,v 1.16 2012/08/02 16:06:59 christos Exp $	*/
+/*	$NetBSD: coda_vnops.h,v 1.17 2020/11/14 11:42:05 hannken Exp $	*/
 
 /*
  *
@@ -74,6 +74,7 @@ int coda_reclaim(void *);
 int coda_lock(void *);
 int coda_unlock(void *);
 int coda_islocked(void *);
+int coda_pathconf(void *);
 int coda_vop_error(void *);
 int coda_vop_nop(void *);
 int coda_getpages(void *);



CVS commit: src/sys/coda

2020-11-14 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sat Nov 14 11:42:56 UTC 2020

Modified Files:
src/sys/coda: coda.h coda_vnops.c

Log Message:
Rewrite coda_readdir() to directly process the container file.

Passing this operation down to the file system holding the container
cannot work for anything but UFS and UFS doesn't allow reading
directory from a plain file since ~2015.

Fixes PR kern/55775 Coda client, its in-kernel part, opens wrong files ...


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/coda/coda.h
cvs rdiff -u -r1.113 -r1.114 src/sys/coda/coda_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/coda/coda.h
diff -u src/sys/coda/coda.h:1.20 src/sys/coda/coda.h:1.21
--- src/sys/coda/coda.h:1.20	Thu Apr 19 21:50:07 2018
+++ src/sys/coda/coda.h	Sat Nov 14 11:42:56 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: coda.h,v 1.20 2018/04/19 21:50:07 christos Exp $ */
+/* $NetBSD: coda.h,v 1.21 2020/11/14 11:42:56 hannken Exp $ */
 
 /*
 
@@ -61,6 +61,10 @@ Mellon the rights to redistribute these 
 #define CODA_MAXSYMLINKS 10
 #endif
 
+#ifndef CODA_DIRBLKSIZ
+#define CODA_DIRBLKSIZ 0x1000
+#endif
+
 #if defined(DJGPP) || defined(__CYGWIN32__)
 #ifdef KERNEL
 typedef unsigned long u_long;
@@ -169,7 +173,7 @@ struct venus_dirent {
 #ifndef _VENUS_DIRENT_T_
 #define _VENUS_DIRENT_T_ 1
 struct venus_dirent {
-unsigned long	d_fileno;		/* file number of entry */
+unsigned int	d_fileno;		/* file number of entry */
 unsigned short	d_reclen;		/* length of this record */
 unsigned char 	d_type;			/* file type, see below */
 unsigned char	d_namlen;		/* length of string in d_name */

Index: src/sys/coda/coda_vnops.c
diff -u src/sys/coda/coda_vnops.c:1.113 src/sys/coda/coda_vnops.c:1.114
--- src/sys/coda/coda_vnops.c:1.113	Sat Nov 14 11:42:05 2020
+++ src/sys/coda/coda_vnops.c	Sat Nov 14 11:42:56 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: coda_vnops.c,v 1.113 2020/11/14 11:42:05 hannken Exp $	*/
+/*	$NetBSD: coda_vnops.c,v 1.114 2020/11/14 11:42:56 hannken Exp $	*/
 
 /*
  *
@@ -46,7 +46,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: coda_vnops.c,v 1.113 2020/11/14 11:42:05 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: coda_vnops.c,v 1.114 2020/11/14 11:42:56 hannken Exp $");
 
 #include 
 #include 
@@ -62,6 +62,7 @@ __KERNEL_RCSID(0, "$NetBSD: coda_vnops.c
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -1528,70 +1529,143 @@ int
 coda_readdir(void *v)
 {
 /* true args */
-struct vop_readdir_args *ap = v;
-vnode_t *vp = ap->a_vp;
-struct cnode *cp = VTOC(vp);
-struct uio *uiop = ap->a_uio;
-kauth_cred_t cred = ap->a_cred;
-int *eofflag = ap->a_eofflag;
-off_t **cookies = ap->a_cookies;
-int *ncookies = ap->a_ncookies;
+	struct vop_readdir_args *ap = v;
+	vnode_t *vp = ap->a_vp;
+	struct cnode *cp = VTOC(vp);
+	struct uio *uiop = ap->a_uio;
+	kauth_cred_t cred = ap->a_cred;
+	int *eofflag = ap->a_eofflag;
 /* upcall decl */
 /* locals */
-int error = 0;
-enum vtype saved_type;
-
-MARK_ENTRY(CODA_READDIR_STATS);
-
-CODADEBUG(CODA_READDIR, myprintf(("%s: (%p, %lu, %lld)\n", __func__,
-	uiop->uio_iov->iov_base, (unsigned long) uiop->uio_resid,
-	(long long) uiop->uio_offset)); )
-
-/* Check for readdir of control object. */
-if (IS_CTL_VP(vp)) {
-	MARK_INT_FAIL(CODA_READDIR_STATS);
-	return(ENOENT);
-}
+	size_t initial_resid = uiop->uio_resid;
+	int error = 0;
+	int opened_internally = 0;
+	int ncookies;
+	char *buf;
+	struct vnode *cvp;
+	struct dirent *dirp;
+
+	MARK_ENTRY(CODA_READDIR_STATS);
+
+	CODADEBUG(CODA_READDIR, myprintf(("%s: (%p, %lu, %lld)\n", __func__,
+	uiop->uio_iov->iov_base, (unsigned long) uiop->uio_resid,
+	(long long) uiop->uio_offset)); )
 
-{
-	/* Redirect the request to UFS. */
+	/* Check for readdir of control object. */
+	if (IS_CTL_VP(vp)) {
+		MARK_INT_FAIL(CODA_READDIR_STATS);
+		return ENOENT;
+	}
 
 	/* If directory is not already open do an "internal open" on it. */
-	int opened_internally = 0;
 	if (cp->c_ovp == NULL) {
-	opened_internally = 1;
-	MARK_INT_GEN(CODA_OPEN_STATS);
-	error = VOP_OPEN(vp, FREAD, cred);
+		opened_internally = 1;
+		MARK_INT_GEN(CODA_OPEN_STATS);
+		error = VOP_OPEN(vp, FREAD, cred);
 #ifdef	CODA_VERBOSE
-	printf("%s: Internally Opening %p\n", __func__, vp);
+		printf("%s: Internally Opening %p\n", __func__, vp);
 #endif
-	if (error) return(error);
-	} else
-	vp = cp->c_ovp;
+		if (error)
+			return error;
+		KASSERT(cp->c_ovp != NULL);
+	}
+	cvp = cp->c_ovp;
 
-	/* Have UFS handle the call. */
 	CODADEBUG(CODA_READDIR, myprintf(("%s: fid = %s, refcnt = %d\n",
-	__func__, coda_f2s(>c_fid), vrefcnt(vp))); )
-	saved_type = vp->v_type;
-	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
-	vp->v_type = VDIR; /* pretend the container file is a dir */
-	error = VOP_READDIR(vp, uiop, cred, 

CVS commit: src/sys/coda

2020-11-14 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sat Nov 14 11:41:29 UTC 2020

Modified Files:
src/sys/coda: coda_vfsops.c

Log Message:
Respect "lktype" in all paths in coda_root().


To generate a diff of this commit:
cvs rdiff -u -r1.87 -r1.88 src/sys/coda/coda_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/coda/coda_vfsops.c
diff -u src/sys/coda/coda_vfsops.c:1.87 src/sys/coda/coda_vfsops.c:1.88
--- src/sys/coda/coda_vfsops.c:1.87	Fri Jan 17 20:08:06 2020
+++ src/sys/coda/coda_vfsops.c	Sat Nov 14 11:41:29 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: coda_vfsops.c,v 1.87 2020/01/17 20:08:06 ad Exp $	*/
+/*	$NetBSD: coda_vfsops.c,v 1.88 2020/11/14 11:41:29 hannken Exp $	*/
 
 /*
  *
@@ -45,7 +45,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: coda_vfsops.c,v 1.87 2020/01/17 20:08:06 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: coda_vfsops.c,v 1.88 2020/11/14 11:41:29 hannken Exp $");
 
 #include 
 #include 
@@ -388,7 +388,7 @@ coda_root(struct mount *vfsp, int lktype
 
 	*vpp = mi->mi_rootvp;
 	vref(*vpp);
-	vn_lock(*vpp, LK_EXCLUSIVE);
+	vn_lock(*vpp, lktype);
 	MARK_INT_SAT(CODA_ROOT_STATS);
 	goto exit;
 } else if (error == ENODEV || error == EINTR) {
@@ -403,7 +403,7 @@ coda_root(struct mount *vfsp, int lktype
 	 */
 	*vpp = mi->mi_rootvp;
 	vref(*vpp);
-	vn_lock(*vpp, LK_EXCLUSIVE);
+	vn_lock(*vpp, lktype);
 	MARK_INT_FAIL(CODA_ROOT_STATS);
 	error = 0;
 	goto exit;



CVS commit: src/sys/kern

2020-10-13 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Tue Oct 13 13:15:39 UTC 2020

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

Log Message:
Suspend file system before unmounting in mount_domount() error path
to prevent diagnostic assertions from unmount/flush.

Reported-by: syzbot+8d557f49c8b788818...@syzkaller.appspotmail.com
Reported-by: syzbot+e87fe1e769a3426d9...@syzkaller.appspotmail.com
Reported-by: syzbot+9c5b86e651e98c5bf...@syzkaller.appspotmail.com
Reported-by: syzbot+610b614af0d66179c...@syzkaller.appspotmail.com
Reported-by: syzbot+7818ff113a1535ebc...@syzkaller.appspotmail.com


To generate a diff of this commit:
cvs rdiff -u -r1.83 -r1.84 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.83 src/sys/kern/vfs_mount.c:1.84
--- src/sys/kern/vfs_mount.c:1.83	Sat May 23 23:42:43 2020
+++ src/sys/kern/vfs_mount.c	Tue Oct 13 13:15:39 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_mount.c,v 1.83 2020/05/23 23:42:43 ad Exp $	*/
+/*	$NetBSD: vfs_mount.c,v 1.84 2020/10/13 13:15:39 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1997-2020 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.83 2020/05/23 23:42:43 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.84 2020/10/13 13:15:39 hannken Exp $");
 
 #include 
 #include 
@@ -832,8 +832,11 @@ mount_domount(struct lwp *l, vnode_t **v
 	return error;
 
 err_mounted:
+	if (vfs_suspend(mp, 0))
+		panic("Suspending fresh file system failed");
 	if (VFS_UNMOUNT(mp, MNT_FORCE) != 0)
 		panic("Unmounting fresh file system failed");
+	vfs_resume(mp);
 
 err_unmounted:
 	vp->v_mountedhere = NULL;



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

2020-10-12 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Mon Oct 12 08:21:21 UTC 2020

Modified Files:
src/external/cddl/osnet/sys/sys: cred.h

Log Message:
Stub groupmember() has to test both group list and current group id.

Fixes kern/55675: ZFS mounts do not work with setuid programs


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/external/cddl/osnet/sys/sys/cred.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/sys/sys/cred.h
diff -u src/external/cddl/osnet/sys/sys/cred.h:1.7 src/external/cddl/osnet/sys/sys/cred.h:1.8
--- src/external/cddl/osnet/sys/sys/cred.h:1.7	Wed Apr 29 05:54:37 2020
+++ src/external/cddl/osnet/sys/sys/cred.h	Mon Oct 12 08:21:21 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cred.h,v 1.7 2020/04/29 05:54:37 riastradh Exp $	*/
+/*	$NetBSD: cred.h,v 1.8 2020/10/12 08:21:21 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2007 Pawel Jakub Dawidek 
@@ -70,10 +70,12 @@ extern kauth_cred_t	cred0;
 static __inline int
 groupmember(gid_t gid, cred_t *cr) 
 {
-	int result;
+	int result, error;
 
-	kauth_cred_ismember_gid(cr, gid, );
-	return result;
+	error = kauth_cred_ismember_gid(cr, gid, );
+	if (error)
+		return 0;
+	return (kauth_cred_getegid(cr) == gid || result);
 }
 
 #endif	/* _KERNEL */



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

2020-08-28 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Fri Aug 28 16:13:48 UTC 2020

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

Log Message:
Glue operation secpolicy_fs_mount() passes wrong arguments to
operation kauth_authorize_system().

KAUTH_SYSTEM_MOUNT / KAUTH_REQ_SYSTEM_MOUNT_NEW wants the to be
covered vnode and the mount flags, not the mount structure.

Fix for PR kern/55602: zpool panic on mounting zfs filesystem


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/external/cddl/osnet/sys/kern/policy.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/policy.c
diff -u src/external/cddl/osnet/sys/kern/policy.c:1.8 src/external/cddl/osnet/sys/kern/policy.c:1.9
--- src/external/cddl/osnet/sys/kern/policy.c:1.8	Sat May 16 18:31:46 2020
+++ src/external/cddl/osnet/sys/kern/policy.c	Fri Aug 28 16:13:48 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: policy.c,v 1.8 2020/05/16 18:31:46 christos Exp $	*/
+/*	$NetBSD: policy.c,v 1.9 2020/08/28 16:13:48 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -119,7 +119,7 @@ secpolicy_fs_mount(cred_t *cred, vnode_t
 {
 
 	return kauth_authorize_system(cred, KAUTH_SYSTEM_MOUNT,
-	KAUTH_REQ_SYSTEM_MOUNT_NEW, vfsp, NULL, NULL);
+	KAUTH_REQ_SYSTEM_MOUNT_NEW, mvp, KAUTH_ARG(vfsp->mnt_flag), NULL);
 }
 
 int



CVS commit: src/share/man/man9

2020-08-28 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Fri Aug 28 07:29:00 UTC 2020

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

Log Message:
Another typo -- its vfs_newvnode().


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/share/man/man9/vfsops.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/vfsops.9
diff -u src/share/man/man9/vfsops.9:1.52 src/share/man/man9/vfsops.9:1.53
--- src/share/man/man9/vfsops.9:1.52	Thu Aug 27 14:14:00 2020
+++ src/share/man/man9/vfsops.9	Fri Aug 28 07:28:59 2020
@@ -1,4 +1,4 @@
-.\" $NetBSD: vfsops.9,v 1.52 2020/08/27 14:14:00 fcambus Exp $
+.\" $NetBSD: vfsops.9,v 1.53 2020/08/28 07:28:59 hannken Exp $
 .\"
 .\" Copyright (c) 2001 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -142,7 +142,7 @@ Ta Get vnode from file id
 Ta Dv VFS_LOADVNODE \
 Ta Initialize vnode with file
 .\"
-.It int (*vfs_loadvnode)() \
+.It int (*vfs_newvnode)() \
 Ta Dv VFS_NEWVNODE \
 Ta Initialize vnode with new file
 .\"



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

2020-08-27 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Thu Aug 27 09:57:34 UTC 2020

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

Log Message:
Enable NCLOOKUP for ZFS.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vfsops.c
cvs rdiff -u -r1.69 -r1.70 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c
cvs rdiff -u -r1.33 -r1.34 \
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_vfsops.c
diff -u src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vfsops.c:1.28 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vfsops.c:1.29
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vfsops.c:1.28	Tue May 26 08:39:27 2020
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vfsops.c	Thu Aug 27 09:57:33 2020
@@ -1517,7 +1517,7 @@ zfs_domount(vfs_t *vfsp, char *osname)
 #endif
 #ifdef __NetBSD__
 	vfsp->mnt_flag |= MNT_LOCAL;
-	vfsp->mnt_iflag |= IMNT_MPSAFE;
+	vfsp->mnt_iflag |= IMNT_MPSAFE | IMNT_NCLOOKUP;
 #endif
 
 	/*
@@ -2078,7 +2078,7 @@ zfs_mount(vfs_t *vfsp, const char *path,
 	vfsp->vfs_flag |= MNT_NFS4ACLS;
 #endif
 #ifdef __NetBSD__
-	vfsp->mnt_iflag |= IMNT_MPSAFE;
+	vfsp->mnt_iflag |= IMNT_MPSAFE | IMNT_NCLOOKUP;
 #endif
 
 	/*

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.69 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.70
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.69	Thu May 21 20:43:23 2020
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c	Thu Aug 27 09:57:33 2020
@@ -1354,6 +1354,10 @@ zfs_write(vnode_t *vp, uio_t *uio, int i
 			newmode = zp->z_mode;
 			(void) sa_update(zp->z_sa_hdl, SA_ZPL_MODE(zfsvfs),
 			(void *), sizeof (uint64_t), tx);
+#ifdef __NetBSD__
+			cache_enter_id(vp, zp->z_mode, zp->z_uid, zp->z_gid,
+			true);
+#endif
 		}
 		mutex_exit(>z_acl_lock);
 
@@ -5645,8 +5649,11 @@ zfs_netbsd_setattr(void *v)
 	}
 
 	error = zfs_setattr(vp, (vattr_t *), flags, cred, NULL);
-	if (error == 0)
-		VN_KNOTE(vp, NOTE_ATTRIB);
+	if (error)
+		return error;
+
+	VN_KNOTE(vp, NOTE_ATTRIB);
+	cache_enter_id(vp, zp->z_mode, zp->z_uid, zp->z_gid, true);
 
 	return error;
 }

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.33 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c:1.34
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c:1.33	Thu May  7 09:13:06 2020
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c	Thu Aug 27 09:57:33 2020
@@ -871,6 +871,7 @@ zfs_loadvnode(struct mount *mp, struct v
 		return (SET_ERROR(ENOENT));
 	}
 	ASSERT(zp == VTOZ(vp));
+	cache_enter_id(vp, zp->z_mode, zp->z_uid, zp->z_gid, true);
 
 	ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
 
@@ -891,6 +892,8 @@ zfs_newvnode(struct mount *mp, vnode_t *
 
 	zfs_mknode1(dzp, vap, tx, cr, flag, , acl_ids, vp);
 	ASSERT(zp == VTOZ(vp));
+	cache_enter_id(vp, zp->z_mode, zp->z_uid, zp->z_gid, true);
+
 	*key_len = sizeof(zp->z_id);
 	*new_key = >z_id;
 



CVS commit: src/sys/fs/union

2020-08-18 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Tue Aug 18 09:44:07 UTC 2020

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

Log Message:
Operation union_readdirhook() stores the lower directory as un_uppervp.
This breaks the assumption that un_uppervp->v_mount is the upper mount.

Fix by storing the directory as un_lowervp and adapt union_readdir().

Should fix PR kern/2: panic with union mount


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/fs/union/union.h
cvs rdiff -u -r1.78 -r1.79 src/sys/fs/union/union_subr.c
cvs rdiff -u -r1.73 -r1.74 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.h
diff -u src/sys/fs/union/union.h:1.29 src/sys/fs/union/union.h:1.30
--- src/sys/fs/union/union.h:1.29	Mon Jul 17 09:22:36 2017
+++ src/sys/fs/union/union.h	Tue Aug 18 09:44:07 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: union.h,v 1.29 2017/07/17 09:22:36 hannken Exp $	*/
+/*	$NetBSD: union.h,v 1.30 2020/08/18 09:44:07 hannken Exp $	*/
 
 /*
  * Copyright (c) 1994 The Regents of the University of California.
@@ -130,6 +130,7 @@ struct union_node {
 	char			*un_path;	/* v: saved component name */
 	int			un_openl;	/* v: # of opens on lowervp */
 	unsigned int		un_cflags;	/* c: cache flags */
+	bool			un_hooknode;	/* :: from union_readdirhook */
 	struct vnode		**un_dircache;	/* v: cached union stack */
 	off_t			un_uppersz;	/* l: size of upper object */
 	off_t			un_lowersz;	/* l: size of lower object */

Index: src/sys/fs/union/union_subr.c
diff -u src/sys/fs/union/union_subr.c:1.78 src/sys/fs/union/union_subr.c:1.79
--- src/sys/fs/union/union_subr.c:1.78	Sun Feb 23 15:46:41 2020
+++ src/sys/fs/union/union_subr.c	Tue Aug 18 09:44:07 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: union_subr.c,v 1.78 2020/02/23 15:46:41 ad Exp $	*/
+/*	$NetBSD: union_subr.c,v 1.79 2020/08/18 09:44:07 hannken Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -72,7 +72,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: union_subr.c,v 1.78 2020/02/23 15:46:41 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: union_subr.c,v 1.79 2020/08/18 09:44:07 hannken Exp $");
 
 #include 
 #include 
@@ -480,6 +480,7 @@ found:
 	un->un_dircache = 0;
 	un->un_openl = 0;
 	un->un_cflags = 0;
+	un->un_hooknode = false;
 
 	un->un_uppersz = VNOVAL;
 	un->un_lowersz = VNOVAL;
@@ -1067,7 +1068,7 @@ union_dircache(struct vnode *vp, struct 
 	} else {
 		vpp = dircache;
 		do {
-			if (*vpp++ == VTOUNION(vp)->un_uppervp)
+			if (*vpp++ == VTOUNION(vp)->un_lowervp)
 break;
 		} while (*vpp != NULLVP);
 	}
@@ -1076,10 +1077,12 @@ union_dircache(struct vnode *vp, struct 
 		goto out;
 
 	vref(*vpp);
-	error = union_allocvp(, vp->v_mount, NULLVP, NULLVP, 0, *vpp, NULLVP, 0);
+	error = union_allocvp(, vp->v_mount, NULLVP, NULLVP, 0,
+	NULLVP, *vpp, 0);
 	if (!error) {
 		vn_lock(nvp, LK_EXCLUSIVE | LK_RETRY);
 		VTOUNION(vp)->un_dircache = 0;
+		VTOUNION(nvp)->un_hooknode = true;
 		VTOUNION(nvp)->un_dircache = dircache;
 	}
 

Index: src/sys/fs/union/union_vnops.c
diff -u src/sys/fs/union/union_vnops.c:1.73 src/sys/fs/union/union_vnops.c:1.74
--- src/sys/fs/union/union_vnops.c:1.73	Sat May 16 18:31:50 2020
+++ src/sys/fs/union/union_vnops.c	Tue Aug 18 09:44:07 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: union_vnops.c,v 1.73 2020/05/16 18:31:50 christos Exp $	*/
+/*	$NetBSD: union_vnops.c,v 1.74 2020/08/18 09:44:07 hannken Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993, 1994, 1995
@@ -72,7 +72,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: union_vnops.c,v 1.73 2020/05/16 18:31:50 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: union_vnops.c,v 1.74 2020/08/18 09:44:07 hannken Exp $");
 
 #include 
 #include 
@@ -1493,13 +1493,29 @@ union_readdir(void *v)
 		int a_ncookies;
 	} */ *ap = v;
 	struct union_node *un = VTOUNION(ap->a_vp);
-	struct vnode *uvp = un->un_uppervp;
+	struct vnode *vp;
+	int dolock, error;
 
-	if (uvp == NULLVP)
-		return (0);
+	if (un->un_hooknode) {
+		KASSERT(un->un_uppervp == NULLVP);
+		KASSERT(un->un_lowervp != NULLVP);
+		vp = un->un_lowervp;
+		dolock = 1;
+	} else {
+		vp = un->un_uppervp;
+		dolock = 0;
+	}
+	if (vp == NULLVP)
+		return 0;
 
-	ap->a_vp = uvp;
-	return (VCALL(uvp, VOFFSET(vop_readdir), ap));
+	if (dolock)
+		vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
+	ap->a_vp = vp;
+	error = VCALL(vp, VOFFSET(vop_readdir), ap);
+	if (dolock)
+		VOP_UNLOCK(vp);
+
+	return error;
 }
 
 int



CVS commit: src/external/cddl/osnet

2020-05-26 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Tue May 26 08:39:27 UTC 2020

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

Log Message:
Replace vp->v_count with vrefcnt(vp) and
remove now unneeded "#define v_count ...".


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vfsops.c
cvs rdiff -u -r1.16 -r1.17 src/external/cddl/osnet/sys/sys/vnode.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_vfsops.c
diff -u src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vfsops.c:1.27 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vfsops.c:1.28
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vfsops.c:1.27	Mon Apr 13 19:23:17 2020
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vfsops.c	Tue May 26 08:39:27 2020
@@ -2311,7 +2311,11 @@ zfsvfs_teardown(zfsvfs_t *zfsvfs, boolea
 	for (zp = list_head(>z_all_znodes); zp != NULL;
 	zp = list_next(>z_all_znodes, zp))
 		if (zp->z_sa_hdl) {
+#ifdef __NetBSD__
+			ASSERT(vrefcnt(ZTOV(zp)) >= 0);
+#else
 			ASSERT(ZTOV(zp)->v_count >= 0);
+#endif
 			zfs_znode_dmu_fini(zp);
 		}
 	mutex_exit(>z_znodes_lock);

Index: src/external/cddl/osnet/sys/sys/vnode.h
diff -u src/external/cddl/osnet/sys/sys/vnode.h:1.16 src/external/cddl/osnet/sys/sys/vnode.h:1.17
--- src/external/cddl/osnet/sys/sys/vnode.h:1.16	Mon Apr 13 19:23:17 2020
+++ src/external/cddl/osnet/sys/sys/vnode.h	Tue May 26 08:39:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: vnode.h,v 1.16 2020/04/13 19:23:17 ad Exp $	*/
+/*	$NetBSD: vnode.h,v 1.17 2020/05/26 08:39:27 hannken Exp $	*/
 
 /*
  * CDDL HEADER START
@@ -135,7 +135,6 @@ typedef int (**vnodeops_t)(void *);
 #define	vop_fid_args	vop_vptofh_args
 #define	a_fid		a_fhp
 
-#define	v_count		v_usecount
 #define	v_object	v_uobj
 
 struct vop_vptofh_args {



CVS commit: src/sys

2020-05-24 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sun May 24 10:42:28 UTC 2020

Modified Files:
src/sys/arch/atari/dev: event_var.h
src/sys/dev/sun: event_var.h

Log Message:
Change proc_lock -> _lock.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/atari/dev/event_var.h
cvs rdiff -u -r1.13 -r1.14 src/sys/dev/sun/event_var.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/arch/atari/dev/event_var.h
diff -u src/sys/arch/atari/dev/event_var.h:1.9 src/sys/arch/atari/dev/event_var.h:1.10
--- src/sys/arch/atari/dev/event_var.h:1.9	Sat Mar 29 16:46:19 2014
+++ src/sys/arch/atari/dev/event_var.h	Sun May 24 10:42:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: event_var.h,v 1.9 2014/03/29 16:46:19 tsutsui Exp $	*/
+/*	$NetBSD: event_var.h,v 1.10 2020/05/24 10:42:27 hannken Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -70,9 +70,9 @@ struct evvar {
 		wakeup((void *)(ev)); \
 	} \
 	if ((ev)->ev_async) { \
-		mutex_enter(proc_lock); \
+		mutex_enter(_lock); \
 		psignal((ev)->ev_io, SIGIO); \
-		mutex_exit(proc_lock); \
+		mutex_exit(_lock); \
 	} \
 }
 

Index: src/sys/dev/sun/event_var.h
diff -u src/sys/dev/sun/event_var.h:1.13 src/sys/dev/sun/event_var.h:1.14
--- src/sys/dev/sun/event_var.h:1.13	Thu Apr 24 15:35:28 2008
+++ src/sys/dev/sun/event_var.h	Sun May 24 10:42:28 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: event_var.h,v 1.13 2008/04/24 15:35:28 ad Exp $	*/
+/*	$NetBSD: event_var.h,v 1.14 2020/05/24 10:42:28 hannken Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -69,9 +69,9 @@ struct evvar {
 		wakeup((void *)(ev)); \
 	} \
 	if ((ev)->ev_async) { \
-		mutex_enter(proc_lock); \
+		mutex_enter(_lock); \
 		psignal((ev)->ev_io, SIGIO); \
-		mutex_exit(proc_lock); \
+		mutex_exit(_lock); \
 	} \
 }
 



CVS commit: src/sys/uvm

2020-05-20 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed May 20 12:47:36 UTC 2020

Modified Files:
src/sys/uvm: uvm_aobj.c

Log Message:
Suppress GCC warnings and fix a UVMHIST_LOG() statement.

Kernels ALL/amd64 and ALL/i386 and port sparc64 build again.


To generate a diff of this commit:
cvs rdiff -u -r1.142 -r1.143 src/sys/uvm/uvm_aobj.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/uvm/uvm_aobj.c
diff -u src/sys/uvm/uvm_aobj.c:1.142 src/sys/uvm/uvm_aobj.c:1.143
--- src/sys/uvm/uvm_aobj.c:1.142	Tue May 19 22:22:15 2020
+++ src/sys/uvm/uvm_aobj.c	Wed May 20 12:47:36 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_aobj.c,v 1.142 2020/05/19 22:22:15 ad Exp $	*/
+/*	$NetBSD: uvm_aobj.c,v 1.143 2020/05/20 12:47:36 hannken Exp $	*/
 
 /*
  * Copyright (c) 1998 Chuck Silvers, Charles D. Cranor and
@@ -38,7 +38,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_aobj.c,v 1.142 2020/05/19 22:22:15 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_aobj.c,v 1.143 2020/05/20 12:47:36 hannken Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_uvmhist.h"
@@ -802,7 +802,7 @@ uao_get(struct uvm_object *uobj, voff_t 
 {
 	voff_t current_offset;
 	struct vm_page *ptmp = NULL;	/* Quell compiler warning */
-	int lcv, gotpages, maxpages, swslot, pageidx;
+	int lcv, gotpages, maxpages, swslot = -1, pageidx = -1; /* XXX: gcc */
 	UVMHIST_FUNC("uao_get"); UVMHIST_CALLED(pdhist);
 
 	UVMHIST_LOG(pdhist, "aobj=%#jx offset=%jd, flags=%jd",
@@ -876,7 +876,8 @@ uao_get(struct uvm_object *uobj, voff_t 
 		 * to unlock and do some waiting or I/O.
  		 */
 
-		UVMHIST_LOG(pdhist, "<- done (done=%jd)", done, 0,0,0);
+		UVMHIST_LOG(pdhist, "<- done (done=%jd)",
+		(pps[centeridx] != NULL), 0,0,0);
 		*npagesp = gotpages;
 		return pps[centeridx] != NULL ? 0 : EBUSY;
 	}



CVS commit: src/sys/kern

2020-05-18 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Mon May 18 08:29:34 UTC 2020

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

Log Message:
VOP_STRATEGY() may still deadlock with devices.

Change FSTRANS from LAZY to NO.


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 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.79 src/sys/kern/vnode_if.src:1.80
--- src/sys/kern/vnode_if.src:1.79	Sat May 16 18:31:50 2020
+++ src/sys/kern/vnode_if.src	Mon May 18 08:29:34 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: vnode_if.src,v 1.79 2020/05/16 18:31:50 christos Exp $
+#	$NetBSD: vnode_if.src,v 1.80 2020/05/18 08:29:34 hannken Exp $
 #
 # Copyright (c) 1992, 1993
 #	The Regents of the University of California.  All rights reserved.
@@ -445,7 +445,7 @@ vop_bmap {
 #% strategy   vp  = = =
 #
 vop_strategy {
-	FSTRANS=LAZY
+	FSTRANS=NO
 	IN struct vnode *vp;
 	IN struct buf *bp;
 };



CVS commit: src/sys/kern

2020-05-18 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Mon May 18 08:30:06 UTC 2020

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

Log Message:
Regen.


To generate a diff of this commit:
cvs rdiff -u -r1.111 -r1.112 src/sys/kern/vnode_if.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/vnode_if.c
diff -u src/sys/kern/vnode_if.c:1.111 src/sys/kern/vnode_if.c:1.112
--- src/sys/kern/vnode_if.c:1.111	Sat May 16 18:31:50 2020
+++ src/sys/kern/vnode_if.c	Mon May 18 08:30:06 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: vnode_if.c,v 1.111 2020/05/16 18:31:50 christos Exp $	*/
+/*	$NetBSD: vnode_if.c,v 1.112 2020/05/18 08:30:06 hannken Exp $	*/
 
 /*
  * Warning: DO NOT EDIT! This file is automatically generated!
@@ -40,7 +40,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vnode_if.c,v 1.111 2020/05/16 18:31:50 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vnode_if.c,v 1.112 2020/05/18 08:30:06 hannken Exp $");
 
 #include 
 #include 
@@ -1414,11 +1414,11 @@ VOP_STRATEGY(struct vnode *vp,
 	a.a_desc = VDESC(vop_strategy);
 	a.a_vp = vp;
 	a.a_bp = bp;
-	error = vop_pre(vp, , , FST_LAZY);
+	error = vop_pre(vp, , , FST_NO);
 	if (error)
 		return error;
 	error = (VCALL(vp, VOFFSET(vop_strategy), ));
-	vop_post(vp, mp, mpsafe, FST_LAZY);
+	vop_post(vp, mp, mpsafe, FST_NO);
 	return error;
 }
 



CVS commit: src/sys/ufs

2020-05-18 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Mon May 18 08:28:44 UTC 2020

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

Log Message:
Assert ufs_strategy() always gets used while current thread
holds a fstrans lock.


To generate a diff of this commit:
cvs rdiff -u -r1.369 -r1.370 src/sys/ufs/ffs/ffs_vfsops.c
cvs rdiff -u -r1.254 -r1.255 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/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.369 src/sys/ufs/ffs/ffs_vfsops.c:1.370
--- src/sys/ufs/ffs/ffs_vfsops.c:1.369	Sat May 16 18:31:53 2020
+++ src/sys/ufs/ffs/ffs_vfsops.c	Mon May 18 08:28:44 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.369 2020/05/16 18:31:53 christos Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.370 2020/05/18 08:28:44 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.369 2020/05/16 18:31:53 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.370 2020/05/18 08:28:44 hannken Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -75,6 +75,7 @@ __KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -581,7 +582,12 @@ ffs_mount(struct mount *mp, const char *
 			DPRINTF("VOP_OPEN returned %d", error);
 			goto fail;
 		}
+		/* Need fstrans_start() for assertion in ufs_strategy(). */
+		if ((mp->mnt_flag & MNT_RDONLY) == 0)
+			fstrans_start(mp);
 		error = ffs_mountfs(devvp, mp, l);
+		if ((mp->mnt_flag & MNT_RDONLY) == 0)
+			fstrans_done(mp);
 		if (error) {
 			DPRINTF("ffs_mountfs returned %d", error);
 			vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);

Index: src/sys/ufs/ufs/ufs_vnops.c
diff -u src/sys/ufs/ufs/ufs_vnops.c:1.254 src/sys/ufs/ufs/ufs_vnops.c:1.255
--- src/sys/ufs/ufs/ufs_vnops.c:1.254	Sat May 16 18:31:54 2020
+++ src/sys/ufs/ufs/ufs_vnops.c	Mon May 18 08:28:44 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_vnops.c,v 1.254 2020/05/16 18:31:54 christos Exp $	*/
+/*	$NetBSD: ufs_vnops.c,v 1.255 2020/05/18 08:28:44 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2020 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ufs_vnops.c,v 1.254 2020/05/16 18:31:54 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_vnops.c,v 1.255 2020/05/18 08:28:44 hannken Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -84,6 +84,7 @@ __KERNEL_RCSID(0, "$NetBSD: ufs_vnops.c,
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -1869,6 +1870,7 @@ ufs_strategy(void *v)
 	ip = VTOI(vp);
 	if (vp->v_type == VBLK || vp->v_type == VCHR)
 		panic("ufs_strategy: spec");
+	KASSERT(fstrans_held(vp->v_mount));
 	KASSERT(bp->b_bcount != 0);
 	if (bp->b_blkno == bp->b_lblkno) {
 		error = VOP_BMAP(vp, bp->b_lblkno, NULL, >b_blkno,



CVS commit: src/sys/kern

2020-05-18 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Mon May 18 08:27:54 UTC 2020

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

Log Message:
vrele_flush(): yield() every 100ms like we do it in vflush().


To generate a diff of this commit:
cvs rdiff -u -r1.121 -r1.122 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.121 src/sys/kern/vfs_vnode.c:1.122
--- src/sys/kern/vfs_vnode.c:1.121	Sun Apr 19 13:25:00 2020
+++ src/sys/kern/vfs_vnode.c	Mon May 18 08:27:54 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_vnode.c,v 1.121 2020/04/19 13:25:00 hannken Exp $	*/
+/*	$NetBSD: vfs_vnode.c,v 1.122 2020/05/18 08:27:54 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1997-2011, 2019, 2020 The NetBSD Foundation, Inc.
@@ -155,7 +155,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.121 2020/04/19 13:25:00 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.122 2020/05/18 08:27:54 hannken Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_pax.h"
@@ -534,6 +534,7 @@ vrele_flush(struct mount *mp)
 {
 	vnode_impl_t *vip, *marker;
 	vnode_t *vp;
+	int when = 0;
 
 	KASSERT(fstrans_is_owner(mp));
 
@@ -561,6 +562,11 @@ vrele_flush(struct mount *mp)
 		mutex_enter(vp->v_interlock);
 		vrelel(vp, 0, LK_EXCLUSIVE);
 
+		if (getticks() > when) {
+			yield();
+			when = getticks() + hz / 10;
+		}
+
 		mutex_enter(_lock);
 	}
 



CVS commit: src/sys/kern

2020-05-16 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sat May 16 17:42:07 UTC 2020

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

Log Message:
Add __diagused, amd64 kernel ALL compiles again.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/kern/subr_kcov.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_kcov.c
diff -u src/sys/kern/subr_kcov.c:1.14 src/sys/kern/subr_kcov.c:1.15
--- src/sys/kern/subr_kcov.c:1.14	Fri May 15 13:09:02 2020
+++ src/sys/kern/subr_kcov.c	Sat May 16 17:42:06 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_kcov.c,v 1.14 2020/05/15 13:09:02 maxv Exp $	*/
+/*	$NetBSD: subr_kcov.c,v 1.15 2020/05/16 17:42:06 hannken Exp $	*/
 
 /*
  * Copyright (c) 2019-2020 The NetBSD Foundation, Inc.
@@ -274,7 +274,7 @@ kcov_remote_enter(uint64_t subsystem, ui
 	struct lwp *l = curlwp;
 	kcov_remote_t *kr;
 	kcov_t *kd;
-	u_int refs;
+	u_int refs __diagused;
 
 	kr = kcov_remote_find(subsystem, id);
 	if (__predict_false(kr == NULL)) {
@@ -296,7 +296,7 @@ kcov_remote_leave(uint64_t subsystem, ui
 {
 	struct lwp *l = curlwp;
 	kcov_remote_t *kr;
-	u_int refs;
+	u_int refs __diagused;
 
 	kr = kcov_remote_find(subsystem, id);
 	if (__predict_false(kr == NULL)) {



CVS commit: src/sys

2020-05-13 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed May 13 09:21:30 UTC 2020

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

Log Message:
Add operation fstrans_held(struct mount *), true if the current thread
holds a fstrans lock.

Ride 9.99.61


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 src/sys/kern/vfs_trans.c
cvs rdiff -u -r1.13 -r1.14 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/sys/kern/vfs_trans.c
diff -u src/sys/kern/vfs_trans.c:1.61 src/sys/kern/vfs_trans.c:1.62
--- src/sys/kern/vfs_trans.c:1.61	Mon Jun 17 08:07:27 2019
+++ src/sys/kern/vfs_trans.c	Wed May 13 09:21:30 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_trans.c,v 1.61 2019/06/17 08:07:27 hannken Exp $	*/
+/*	$NetBSD: vfs_trans.c,v 1.62 2020/05/13 09:21:30 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_trans.c,v 1.61 2019/06/17 08:07:27 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_trans.c,v 1.62 2020/05/13 09:21:30 hannken Exp $");
 
 /*
  * File system transaction operations.
@@ -569,6 +569,23 @@ fstrans_done(struct mount *mp)
 }
 
 /*
+ * Check if we hold an lock.
+ */
+int
+fstrans_held(struct mount *mp)
+{
+	struct fstrans_lwp_info *fli;
+	struct fstrans_mount_info *fmi;
+
+	KASSERT(mp != dead_rootmount);
+
+	fli = fstrans_get_lwp_info(mp, true);
+	fmi = fli->fli_mountinfo;
+
+	return (fli->fli_trans_cnt > 0 || fmi->fmi_owner == curlwp);
+}
+
+/*
  * Check if this thread has an exclusive lock.
  */
 int

Index: src/sys/sys/fstrans.h
diff -u src/sys/sys/fstrans.h:1.13 src/sys/sys/fstrans.h:1.14
--- src/sys/sys/fstrans.h:1.13	Fri Mar  1 09:02:03 2019
+++ src/sys/sys/fstrans.h	Wed May 13 09:21:30 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: fstrans.h,v 1.13 2019/03/01 09:02:03 hannken Exp $	*/
+/*	$NetBSD: fstrans.h,v 1.14 2020/05/13 09:21:30 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -53,6 +53,7 @@ void	fstrans_start(struct mount *);
 int	fstrans_start_nowait(struct mount *);
 void	fstrans_start_lazy(struct mount *);
 void	fstrans_done(struct mount *);
+int	fstrans_held(struct mount *);
 int	fstrans_is_owner(struct mount *);
 int	fstrans_mount(struct mount *);
 void	fstrans_unmount(struct mount *);



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

2020-05-07 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Thu May  7 09:13:06 UTC 2020

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

Log Message:
Operation zfs_zget_cleaner() cannot fail, comment and add assertions.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 \
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.32 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c:1.33
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c:1.32	Thu May  7 09:12:31 2020
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c	Thu May  7 09:13:06 2020
@@ -1288,6 +1288,12 @@ zfs_zget(zfsvfs_t *zfsvfs, uint64_t obj_
 	return error;
 }
 
+/*
+ * Get a known cached znode, to be used from zil_commit()->zfs_get_data()
+ * to resolve log entries.  Doesn't take a reference, will never fail and
+ * depends on zfs_vnops.c::zfs_netbsd_reclaim() running a zil_commit()
+ * before the znode gets freed.
+ */
 int
 zfs_zget_cleaner(zfsvfs_t *zfsvfs, uint64_t obj_num, znode_t **zpp)
 {
@@ -1295,31 +1301,26 @@ zfs_zget_cleaner(zfsvfs_t *zfsvfs, uint6
 	sa_handle_t *hdl;
 	dmu_object_info_t doi;
 	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));
-	}
+	VERIFY(0 == sa_buf_hold(zfsvfs->z_os, obj_num, NULL, ));
 
 	dmu_object_info_from_db(db, );
-	if (doi.doi_bonus_type != DMU_OT_SA &&
-	(doi.doi_bonus_type != DMU_OT_ZNODE ||
+	ASSERT(doi.doi_bonus_type == DMU_OT_SA ||
 	(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));
-	}
+	doi.doi_bonus_size >= sizeof (znode_phys_t)));
+
 	hdl = dmu_buf_get_user(db);
 	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/dist/uts/common/fs/zfs

2020-05-07 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Thu May  7 09:12:03 UTC 2020

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

Log Message:
Revert Rev. 1.63 and add a comment why we have to zil_commit() here:

Operation zfs_znode.c::zfs_zget_cleaner() depends on this
zil_commit() as a barrier to guarantee the znode cannot
get freed before its log entries are resolved.


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 \
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.64 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.65
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.64	Sat Mar 14 20:45:23 2020
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c	Thu May  7 09:12:03 2020
@@ -5858,11 +5858,16 @@ zfs_netbsd_reclaim(void *v)
 			zp->z_atime_dirty = 0;
 			dmu_tx_commit(tx);
 		}
-
-		if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
-			zil_commit(zfsvfs->z_log, zp->z_id);
 	}
 
+	/*
+	 * Operation zfs_znode.c::zfs_zget_cleaner() depends on this
+	 * zil_commit() as a barrier to guarantee the znode cannot
+	 * get freed before its log entries are resolved.
+	 */
+	if (zfsvfs->z_log)
+		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

2020-05-07 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Thu May  7 09:12:32 UTC 2020

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

Log Message:
Revert Rev. 1.31 as it is no longer possible for the handle to be NULL.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 \
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.31 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c:1.32
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c:1.31	Fri Mar 20 08:26:01 2020
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c	Thu May  7 09:12:31 2020
@@ -1315,11 +1315,7 @@ zfs_zget_cleaner(zfsvfs_t *zfsvfs, uint6
 		return (SET_ERROR(EINVAL));
 	}
 	hdl = dmu_buf_get_user(db);
-	if (hdl == NULL) {
-		sa_buf_rele(db, NULL);
-		ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
-		return (SET_ERROR(EINVAL));
-	}
+	ASSERT3P(hdl, !=, NULL);
 	zp = sa_get_userdata(hdl);
 	ASSERT3U(zp->z_id, ==, obj_num);
 	sa_buf_rele(db, NULL);



CVS commit: src/sys/arch/x86/x86

2020-05-01 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Fri May  1 14:16:15 UTC 2020

Modified Files:
src/sys/arch/x86/x86: x86_machdep.c

Log Message:
Use PRIxPADDR for paddr_t to make i386/ALL compile.


To generate a diff of this commit:
cvs rdiff -u -r1.139 -r1.140 src/sys/arch/x86/x86/x86_machdep.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/arch/x86/x86/x86_machdep.c
diff -u src/sys/arch/x86/x86/x86_machdep.c:1.139 src/sys/arch/x86/x86/x86_machdep.c:1.140
--- src/sys/arch/x86/x86/x86_machdep.c:1.139	Thu Apr 30 22:09:32 2020
+++ src/sys/arch/x86/x86/x86_machdep.c	Fri May  1 14:16:15 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_machdep.c,v 1.139 2020/04/30 22:09:32 bouyer Exp $	*/
+/*	$NetBSD: x86_machdep.c,v 1.140 2020/05/01 14:16:15 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2006, 2007 YAMAMOTO Takashi,
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.139 2020/04/30 22:09:32 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.140 2020/05/01 14:16:15 hannken Exp $");
 
 #include "opt_modular.h"
 #include "opt_physmem.h"
@@ -959,7 +959,8 @@ init_x86_vm(paddr_t pa_kend)
 		if (seg_start <= pa_kstart && pa_kend <= seg_end) {
 #ifdef DEBUG_MEMLOAD
 			printf("split kernel overlapping to "
-			"%" PRIx64 " - %lx and %lx - %" PRIx64 "\n",
+			"%" PRIx64 " - %" PRIxPADDR " and "
+			"%" PRIxPADDR " - %" PRIx64 "\n",
 			seg_start, pa_kstart, pa_kend, seg_end);
 #endif
 			seg_start1 = pa_kend;
@@ -991,7 +992,8 @@ init_x86_vm(paddr_t pa_kend)
 		pa_kend < seg_end) {
 #ifdef DEBUG_MEMLOAD
 			printf("discard leading kernel overlap "
-			"%" PRIx64 " - %lx\n", seg_start, pa_kend);
+			"%" PRIx64 " - %" PRIxPADDR "\n",
+			seg_start, pa_kend);
 #endif
 			seg_start = pa_kend;
 		}
@@ -1006,7 +1008,8 @@ init_x86_vm(paddr_t pa_kend)
 		seg_end < pa_kend) {
 #ifdef DEBUG_MEMLOAD
 			printf("discard trailing kernel overlap "
-			"%lx - %" PRIx64 "\n", pa_kstart, seg_end);
+			"%" PRIxPADDR " - %" PRIx64 "\n",
+			pa_kstart, seg_end);
 #endif
 			seg_end = pa_kstart;
 		}



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

2020-05-01 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Fri May  1 14:15:41 UTC 2020

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

Log Message:
Remove wd* at umass?, it was dropped.


To generate a diff of this commit:
cvs rdiff -u -r1.490 -r1.491 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.490 src/sys/arch/i386/conf/ALL:1.491
--- src/sys/arch/i386/conf/ALL:1.490	Wed Mar 25 17:06:19 2020
+++ src/sys/arch/i386/conf/ALL	Fri May  1 14:15:41 2020
@@ -1,4 +1,4 @@
-# $NetBSD: ALL,v 1.490 2020/03/25 17:06:19 jdolecek Exp $
+# $NetBSD: ALL,v 1.491 2020/05/01 14:15:41 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.490 $"
+#ident		"ALL-$Revision: 1.491 $"
 
 maxusers	64		# estimated number of users
 
@@ -1302,7 +1302,6 @@ uhso*	at uhub? port ? configuration ?
 
 # USB Mass Storage
 umass*	at uhub? port ? configuration ? interface ?
-wd*	at umass?
 
 # USB audio
 uaudio* at uhub? port ? configuration ?



CVS commit: src/sys/kern

2020-05-01 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Fri May  1 08:45:01 UTC 2020

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

Log Message:
Undo Rev. 1.79, it breaks root-on-raid where it destroys the component
disks before the raid:

  forcefully unmounting / (/dev/raid0a)...
  sd1: detached
  sd0: detached
  raid0: cache flush to component /dev/sd0a failed.
  raid0: cache flush to component /dev/sd1a failed.
  fatal page fault in supervisor mode
  Stopped in pid 2356.2356 (reboot) at netbsd:sdstrategy+0x36

Reopens PR kern/54969: Disk cache is no longer flushed on shutdown


To generate a diff of this commit:
cvs rdiff -u -r1.81 -r1.82 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.81 src/sys/kern/vfs_mount.c:1.82
--- src/sys/kern/vfs_mount.c:1.81	Tue Apr 21 21:42:47 2020
+++ src/sys/kern/vfs_mount.c	Fri May  1 08:45:01 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_mount.c,v 1.81 2020/04/21 21:42:47 ad Exp $	*/
+/*	$NetBSD: vfs_mount.c,v 1.82 2020/05/01 08:45:01 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1997-2020 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.81 2020/04/21 21:42:47 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.82 2020/05/01 08:45:01 hannken Exp $");
 
 #include 
 #include 
@@ -114,8 +114,6 @@ static struct vnode *vfs_vnode_iterator_
 /* Root filesystem. */
 vnode_t *			rootvnode;
 
-extern struct mount		*dead_rootmount;
-
 /* Mounted filesystem list. */
 static TAILQ_HEAD(mountlist, mountlist_entry) mountlist;
 static kmutex_t			mountlist_lock __cacheline_aligned;
@@ -1016,7 +1014,6 @@ bool
 vfs_unmountall1(struct lwp *l, bool force, bool verbose)
 {
 	struct mount *mp;
-	mount_iterator_t *iter;
 	bool any_error = false, progress = false;
 	uint64_t gen;
 	int error;
@@ -1051,24 +1048,6 @@ vfs_unmountall1(struct lwp *l, bool forc
 	if (any_error && verbose) {
 		printf("WARNING: some file systems would not unmount\n");
 	}
-
-	/* If the mountlist is empty destroy anonymous device vnodes. */
-	mountlist_iterator_init();
-	if (mountlist_iterator_next(iter) == NULL) {
-		struct vnode_iterator *marker;
-		vnode_t *vp;
-
-		vfs_vnode_iterator_init(dead_rootmount, );
-		while ((vp = vfs_vnode_iterator_next(marker, NULL, NULL))) {
-			if (vp->v_type == VCHR || vp->v_type == VBLK)
-vgone(vp);
-			else
-vrele(vp);
-		}
-		vfs_vnode_iterator_destroy(marker);
-	}
-	mountlist_iterator_destroy(iter);
-
 	return progress;
 }
 



CVS commit: src/sys/ufs/ufs

2020-05-01 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Fri May  1 08:43:37 UTC 2020

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

Log Message:
There is no difference between a zero-sized and not yet
reclaimed directory vnode and a non-existent vnode.

Teach ufs_fhtovp() to treat zero-sized directories as stale.

PR kern/55211 (fs/vfs/t_vnops:nfs_dir_rmdirdotdot test fails)


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 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/ufs/ufs/ufs_vfsops.c
diff -u src/sys/ufs/ufs/ufs_vfsops.c:1.59 src/sys/ufs/ufs/ufs_vfsops.c:1.60
--- src/sys/ufs/ufs/ufs_vfsops.c:1.59	Fri Jan 17 20:08:10 2020
+++ src/sys/ufs/ufs/ufs_vfsops.c	Fri May  1 08:43:37 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_vfsops.c,v 1.59 2020/01/17 20:08:10 ad Exp $	*/
+/*	$NetBSD: ufs_vfsops.c,v 1.60 2020/05/01 08:43:37 hannken Exp $	*/
 
 /*
  * Copyright (c) 1991, 1993, 1994
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ufs_vfsops.c,v 1.59 2020/01/17 20:08:10 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_vfsops.c,v 1.60 2020/05/01 08:43:37 hannken Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -247,7 +247,8 @@ ufs_fhtovp(struct mount *mp, struct ufid
 	}
 	ip = VTOI(nvp);
 	KASSERT(ip != NULL);
-	if (ip->i_mode == 0 || ip->i_gen != ufhp->ufid_gen) {
+	if (ip->i_mode == 0 || ip->i_gen != ufhp->ufid_gen ||
+	((ip->i_mode & IFMT) == IFDIR && ip->i_size == 0)) {
 		vput(nvp);
 		*vpp = NULLVP;
 		return (ESTALE);



CVS commit: src/sys/nfs

2020-05-01 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Fri May  1 08:43:00 UTC 2020

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

Log Message:
Resolve delayed truncation from nfs_inactive() too.

Should prevent "locking against self" from nfs_unlock().


To generate a diff of this commit:
cvs rdiff -u -r1.125 -r1.126 src/sys/nfs/nfs_node.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_node.c
diff -u src/sys/nfs/nfs_node.c:1.125 src/sys/nfs/nfs_node.c:1.126
--- src/sys/nfs/nfs_node.c:1.125	Mon Feb 24 20:11:45 2020
+++ src/sys/nfs/nfs_node.c	Fri May  1 08:43:00 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nfs_node.c,v 1.125 2020/02/24 20:11:45 ad Exp $	*/
+/*	$NetBSD: nfs_node.c,v 1.126 2020/05/01 08:43:00 hannken Exp $	*/
 
 /*
  * Copyright (c) 1989, 1993
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nfs_node.c,v 1.125 2020/02/24 20:11:45 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nfs_node.c,v 1.126 2020/05/01 08:43:00 hannken Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_nfs.h"
@@ -186,6 +186,9 @@ nfs_inactive(void *v)
 	struct sillyrename *sp;
 	struct vnode *vp = ap->a_vp;
 
+	/* If we have a delayed truncation, do it now. */
+	nfs_delayedtruncate(vp);
+
 	np = VTONFS(vp);
 	if (vp->v_type != VDIR) {
 		sp = np->n_sillyrename;



CVS commit: src/sys/kern

2020-04-19 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sun Apr 19 13:26:18 UTC 2020

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

Log Message:
Destroy anonymous device vnodes on reboot once the last file system
got unmounted and the mount list is empty.

PR kern/54969: Disk cache is no longer flushed on shutdown


To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.79 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.78 src/sys/kern/vfs_mount.c:1.79
--- src/sys/kern/vfs_mount.c:1.78	Mon Apr 13 19:23:18 2020
+++ src/sys/kern/vfs_mount.c	Sun Apr 19 13:26:17 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_mount.c,v 1.78 2020/04/13 19:23:18 ad Exp $	*/
+/*	$NetBSD: vfs_mount.c,v 1.79 2020/04/19 13:26:17 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1997-2020 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.78 2020/04/13 19:23:18 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.79 2020/04/19 13:26:17 hannken Exp $");
 
 #include 
 #include 
@@ -115,6 +115,8 @@ static struct vnode *vfs_vnode_iterator_
 /* Root filesystem. */
 vnode_t *			rootvnode;
 
+extern struct mount		*dead_rootmount;
+
 /* Mounted filesystem list. */
 static TAILQ_HEAD(mountlist, mountlist_entry) mountlist;
 static kmutex_t			mountlist_lock __cacheline_aligned;
@@ -1020,6 +1022,7 @@ bool
 vfs_unmountall1(struct lwp *l, bool force, bool verbose)
 {
 	struct mount *mp;
+	mount_iterator_t *iter;
 	bool any_error = false, progress = false;
 	uint64_t gen;
 	int error;
@@ -1054,6 +1057,24 @@ vfs_unmountall1(struct lwp *l, bool forc
 	if (any_error && verbose) {
 		printf("WARNING: some file systems would not unmount\n");
 	}
+
+	/* If the mountlist is empty destroy anonymous device vnodes. */
+	mountlist_iterator_init();
+	if (mountlist_iterator_next(iter) == NULL) {
+		struct vnode_iterator *marker;
+		vnode_t *vp;
+
+		vfs_vnode_iterator_init(dead_rootmount, );
+		while ((vp = vfs_vnode_iterator_next(marker, NULL, NULL))) {
+			if (vp->v_type == VCHR || vp->v_type == VBLK)
+vgone(vp);
+			else
+vrele(vp);
+		}
+		vfs_vnode_iterator_destroy(marker);
+	}
+	mountlist_iterator_destroy(iter);
+
 	return progress;
 }
 



CVS commit: src/sys/kern

2020-04-19 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sun Apr 19 13:25:00 UTC 2020

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

Log Message:
Take some pressure from vdrain lock:

- Use cv_signal() instead of cv_broadcast(), there is only one waiter.
- No need to signal if number of vnodes doesn't increase.
- Use kpause(1) instead of yield().


To generate a diff of this commit:
cvs rdiff -u -r1.120 -r1.121 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.120 src/sys/kern/vfs_vnode.c:1.121
--- src/sys/kern/vfs_vnode.c:1.120	Mon Apr 13 19:23:18 2020
+++ src/sys/kern/vfs_vnode.c	Sun Apr 19 13:25:00 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_vnode.c,v 1.120 2020/04/13 19:23:18 ad Exp $	*/
+/*	$NetBSD: vfs_vnode.c,v 1.121 2020/04/19 13:25:00 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1997-2011, 2019, 2020 The NetBSD Foundation, Inc.
@@ -155,7 +155,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.120 2020/04/13 19:23:18 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.121 2020/04/19 13:25:00 hannken Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_pax.h"
@@ -519,8 +519,9 @@ lru_requeue(vnode_t *vp, vnodelst_t *lis
 		 */
 		numvnodes += d;
 	}
-	if (numvnodes > desiredvnodes || listhd == _list[LRU_VRELE])
-		cv_broadcast(_cv);
+	if ((d > 0 && numvnodes > desiredvnodes) ||
+	listhd == _list[LRU_VRELE])
+		cv_signal(_cv);
 	mutex_exit(_lock);
 }
 
@@ -686,9 +687,7 @@ vdrain_thread(void *cookie)
 		}
 
 		if (vdrain_retry) {
-			mutex_exit(_lock);
-			yield();
-			mutex_enter(_lock);
+			kpause("vdrainrt", false, 1, _lock);
 		} else {
 			vdrain_gen++;
 			cv_broadcast(_gen_cv);



CVS commit: src/sys/fs/udf

2020-04-06 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Mon Apr  6 14:31:06 UTC 2020

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

Log Message:
udf_get_node(): fix typo and honor "lktype" argument.


To generate a diff of this commit:
cvs rdiff -u -r1.149 -r1.150 src/sys/fs/udf/udf_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/udf/udf_subr.c
diff -u src/sys/fs/udf/udf_subr.c:1.149 src/sys/fs/udf/udf_subr.c:1.150
--- src/sys/fs/udf/udf_subr.c:1.149	Thu Feb 27 22:12:54 2020
+++ src/sys/fs/udf/udf_subr.c	Mon Apr  6 14:31:06 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: udf_subr.c,v 1.149 2020/02/27 22:12:54 ad Exp $ */
+/* $NetBSD: udf_subr.c,v 1.150 2020/04/06 14:31:06 hannken Exp $ */
 
 /*
  * Copyright (c) 2006, 2008 Reinoud Zandijk
@@ -29,7 +29,7 @@
 
 #include 
 #ifndef lint
-__KERNEL_RCSID(0, "$NetBSD: udf_subr.c,v 1.149 2020/02/27 22:12:54 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: udf_subr.c,v 1.150 2020/04/06 14:31:06 hannken Exp $");
 #endif /* not lint */
 
 
@@ -5641,7 +5641,7 @@ udf_get_node(struct udf_mount *ump, stru
 	sizeof(node_icb_loc->loc), );
 	if (error)
 		return error;
-	error = vn_lock(vp, LK_EXCLUSIVE);
+	error = vn_lock(vp, lktype);
 	if (error) {
 		vrele(vp);
 		return error;



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

2020-03-20 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Fri Mar 20 08:26:01 UTC 2020

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

Log Message:
With zfs_netbsd_reclaim() no longer doing an unconditional
zil commit dmu_buf_get_user() may return a NULL handle when
the znode already disappeared.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 \
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.30 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c:1.31
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c:1.30	Sun Feb 23 15:46:38 2020
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c	Fri Mar 20 08:26:01 2020
@@ -1315,7 +1315,11 @@ zfs_zget_cleaner(zfsvfs_t *zfsvfs, uint6
 		return (SET_ERROR(EINVAL));
 	}
 	hdl = dmu_buf_get_user(db);
-	ASSERT3P(hdl, !=, NULL);
+	if (hdl == NULL) {
+		sa_buf_rele(db, NULL);
+		ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
+		return (SET_ERROR(EINVAL));
+	}
 	zp = sa_get_userdata(hdl);
 	ASSERT3U(zp->z_id, ==, obj_num);
 	sa_buf_rele(db, NULL);



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

2020-02-13 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Thu Feb 13 16:53:32 UTC 2020

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

Log Message:
zfs_netbsd_setattr: ignore size changes on device nodes.


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 \
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.56 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.57
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.56	Sat Jan 18 15:21:32 2020
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c	Thu Feb 13 16:53:32 2020
@@ -5575,6 +5575,9 @@ zfs_netbsd_setattr(void *v)
 
 	zflags = VTOZ(vp)->z_pflags;
 
+	/* Ignore size changes on device nodes. */
+	if (vp->v_type == VBLK || vp->v_type == VCHR)
+		xvap.xva_vattr.va_mask &= ~AT_SIZE;
 	if (vap->va_flags != VNOVAL) {
 		int error;
 



CVS commit: src/sys/arch/x86/x86

2019-12-03 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Tue Dec  3 11:50:45 UTC 2019

Modified Files:
src/sys/arch/x86/x86: x86_machdep.c

Log Message:
Make sure the assignment to "idepth" is done inside the loop to prevent
preemption between loop end and dereference of "l_cpu->ci_depth".


To generate a diff of this commit:
cvs rdiff -u -r1.131 -r1.132 src/sys/arch/x86/x86/x86_machdep.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/arch/x86/x86/x86_machdep.c
diff -u src/sys/arch/x86/x86/x86_machdep.c:1.131 src/sys/arch/x86/x86/x86_machdep.c:1.132
--- src/sys/arch/x86/x86/x86_machdep.c:1.131	Tue Dec  3 11:50:16 2019
+++ src/sys/arch/x86/x86/x86_machdep.c	Tue Dec  3 11:50:45 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_machdep.c,v 1.131 2019/12/03 11:50:16 hannken Exp $	*/
+/*	$NetBSD: x86_machdep.c,v 1.132 2019/12/03 11:50:45 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2006, 2007 YAMAMOTO Takashi,
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.131 2019/12/03 11:50:16 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.132 2019/12/03 11:50:45 hannken Exp $");
 
 #include "opt_modular.h"
 #include "opt_physmem.h"
@@ -350,7 +350,7 @@ bool
 cpu_intr_p(void)
 {
 	uint64_t ncsw;
-	int idepth;
+	volatile int idepth;
 	lwp_t *l;
 
 	l = curlwp;



CVS commit: src/sys/arch/x86/x86

2019-12-03 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Tue Dec  3 11:50:16 UTC 2019

Modified Files:
src/sys/arch/x86/x86: x86_machdep.c

Log Message:
Make cpu_intr_p() work with "curlwp->l_cpu == NULL" and
assert "curlwp == " in this case.

Prevents crash during early boot with "options LOCKDEBUG".


To generate a diff of this commit:
cvs rdiff -u -r1.130 -r1.131 src/sys/arch/x86/x86/x86_machdep.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/arch/x86/x86/x86_machdep.c
diff -u src/sys/arch/x86/x86/x86_machdep.c:1.130 src/sys/arch/x86/x86/x86_machdep.c:1.131
--- src/sys/arch/x86/x86/x86_machdep.c:1.130	Sun Dec  1 14:52:14 2019
+++ src/sys/arch/x86/x86/x86_machdep.c	Tue Dec  3 11:50:16 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_machdep.c,v 1.130 2019/12/01 14:52:14 ad Exp $	*/
+/*	$NetBSD: x86_machdep.c,v 1.131 2019/12/03 11:50:16 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2006, 2007 YAMAMOTO Takashi,
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.130 2019/12/01 14:52:14 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.131 2019/12/03 11:50:16 hannken Exp $");
 
 #include "opt_modular.h"
 #include "opt_physmem.h"
@@ -354,6 +354,10 @@ cpu_intr_p(void)
 	lwp_t *l;
 
 	l = curlwp;
+	if (__predict_false(l->l_cpu == NULL)) {
+		KASSERT(l == );
+		return false;
+	}
 	do {
 		ncsw = l->l_ncsw;
 		idepth = l->l_cpu->ci_idepth;



CVS commit: src/tools

2019-05-07 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Tue May  7 10:22:54 UTC 2019

Modified Files:
src/tools: Makefile

Log Message:
Fix build, "pax" must be built before "libprop".

Ok: Matthew Green mrg@


To generate a diff of this commit:
cvs rdiff -u -r1.202 -r1.203 src/tools/Makefile

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

Modified files:

Index: src/tools/Makefile
diff -u src/tools/Makefile:1.202 src/tools/Makefile:1.203
--- src/tools/Makefile:1.202	Tue May  7 04:29:45 2019
+++ src/tools/Makefile	Tue May  7 10:22:54 2019
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.202 2019/05/07 04:29:45 thorpej Exp $
+#	$NetBSD: Makefile,v 1.203 2019/05/07 10:22:54 hannken Exp $
 
 .include 
 .include 
@@ -101,12 +101,11 @@ SUBDIR+= cap_mkdb crunchgen ctags gencat
 .endif
 
 SUBDIR+= cat rpcgen join lorder m4 mkdep tsort xz-include .WAIT yacc .WAIT awk .WAIT lex
-SUBDIR+= grep xz-lib libprop
+SUBDIR+= grep xz-lib pax .WAIT libprop
 
 .if ${TOOLS_BUILDRUMP} == "no"
 SUBDIR += .WAIT texinfo \
 	.WAIT tic \
-	.WAIT pax \
 	.WAIT ${TOOLCHAIN_BITS} \
 	${DTRACE_BITS} \
 		asn1_compile cksum compile_et db \



CVS commit: src

2019-05-07 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Tue May  7 08:51:10 UTC 2019

Modified Files:
src/external/cddl/osnet/dist/uts/common/fs/zfs: spa_misc.c zfs_ioctl.c
src/external/cddl/osnet/dist/uts/common/sys/fs: zfs.h
src/external/cddl/osnet/sys/kern: mod.c
src/sys/rump/fs/lib/libzfs: zfs_component.c

Log Message:
Cleanup modules "solaris" and "zfs":

- Defer spa_config_load() until root is mounted.
- Restore the config path to "/etc/zfs/zpool.cache".
- Module "zfs" is type MODULE_CLASS_VFS and no longer depends on "rootvnode".
- Module "solaris" no longer depends on "mp_online".
- Fix rump component registration to not detach "/dev/zfs" if
  it didn't attach it.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/spa_misc.c
cvs rdiff -u -r1.16 -r1.17 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ioctl.c
cvs rdiff -u -r1.5 -r1.6 src/external/cddl/osnet/dist/uts/common/sys/fs/zfs.h
cvs rdiff -u -r1.4 -r1.5 src/external/cddl/osnet/sys/kern/mod.c
cvs rdiff -u -r1.2 -r1.3 src/sys/rump/fs/lib/libzfs/zfs_component.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/spa_misc.c
diff -u src/external/cddl/osnet/dist/uts/common/fs/zfs/spa_misc.c:1.4 src/external/cddl/osnet/dist/uts/common/fs/zfs/spa_misc.c:1.5
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/spa_misc.c:1.4	Thu Nov 15 04:55:38 2018
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/spa_misc.c	Tue May  7 08:51:09 2019
@@ -60,6 +60,10 @@
 #include 
 #endif
 
+#if defined( __NetBSD__) && defined(_KERNEL)
+#include 
+#endif
+
 /*
  * SPA locking
  *
@@ -2071,7 +2075,11 @@ spa_init(int mode)
 	zfs_prop_init();
 	zpool_prop_init();
 	zpool_feature_init();
+#if defined(__NetBSD__) && defined(_KERNEL)
+	config_mountroot((device_t) 0, (void (*)(device_t)) spa_config_load);
+#else
 	spa_config_load();
+#endif
 	l2arc_start();
 #ifdef __FreeBSD__
 #ifdef _KERNEL

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.16 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ioctl.c:1.17
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ioctl.c:1.16	Tue Feb  5 09:54:36 2019
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ioctl.c	Tue May  7 08:51:09 2019
@@ -6973,7 +6973,7 @@ MODULE_DEPEND(zfsctrl, acl_nfs4, 1, 1, 1
 #include 
 #include 
 
-MODULE(MODULE_CLASS_DRIVER, zfs, "solaris");
+MODULE(MODULE_CLASS_VFS, zfs, "solaris");
 
 static const struct fileops zfs_fileops;
 
@@ -7180,9 +7180,6 @@ zfs_modcmd(modcmd_t cmd, void *arg)
 
 	switch (cmd) {
 	case MODULE_CMD_INIT:
-		if (!rootvnode)
-			return EAGAIN;
-
 		/* XXXNETBSD trim is not supported yet */
 		zfs_trim_enabled = B_FALSE;
 

Index: src/external/cddl/osnet/dist/uts/common/sys/fs/zfs.h
diff -u src/external/cddl/osnet/dist/uts/common/sys/fs/zfs.h:1.5 src/external/cddl/osnet/dist/uts/common/sys/fs/zfs.h:1.6
--- src/external/cddl/osnet/dist/uts/common/sys/fs/zfs.h:1.5	Mon May 28 21:05:08 2018
+++ src/external/cddl/osnet/dist/uts/common/sys/fs/zfs.h	Tue May  7 08:51:09 2019
@@ -630,7 +630,7 @@ typedef struct zpool_rewind_policy {
 #define	ZPOOL_CACHE		"/boot/zfs/zpool.cache"
 #endif
 #ifdef __NetBSD__
-#define	ZPOOL_CACHE		"/var/db/zfs/zpool.cache"
+#define	ZPOOL_CACHE		"/etc/zfs/zpool.cache"
 #endif
 
 /*

Index: src/external/cddl/osnet/sys/kern/mod.c
diff -u src/external/cddl/osnet/sys/kern/mod.c:1.4 src/external/cddl/osnet/sys/kern/mod.c:1.5
--- src/external/cddl/osnet/sys/kern/mod.c:1.4	Thu Dec 13 10:19:47 2018
+++ src/external/cddl/osnet/sys/kern/mod.c	Tue May  7 08:51:09 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: mod.c,v 1.4 2018/12/13 10:19:47 hannken Exp $	*/
+/*	$NetBSD: mod.c,v 1.5 2019/05/07 08:51:09 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mod.c,v 1.4 2018/12/13 10:19:47 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mod.c,v 1.5 2019/05/07 08:51:09 hannken Exp $");
 
 #include 
 #include 
@@ -49,9 +49,6 @@ 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();

Index: src/sys/rump/fs/lib/libzfs/zfs_component.c
diff -u src/sys/rump/fs/lib/libzfs/zfs_component.c:1.2 src/sys/rump/fs/lib/libzfs/zfs_component.c:1.3
--- src/sys/rump/fs/lib/libzfs/zfs_component.c:1.2	Tue Jan 26 23:12:17 2016
+++ src/sys/rump/fs/lib/libzfs/zfs_component.c	Tue May  7 08:51:09 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: zfs_component.c,v 1.2 2016/01/26 23:12:17 pooka Exp $	*/
+/*	$NetBSD: zfs_component.c,v 1.3 2019/05/07 08:51:09 hannken Exp $	*/
 
 /*
  * Copyright (c) 2009 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, 

CVS commit: src/external/cddl/osnet

2019-05-07 Thread Juergen Hannken-Illjes
y 
- *
- *   There are three locks used in task queues:
- *
- *   1) The taskq_t's tq_lock, protecting global task queue state.
- *
- *   2) Each per-CPU bucket has a lock for bucket management.
- *
- *   3) The global taskq_cpupct_lock, which protects the list of
- *  TASKQ_THREADS_CPU_PCT taskqs.
- *
- *   If both (1) and (2) are needed, tq_lock should be taken *after* the bucket
- *   lock.
- *
- *   If both (1) and (3) are needed, tq_lock should be taken *after*
- *   taskq_cpupct_lock.
- *
- * DEBUG FACILITIES 
- *
- * For DEBUG kernels it is possible to induce random failures to
- * taskq_dispatch() function when it is given TQ_NOSLEEP argument. The value of
- * taskq_dmtbf and taskq_smtbf tunables control the mean time between induced
- * failures for dynamic and static task queues respectively.
- *
- * Setting TASKQ_STATISTIC to 0 will disable per-bucket statistics.
- *
- * TUNABLES 
- *
- *	system_taskq_size	- Size of the global system_taskq.
- *  This value is multiplied by nCPUs to determine
- *  actual size.
- *  Default value: 64
- *
- *	taskq_minimum_nthreads_max
- *- Minimum size of the thread list for a taskq.
- *  Useful for testing different thread pool
- *  sizes by overwriting tq_nthreads_target.
- *
- *	taskq_thread_timeout	- Maximum idle time for taskq_d_thread()
- *  Default value: 5 minutes
- *
- *	taskq_maxbuckets	- Maximum number of buckets in any task queue
- *  Default value: 128
- *
- *	taskq_search_depth	- Maximum # of buckets searched for a free entry
- *  Default value: 4
- *
- *	taskq_dmtbf		- Mean time between induced dispatch failures
- *  for dynamic task queues.
- *  Default value: UINT_MAX (no induced failures)
- *
- *	taskq_smtbf		- Mean time between induced dispatch failures
- *  for static task queues.
- *  Default value: UINT_MAX (no induced failures)
- *
- * CONDITIONAL compilation -
- *
- *    TASKQ_STATISTIC	- If set will enable bucket statistic (default).
- *
+/*-
+ * Copyright (c) 2019 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Juergen Hannken-Illjes.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
+#include 
 #include 
-#include 
-#include 
-
-static kmem_cache_t *taskq_ent_cache, *taskq_cache;
-
-/* Global system task queue for common use */
-taskq_t *system_taskq;
-
-/*
- * Maxmimum number of entries in global system taskq is
- *  system_taskq_size * max_ncpus
- */
-#define SYSTEM_TASKQ_SIZE 1
-int system_taskq_size = SYSTEM_TASKQ_SIZE;
-
-/*
- * Minimum size for tq_nthreads_max; useful for those who want to play around
- * with increasing a taskq's tq_nthreads_target.
- */
-int taskq_minimum_nthreads_max = 1;
-
-/*
- * We want to ensure that when taskq_create() returns, there is at least
- * one thread ready to handle requests.  To guarantee this, we have to wait
- * for the second thread, since the first one cannot process requests until
- * the second thread has been created.
- */
-#define	TASKQ_CREATE_ACTIVE_THREADS	2
-
-/* Maximum percentage allowed for TASKQ_THREADS_CPU_PCT */
-#define	TASKQ_CPUPCT_MAX_PERCENT	1000
-int taskq_cpupct_max_percent = TASKQ_CPUPCT_MAX_PERCENT;
-
-/*
- * Dynamic task queue threads that don't get any work within
- * taskq_thread_timeout destroy themselves
- */
-#define	TASKQ_T

CVS commit: src/sys/kern

2019-04-15 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Mon Apr 15 13:01:08 UTC 2019

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

Log Message:
Add reference counting to alias states to prevent them disappearing
while still in use.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 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.58 src/sys/kern/vfs_trans.c:1.59
--- src/sys/kern/vfs_trans.c:1.58	Thu Mar  7 11:09:10 2019
+++ src/sys/kern/vfs_trans.c	Mon Apr 15 13:01:08 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_trans.c,v 1.58 2019/03/07 11:09:10 hannken Exp $	*/
+/*	$NetBSD: vfs_trans.c,v 1.59 2019/04/15 13:01:08 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_trans.c,v 1.58 2019/03/07 11:09:10 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_trans.c,v 1.59 2019/04/15 13:01:08 hannken Exp $");
 
 /*
  * File system transaction operations.
@@ -71,6 +71,7 @@ struct fstrans_lwp_info {
 	struct fstrans_lwp_info *fli_alias;
 	struct fstrans_mount_info *fli_mountinfo;
 	int fli_trans_cnt;
+	int fli_alias_cnt;
 	int fli_cow_cnt;
 	enum fstrans_lock_type fli_lock_type;
 	LIST_ENTRY(fstrans_lwp_info) fli_list;
@@ -203,6 +204,7 @@ fstrans_lwp_dtor(lwp_t *l)
 		if (fli->fli_mount != NULL)
 			fstrans_mount_dtor(fli->fli_mountinfo);
 		fli_next = fli->fli_succ;
+		fli->fli_alias_cnt = 0;
 		fli->fli_mount = NULL;
 		fli->fli_alias = NULL;
 		fli->fli_mountinfo = NULL;
@@ -300,14 +302,21 @@ fstrans_clear_lwp_info(void)
 		fli = *p;
 		if (fli->fli_mount != NULL &&
 		fli->fli_mountinfo->fmi_gone &&
-		fli->fli_trans_cnt == 0 && fli->fli_cow_cnt == 0) {
+		fli->fli_trans_cnt == 0 &&
+		fli->fli_cow_cnt == 0 &&
+		fli->fli_alias_cnt == 0) {
 			*p = (*p)->fli_succ;
 			fstrans_mount_dtor(fli->fli_mountinfo);
+			if (fli->fli_alias) {
+KASSERT(fli->fli_alias->fli_alias_cnt > 0);
+fli->fli_alias->fli_alias_cnt--;
+			}
 			fli->fli_mount = NULL;
 			fli->fli_alias = NULL;
 			fli->fli_mountinfo = NULL;
 			membar_sync();
 			fli->fli_self = NULL;
+			p = >l_fstrans;
 		} else {
 			p = &(*p)->fli_succ;
 		}
@@ -343,6 +352,7 @@ fstrans_alloc_lwp_info(struct mount *mp)
 			KASSERT(fli->fli_mount == NULL);
 			KASSERT(fli->fli_trans_cnt == 0);
 			KASSERT(fli->fli_cow_cnt == 0);
+			KASSERT(fli->fli_alias_cnt == 0);
 			fli->fli_self = curlwp;
 			fli->fli_succ = curlwp->l_fstrans;
 			curlwp->l_fstrans = fli;
@@ -378,6 +388,7 @@ fstrans_alloc_lwp_info(struct mount *mp)
 
 	if (mp) {
 		fli->fli_alias = fstrans_alloc_lwp_info(mp);
+		fli->fli_alias->fli_alias_cnt++;
 		fli = fli->fli_alias;
 	}
 
@@ -971,7 +982,8 @@ fstrans_print_lwp(struct proc *p, struct
 break;
 			}
 		}
-		printf(" %d cow %d\n", fli->fli_trans_cnt, fli->fli_cow_cnt);
+		printf(" %d cow %d alias %d\n",
+		fli->fli_trans_cnt, fli->fli_cow_cnt, fli->fli_alias_cnt);
 		prefix[0] = '\0';
 	}
 }



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

2019-04-15 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Mon Apr 15 12:59:38 UTC 2019

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

Log Message:
Add support for fifos, character and block devices.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vfsops.c
cvs rdiff -u -r1.47 -r1.48 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c
cvs rdiff -u -r1.25 -r1.26 \
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_vfsops.c
diff -u src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vfsops.c:1.21 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vfsops.c:1.22
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vfsops.c:1.21	Mon Mar 18 09:22:14 2019
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vfsops.c	Mon Apr 15 12:59:38 2019
@@ -147,10 +147,14 @@ void zfs_init(void);
 void zfs_fini(void);
 
 extern const struct vnodeopv_desc zfs_vnodeop_opv_desc;
+extern const struct vnodeopv_desc zfs_specop_opv_desc;
+extern const struct vnodeopv_desc zfs_fifoop_opv_desc;
 extern const struct vnodeopv_desc zfs_sfsop_opv_desc;
 
 static const struct vnodeopv_desc * const zfs_vnodeop_descs[] = {
 	_vnodeop_opv_desc,
+	_specop_opv_desc,
+	_fifoop_opv_desc,
 	_sfsop_opv_desc,
 	NULL,
 };

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.47 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.48
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.47	Mon Mar 18 09:20:58 2019
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c	Mon Apr 15 12:59:38 2019
@@ -81,6 +81,7 @@
 
 #ifdef __NetBSD__
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -5072,16 +5073,39 @@ static int
 zfs_netbsd_read(void *v)
 {
 	struct vop_read_args *ap = v;
+	vnode_t *vp = ap->a_vp;
+	znode_t *zp = VTOZ(vp);
 
-	return (zfs_read(ap->a_vp, ap->a_uio, ioflags(ap->a_ioflag), ap->a_cred, NULL));
+	switch (vp->v_type) {
+	case VBLK:
+	case VCHR:
+		ZFS_ACCESSTIME_STAMP(zp->z_zfsvfs, zp);
+		return (VOCALL(spec_vnodeop_p, VOFFSET(vop_read), ap));
+	case VFIFO:
+		ZFS_ACCESSTIME_STAMP(zp->z_zfsvfs, zp);
+		return (VOCALL(fifo_vnodeop_p, VOFFSET(vop_read), ap));
+	}
+
+	return (zfs_read(vp, ap->a_uio, ioflags(ap->a_ioflag), ap->a_cred, NULL));
 }
 
 static int
 zfs_netbsd_write(void *v)
 {
 	struct vop_write_args *ap = v;
+	vnode_t *vp = ap->a_vp;
 
-	return (zfs_write(ap->a_vp, ap->a_uio, ioflags(ap->a_ioflag), ap->a_cred, NULL));
+	switch (vp->v_type) {
+	case VBLK:
+	case VCHR:
+		GOP_MARKUPDATE(vp, GOP_UPDATE_MODIFIED);
+		return (VOCALL(spec_vnodeop_p, VOFFSET(vop_write), ap));
+	case VFIFO:
+		GOP_MARKUPDATE(vp, GOP_UPDATE_MODIFIED);
+		return (VOCALL(fifo_vnodeop_p, VOFFSET(vop_write), ap));
+	}
+
+	return (zfs_write(vp, ap->a_uio, ioflags(ap->a_ioflag), ap->a_cred, NULL));
 }
 
 static int
@@ -5278,6 +5302,44 @@ zfs_netbsd_create(void *v)
 }
 
 static int
+zfs_netbsd_mknod(void *v)
+{
+	struct vop_mknod_v3_args /* {
+		struct vnode *a_dvp;
+		struct vnode **a_vpp;
+		struct componentname *a_cnp;
+		struct vattr *a_vap;
+	} */ *ap = v;
+	struct vnode *dvp = ap->a_dvp;
+	struct vnode **vpp = ap->a_vpp;
+	struct componentname *cnp = ap->a_cnp;
+	struct vattr *vap = ap->a_vap;
+	char *nm;
+	int mode;
+	int error;
+
+	KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE);
+
+	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, nm, vap, !EXCL, mode, vpp, cnp->cn_cred, NULL);
+
+	PNBUF_PUT(nm);
+
+	KASSERT((error == 0) == (*vpp != NULL));
+	KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE);
+	VOP_UNLOCK(*vpp, 0);
+
+	return (error);
+}
+
+static int
 zfs_netbsd_remove(void *v)
 {
 	struct vop_remove_v2_args /* {
@@ -6149,6 +6211,7 @@ const struct vnodeopv_entry_desc zfs_vno
 	{ _default_desc,		vn_default_error },
 	{ _lookup_desc,		zfs_netbsd_lookup },
 	{ _create_desc,		zfs_netbsd_create },
+	{ _mknod_desc,		zfs_netbsd_mknod },
 	{ _open_desc,		zfs_netbsd_open },
 	{ _close_desc,		zfs_netbsd_close },
 	{ _access_desc,		zfs_netbsd_access },
@@ -6185,4 +6248,87 @@ const struct vnodeopv_entry_desc zfs_vno
 const struct vnodeopv_desc zfs_vnodeop_opv_desc =
 	{ _vnodeop_p, zfs_vnodeop_entries };
 
+int (**zfs_specop_p)(void *);
+const struct vnodeopv_entry_desc zfs_specop_entries[] = {
+	{ _default_desc,		vn_default_error },
+	{ _lookup_desc,		spec_lookup },
+	{ _create_desc,		spec_create },
+	{ _mknod_desc,		spec_mknod },
+	{ _open_desc,		spec_open },
+	{ _close_desc,		spec_close },
+	{ _access_desc,		

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

2019-03-18 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Mon Mar 18 09:22:15 UTC 2019

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

Log Message:
Make ZFS exportable by NFS, implement zfsctl_vptofh(),
zfs_netbsd_vptofh() and zfs_netbsd_fhtovp().

Undo changes to now completely unused zfs_fhtovp().


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c
cvs rdiff -u -r1.20 -r1.21 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vfsops.c
cvs rdiff -u -r1.2 -r1.3 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/sys/zfs_ctldir.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_ctldir.c
diff -u src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c:1.8 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c:1.9
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c:1.8	Mon Mar 18 09:21:31 2019
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c	Mon Mar 18 09:22:14 2019
@@ -1885,6 +1885,33 @@ zfsctl_loadvnode(vfs_t *vfsp, vnode_t *v
 	return 0;
 }
 
+int
+zfsctl_vptofh(vnode_t *vp, fid_t *fidp, size_t *fh_size)
+{
+	struct sfs_node *node = VTOSFS(vp);
+	uint64_t object = node->sn_id;
+	zfid_short_t *zfid = (zfid_short_t *)fidp;
+	int i;
+
+	SFS_NODE_ASSERT(vp);
+
+	if (*fh_size < SHORT_FID_LEN) {
+		*fh_size = SHORT_FID_LEN;
+		return SET_ERROR(E2BIG);
+	}
+	*fh_size = SHORT_FID_LEN;
+
+	zfid->zf_len = SHORT_FID_LEN;
+	for (i = 0; i < sizeof(zfid->zf_object); i++)
+		zfid->zf_object[i] = (uint8_t)(object >> (8 * i));
+
+	/* .zfs nodes always have a generation number of 0 */
+	for (i = 0; i < sizeof(zfid->zf_gen); i++)
+		zfid->zf_gen[i] = 0;
+
+	return 0;
+}
+
 /*
  * Return the ".zfs" vnode.
  */

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.20 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vfsops.c:1.21
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vfsops.c:1.20	Mon Mar 18 09:20:58 2019
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vfsops.c	Mon Mar 18 09:22:14 2019
@@ -136,7 +136,8 @@ static int zfs_umount(vfs_t *vfsp, int f
 static int zfs_root(vfs_t *vfsp, int flags, vnode_t **vpp);
 static int zfs_netbsd_root(vfs_t *vfsp, vnode_t **vpp);
 static int zfs_statvfs(vfs_t *vfsp, struct statvfs *statp);
-static int zfs_fhtovp(vfs_t *vfsp, fid_t *fidp, vnode_t **vpp);
+static int zfs_netbsd_vptofh(vnode_t *vp, fid_t *fidp, size_t *fh_size);
+static int zfs_netbsd_fhtovp(vfs_t *vfsp, fid_t *fidp, vnode_t **vpp);
 static int zfs_vget(vfs_t *vfsp, ino_t ino, vnode_t **vpp);
 static int zfs_sync(vfs_t *vfsp, int waitfor);
 static int zfs_netbsd_sync(vfs_t *vfsp, int waitfor, cred_t *cr);
@@ -172,8 +173,8 @@ struct vfsops zfs_vfsops = {
 	.vfs_renamelock_enter = genfs_renamelock_enter,
 	.vfs_renamelock_exit = genfs_renamelock_exit,
 	.vfs_reinit = (void *)nullop,
-	.vfs_vptofh = (void *)eopnotsupp,
-	.vfs_fhtovp = (void *)eopnotsupp,
+	.vfs_vptofh = zfs_netbsd_vptofh,
+	.vfs_fhtovp = zfs_netbsd_fhtovp,
 	.vfs_quotactl = (void *)eopnotsupp,
 	.vfs_extattrctl = (void *)eopnotsupp,
 	.vfs_suspendctl = genfs_suspendctl,
@@ -254,6 +255,171 @@ zfs_netbsd_root(vfs_t *vfsp, vnode_t **v
 	return zfs_root(vfsp, LK_EXCLUSIVE | LK_RETRY, vpp);
 }
 
+static int
+zfs_netbsd_vptofh(vnode_t *vp, fid_t *fidp, size_t *fh_size)
+{
+	znode_t		*zp;
+	zfsvfs_t	*zfsvfs;
+	uint32_t	gen;
+	uint64_t	gen64;
+	uint64_t	object;
+	zfid_short_t	*zfid;
+	int		size, i, error;
+
+	if (zfsctl_is_node(vp))
+		return zfsctl_vptofh(vp, fidp, fh_size);
+
+	zp = VTOZ(vp);
+	zfsvfs = zp->z_zfsvfs;
+	object = zp->z_id;
+
+	ZFS_ENTER(zfsvfs);
+	ZFS_VERIFY_ZP(zp);
+
+	if ((error = sa_lookup(zp->z_sa_hdl, SA_ZPL_GEN(zfsvfs),
+	, sizeof (uint64_t))) != 0) {
+		ZFS_EXIT(zfsvfs);
+		return (error);
+	}
+
+	gen = (uint32_t)gen64;
+
+	size = (zfsvfs->z_parent != zfsvfs) ? LONG_FID_LEN : SHORT_FID_LEN;
+
+	if (*fh_size < size) {
+		ZFS_EXIT(zfsvfs);
+		*fh_size = size;
+		return SET_ERROR(E2BIG);
+	}
+	*fh_size = size;
+
+	zfid = (zfid_short_t *)fidp;
+
+	zfid->zf_len = size;
+
+	for (i = 0; i < sizeof (zfid->zf_object); i++)
+		zfid->zf_object[i] = (uint8_t)(object >> (8 * i));
+
+	/* Must have a non-zero generation number to distinguish from .zfs */
+	if (gen == 0)
+		gen = 1;
+	for (i = 0; i < sizeof (zfid->zf_gen); i++)
+		zfid->zf_gen[i] = (uint8_t)(gen >> (8 * i));
+
+	if (size == LONG_FID_LEN) {
+		uint64_t	objsetid = dmu_objset_id(zfsvfs->z_os);
+		zfid_long_t	*zlfid;
+
+		zlfid = (zfid_long_t *)fidp;
+
+		for (i = 0; i < sizeof (zlfid->zf_setid); i++)
+			zlfid->zf_setid[i] = (uint8_t)(objsetid >> (8 * i));
+
+		/* XXX - this should be the generation 

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

2019-03-18 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Mon Mar 18 09:21:31 UTC 2019

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

Log Message:
Implement zfsctl_lookup_objset() to look up "zfsvfs" of an mounted snapshot.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.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_ctldir.c
diff -u src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c:1.7 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c:1.8
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c:1.7	Mon Mar 18 09:20:58 2019
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c	Mon Mar 18 09:21:31 2019
@@ -1946,8 +1946,23 @@ zfsctl_destroy(zfsvfs_t *zfsvfs)
 int
 zfsctl_lookup_objset(vfs_t *vfsp, uint64_t objsetid, zfsvfs_t **zfsvfsp)
 {
+	struct sfs_node_key key = {
+		.parent_id = ZFSCTL_INO_SNAPDIR,
+		.id = objsetid
+	};
+	vnode_t *vp;
+	int error;
 
-	return EINVAL;
+	*zfsvfsp = NULL;
+	error = vcache_get(vfsp, , sizeof(key), );
+	if (error == 0) {
+		if (vp->v_mountedhere)
+			*zfsvfsp = vp->v_mountedhere->mnt_data;
+		vrele(vp);
+	}
+	if (*zfsvfsp == NULL)
+		return SET_ERROR(EINVAL);
+	return 0;
 }
 
 int



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

2019-03-18 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Mon Mar 18 09:20:58 UTC 2019

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

Log Message:
Set "mnt_stat.f_fsid" and "mnt_stat.f_fsidx" from the objset guid
like FreeBSD and Illumos do.

Use "f_fsid" for "va_fsid" and cheat NFSD to export snapshots under
".zfs" by setting these snaphots "f_fsidx" to the parents "f_fsidx".


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c
cvs rdiff -u -r1.19 -r1.20 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vfsops.c
cvs rdiff -u -r1.46 -r1.47 \
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_ctldir.c
diff -u src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c:1.6 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c:1.7
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c:1.6	Wed Feb 20 10:08:37 2019
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c	Mon Mar 18 09:20:58 2019
@@ -1335,7 +1335,9 @@ sfs_snapshot_mount(vnode_t *vp, const ch
 	if (error)
 		goto out;
 
-	vfs_getnewfsid(vfsp);
+	/* Set f_fsidx from parent to cheat NFSD. */
+	vfsp->mnt_stat.f_fsidx = vp->v_vfsp->mnt_stat.f_fsidx;
+
 	strlcpy(vfsp->mnt_stat.f_mntfromname, osname,
 	sizeof(vfsp->mnt_stat.f_mntfromname));
 	set_statvfs_info(path, UIO_SYSSPACE, vfsp->mnt_stat.f_mntfromname,
@@ -1622,7 +1624,7 @@ sfs_getattr(void *v)
 	vap->va_nlink = 2;
 	vap->va_uid = 0;
 	vap->va_gid = 0;
-	vap->va_fsid = vp->v_vfsp->mnt_stat.f_fsidx.__fsid_val[0];
+	vap->va_fsid = vp->v_vfsp->mnt_stat.f_fsid;
 	vap->va_fileid = node->sn_id;
 	vap->va_size = 0;
 	vap->va_blocksize = 0;

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.19 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vfsops.c:1.20
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vfsops.c:1.19	Tue Feb  5 09:54:36 2019
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vfsops.c	Mon Mar 18 09:20:58 2019
@@ -1374,7 +1374,9 @@ zfs_domount(vfs_t *vfsp, char *osname)
 #endif
 #ifdef __NetBSD__
 	vfsp->mnt_stat.f_fsidx.__fsid_val[0] = fsid_guid;
-	vfsp->mnt_stat.f_fsidx.__fsid_val[1] = fsid_guid >> 32;
+	vfsp->mnt_stat.f_fsidx.__fsid_val[1] = ((fsid_guid>>32) << 8) |
+	makefstype(vfsp->mnt_op->vfs_name) & 0xFF;
+	vfsp->mnt_stat.f_fsid = fsid_guid;
 #endif
 
 	/*
@@ -1962,8 +1964,6 @@ zfs_mount(vfs_t *vfsp, const char *path,
 #endif
 
 #ifdef __NetBSD__
-	vfs_getnewfsid(vfsp);
-
 	/* setup zfs mount info */
 	strlcpy(vfsp->mnt_stat.f_mntfromname, osname,
 	sizeof(vfsp->mnt_stat.f_mntfromname));
@@ -2036,7 +2036,8 @@ zfs_statvfs(vfs_t *vfsp, struct statvfs 
 	statp->f_fsid = d32;
 #endif
 #ifdef __NetBSD__
-	statp->f_fsid = vfsp->mnt_stat.f_fsidx.__fsid_val[0];
+	statp->f_fsid = vfsp->mnt_stat.f_fsid;
+	statp->f_fsidx = vfsp->mnt_stat.f_fsidx;
 #endif
 
 	/*

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.46 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.47
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.46	Mon Mar 18 09:20:15 2019
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c	Mon Mar 18 09:20:58 2019
@@ -3073,7 +3073,7 @@ zfs_getattr(vnode_t *vp, vattr_t *vap, i
 	vap->va_nodeid = zp->z_id;
 #endif
 #ifdef __NetBSD__
-	vap->va_fsid = vp->v_mount->mnt_stat.f_fsidx.__fsid_val[0];
+	vap->va_fsid = vp->v_mount->mnt_stat.f_fsid;
 	vap->va_nodeid = zp->z_id;
 	/*
 	 * If we are a snapshot mounted under .zfs, return



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

2019-03-18 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Mon Mar 18 09:20:15 UTC 2019

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

Log Message:
As zfs_netbsd_getpages() ignores "a_count" and processes exactly one page
return an error if "a_count != 1".


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 \
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.45 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.46
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.45	Mon Mar 18 09:19:39 2019
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c	Mon Mar 18 09:20:15 2019
@@ -5844,6 +5844,9 @@ zfs_netbsd_getpages(void *v)
 	if (async) {
 		return 0;
 	}
+	if (*ap->a_count != 1) {
+		return EBUSY;
+	}
 
 	ZFS_ENTER(zfsvfs);
 	ZFS_VERIFY_ZP(zp);



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

2019-03-18 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Mon Mar 18 09:19:39 UTC 2019

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

Log Message:
Change zfs_readdir() to use malloc() instead of kmem_alloc() to
allocate cookies.  Required by protocol, caller uses free().


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 \
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.44 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.45
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.44	Tue Feb  5 09:54:36 2019
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c	Mon Mar 18 09:19:39 2019
@@ -85,6 +85,7 @@
 #include 
 #include 
 #include 
+#include 
 
 uint_t zfs_putpage_key;
 #endif
@@ -2754,7 +2755,7 @@ zfs_readdir(vnode_t *vp, uio_t *uio, cre
 #endif
 #ifdef __NetBSD__
 		ncooks = uio->uio_resid / _DIRENT_MINSIZE(odp);
-		cooks = kmem_alloc(ncooks * sizeof(off_t), KM_SLEEP);
+		cooks = malloc(ncooks * sizeof(off_t), M_TEMP, M_WAITOK);
 #endif
 		*cookies = cooks;
 		*ncookies = ncooks;



CVS commit: src/sys/kern

2019-03-17 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sun Mar 17 10:14:52 UTC 2019

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

Log Message:
With TRYEMULROOT namei_getstartdir() gets used twice so have to
vrele() "ni_rootdir" and "ni_erootdir" on entry.


To generate a diff of this commit:
cvs rdiff -u -r1.209 -r1.210 src/sys/kern/vfs_lookup.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_lookup.c
diff -u src/sys/kern/vfs_lookup.c:1.209 src/sys/kern/vfs_lookup.c:1.210
--- src/sys/kern/vfs_lookup.c:1.209	Tue Mar 12 14:03:35 2019
+++ src/sys/kern/vfs_lookup.c	Sun Mar 17 10:14:52 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_lookup.c,v 1.209 2019/03/12 14:03:35 hannken Exp $	*/
+/*	$NetBSD: vfs_lookup.c,v 1.210 2019/03/17 10:14:52 hannken Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_lookup.c,v 1.209 2019/03/12 14:03:35 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_lookup.c,v 1.210 2019/03/17 10:14:52 hannken Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_magiclinks.h"
@@ -537,6 +537,13 @@ namei_getstartdir(struct namei_state *st
 	struct lwp *self = curlwp;	/* thread doing namei() */
 	struct vnode *rootdir, *erootdir, *curdir, *startdir;
 
+	if (state->root_referenced) {
+		vrele(state->ndp->ni_rootdir);
+		if (state->ndp->ni_erootdir != NULL)
+			vrele(state->ndp->ni_erootdir);
+		state->root_referenced = 0;
+	}
+
 	cwdi = self->l_proc->p_cwdi;
 	rw_enter(>cwdi_lock, RW_READER);
 
@@ -589,7 +596,6 @@ namei_getstartdir(struct namei_state *st
 	 * A multithreaded process may chroot during namei.
 	 */
 	vref(startdir);
-	KASSERT(! state->root_referenced);
 	vref(state->ndp->ni_rootdir);
 	if (state->ndp->ni_erootdir != NULL)
 		vref(state->ndp->ni_erootdir);



CVS commit: src/sys/kern

2019-03-12 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Tue Mar 12 14:03:35 UTC 2019

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

Log Message:
Take a reference on ndp->ni_rootdir and ndp->ni_erootdir.

A multithreaded process may chroot during namei() and we end up with
vn_under() trying to reference the now unreferenced ni_rootdir.

Ok: David Holland 

Reported-by: syzbot+889319cdf91a3d037...@syzkaller.appspotmail.com


To generate a diff of this commit:
cvs rdiff -u -r1.208 -r1.209 src/sys/kern/vfs_lookup.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_lookup.c
diff -u src/sys/kern/vfs_lookup.c:1.208 src/sys/kern/vfs_lookup.c:1.209
--- src/sys/kern/vfs_lookup.c:1.208	Sun Jul  9 22:48:44 2017
+++ src/sys/kern/vfs_lookup.c	Tue Mar 12 14:03:35 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_lookup.c,v 1.208 2017/07/09 22:48:44 dholland Exp $	*/
+/*	$NetBSD: vfs_lookup.c,v 1.209 2019/03/12 14:03:35 hannken Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_lookup.c,v 1.208 2017/07/09 22:48:44 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_lookup.c,v 1.209 2019/03/12 14:03:35 hannken Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_magiclinks.h"
@@ -469,6 +469,8 @@ struct namei_state {
 	int slashes;
 
 	unsigned attempt_retry:1;	/* true if error allows emul retry */
+	unsigned root_referenced:1;	/* true if ndp->ni_rootdir and
+	 ndp->ni_erootdir were referenced */
 };
 
 
@@ -486,6 +488,8 @@ namei_init(struct namei_state *state, st
 	state->rdonly = 0;
 	state->slashes = 0;
 
+	state->root_referenced = 0;
+
 	KASSERTMSG((state->cnp->cn_cred != NULL), "namei: bad cred/proc");
 	KASSERTMSG(((state->cnp->cn_nameiop & (~OPMASK)) == 0),
 	"namei: nameiop contaminated with flags: %08"PRIx32,
@@ -510,8 +514,11 @@ namei_cleanup(struct namei_state *state)
 {
 	KASSERT(state->cnp == >ndp->ni_cnd);
 
-	/* nothing for now */
-	(void)state;
+	if (state->root_referenced) {
+		vrele(state->ndp->ni_rootdir);
+		if (state->ndp->ni_erootdir != NULL)
+			vrele(state->ndp->ni_erootdir);
+	}
 }
 
 //
@@ -578,11 +585,15 @@ namei_getstartdir(struct namei_state *st
 	/*
 	 * Get a reference to the start dir so we can safely unlock cwdi.
 	 *
-	 * XXX: should we hold references to rootdir and erootdir while
-	 * we're running? What happens if a multithreaded process chroots
-	 * during namei?
+	 * Must hold references to rootdir and erootdir while we're running.
+	 * A multithreaded process may chroot during namei.
 	 */
 	vref(startdir);
+	KASSERT(! state->root_referenced);
+	vref(state->ndp->ni_rootdir);
+	if (state->ndp->ni_erootdir != NULL)
+		vref(state->ndp->ni_erootdir);
+	state->root_referenced = 1;
 
 	rw_exit(>cwdi_lock);
 	return startdir;
@@ -603,6 +614,9 @@ namei_getstartdir_for_nfsd(struct namei_
 	state->ndp->ni_erootdir = NULL;
 
 	vref(state->ndp->ni_atdir);
+	KASSERT(! state->root_referenced);
+	vref(state->ndp->ni_rootdir);
+	state->root_referenced = 1;
 	return state->ndp->ni_atdir;
 }
 



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

2019-03-09 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sat Mar  9 09:02:38 UTC 2019

Modified Files:
src/sys/rump/librump/rumpkern: emul.c lwproc.c

Log Message:
Rumpkernel has its own thread deallocation.  Add missing fstrans_lwp_dtor()
to lwproc_freelwp().

PR bin/50350: rump/rumpkern/t_sp/stress_{long,short} fail on Core 2 Quad


To generate a diff of this commit:
cvs rdiff -u -r1.189 -r1.190 src/sys/rump/librump/rumpkern/emul.c
cvs rdiff -u -r1.40 -r1.41 src/sys/rump/librump/rumpkern/lwproc.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/rumpkern/emul.c
diff -u src/sys/rump/librump/rumpkern/emul.c:1.189 src/sys/rump/librump/rumpkern/emul.c:1.190
--- src/sys/rump/librump/rumpkern/emul.c:1.189	Wed Dec  5 19:56:49 2018
+++ src/sys/rump/librump/rumpkern/emul.c	Sat Mar  9 09:02:38 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: emul.c,v 1.189 2018/12/05 19:56:49 christos Exp $	*/
+/*	$NetBSD: emul.c,v 1.190 2019/03/09 09:02:38 hannken Exp $	*/
 
 /*
  * Copyright (c) 2007-2011 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: emul.c,v 1.189 2018/12/05 19:56:49 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: emul.c,v 1.190 2019/03/09 09:02:38 hannken Exp $");
 
 #include 
 #include 
@@ -292,6 +292,15 @@ rump_fstrans_done(struct mount *mp)
 }
 __weak_alias(fstrans_done,rump_fstrans_done);
 
+
+void rump_fstrans_lwp_dtor(struct lwp *);
+void
+rump_fstrans_lwp_dtor(struct lwp *l)
+{
+
+}
+__weak_alias(fstrans_lwp_dtor,rump_fstrans_lwp_dtor);
+
 /*
  * Provide weak aliases for tty routines used by printf.
  * They will be used unless the rumpkern_tty component is present.

Index: src/sys/rump/librump/rumpkern/lwproc.c
diff -u src/sys/rump/librump/rumpkern/lwproc.c:1.40 src/sys/rump/librump/rumpkern/lwproc.c:1.41
--- src/sys/rump/librump/rumpkern/lwproc.c:1.40	Sun Apr 24 07:45:10 2016
+++ src/sys/rump/librump/rumpkern/lwproc.c	Sat Mar  9 09:02:38 2019
@@ -1,4 +1,4 @@
-/*  $NetBSD: lwproc.c,v 1.40 2016/04/24 07:45:10 martin Exp $	*/
+/*  $NetBSD: lwproc.c,v 1.41 2019/03/09 09:02:38 hannken Exp $	*/
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -28,11 +28,12 @@
 #define RUMP__CURLWP_PRIVATE
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lwproc.c,v 1.40 2016/04/24 07:45:10 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lwproc.c,v 1.41 2019/03/09 09:02:38 hannken Exp $");
 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -326,6 +327,7 @@ lwproc_freelwp(struct lwp *l)
 
 	if (l->l_name)
 		kmem_free(l->l_name, MAXCOMLEN);
+	fstrans_lwp_dtor(l);
 	lwp_finispecific(l);
 
 	lwproc_curlwpop(RUMPUSER_LWP_DESTROY, l);



CVS commit: src/sys/kern

2019-03-07 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Thu Mar  7 11:09:48 UTC 2019

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

Log Message:
Change vn_openchk() to fail VNON and VBAD with error ENXIO.

Reported-by: syzbot+d66b1be08516a4d2d...@syzkaller.appspotmail.com
Reported-by: syzbot+c5eaef5a8af535c3b...@syzkaller.appspotmail.com


To generate a diff of this commit:
cvs rdiff -u -r1.199 -r1.200 src/sys/kern/vfs_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/kern/vfs_vnops.c
diff -u src/sys/kern/vfs_vnops.c:1.199 src/sys/kern/vfs_vnops.c:1.200
--- src/sys/kern/vfs_vnops.c:1.199	Mon Feb  4 04:18:59 2019
+++ src/sys/kern/vfs_vnops.c	Thu Mar  7 11:09:48 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_vnops.c,v 1.199 2019/02/04 04:18:59 mrg Exp $	*/
+/*	$NetBSD: vfs_vnops.c,v 1.200 2019/03/07 11:09:48 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_vnops.c,v 1.199 2019/02/04 04:18:59 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_vnops.c,v 1.200 2019/03/07 11:09:48 hannken Exp $");
 
 #include "veriexec.h"
 
@@ -297,6 +297,9 @@ vn_openchk(struct vnode *vp, kauth_cred_
 	int permbits = 0;
 	int error;
 
+	if (vp->v_type == VNON || vp->v_type == VBAD)
+		return ENXIO;
+
 	if ((fflags & O_DIRECTORY) != 0 && vp->v_type != VDIR)
 		return ENOTDIR;
 



CVS commit: src/sys/kern

2019-03-07 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Thu Mar  7 11:09:10 UTC 2019

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

Log Message:
Change "fli_alias" to point to the corresponding "fstrans_lwp_info".

Fix fstrans_clear_lwp_info() list traversal, remove already advanced
the list pointer.


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 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.57 src/sys/kern/vfs_trans.c:1.58
--- src/sys/kern/vfs_trans.c:1.57	Fri Mar  1 09:02:03 2019
+++ src/sys/kern/vfs_trans.c	Thu Mar  7 11:09:10 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_trans.c,v 1.57 2019/03/01 09:02:03 hannken Exp $	*/
+/*	$NetBSD: vfs_trans.c,v 1.58 2019/03/07 11:09:10 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_trans.c,v 1.57 2019/03/01 09:02:03 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_trans.c,v 1.58 2019/03/07 11:09:10 hannken Exp $");
 
 /*
  * File system transaction operations.
@@ -68,7 +68,7 @@ struct fstrans_lwp_info {
 	struct fstrans_lwp_info *fli_succ;
 	struct lwp *fli_self;
 	struct mount *fli_mount;
-	struct mount *fli_alias;
+	struct fstrans_lwp_info *fli_alias;
 	struct fstrans_mount_info *fli_mountinfo;
 	int fli_trans_cnt;
 	int fli_cow_cnt;
@@ -296,7 +296,7 @@ fstrans_clear_lwp_info(void)
 	/*
 	 * Scan our list clearing entries whose mount is gone.
 	 */
-	for (p = >l_fstrans; *p; p = &(*p)->fli_succ) {
+	for (p = >l_fstrans; *p; ) {
 		fli = *p;
 		if (fli->fli_mount != NULL &&
 		fli->fli_mountinfo->fmi_gone &&
@@ -308,11 +308,15 @@ fstrans_clear_lwp_info(void)
 			fli->fli_mountinfo = NULL;
 			membar_sync();
 			fli->fli_self = NULL;
-
-			if (*p == NULL)
-break;
+		} else {
+			p = &(*p)->fli_succ;
 		}
 	}
+#ifdef DIAGNOSTIC
+	for (fli = curlwp->l_fstrans; fli; fli = fli->fli_succ)
+		if (fli->fli_alias != NULL)
+			KASSERT(fli->fli_alias->fli_self == curlwp);
+#endif /* DIAGNOSTIC */
 }
 
 /*
@@ -321,7 +325,7 @@ fstrans_clear_lwp_info(void)
 static struct fstrans_lwp_info *
 fstrans_alloc_lwp_info(struct mount *mp)
 {
-	struct fstrans_lwp_info *fli, *fli2;
+	struct fstrans_lwp_info *fli;
 	struct fstrans_mount_info *fmi;
 
 	for (fli = curlwp->l_fstrans; fli; fli = fli->fli_succ) {
@@ -373,10 +377,8 @@ fstrans_alloc_lwp_info(struct mount *mp)
 	mutex_exit(_mount_lock);
 
 	if (mp) {
-		fli2 = fstrans_alloc_lwp_info(mp);
-		fli->fli_alias = fli2->fli_mount;
-
-		fli = fli2;
+		fli->fli_alias = fstrans_alloc_lwp_info(mp);
+		fli = fli->fli_alias;
 	}
 
 	return fli;
@@ -388,22 +390,17 @@ fstrans_alloc_lwp_info(struct mount *mp)
 static inline struct fstrans_lwp_info *
 fstrans_get_lwp_info(struct mount *mp, bool do_alloc)
 {
-	struct fstrans_lwp_info *fli, *fli2;
+	struct fstrans_lwp_info *fli;
 
 	/*
 	 * Scan our list for a match.
 	 */
 	for (fli = curlwp->l_fstrans; fli; fli = fli->fli_succ) {
 		if (fli->fli_mount == mp) {
-			if (fli->fli_alias != NULL) {
-for (fli2 = curlwp->l_fstrans; fli2;
-fli2 = fli2->fli_succ) {
-	if (fli2->fli_mount == fli->fli_alias)
-		break;
-}
-KASSERT(fli2 != NULL);
-fli = fli2;
-			}
+			KASSERT((mp->mnt_lower == NULL) ==
+			(fli->fli_alias == NULL));
+			if (fli->fli_alias != NULL)
+fli = fli->fli_alias;
 			break;
 		}
 	}
@@ -943,9 +940,17 @@ fstrans_print_lwp(struct proc *p, struct
 			printf(" (%s)", fli->fli_mount->mnt_stat.f_mntonname);
 		else
 			printf(" NULL");
-		if (fli->fli_alias != NULL)
-			printf(" alias (%s)",
-			fli->fli_alias->mnt_stat.f_mntonname);
+		if (fli->fli_alias != NULL) {
+			struct mount *amp = fli->fli_alias->fli_mount;
+
+			printf(" alias");
+			if (verbose)
+printf(" @%p", fli->fli_alias);
+			if (amp == NULL)
+printf(" NULL");
+			else
+printf(" (%s)", amp->mnt_stat.f_mntonname);
+		}
 		if (fli->fli_mountinfo && fli->fli_mountinfo->fmi_gone)
 			printf(" gone");
 		if (fli->fli_trans_cnt == 0) {



CVS commit: src/sys

2019-03-01 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Fri Mar  1 09:02:03 UTC 2019

Modified Files:
src/sys/kern: kern_exit.c kern_lwp.c vfs_trans.c
src/sys/sys: fstrans.h lwp.h

Log Message:
Move pointer to fstrans private data into "struct lwp".

Ride NetBSD 8.99.35


To generate a diff of this commit:
cvs rdiff -u -r1.273 -r1.274 src/sys/kern/kern_exit.c
cvs rdiff -u -r1.195 -r1.196 src/sys/kern/kern_lwp.c
cvs rdiff -u -r1.56 -r1.57 src/sys/kern/vfs_trans.c
cvs rdiff -u -r1.12 -r1.13 src/sys/sys/fstrans.h
cvs rdiff -u -r1.180 -r1.181 src/sys/sys/lwp.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/kern_exit.c
diff -u src/sys/kern/kern_exit.c:1.273 src/sys/kern/kern_exit.c:1.274
--- src/sys/kern/kern_exit.c:1.273	Thu Nov 29 12:37:22 2018
+++ src/sys/kern/kern_exit.c	Fri Mar  1 09:02:03 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_exit.c,v 1.273 2018/11/29 12:37:22 maxv Exp $	*/
+/*	$NetBSD: kern_exit.c,v 1.274 2019/03/01 09:02:03 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1998, 1999, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.273 2018/11/29 12:37:22 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.274 2019/03/01 09:02:03 hannken Exp $");
 
 #include "opt_ktrace.h"
 #include "opt_dtrace.h"
@@ -84,6 +84,7 @@ __KERNEL_RCSID(0, "$NetBSD: kern_exit.c,
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -400,6 +401,9 @@ exit1(struct lwp *l, int exitcode, int s
 	}
 	fixjobc(p, p->p_pgrp, 0);
 
+	/* Release fstrans private data. */
+	fstrans_lwp_dtor(l);
+
 	/*
 	 * Finalize the last LWP's specificdata, as well as the
 	 * specificdata for the proc itself.

Index: src/sys/kern/kern_lwp.c
diff -u src/sys/kern/kern_lwp.c:1.195 src/sys/kern/kern_lwp.c:1.196
--- src/sys/kern/kern_lwp.c:1.195	Mon Nov 26 17:18:01 2018
+++ src/sys/kern/kern_lwp.c	Fri Mar  1 09:02:03 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_lwp.c,v 1.195 2018/11/26 17:18:01 skrll Exp $	*/
+/*	$NetBSD: kern_lwp.c,v 1.196 2019/03/01 09:02:03 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -211,7 +211,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.195 2018/11/26 17:18:01 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.196 2019/03/01 09:02:03 hannken Exp $");
 
 #include "opt_ddb.h"
 #include "opt_lockdebug.h"
@@ -236,6 +236,7 @@ __KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -1093,6 +1094,9 @@ lwp_exit(struct lwp *l)
 	/* Drop filedesc reference. */
 	fd_free();
 
+	/* Release fstrans private data. */
+	fstrans_lwp_dtor(l);
+
 	/* Delete the specificdata while it's still safe to sleep. */
 	lwp_finispecific(l);
 

Index: src/sys/kern/vfs_trans.c
diff -u src/sys/kern/vfs_trans.c:1.56 src/sys/kern/vfs_trans.c:1.57
--- src/sys/kern/vfs_trans.c:1.56	Sun Feb 24 16:11:24 2019
+++ src/sys/kern/vfs_trans.c	Fri Mar  1 09:02:03 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_trans.c,v 1.56 2019/02/24 16:11:24 hannken Exp $	*/
+/*	$NetBSD: vfs_trans.c,v 1.57 2019/03/01 09:02:03 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_trans.c,v 1.56 2019/02/24 16:11:24 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_trans.c,v 1.57 2019/03/01 09:02:03 hannken Exp $");
 
 /*
  * File system transaction operations.
@@ -84,7 +84,6 @@ struct fstrans_mount_info {
 	struct mount *fmi_mount;
 };
 
-static specificdata_key_t lwp_data_key;	/* Our specific data key. */
 static kmutex_t vfs_suspend_lock;	/* Serialize suspensions. */
 static kmutex_t fstrans_lock;		/* Fstrans big lock. */
 static kmutex_t fstrans_mount_lock;	/* Fstrans mount big lock. */
@@ -95,7 +94,6 @@ static LIST_HEAD(fstrans_lwp_head, fstra
 	/* List of all fstrans_lwp_info. */
 static int fstrans_gone_count;		/* Number of fstrans_mount_info gone. */
 
-static void fstrans_lwp_dtor(void *);
 static void fstrans_mount_dtor(struct fstrans_mount_info *);
 static void fstrans_clear_lwp_info(void);
 static inline struct fstrans_lwp_info *
@@ -180,10 +178,6 @@ fstrans_debug_validate_mount(struct moun
 void
 fstrans_init(void)
 {
-	int error __diagused;
-
-	error = lwp_specific_key_create(_data_key, fstrans_lwp_dtor);
-	KASSERT(error == 0);
 
 	mutex_init(_suspend_lock, MUTEX_DEFAULT, IPL_NONE);
 	mutex_init(_lock, MUTEX_DEFAULT, IPL_NONE);
@@ -197,14 +191,15 @@ fstrans_init(void)
 /*
  * Deallocate lwp state.
  */
-static void
-fstrans_lwp_dtor(void *arg)
+void
+fstrans_lwp_dtor(lwp_t *l)
 {
 	struct fstrans_lwp_info *fli, *fli_next;
 
-	for (fli = arg; fli; fli = fli_next) {
+	for (fli = l->l_fstrans; fli; fli = fli_next) {
 		KASSERT(fli->fli_trans_cnt == 0);
 		KASSERT(fli->fli_cow_cnt == 0);
+		KASSERT(fli->fli_self == l);
 		if 

CVS commit: src/sys/kern

2019-02-24 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sun Feb 24 16:11:24 UTC 2019

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

Log Message:
Clear per-lwp entries whose mount is gone before the first return
from fstrans_done().

No longer leaks "struct mount" forever.


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 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.55 src/sys/kern/vfs_trans.c:1.56
--- src/sys/kern/vfs_trans.c:1.55	Thu Feb 21 08:52:53 2019
+++ src/sys/kern/vfs_trans.c	Sun Feb 24 16:11:24 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_trans.c,v 1.55 2019/02/21 08:52:53 hannken Exp $	*/
+/*	$NetBSD: vfs_trans.c,v 1.56 2019/02/24 16:11:24 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_trans.c,v 1.55 2019/02/21 08:52:53 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_trans.c,v 1.56 2019/02/24 16:11:24 hannken Exp $");
 
 /*
  * File system transaction operations.
@@ -543,6 +543,9 @@ fstrans_done(struct mount *mp)
 		return;
 	}
 
+	if (__predict_false(fstrans_gone_count > 0))
+		fstrans_clear_lwp_info();
+
 	s = pserialize_read_enter();
 	if (__predict_true(fmi->fmi_state == FSTRANS_NORMAL)) {
 		fli->fli_trans_cnt = 0;
@@ -552,9 +555,6 @@ fstrans_done(struct mount *mp)
 	}
 	pserialize_read_exit(s);
 
-	if (__predict_false(fstrans_gone_count > 0))
-		fstrans_clear_lwp_info();
-
 	mutex_enter(_lock);
 	fli->fli_trans_cnt = 0;
 	cv_signal(_count_cv);



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

2019-02-22 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Fri Feb 22 09:01:32 UTC 2019

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

Log Message:
Always set "cn_namelen" in addition to "cn_nameptr".

Fix vnode locking for REMOVE, RMDIR and RENAME.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_replay.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_replay.c
diff -u src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_replay.c:1.11 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_replay.c:1.12
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_replay.c:1.11	Mon May 28 21:05:07 2018
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_replay.c	Fri Feb 22 09:01:32 2019
@@ -501,6 +501,9 @@ zfs_replay_create(zfsvfs_t *zfsvfs, lr_c
 			name = (char *)start;
 
 		cn.cn_nameptr = name;
+#ifdef __NetBSD__
+		cn.cn_namelen = strlen(name);
+#endif
 		error = VOP_CREATE(ZTOV(dzp), , , _vattr /*,vflg*/);
 		break;
 	case TX_MKDIR_ATTR:
@@ -519,6 +522,9 @@ zfs_replay_create(zfsvfs_t *zfsvfs, lr_c
 			name = (char *)(lr + 1);
 
 		cn.cn_nameptr = name;
+#ifdef __NetBSD__
+		cn.cn_namelen = strlen(name);
+#endif
 		error = VOP_MKDIR(ZTOV(dzp), , , _vattr /*,vflg*/);
 		break;
 	case TX_MKXATTR:
@@ -528,6 +534,9 @@ zfs_replay_create(zfsvfs_t *zfsvfs, lr_c
 		name = (char *)(lr + 1);
 		link = name + strlen(name) + 1;
 		cn.cn_nameptr = name;
+#ifdef __NetBSD__
+		cn.cn_namelen = strlen(name);
+#endif
 		error = VOP_SYMLINK(ZTOV(dzp), , , _vattr, link /*,vflg*/);
 		break;
 	default:
@@ -585,7 +594,7 @@ zfs_replay_remove(zfsvfs_t *zfsvfs, lr_r
 		goto fail;
 	}
 #ifdef __NetBSD__
-	VOP_UNLOCK(vp, 0);
+	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
 #endif
 
 	switch ((int)lr->lr_common.lrc_txtype) {
@@ -596,11 +605,12 @@ zfs_replay_remove(zfsvfs_t *zfsvfs, lr_r
 		error = VOP_RMDIR(ZTOV(dzp), vp,  /*,vflg*/);
 		break;
 	default:
+#ifdef __NetBSD__
+		vput(vp);
+#endif
 		error = SET_ERROR(ENOTSUP);
 	}
-#ifdef __NetBSD__
-	vrele(vp);
-#else
+#ifndef __NetBSD__
 	vput(vp);
 #endif
 	VOP_UNLOCK(ZTOV(dzp), 0);
@@ -635,6 +645,9 @@ zfs_replay_link(zfsvfs_t *zfsvfs, lr_lin
 		vflg |= FIGNORECASE;
 
 	cn.cn_nameptr = name;
+#ifdef __NetBSD__
+	cn.cn_namelen = strlen(name);
+#endif
 	cn.cn_cred = kcred;
 #ifndef __NetBSD__
 	cn.cn_thread = curthread;
@@ -698,7 +711,9 @@ zfs_replay_rename(zfsvfs_t *zfsvfs, lr_r
 	VOP_UNLOCK(ZTOV(sdzp), 0);
 	if (error != 0)
 		goto fail;
+#ifndef __NetBSD__
 	VOP_UNLOCK(svp, 0);
+#endif
 
 	tcn.cn_nameptr = tname;
 	tcn.cn_namelen = strlen(tname);
@@ -718,7 +733,8 @@ zfs_replay_rename(zfsvfs_t *zfsvfs, lr_r
 		goto fail;
 	}
 #ifdef __NetBSD__
-	vn_lock(tvp, LK_EXCLUSIVE | LK_RETRY);
+	if (tvp != NULL)
+		vn_lock(tvp, LK_EXCLUSIVE | LK_RETRY);
 #endif
 
 	error = VOP_RENAME(ZTOV(sdzp), svp, , ZTOV(tdzp), tvp,  /*,vflg*/);



CVS commit: src/sys/kern

2019-02-21 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Thu Feb 21 08:52:53 UTC 2019

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

Log Message:
Fix bad assertion: vfs_suspend(dead_rootmount) may happen and
must return EOPNOTSUPP.


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 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.54 src/sys/kern/vfs_trans.c:1.55
--- src/sys/kern/vfs_trans.c:1.54	Wed Feb 20 10:09:45 2019
+++ src/sys/kern/vfs_trans.c	Thu Feb 21 08:52:53 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_trans.c,v 1.54 2019/02/20 10:09:45 hannken Exp $	*/
+/*	$NetBSD: vfs_trans.c,v 1.55 2019/02/21 08:52:53 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_trans.c,v 1.54 2019/02/20 10:09:45 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_trans.c,v 1.55 2019/02/21 08:52:53 hannken Exp $");
 
 /*
  * File system transaction operations.
@@ -677,7 +677,8 @@ vfs_suspend(struct mount *mp, int nowait
 	struct fstrans_lwp_info *fli;
 	int error;
 
-	KASSERT(mp != dead_rootmount);
+	if (mp == dead_rootmount)
+		return EOPNOTSUPP;
 
 	fli = fstrans_get_lwp_info(mp, true);
 	mp = fli->fli_mount;



CVS commit: src/sys/kern

2019-02-20 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed Feb 20 10:09:45 UTC 2019

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

Log Message:
- Make the fstrans mount info part of the per-lwp state and replace
  most accesses to the mount with fstrans mount info.

- Add "fmi_gone" to be true after unmount and add a counter of
  outstanding mount infos so fstrans_clear_lwp_info() only runs
  if there may be something to do.

- Move lookup of base mounts into per-lwp state.

- Keep a list of valid mounts for DIAGNOSTIC checks.


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 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.53 src/sys/kern/vfs_trans.c:1.54
--- src/sys/kern/vfs_trans.c:1.53	Wed Feb 20 10:08:37 2019
+++ src/sys/kern/vfs_trans.c	Wed Feb 20 10:09:45 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_trans.c,v 1.53 2019/02/20 10:08:37 hannken Exp $	*/
+/*	$NetBSD: vfs_trans.c,v 1.54 2019/02/20 10:09:45 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_trans.c,v 1.53 2019/02/20 10:08:37 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_trans.c,v 1.54 2019/02/20 10:09:45 hannken Exp $");
 
 /*
  * File system transaction operations.
@@ -68,6 +68,8 @@ struct fstrans_lwp_info {
 	struct fstrans_lwp_info *fli_succ;
 	struct lwp *fli_self;
 	struct mount *fli_mount;
+	struct mount *fli_alias;
+	struct fstrans_mount_info *fli_mountinfo;
 	int fli_trans_cnt;
 	int fli_cow_cnt;
 	enum fstrans_lock_type fli_lock_type;
@@ -76,8 +78,10 @@ struct fstrans_lwp_info {
 struct fstrans_mount_info {
 	enum fstrans_state fmi_state;
 	unsigned int fmi_ref_cnt;
+	bool fmi_gone;
 	bool fmi_cow_change;
 	LIST_HEAD(, fscow_handler) fmi_cow_handler;
+	struct mount *fmi_mount;
 };
 
 static specificdata_key_t lwp_data_key;	/* Our specific data key. */
@@ -89,23 +93,87 @@ static kcondvar_t fstrans_count_cv;	/* F
 static pserialize_t fstrans_psz;	/* Pserialize state. */
 static LIST_HEAD(fstrans_lwp_head, fstrans_lwp_info) fstrans_fli_head;
 	/* List of all fstrans_lwp_info. */
+static int fstrans_gone_count;		/* Number of fstrans_mount_info gone. */
 
-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_mount_dtor(struct fstrans_mount_info *);
 static void fstrans_clear_lwp_info(void);
 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 *);
-static bool cow_state_change_done(const struct mount *);
-static void cow_change_enter(const struct mount *);
-static void cow_change_done(const struct mount *);
+static bool state_change_done(const struct fstrans_mount_info *);
+static bool cow_state_change_done(const struct fstrans_mount_info *);
+static void cow_change_enter(struct fstrans_mount_info *);
+static void cow_change_done(struct fstrans_mount_info *);
 
 extern struct mount *dead_rootmount;
 
+#if defined(DIAGNOSTIC)
+
+struct fstrans_debug_mount {
+	struct mount *fdm_mount;
+	SLIST_ENTRY(fstrans_debug_mount) fdm_list;
+};
+
+static SLIST_HEAD(, fstrans_debug_mount) fstrans_debug_mount_head =
+SLIST_HEAD_INITIALIZER(fstrans_debug_mount_head);
+
+static void
+fstrans_debug_mount(struct mount *mp)
+{
+	struct fstrans_debug_mount *fdm, *new;
+
+	KASSERT(mutex_owned(_mount_lock));
+
+	mutex_exit(_mount_lock);
+	new = kmem_alloc(sizeof(*new), KM_SLEEP);
+	new->fdm_mount = mp;
+	mutex_enter(_mount_lock);
+
+	SLIST_FOREACH(fdm, _debug_mount_head, fdm_list)
+		KASSERT(fdm->fdm_mount != mp);
+	SLIST_INSERT_HEAD(_debug_mount_head, new, fdm_list);
+}
+
+static void
+fstrans_debug_unmount(struct mount *mp)
+{
+	struct fstrans_debug_mount *fdm;
+
+	KASSERT(mutex_owned(_mount_lock));
+
+	SLIST_FOREACH(fdm, _debug_mount_head, fdm_list)
+		if (fdm->fdm_mount == mp)
+			break;
+	KASSERT(fdm != NULL);
+	SLIST_REMOVE(_debug_mount_head, fdm,
+	fstrans_debug_mount, fdm_list);
+	kmem_free(fdm, sizeof(*fdm));
+}
+
+static void
+fstrans_debug_validate_mount(struct mount *mp)
+{
+	struct fstrans_debug_mount *fdm;
+
+	KASSERT(mutex_owned(_mount_lock));
+
+	SLIST_FOREACH(fdm, _debug_mount_head, fdm_list)
+		if (fdm->fdm_mount == mp)
+			break;
+	KASSERTMSG(fdm != NULL, "mount %p invalid", mp);
+}
+
+#else /* defined(DIAGNOSTIC) */
+
+#define fstrans_debug_mount(mp)
+#define fstrans_debug_unmount(mp)
+#define fstrans_debug_validate_mount(mp)
+
+#endif  /* defined(DIAGNOSTIC) */
+
 /*
  * Initialize.
  */
@@ -127,21 +195,6 

CVS commit: src

2019-02-20 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed Feb 20 10:08:38 UTC 2019

Modified Files:
src/external/cddl/osnet/dist/uts/common/fs/zfs: zfs_ctldir.c
src/sys/kern: vfs_mount.c vfs_trans.c

Log Message:
Move fstrans_unmount() to vfs_rele(), just before it would free the mount.
Don't take a mount reference for fstrans as it gets notified about the release.

Defer the final free of the mount to fstrans_mount_dtor() when fstrans
has released all references to this mount.  Prevents the mount's memory
to be reused as a new mount before fstrans released all references.

Address PR kern/53928 modules/t_builtin:disable test case randomly fails.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c
cvs rdiff -u -r1.69 -r1.70 src/sys/kern/vfs_mount.c
cvs rdiff -u -r1.52 -r1.53 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/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c
diff -u src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c:1.5 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c:1.6
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c:1.5	Tue Feb  5 09:55:48 2019
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c	Wed Feb 20 10:08:37 2019
@@ -1261,7 +1261,6 @@ zfsctl_umount_snapshots(vfs_t *vfsp, int
 
 #ifdef __NetBSD__
 
-#include 
 #include 
 #include 
 #include 
@@ -1354,7 +1353,6 @@ sfs_snapshot_mount(vnode_t *vp, const ch
 out:;
 	if (error && vfsp) {
 		mutex_exit(>mnt_updating);
-		fstrans_unmount(vfsp);
 		vfs_rele(vfsp);
 	}
 	PNBUF_PUT(osname);

Index: src/sys/kern/vfs_mount.c
diff -u src/sys/kern/vfs_mount.c:1.69 src/sys/kern/vfs_mount.c:1.70
--- src/sys/kern/vfs_mount.c:1.69	Wed Feb 20 10:07:27 2019
+++ src/sys/kern/vfs_mount.c	Wed Feb 20 10:08:37 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_mount.c,v 1.69 2019/02/20 10:07:27 hannken Exp $	*/
+/*	$NetBSD: vfs_mount.c,v 1.70 2019/02/20 10:08:37 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1997-2011 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.69 2019/02/20 10:07:27 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.70 2019/02/20 10:08:37 hannken Exp $");
 
 #include 
 #include 
@@ -297,7 +297,13 @@ vfs_rele(struct mount *mp)
 	if (mp->mnt_op != NULL) {
 		vfs_delref(mp->mnt_op);
 	}
-	kmem_free(mp, sizeof(*mp));
+	fstrans_unmount(mp);
+	/*
+	 * Final free of mp gets done from fstrans_mount_dtor().
+	 *
+	 * Prevents this memory to be reused as a mount before
+	 * fstrans releases all references to it.
+	 */
 }
 
 /*
@@ -818,7 +824,6 @@ err_mounted:
 err_unmounted:
 	vp->v_mountedhere = NULL;
 	mutex_exit(>mnt_updating);
-	fstrans_unmount(mp);
 	vfs_rele(mp);
 
 	return error;
@@ -906,7 +911,6 @@ dounmount(struct mount *mp, int flags, s
 		panic("unmount: dangling vnode");
 	vfs_hooks_unmount(mp);
 
-	fstrans_unmount(mp);
 	vfs_rele(mp);	/* reference from mount() */
 	if (coveredvp != NULLVP) {
 		vrele(coveredvp);

Index: src/sys/kern/vfs_trans.c
diff -u src/sys/kern/vfs_trans.c:1.52 src/sys/kern/vfs_trans.c:1.53
--- src/sys/kern/vfs_trans.c:1.52	Wed Feb 20 10:07:27 2019
+++ src/sys/kern/vfs_trans.c	Wed Feb 20 10:08:37 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_trans.c,v 1.52 2019/02/20 10:07:27 hannken Exp $	*/
+/*	$NetBSD: vfs_trans.c,v 1.53 2019/02/20 10:08:37 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_trans.c,v 1.52 2019/02/20 10:07:27 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_trans.c,v 1.53 2019/02/20 10:08:37 hannken Exp $");
 
 /*
  * File system transaction operations.
@@ -186,8 +186,8 @@ fstrans_mount_dtor(struct mount *mp)
 
 	mutex_exit(_mount_lock);
 
+	kmem_free(mp, sizeof(*mp));
 	kmem_free(fmi, sizeof(*fmi));
-	vfs_rele(mp);
 }
 
 /*
@@ -208,8 +208,6 @@ fstrans_mount(struct mount *mp)
 	mp->mnt_transinfo = newfmi;
 	mutex_exit(_mount_lock);
 
-	vfs_ref(mp);
-
 	return 0;
 }
 
@@ -719,8 +717,11 @@ fscow_establish(struct mount *mp, int (*
 
 	KASSERT(mp != dead_rootmount);
 
+	mutex_enter(_mount_lock);
 	fmi = mp->mnt_transinfo;
 	KASSERT(fmi != NULL);
+	fmi->fmi_ref_cnt += 1;
+	mutex_exit(_mount_lock);
 
 	newch = kmem_alloc(sizeof(*newch), KM_SLEEP);
 	newch->ch_func = func;
@@ -758,6 +759,8 @@ fscow_disestablish(struct mount *mp, int
 	}
 	cow_change_done(mp);
 
+	fstrans_mount_dtor(mp);
+
 	return hp ? 0 : EINVAL;
 }
 



CVS commit: src/sys

2019-02-20 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed Feb 20 10:07:27 UTC 2019

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

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

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


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

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

Modified files:

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

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

Index: src/sys/kern/vfs_trans.c
diff -u src/sys/kern/vfs_trans.c:1.51 src/sys/kern/vfs_trans.c:1.52
--- src/sys/kern/vfs_trans.c:1.51	Fri Oct  5 09:51:55 2018
+++ src/sys/kern/vfs_trans.c	Wed Feb 20 10:07:27 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_trans.c,v 1.51 2018/10/05 09:51:55 hannken Exp $	*/
+/*	$NetBSD: vfs_trans.c,v 1.52 2019/02/20 10:07:27 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_trans.c,v 1.51 2018/10/05 09:51:55 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_trans.c,v 1.52 2019/02/20 10:07:27 hannken Exp $");
 
 /*
  * File system transaction operations.
@@ -104,6 +104,8 @@ static bool cow_state_change_done(const 
 static void cow_change_enter(const struct mount *);
 static void cow_change_done(const struct mount *);
 
+extern struct mount *dead_rootmount;
+
 /*
  * Initialize.
  */
@@ -136,8 +138,6 @@ fstrans_normalize_mount(struct mount *mp
 		mp = mp->mnt_lower;
 	if (mp == NULL)
 		return NULL;
-	if ((mp->mnt_iflag & IMNT_HAS_TRANS) == 0)
-		return NULL;
 	return mp;
 }
 
@@ -182,7 +182,6 @@ fstrans_mount_dtor(struct mount *mp)
 	KASSERT(fmi->fmi_state == FSTRANS_NORMAL);
 	KASSERT(LIST_FIRST(>fmi_cow_handler) == NULL);
 
-	mp->mnt_iflag &= ~IMNT_HAS_TRANS;
 	mp->mnt_transinfo = NULL;
 
 	mutex_exit(_mount_lock);
@@ -207,7 +206,6 @@ fstrans_mount(struct mount *mp)
 
 	mutex_enter(_mount_lock);
 	mp->mnt_transinfo = newfmi;
-	mp->mnt_iflag |= IMNT_HAS_TRANS;
 	mutex_exit(_mount_lock);
 
 	vfs_ref(mp);
@@ -222,9 +220,6 @@ void
 fstrans_unmount(struct mount *mp)
 {
 
-	if ((mp->mnt_iflag & IMNT_HAS_TRANS) == 0)
-		return;

CVS commit: src/sys

2019-02-20 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed Feb 20 10:06:00 UTC 2019

Modified Files:
src/sys/fs/union: union_vfsops.c
src/sys/miscfs/nullfs: null_vfsops.c
src/sys/miscfs/overlay: overlay_vfsops.c
src/sys/miscfs/umapfs: umap_vfsops.c

Log Message:
Set "mnt_lower" before the first file system operation on the new file system.


To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.79 src/sys/fs/union/union_vfsops.c
cvs rdiff -u -r1.94 -r1.95 src/sys/miscfs/nullfs/null_vfsops.c
cvs rdiff -u -r1.67 -r1.68 src/sys/miscfs/overlay/overlay_vfsops.c
cvs rdiff -u -r1.99 -r1.100 src/sys/miscfs/umapfs/umap_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/union/union_vfsops.c
diff -u src/sys/fs/union/union_vfsops.c:1.78 src/sys/fs/union/union_vfsops.c:1.79
--- src/sys/fs/union/union_vfsops.c:1.78	Sat Apr  1 19:35:56 2017
+++ src/sys/fs/union/union_vfsops.c	Wed Feb 20 10:05:59 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: union_vfsops.c,v 1.78 2017/04/01 19:35:56 riastradh Exp $	*/
+/*	$NetBSD: union_vfsops.c,v 1.79 2019/02/20 10:05:59 hannken Exp $	*/
 
 /*
  * Copyright (c) 1994 The Regents of the University of California.
@@ -77,7 +77,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: union_vfsops.c,v 1.78 2017/04/01 19:35:56 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: union_vfsops.c,v 1.79 2019/02/20 10:05:59 hannken Exp $");
 
 #include 
 #include 
@@ -246,14 +246,13 @@ union_mount(struct mount *mp, const char
 
 	mp->mnt_data = um;
 	vfs_getnewfsid(mp);
+	mp->mnt_lower = um->um_uppervp->v_mount;
 
 	error = set_statvfs_info( path, UIO_USERSPACE, NULL, UIO_USERSPACE,
 	mp->mnt_op->vfs_name, mp, l);
 	if (error)
 		goto bad;
 
-	mp->mnt_lower = um->um_uppervp->v_mount;
-
 	switch (um->um_op) {
 	case UNMNT_ABOVE:
 		cp = ":";

Index: src/sys/miscfs/nullfs/null_vfsops.c
diff -u src/sys/miscfs/nullfs/null_vfsops.c:1.94 src/sys/miscfs/nullfs/null_vfsops.c:1.95
--- src/sys/miscfs/nullfs/null_vfsops.c:1.94	Tue Apr 11 07:51:37 2017
+++ src/sys/miscfs/nullfs/null_vfsops.c	Wed Feb 20 10:06:00 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: null_vfsops.c,v 1.94 2017/04/11 07:51:37 hannken Exp $	*/
+/*	$NetBSD: null_vfsops.c,v 1.95 2019/02/20 10:06:00 hannken Exp $	*/
 
 /*
  * Copyright (c) 1999 National Aeronautics & Space Administration
@@ -76,7 +76,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: null_vfsops.c,v 1.94 2017/04/11 07:51:37 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: null_vfsops.c,v 1.95 2019/02/20 10:06:00 hannken Exp $");
 
 #include 
 #include 
@@ -146,6 +146,7 @@ nullfs_mount(struct mount *mp, const cha
 	 * that the node create call will work.
 	 */
 	vfs_getnewfsid(mp);
+	mp->mnt_lower = lowerrootvp->v_mount;
 
 	nmp->nullm_size = sizeof(struct null_node);
 	nmp->nullm_tag = VT_NULL;
@@ -175,7 +176,6 @@ nullfs_mount(struct mount *mp, const cha
 	if (error)
 		return error;
 
-	mp->mnt_lower = lowerrootvp->v_mount;
 	if (mp->mnt_lower->mnt_flag & MNT_LOCAL)
 		mp->mnt_flag |= MNT_LOCAL;
 	return 0;

Index: src/sys/miscfs/overlay/overlay_vfsops.c
diff -u src/sys/miscfs/overlay/overlay_vfsops.c:1.67 src/sys/miscfs/overlay/overlay_vfsops.c:1.68
--- src/sys/miscfs/overlay/overlay_vfsops.c:1.67	Tue Apr 11 07:51:37 2017
+++ src/sys/miscfs/overlay/overlay_vfsops.c	Wed Feb 20 10:06:00 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: overlay_vfsops.c,v 1.67 2017/04/11 07:51:37 hannken Exp $	*/
+/*	$NetBSD: overlay_vfsops.c,v 1.68 2019/02/20 10:06:00 hannken Exp $	*/
 
 /*
  * Copyright (c) 1999, 2000 National Aeronautics & Space Administration
@@ -74,7 +74,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: overlay_vfsops.c,v 1.67 2017/04/11 07:51:37 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: overlay_vfsops.c,v 1.68 2019/02/20 10:06:00 hannken Exp $");
 
 #include 
 #include 
@@ -155,6 +155,7 @@ ov_mount(struct mount *mp, const char *p
 	 * that the node create call will work.
 	 */
 	vfs_getnewfsid(mp);
+	mp->mnt_lower = lowerrootvp->v_mount;
 
 	nmp->ovm_size = sizeof (struct overlay_node);
 	nmp->ovm_tag = VT_OVERLAY;
@@ -189,7 +190,6 @@ ov_mount(struct mount *mp, const char *p
 	if (error)
 		return error;
 
-	mp->mnt_lower = lowerrootvp->v_mount;
 	if (mp->mnt_lower->mnt_flag & MNT_LOCAL)
 		mp->mnt_flag |= MNT_LOCAL;
 #ifdef OVERLAYFS_DIAGNOSTIC

Index: src/sys/miscfs/umapfs/umap_vfsops.c
diff -u src/sys/miscfs/umapfs/umap_vfsops.c:1.99 src/sys/miscfs/umapfs/umap_vfsops.c:1.100
--- src/sys/miscfs/umapfs/umap_vfsops.c:1.99	Tue Apr 11 07:51:37 2017
+++ src/sys/miscfs/umapfs/umap_vfsops.c	Wed Feb 20 10:06:00 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: umap_vfsops.c,v 1.99 2017/04/11 07:51:37 hannken Exp $	*/
+/*	$NetBSD: umap_vfsops.c,v 1.100 2019/02/20 10:06:00 hannken Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: umap_vfsops.c,v 1.99 2017/04/11 07:51:37 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: umap_vfsops.c,v 

CVS commit: src/sys/kern

2019-02-20 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed Feb 20 10:06:33 UTC 2019

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

Log Message:
Assign vnode to dead_rootmount before vcache_dealloc() releases it.

Now v_mount is never NULL.


To generate a diff of this commit:
cvs rdiff -u -r1.101 -r1.102 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.101 src/sys/kern/vfs_vnode.c:1.102
--- src/sys/kern/vfs_vnode.c:1.101	Tue Jan  1 10:06:54 2019
+++ src/sys/kern/vfs_vnode.c	Wed Feb 20 10:06:33 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_vnode.c,v 1.101 2019/01/01 10:06:54 hannken Exp $	*/
+/*	$NetBSD: vfs_vnode.c,v 1.102 2019/02/20 10:06:33 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1997-2011 The NetBSD Foundation, Inc.
@@ -156,7 +156,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.101 2019/01/01 10:06:54 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.102 2019/02/20 10:06:33 hannken Exp $");
 
 #include 
 #include 
@@ -1162,6 +1162,8 @@ vcache_dealloc(vnode_impl_t *vip)
 	KASSERT(mutex_owned(_lock));
 
 	vp = VIMPL_TO_VNODE(vip);
+	vfs_ref(dead_rootmount);
+	vfs_insmntque(vp, dead_rootmount);
 	mutex_enter(vp->v_interlock);
 	vp->v_op = dead_vnodeop_p;
 	VSTATE_CHANGE(vp, VS_LOADING, VS_RECLAIMED);



CVS commit: src/sys

2019-02-20 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed Feb 20 10:05:20 UTC 2019

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

Log Message:
Bracket do_sys_renameat() and nfsrv_rename() with fstrans.

The v_mount field for vnodes on the same file system as "from"
is now stable for referenced vnodes.

VFS_RENAMELOCK no longer may use lock from an unreferenced and
freed "struct mount".


To generate a diff of this commit:
cvs rdiff -u -r1.525 -r1.526 src/sys/kern/vfs_syscalls.c
cvs rdiff -u -r1.176 -r1.177 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/kern/vfs_syscalls.c
diff -u src/sys/kern/vfs_syscalls.c:1.525 src/sys/kern/vfs_syscalls.c:1.526
--- src/sys/kern/vfs_syscalls.c:1.525	Tue Feb 19 06:55:28 2019
+++ src/sys/kern/vfs_syscalls.c	Wed Feb 20 10:05:20 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_syscalls.c,v 1.525 2019/02/19 06:55:28 mlelstv Exp $	*/
+/*	$NetBSD: vfs_syscalls.c,v 1.526 2019/02/20 10:05:20 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.525 2019/02/19 06:55:28 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.526 2019/02/20 10:05:20 hannken Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_fileassoc.h"
@@ -4224,9 +4224,18 @@ do_sys_renameat(struct lwp *l, int fromf
 	 */
 	fdvp = fnd.ni_dvp;
 	fvp = fnd.ni_vp;
+	mp = fdvp->v_mount;
 	KASSERT(fdvp != NULL);
 	KASSERT(fvp != NULL);
 	KASSERT((fdvp == fvp) || (VOP_ISLOCKED(fdvp) == LK_EXCLUSIVE));
+	/*
+	 * Bracket the operation with fstrans_start()/fstrans_done().
+	 *
+	 * Inside the bracket this file system cannot be unmounted so
+	 * a vnode on this file system cannot change its v_mount.
+	 * A vnode on another file system may still change to dead mount.
+	 */
+	fstrans_start(mp);
 
 	/*
 	 * Make sure neither fdvp nor fvp is locked.
@@ -4311,38 +4320,16 @@ do_sys_renameat(struct lwp *l, int fromf
 	}
 
 	/*
-	 * Get the mount point.  If the file system has been unmounted,
-	 * which it may be because we're not holding any vnode locks,
-	 * then v_mount will be NULL.  We're not really supposed to
-	 * read v_mount without holding the vnode lock, but since we
-	 * have fdvp referenced, if fdvp->v_mount changes then at worst
-	 * it will be set to NULL, not changed to another mount point.
-	 * And, of course, since it is up to the file system to
-	 * determine the real lock order, we can't lock both fdvp and
-	 * tdvp at the same time.
-	 */
-	mp = fdvp->v_mount;
-	if (mp == NULL) {
-		error = ENOENT;
-		goto abort1;
-	}
-
-	/*
-	 * Make sure the mount points match.  Again, although we don't
-	 * hold any vnode locks, the v_mount fields may change -- but
-	 * at worst they will change to NULL, so this will never become
-	 * a cross-device rename, because we hold vnode references.
+	 * Make sure the mount points match.  Although we don't hold
+	 * any vnode locks, the v_mount on fdvp file system are stable.
 	 *
-	 * XXX Because nothing is locked and the compiler may reorder
-	 * things here, unmounting the file system at an inopportune
-	 * moment may cause rename to fail with EXDEV when it really
-	 * should fail with ENOENT.
+	 * Unmounting another file system at an inopportune moment may
+	 * cause tdvp to disappear and change its v_mount to dead.
+	 *
+	 * So in either case different v_mount means cross-device rename.
 	 */
+	KASSERT(mp != NULL);
 	tmp = tdvp->v_mount;
-	if (tmp == NULL) {
-		error = ENOENT;
-		goto abort1;
-	}
 
 	if (mp != tmp) {
 		error = EXDEV;
@@ -4497,6 +4484,7 @@ do_sys_renameat(struct lwp *l, int fromf
 	 * destroy the pathbufs.
 	 */
 	VFS_RENAMELOCK_EXIT(mp);
+	fstrans_done(mp);
 	goto out2;
 
 abort3:	if ((tvp != NULL) && (tvp != tdvp))
@@ -4510,6 +4498,7 @@ abort1:	VOP_ABORTOP(tdvp, _cnd);
 abort0:	VOP_ABORTOP(fdvp, _cnd);
 	vrele(fdvp);
 	vrele(fvp);
+	fstrans_done(mp);
 out2:	pathbuf_destroy(tpb);
 out1:	pathbuf_destroy(fpb);
 out0:	return error;

Index: src/sys/nfs/nfs_serv.c
diff -u src/sys/nfs/nfs_serv.c:1.176 src/sys/nfs/nfs_serv.c:1.177
--- src/sys/nfs/nfs_serv.c:1.176	Sun Feb  3 03:19:28 2019
+++ src/sys/nfs/nfs_serv.c	Wed Feb 20 10:05:20 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: nfs_serv.c,v 1.176 2019/02/03 03:19:28 mrg Exp $	*/
+/*	$NetBSD: nfs_serv.c,v 1.177 2019/02/20 10:05:20 hannken Exp $	*/
 
 /*
  * Copyright (c) 1989, 1993
@@ -55,7 +55,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nfs_serv.c,v 1.176 2019/02/03 03:19:28 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nfs_serv.c,v 1.177 2019/02/20 10:05:20 hannken Exp $");
 
 #include 
 #include 
@@ -64,6 +64,7 @@ __KERNEL_RCSID(0, "$NetBSD: nfs_serv.c,v
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -1957,12 +1958,13 @@ nfsrv_rename(struct nfsrv_descript *nfsd
 		}
 		return (0);
 	}
+	localfs = fromnd.ni_dvp->v_mount;
+	

CVS commit: src/sys/dev/raidframe

2019-02-20 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed Feb 20 10:04:28 UTC 2019

Modified Files:
src/sys/dev/raidframe: rf_netbsdkintf.c

Log Message:
Fix vnode locking, must lock for VOP_OPEN() and VOP_UNLOCK() when done.


To generate a diff of this commit:
cvs rdiff -u -r1.374 -r1.375 src/sys/dev/raidframe/rf_netbsdkintf.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/raidframe/rf_netbsdkintf.c
diff -u src/sys/dev/raidframe/rf_netbsdkintf.c:1.374 src/sys/dev/raidframe/rf_netbsdkintf.c:1.375
--- src/sys/dev/raidframe/rf_netbsdkintf.c:1.374	Sat Feb  9 03:34:00 2019
+++ src/sys/dev/raidframe/rf_netbsdkintf.c	Wed Feb 20 10:04:28 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: rf_netbsdkintf.c,v 1.374 2019/02/09 03:34:00 christos Exp $	*/
+/*	$NetBSD: rf_netbsdkintf.c,v 1.375 2019/02/20 10:04:28 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2008-2011 The NetBSD Foundation, Inc.
@@ -101,7 +101,7 @@
  ***/
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: rf_netbsdkintf.c,v 1.374 2019/02/09 03:34:00 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rf_netbsdkintf.c,v 1.375 2019/02/20 10:04:28 hannken Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_raid_autoconfig.h"
@@ -2838,6 +2838,7 @@ rf_find_raid_components(void)
 			if (bdevvp(dev, ))
 panic("RAID can't alloc vnode");
 
+			vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
 			error = VOP_OPEN(vp, FREAD | FSILENT, NOCRED);
 
 			if (error) {
@@ -2858,7 +2859,6 @@ rf_find_raid_components(void)
 	printf("RAIDframe: can't get disk size"
 	" for dev %s (%d)\n",
 	device_xname(dv), error);
-vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
 VOP_CLOSE(vp, FREAD | FWRITE, NOCRED);
 vput(vp);
 continue;
@@ -2870,19 +2870,18 @@ rf_find_raid_components(void)
 if (error) {
 	printf("RAIDframe: can't get wedge info for "
 	"dev %s (%d)\n", device_xname(dv), error);
-	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
 	VOP_CLOSE(vp, FREAD | FWRITE, NOCRED);
 	vput(vp);
 	continue;
 }
 
 if (strcmp(dkw.dkw_ptype, DKW_PTYPE_RAIDFRAME) != 0) {
-	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
 	VOP_CLOSE(vp, FREAD | FWRITE, NOCRED);
 	vput(vp);
 	continue;
 }
 	
+VOP_UNLOCK(vp);
 ac_list = rf_get_component(ac_list, dev, vp,
 device_xname(dv), dkw.dkw_size, numsecs, secsize);
 rf_part_found = 1; /*There is a raid component on this disk*/
@@ -2903,7 +2902,6 @@ rf_find_raid_components(void)
 
 			/* don't need this any more.  We'll allocate it again
 			   a little later if we really do... */
-			vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
 			VOP_CLOSE(vp, FREAD | FWRITE, NOCRED);
 			vput(vp);
 
@@ -2922,12 +2920,14 @@ rf_find_raid_components(void)
 if (bdevvp(dev, ))
 	panic("RAID can't alloc vnode");
 
+vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
 error = VOP_OPEN(vp, FREAD, NOCRED);
 if (error) {
 	/* Whatever... */
 	vput(vp);
 	continue;
 }
+VOP_UNLOCK(vp);
 snprintf(cname, sizeof(cname), "%s%c",
 device_xname(dv), 'a' + i);
 ac_list = rf_get_component(ac_list, dev, vp, cname,
@@ -2949,12 +2949,15 @@ rf_find_raid_components(void)
 if (bdevvp(dev, ))
 	panic("RAID can't alloc vnode");
 
+vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
+
 error = VOP_OPEN(vp, FREAD, NOCRED);
 if (error) {
 	/* Whatever... */
 	vput(vp);
 	continue;
 }
+VOP_UNLOCK(vp);
 snprintf(cname, sizeof(cname), "%s%c",
 device_xname(dv), 'a' + RAW_PART);
 ac_list = rf_get_component(ac_list, dev, vp, cname,



CVS commit: src/sys/ufs/mfs

2019-02-20 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed Feb 20 10:03:56 UTC 2019

Modified Files:
src/sys/ufs/mfs: mfs_vnops.c

Log Message:
Remove superfluous VOP_UNLOCK(), vnode will be unlocked from spec_reclaim().


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/sys/ufs/mfs/mfs_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/mfs/mfs_vnops.c
diff -u src/sys/ufs/mfs/mfs_vnops.c:1.58 src/sys/ufs/mfs/mfs_vnops.c:1.59
--- src/sys/ufs/mfs/mfs_vnops.c:1.58	Fri May 26 14:21:02 2017
+++ src/sys/ufs/mfs/mfs_vnops.c	Wed Feb 20 10:03:55 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: mfs_vnops.c,v 1.58 2017/05/26 14:21:02 riastradh Exp $	*/
+/*	$NetBSD: mfs_vnops.c,v 1.59 2019/02/20 10:03:55 hannken Exp $	*/
 
 /*
  * Copyright (c) 1989, 1993
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mfs_vnops.c,v 1.58 2017/05/26 14:21:02 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mfs_vnops.c,v 1.59 2019/02/20 10:03:55 hannken Exp $");
 
 #include 
 #include 
@@ -297,8 +297,6 @@ mfs_reclaim(void *v)
 	struct mfsnode *mfsp = VTOMFS(vp);
 	int refcnt;
 
-	VOP_UNLOCK(vp);
-
 	mutex_enter(_lock);
 	vp->v_data = NULL;
 	refcnt = --mfsp->mfs_refcnt;



CVS commit: src/sys/dev

2019-02-20 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed Feb 20 10:03:25 UTC 2019

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

Log Message:
Make FSS_ERROR a flag to prevent bogus fscow_disestablish() after error.


To generate a diff of this commit:
cvs rdiff -u -r1.106 -r1.107 src/sys/dev/fss.c
cvs rdiff -u -r1.31 -r1.32 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.106 src/sys/dev/fss.c:1.107
--- src/sys/dev/fss.c:1.106	Wed Aug 29 09:04:40 2018
+++ src/sys/dev/fss.c	Wed Feb 20 10:03:25 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: fss.c,v 1.106 2018/08/29 09:04:40 hannken Exp $	*/
+/*	$NetBSD: fss.c,v 1.107 2019/02/20 10:03:25 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fss.c,v 1.106 2018/08/29 09:04:40 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fss.c,v 1.107 2019/02/20 10:03:25 hannken Exp $");
 
 #include 
 #include 
@@ -398,8 +398,7 @@ fss_ioctl(dev_t dev, u_long cmd, void *d
 		mutex_enter(>sc_slock);
 		if ((flag & FWRITE) == 0) {
 			error = EPERM;
-		} else if (sc->sc_state != FSS_ACTIVE &&
-		sc->sc_state != FSS_ERROR) {
+		} else if (sc->sc_state != FSS_ACTIVE) {
 			error = EBUSY;
 		} else {
 			sc->sc_state = FSS_DESTROYING;
@@ -509,7 +508,7 @@ fss_error(struct fss_softc *sc, const ch
 
 	KASSERT(mutex_owned(>sc_slock));
 
-	if (sc->sc_state == FSS_ERROR)
+	if ((sc->sc_flags & FSS_ERROR))
 		return;
 
 	aprint_error_dev(sc->sc_dev, "snapshot invalid: %s\n", msg);
@@ -518,7 +517,7 @@ fss_error(struct fss_softc *sc, const ch
 		fscow_disestablish(sc->sc_mount, fss_copy_on_write, sc);
 		mutex_enter(>sc_slock);
 	}
-	sc->sc_state = FSS_ERROR;
+	sc->sc_flags |= FSS_ERROR;
 }
 
 /*
@@ -944,7 +943,8 @@ fss_delete_snapshot(struct fss_softc *sc
 {
 
 	mutex_enter(>sc_slock);
-	if ((sc->sc_flags & FSS_PERSISTENT) == 0 && sc->sc_state != FSS_ERROR) {
+	if ((sc->sc_flags & FSS_PERSISTENT) == 0 &&
+	(sc->sc_flags & FSS_ERROR) == 0) {
 		mutex_exit(>sc_slock);
 		fscow_disestablish(sc->sc_mount, fss_copy_on_write, sc);
 	} else {

Index: src/sys/dev/fssvar.h
diff -u src/sys/dev/fssvar.h:1.31 src/sys/dev/fssvar.h:1.32
--- src/sys/dev/fssvar.h:1.31	Wed Aug 29 09:04:40 2018
+++ src/sys/dev/fssvar.h	Wed Feb 20 10:03:25 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: fssvar.h,v 1.31 2018/08/29 09:04:40 hannken Exp $	*/
+/*	$NetBSD: fssvar.h,v 1.32 2019/02/20 10:03:25 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
@@ -137,8 +137,7 @@ typedef enum {
 	FSS_IDLE,			/* Device is unconfigured */
 	FSS_CREATING,			/* Device is currently configuring */
 	FSS_ACTIVE,			/* Device is configured */
-	FSS_DESTROYING,			/* Device is currently unconfiguring */
-	FSS_ERROR			/* Device had errors */
+	FSS_DESTROYING			/* Device is currently unconfiguring */
 } fss_state_t;
 
 struct fss_softc {
@@ -148,6 +147,7 @@ struct fss_softc {
 	kcondvar_t	sc_cache_cv;	/* Signals free cache slot */
 	fss_state_t	sc_state;	/* Current state */
 	volatile int	sc_flags;	/* Flags */
+#define FSS_ERROR	0x01		/* Device had errors. */
 #define FSS_BS_THREAD	0x04		/* Kernel thread is running */
 #define FSS_PERSISTENT	0x20		/* File system internal snapshot */
 #define FSS_CDEV_OPEN	0x40		/* character device open */



CVS commit: src/sys/kern

2019-02-20 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed Feb 20 10:02:52 UTC 2019

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

Log Message:
Fix vnode locking for opendisk(), must lock for VOP_OPEN().


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/kern/subr_disk_open.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_disk_open.c
diff -u src/sys/kern/subr_disk_open.c:1.13 src/sys/kern/subr_disk_open.c:1.14
--- src/sys/kern/subr_disk_open.c:1.13	Tue Dec  8 20:36:15 2015
+++ src/sys/kern/subr_disk_open.c	Wed Feb 20 10:02:51 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_disk_open.c,v 1.13 2015/12/08 20:36:15 christos Exp $	*/
+/*	$NetBSD: subr_disk_open.c,v 1.14 2019/02/20 10:02:51 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2006 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: subr_disk_open.c,v 1.13 2015/12/08 20:36:15 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_disk_open.c,v 1.14 2019/02/20 10:02:51 hannken Exp $");
 
 #include 
 #include 
@@ -65,6 +65,7 @@ opendisk(device_t dv)
 	if (bdevvp(dev, ))
 		panic("%s: can't alloc vnode for %s", __func__,
 		device_xname(dv));
+	vn_lock(tmpvn, LK_EXCLUSIVE | LK_RETRY);
 	error = VOP_OPEN(tmpvn, FREAD | FSILENT, NOCRED);
 	if (error) {
 		/*



CVS commit: src/sys/dev/hyperv

2019-02-15 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Fri Feb 15 16:37:54 UTC 2019

Modified Files:
src/sys/dev/hyperv: vmbus.c

Log Message:
Add __diagused.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/hyperv/vmbus.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/hyperv/vmbus.c
diff -u src/sys/dev/hyperv/vmbus.c:1.1 src/sys/dev/hyperv/vmbus.c:1.2
--- src/sys/dev/hyperv/vmbus.c:1.1	Fri Feb 15 08:54:01 2019
+++ src/sys/dev/hyperv/vmbus.c	Fri Feb 15 16:37:54 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: vmbus.c,v 1.1 2019/02/15 08:54:01 nonaka Exp $	*/
+/*	$NetBSD: vmbus.c,v 1.2 2019/02/15 16:37:54 hannken Exp $	*/
 /*	$OpenBSD: hyperv.c,v 1.43 2017/06/27 13:56:15 mikeb Exp $	*/
 
 /*-
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vmbus.c,v 1.1 2019/02/15 08:54:01 nonaka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vmbus.c,v 1.2 2019/02/15 16:37:54 hannken Exp $");
 
 #include 
 #include 
@@ -1020,7 +1020,7 @@ vmbus_channel_add(struct vmbus_channel *
 {
 	struct vmbus_softc *sc = nch->ch_sc;
 	struct vmbus_channel *ch;
-	u_int refs;
+	u_int refs __diagused;
 
 	if (nch->ch_id == 0) {
 		device_printf(sc->sc_dev, "got channel 0 offer, discard\n");



CVS commit: src/sys/arch/sparc64/sparc64

2019-02-15 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Fri Feb 15 16:36:33 UTC 2019

Modified Files:
src/sys/arch/sparc64/sparc64: trap.c

Log Message:
Add /* FALLTHROUGH */ for DEBUG kernel.


To generate a diff of this commit:
cvs rdiff -u -r1.190 -r1.191 src/sys/arch/sparc64/sparc64/trap.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/arch/sparc64/sparc64/trap.c
diff -u src/sys/arch/sparc64/sparc64/trap.c:1.190 src/sys/arch/sparc64/sparc64/trap.c:1.191
--- src/sys/arch/sparc64/sparc64/trap.c:1.190	Thu Feb 14 20:09:40 2019
+++ src/sys/arch/sparc64/sparc64/trap.c	Fri Feb 15 16:36:33 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.190 2019/02/14 20:09:40 palle Exp $ */
+/*	$NetBSD: trap.c,v 1.191 2019/02/15 16:36:33 hannken Exp $ */
 
 /*
  * Copyright (c) 1996-2002 Eduardo Horvath.  All rights reserved.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.190 2019/02/14 20:09:40 palle Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.191 2019/02/15 16:36:33 hannken Exp $");
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
@@ -625,6 +625,7 @@ dopanic:
 		   l->l_proc->p_pid, l->l_lid, l->l_proc->p_comm,
 		   pc, type, type < N_TRAP_TYPES ? trap_type[type] : T);
 #endif
+		/* FALLTHROUGH */
 	case T_ILLINST:
 #if defined(DDB) && defined(DEBUG)
 		if (trapdebug & TDB_STOPSIG)



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

2019-02-05 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Tue Feb  5 09:55:48 UTC 2019

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

Log Message:
Implement the ZFS control directory ".zfs" and its subdirectory 'snapshot".

Automatically mount snapshots on access of ".zfs/snapshot/".


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.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_ctldir.c
diff -u src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c:1.4 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c:1.5
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c:1.4	Tue Feb  5 09:54:36 2019
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c	Tue Feb  5 09:55:48 2019
@@ -1261,14 +1261,584 @@ zfsctl_umount_snapshots(vfs_t *vfsp, int
 
 #ifdef __NetBSD__
 
+#include 
+#include 
 #include 
+#include 
 #include 
 #include 
+#include 
+#include 
+
+struct zfsctl_root {
+	timestruc_t zc_cmtime;
+};
+
+struct sfs_node_key {
+	uint64_t parent_id;
+	uint64_t id;
+};
+struct sfs_node {
+	struct sfs_node_key sn_key;
+#define sn_parent_id sn_key.parent_id
+#define sn_id sn_key.id
+	lwp_t *sn_mounting;
+};
+
+#define ZFS_SNAPDIR_NAME "snapshot"
+
+#define VTOSFS(vp) ((struct sfs_node *)((vp)->v_data))
+
+#define SFS_NODE_ASSERT(vp) \
+	do { \
+		struct sfs_node *np = VTOSFS(vp); \
+		ASSERT((vp)->v_op == zfs_sfsop_p); \
+		ASSERT((vp)->v_type == VDIR); \
+	} while (/*CONSTCOND*/ 0)
 
 static int (**zfs_sfsop_p)(void *);
 
-static const struct vnodeopv_entry_desc zfs_sfsop_entries[] = {
+/*
+ * Mount a snapshot.  Cannot use do_sys_umount() as it
+ * doesn't allow its "path" argument from SYSSPACE.
+ */
+static int
+sfs_snapshot_mount(vnode_t *vp, const char *snapname)
+{
+	struct sfs_node *node = VTOSFS(vp);
+	zfsvfs_t *zfsvfs = vp->v_vfsp->vfs_data;
+	vfs_t *vfsp;
+	char *path, *osname;
+	int error;
+	extern int zfs_domount(vfs_t *, char *);
+
+	path = PNBUF_GET();
+	osname = PNBUF_GET();
+
+	dmu_objset_name(zfsvfs->z_os, path);
+	snprintf(osname, MAXPATHLEN, "%s@%s", path, snapname);
+	snprintf(path, MAXPATHLEN,
+	"%s/" ZFS_CTLDIR_NAME "/" ZFS_SNAPDIR_NAME "/%s",
+	vp->v_vfsp->mnt_stat.f_mntonname, snapname);
+
+	vfsp = vfs_mountalloc(vp->v_vfsp->mnt_op, vp);
+	if (vfsp == NULL) {
+		error = ENOMEM;
+		goto out;
+	}
+	vfsp->mnt_op->vfs_refcount++;
+	vfsp->mnt_stat.f_owner = 0;
+	vfsp->mnt_flag = MNT_RDONLY | MNT_NOSUID | MNT_IGNORE;
+
+	mutex_enter(>mnt_updating);
+
+	error = zfs_domount(vfsp, osname);
+	if (error)
+		goto out;
+
+	vfs_getnewfsid(vfsp);
+	strlcpy(vfsp->mnt_stat.f_mntfromname, osname,
+	sizeof(vfsp->mnt_stat.f_mntfromname));
+	set_statvfs_info(path, UIO_SYSSPACE, vfsp->mnt_stat.f_mntfromname,
+	UIO_SYSSPACE, vfsp->mnt_op->vfs_name, vfsp, curlwp);
+
+	vfsp->mnt_lower = vp->v_vfsp;
+
+	mountlist_append(vfsp);
+	vref(vp);
+	vp->v_mountedhere = vfsp;
+
+	mutex_exit(>mnt_updating);
+	(void) VFS_STATVFS(vfsp, >mnt_stat);
+
+out:;
+	if (error && vfsp) {
+		mutex_exit(>mnt_updating);
+		fstrans_unmount(vfsp);
+		vfs_rele(vfsp);
+	}
+	PNBUF_PUT(osname);
+	PNBUF_PUT(path);
+
+	return error;
+}
+
+static int
+sfs_lookup_snapshot(vnode_t *dvp, struct componentname *cnp, vnode_t **vpp)
+{
+	zfsvfs_t *zfsvfs = dvp->v_vfsp->vfs_data;
+	vnode_t *vp;
+	struct sfs_node *node;
+	struct sfs_node_key key;
+	char snapname[ZFS_MAX_DATASET_NAME_LEN];
+	int error;
+
+	/* Retrieve the snapshot object id and the to be mounted on vnode. */
+	if (cnp->cn_namelen >= sizeof(snapname))
+		return ENOENT;
+
+	strlcpy(snapname, cnp->cn_nameptr, cnp->cn_namelen + 1);
+	error = dsl_dataset_snap_lookup( dmu_objset_ds(zfsvfs->z_os),
+	snapname, );
+	if (error)
+		return error;
+	key.parent_id = ZFSCTL_INO_SNAPDIR;
+	error = vcache_get(zfsvfs->z_vfs, , sizeof(key), vpp);
+	if (error)
+		return error;
+
+	/* Handle case where the vnode is currently mounting. */
+	vp = *vpp;
+	mutex_enter(vp->v_interlock);
+	node = VTOSFS(vp);
+	if (node->sn_mounting) {
+		if (node->sn_mounting == curlwp)
+			error = 0;
+		else
+			error = ERESTART;
+		mutex_exit(vp->v_interlock);
+		if (error)
+			yield();
+		return error;
+	}
+
+	/* If not yet mounted mount the snapshot. */
+	if (vp->v_mountedhere == NULL) {
+		ASSERT(node->sn_mounting == NULL);
+		node->sn_mounting = curlwp;
+		mutex_exit(vp->v_interlock);
+
+		VOP_UNLOCK(dvp, 0);
+		error = sfs_snapshot_mount(vp, snapname);
+		if (vn_lock(dvp, LK_EXCLUSIVE) != 0) {
+			vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY);
+			error = ENOENT;
+		}
+
+		mutex_enter(vp->v_interlock);
+		if ((node = VTOSFS(vp)))
+			node->sn_mounting = NULL;
+		mutex_exit(vp->v_interlock);
+
+		if (error) {
+			vrele(vp);
+			*vpp = NULL;
+			return error;
+		}
+	} else
+		mutex_exit(vp->v_interlock);
+
+	/* Return the mounted root 

CVS commit: src

2019-02-05 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Tue Feb  5 09:54:36 UTC 2019

Modified Files:
src/external/cddl/osnet/dist/uts/common/fs/zfs: zfs_ctldir.c
zfs_ioctl.c zfs_vfsops.c zfs_vnops.c zfs_znode.c
src/external/cddl/osnet/dist/uts/common/fs/zfs/sys: zfs_ctldir.h
src/sys/modules/zfs: Makefile.zfsmod
Removed Files:
src/external/cddl/osnet/sys/kern: zfs_stub.c

Log Message:
Prepare the implementation of the ZFS control directory ".zfs".

- Move the stub routines from zfs_stub.c to zfs_ctldir.c and
  remove now empty file zfs_stub.c

- Add stub routines for zfsctl_loadvnode() to initialize control
  nodes and zfsctl_snapshot() to retrieve ".zfs/snapshot".

- Add an initial vnode operations vector for control nodes.

- Implement lookup into ".zfs" and lookup ".." from ".zfs/snapshot/".

- Change nodeid of mounted snapshots to the snapshot object id.

- Respect "-u" flag to "zfs rename  ...".


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c
cvs rdiff -u -r1.15 -r1.16 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ioctl.c
cvs rdiff -u -r1.18 -r1.19 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vfsops.c
cvs rdiff -u -r1.43 -r1.44 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c
cvs rdiff -u -r1.24 -r1.25 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c
cvs rdiff -u -r1.1.1.3 -r1.2 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/sys/zfs_ctldir.h
cvs rdiff -u -r1.2 -r0 src/external/cddl/osnet/sys/kern/zfs_stub.c
cvs rdiff -u -r1.8 -r1.9 src/sys/modules/zfs/Makefile.zfsmod

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_ctldir.c
diff -u src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c:1.3 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c:1.4
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c:1.3	Mon May 28 21:05:07 2018
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c	Tue Feb  5 09:54:36 2019
@@ -1261,9 +1261,80 @@ zfsctl_umount_snapshots(vfs_t *vfsp, int
 
 #ifdef __NetBSD__
 
+#include 
 #include 
 #include 
 
+static int (**zfs_sfsop_p)(void *);
+
+static const struct vnodeopv_entry_desc zfs_sfsop_entries[] = {
+	{ _default_desc,		vn_default_error },
+	{ NULL, NULL }
+};
+
+const struct vnodeopv_desc zfs_sfsop_opv_desc =
+	{ _sfsop_p, zfs_sfsop_entries };
+
+void
+zfsctl_init(void)
+{
+}
+
+void
+zfsctl_fini(void)
+{
+}
+
+int
+zfsctl_loadvnode(vfs_t *vfsp, vnode_t *vp,
+const void *key, size_t key_len, const void **new_key)
+{
+
+	return EINVAL;
+}
+
+int
+zfsctl_root(zfsvfs_t *zfsvfs, vnode_t **znode)
+{
+
+	return ENOENT;
+}
+
+int
+zfsctl_snapshot(zfsvfs_t *zfsvfs, vnode_t **znode)
+{
+
+	return ENOENT;
+}
+
+void
+zfsctl_create(zfsvfs_t *zfsvfs)
+{
+
+	ASSERT(zfsvfs->z_ctldir == NULL);
+}
+
+void
+zfsctl_destroy(zfsvfs_t *zfsvfs)
+{
+
+	ASSERT(zfsvfs->z_ctldir == NULL);
+}
+
+int
+zfsctl_lookup_objset(vfs_t *vfsp, uint64_t objsetid, zfsvfs_t **zfsvfsp)
+{
+
+	return EINVAL;
+}
+
+int
+zfsctl_umount_snapshots(vfs_t *vfsp, int fflags, cred_t *cr)
+{
+
+	return 0;
+}
+
 boolean_t
 zfsctl_is_node(vnode_t *vp)
 {

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.15 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ioctl.c:1.16
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ioctl.c:1.15	Sat Jan 12 10:43:33 2019
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ioctl.c	Tue Feb  5 09:54:36 2019
@@ -3881,7 +3881,7 @@ zfs_ioc_rename(zfs_cmd_t *zc)
 	char *at;
 	boolean_t allow_mounted = B_TRUE;
 
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) || defined(__NetBSD__)
 	allow_mounted = (zc->zc_cookie & 2) != 0;
 #endif
 

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.18 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vfsops.c:1.19
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vfsops.c:1.18	Tue Jan  1 10:08:01 2019
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vfsops.c	Tue Feb  5 09:54:36 2019
@@ -146,9 +146,11 @@ void zfs_init(void);
 void zfs_fini(void);
 
 extern const struct vnodeopv_desc zfs_vnodeop_opv_desc;
+extern const struct vnodeopv_desc zfs_sfsop_opv_desc;
 
 static const struct vnodeopv_desc * const zfs_vnodeop_descs[] = {
 	_vnodeop_opv_desc,
+	_sfsop_opv_desc,
 	NULL,
 };
 
@@ -185,9 +187,11 @@ zfs_sync_selector(void *cl, struct vnode
 	znode_t *zp;
 
 	/*
-	 * Skip the vnode/inode if inaccessible, or if the
+	 * Skip the vnode/inode if inaccessible, is control node or if the
 	 * atime is clean.
 	 */
+	if (zfsctl_is_node(vp))
+		return false;
 	zp = VTOZ(vp);
 	return zp != NULL && vp->v_type != VNON && 

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

2019-02-05 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Tue Feb  5 09:50:18 UTC 2019

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

Log Message:
zfs_netbsd_reclaim(): validate "z_log" before zil_commit().


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 \
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.42 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.43
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.42	Sat Jan  5 09:20:29 2019
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c	Tue Feb  5 09:50:18 2019
@@ -5680,7 +5680,8 @@ zfs_netbsd_reclaim(void *v)
 		}
 	}
 
-	zil_commit(zfsvfs->z_log, zp->z_id);
+	if (zfsvfs->z_log)
+		zil_commit(zfsvfs->z_log, zp->z_id);
 
 	if (zp->z_sa_hdl == NULL)
 		zfs_znode_free(zp);



CVS commit: src/sys/kern

2019-02-05 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Tue Feb  5 09:49:44 UTC 2019

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

Log Message:
Allow dounmount() with file system already suspended.

Remove no longer valid test for layered mounts,
ZFS will unmount snapshots bottom up.


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 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.67 src/sys/kern/vfs_mount.c:1.68
--- src/sys/kern/vfs_mount.c:1.67	Mon Aug 21 09:00:21 2017
+++ src/sys/kern/vfs_mount.c	Tue Feb  5 09:49:44 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_mount.c,v 1.67 2017/08/21 09:00:21 hannken Exp $	*/
+/*	$NetBSD: vfs_mount.c,v 1.68 2019/02/05 09:49:44 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1997-2011 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.67 2017/08/21 09:00:21 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.68 2019/02/05 09:49:44 hannken Exp $");
 
 #include 
 #include 
@@ -835,10 +835,9 @@ err_unmounted:
 int
 dounmount(struct mount *mp, int flags, struct lwp *l)
 {
-	mount_iterator_t *iter;
-	struct mount *cmp;
 	vnode_t *coveredvp;
 	int error, async, used_syncer, used_extattr;
+	const bool was_suspended = fstrans_is_owner(mp);
 
 #if NVERIEXEC > 0
 	error = veriexec_unmountchk(mp);
@@ -846,22 +845,12 @@ dounmount(struct mount *mp, int flags, s
 		return (error);
 #endif /* NVERIEXEC > 0 */
 
-	/*
-	 * No unmount below layered mounts.
-	 */
-	mountlist_iterator_init();
-	while ((cmp = mountlist_iterator_next(iter)) != NULL) {
-		if (cmp->mnt_lower == mp) {
-			mountlist_iterator_destroy(iter);
-			return EBUSY;
+	if (!was_suspended) {
+		error = vfs_suspend(mp, 0);
+		if (error) {
+			return error;
 		}
 	}
-	mountlist_iterator_destroy(iter);
-
-	error = vfs_suspend(mp, 0);
-	if (error) {
-		return error;
-	}
 
 	KASSERT((mp->mnt_iflag & IMNT_GONE) == 0);
 
@@ -888,7 +877,8 @@ 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 (!was_suspended)
+			vfs_resume(mp);
 		if (used_extattr) {
 			if (start_extattr(mp) != 0)
 mp->mnt_flag &= ~MNT_EXTATTR;
@@ -905,7 +895,8 @@ dounmount(struct mount *mp, int flags, s
 	 * vfs_busy() from succeeding.
 	 */
 	mp->mnt_iflag |= IMNT_GONE;
-	vfs_resume(mp);
+	if (!was_suspended)
+		vfs_resume(mp);
 
 	if ((coveredvp = mp->mnt_vnodecovered) != NULLVP) {
 		vn_lock(coveredvp, LK_EXCLUSIVE | LK_RETRY);



CVS commit: src/sys/arch/sparc64/sparc64

2019-01-30 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed Jan 30 10:11:11 UTC 2019

Modified Files:
src/sys/arch/sparc64/sparc64: netbsd32_machdep_13.c

Log Message:
Make this compile with "options DEBUG".


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/sparc64/sparc64/netbsd32_machdep_13.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/arch/sparc64/sparc64/netbsd32_machdep_13.c
diff -u src/sys/arch/sparc64/sparc64/netbsd32_machdep_13.c:1.2 src/sys/arch/sparc64/sparc64/netbsd32_machdep_13.c:1.3
--- src/sys/arch/sparc64/sparc64/netbsd32_machdep_13.c:1.2	Sun Jan 27 02:08:38 2019
+++ src/sys/arch/sparc64/sparc64/netbsd32_machdep_13.c	Wed Jan 30 10:11:11 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_machdep_13.c,v 1.2 2019/01/27 02:08:38 pgoyette Exp $	*/
+/*	$NetBSD: netbsd32_machdep_13.c,v 1.3 2019/01/30 10:11:11 hannken Exp $	*/
 
 /*
  * Copyright (c) 1998, 2001 Matthew R. Green
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep_13.c,v 1.2 2019/01/27 02:08:38 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep_13.c,v 1.3 2019/01/30 10:11:11 hannken Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -83,6 +83,10 @@ __KERNEL_RCSID(0, "$NetBSD: netbsd32_mac
 #include 
 #include 
 
+#ifdef DEBUG
+#include 
+#endif
+
 int
 compat_13_netbsd32_sigreturn(struct lwp *l, const struct compat_13_netbsd32_sigreturn_args *uap, register_t *retval)
 {
@@ -108,7 +112,7 @@ compat_13_netbsd32_sigreturn(struct lwp 
 	}
 #ifdef DEBUG
 	if (sigdebug & SDB_FOLLOW) {
-		printf("%s: %s[%d], sigcntxp %p\n", __func__,
+		printf("%s: %s[%d], sigcntxp %u\n", __func__,
 		p->p_comm, p->p_pid, SCARG(uap, sigcntxp));
 		if (sigdebug & SDB_DDB) Debugger();
 	}
@@ -133,7 +137,7 @@ compat_13_netbsd32_sigreturn(struct lwp 
 	if (((sc.sc_pc | sc.sc_npc) & 3) != 0)
 #ifdef DEBUG
 	{
-		printf("%s: pc %p or npc %p invalid\n",
+		printf("%s: pc %d or npc %d invalid\n",
 		   __func__, sc.sc_pc, sc.sc_npc);
 		Debugger();
 		return (EINVAL);
@@ -150,7 +154,7 @@ compat_13_netbsd32_sigreturn(struct lwp 
 	tf->tf_out[6] = (int64_t)sc.sc_sp;
 #ifdef DEBUG
 	if (sigdebug & SDB_FOLLOW) {
-		printf("%s: return trapframe pc=%p sp=%p tstate=%x\n", __func__,
+		printf("%s: return trapframe pc=%d sp=%d tstate=%x\n", __func__,
 		   (int)tf->tf_pc, (int)tf->tf_out[6], (int)tf->tf_tstate);
 		if (sigdebug & SDB_DDB) Debugger();
 	}



CVS commit: src/sys/dev/pci

2019-01-17 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Thu Jan 17 10:20:01 UTC 2019

Modified Files:
src/sys/dev/pci: ld_virtio.c

Log Message:
Use cv_broadcast() on "sc_sync_wait" to prevent deadlock
when more than one thread try to "DIOCCACHESYNC" at the
same time.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sys/dev/pci/ld_virtio.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/pci/ld_virtio.c
diff -u src/sys/dev/pci/ld_virtio.c:1.26 src/sys/dev/pci/ld_virtio.c:1.27
--- src/sys/dev/pci/ld_virtio.c:1.26	Fri Nov 23 18:08:11 2018
+++ src/sys/dev/pci/ld_virtio.c	Thu Jan 17 10:20:01 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ld_virtio.c,v 1.26 2018/11/23 18:08:11 jmcneill Exp $	*/
+/*	$NetBSD: ld_virtio.c,v 1.27 2019/01/17 10:20:01 hannken Exp $	*/
 
 /*
  * Copyright (c) 2010 Minoura Makoto.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ld_virtio.c,v 1.26 2018/11/23 18:08:11 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ld_virtio.c,v 1.27 2019/01/17 10:20:01 hannken Exp $");
 
 #include 
 #include 
@@ -465,7 +465,7 @@ ld_virtio_vq_done1(struct ld_virtio_soft
 		mutex_enter(>sc_sync_wait_lock);
 		sc->sc_sync_status = vr->vr_status;
 		sc->sc_sync_use = SYNC_DONE;
-		cv_signal(>sc_sync_wait);
+		cv_broadcast(>sc_sync_wait);
 		mutex_exit(>sc_sync_wait_lock);
 		virtio_dequeue_commit(vsc, vq, slot);
 		return;
@@ -716,7 +716,7 @@ ld_virtio_flush(struct ld_softc *ld, boo
 		r = EIO;
 
 	sc->sc_sync_use = SYNC_FREE;
-	cv_signal(>sc_sync_wait);
+	cv_broadcast(>sc_sync_wait);
 	mutex_exit(>sc_sync_wait_lock);
 
 	return r;



CVS commit: src/sys/kern

2019-01-17 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Thu Jan 17 10:18:52 UTC 2019

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

Log Message:
Use PRIu64 for "uint64_t tp_refcnt".


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/kern/kern_threadpool.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/kern_threadpool.c
diff -u src/sys/kern/kern_threadpool.c:1.14 src/sys/kern/kern_threadpool.c:1.15
--- src/sys/kern/kern_threadpool.c:1.14	Sat Dec 29 04:39:14 2018
+++ src/sys/kern/kern_threadpool.c	Thu Jan 17 10:18:52 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_threadpool.c,v 1.14 2018/12/29 04:39:14 thorpej Exp $	*/
+/*	$NetBSD: kern_threadpool.c,v 1.15 2019/01/17 10:18:52 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2014, 2018 The NetBSD Foundation, Inc.
@@ -81,7 +81,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_threadpool.c,v 1.14 2018/12/29 04:39:14 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_threadpool.c,v 1.15 2019/01/17 10:18:52 hannken Exp $");
 
 #include 
 #include 
@@ -364,7 +364,7 @@ threadpool_destroy(struct threadpool *po
 	TAILQ_FOREACH(thread, >tp_idle_threads, tpt_entry)
 		cv_broadcast(>tpt_cv);
 	while (0 < pool->tp_refcnt) {
-		TP_LOG(("%s: draining %u references...\n", __func__,
+		TP_LOG(("%s: draining %" PRIu64 " references...\n", __func__,
 		pool->tp_refcnt));
 		cv_wait(>tp_overseer.tpt_cv, >tp_lock);
 	}



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

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

Modified Files:
src/external/cddl/osnet/sys/sys: vnode.h

Log Message:
Allow zfs_vn_rdwr() with "rw == UIO_READ" too.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/external/cddl/osnet/sys/sys/vnode.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/sys/sys/vnode.h
diff -u src/external/cddl/osnet/sys/sys/vnode.h:1.14 src/external/cddl/osnet/sys/sys/vnode.h:1.15
--- src/external/cddl/osnet/sys/sys/vnode.h:1.14	Mon May 28 21:05:10 2018
+++ src/external/cddl/osnet/sys/sys/vnode.h	Sat Jan 12 10:44:36 2019
@@ -1,5 +1,5 @@
 
-/*	$NetBSD: vnode.h,v 1.14 2018/05/28 21:05:10 chs Exp $	*/
+/*	$NetBSD: vnode.h,v 1.15 2019/01/12 10:44:36 hannken Exp $	*/
 
 /*
  * CDDL HEADER START
@@ -277,7 +277,7 @@ zfs_vn_rdwr(enum uio_rw rw, vnode_t *vp,
 	int error;
 	size_t resid;
 
-	ASSERT(rw == UIO_WRITE);
+	ASSERT(rw == UIO_READ || rw == UIO_WRITE);
 	ASSERT(ioflag == 0);
 	ASSERT(ulimit == RLIM64_INFINITY);
 



  1   2   3   4   5   6   7   >