CVS commit: src/sys/ufs/chfs

2021-08-10 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Wed Aug 11 05:17:48 UTC 2021

Modified Files:
src/sys/ufs/chfs: media.h

Log Message:
s/enrty/entry/


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/ufs/chfs/media.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/ufs/chfs/media.h
diff -u src/sys/ufs/chfs/media.h:1.2 src/sys/ufs/chfs/media.h:1.3
--- src/sys/ufs/chfs/media.h:1.2	Fri Oct 19 12:44:39 2012
+++ src/sys/ufs/chfs/media.h	Wed Aug 11 05:17:48 2021
@@ -46,7 +46,7 @@ typedef uint64_t le64;
 enum {
 	CHFS_NODETYPE_VNODE = 1,	/* vnode information */
 	CHFS_NODETYPE_DATA,			/* data node */
-	CHFS_NODETYPE_DIRENT,		/* directory enrty */
+	CHFS_NODETYPE_DIRENT,		/* directory entry */
 	CHFS_NODETYPE_PADDING,		/* padding node */
 };
 



CVS commit: src/sys/ufs/lfs

2021-07-25 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Jul 25 06:10:01 UTC 2021

Modified Files:
src/sys/ufs/lfs: ulfs_quota1_subr.c

Log Message:
#include  for COHERENCY_UNIT (and KNF)


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/ufs/lfs/ulfs_quota1_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/ufs/lfs/ulfs_quota1_subr.c
diff -u src/sys/ufs/lfs/ulfs_quota1_subr.c:1.3 src/sys/ufs/lfs/ulfs_quota1_subr.c:1.4
--- src/sys/ufs/lfs/ulfs_quota1_subr.c:1.3	Thu Jun  6 00:49:28 2013
+++ src/sys/ufs/lfs/ulfs_quota1_subr.c	Sun Jul 25 06:10:01 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ulfs_quota1_subr.c,v 1.3 2013/06/06 00:49:28 dholland Exp $	*/
+/*	$NetBSD: ulfs_quota1_subr.c,v 1.4 2021/07/25 06:10:01 skrll Exp $	*/
 /*  from NetBSD: quota1_subr.c,v 1.7 2012/01/29 06:23:20 dholland Exp  */
 
 /*-
@@ -28,12 +28,12 @@
   */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ulfs_quota1_subr.c,v 1.3 2013/06/06 00:49:28 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ulfs_quota1_subr.c,v 1.4 2021/07/25 06:10:01 skrll Exp $");
 
+#include 
 #include 
-#include 
-
 #include 
+
 #include 
 
 static uint64_t



CVS commit: src/sys/ufs/chfs

2021-07-19 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Mon Jul 19 22:24:55 UTC 2021

Modified Files:
src/sys/ufs/chfs: chfs_gc.c

Log Message:
NFC - if/else blocks start with the same mutex_exit, just move it up.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/ufs/chfs/chfs_gc.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/chfs/chfs_gc.c
diff -u src/sys/ufs/chfs/chfs_gc.c:1.10 src/sys/ufs/chfs/chfs_gc.c:1.11
--- src/sys/ufs/chfs/chfs_gc.c:1.10	Fri Jul 16 21:18:41 2021
+++ src/sys/ufs/chfs/chfs_gc.c	Mon Jul 19 22:24:55 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: chfs_gc.c,v 1.10 2021/07/16 21:18:41 andvar Exp $	*/
+/*	$NetBSD: chfs_gc.c,v 1.11 2021/07/19 22:24:55 andvar Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -232,15 +232,13 @@ chfs_gc_fetch_inode(struct chfs_mount *c
 mutex_exit(>chm_lock_vnocache);
 return NULL;
 			}
+			mutex_exit(>chm_lock_vnocache);
 			if (vc->state != VNO_STATE_CHECKEDABSENT) {
-mutex_exit(>chm_lock_vnocache);
 /* XXX why do we need the delay here?! */
 KASSERT(mutex_owned(>chm_lock_mountfields));
 cv_timedwait_sig(
 	>chm_gc_thread.gcth_wakeup,
 	>chm_lock_mountfields, mstohz(50));
-			} else {
-mutex_exit(>chm_lock_vnocache);
 			}
 			return NULL;
 		}



CVS commit: src/sys/ufs/chfs

2021-07-19 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Mon Jul 19 21:04:39 UTC 2021

Modified Files:
src/sys/ufs/chfs: chfs_build.c chfs_write.c

Log Message:
Release mutexes in few more places on failure path. Reviewed them in chfs code 
after fixing PR kern/56242.
ok riastradh


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/ufs/chfs/chfs_build.c \
src/sys/ufs/chfs/chfs_write.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/chfs/chfs_build.c
diff -u src/sys/ufs/chfs/chfs_build.c:1.5 src/sys/ufs/chfs/chfs_build.c:1.6
--- src/sys/ufs/chfs/chfs_build.c:1.5	Fri Oct 19 12:44:39 2012
+++ src/sys/ufs/chfs/chfs_build.c	Mon Jul 19 21:04:39 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: chfs_build.c,v 1.5 2012/10/19 12:44:39 ttoth Exp $	*/
+/*	$NetBSD: chfs_build.c,v 1.6 2021/07/19 21:04:39 andvar Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -252,8 +252,10 @@ chfs_build_filesystem(struct chfs_mount 
 if (chmp->chm_nextblock) {
 	err = chfs_close_eraseblock(chmp,
 	chmp->chm_nextblock);
-	if (err)
+	if (err) {
+		mutex_exit(>chm_lock_mountfields);
 		return err;
+	}
 }
 chmp->chm_nextblock = >chm_blocks[i];
 			} else {
@@ -261,8 +263,10 @@ chfs_build_filesystem(struct chfs_mount 
  * dirty and put it on a list */
 err = chfs_close_eraseblock(chmp,
 >chm_blocks[i]);
-if (err)
+if (err) {
+	mutex_exit(>chm_lock_mountfields);
 	return err;
+}
 			}
 			break;
 		case CHFS_BLK_STATE_ALLDIRTY:
Index: src/sys/ufs/chfs/chfs_write.c
diff -u src/sys/ufs/chfs/chfs_write.c:1.5 src/sys/ufs/chfs/chfs_write.c:1.6
--- src/sys/ufs/chfs/chfs_write.c:1.5	Fri Oct 19 12:44:39 2012
+++ src/sys/ufs/chfs/chfs_write.c	Mon Jul 19 21:04:39 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: chfs_write.c,v 1.5 2012/10/19 12:44:39 ttoth Exp $	*/
+/*	$NetBSD: chfs_write.c,v 1.6 2021/07/19 21:04:39 andvar Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -438,8 +438,10 @@ chfs_do_link(struct chfs_inode *ip, stru
 
 	/* update vnode information */
 	error = chfs_write_flash_vnode(chmp, ip, ALLOC_NORMAL);
-	if (error)
+	if (error) {
+		mutex_exit(>chm_lock_mountfields);
 		return error;
+	}
 
 	/* write out the new dirent */
 	error = chfs_write_flash_dirent(chmp,



CVS commit: src/sys/ufs/chfs

2021-07-16 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Fri Jul 16 21:18:41 UTC 2021

Modified Files:
src/sys/ufs/chfs: chfs_gc.c chfs_scan.c

Log Message:
Fix incorrect function name, some grammar and typos in comments. Remove 
trailing tab symbol.
No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/ufs/chfs/chfs_gc.c \
src/sys/ufs/chfs/chfs_scan.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/chfs/chfs_gc.c
diff -u src/sys/ufs/chfs/chfs_gc.c:1.9 src/sys/ufs/chfs/chfs_gc.c:1.10
--- src/sys/ufs/chfs/chfs_gc.c:1.9	Thu Jun  1 02:45:15 2017
+++ src/sys/ufs/chfs/chfs_gc.c	Fri Jul 16 21:18:41 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: chfs_gc.c,v 1.9 2017/06/01 02:45:15 chs Exp $	*/
+/*	$NetBSD: chfs_gc.c,v 1.10 2021/07/16 21:18:41 andvar Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -89,7 +89,7 @@ chfs_gc_thread(void *data)
 	mutex_enter(>chm_lock_mountfields);
 	while (gc->gcth_running) {
 		/* we must call chfs_gc_thread_should_wake with chm_lock_mountfields
-		 * held, which is a bit awkwardly done here, but we cant relly
+		 * held, which is a bit awkwardly done here, but we can't really
 		 * do it otherway with the current design...
 		 */
 		if (chfs_gc_thread_should_wake(chmp)) {
@@ -127,7 +127,7 @@ chfs_gc_thread_start(struct chfs_mount *
 	"chfsgcth");
 }
 
-/* chfs_gc_thread_start - stops GC */
+/* chfs_gc_thread_stop - stops GC */
 void
 chfs_gc_thread_stop(struct chfs_mount *chmp)
 {
@@ -191,7 +191,7 @@ chfs_gc_thread_should_wake(struct chfs_m
 		return 1;
 	}
 
-	/* There is too much very dirty blocks. */
+	/* There are too much very dirty blocks. */
 	TAILQ_FOREACH(cheb, >chm_very_dirty_queue, queue) {
 		nr_very_dirty++;
 		if (nr_very_dirty == chmp->chm_vdirty_blocks_gctrigger) {
@@ -200,7 +200,7 @@ chfs_gc_thread_should_wake(struct chfs_m
 		}
 	}
 
-	/* Everythin OK, GC shouldn't run. */
+	/* Everything is OK, GC shouldn't run. */
 	return 0;
 }
 
Index: src/sys/ufs/chfs/chfs_scan.c
diff -u src/sys/ufs/chfs/chfs_scan.c:1.9 src/sys/ufs/chfs/chfs_scan.c:1.10
--- src/sys/ufs/chfs/chfs_scan.c:1.9	Thu Jul 15 22:39:06 2021
+++ src/sys/ufs/chfs/chfs_scan.c	Fri Jul 16 21:18:41 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: chfs_scan.c,v 1.9 2021/07/15 22:39:06 andvar Exp $	*/
+/*	$NetBSD: chfs_scan.c,v 1.10 2021/07/16 21:18:41 andvar Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -225,7 +225,7 @@ chfs_add_fd_to_list(struct chfs_mount *c
 	new->nsize);
 	cheb = >chm_blocks[new->nref->nref_lnr];
 
-	mutex_enter(>chm_lock_sizes);	
+	mutex_enter(>chm_lock_sizes);
 	TAILQ_FOREACH_SAFE(fd, >scan_dirents, fds, tmpfd) {
 		if (fd->nhash > new->nhash) {
 			/* insert new before fd */



CVS commit: src/sys/ufs/chfs

2021-07-15 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Thu Jul 15 22:39:06 UTC 2021

Modified Files:
src/sys/ufs/chfs: chfs_readinode.c chfs_scan.c

Log Message:
Make sure that mutex is released before conditional return statements. Fixes PR 
kern/56242
ok riastradh


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/ufs/chfs/chfs_readinode.c
cvs rdiff -u -r1.8 -r1.9 src/sys/ufs/chfs/chfs_scan.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/chfs/chfs_readinode.c
diff -u src/sys/ufs/chfs/chfs_readinode.c:1.10 src/sys/ufs/chfs/chfs_readinode.c:1.11
--- src/sys/ufs/chfs/chfs_readinode.c:1.10	Thu Jun  1 02:45:15 2017
+++ src/sys/ufs/chfs/chfs_readinode.c	Thu Jul 15 22:39:06 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: chfs_readinode.c,v 1.10 2017/06/01 02:45:15 chs Exp $	*/
+/*	$NetBSD: chfs_readinode.c,v 1.11 2021/07/15 22:39:06 andvar Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -1012,6 +1012,7 @@ retry:
 (unsigned long long)vc->vno, vc->state);
 			chfs_err("wants to read a nonexistent ino %llu\n",
 (unsigned long long)vc->vno);
+			mutex_exit(>chm_lock_vnocache);
 			return ENOENT;
 		default:
 			panic("BUG() Bad vno cache state.");

Index: src/sys/ufs/chfs/chfs_scan.c
diff -u src/sys/ufs/chfs/chfs_scan.c:1.8 src/sys/ufs/chfs/chfs_scan.c:1.9
--- src/sys/ufs/chfs/chfs_scan.c:1.8	Mon Jun 17 17:14:56 2019
+++ src/sys/ufs/chfs/chfs_scan.c	Thu Jul 15 22:39:06 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: chfs_scan.c,v 1.8 2019/06/17 17:14:56 ryoon Exp $	*/
+/*	$NetBSD: chfs_scan.c,v 1.9 2021/07/15 22:39:06 andvar Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -151,6 +151,7 @@ chfs_scan_check_vnode(struct chfs_mount 
 		} else {
 			err = chfs_update_eb_dirty(chmp, cheb,
 			sizeof(struct chfs_flash_vnode));
+			mutex_exit(>chm_lock_vnocache);
 			return CHFS_NODE_OK;
 		}
 	} else {
@@ -325,6 +326,7 @@ chfs_scan_check_dirent_node(struct chfs_
 	parentvc = chfs_scan_make_vnode_cache(chmp, le64toh(dirent->pvno));
 	if (!parentvc) {
 		chfs_free_dirent(fd);
+		mutex_exit(>chm_lock_vnocache);
 		return ENOMEM;
 	}
 
@@ -381,8 +383,10 @@ chfs_scan_check_data_node(struct chfs_mo
 	vc = chfs_vnode_cache_get(chmp, vno);
 	if (!vc) {
 		vc = chfs_scan_make_vnode_cache(chmp, vno);
-		if (!vc)
+		if (!vc) {
+			mutex_exit(>chm_lock_vnocache);
 			return ENOMEM;
+		}
 	}
 	chfs_add_node_to_list(chmp, vc, nref, >dnode);
 	mutex_exit(>chm_lock_vnocache);



CVS commit: src/sys/ufs/ffs

2021-07-14 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Jul 14 07:24:14 UTC 2021

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

Log Message:
Hook up ffsext_strategy to fifos. Pointed out by dholland@


To generate a diff of this commit:
cvs rdiff -u -r1.134 -r1.135 src/sys/ufs/ffs/ffs_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_vnops.c
diff -u src/sys/ufs/ffs/ffs_vnops.c:1.134 src/sys/ufs/ffs/ffs_vnops.c:1.135
--- src/sys/ufs/ffs/ffs_vnops.c:1.134	Tue Jun 29 18:34:09 2021
+++ src/sys/ufs/ffs/ffs_vnops.c	Wed Jul 14 03:24:14 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vnops.c,v 1.134 2021/06/29 22:34:09 dholland Exp $	*/
+/*	$NetBSD: ffs_vnops.c,v 1.135 2021/07/14 07:24:14 christos Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_vnops.c,v 1.134 2021/06/29 22:34:09 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_vnops.c,v 1.135 2021/07/14 07:24:14 christos Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -261,7 +261,7 @@ const struct vnodeopv_entry_desc ffs_fif
 	{ _lock_desc, ufs_lock },			/* lock */
 	{ _unlock_desc, ufs_unlock },		/* unlock */
 	{ _bmap_desc, vn_fifo_bypass },		/* bmap */
-	{ _strategy_desc, vn_fifo_bypass },		/* strategy */
+	{ _strategy_desc, ffsext_strategy },	/* strategy */
 	{ _print_desc, ufs_print },			/* print */
 	{ _islocked_desc, ufs_islocked },		/* islocked */
 	{ _pathconf_desc, vn_fifo_bypass },		/* pathconf */



CVS commit: src/sys/ufs/chfs

2021-07-05 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Mon Jul  5 21:43:56 UTC 2021

Modified Files:
src/sys/ufs/chfs: chfs_vnops.c

Log Message:
whitespace


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/sys/ufs/chfs/chfs_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/chfs/chfs_vnops.c
diff -u src/sys/ufs/chfs/chfs_vnops.c:1.43 src/sys/ufs/chfs/chfs_vnops.c:1.44
--- src/sys/ufs/chfs/chfs_vnops.c:1.43	Tue Jun 29 22:34:09 2021
+++ src/sys/ufs/chfs/chfs_vnops.c	Mon Jul  5 21:43:56 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: chfs_vnops.c,v 1.43 2021/06/29 22:34:09 dholland Exp $	*/
+/*	$NetBSD: chfs_vnops.c,v 1.44 2021/07/05 21:43:56 dholland Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -1598,7 +1598,7 @@ int
 const struct vnodeopv_entry_desc chfs_vnodeop_entries[] =
 	{
 		{ _default_desc, vn_default_error },
-	{ _parsepath_desc, genfs_parsepath },	/* parsepath */
+		{ _parsepath_desc, genfs_parsepath },	/* parsepath */
 		{ _lookup_desc, chfs_lookup },
 		{ _create_desc, chfs_create },
 		{ _mknod_desc, chfs_mknod },



CVS commit: src/sys/ufs/ufs

2020-12-25 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Fri Dec 25 10:00:40 UTC 2020

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

Log Message:
Avoid potentially accessing an array with an index out of range.

Reported-by: syzbot+8832f540234b996bc...@syzkaller.appspotmail.com
Reported-by: syzbot+0b785dd10d987350e...@syzkaller.appspotmail.com


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/ufs/ufs/ufs_quota1.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_quota1.c
diff -u src/sys/ufs/ufs/ufs_quota1.c:1.22 src/sys/ufs/ufs/ufs_quota1.c:1.23
--- src/sys/ufs/ufs/ufs_quota1.c:1.22	Mon Jun 20 00:52:04 2016
+++ src/sys/ufs/ufs/ufs_quota1.c	Fri Dec 25 10:00:40 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_quota1.c,v 1.22 2016/06/20 00:52:04 dholland Exp $	*/
+/*	$NetBSD: ufs_quota1.c,v 1.23 2020/12/25 10:00:40 nia Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993, 1995
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ufs_quota1.c,v 1.22 2016/06/20 00:52:04 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_quota1.c,v 1.23 2020/12/25 10:00:40 nia Exp $");
 
 #include 
 #include 
@@ -311,6 +311,9 @@ quota1_handle_cmd_quotaon(struct lwp *l,
 	struct pathbuf *pb;
 	struct nameidata nd;
 
+	if (type < 0 || type >= MAXQUOTAS)
+		return EINVAL;
+
 	if (ump->um_flags & UFS_QUOTA2) {
 		uprintf("%s: quotas v2 already enabled\n",
 		mp->mnt_stat.f_mntonname);
@@ -421,6 +424,9 @@ quota1_handle_cmd_quotaoff(struct lwp *l
 	kauth_cred_t cred;
 	int i, error;
 
+	if (type < 0 || type >= MAXQUOTAS)
+		return EINVAL;
+
 	mutex_enter();
 	while ((ump->umq1_qflags[type] & (QTF_CLOSING | QTF_OPENING)) != 0)
 		cv_wait(, );



CVS commit: src/sys/ufs

2020-09-24 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu Sep 24 17:20:53 UTC 2020

Modified Files:
src/sys/ufs: files.ufs

Log Message:
lfs: Include lfs_debug.c only if DEBUG is enabled.


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/sys/ufs/files.ufs

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/files.ufs
diff -u src/sys/ufs/files.ufs:1.48 src/sys/ufs/files.ufs:1.49
--- src/sys/ufs/files.ufs:1.48	Sat May 16 18:31:53 2020
+++ src/sys/ufs/files.ufs	Thu Sep 24 17:20:53 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: files.ufs,v 1.48 2020/05/16 18:31:53 christos Exp $
+#	$NetBSD: files.ufs,v 1.49 2020/09/24 17:20:53 riastradh Exp $
 
 deffs	FFS
 deffs	EXT2FS
@@ -68,7 +68,7 @@ file	ufs/lfs/lfs_alloc.c		lfs
 file	ufs/lfs/lfs_balloc.c		lfs
 file	ufs/lfs/lfs_bio.c		lfs
 file	ufs/lfs/lfs_cksum.c		lfs
-file	ufs/lfs/lfs_debug.c		lfs
+file	ufs/lfs/lfs_debug.c		lfs & debug
 file	ufs/lfs/lfs_inode.c		lfs
 file	ufs/lfs/lfs_itimes.c		lfs
 file	ufs/lfs/lfs_pages.c		lfs



CVS commit: src/sys/ufs/lfs

2020-09-06 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Sep  7 02:28:12 UTC 2020

Modified Files:
src/sys/ufs/lfs: lfs_accessors.h

Log Message:
Suppress -Waddress-of-packed-member just for lfs_accessors.h.

We can remove -Wno-error=address-of-packed-member from various
makefiles now.


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/sys/ufs/lfs/lfs_accessors.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/ufs/lfs/lfs_accessors.h
diff -u src/sys/ufs/lfs/lfs_accessors.h:1.49 src/sys/ufs/lfs/lfs_accessors.h:1.50
--- src/sys/ufs/lfs/lfs_accessors.h:1.49	Sat Mar 21 06:11:05 2020
+++ src/sys/ufs/lfs/lfs_accessors.h	Mon Sep  7 02:28:12 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_accessors.h,v 1.49 2020/03/21 06:11:05 riastradh Exp $	*/
+/*	$NetBSD: lfs_accessors.h,v 1.50 2020/09/07 02:28:12 riastradh Exp $	*/
 
 /*  from NetBSD: lfs.h,v 1.165 2015/07/24 06:59:32 dholland Exp  */
 /*  from NetBSD: dinode.h,v 1.25 2016/01/22 23:06:10 dholland Exp  */
@@ -218,6 +218,31 @@
 
 
 /*
+ * Suppress spurious warnings -- we use
+ *
+ *	type *foo = >member;
+ *
+ * in macros to verify that obj->member has the right type.  When the
+ * object is a packed structure with misaligned members, this causes
+ * some compiles to squeal that taking the address might lead to
+ * undefined behaviour later on -- which is helpful in general, not
+ * relevant in this case, because we don't do anything with foo
+ * afterward; we only declare it to get a type check and then we
+ * discard it.
+ */
+#ifdef __GNUC__
+#if defined(__clang__)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Waddress-of-packed-member"
+#elif __GNUC_PREREQ__(9,0)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Waddress-of-packed-member"
+#endif
+#endif
+
+
+
+/*
  * directories
  */
 
@@ -1508,5 +1533,16 @@ lfs_blocks_sub(STRUCT_LFS *fs, union lfs
 #define LFS_NRESERVE(F) (lfs_btofsb((F), (2 * ULFS_NIADDR + 3) << lfs_sb_getbshift(F)))
 
 
+/*
+ * Suppress spurious clang warnings
+ */
+#ifdef __GNUC__
+#if defined(__clang__)
+#pragma clang diagnostic pop
+#elif __GNUC_PREREQ__(9,0)
+#pragma GCC diagnostic pop
+#endif
+#endif
+
 
 #endif /* _UFS_LFS_LFS_ACCESSORS_H_ */



CVS commit: src/sys/ufs

2020-08-20 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Aug 20 20:28:13 UTC 2020

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

Log Message:
Don't cache id's for vnodes that have ACLs. ok chs@


To generate a diff of this commit:
cvs rdiff -u -r1.371 -r1.372 src/sys/ufs/ffs/ffs_vfsops.c
cvs rdiff -u -r1.77 -r1.78 src/sys/ufs/ufs/inode.h
cvs rdiff -u -r1.255 -r1.256 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.371 src/sys/ufs/ffs/ffs_vfsops.c:1.372
--- src/sys/ufs/ffs/ffs_vfsops.c:1.371	Sun Jul  5 16:37:40 2020
+++ src/sys/ufs/ffs/ffs_vfsops.c	Thu Aug 20 16:28:13 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.371 2020/07/05 20:37:40 christos Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.372 2020/08/20 20:28:13 christos Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.371 2020/07/05 20:37:40 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.372 2020/08/20 20:28:13 christos Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -2139,7 +2139,7 @@ ffs_loadvnode(struct mount *mp, struct v
 		ip->i_gid = ip->i_ffs1_ogid;			/* XXX */
 	}			/* XXX */
 	uvm_vnp_setsize(vp, ip->i_size);
-	cache_enter_id(vp, ip->i_mode, ip->i_uid, ip->i_gid, true);
+	cache_enter_id(vp, ip->i_mode, ip->i_uid, ip->i_gid, !HAS_ACLS(ip));
 	*new_key = >i_number;
 	return 0;
 }
@@ -2261,7 +2261,7 @@ ffs_newvnode(struct mount *mp, struct vn
 	}
 
 	uvm_vnp_setsize(vp, ip->i_size);
-	cache_enter_id(vp, ip->i_mode, ip->i_uid, ip->i_gid, true);
+	cache_enter_id(vp, ip->i_mode, ip->i_uid, ip->i_gid, !HAS_ACLS(ip));
 	*new_key = >i_number;
 	return 0;
 }

Index: src/sys/ufs/ufs/inode.h
diff -u src/sys/ufs/ufs/inode.h:1.77 src/sys/ufs/ufs/inode.h:1.78
--- src/sys/ufs/ufs/inode.h:1.77	Sat Apr 18 15:18:34 2020
+++ src/sys/ufs/ufs/inode.h	Thu Aug 20 16:28:13 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: inode.h,v 1.77 2020/04/18 19:18:34 christos Exp $	*/
+/*	$NetBSD: inode.h,v 1.78 2020/08/20 20:28:13 christos Exp $	*/
 
 /*
  * Copyright (c) 1982, 1989, 1993
@@ -238,6 +238,14 @@ struct inode {
 #if defined(_KERNEL)
 
 /*
+ * This macro does not differentiate between having extattrs and having
+ * extattrs containing ACLS, but that's ok since it is only used to
+ * determine if we are eligible for namei cache and we can be pessimistic
+ */
+#define HAS_ACLS(ip) \
+((ip)->i_ump->um_fstype == UFS2 && (ip)->i_ffs2_extsize > 0)
+
+/*
  * The DIP macro is used to access fields in the dinode that are
  * not cached in the inode itself.
  */

Index: src/sys/ufs/ufs/ufs_vnops.c
diff -u src/sys/ufs/ufs/ufs_vnops.c:1.255 src/sys/ufs/ufs/ufs_vnops.c:1.256
--- src/sys/ufs/ufs/ufs_vnops.c:1.255	Mon May 18 04:28:44 2020
+++ src/sys/ufs/ufs/ufs_vnops.c	Thu Aug 20 16:28:13 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_vnops.c,v 1.255 2020/05/18 08:28:44 hannken Exp $	*/
+/*	$NetBSD: ufs_vnops.c,v 1.256 2020/08/20 20:28:13 christos Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2020 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ufs_vnops.c,v 1.255 2020/05/18 08:28:44 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_vnops.c,v 1.256 2020/08/20 20:28:13 christos Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -669,7 +669,7 @@ ufs_setattr(void *v)
 	}
 	VN_KNOTE(vp, NOTE_ATTRIB);
 out:
-	cache_enter_id(vp, ip->i_mode, ip->i_uid, ip->i_gid, true);
+	cache_enter_id(vp, ip->i_mode, ip->i_uid, ip->i_gid, !HAS_ACLS(ip));
 	return (error);
 }
 
@@ -740,7 +740,7 @@ ufs_chmod(struct vnode *vp, int mode, ka
 	ip->i_flag |= IN_CHANGE;
 	DIP_ASSIGN(ip, mode, ip->i_mode);
 	UFS_WAPBL_UPDATE(vp, NULL, NULL, 0);
-	cache_enter_id(vp, ip->i_mode, ip->i_uid, ip->i_gid, true);
+	cache_enter_id(vp, ip->i_mode, ip->i_uid, ip->i_gid, !HAS_ACLS(ip));
 	return (0);
 }
 
@@ -810,7 +810,7 @@ ufs_chown(struct vnode *vp, uid_t uid, g
 #endif /* QUOTA || QUOTA2 */
 	ip->i_flag |= IN_CHANGE;
 	UFS_WAPBL_UPDATE(vp, NULL, NULL, 0);
-	cache_enter_id(vp, ip->i_mode, ip->i_uid, ip->i_gid, true);
+	cache_enter_id(vp, ip->i_mode, ip->i_uid, ip->i_gid, !HAS_ACLS(ip));
 	return (0);
 }
 



CVS commit: src/sys/ufs/lfs

2020-08-13 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu Aug 13 17:26:43 UTC 2020

Modified Files:
src/sys/ufs/lfs: lfs_segment.c

Log Message:
Skip unlinked inodes.

They no longer matter on disk so we don't need to write anything out
for them.


To generate a diff of this commit:
cvs rdiff -u -r1.286 -r1.287 src/sys/ufs/lfs/lfs_segment.c

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

Modified files:

Index: src/sys/ufs/lfs/lfs_segment.c
diff -u src/sys/ufs/lfs/lfs_segment.c:1.286 src/sys/ufs/lfs/lfs_segment.c:1.287
--- src/sys/ufs/lfs/lfs_segment.c:1.286	Sun Feb 23 15:46:42 2020
+++ src/sys/ufs/lfs/lfs_segment.c	Thu Aug 13 17:26:43 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_segment.c,v 1.286 2020/02/23 15:46:42 ad Exp $	*/
+/*	$NetBSD: lfs_segment.c,v 1.287 2020/08/13 17:26:43 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_segment.c,v 1.286 2020/02/23 15:46:42 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_segment.c,v 1.287 2020/08/13 17:26:43 riastradh Exp $");
 
 #ifdef DEBUG
 # define vndebug(vp, str) do {		\
@@ -487,7 +487,7 @@ lfs_writevnodes_selector(void *cl, struc
 	KASSERT(mutex_owned(vp->v_interlock));
 
 	ip = VTOI(vp);
-	if (ip == NULL || vp->v_type == VNON)
+	if (ip == NULL || vp->v_type == VNON || ip->i_nlink <= 0)
 		return false;
 	if ((op == VN_DIROP && !(vp->v_uflag & VU_DIROP)) ||
 	(op != VN_DIROP && op != VN_CLEAN && (vp->v_uflag & VU_DIROP))) {



CVS commit: src/sys/ufs/lfs

2020-08-03 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Aug  4 03:00:47 UTC 2020

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

Log Message:
Mark lfs vnodes with VV_LOCKSWORK, same as ffs.


To generate a diff of this commit:
cvs rdiff -u -r1.378 -r1.379 src/sys/ufs/lfs/lfs_vfsops.c

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

Modified files:

Index: src/sys/ufs/lfs/lfs_vfsops.c
diff -u src/sys/ufs/lfs/lfs_vfsops.c:1.378 src/sys/ufs/lfs/lfs_vfsops.c:1.379
--- src/sys/ufs/lfs/lfs_vfsops.c:1.378	Sat Apr  4 20:49:31 2020
+++ src/sys/ufs/lfs/lfs_vfsops.c	Tue Aug  4 03:00:47 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_vfsops.c,v 1.378 2020/04/04 20:49:31 ad Exp $	*/
+/*	$NetBSD: lfs_vfsops.c,v 1.379 2020/08/04 03:00:47 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007, 2007
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_vfsops.c,v 1.378 2020/04/04 20:49:31 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_vfsops.c,v 1.379 2020/08/04 03:00:47 riastradh Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_lfs.h"
@@ -1592,6 +1592,7 @@ lfs_init_vnode(struct ulfsmount *ump, in
 
 	vp->v_tag = VT_LFS;
 	vp->v_op = lfs_vnodeop_p;
+	vp->v_vflag |= VV_LOCKSWORK;
 	vp->v_data = ip;
 }
 



CVS commit: src/sys/ufs

2020-07-25 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Sun Jul 26 00:21:24 UTC 2020

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

Log Message:
pull in a bit more FreeBSD code to allow specifying truncation of
the regular bmap (IO_NORMAL) independently of the extattr bmap (IO_EXT).
fixes fs corruption when removing extattrs in UFS2.


To generate a diff of this commit:
cvs rdiff -u -r1.129 -r1.130 src/sys/ufs/ffs/ffs_inode.c
cvs rdiff -u -r1.110 -r1.111 src/sys/ufs/ufs/ufs_inode.c

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

Modified files:

Index: src/sys/ufs/ffs/ffs_inode.c
diff -u src/sys/ufs/ffs/ffs_inode.c:1.129 src/sys/ufs/ffs/ffs_inode.c:1.130
--- src/sys/ufs/ffs/ffs_inode.c:1.129	Sat May  2 22:11:16 2020
+++ src/sys/ufs/ffs/ffs_inode.c	Sun Jul 26 00:21:24 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_inode.c,v 1.129 2020/05/02 22:11:16 christos Exp $	*/
+/*	$NetBSD: ffs_inode.c,v 1.130 2020/07/26 00:21:24 chs Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_inode.c,v 1.129 2020/05/02 22:11:16 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_inode.c,v 1.130 2020/07/26 00:21:24 chs Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -232,6 +232,14 @@ ffs_truncate(struct vnode *ovp, off_t le
 	if (length < 0)
 		return (EINVAL);
 
+	/*
+	 * Historically clients did not have to specify which data
+	 * they were truncating. So, if not specified, we assume
+	 * traditional behavior, e.g., just the normal data.
+	 */
+	if ((ioflag & (IO_EXT | IO_NORMAL)) == 0)
+		ioflag |= IO_NORMAL;
+
 	fs = oip->i_fs;
 #define i_din2 i_din.ffs2_din
 	extblocks = 0;
@@ -267,6 +275,8 @@ ffs_truncate(struct vnode *ovp, off_t le
 			extblocks = 0;
 		}
 	}
+	if ((ioflag & IO_NORMAL) == 0)
+		return (0);
 	if (ovp->v_type == VLNK &&
 	(oip->i_size < ump->um_maxsymlinklen ||
 	 (ump->um_maxsymlinklen == 0 && datablocks == 0))) {
@@ -376,8 +386,7 @@ ffs_truncate(struct vnode *ovp, off_t le
 		}
 	}
 
-	if (!(ioflag & IO_EXT))
-		genfs_node_wrlock(ovp);
+	genfs_node_wrlock(ovp);
 	oip->i_size = length;
 	DIP_ASSIGN(oip, size, length);
 	uvm_vnp_setsize(ovp, length);
@@ -586,8 +595,7 @@ out:
 	oip->i_size = length;
 	DIP_ASSIGN(oip, size, length);
 	DIP_ADD(oip, blocks, -blocksreleased);
-	if (!(ioflag & IO_EXT))
-		genfs_node_unlock(ovp);
+	genfs_node_unlock(ovp);
 	oip->i_flag |= IN_CHANGE;
 	UFS_WAPBL_UPDATE(ovp, NULL, NULL, 0);
 #if defined(QUOTA) || defined(QUOTA2)

Index: src/sys/ufs/ufs/ufs_inode.c
diff -u src/sys/ufs/ufs/ufs_inode.c:1.110 src/sys/ufs/ufs/ufs_inode.c:1.111
--- src/sys/ufs/ufs/ufs_inode.c:1.110	Sat Apr 18 19:18:34 2020
+++ src/sys/ufs/ufs/ufs_inode.c	Sun Jul 26 00:21:24 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_inode.c,v 1.110 2020/04/18 19:18:34 christos Exp $	*/
+/*	$NetBSD: ufs_inode.c,v 1.111 2020/07/26 00:21:24 chs Exp $	*/
 
 /*
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ufs_inode.c,v 1.110 2020/04/18 19:18:34 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_inode.c,v 1.111 2020/07/26 00:21:24 chs Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -327,5 +327,5 @@ ufs_truncate_all(struct vnode *vp)
 
 	if (isize == 0)
 		return 0;
-	return ufs_truncate_retry(vp, IO_EXT, 0, NOCRED);
+	return ufs_truncate_retry(vp, IO_NORMAL | IO_EXT, 0, NOCRED);
 }



CVS commit: src/sys/ufs/ffs

2020-07-25 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Sun Jul 26 00:20:14 UTC 2020

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

Log Message:
skip the assertions about page-locking when allocating to the extattr bmap,
since extattrs do not use the page cache.


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

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

Modified files:

Index: src/sys/ufs/ffs/ffs_alloc.c
diff -u src/sys/ufs/ffs/ffs_alloc.c:1.167 src/sys/ufs/ffs/ffs_alloc.c:1.168
--- src/sys/ufs/ffs/ffs_alloc.c:1.167	Sat Apr 18 19:18:34 2020
+++ src/sys/ufs/ffs/ffs_alloc.c	Sun Jul 26 00:20:13 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_alloc.c,v 1.167 2020/04/18 19:18:34 christos Exp $	*/
+/*	$NetBSD: ffs_alloc.c,v 1.168 2020/07/26 00:20:13 chs Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.167 2020/04/18 19:18:34 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.168 2020/07/26 00:20:13 chs Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -204,7 +204,7 @@ ffs_alloc(struct inode *ip, daddr_t lbn,
 	 */
 
 	struct vnode *vp = ITOV(ip);
-	if (vp->v_type == VREG &&
+	if (vp->v_type == VREG && (flags & IO_EXT) == 0 &&
 	ffs_lblktosize(fs, (voff_t)lbn) < round_page(vp->v_size) &&
 	((vp->v_vflag & VV_MAPPED) != 0 || (size & PAGE_MASK) != 0 ||
 	 ffs_blkoff(fs, size) != 0)) {



CVS commit: src/sys/ufs/ffs

2020-07-05 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Jul  5 20:37:40 UTC 2020

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

Log Message:
simplify the acl setup, and fix reversed mask in the fs_flags code.


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

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

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.370 src/sys/ufs/ffs/ffs_vfsops.c:1.371
--- src/sys/ufs/ffs/ffs_vfsops.c:1.370	Mon May 18 04:28:44 2020
+++ src/sys/ufs/ffs/ffs_vfsops.c	Sun Jul  5 16:37:40 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.370 2020/05/18 08:28:44 hannken Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.371 2020/07/05 20:37:40 christos Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.370 2020/05/18 08:28:44 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.371 2020/07/05 20:37:40 christos Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -404,8 +404,8 @@ ffs_acls(struct mount *mp, int fs_flags)
 			printf("WARNING: %s: ACLs flag on fs conflicts with "
 			"\"posix1eacls\" mount option; option ignored\n",
 			mp->mnt_stat.f_mntonname);
-		mp->mnt_flag &= ~MNT_ACLS;
-		mp->mnt_flag |= MNT_POSIX1EACLS;
+		mp->mnt_flag &= ~MNT_POSIX1EACLS;
+		mp->mnt_flag |= MNT_ACLS;
 
 #else
 		printf("WARNING: %s: ACLs flag on fs but no ACLs support\n",
@@ -418,8 +418,8 @@ ffs_acls(struct mount *mp, int fs_flags)
 			printf("WARNING: %s: NFSv4 ACLs flag on fs conflicts "
 			"with \"acls\" mount option; option ignored\n",
 			mp->mnt_stat.f_mntonname);
-		mp->mnt_flag &= ~MNT_POSIX1EACLS;
-		mp->mnt_flag |= MNT_ACLS;
+		mp->mnt_flag &= ~MNT_ACLS;
+		mp->mnt_flag |= MNT_POSIX1EACLS;
 #else
 		printf("WARNING: %s: POSIX.1e ACLs flag on fs but no "
 		"ACLs support\n", mp->mnt_stat.f_mntonname);
@@ -658,14 +658,13 @@ ffs_mount(struct mount *mp, const char *
 			fs->fs_fmod = 0;
 		}
 
+		ffs_acls(mp, fs->fs_flags);
 		if (mp->mnt_flag & MNT_RELOAD) {
 			error = ffs_reload(mp, l->l_cred, l);
 			if (error) {
 DPRINTF("ffs_reload returned %d", error);
 return error;
 			}
-		} else {
-			ffs_acls(mp, 0);
 		}
 
 		if (fs->fs_ronly && (mp->mnt_iflag & IMNT_WANTRDWR)) {
@@ -908,8 +907,6 @@ ffs_reload(struct mount *mp, kauth_cred_
 	}
 	ffs_oldfscompat_read(fs, ump, sblockloc);
 
-	ffs_acls(mp, 0);
-
 	mutex_enter(>um_lock);
 	ump->um_maxfilesize = fs->fs_maxfilesize;
 	if (fs->fs_flags & ~(FS_KNOWN_FLAGS | FS_INTERNAL)) {



CVS commit: src/sys/ufs/chfs

2020-05-20 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed May 20 17:04:58 UTC 2020

Modified Files:
src/sys/ufs/chfs: chfs_vnops.c

Log Message:
fix accessx confusion (thanks hannken@)


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/sys/ufs/chfs/chfs_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/chfs/chfs_vnops.c
diff -u src/sys/ufs/chfs/chfs_vnops.c:1.39 src/sys/ufs/chfs/chfs_vnops.c:1.40
--- src/sys/ufs/chfs/chfs_vnops.c:1.39	Sat May 16 14:31:53 2020
+++ src/sys/ufs/chfs/chfs_vnops.c	Wed May 20 13:04:58 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: chfs_vnops.c,v 1.39 2020/05/16 18:31:53 christos Exp $	*/
+/*	$NetBSD: chfs_vnops.c,v 1.40 2020/05/20 17:04:58 christos Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -1663,7 +1663,7 @@ const struct vnodeopv_entry_desc chfs_sp
 		{ _open_desc, spec_open },
 		{ _close_desc, ufsspec_close },
 		{ _access_desc, chfs_access },
-		{ _accessx_desc, genfs_access },
+		{ _accessx_desc, genfs_accessx },
 		{ _getattr_desc, chfs_getattr },
 		{ _setattr_desc, chfs_setattr },
 		{ _read_desc, chfs_read },
@@ -1720,7 +1720,7 @@ const struct vnodeopv_entry_desc chfs_fi
 		{ _open_desc, vn_fifo_bypass },
 		{ _close_desc, ufsfifo_close },
 		{ _access_desc, chfs_access },
-		{ _accessx_desc, genfs_access },
+		{ _accessx_desc, genfs_accessx },
 		{ _getattr_desc, chfs_getattr },
 		{ _setattr_desc, chfs_setattr },
 		{ _read_desc, ufsfifo_read },



CVS commit: src/sys/ufs/ffs

2020-05-20 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed May 20 13:16:30 UTC 2020

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

Log Message:
remove accmode_t typedef (not needed, breaks llvm) from maxv@


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/ufs/ffs/ffs_extattr.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_extattr.c
diff -u src/sys/ufs/ffs/ffs_extattr.c:1.5 src/sys/ufs/ffs/ffs_extattr.c:1.6
--- src/sys/ufs/ffs/ffs_extattr.c:1.5	Sat May 16 14:31:53 2020
+++ src/sys/ufs/ffs/ffs_extattr.c	Wed May 20 09:16:30 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_extattr.c,v 1.5 2020/05/16 18:31:53 christos Exp $	*/
+/*	$NetBSD: ffs_extattr.c,v 1.6 2020/05/20 13:16:30 christos Exp $	*/
 
 /*-
  * SPDX-License-Identifier: (BSD-2-Clause-FreeBSD AND BSD-3-Clause)
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_extattr.c,v 1.5 2020/05/16 18:31:53 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_extattr.c,v 1.6 2020/05/20 13:16:30 christos Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -121,7 +121,6 @@ __KERNEL_RCSID(0, "$NetBSD: ffs_extattr.
 #define	lblkno(fs, o)		ffs_lblkno(fs, o)
 #define	blkoff(fs, o)		ffs_blkoff(fs, o)
 #define	sblksize(fs, o, lbn)	ffs_sblksize(fs, o, lbn)
-typedef mode_t accmode_t;	/* so that it breaks soon */
 typedef daddr_t ufs_lbn_t;
 #define msleep(chan, mtx, pri, wmesg, timeo) \
 mtsleep((chan), (pri), (wmesg), (timeo), *(mtx))



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/ufs/ffs

2020-05-02 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat May  2 22:11:16 UTC 2020

Modified Files:
src/sys/ufs/ffs: ffs_extattr.c ffs_inode.c

Log Message:
Remove the unlock/relock hack by using IO_EXT to indicate that we are already
holding the lock.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/ufs/ffs/ffs_extattr.c
cvs rdiff -u -r1.128 -r1.129 src/sys/ufs/ffs/ffs_inode.c

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

Modified files:

Index: src/sys/ufs/ffs/ffs_extattr.c
diff -u src/sys/ufs/ffs/ffs_extattr.c:1.3 src/sys/ufs/ffs/ffs_extattr.c:1.4
--- src/sys/ufs/ffs/ffs_extattr.c:1.3	Mon Apr 20 14:10:10 2020
+++ src/sys/ufs/ffs/ffs_extattr.c	Sat May  2 18:11:16 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_extattr.c,v 1.3 2020/04/20 18:10:10 christos Exp $	*/
+/*	$NetBSD: ffs_extattr.c,v 1.4 2020/05/02 22:11:16 christos Exp $	*/
 
 /*-
  * SPDX-License-Identifier: (BSD-2-Clause-FreeBSD AND BSD-3-Clause)
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_extattr.c,v 1.3 2020/04/20 18:10:10 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_extattr.c,v 1.4 2020/05/02 22:11:16 christos Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -392,10 +392,8 @@ ffs_extwrite(struct vnode *vp, struct ui
 	}
 	if (error) {
 		if (ioflag & IO_UNIT) {
-			genfs_node_unlock(vp);	// XXX: need our own lock
 			(void)ffs_truncate(vp, osize,
 			IO_EXT | (ioflag_SYNC), ucred);
-			genfs_node_wrlock(vp);
 			uio->uio_offset -= resid - uio->uio_resid;
 			uio->uio_resid = resid;
 		}
@@ -561,9 +559,7 @@ ffs_close_ea(struct vnode *vp, int commi
 ffs_unlock_ea(vp);
 return error;
 			}
-			genfs_node_unlock(vp);	// XXX: need our own lock
 			error = ffs_truncate(vp, 0, IO_EXT, cred);
-			genfs_node_wrlock(vp);
 			UFS_WAPBL_END(vp->v_mount);
 		}
 		error = ffs_extwrite(vp, , IO_EXT | IO_SYNC, cred);

Index: src/sys/ufs/ffs/ffs_inode.c
diff -u src/sys/ufs/ffs/ffs_inode.c:1.128 src/sys/ufs/ffs/ffs_inode.c:1.129
--- src/sys/ufs/ffs/ffs_inode.c:1.128	Thu Apr 23 17:47:09 2020
+++ src/sys/ufs/ffs/ffs_inode.c	Sat May  2 18:11:16 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_inode.c,v 1.128 2020/04/23 21:47:09 ad Exp $	*/
+/*	$NetBSD: ffs_inode.c,v 1.129 2020/05/02 22:11:16 christos Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_inode.c,v 1.128 2020/04/23 21:47:09 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_inode.c,v 1.129 2020/05/02 22:11:16 christos Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -376,7 +376,8 @@ ffs_truncate(struct vnode *ovp, off_t le
 		}
 	}
 
-	genfs_node_wrlock(ovp);
+	if (!(ioflag & IO_EXT))
+		genfs_node_wrlock(ovp);
 	oip->i_size = length;
 	DIP_ASSIGN(oip, size, length);
 	uvm_vnp_setsize(ovp, length);
@@ -585,7 +586,8 @@ out:
 	oip->i_size = length;
 	DIP_ASSIGN(oip, size, length);
 	DIP_ADD(oip, blocks, -blocksreleased);
-	genfs_node_unlock(ovp);
+	if (!(ioflag & IO_EXT))
+		genfs_node_unlock(ovp);
 	oip->i_flag |= IN_CHANGE;
 	UFS_WAPBL_UPDATE(ovp, NULL, NULL, 0);
 #if defined(QUOTA) || defined(QUOTA2)



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/ufs/ffs

2020-04-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Apr 21 15:04:13 UTC 2020

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

Log Message:
use %s/__func__ so that the strings can be shared.


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 src/sys/ufs/ffs/ffs_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/ufs/ffs/ffs_subr.c
diff -u src/sys/ufs/ffs/ffs_subr.c:1.51 src/sys/ufs/ffs/ffs_subr.c:1.52
--- src/sys/ufs/ffs/ffs_subr.c:1.51	Mon May 27 23:53:28 2019
+++ src/sys/ufs/ffs/ffs_subr.c	Tue Apr 21 11:04:12 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_subr.c,v 1.51 2019/05/28 03:53:28 kamil Exp $	*/
+/*	$NetBSD: ffs_subr.c,v 1.52 2020/04/21 15:04:12 christos Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -36,7 +36,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_subr.c,v 1.51 2019/05/28 03:53:28 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_subr.c,v 1.52 2020/04/21 15:04:12 christos Exp $");
 
 #include 
 
@@ -195,7 +195,7 @@ ffs_isblock(struct fs *fs, u_char *cp, i
 		mask = 0x01 << (h & 0x7);
 		return ((cp[h >> 3] & mask) == mask);
 	default:
-		panic("ffs_isblock: unknown fs_fragshift %d",
+		panic("%s: unknown fs_fragshift %d", __func__,
 		(int)fs->fs_fragshift);
 	}
 }
@@ -219,7 +219,7 @@ ffs_isfreeblock(struct fs *fs, u_char *c
 	case 0:
 		return ((cp[h >> 3] & (0x01 << (h & 0x7))) == 0);
 	default:
-		panic("ffs_isfreeblock: unknown fs_fragshift %d",
+		panic("%s: unknown fs_fragshift %d", __func__,
 		(int)fs->fs_fragshift);
 	}
 }
@@ -245,7 +245,7 @@ ffs_clrblock(struct fs *fs, u_char *cp, 
 		cp[h >> 3] &= ~(0x01 << (h & 0x7));
 		return;
 	default:
-		panic("ffs_clrblock: unknown fs_fragshift %d",
+		panic("%s: unknown fs_fragshift %d", __func__,
 		(int)fs->fs_fragshift);
 	}
 }
@@ -271,7 +271,7 @@ ffs_setblock(struct fs *fs, u_char *cp, 
 		cp[h >> 3] |= (0x01 << (h & 0x7));
 		return;
 	default:
-		panic("ffs_setblock: unknown fs_fragshift %d",
+		panic("%s: unknown fs_fragshift %d", __func__,
 		(int)fs->fs_fragshift);
 	}
 }



CVS commit: src/sys/ufs/ffs

2020-04-20 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Apr 20 18:10:10 UTC 2020

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

Log Message:
- Allow root to set system attributes, samba does this
- Fix locking issue, perhaps we should use our own mutex; does not seem worth
  it for this simple case.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/ufs/ffs/ffs_extattr.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_extattr.c
diff -u src/sys/ufs/ffs/ffs_extattr.c:1.2 src/sys/ufs/ffs/ffs_extattr.c:1.3
--- src/sys/ufs/ffs/ffs_extattr.c:1.2	Sun Apr 19 09:59:13 2020
+++ src/sys/ufs/ffs/ffs_extattr.c	Mon Apr 20 14:10:10 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_extattr.c,v 1.2 2020/04/19 13:59:13 christos Exp $	*/
+/*	$NetBSD: ffs_extattr.c,v 1.3 2020/04/20 18:10:10 christos Exp $	*/
 
 /*-
  * SPDX-License-Identifier: (BSD-2-Clause-FreeBSD AND BSD-3-Clause)
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_extattr.c,v 1.2 2020/04/19 13:59:13 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_extattr.c,v 1.3 2020/04/20 18:10:10 christos Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -153,8 +153,8 @@ ffs_extattr_check_cred(struct vnode *vp,
 	 */
 	switch (attrnamespace) {
 	case EXTATTR_NAMESPACE_SYSTEM:
-		/* Potentially with privs */
-		return EPERM;
+		return kauth_authorize_system(cred, KAUTH_SYSTEM_FS_EXTATTR,
+		0, vp->v_mount, NULL, NULL);
 	case EXTATTR_NAMESPACE_USER:
 		return VOP_ACCESS(vp, accmode, cred);
 	default:
@@ -392,8 +392,10 @@ ffs_extwrite(struct vnode *vp, struct ui
 	}
 	if (error) {
 		if (ioflag & IO_UNIT) {
+			genfs_node_unlock(vp);	// XXX: need our own lock
 			(void)ffs_truncate(vp, osize,
 			IO_EXT | (ioflag_SYNC), ucred);
+			genfs_node_wrlock(vp);
 			uio->uio_offset -= resid - uio->uio_resid;
 			uio->uio_resid = resid;
 		}
@@ -559,7 +561,9 @@ ffs_close_ea(struct vnode *vp, int commi
 ffs_unlock_ea(vp);
 return error;
 			}
+			genfs_node_unlock(vp);	// XXX: need our own lock
 			error = ffs_truncate(vp, 0, IO_EXT, cred);
+			genfs_node_wrlock(vp);
 			UFS_WAPBL_END(vp->v_mount);
 		}
 		error = ffs_extwrite(vp, , IO_EXT | IO_SYNC, cred);
@@ -935,7 +939,6 @@ ffs_deleteextattr(void *v)
 	error = ffs_extattr_check_cred(ap->a_vp, ap->a_attrnamespace,
 	ap->a_cred, VWRITE);
 	if (error) {
-
 		/*
 		 * ffs_lock_ea is not needed there, because the vnode
 		 * must be exclusively locked.



CVS commit: src/sys/ufs/ufs

2020-04-19 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Apr 20 03:57:02 UTC 2020

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

Log Message:
handle negative small block numbers for extattr


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/sys/ufs/ufs/ufs_bmap.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_bmap.c
diff -u src/sys/ufs/ufs/ufs_bmap.c:1.52 src/sys/ufs/ufs/ufs_bmap.c:1.53
--- src/sys/ufs/ufs/ufs_bmap.c:1.52	Sat Mar 18 01:33:06 2017
+++ src/sys/ufs/ufs/ufs_bmap.c	Sun Apr 19 23:57:02 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_bmap.c,v 1.52 2017/03/18 05:33:06 riastradh Exp $	*/
+/*	$NetBSD: ufs_bmap.c,v 1.53 2020/04/20 03:57:02 christos Exp $	*/
 
 /*
  * Copyright (c) 1989, 1991, 1993
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ufs_bmap.c,v 1.52 2017/03/18 05:33:06 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_bmap.c,v 1.53 2020/04/20 03:57:02 christos Exp $");
 
 #include 
 #include 
@@ -190,6 +190,13 @@ ufs_bmaparray(struct vnode *vp, daddr_t 
 			}
 		}
 		return (0);
+	} else if (bn < 0 && bn >= -UFS_NXADDR) {
+		KASSERT(ump->um_fstype == UFS2);
+		daddr = ufs_rw64(ip->i_ffs2_extb[-1 - bn], UFS_MPNEEDSWAP(ump));
+		*bnp = blkptrtodb(ump, daddr);
+		if (*bnp == 0)
+			*bnp = -1;
+		return 0;
 	}
 
 	xap = ap == NULL ? a : ap;



CVS commit: src/sys/ufs/ffs

2020-04-19 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Apr 19 13:59:13 UTC 2020

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

Log Message:
- add locking
- wrap wapbl around truncating, ffs_extwrite does it on its own.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/ufs/ffs/ffs_extattr.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_extattr.c
diff -u src/sys/ufs/ffs/ffs_extattr.c:1.1 src/sys/ufs/ffs/ffs_extattr.c:1.2
--- src/sys/ufs/ffs/ffs_extattr.c:1.1	Sat Apr 18 15:18:34 2020
+++ src/sys/ufs/ffs/ffs_extattr.c	Sun Apr 19 09:59:13 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_extattr.c,v 1.1 2020/04/18 19:18:34 christos Exp $	*/
+/*	$NetBSD: ffs_extattr.c,v 1.2 2020/04/19 13:59:13 christos Exp $	*/
 
 /*-
  * SPDX-License-Identifier: (BSD-2-Clause-FreeBSD AND BSD-3-Clause)
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_extattr.c,v 1.1 2020/04/18 19:18:34 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_extattr.c,v 1.2 2020/04/19 13:59:13 christos Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -478,34 +478,13 @@ ffs_rdextattr(u_char **p, struct vnode *
 static void
 ffs_lock_ea(struct vnode *vp)
 {
-#if 0
-	struct inode *ip;
-
-	ip = VTOI(vp);
-	VI_LOCK(vp);
-	while (ip->i_flag & IN_EA_LOCKED) {
-		UFS_INODE_SET_FLAG(ip, IN_EA_LOCKWAIT);
-		msleep(>i_ea_refs, >v_interlock, PINOD + 2, "ufs_ea",
-		0);
-	}
-	UFS_INODE_SET_FLAG(ip, IN_EA_LOCKED);
-	VI_UNLOCK(vp);
-#endif
+	genfs_node_wrlock(vp);
 }
 
 static void
 ffs_unlock_ea(struct vnode *vp)
 {
-#if 0
-	struct inode *ip;
-
-	ip = VTOI(vp);
-	VI_LOCK(vp);
-	if (ip->i_flag & IN_EA_LOCKWAIT)
-		wakeup(>i_ea_refs);
-	ip->i_flag &= ~(IN_EA_LOCKED | IN_EA_LOCKWAIT);
-	VI_UNLOCK(vp);
-#endif
+	genfs_node_unlock(vp);
 }
 
 static int
@@ -573,16 +552,17 @@ ffs_close_ea(struct vnode *vp, int commi
 		luio.uio_resid = ip->i_ea_len;
 		luio.uio_vmspace = vmspace_kernel();
 		luio.uio_rw = UIO_WRITE;
-		if ((error = UFS_WAPBL_BEGIN(vp->v_mount)) != 0) {
-			ffs_unlock_ea(vp);
-			return error;
-		}
 
 		/* XXX: I'm not happy about truncating to zero size */
-		if (ip->i_ea_len < dp->di_extsize)
+		if (ip->i_ea_len < dp->di_extsize) {
+			if ((error = UFS_WAPBL_BEGIN(vp->v_mount)) != 0) {
+ffs_unlock_ea(vp);
+return error;
+			}
 			error = ffs_truncate(vp, 0, IO_EXT, cred);
+			UFS_WAPBL_END(vp->v_mount);
+		}
 		error = ffs_extwrite(vp, , IO_EXT | IO_SYNC, cred);
-		UFS_WAPBL_END(vp->v_mount);
 	}
 	if (--ip->i_ea_refs == 0) {
 		free(ip->i_ea_area, M_TEMP);



CVS commit: src/sys/ufs

2020-04-11 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sat Apr 11 17:43:54 UTC 2020

Modified Files:
src/sys/ufs: files.ufs
src/sys/ufs/ffs: ffs_wapbl.c
src/sys/ufs/ufs: ufs_wapbl.h
Removed Files:
src/sys/ufs/ufs: ufs_wapbl.c

Log Message:
remove noncompilable WAPBL_DEBUG_INODES

PR kern/49554 by Thomas Klausner


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/sys/ufs/files.ufs
cvs rdiff -u -r1.45 -r1.46 src/sys/ufs/ffs/ffs_wapbl.c
cvs rdiff -u -r1.25 -r0 src/sys/ufs/ufs/ufs_wapbl.c
cvs rdiff -u -r1.18 -r1.19 src/sys/ufs/ufs/ufs_wapbl.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/ufs/files.ufs
diff -u src/sys/ufs/files.ufs:1.45 src/sys/ufs/files.ufs:1.46
--- src/sys/ufs/files.ufs:1.45	Mon Jun 17 03:32:58 2019
+++ src/sys/ufs/files.ufs	Sat Apr 11 17:43:54 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: files.ufs,v 1.45 2019/06/17 03:32:58 christos Exp $
+#	$NetBSD: files.ufs,v 1.46 2020/04/11 17:43:54 jdolecek Exp $
 
 deffs	FFS
 deffs	EXT2FS
@@ -111,4 +111,3 @@ file	ufs/ufs/quota2_subr.c		quota2 & (ff
 file	ufs/ufs/ufs_rename.c		ffs | mfs | chfs
 file	ufs/ufs/ufs_vfsops.c		ufs & (ffs | mfs | ext2fs | chfs)
 file	ufs/ufs/ufs_vnops.c		ufs & (ffs | mfs | ext2fs | chfs)
-file	ufs/ufs/ufs_wapbl.c		ffs & wapbl

Index: src/sys/ufs/ffs/ffs_wapbl.c
diff -u src/sys/ufs/ffs/ffs_wapbl.c:1.45 src/sys/ufs/ffs/ffs_wapbl.c:1.46
--- src/sys/ufs/ffs/ffs_wapbl.c:1.45	Fri Jan 17 20:08:10 2020
+++ src/sys/ufs/ffs/ffs_wapbl.c	Sat Apr 11 17:43:54 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_wapbl.c,v 1.45 2020/01/17 20:08:10 ad Exp $	*/
+/*	$NetBSD: ffs_wapbl.c,v 1.46 2020/04/11 17:43:54 jdolecek Exp $	*/
 
 /*-
  * Copyright (c) 2003,2006,2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_wapbl.c,v 1.45 2020/01/17 20:08:10 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_wapbl.c,v 1.46 2020/04/11 17:43:54 jdolecek Exp $");
 
 #define WAPBL_INTERNAL
 
@@ -179,10 +179,6 @@ ffs_wapbl_sync_metadata(struct mount *mp
 
 	UFS_WAPBL_JLOCK_ASSERT(ump->um_mountp);
 
-#ifdef WAPBL_DEBUG_INODES
-	ufs_wapbl_verify_inodes(mp, __func__);
-#endif
-
 	for (wd = fdealloc; wd != NULL; wd = TAILQ_NEXT(wd, wd_entries)) {
 		/*
 		 * blkfree errors are unreported, might silently fail

Index: src/sys/ufs/ufs/ufs_wapbl.h
diff -u src/sys/ufs/ufs/ufs_wapbl.h:1.18 src/sys/ufs/ufs/ufs_wapbl.h:1.19
--- src/sys/ufs/ufs/ufs_wapbl.h:1.18	Thu Mar  5 15:18:55 2020
+++ src/sys/ufs/ufs/ufs_wapbl.h	Sat Apr 11 17:43:54 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_wapbl.h,v 1.18 2020/03/05 15:18:55 riastradh Exp $	*/
+/*	$NetBSD: ufs_wapbl.h,v 1.19 2020/04/11 17:43:54 jdolecek Exp $	*/
 
 /*-
  * Copyright (c) 2003,2006,2008 The NetBSD Foundation, Inc.
@@ -82,18 +82,6 @@
 
 #if defined(WAPBL)
 
-#if defined(WAPBL_DEBUG)
-#define	WAPBL_DEBUG_INODES
-#endif
-
-#ifdef WAPBL_DEBUG_INODES
-#error Undefine WAPBL_DEBUG_INODES or update the code.  Have a nice day.
-#endif
-
-#ifdef WAPBL_DEBUG_INODES
-void	ufs_wapbl_verify_inodes(struct mount *, const char *);
-#endif
-
 static __inline int
 ufs_wapbl_begin(struct mount *mp, const char *file, int line)
 {
@@ -102,10 +90,6 @@ ufs_wapbl_begin(struct mount *mp, const 
 		error = wapbl_begin(mp->mnt_wapbl, file, line);
 		if (error)
 			return error;
-#ifdef WAPBL_DEBUG_INODES
-		if (mp->mnt_wapbl->wl_lock.lk_exclusivecount == 1)
-			ufs_wapbl_verify_inodes(mp, "wapbl_begin");
-#endif
 	}
 	return 0;
 }
@@ -114,10 +98,6 @@ static __inline void
 ufs_wapbl_end(struct mount *mp)
 {
 	if (mp->mnt_wapbl) {
-#ifdef WAPBL_DEBUG_INODES
-		if (mp->mnt_wapbl->wl_lock.lk_exclusivecount == 1)
-			ufs_wapbl_verify_inodes(mp, "wapbl_end");
-#endif
 		wapbl_end(mp->mnt_wapbl);
 	}
 }



CVS commit: src/sys/ufs/lfs

2020-03-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Mar 28 01:08:43 UTC 2020

Modified Files:
src/sys/ufs/lfs: lfs.h

Log Message:
Comment out some of the CTASSERTS for lint until I fix lint.


To generate a diff of this commit:
cvs rdiff -u -r1.207 -r1.208 src/sys/ufs/lfs/lfs.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/ufs/lfs/lfs.h
diff -u src/sys/ufs/lfs/lfs.h:1.207 src/sys/ufs/lfs/lfs.h:1.208
--- src/sys/ufs/lfs/lfs.h:1.207	Sat Mar 21 02:11:05 2020
+++ src/sys/ufs/lfs/lfs.h	Fri Mar 27 21:08:42 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs.h,v 1.207 2020/03/21 06:11:05 riastradh Exp $	*/
+/*	$NetBSD: lfs.h,v 1.208 2020/03/28 01:08:42 christos Exp $	*/
 
 /*  from NetBSD: dinode.h,v 1.25 2016/01/22 23:06:10 dholland Exp  */
 /*  from NetBSD: dir.h,v 1.25 2015/09/01 06:16:03 dholland Exp  */
@@ -370,7 +370,9 @@ union lfs_dirheader {
 	struct lfs_dirheader32 u_32;
 };
 __CTASSERT(__alignof(union lfs_dirheader) == __alignof(struct lfs_dirheader64));
+#ifndef __lint__
 __CTASSERT(__alignof(union lfs_dirheader) == __alignof(struct lfs_dirheader32));
+#endif
 
 typedef union lfs_dirheader LFS_DIRHEADER;
 
@@ -583,7 +585,9 @@ typedef union finfo {
 	struct finfo32 u_32;
 } FINFO;
 __CTASSERT(__alignof(union finfo) == __alignof(struct finfo64));
+#ifndef __lint__
 __CTASSERT(__alignof(union finfo) == __alignof(struct finfo32));
+#endif
 
 /*
  * inode info (part of the segment summary)
@@ -608,7 +612,9 @@ typedef union iinfo {
 	struct iinfo32 u_32;
 } IINFO;
 __CTASSERT(__alignof(union iinfo) == __alignof(struct iinfo64));
+#ifndef __lint__
 __CTASSERT(__alignof(union iinfo) == __alignof(struct iinfo32));
+#endif
 
 /*
  * Index file inode entries.
@@ -663,8 +669,10 @@ typedef union ifile {
 	struct ifile_v1 u_v1;
 } IFILE;
 __CTASSERT(__alignof(union ifile) == __alignof(struct ifile64));
+#ifndef __lint__
 __CTASSERT(__alignof(union ifile) == __alignof(struct ifile32));
 __CTASSERT(__alignof(union ifile) == __alignof(struct ifile_v1));
+#endif
 
 /*
  * Cleaner information structure.  This resides in the ifile and is used
@@ -702,8 +710,10 @@ typedef union _cleanerinfo {
 	CLEANERINFO32 u_32;
 	CLEANERINFO64 u_64;
 } CLEANERINFO;
+#ifndef __lint__
 __CTASSERT(__alignof(union _cleanerinfo) == __alignof(struct _cleanerinfo32));
 __CTASSERT(__alignof(union _cleanerinfo) == __alignof(struct _cleanerinfo64));
+#endif
 
 /*
  * On-disk segment summary information
@@ -781,7 +791,9 @@ union segsum {
 };
 __CTASSERT(__alignof(union segsum) == __alignof(struct segsum64));
 __CTASSERT(__alignof(union segsum) == __alignof(struct segsum32));
+#ifndef __lint__
 __CTASSERT(__alignof(union segsum) == __alignof(struct segsum_v1));
+#endif
 
 /*
  * On-disk super block.



CVS commit: src/sys/ufs/lfs

2020-03-21 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Mar 21 06:11:05 UTC 2020

Modified Files:
src/sys/ufs/lfs: lfs.h lfs_accessors.h

Log Message:
Avoid misaligned access to lfs64 on-disk records in memory.

lfs64 directory entries are only 32-bit aligned in order to conserve
space in directory blocks, and we had a hack to stuff a 64-bit inode
in them.  This replaces the hack by __aligned(4) __packed, and goes
further:

1. It's not clear that all the other lfs64 data structures are 64-bit
   aligned on disk to begin with.  We can go through these later and
   upgrade them from

struct foo64 {
...
} __aligned(4) __packed;

union foo {
struct foo64 f64;
...
};

   to

struct foo64 {
...
};

union foo {
struct foo64 f64 __aligned(8);
...
} __aligned(4) __packed;

   if we really want to take advantage of 64-bit memory accesses.

   However, the __aligned(4) __packed must remain on the union
   because:

2. We access even the lfs32 data structures via a union that has
   lfs64 members, and it turns out that compilers will assume access
   through a union with 64-bit aligned members implies the whole
   union has 64-bit alignment, even if we're only accessing a 32-bit
   aligned member.


To generate a diff of this commit:
cvs rdiff -u -r1.206 -r1.207 src/sys/ufs/lfs/lfs.h
cvs rdiff -u -r1.48 -r1.49 src/sys/ufs/lfs/lfs_accessors.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/ufs/lfs/lfs.h
diff -u src/sys/ufs/lfs/lfs.h:1.206 src/sys/ufs/lfs/lfs.h:1.207
--- src/sys/ufs/lfs/lfs.h:1.206	Sat Mar 21 06:09:33 2020
+++ src/sys/ufs/lfs/lfs.h	Sat Mar 21 06:11:05 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs.h,v 1.206 2020/03/21 06:09:33 riastradh Exp $	*/
+/*	$NetBSD: lfs.h,v 1.207 2020/03/21 06:11:05 riastradh Exp $	*/
 
 /*  from NetBSD: dinode.h,v 1.25 2016/01/22 23:06:10 dholland Exp  */
 /*  from NetBSD: dir.h,v 1.25 2015/09/01 06:16:03 dholland Exp  */
@@ -358,18 +358,19 @@ struct lfs_dirheader32 {
 __CTASSERT(sizeof(struct lfs_dirheader32) == 8);
 
 struct lfs_dirheader64 {
-	uint32_t dh_inoA;		/* inode number of entry */
-	uint32_t dh_inoB;		/* inode number of entry */
+	uint64_t dh_ino;		/* inode number of entry */
 	uint16_t dh_reclen;		/* length of this record */
 	uint8_t  dh_type; 		/* file type, see below */
 	uint8_t  dh_namlen;		/* length of string in d_name */
-};
+} __aligned(4) __packed;
 __CTASSERT(sizeof(struct lfs_dirheader64) == 12);
 
 union lfs_dirheader {
 	struct lfs_dirheader64 u_64;
 	struct lfs_dirheader32 u_32;
 };
+__CTASSERT(__alignof(union lfs_dirheader) == __alignof(struct lfs_dirheader64));
+__CTASSERT(__alignof(union lfs_dirheader) == __alignof(struct lfs_dirheader32));
 
 typedef union lfs_dirheader LFS_DIRHEADER;
 
@@ -481,6 +482,8 @@ union lfs_dinode {
 	struct lfs64_dinode u_64;
 	struct lfs32_dinode u_32;
 };
+__CTASSERT(__alignof(union lfs_dinode) == __alignof(struct lfs64_dinode));
+__CTASSERT(__alignof(union lfs_dinode) == __alignof(struct lfs32_dinode));
 
 /*
  * The di_db fields may be overlaid with other information for
@@ -563,7 +566,7 @@ struct finfo64 {
 	uint64_t fi_ino;		/* inode number */
 	uint32_t fi_lastlength;		/* length of last block in array */
 	uint32_t fi_pad;		/* unused */
-};
+} __aligned(4) __packed;
 __CTASSERT(sizeof(struct finfo64) == 24);
 
 typedef struct finfo32 FINFO32;
@@ -579,6 +582,8 @@ typedef union finfo {
 	struct finfo64 u_64;
 	struct finfo32 u_32;
 } FINFO;
+__CTASSERT(__alignof(union finfo) == __alignof(struct finfo64));
+__CTASSERT(__alignof(union finfo) == __alignof(struct finfo32));
 
 /*
  * inode info (part of the segment summary)
@@ -590,7 +595,7 @@ typedef union finfo {
 
 typedef struct iinfo64 {
 	uint64_t ii_block;		/* block number */
-} IINFO64;
+} __aligned(4) __packed IINFO64;
 __CTASSERT(sizeof(struct iinfo64) == 8);
 
 typedef struct iinfo32 {
@@ -602,6 +607,8 @@ typedef union iinfo {
 	struct iinfo64 u_64;
 	struct iinfo32 u_32;
 } IINFO;
+__CTASSERT(__alignof(union iinfo) == __alignof(struct iinfo64));
+__CTASSERT(__alignof(union iinfo) == __alignof(struct iinfo32));
 
 /*
  * Index file inode entries.
@@ -620,7 +627,7 @@ struct ifile64 {
 	uint64_t if_atime_sec;		/* Last access time, seconds */
 	int64_t	  if_daddr;		/* inode disk address */
 	uint64_t if_nextfree;		/* next-unallocated inode */
-};
+} __aligned(4) __packed;
 __CTASSERT(sizeof(struct ifile64) == 32);
 
 typedef struct ifile32 IFILE32;
@@ -655,6 +662,9 @@ typedef union ifile {
 	struct ifile32 u_32;
 	struct ifile_v1 u_v1;
 } IFILE;
+__CTASSERT(__alignof(union ifile) == __alignof(struct ifile64));
+__CTASSERT(__alignof(union ifile) == __alignof(struct ifile32));
+__CTASSERT(__alignof(union ifile) == __alignof(struct ifile_v1));
 
 /*
  * Cleaner information structure.  This resides in 

CVS commit: src/sys/ufs/lfs

2020-03-21 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Mar 21 06:09:34 UTC 2020

Modified Files:
src/sys/ufs/lfs: lfs.h

Log Message:
CTASSERT lfs on-disk structure sizes.


To generate a diff of this commit:
cvs rdiff -u -r1.205 -r1.206 src/sys/ufs/lfs/lfs.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/ufs/lfs/lfs.h
diff -u src/sys/ufs/lfs/lfs.h:1.205 src/sys/ufs/lfs/lfs.h:1.206
--- src/sys/ufs/lfs/lfs.h:1.205	Sun Feb 23 08:49:34 2020
+++ src/sys/ufs/lfs/lfs.h	Sat Mar 21 06:09:33 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs.h,v 1.205 2020/02/23 08:49:34 riastradh Exp $	*/
+/*	$NetBSD: lfs.h,v 1.206 2020/03/21 06:09:33 riastradh Exp $	*/
 
 /*  from NetBSD: dinode.h,v 1.25 2016/01/22 23:06:10 dholland Exp  */
 /*  from NetBSD: dir.h,v 1.25 2015/09/01 06:16:03 dholland Exp  */
@@ -355,6 +355,7 @@ struct lfs_dirheader32 {
 	uint8_t  dh_type; 		/* file type, see below */
 	uint8_t  dh_namlen;		/* length of string in d_name */
 };
+__CTASSERT(sizeof(struct lfs_dirheader32) == 8);
 
 struct lfs_dirheader64 {
 	uint32_t dh_inoA;		/* inode number of entry */
@@ -363,6 +364,7 @@ struct lfs_dirheader64 {
 	uint8_t  dh_type; 		/* file type, see below */
 	uint8_t  dh_namlen;		/* length of string in d_name */
 };
+__CTASSERT(sizeof(struct lfs_dirheader64) == 12);
 
 union lfs_dirheader {
 	struct lfs_dirheader64 u_64;
@@ -381,6 +383,7 @@ struct lfs_dirtemplate32 {
 	struct lfs_dirheader32	dotdot_header;
 	char			dotdot_name[4];	/* ditto */
 };
+__CTASSERT(sizeof(struct lfs_dirtemplate32) == 2*(8 + 4));
 
 struct lfs_dirtemplate64 {
 	struct lfs_dirheader64	dot_header;
@@ -388,6 +391,7 @@ struct lfs_dirtemplate64 {
 	struct lfs_dirheader64	dotdot_header;
 	char			dotdot_name[4];	/* ditto */
 };
+__CTASSERT(sizeof(struct lfs_dirtemplate64) == 2*(12 + 4));
 
 union lfs_dirtemplate {
 	struct lfs_dirtemplate64 u_64;
@@ -408,6 +412,7 @@ struct lfs_odirtemplate {
 	uint16_t	dotdot_namlen;
 	char		dotdot_name[4];	/* ditto */
 };
+__CTASSERT(sizeof(struct lfs_odirtemplate) == 2*(8 + 4));
 #endif
 
 /*
@@ -441,6 +446,7 @@ struct lfs32_dinode {
 	uint32_t	di_gid;		/* 116: File group. */
 	uint64_t	di_modrev;	/* 120: i_modrev for NFSv4 */
 };
+__CTASSERT(sizeof(struct lfs32_dinode) == 128);
 
 struct lfs64_dinode {
 	uint16_t	di_mode;	/*   0: IFMT, permissions; see below. */
@@ -469,6 +475,7 @@ struct lfs64_dinode {
 	uint64_t	di_inumber;	/* 240: Inode number */
 	uint64_t	di_spare[1];	/* 248: Reserved; currently unused */
 };
+__CTASSERT(sizeof(struct lfs64_dinode) == 256);
 
 union lfs_dinode {
 	struct lfs64_dinode u_64;
@@ -529,6 +536,7 @@ struct segusage {
 	uint32_t su_flags;		/* 12: segment flags */
 	uint64_t su_lastmod;		/* 16: last modified timestamp */
 };
+__CTASSERT(sizeof(struct segusage) == 24);
 
 typedef struct segusage_v1 SEGUSE_V1;
 struct segusage_v1 {
@@ -538,6 +546,7 @@ struct segusage_v1 {
 	uint16_t su_ninos;		/* 10: number of inode blocks in seg */
 	uint32_t su_flags;		/* 12: segment flags  */
 };
+__CTASSERT(sizeof(struct segusage_v1) == 16);
 
 /*
  * On-disk file information.  One per file with data blocks in the segment.
@@ -555,6 +564,7 @@ struct finfo64 {
 	uint32_t fi_lastlength;		/* length of last block in array */
 	uint32_t fi_pad;		/* unused */
 };
+__CTASSERT(sizeof(struct finfo64) == 24);
 
 typedef struct finfo32 FINFO32;
 struct finfo32 {
@@ -563,6 +573,7 @@ struct finfo32 {
 	uint32_t fi_ino;		/* inode number */
 	uint32_t fi_lastlength;		/* length of last block in array */
 };
+__CTASSERT(sizeof(struct finfo32) == 16);
 
 typedef union finfo {
 	struct finfo64 u_64;
@@ -580,10 +591,12 @@ typedef union finfo {
 typedef struct iinfo64 {
 	uint64_t ii_block;		/* block number */
 } IINFO64;
+__CTASSERT(sizeof(struct iinfo64) == 8);
 
 typedef struct iinfo32 {
 	uint32_t ii_block;		/* block number */
 } IINFO32;
+__CTASSERT(sizeof(struct iinfo32) == 4);
 
 typedef union iinfo {
 	struct iinfo64 u_64;
@@ -608,6 +621,7 @@ struct ifile64 {
 	int64_t	  if_daddr;		/* inode disk address */
 	uint64_t if_nextfree;		/* next-unallocated inode */
 };
+__CTASSERT(sizeof(struct ifile64) == 32);
 
 typedef struct ifile32 IFILE32;
 struct ifile32 {
@@ -617,6 +631,7 @@ struct ifile32 {
 	uint32_t if_atime_sec;		/* Last access time, seconds */
 	uint32_t if_atime_nsec;		/* and nanoseconds */
 };
+__CTASSERT(sizeof(struct ifile32) == 20);
 
 typedef struct ifile_v1 IFILE_V1;
 struct ifile_v1 {
@@ -628,6 +643,7 @@ struct ifile_v1 {
 	struct timespec if_atime;	/* Last access time */
 #endif
 };
+__CTASSERT(sizeof(struct ifile_v1) == 12);
 
 /*
  * Note: struct ifile_v1 is often handled by accessing the first three
@@ -657,6 +673,7 @@ typedef struct _cleanerinfo32 {
 	uint32_t free_tail;		/* 20: tail of the inode free list */
 	uint32_t flags;			/* 24: status word from the kernel */
 } CLEANERINFO32;
+__CTASSERT(sizeof(struct _cleanerinfo32) == 28);
 
 typedef struct _cleanerinfo64 {
 	uint32_t 

CVS commit: src/sys/ufs/lfs

2020-03-14 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Mar 14 15:35:35 UTC 2020

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

Log Message:
OR into bp->b_cflags; don't overwrite.


To generate a diff of this commit:
cvs rdiff -u -r1.146 -r1.147 src/sys/ufs/lfs/lfs_bio.c
cvs rdiff -u -r1.374 -r1.375 src/sys/ufs/lfs/lfs_vfsops.c

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

Modified files:

Index: src/sys/ufs/lfs/lfs_bio.c
diff -u src/sys/ufs/lfs/lfs_bio.c:1.146 src/sys/ufs/lfs/lfs_bio.c:1.147
--- src/sys/ufs/lfs/lfs_bio.c:1.146	Sun Feb 23 08:39:28 2020
+++ src/sys/ufs/lfs/lfs_bio.c	Sat Mar 14 15:35:35 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_bio.c,v 1.146 2020/02/23 08:39:28 riastradh Exp $	*/
+/*	$NetBSD: lfs_bio.c,v 1.147 2020/03/14 15:35:35 ad Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2008 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_bio.c,v 1.146 2020/02/23 08:39:28 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_bio.c,v 1.147 2020/03/14 15:35:35 ad Exp $");
 
 #include 
 #include 
@@ -735,7 +735,7 @@ lfs_newbuf(struct lfs *fs, struct vnode 
 	bp->b_error = 0;
 	bp->b_resid = 0;
 	bp->b_iodone = lfs_free_aiodone;
-	bp->b_cflags = BC_BUSY | BC_NOCACHE;
+	bp->b_cflags |= BC_BUSY | BC_NOCACHE;
 	bp->b_private = fs;
 
 	mutex_enter(_lock);

Index: src/sys/ufs/lfs/lfs_vfsops.c
diff -u src/sys/ufs/lfs/lfs_vfsops.c:1.374 src/sys/ufs/lfs/lfs_vfsops.c:1.375
--- src/sys/ufs/lfs/lfs_vfsops.c:1.374	Sun Feb 23 15:46:42 2020
+++ src/sys/ufs/lfs/lfs_vfsops.c	Sat Mar 14 15:35:35 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_vfsops.c,v 1.374 2020/02/23 15:46:42 ad Exp $	*/
+/*	$NetBSD: lfs_vfsops.c,v 1.375 2020/03/14 15:35:35 ad Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007, 2007
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_vfsops.c,v 1.374 2020/02/23 15:46:42 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_vfsops.c,v 1.375 2020/03/14 15:35:35 ad Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_lfs.h"
@@ -2127,7 +2127,7 @@ lfs_gop_write(struct vnode *vp, struct v
 	mbp->b_bufsize = npages << PAGE_SHIFT;
 	mbp->b_data = (void *)kva;
 	mbp->b_resid = mbp->b_bcount = bytes;
-	mbp->b_cflags = BC_BUSY|BC_AGE;
+	mbp->b_cflags |= BC_BUSY|BC_AGE;
 	mbp->b_iodone = uvm_aio_aiodone;
 
 	bp = NULL;



CVS commit: src/sys/ufs/ext2fs

2020-03-08 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sun Mar  8 17:38:12 UTC 2020

Modified Files:
src/sys/ufs/ext2fs: ext2fs_vnops.c

Log Message:
Perform bit operations on unsigned integer

ext2fs_vnops.c:1002:2, signed integer overflow: 510008 * 4294 cannot be 
represented in type 'int

Maximum usec * 4294 is in the range of unsigned int.

>>> 100*4294
429400
>>> 2**32
4294967296

Patch submitted by Nisarg S. Joshi.


To generate a diff of this commit:
cvs rdiff -u -r1.130 -r1.131 src/sys/ufs/ext2fs/ext2fs_vnops.c

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

Modified files:

Index: src/sys/ufs/ext2fs/ext2fs_vnops.c
diff -u src/sys/ufs/ext2fs/ext2fs_vnops.c:1.130 src/sys/ufs/ext2fs/ext2fs_vnops.c:1.131
--- src/sys/ufs/ext2fs/ext2fs_vnops.c:1.130	Wed Sep 18 17:59:15 2019
+++ src/sys/ufs/ext2fs/ext2fs_vnops.c	Sun Mar  8 17:38:12 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ext2fs_vnops.c,v 1.130 2019/09/18 17:59:15 christos Exp $	*/
+/*	$NetBSD: ext2fs_vnops.c,v 1.131 2020/03/08 17:38:12 kamil Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -65,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ext2fs_vnops.c,v 1.130 2019/09/18 17:59:15 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ext2fs_vnops.c,v 1.131 2020/03/08 17:38:12 kamil Exp $");
 
 #include 
 #include 
@@ -999,7 +999,7 @@ ext2fs_vinit(struct mount *mntp, int (**
 	 */
 	getmicrouptime();
 	SETHIGH(ip->i_modrev, tv.tv_sec);
-	SETLOW(ip->i_modrev, tv.tv_usec * 4294);
+	SETLOW(ip->i_modrev, tv.tv_usec * 4294U);
 	*vpp = vp;
 	return 0;
 }



CVS commit: src/sys/ufs/ufs

2020-03-07 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Sun Mar  8 00:23:59 UTC 2020

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

Log Message:
in ufsdirhash_free(), only examine dh->dh_onlist after taking the
dirhashlist lock.  if we skip the lock then we might see that
dh_onlist is zero while ufsdirhash_recycle() is still working on
the dirhash.  the symptom I saw was that ufsdirhash_free() would
try to destroy the dh_lock mutex while it was still held.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/sys/ufs/ufs/ufs_dirhash.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_dirhash.c
diff -u src/sys/ufs/ufs/ufs_dirhash.c:1.37 src/sys/ufs/ufs/ufs_dirhash.c:1.38
--- src/sys/ufs/ufs/ufs_dirhash.c:1.37	Sat Dec 20 00:28:05 2014
+++ src/sys/ufs/ufs/ufs_dirhash.c	Sun Mar  8 00:23:59 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_dirhash.c,v 1.37 2014/12/20 00:28:05 christos Exp $	*/
+/*	$NetBSD: ufs_dirhash.c,v 1.38 2020/03/08 00:23:59 chs Exp $	*/
 
 /*
  * Copyright (c) 2001, 2002 Ian Dowse.  All rights reserved.
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ufs_dirhash.c,v 1.37 2014/12/20 00:28:05 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_dirhash.c,v 1.38 2020/03/08 00:23:59 chs Exp $");
 
 /*
  * This implements a hash-based lookup scheme for UFS directories.
@@ -285,12 +285,10 @@ ufsdirhash_free(struct inode *ip)
 
 	ip->i_dirhash = NULL;
 
-	if (dh->dh_onlist) {
-		DIRHASHLIST_LOCK();
-		if (dh->dh_onlist)
-			TAILQ_REMOVE(_list, dh, dh_list);
-		DIRHASHLIST_UNLOCK();
-	}
+	DIRHASHLIST_LOCK();
+	if (dh->dh_onlist)
+		TAILQ_REMOVE(_list, dh, dh_list);
+	DIRHASHLIST_UNLOCK();
 
 	/* The dirhash pointed to by 'dh' is exclusively ours now. */
 	mem = sizeof(*dh);



CVS commit: src/sys/ufs/ufs

2020-02-26 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Wed Feb 26 18:00:12 UTC 2020

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

Log Message:
Zero out the padding in 'd_namlen', to prevent info leaks. Same logic as
ufs_makedirentry().

Found by kMSan: the unzeroed bytes of the pool_cache were getting copied
to the disk via a DMA write operation, and there kMSan was noticing
uninitialized memory leaving the system.

Reported-by: syzbot+382c9dffc06a9683a...@syzkaller.appspotmail.com


To generate a diff of this commit:
cvs rdiff -u -r1.248 -r1.249 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/ufs/ufs_vnops.c
diff -u src/sys/ufs/ufs/ufs_vnops.c:1.248 src/sys/ufs/ufs/ufs_vnops.c:1.249
--- src/sys/ufs/ufs/ufs_vnops.c:1.248	Wed Sep 18 17:59:15 2019
+++ src/sys/ufs/ufs/ufs_vnops.c	Wed Feb 26 18:00:12 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_vnops.c,v 1.248 2019/09/18 17:59:15 christos Exp $	*/
+/*	$NetBSD: ufs_vnops.c,v 1.249 2020/02/26 18:00:12 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ufs_vnops.c,v 1.248 2019/09/18 17:59:15 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_vnops.c,v 1.249 2020/02/26 18:00:12 maxv Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -873,7 +873,11 @@ ufs_whiteout(void *v)
 		newdir->d_namlen = cnp->cn_namelen;
 		memcpy(newdir->d_name, cnp->cn_nameptr,
 		(size_t)cnp->cn_namelen);
-		newdir->d_name[cnp->cn_namelen] = '\0';
+
+		/* NUL terminate and zero out padding */
+		memset(>d_name[cnp->cn_namelen], 0,
+		UFS_NAMEPAD(cnp->cn_namelen));
+
 		newdir->d_type = DT_WHT;
 		error = ufs_direnter(dvp, ulr, NULL, newdir, cnp, NULL);
 		pool_cache_put(ufs_direct_cache, newdir);



CVS commit: src/sys/ufs/lfs

2020-02-23 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Feb 23 15:23:08 UTC 2020

Modified Files:
src/sys/ufs/lfs: lfs_subr.c lfs_vnops.c

Log Message:
Fix missing  by removing the evcnts instead.

Just wanted to confirm that a race might happen, and indeed it did.
These serve little diagnostic value otherwise.


To generate a diff of this commit:
cvs rdiff -u -r1.101 -r1.102 src/sys/ufs/lfs/lfs_subr.c
cvs rdiff -u -r1.329 -r1.330 src/sys/ufs/lfs/lfs_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/lfs/lfs_subr.c
diff -u src/sys/ufs/lfs/lfs_subr.c:1.101 src/sys/ufs/lfs/lfs_subr.c:1.102
--- src/sys/ufs/lfs/lfs_subr.c:1.101	Sun Feb 23 15:09:55 2020
+++ src/sys/ufs/lfs/lfs_subr.c	Sun Feb 23 15:23:08 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_subr.c,v 1.101 2020/02/23 15:09:55 ad Exp $	*/
+/*	$NetBSD: lfs_subr.c,v 1.102 2020/02/23 15:23:08 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_subr.c,v 1.101 2020/02/23 15:09:55 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_subr.c,v 1.102 2020/02/23 15:23:08 riastradh Exp $");
 
 #include 
 #include 
@@ -337,10 +337,6 @@ lfs_seglock(struct lfs *fs, unsigned lon
 
 static void lfs_unmark_dirop(struct lfs *);
 
-static struct evcnt lfs_dchain_marker_pass_dirop =
-EVCNT_INITIALIZER(EVCNT_TYPE_MISC, NULL, "lfs", "dchain marker pass dirop");
-EVCNT_ATTACH_STATIC(lfs_dchain_marker_pass_dirop);
-
 static void
 lfs_unmark_dirop(struct lfs *fs)
 {
@@ -371,10 +367,8 @@ lfs_unmark_dirop(struct lfs *fs)
 		TAILQ_REMOVE(>lfs_dchainhd, marker, i_lfs_dchain);
 		TAILQ_INSERT_AFTER(>lfs_dchainhd, ip, marker,
 		i_lfs_dchain);
-		if (ip->i_state & IN_MARKER) {
-			lfs_dchain_marker_pass_dirop.ev_count++;
+		if (ip->i_state & IN_MARKER)
 			continue;
-		}
 		vp = ITOV(ip);
 		if ((ip->i_state & (IN_ADIROP | IN_CDIROP)) == IN_CDIROP) {
 			--lfs_dirvcount;

Index: src/sys/ufs/lfs/lfs_vnops.c
diff -u src/sys/ufs/lfs/lfs_vnops.c:1.329 src/sys/ufs/lfs/lfs_vnops.c:1.330
--- src/sys/ufs/lfs/lfs_vnops.c:1.329	Sun Feb 23 08:40:19 2020
+++ src/sys/ufs/lfs/lfs_vnops.c	Sun Feb 23 15:23:08 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_vnops.c,v 1.329 2020/02/23 08:40:19 riastradh Exp $	*/
+/*	$NetBSD: lfs_vnops.c,v 1.330 2020/02/23 15:23:08 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -125,7 +125,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.329 2020/02/23 08:40:19 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.330 2020/02/23 15:23:08 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -1595,10 +1595,6 @@ lfs_strategy(void *v)
 	return VOP_STRATEGY(vp, bp);
 }
 
-static struct evcnt lfs_dchain_marker_pass_flush =
-EVCNT_INITIALIZER(EVCNT_TYPE_MISC, NULL, "lfs", "dchain marker pass flush");
-EVCNT_ATTACH_STATIC(lfs_dchain_marker_pass_flush);
-
 /*
  * Inline lfs_segwrite/lfs_writevnodes, but just for dirops.
  * Technically this is a checkpoint (the on-disk state is valid)
@@ -1662,10 +1658,8 @@ lfs_flush_dirops(struct lfs *fs)
 		TAILQ_REMOVE(>lfs_dchainhd, marker, i_lfs_dchain);
 		TAILQ_INSERT_AFTER(>lfs_dchainhd, ip, marker,
 		i_lfs_dchain);
-		if (ip->i_state & IN_MARKER) {
-			lfs_dchain_marker_pass_flush.ev_count++;
+		if (ip->i_state & IN_MARKER)
 			continue;
-		}
 		vp = ITOV(ip);
 
 		/*



CVS commit: src/sys/ufs/lfs

2020-02-23 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sun Feb 23 15:09:55 UTC 2020

Modified Files:
src/sys/ufs/lfs: lfs_subr.c

Log Message:
Fix !DIAGNOSTIC compile


To generate a diff of this commit:
cvs rdiff -u -r1.100 -r1.101 src/sys/ufs/lfs/lfs_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/ufs/lfs/lfs_subr.c
diff -u src/sys/ufs/lfs/lfs_subr.c:1.100 src/sys/ufs/lfs/lfs_subr.c:1.101
--- src/sys/ufs/lfs/lfs_subr.c:1.100	Sun Feb 23 08:42:53 2020
+++ src/sys/ufs/lfs/lfs_subr.c	Sun Feb 23 15:09:55 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_subr.c,v 1.100 2020/02/23 08:42:53 riastradh Exp $	*/
+/*	$NetBSD: lfs_subr.c,v 1.101 2020/02/23 15:09:55 ad Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_subr.c,v 1.100 2020/02/23 08:42:53 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_subr.c,v 1.101 2020/02/23 15:09:55 ad Exp $");
 
 #include 
 #include 
@@ -574,7 +574,7 @@ lfs_segunlock(struct lfs *fs)
 void
 lfs_writer_enter(struct lfs *fs, const char *wmesg)
 {
-	int error;
+	int error __diagused;
 
 	ASSERT_NO_SEGLOCK(fs);
 	mutex_enter(_lock);



CVS commit: src/sys/ufs/lfs

2020-02-23 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Feb 23 08:49:46 UTC 2020

Modified Files:
src/sys/ufs/lfs: lfs_alloc.c lfs_extern.h lfs_vfsops.c

Log Message:
Dust off the orphan detection code and try to make it work.


To generate a diff of this commit:
cvs rdiff -u -r1.140 -r1.141 src/sys/ufs/lfs/lfs_alloc.c
cvs rdiff -u -r1.117 -r1.118 src/sys/ufs/lfs/lfs_extern.h
cvs rdiff -u -r1.372 -r1.373 src/sys/ufs/lfs/lfs_vfsops.c

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

Modified files:

Index: src/sys/ufs/lfs/lfs_alloc.c
diff -u src/sys/ufs/lfs/lfs_alloc.c:1.140 src/sys/ufs/lfs/lfs_alloc.c:1.141
--- src/sys/ufs/lfs/lfs_alloc.c:1.140	Sun Feb 23 08:49:34 2020
+++ src/sys/ufs/lfs/lfs_alloc.c	Sun Feb 23 08:49:46 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_alloc.c,v 1.140 2020/02/23 08:49:34 riastradh Exp $	*/
+/*	$NetBSD: lfs_alloc.c,v 1.141 2020/02/23 08:49:46 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_alloc.c,v 1.140 2020/02/23 08:49:34 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_alloc.c,v 1.141 2020/02/23 08:49:46 riastradh Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_quota.h"
@@ -705,16 +705,16 @@ lfs_vfree(struct vnode *vp, ino_t ino, i
  * Takes the segmenet lock.
  */
 void
-lfs_order_freelist(struct lfs *fs)
+lfs_order_freelist(struct lfs *fs, ino_t **orphanp, size_t *norphanp)
 {
 	CLEANERINFO *cip;
 	IFILE *ifp = NULL;
 	struct buf *bp;
 	ino_t ino, firstino, lastino, maxino;
-#ifdef notyet
-	struct vnode *vp;
-#endif
-	
+	ino_t *orphan = NULL;
+	size_t norphan = 0;
+	size_t norphan_alloc = 0;
+
 	ASSERT_NO_SEGLOCK(fs);
 	lfs_seglock(fs, SEGM_PROT);
 
@@ -745,7 +745,6 @@ lfs_order_freelist(struct lfs *fs)
 		if (ino == LFS_UNUSED_INUM || ino == LFS_IFILE_INUM)
 			continue;
 
-#ifdef notyet
 		/*
 		 * Address orphaned files.
 		 *
@@ -757,40 +756,26 @@ lfs_order_freelist(struct lfs *fs)
 		 * but presumably it doesn't work... not sure what
 		 * happens to such files currently. -- dholland 20160806
 		 */
-		if (lfs_if_getnextfree(fs, ifp) == LFS_ORPHAN_NEXTFREE(fs) &&
-		VFS_VGET(fs->lfs_ivnode->v_mount, ino, LK_EXCLUSIVE, )
-		 == 0) {
-			unsigned segno;
-
-			/* get the segment the inode in on disk  */
-			segno = lfs_dtosn(fs, lfs_if_getdaddr(fs, ifp));
-
-			/* truncate the inode */
-			lfs_truncate(vp, 0, 0, NOCRED);
-			vput(vp);
-
-			/* load the segment summary */
-			LFS_SEGENTRY(sup, fs, segno, bp);
-			/* update the number of bytes in the segment */
-			KASSERT(sup->su_nbytes >= DINOSIZE(fs));
-			sup->su_nbytes -= DINOSIZE(fs);
-			/* write the segment summary */
-			LFS_WRITESEGENTRY(sup, fs, segno, bp);
-
-			/* Drop the on-disk address */
-			lfs_if_setdaddr(fs, ifp, LFS_UNUSED_DADDR);
-			/* write the ifile entry */
-			LFS_BWRITE_LOG(bp);
-
-			/*
-			 * and reload it (XXX: why? I guess
-			 * LFS_BWRITE_LOG drops it...)
-			 */
-			LFS_IENTRY(ifp, fs, ino, bp);
-
-			/* Fall through to next if block */
+		if (lfs_if_getnextfree(fs, ifp) == LFS_ORPHAN_NEXTFREE(fs)) {
+			if (orphan == NULL) {
+norphan_alloc = 32; /* XXX pulled from arse */
+orphan = kmem_zalloc(sizeof(orphan[0]) *
+norphan_alloc, KM_SLEEP);
+			} else if (norphan == norphan_alloc) {
+ino_t *orphan_new;
+if (norphan_alloc >= 4096)
+	norphan_alloc += 4096;
+else
+	norphan_alloc *= 2;
+orphan_new = kmem_zalloc(sizeof(orphan[0]) *
+norphan_alloc, KM_SLEEP);
+memcpy(orphan_new, orphan, sizeof(orphan[0]) *
+norphan);
+kmem_free(orphan, sizeof(orphan[0]) * norphan);
+orphan = orphan_new;
+			}
+			orphan[norphan++] = ino;
 		}
-#endif
 
 		if (lfs_if_getdaddr(fs, ifp) == LFS_UNUSED_DADDR) {
 
@@ -837,6 +822,22 @@ lfs_order_freelist(struct lfs *fs)
 
 	/* done */
 	lfs_segunlock(fs);
+
+	/*
+	 * Shrink the array of orphans so we don't have to carry around
+	 * the allocation size.
+	 */
+	if (norphan < norphan_alloc) {
+		ino_t *orphan_new = kmem_alloc(sizeof(orphan[0]) * norphan,
+		KM_SLEEP);
+		memcpy(orphan_new, orphan, sizeof(orphan[0]) * norphan);
+		kmem_free(orphan, sizeof(orphan[0]) * norphan_alloc);
+		orphan = orphan_new;
+		norphan_alloc = norphan;
+	}
+
+	*orphanp = orphan;
+	*norphanp = norphan;
 }
 
 /*
@@ -855,3 +856,82 @@ lfs_orphan(struct lfs *fs, ino_t ino)
 	lfs_if_setnextfree(fs, ifp, LFS_ORPHAN_NEXTFREE(fs));
 	LFS_BWRITE_LOG(bp);
 }
+
+/*
+ * Free orphans discovered during mount.  This is a separate stage
+ * because it requires fs->lfs_suflags to be set up, which is not done
+ * by the time we run lfs_order_freelist.  It's possible that we could
+ * run lfs_order_freelist later (i.e., set up fs->lfs_suflags sooner)
+ * but that requires more thought than I can put into this at the
+ * moment.
+ */
+void
+lfs_free_orphans(struct lfs *fs, ino_t *orphan, size_t norphan)
+{
+	size_t i;
+
+	

CVS commit: src/sys/ufs/lfs

2020-02-23 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Feb 23 08:49:34 UTC 2020

Modified Files:
src/sys/ufs/lfs: lfs.h lfs_alloc.c

Log Message:
Teach LFS_ORPHAN_NEXTFREE about lfs64.


To generate a diff of this commit:
cvs rdiff -u -r1.204 -r1.205 src/sys/ufs/lfs/lfs.h
cvs rdiff -u -r1.139 -r1.140 src/sys/ufs/lfs/lfs_alloc.c

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

Modified files:

Index: src/sys/ufs/lfs/lfs.h
diff -u src/sys/ufs/lfs/lfs.h:1.204 src/sys/ufs/lfs/lfs.h:1.205
--- src/sys/ufs/lfs/lfs.h:1.204	Thu Jan 10 06:31:04 2019
+++ src/sys/ufs/lfs/lfs.h	Sun Feb 23 08:49:34 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs.h,v 1.204 2019/01/10 06:31:04 martin Exp $	*/
+/*	$NetBSD: lfs.h,v 1.205 2020/02/23 08:49:34 riastradh Exp $	*/
 
 /*  from NetBSD: dinode.h,v 1.25 2016/01/22 23:06:10 dholland Exp  */
 /*  from NetBSD: dir.h,v 1.25 2015/09/01 06:16:03 dholland Exp  */
@@ -596,8 +596,9 @@ typedef union iinfo {
 
 /* magic value for daddrs */
 #define	LFS_UNUSED_DADDR	0	/* out-of-band daddr */
-/* magic value for if_nextfree */
-#define LFS_ORPHAN_NEXTFREE	(~(uint32_t)0) /* indicate orphaned file */
+/* magic value for if_nextfree -- indicate orphaned file */
+#define LFS_ORPHAN_NEXTFREE(fs) \
+	((fs)->lfs_is64 ? ~(uint64_t)0 : ~(uint32_t)0)
 
 typedef struct ifile64 IFILE64;
 struct ifile64 {

Index: src/sys/ufs/lfs/lfs_alloc.c
diff -u src/sys/ufs/lfs/lfs_alloc.c:1.139 src/sys/ufs/lfs/lfs_alloc.c:1.140
--- src/sys/ufs/lfs/lfs_alloc.c:1.139	Sat Feb 22 00:32:08 2020
+++ src/sys/ufs/lfs/lfs_alloc.c	Sun Feb 23 08:49:34 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_alloc.c,v 1.139 2020/02/22 00:32:08 kamil Exp $	*/
+/*	$NetBSD: lfs_alloc.c,v 1.140 2020/02/23 08:49:34 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_alloc.c,v 1.139 2020/02/22 00:32:08 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_alloc.c,v 1.140 2020/02/23 08:49:34 riastradh Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_quota.h"
@@ -757,7 +757,7 @@ lfs_order_freelist(struct lfs *fs)
 		 * but presumably it doesn't work... not sure what
 		 * happens to such files currently. -- dholland 20160806
 		 */
-		if (lfs_if_getnextfree(fs, ifp) == LFS_ORPHAN_NEXTFREE &&
+		if (lfs_if_getnextfree(fs, ifp) == LFS_ORPHAN_NEXTFREE(fs) &&
 		VFS_VGET(fs->lfs_ivnode->v_mount, ino, LK_EXCLUSIVE, )
 		 == 0) {
 			unsigned segno;
@@ -852,6 +852,6 @@ lfs_orphan(struct lfs *fs, ino_t ino)
 	struct buf *bp;
 
 	LFS_IENTRY(ifp, fs, ino, bp);
-	lfs_if_setnextfree(fs, ifp, LFS_ORPHAN_NEXTFREE);
+	lfs_if_setnextfree(fs, ifp, LFS_ORPHAN_NEXTFREE(fs));
 	LFS_BWRITE_LOG(bp);
 }



CVS commit: src/sys/ufs/lfs

2020-02-23 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Feb 23 08:42:53 UTC 2020

Modified Files:
src/sys/ufs/lfs: lfs_extern.h lfs_subr.c

Log Message:
lfs_writer_enter can't fail; keep it simple and don't pretend it can.

Assert that mtsleep can't fail either -- it doesn't catch signals and
there's no timeout.


To generate a diff of this commit:
cvs rdiff -u -r1.116 -r1.117 src/sys/ufs/lfs/lfs_extern.h
cvs rdiff -u -r1.99 -r1.100 src/sys/ufs/lfs/lfs_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/ufs/lfs/lfs_extern.h
diff -u src/sys/ufs/lfs/lfs_extern.h:1.116 src/sys/ufs/lfs/lfs_extern.h:1.117
--- src/sys/ufs/lfs/lfs_extern.h:1.116	Sun Feb 23 08:40:37 2020
+++ src/sys/ufs/lfs/lfs_extern.h	Sun Feb 23 08:42:53 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_extern.h,v 1.116 2020/02/23 08:40:37 riastradh Exp $	*/
+/*	$NetBSD: lfs_extern.h,v 1.117 2020/02/23 08:42:53 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -210,7 +210,7 @@ void lfs_free(struct lfs *, void *, int)
 int lfs_seglock(struct lfs *, unsigned long);
 void lfs_segunlock(struct lfs *);
 void lfs_segunlock_relock(struct lfs *);
-int lfs_writer_enter(struct lfs *, const char *);
+void lfs_writer_enter(struct lfs *, const char *);
 int lfs_writer_tryenter(struct lfs *);
 void lfs_writer_leave(struct lfs *);
 void lfs_wakeup_cleaner(struct lfs *);

Index: src/sys/ufs/lfs/lfs_subr.c
diff -u src/sys/ufs/lfs/lfs_subr.c:1.99 src/sys/ufs/lfs/lfs_subr.c:1.100
--- src/sys/ufs/lfs/lfs_subr.c:1.99	Sun Feb 23 08:40:37 2020
+++ src/sys/ufs/lfs/lfs_subr.c	Sun Feb 23 08:42:53 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_subr.c,v 1.99 2020/02/23 08:40:37 riastradh Exp $	*/
+/*	$NetBSD: lfs_subr.c,v 1.100 2020/02/23 08:42:53 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_subr.c,v 1.99 2020/02/23 08:40:37 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_subr.c,v 1.100 2020/02/23 08:42:53 riastradh Exp $");
 
 #include 
 #include 
@@ -561,6 +561,7 @@ lfs_segunlock(struct lfs *fs)
 			lfs_unmark_dirop(fs);
 	} else {
 		--fs->lfs_seglock;
+		KASSERT(fs->lfs_seglock != 0);
 		mutex_exit(_lock);
 	}
 }
@@ -570,10 +571,10 @@ lfs_segunlock(struct lfs *fs)
  *
  * No simple_locks are held when we enter and none are held when we return.
  */
-int
+void
 lfs_writer_enter(struct lfs *fs, const char *wmesg)
 {
-	int error = 0;
+	int error;
 
 	ASSERT_NO_SEGLOCK(fs);
 	mutex_enter(_lock);
@@ -585,15 +586,11 @@ lfs_writer_enter(struct lfs *fs, const c
 		++fs->lfs_diropwait;
 		error = mtsleep(>lfs_writer, PRIBIO+1, wmesg, 0,
 _lock);
+		KASSERT(error == 0);
 		--fs->lfs_diropwait;
 	}
 
-	if (error)
-		fs->lfs_writer--;
-
 	mutex_exit(_lock);
-
-	return error;
 }
 
 int



CVS commit: src/sys/ufs/lfs

2020-02-23 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Feb 23 08:41:08 UTC 2020

Modified Files:
src/sys/ufs/lfs: lfs_rename.c

Log Message:
Call lfs_orphan in lfs_rename while we're still in the dirop.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/ufs/lfs/lfs_rename.c

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

Modified files:

Index: src/sys/ufs/lfs/lfs_rename.c
diff -u src/sys/ufs/lfs/lfs_rename.c:1.22 src/sys/ufs/lfs/lfs_rename.c:1.23
--- src/sys/ufs/lfs/lfs_rename.c:1.22	Sat Jun 10 05:29:36 2017
+++ src/sys/ufs/lfs/lfs_rename.c	Sun Feb 23 08:41:07 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_rename.c,v 1.22 2017/06/10 05:29:36 maya Exp $	*/
+/*	$NetBSD: lfs_rename.c,v 1.23 2020/02/23 08:41:07 riastradh Exp $	*/
 /*  from NetBSD: ufs_rename.c,v 1.12 2015/03/27 17:27:56 riastradh Exp  */
 
 /*-
@@ -89,7 +89,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_rename.c,v 1.22 2017/06/10 05:29:36 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_rename.c,v 1.23 2020/02/23 08:41:07 riastradh Exp $");
 
 #include 
 #include 
@@ -1061,6 +1061,9 @@ lfs_gro_rename(struct mount *mp, kauth_c
 	fdvp, fcnp, fde, fvp,
 	tdvp, tcnp, tde, tvp);
 
+	if (tvp && VTOI(tvp)->i_nlink == 0)
+		lfs_orphan(VTOI(tvp)->i_lfs, VTOI(tvp)->i_number);
+
 	UNMARK_VNODE(fdvp);
 	UNMARK_VNODE(fvp);
 	UNMARK_VNODE(tdvp);



CVS commit: src/sys/ufs/lfs

2020-02-23 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Feb 23 08:40:59 UTC 2020

Modified Files:
src/sys/ufs/lfs: lfs_inode.c

Log Message:
In lfs_update, hold lfs_writer around lfs_vflush.

Otherwise, we might do

lfs_vflush
-> lfs_seglock
-> lfs_segwait(SEGM_CKP)
   -> lfs_writer_enter

which is the reverse of the lfs_writer -> lfs_seglock ordering.


To generate a diff of this commit:
cvs rdiff -u -r1.157 -r1.158 src/sys/ufs/lfs/lfs_inode.c

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

Modified files:

Index: src/sys/ufs/lfs/lfs_inode.c
diff -u src/sys/ufs/lfs/lfs_inode.c:1.157 src/sys/ufs/lfs/lfs_inode.c:1.158
--- src/sys/ufs/lfs/lfs_inode.c:1.157	Sat Jun 10 05:29:36 2017
+++ src/sys/ufs/lfs/lfs_inode.c	Sun Feb 23 08:40:58 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_inode.c,v 1.157 2017/06/10 05:29:36 maya Exp $	*/
+/*	$NetBSD: lfs_inode.c,v 1.158 2020/02/23 08:40:58 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_inode.c,v 1.157 2017/06/10 05:29:36 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_inode.c,v 1.158 2020/02/23 08:40:58 riastradh Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_quota.h"
@@ -133,6 +133,7 @@ lfs_update(struct vnode *vp, const struc
 	struct inode *ip;
 	struct lfs *fs = VFSTOULFS(vp->v_mount)->um_lfs;
 	int flags;
+	int error;
 
 	ASSERT_NO_SEGLOCK(fs);
 	if (vp->v_mount->mnt_flag & MNT_RDONLY)
@@ -175,7 +176,7 @@ lfs_update(struct vnode *vp, const struc
 			  vp->v_iflag | vp->v_vflag | vp->v_uflag,
 			  ip->i_state));
 			if (fs->lfs_dirops == 0)
-lfs_flush_fs(fs, SEGM_SYNC);
+break;
 			else
 mtsleep(>lfs_writer, PRIBIO+1, "lfs_fsync",
 	0, _lock);
@@ -183,8 +184,18 @@ lfs_update(struct vnode *vp, const struc
 			twice? */
 		}
 		--fs->lfs_diropwait;
+		fs->lfs_writer++;
+		if (vp->v_uflag & VU_DIROP) {
+			KASSERT(fs->lfs_dirops == 0);
+			lfs_flush_fs(fs, SEGM_SYNC);
+		}
+		mutex_exit(_lock);
+		error = lfs_vflush(vp);
+		mutex_enter(_lock);
+		if (--fs->lfs_writer == 0)
+			cv_broadcast(>lfs_diropscv);
 		mutex_exit(_lock);
-		return lfs_vflush(vp);
+		return error;
 	}
 	return 0;
 }



CVS commit: src/sys/ufs/lfs

2020-02-23 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Feb 23 08:40:49 UTC 2020

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

Log Message:
Initialize/destroy lfs_allclean_wakeup in modcmd, not lfs_mountfs.

Fixes reloading lfs.kmod.


To generate a diff of this commit:
cvs rdiff -u -r1.371 -r1.372 src/sys/ufs/lfs/lfs_vfsops.c

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

Modified files:

Index: src/sys/ufs/lfs/lfs_vfsops.c
diff -u src/sys/ufs/lfs/lfs_vfsops.c:1.371 src/sys/ufs/lfs/lfs_vfsops.c:1.372
--- src/sys/ufs/lfs/lfs_vfsops.c:1.371	Sun Feb 23 08:39:18 2020
+++ src/sys/ufs/lfs/lfs_vfsops.c	Sun Feb 23 08:40:49 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_vfsops.c,v 1.371 2020/02/23 08:39:18 riastradh Exp $	*/
+/*	$NetBSD: lfs_vfsops.c,v 1.372 2020/02/23 08:40:49 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007, 2007
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_vfsops.c,v 1.371 2020/02/23 08:39:18 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_vfsops.c,v 1.372 2020/02/23 08:40:49 riastradh Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_lfs.h"
@@ -356,6 +356,7 @@ lfs_modcmd(modcmd_t cmd, void *arg)
 			break;
 		}
 		lfs_sysctl_setup(_sysctl_log);
+		cv_init(_allclean_wakeup, "segment");
 		break;
 	case MODULE_CMD_FINI:
 		error = vfs_detach(_vfsops);
@@ -363,6 +364,7 @@ lfs_modcmd(modcmd_t cmd, void *arg)
 			break;
 		syscall_disestablish(NULL, lfs_syscalls);
 		sysctl_teardown(_sysctl_log);
+		cv_destroy(_allclean_wakeup);
 		break;
 	default:
 		error = ENOTTY;
@@ -857,7 +859,6 @@ lfs_checkmagic(struct lfs *fs)
 int
 lfs_mountfs(struct vnode *devvp, struct mount *mp, struct lwp *l)
 {
-	static bool lfs_mounted_once = false;
 	struct lfs *primarysb, *altsb, *thesb;
 	struct buf *primarybuf, *altbuf;
 	struct lfs *fs;
@@ -1091,12 +1092,6 @@ lfs_mountfs(struct vnode *devvp, struct 
 	cv_init(>lfs_stopcv, "lfsstop");
 	cv_init(>lfs_nextsegsleep, "segment");
 
-	/* Initialize values for all LFS mounts */
-	if (!lfs_mounted_once) {
-		cv_init(_allclean_wakeup, "segment");
-		lfs_mounted_once = true;
-	}
-
 	/* Set the file system readonly/modify bits. */
 	fs->lfs_ronly = ronly;
 	if (ronly == 0)



CVS commit: src/sys/ufs/lfs

2020-02-23 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Feb 23 08:40:08 UTC 2020

Modified Files:
src/sys/ufs/lfs: lfs_segment.c lfs_vnops.c

Log Message:
Change some cheap KDASSERT into KASSERT.


To generate a diff of this commit:
cvs rdiff -u -r1.283 -r1.284 src/sys/ufs/lfs/lfs_segment.c
cvs rdiff -u -r1.327 -r1.328 src/sys/ufs/lfs/lfs_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/lfs/lfs_segment.c
diff -u src/sys/ufs/lfs/lfs_segment.c:1.283 src/sys/ufs/lfs/lfs_segment.c:1.284
--- src/sys/ufs/lfs/lfs_segment.c:1.283	Sat Feb 22 22:20:47 2020
+++ src/sys/ufs/lfs/lfs_segment.c	Sun Feb 23 08:40:08 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_segment.c,v 1.283 2020/02/22 22:20:47 ad Exp $	*/
+/*	$NetBSD: lfs_segment.c,v 1.284 2020/02/23 08:40:08 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_segment.c,v 1.283 2020/02/22 22:20:47 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_segment.c,v 1.284 2020/02/23 08:40:08 riastradh Exp $");
 
 #ifdef DEBUG
 # define vndebug(vp, str) do {		\
@@ -396,7 +396,7 @@ lfs_vflush(struct vnode *vp)
 	 * still not done with this vnode.
 	 * XXX we can do better than this.
 	 */
-	KDASSERT(ip->i_number != LFS_IFILE_INUM);
+	KASSERT(ip->i_number != LFS_IFILE_INUM);
 	lfs_writeinode(fs, sp, ip);
 	mutex_enter(_lock);
 	LFS_SET_UINO(ip, IN_MODIFIED);

Index: src/sys/ufs/lfs/lfs_vnops.c
diff -u src/sys/ufs/lfs/lfs_vnops.c:1.327 src/sys/ufs/lfs/lfs_vnops.c:1.328
--- src/sys/ufs/lfs/lfs_vnops.c:1.327	Sun Feb 23 08:39:39 2020
+++ src/sys/ufs/lfs/lfs_vnops.c	Sun Feb 23 08:40:08 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_vnops.c,v 1.327 2020/02/23 08:39:39 riastradh Exp $	*/
+/*	$NetBSD: lfs_vnops.c,v 1.328 2020/02/23 08:40:08 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -125,7 +125,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.327 2020/02/23 08:39:39 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.328 2020/02/23 08:40:08 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -1707,7 +1707,7 @@ lfs_flush_dirops(struct lfs *fs)
 break;
 			}
 		}
-		KDASSERT(ip->i_number != LFS_IFILE_INUM);
+		KASSERT(ip->i_number != LFS_IFILE_INUM);
 		error = lfs_writeinode(fs, sp, ip);
 		mutex_enter(_lock);
 		if (error && (sp->seg_flags & SEGM_SINGLE)) {
@@ -1829,7 +1829,7 @@ lfs_flush_pchain(struct lfs *fs)
 			LFS_SET_UINO(ip, IN_MODIFIED);
 			mutex_exit(_lock);
 		}
-		KDASSERT(ip->i_number != LFS_IFILE_INUM);
+		KASSERT(ip->i_number != LFS_IFILE_INUM);
 		error2 = lfs_writeinode(fs, sp, ip);
 
 		VOP_UNLOCK(vp);



CVS commit: src/sys/ufs/lfs

2020-02-23 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Feb 23 08:40:19 UTC 2020

Modified Files:
src/sys/ufs/lfs: lfs_vnops.c

Log Message:
Take a reference and fix assertions in lfs_flush_dirops.

Fixes panic:

KASSERT((ip->i_state & IN_ADIROP) == 0) at lfs_vnops.c:1670
lfs_flush_dirops
lfs_check
lfs_setattr
VOP_SETATTR
change_mode
sys_fchmod
syscall

This assertion -- and the assertion that vp->v_uflag has VU_DIROP set
-- is valid only until we release lfs_lock, because we may race with
lfs_unmark_dirop which will remove the nodes and change the flags.

Further, vp itself is valid only as long as it is referenced, which it
is as long as it's on the dchain, but lfs_unmark_dirop drops the
dchain's reference.


To generate a diff of this commit:
cvs rdiff -u -r1.328 -r1.329 src/sys/ufs/lfs/lfs_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/lfs/lfs_vnops.c
diff -u src/sys/ufs/lfs/lfs_vnops.c:1.328 src/sys/ufs/lfs/lfs_vnops.c:1.329
--- src/sys/ufs/lfs/lfs_vnops.c:1.328	Sun Feb 23 08:40:08 2020
+++ src/sys/ufs/lfs/lfs_vnops.c	Sun Feb 23 08:40:19 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_vnops.c,v 1.328 2020/02/23 08:40:08 riastradh Exp $	*/
+/*	$NetBSD: lfs_vnops.c,v 1.329 2020/02/23 08:40:19 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -125,7 +125,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.328 2020/02/23 08:40:08 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.329 2020/02/23 08:40:19 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -1623,7 +1623,6 @@ lfs_flush_dirops(struct lfs *fs)
 		return EROFS;
 
 	mutex_enter(_lock);
-	KASSERT(fs->lfs_writer);
 	if (TAILQ_FIRST(>lfs_dchainhd) == NULL) {
 		mutex_exit(_lock);
 		return 0;
@@ -1667,13 +1666,33 @@ lfs_flush_dirops(struct lfs *fs)
 			lfs_dchain_marker_pass_flush.ev_count++;
 			continue;
 		}
-		mutex_exit(_lock);
 		vp = ITOV(ip);
-		mutex_enter(vp->v_interlock);
 
+		/*
+		 * Prevent the vnode from going away if it's just been
+		 * put out in the segment and lfs_unmark_dirop is about
+		 * to release it.  While it is on the list it is always
+		 * referenced, so it cannot be reclaimed until we
+		 * release it.
+		 */
+		vref(vp);
+
+		/*
+		 * Since we hold lfs_writer, the node can't be in an
+		 * active dirop.  Since it's on the list and we hold a
+		 * reference to it, it can't be reclaimed now.
+		 */
 		KASSERT((ip->i_state & IN_ADIROP) == 0);
 		KASSERT(vp->v_uflag & VU_DIROP);
-		KASSERT(vdead_check(vp, VDEAD_NOWAIT) == 0);
+
+		/*
+		 * After we release lfs_lock, if we were in the middle
+		 * of writing a segment, lfs_unmark_dirop may end up
+		 * clearing VU_DIROP, and we have no way to stop it.
+		 * That should be OK -- we'll just have less to do
+		 * here.
+		 */
+		mutex_exit(_lock);
 
 		/*
 		 * All writes to directories come from dirops; all
@@ -1683,15 +1702,6 @@ lfs_flush_dirops(struct lfs *fs)
 		 * directory blocks inodes and file inodes.  So we don't
 		 * really need to lock.
 		 */
-		if (vdead_check(vp, VDEAD_NOWAIT) != 0) {
-			mutex_exit(vp->v_interlock);
-			mutex_enter(_lock);
-			continue;
-		}
-		mutex_exit(vp->v_interlock);
-		/* XXX see below
-		 * waslocked = VOP_ISLOCKED(vp);
-		 */
 		if (vp->v_type != VREG &&
 		((ip->i_state & IN_ALLMOD) || !VPISEMPTY(vp))) {
 			error = lfs_writefile(fs, sp, vp);
@@ -1702,6 +1712,7 @@ lfs_flush_dirops(struct lfs *fs)
 				mutex_exit(_lock);
 			}
 			if (error && (sp->seg_flags & SEGM_SINGLE)) {
+vrele(vp);
 mutex_enter(_lock);
 error = EAGAIN;
 break;
@@ -1709,8 +1720,9 @@ lfs_flush_dirops(struct lfs *fs)
 		}
 		KASSERT(ip->i_number != LFS_IFILE_INUM);
 		error = lfs_writeinode(fs, sp, ip);
-		mutex_enter(_lock);
 		if (error && (sp->seg_flags & SEGM_SINGLE)) {
+			vrele(vp);
+			mutex_enter(_lock);
 			error = EAGAIN;
 			break;
 		}
@@ -1723,7 +1735,12 @@ lfs_flush_dirops(struct lfs *fs)
 		 * write them.
 		 */
 		/* XXX only for non-directories? --KS */
+		mutex_enter(_lock);
 		LFS_SET_UINO(ip, IN_MODIFIED);
+		mutex_exit(_lock);
+
+		vrele(vp);
+		mutex_enter(_lock);
 	}
 	TAILQ_REMOVE(>lfs_dchainhd, marker, i_lfs_dchain);
 	mutex_exit(_lock);



CVS commit: src/sys/ufs/lfs

2020-02-23 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Feb 23 08:40:28 UTC 2020

Modified Files:
src/sys/ufs/lfs: lfs_pages.c

Log Message:
Don't lfs_writer_enter while holding v_interlock.

There's no need to lfs_writer_enter at all here, as far as I can see.
lfs_flush_fs will do it for us.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/ufs/lfs/lfs_pages.c

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

Modified files:

Index: src/sys/ufs/lfs/lfs_pages.c
diff -u src/sys/ufs/lfs/lfs_pages.c:1.20 src/sys/ufs/lfs/lfs_pages.c:1.21
--- src/sys/ufs/lfs/lfs_pages.c:1.20	Wed Jan 15 17:55:44 2020
+++ src/sys/ufs/lfs/lfs_pages.c	Sun Feb 23 08:40:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_pages.c,v 1.20 2020/01/15 17:55:44 ad Exp $	*/
+/*	$NetBSD: lfs_pages.c,v 1.21 2020/02/23 08:40:27 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2019 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_pages.c,v 1.20 2020/01/15 17:55:44 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_pages.c,v 1.21 2020/02/23 08:40:27 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -671,29 +671,30 @@ retry:
 	(vp->v_uflag & VU_DIROP)) {
 		DLOG((DLOG_PAGE, "lfs_putpages: flushing VU_DIROP\n"));
 
- 		lfs_writer_enter(fs, "ppdirop");
+		/*
+		 * NB: lfs_flush_fs can recursively call lfs_putpages,
+		 * but it won't reach this branch because it passes
+		 * PGO_LOCKED.
+		 */
 
-		/* Note if we hold the vnode locked */
-		if (VOP_ISLOCKED(vp) == LK_EXCLUSIVE)
-		{
-		DLOG((DLOG_PAGE, "lfs_putpages: dirop inode already locked\n"));
-		} else {
-		DLOG((DLOG_PAGE, "lfs_putpages: dirop inode not locked\n"));
-		}
 		mutex_exit(vp->v_interlock);
-
 		mutex_enter(_lock);
 		lfs_flush_fs(fs, sync ? SEGM_SYNC : 0);
 		mutex_exit(_lock);
-
 		mutex_enter(vp->v_interlock);
-		lfs_writer_leave(fs);
 
 		/*
 		 * The flush will have cleaned out this vnode as well,
 		 *  no need to do more to it.
 		 *  XXX then why are we falling through and continuing?
 		 */
+
+		/*
+		 * XXX State may have changed while we dropped the
+		 * lock; start over just in case.  The above comment
+		 * suggests this should maybe instead be goto out.
+		 */
+		goto retry;
 	}
 
 	/*



CVS commit: src/sys/ufs/lfs

2020-02-23 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Feb 23 08:40:37 UTC 2020

Modified Files:
src/sys/ufs/lfs: lfs_extern.h lfs_segment.c lfs_subr.c

Log Message:
Break deadlock in PR kern/52301.

The lock order is lfs_writer -> lfs_seglock.  The problem in 52301 is
that lfs_segwrite violates this lock order by sometimes doing
lfs_seglock -> lfs_writer, either (a) when doing a checkpoint or (b),
opportunistically, when there are no dirops pending.  Both cases can
deadlock, because dirops sometimes take the seglock (lfs_truncate,
lfs_valloc, lfs_vfree):

(a) There may be dirops pending, and they may be waiting for the
seglock, so we can't wait for them to complete while holding the
seglock.

(b) The test for fs->lfs_dirops == 0 happens unlocked, and the state
may change by the time lfs_writer_enter acquires lfs_lock.

To resolve this in each case:

(a) Do lfs_writer_enter before lfs_seglock, since we will need it
unconditionally anyway.  The worst performance impact of this should
be that some dirops get delayed a little bit.

(b) Create a new lfs_writer_tryenter to use at this point so that the
test for fs->lfs_dirops == 0 and the acquisition of lfs_writer happen
atomically under lfs_lock.


To generate a diff of this commit:
cvs rdiff -u -r1.115 -r1.116 src/sys/ufs/lfs/lfs_extern.h
cvs rdiff -u -r1.284 -r1.285 src/sys/ufs/lfs/lfs_segment.c
cvs rdiff -u -r1.98 -r1.99 src/sys/ufs/lfs/lfs_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/ufs/lfs/lfs_extern.h
diff -u src/sys/ufs/lfs/lfs_extern.h:1.115 src/sys/ufs/lfs/lfs_extern.h:1.116
--- src/sys/ufs/lfs/lfs_extern.h:1.115	Tue Feb 18 20:23:17 2020
+++ src/sys/ufs/lfs/lfs_extern.h	Sun Feb 23 08:40:37 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_extern.h,v 1.115 2020/02/18 20:23:17 chs Exp $	*/
+/*	$NetBSD: lfs_extern.h,v 1.116 2020/02/23 08:40:37 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -211,6 +211,7 @@ int lfs_seglock(struct lfs *, unsigned l
 void lfs_segunlock(struct lfs *);
 void lfs_segunlock_relock(struct lfs *);
 int lfs_writer_enter(struct lfs *, const char *);
+int lfs_writer_tryenter(struct lfs *);
 void lfs_writer_leave(struct lfs *);
 void lfs_wakeup_cleaner(struct lfs *);
 

Index: src/sys/ufs/lfs/lfs_segment.c
diff -u src/sys/ufs/lfs/lfs_segment.c:1.284 src/sys/ufs/lfs/lfs_segment.c:1.285
--- src/sys/ufs/lfs/lfs_segment.c:1.284	Sun Feb 23 08:40:08 2020
+++ src/sys/ufs/lfs/lfs_segment.c	Sun Feb 23 08:40:37 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_segment.c,v 1.284 2020/02/23 08:40:08 riastradh Exp $	*/
+/*	$NetBSD: lfs_segment.c,v 1.285 2020/02/23 08:40:37 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_segment.c,v 1.284 2020/02/23 08:40:08 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_segment.c,v 1.285 2020/02/23 08:40:37 riastradh Exp $");
 
 #ifdef DEBUG
 # define vndebug(vp, str) do {		\
@@ -621,6 +621,15 @@ lfs_segwrite(struct mount *mp, int flags
 	 */
 	do_ckp = LFS_SHOULD_CHECKPOINT(fs, flags);
 
+	/*
+	 * If we know we're gonna need the writer lock, take it now to
+	 * preserve the lock order lfs_writer -> lfs_seglock.
+	 */
+	if (do_ckp) {
+		lfs_writer_enter(fs, "ckpwriter");
+		writer_set = 1;
+	}
+
 	/* We can't do a partial write and checkpoint at the same time. */
 	if (do_ckp)
 		flags &= ~SEGM_SINGLE;
@@ -650,11 +659,10 @@ lfs_segwrite(struct mount *mp, int flags
 break;
 			}
 
-			if (do_ckp || fs->lfs_dirops == 0) {
-if (!writer_set) {
-	lfs_writer_enter(fs, "lfs writer");
-	writer_set = 1;
-}
+			if (do_ckp ||
+			(writer_set = lfs_writer_tryenter(fs)) != 0) {
+KASSERT(writer_set);
+KASSERT(fs->lfs_writer);
 error = lfs_writevnodes(fs, mp, sp, VN_DIROP);
 if (um_error == 0)
 	um_error = error;

Index: src/sys/ufs/lfs/lfs_subr.c
diff -u src/sys/ufs/lfs/lfs_subr.c:1.98 src/sys/ufs/lfs/lfs_subr.c:1.99
--- src/sys/ufs/lfs/lfs_subr.c:1.98	Sun Feb 23 08:38:58 2020
+++ src/sys/ufs/lfs/lfs_subr.c	Sun Feb 23 08:40:37 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_subr.c,v 1.98 2020/02/23 08:38:58 riastradh Exp $	*/
+/*	$NetBSD: lfs_subr.c,v 1.99 2020/02/23 08:40:37 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_subr.c,v 1.98 2020/02/23 08:38:58 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_subr.c,v 1.99 2020/02/23 08:40:37 riastradh Exp $");
 
 #include 
 #include 
@@ -575,7 +575,7 @@ lfs_writer_enter(struct lfs *fs, const c
 {
 	int error = 0;
 
-	ASSERT_MAYBE_SEGLOCK(fs);
+	ASSERT_NO_SEGLOCK(fs);
 	mutex_enter(_lock);
 
 	/* disallow dirops during flush */
@@ -596,6 +596,21 @@ lfs_writer_enter(struct lfs *fs, const c
 	return error;
 }
 
+int

CVS commit: src/sys/ufs/lfs

2020-02-23 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Feb 23 08:39:19 UTC 2020

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

Log Message:
Teach lfs to transition ro<->rw.


To generate a diff of this commit:
cvs rdiff -u -r1.370 -r1.371 src/sys/ufs/lfs/lfs_vfsops.c

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

Modified files:

Index: src/sys/ufs/lfs/lfs_vfsops.c
diff -u src/sys/ufs/lfs/lfs_vfsops.c:1.370 src/sys/ufs/lfs/lfs_vfsops.c:1.371
--- src/sys/ufs/lfs/lfs_vfsops.c:1.370	Tue Feb 18 20:23:17 2020
+++ src/sys/ufs/lfs/lfs_vfsops.c	Sun Feb 23 08:39:18 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_vfsops.c,v 1.370 2020/02/18 20:23:17 chs Exp $	*/
+/*	$NetBSD: lfs_vfsops.c,v 1.371 2020/02/23 08:39:18 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007, 2007
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_vfsops.c,v 1.370 2020/02/18 20:23:17 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_vfsops.c,v 1.371 2020/02/23 08:39:18 riastradh Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_lfs.h"
@@ -120,6 +120,7 @@ MODULE(MODULE_CLASS_VFS, lfs, NULL);
 
 static int lfs_gop_write(struct vnode *, struct vm_page **, int, int);
 static int lfs_mountfs(struct vnode *, struct mount *, struct lwp *);
+static int lfs_flushfiles(struct mount *, int);
 
 static struct sysctllog *lfs_sysctl_log;
 
@@ -755,23 +756,18 @@ lfs_mount(struct mount *mp, const char *
 		ump = VFSTOULFS(mp);
 		fs = ump->um_lfs;
 
-		if (fs->lfs_ronly == 0 && (mp->mnt_flag & MNT_RDONLY)) {
+		if (!fs->lfs_ronly && (mp->mnt_iflag & IMNT_WANTRDONLY)) {
 			/*
 			 * Changing from read/write to read-only.
-			 * XXX: shouldn't we sync here? or does vfs do that?
 			 */
-#ifdef LFS_QUOTA2
-			/* XXX: quotas should remain on when readonly */
-			if (fs->lfs_use_quota2) {
-error = lfsquota2_umount(mp, 0);
-if (error) {
-	return error;
-}
-			}
-#endif
-		}
-
-		if (fs->lfs_ronly && (mp->mnt_iflag & IMNT_WANTRDWR)) {
+			int flags = WRITECLOSE;
+			if (mp->mnt_flag & MNT_FORCE)
+flags |= FORCECLOSE;
+			error = lfs_flushfiles(mp, flags);
+			if (error)
+return error;
+			fs->lfs_ronly = 1;
+		} else if (fs->lfs_ronly && (mp->mnt_iflag & IMNT_WANTRDWR)) {
 			/*
 			 * Changing from read-only to read/write.
 			 * Note in the superblocks that we're writing.
@@ -805,8 +801,9 @@ lfs_mount(struct mount *mp, const char *
 lfs_writesuper(fs, lfs_sb_getsboff(fs, 1));
 			}
 		}
+
 		if (args->fspec == NULL)
-			return EINVAL;
+			return 0;
 	}
 
 	error = set_statvfs_info(path, UIO_USERSPACE, args->fspec,
@@ -1137,6 +1134,7 @@ lfs_mountfs(struct vnode *devvp, struct 
 	mp->mnt_stat.f_iosize = lfs_sb_getbsize(fs);
 	mp->mnt_flag |= MNT_LOCAL;
 	mp->mnt_fs_bshift = lfs_sb_getbshift(fs);
+	mp->mnt_iflag |= IMNT_CAN_RWTORO;
 	if (fs->um_maxsymlinklen > 0)
 		mp->mnt_iflag |= IMNT_DTYPE;
 	else
@@ -1328,22 +1326,72 @@ out:
 int
 lfs_unmount(struct mount *mp, int mntflags)
 {
-	struct lwp *l = curlwp;
 	struct ulfsmount *ump;
 	struct lfs *fs;
-	int error, flags, ronly;
-	vnode_t *vp;
+	int error, ronly;
+
+	ump = VFSTOULFS(mp);
+	fs = ump->um_lfs;
 
-	flags = 0;
-	if (mntflags & MNT_FORCE)
-		flags |= FORCECLOSE;
+	error = lfs_flushfiles(mp, mntflags & MNT_FORCE ? FORCECLOSE : 0);
+	if (error)
+		return error;
+
+	/* Finish with the Ifile, now that we're done with it */
+	vgone(fs->lfs_ivnode);
+
+	ronly = !fs->lfs_ronly;
+	if (fs->lfs_devvp->v_type != VBAD)
+		spec_node_setmountedfs(fs->lfs_devvp, NULL);
+	vn_lock(fs->lfs_devvp, LK_EXCLUSIVE | LK_RETRY);
+	error = VOP_CLOSE(fs->lfs_devvp,
+	ronly ? FREAD : FREAD|FWRITE, NOCRED);
+	vput(fs->lfs_devvp);
+
+	/* Complain about page leakage */
+	if (fs->lfs_pages > 0)
+		printf("lfs_unmount: still claim %d pages (%d in subsystem)\n",
+			fs->lfs_pages, lfs_subsys_pages);
+
+	/* Free per-mount data structures */
+	free(fs->lfs_ino_bitmap, M_SEGMENT);
+	free(fs->lfs_suflags[0], M_SEGMENT);
+	free(fs->lfs_suflags[1], M_SEGMENT);
+	free(fs->lfs_suflags, M_SEGMENT);
+	lfs_free_resblks(fs);
+	cv_destroy(>lfs_sleeperscv);
+	cv_destroy(>lfs_diropscv);
+	cv_destroy(>lfs_stopcv);
+	cv_destroy(>lfs_nextsegsleep);
+
+	rw_destroy(>lfs_fraglock);
+	rw_destroy(>lfs_iflock);
+
+	kmem_free(fs, sizeof(struct lfs));
+	kmem_free(ump, sizeof(*ump));
+
+	mp->mnt_data = NULL;
+	mp->mnt_flag &= ~MNT_LOCAL;
+	return (error);
+}
+
+static int
+lfs_flushfiles(struct mount *mp, int flags)
+{
+	struct lwp *l = curlwp;
+	struct ulfsmount *ump;
+	struct lfs *fs;
+	struct vnode *vp;
+	int error;
 
 	ump = VFSTOULFS(mp);
 	fs = ump->um_lfs;
 
 	/* Two checkpoints */
-	lfs_segwrite(mp, SEGM_CKP | SEGM_SYNC);
-	lfs_segwrite(mp, SEGM_CKP | SEGM_SYNC);
+	if (!fs->lfs_ronly) {
+		lfs_segwrite(mp, SEGM_CKP | SEGM_SYNC);
+		lfs_segwrite(mp, SEGM_CKP | SEGM_SYNC);
+	}
 
 	/* wake up the cleaner so it can die */
 	/* XXX: shouldn't this be *after* the error cases below? */
@@ -1383,51 +1431,18 @@ 

CVS commit: src/sys/ufs/lfs

2020-02-23 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Feb 23 08:39:48 UTC 2020

Modified Files:
src/sys/ufs/lfs: lfs_balloc.c

Log Message:
Serialize access to the splay tree with lfs_lock.


To generate a diff of this commit:
cvs rdiff -u -r1.94 -r1.95 src/sys/ufs/lfs/lfs_balloc.c

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

Modified files:

Index: src/sys/ufs/lfs/lfs_balloc.c
diff -u src/sys/ufs/lfs/lfs_balloc.c:1.94 src/sys/ufs/lfs/lfs_balloc.c:1.95
--- src/sys/ufs/lfs/lfs_balloc.c:1.94	Sat Jun 10 05:29:36 2017
+++ src/sys/ufs/lfs/lfs_balloc.c	Sun Feb 23 08:39:48 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_balloc.c,v 1.94 2017/06/10 05:29:36 maya Exp $	*/
+/*	$NetBSD: lfs_balloc.c,v 1.95 2020/02/23 08:39:48 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_balloc.c,v 1.94 2017/06/10 05:29:36 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_balloc.c,v 1.95 2020/02/23 08:39:48 riastradh Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_quota.h"
@@ -660,9 +660,10 @@ lfs_register_block(struct vnode *vp, dad
 static void
 lfs_do_deregister(struct lfs *fs, struct inode *ip, struct lbnentry *lbp)
 {
+
+	KASSERT(mutex_owned(_lock));
 	ASSERT_MAYBE_SEGLOCK(fs);
 
-	mutex_enter(_lock);
 	--ip->i_lfs_nbtree;
 	SPLAY_REMOVE(lfs_splay, >i_lfs_lbtree, lbp);
 	if (fs->lfs_favail > lfs_btofsb(fs, (1 << lfs_sb_getbshift(fs
@@ -671,9 +672,12 @@ lfs_do_deregister(struct lfs *fs, struct
 	if (locked_fakequeue_count > 0)
 		--locked_fakequeue_count;
 	lfs_subsys_pages -= lfs_sb_getbsize(fs) >> PAGE_SHIFT;
-	mutex_exit(_lock);
 
+	mutex_exit(_lock);
 	pool_put(_lbnentry_pool, lbp);
+	mutex_enter(_lock);
+
+	KASSERT(mutex_owned(_lock));
 }
 
 void
@@ -690,19 +694,18 @@ lfs_deregister_block(struct vnode *vp, d
 	if (lbn < 0 || vp->v_type != VREG || ip->i_number == LFS_IFILE_INUM)
 		return;
 
+	mutex_enter(_lock);
 	fs = ip->i_lfs;
 	tmp.lbn = lbn;
-	lbp = SPLAY_FIND(lfs_splay, >i_lfs_lbtree, );
-	if (lbp == NULL)
-		return;
-
-	lfs_do_deregister(fs, ip, lbp);
+	if ((lbp = SPLAY_FIND(lfs_splay, >i_lfs_lbtree, )) != NULL)
+		lfs_do_deregister(fs, ip, lbp);
+	mutex_exit(_lock);
 }
 
 void
 lfs_deregister_all(struct vnode *vp)
 {
-	struct lbnentry *lbp, *nlbp;
+	struct lbnentry *lbp;
 	struct lfs_splay *hd;
 	struct lfs *fs;
 	struct inode *ip;
@@ -711,8 +714,8 @@ lfs_deregister_all(struct vnode *vp)
 	fs = ip->i_lfs;
 	hd = >i_lfs_lbtree;
 
-	for (lbp = SPLAY_MIN(lfs_splay, hd); lbp != NULL; lbp = nlbp) {
-		nlbp = SPLAY_NEXT(lfs_splay, hd, lbp);
+	mutex_enter(_lock);
+	while ((lbp = SPLAY_MIN(lfs_splay, hd)) != NULL)
 		lfs_do_deregister(fs, ip, lbp);
-	}
+	mutex_exit(_lock);
 }



CVS commit: src/sys/ufs/lfs

2020-02-23 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Feb 23 08:39:28 UTC 2020

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

Log Message:
Prevent new dirops while we issue lfs_flush_dirops.

lfs_flush_dirops assumes (by KASSERT((ip->i_state & IN_ADIROP) == 0))
that vnodes on the dchain will not become involved in active dirops
even while holding no other locks (lfs_lock, v_interlock), so we must
set lfs_writer here.  All other callers already set lfs_writer.

We set fs->lfs_writer++ without explicitly doing lfs_writer_enter
because

(a) we already waited for the dirops to drain, and
(b) we hold lfs_lock and cannot drop it before setting lfs_writer.


To generate a diff of this commit:
cvs rdiff -u -r1.145 -r1.146 src/sys/ufs/lfs/lfs_bio.c

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

Modified files:

Index: src/sys/ufs/lfs/lfs_bio.c
diff -u src/sys/ufs/lfs/lfs_bio.c:1.145 src/sys/ufs/lfs/lfs_bio.c:1.146
--- src/sys/ufs/lfs/lfs_bio.c:1.145	Tue Feb 18 20:23:17 2020
+++ src/sys/ufs/lfs/lfs_bio.c	Sun Feb 23 08:39:28 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_bio.c,v 1.145 2020/02/18 20:23:17 chs Exp $	*/
+/*	$NetBSD: lfs_bio.c,v 1.146 2020/02/23 08:39:28 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2008 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_bio.c,v 1.145 2020/02/18 20:23:17 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_bio.c,v 1.146 2020/02/23 08:39:28 riastradh Exp $");
 
 #include 
 #include 
@@ -653,9 +653,14 @@ lfs_check(struct vnode *vp, daddr_t blkn
 	/* If there are too many pending dirops, we have to flush them. */
 	if (fs->lfs_dirvcount > LFS_MAX_FSDIROP(fs) ||
 	lfs_dirvcount > LFS_MAX_DIROP || fs->lfs_diropwait > 0) {
+		KASSERT(fs->lfs_dirops == 0);
+		fs->lfs_writer++;
 		mutex_exit(_lock);
 		lfs_flush_dirops(fs);
 		mutex_enter(_lock);
+		if (--fs->lfs_writer == 0)
+			cv_broadcast(>lfs_diropscv);
+		KASSERT(fs->lfs_dirops == 0);
 	} else if (locked_queue_count + INOCOUNT(fs) > LFS_MAX_BUFS ||
 	locked_queue_bytes + INOBYTES(fs) > LFS_MAX_BYTES ||
 	lfs_subsys_pages > LFS_MAX_PAGES ||



CVS commit: src/sys/ufs/lfs

2020-02-23 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Feb 23 08:39:39 UTC 2020

Modified Files:
src/sys/ufs/lfs: lfs_vnops.c

Log Message:
Assert lfs_writer where I think we can now prove it.


To generate a diff of this commit:
cvs rdiff -u -r1.326 -r1.327 src/sys/ufs/lfs/lfs_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/lfs/lfs_vnops.c
diff -u src/sys/ufs/lfs/lfs_vnops.c:1.326 src/sys/ufs/lfs/lfs_vnops.c:1.327
--- src/sys/ufs/lfs/lfs_vnops.c:1.326	Sun Feb 23 08:38:58 2020
+++ src/sys/ufs/lfs/lfs_vnops.c	Sun Feb 23 08:39:39 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_vnops.c,v 1.326 2020/02/23 08:38:58 riastradh Exp $	*/
+/*	$NetBSD: lfs_vnops.c,v 1.327 2020/02/23 08:39:39 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -125,7 +125,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.326 2020/02/23 08:38:58 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.327 2020/02/23 08:39:39 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -1616,12 +1616,14 @@ lfs_flush_dirops(struct lfs *fs)
 	int error = 0;
 
 	ASSERT_MAYBE_SEGLOCK(fs);
-	KASSERT(fs->lfs_nadirop == 0);
+	KASSERT(fs->lfs_nadirop == 0); /* stable during lfs_writer */
+	KASSERT(fs->lfs_dirops == 0);  /* stable during lfs_writer */
 
 	if (fs->lfs_ronly)
 		return EROFS;
 
 	mutex_enter(_lock);
+	KASSERT(fs->lfs_writer);
 	if (TAILQ_FIRST(>lfs_dchainhd) == NULL) {
 		mutex_exit(_lock);
 		return 0;
@@ -1655,6 +1657,7 @@ lfs_flush_dirops(struct lfs *fs)
 	 *
 	 */
 	mutex_enter(_lock);
+	KASSERT(fs->lfs_writer);
 	TAILQ_INSERT_HEAD(>lfs_dchainhd, marker, i_lfs_dchain);
 	while ((ip = TAILQ_NEXT(marker, i_lfs_dchain)) != NULL) {
 		TAILQ_REMOVE(>lfs_dchainhd, marker, i_lfs_dchain);
@@ -1755,6 +1758,7 @@ lfs_flush_pchain(struct lfs *fs)
 	int error, error2;
 
 	ASSERT_NO_SEGLOCK(fs);
+	KASSERT(fs->lfs_writer);
 
 	if (fs->lfs_ronly)
 		return EROFS;



CVS commit: src/sys/ufs/lfs

2020-02-23 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Feb 23 08:39:09 UTC 2020

Modified Files:
src/sys/ufs/lfs: lfs_debug.c

Log Message:
Just use VOP_BWRITE for lfs_bwrite_log.

Hope this doesn't cause trouble with vfs_suspend.


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 src/sys/ufs/lfs/lfs_debug.c

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

Modified files:

Index: src/sys/ufs/lfs/lfs_debug.c
diff -u src/sys/ufs/lfs/lfs_debug.c:1.54 src/sys/ufs/lfs/lfs_debug.c:1.55
--- src/sys/ufs/lfs/lfs_debug.c:1.54	Tue Sep  1 06:12:04 2015
+++ src/sys/ufs/lfs/lfs_debug.c	Sun Feb 23 08:39:09 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_debug.c,v 1.54 2015/09/01 06:12:04 dholland Exp $	*/
+/*	$NetBSD: lfs_debug.c,v 1.55 2020/02/23 08:39:09 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_debug.c,v 1.54 2015/09/01 06:12:04 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_debug.c,v 1.55 2020/02/23 08:39:09 riastradh Exp $");
 
 #ifdef DEBUG
 
@@ -84,16 +84,12 @@ struct lfs_log_entry lfs_log[LFS_LOGLENG
 int
 lfs_bwrite_log(struct buf *bp, const char *file, int line)
 {
-	struct vop_bwrite_args a;
-
-	a.a_desc = VDESC(vop_bwrite);
-	a.a_bp = bp;
 
 	if (!(bp->b_flags & B_GATHERED) && !(bp->b_oflags & BO_DELWRI)) {
 		LFS_ENTER_LOG("write", file, line, bp->b_lblkno, bp->b_flags,
 			curproc->p_pid);
 	}
-	return (VCALL(bp->b_vp, VOFFSET(vop_bwrite), ));
+	return VOP_BWRITE(bp->b_vp, bp);
 }
 
 void



CVS commit: src/sys/ufs/lfs

2020-02-23 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Feb 23 08:38:58 UTC 2020

Modified Files:
src/sys/ufs/lfs: lfs_inode.h lfs_subr.c lfs_vnops.c

Log Message:
Use a marker node to iterate lfs_dchainhd / i_lfs_dchain.

I believe elements can be removed while the lock is dropped,
including the next node we're hanging on to.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/ufs/lfs/lfs_inode.h
cvs rdiff -u -r1.97 -r1.98 src/sys/ufs/lfs/lfs_subr.c
cvs rdiff -u -r1.325 -r1.326 src/sys/ufs/lfs/lfs_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/lfs/lfs_inode.h
diff -u src/sys/ufs/lfs/lfs_inode.h:1.24 src/sys/ufs/lfs/lfs_inode.h:1.25
--- src/sys/ufs/lfs/lfs_inode.h:1.24	Tue Feb 18 20:23:17 2020
+++ src/sys/ufs/lfs/lfs_inode.h	Sun Feb 23 08:38:58 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_inode.h,v 1.24 2020/02/18 20:23:17 chs Exp $	*/
+/*	$NetBSD: lfs_inode.h,v 1.25 2020/02/23 08:38:58 riastradh Exp $	*/
 /*  from NetBSD: ulfs_inode.h,v 1.5 2013/06/06 00:51:50 dholland Exp  */
 /*  from NetBSD: inode.h,v 1.72 2016/06/03 15:36:03 christos Exp  */
 
@@ -123,6 +123,7 @@ struct inode {
 /* 	   unused	0x0400 */	/* was FFS-only IN_SPACECOUNTED */
 #define	IN_PAGING   0x1000		/* LFS: file is on paging queue */
 #define IN_CDIROP   0x4000  /* LFS: dirop completed pending i/o */
+#define	IN_MARKER	0x0001	/* LFS: marker inode for iteration */
 
 /* XXX this is missing some of the flags */
 #define IN_ALLMOD (IN_MODIFIED|IN_ACCESS|IN_CHANGE|IN_UPDATE|IN_MODIFY|IN_ACCESSED|IN_CLEANING)

Index: src/sys/ufs/lfs/lfs_subr.c
diff -u src/sys/ufs/lfs/lfs_subr.c:1.97 src/sys/ufs/lfs/lfs_subr.c:1.98
--- src/sys/ufs/lfs/lfs_subr.c:1.97	Wed Jul 26 16:42:37 2017
+++ src/sys/ufs/lfs/lfs_subr.c	Sun Feb 23 08:38:58 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_subr.c,v 1.97 2017/07/26 16:42:37 maya Exp $	*/
+/*	$NetBSD: lfs_subr.c,v 1.98 2020/02/23 08:38:58 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_subr.c,v 1.97 2017/07/26 16:42:37 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_subr.c,v 1.98 2020/02/23 08:38:58 riastradh Exp $");
 
 #include 
 #include 
@@ -337,10 +337,14 @@ lfs_seglock(struct lfs *fs, unsigned lon
 
 static void lfs_unmark_dirop(struct lfs *);
 
+static struct evcnt lfs_dchain_marker_pass_dirop =
+EVCNT_INITIALIZER(EVCNT_TYPE_MISC, NULL, "lfs", "dchain marker pass dirop");
+EVCNT_ATTACH_STATIC(lfs_dchain_marker_pass_dirop);
+
 static void
 lfs_unmark_dirop(struct lfs *fs)
 {
-	struct inode *ip, *nip;
+	struct inode *ip, *marker;
 	struct vnode *vp;
 	int doit;
 
@@ -349,13 +353,28 @@ lfs_unmark_dirop(struct lfs *fs)
 	doit = !(fs->lfs_flags & LFS_UNDIROP);
 	if (doit)
 		fs->lfs_flags |= LFS_UNDIROP;
-	if (!doit) {
-		mutex_exit(_lock);
+	mutex_exit(_lock);
+
+	if (!doit)
 		return;
-	}
 
-	for (ip = TAILQ_FIRST(>lfs_dchainhd); ip != NULL; ip = nip) {
-		nip = TAILQ_NEXT(ip, i_lfs_dchain);
+	marker = pool_get(_inode_pool, PR_WAITOK);
+	KASSERT(fs != NULL);
+	memset(marker, 0, sizeof(*marker));
+	marker->inode_ext.lfs = pool_get(_inoext_pool, PR_WAITOK);
+	memset(marker->inode_ext.lfs, 0, sizeof(*marker->inode_ext.lfs));
+	marker->i_state |= IN_MARKER;
+
+	mutex_enter(_lock);
+	TAILQ_INSERT_HEAD(>lfs_dchainhd, marker, i_lfs_dchain);
+	while ((ip = TAILQ_NEXT(marker, i_lfs_dchain)) != NULL) {
+		TAILQ_REMOVE(>lfs_dchainhd, marker, i_lfs_dchain);
+		TAILQ_INSERT_AFTER(>lfs_dchainhd, ip, marker,
+		i_lfs_dchain);
+		if (ip->i_state & IN_MARKER) {
+			lfs_dchain_marker_pass_dirop.ev_count++;
+			continue;
+		}
 		vp = ITOV(ip);
 		if ((ip->i_state & (IN_ADIROP | IN_CDIROP)) == IN_CDIROP) {
 			--lfs_dirvcount;
@@ -371,10 +390,13 @@ lfs_unmark_dirop(struct lfs *fs)
 			ip->i_state &= ~IN_CDIROP;
 		}
 	}
-
+	TAILQ_REMOVE(>lfs_dchainhd, marker, i_lfs_dchain);
 	fs->lfs_flags &= ~LFS_UNDIROP;
 	wakeup(>lfs_flags);
 	mutex_exit(_lock);
+
+	pool_put(_inoext_pool, marker->inode_ext.lfs);
+	pool_put(_inode_pool, marker);
 }
 
 static void

Index: src/sys/ufs/lfs/lfs_vnops.c
diff -u src/sys/ufs/lfs/lfs_vnops.c:1.325 src/sys/ufs/lfs/lfs_vnops.c:1.326
--- src/sys/ufs/lfs/lfs_vnops.c:1.325	Wed Sep 18 17:59:15 2019
+++ src/sys/ufs/lfs/lfs_vnops.c	Sun Feb 23 08:38:58 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_vnops.c,v 1.325 2019/09/18 17:59:15 christos Exp $	*/
+/*	$NetBSD: lfs_vnops.c,v 1.326 2020/02/23 08:38:58 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -125,7 +125,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.325 2019/09/18 17:59:15 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.326 2020/02/23 08:38:58 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -1595,6 +1595,10 @@ lfs_strategy(void *v)
 	return VOP_STRATEGY(vp, bp);
 }

CVS commit: src/sys/ufs/lfs

2020-02-22 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Feb 22 22:20:47 UTC 2020

Modified Files:
src/sys/ufs/lfs: lfs_segment.c

Log Message:
Make LFS/rump play nice with aiodoned removal.

PR kern/55004 (Hundreds of file system tests now fail on real hardware)


To generate a diff of this commit:
cvs rdiff -u -r1.282 -r1.283 src/sys/ufs/lfs/lfs_segment.c

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

Modified files:

Index: src/sys/ufs/lfs/lfs_segment.c
diff -u src/sys/ufs/lfs/lfs_segment.c:1.282 src/sys/ufs/lfs/lfs_segment.c:1.283
--- src/sys/ufs/lfs/lfs_segment.c:1.282	Tue Feb 18 20:23:17 2020
+++ src/sys/ufs/lfs/lfs_segment.c	Sat Feb 22 22:20:47 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_segment.c,v 1.282 2020/02/18 20:23:17 chs Exp $	*/
+/*	$NetBSD: lfs_segment.c,v 1.283 2020/02/22 22:20:47 ad Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_segment.c,v 1.282 2020/02/18 20:23:17 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_segment.c,v 1.283 2020/02/22 22:20:47 ad Exp $");
 
 #ifdef DEBUG
 # define vndebug(vp, str) do {		\
@@ -2513,7 +2513,7 @@ lfs_free_aiodone(struct buf *bp)
 	fs = bp->b_private;
 	ASSERT_NO_SEGLOCK(fs);
 	lfs_freebuf(fs, bp);
-	KERNEL_UNLOCK_LAST(curlwp);
+	KERNEL_UNLOCK_ONE(curlwp);
 }
 
 static void
@@ -2531,7 +2531,7 @@ lfs_super_aiodone(struct buf *bp)
 	wakeup(>lfs_sbactive);
 	mutex_exit(_lock);
 	lfs_freebuf(fs, bp);
-	KERNEL_UNLOCK_LAST(curlwp);
+	KERNEL_UNLOCK_ONE(curlwp);
 }
 
 static void
@@ -2664,7 +2664,7 @@ lfs_cluster_aiodone(struct buf *bp)
 		wakeup(>lfs_iocount);
 	mutex_exit(_lock);
 
-	KERNEL_UNLOCK_LAST(curlwp);
+	KERNEL_UNLOCK_ONE(curlwp);
 
 	pool_put(>lfs_bpppool, cl->bpp);
 	cl->bpp = NULL;



CVS commit: src/sys/ufs/lfs

2020-02-21 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat Feb 22 00:32:09 UTC 2020

Modified Files:
src/sys/ufs/lfs: lfs_alloc.c

Log Message:
Avoid undefined behavior in *_BITMAP_FREE() macros

left shift of 1 by 31 places cannot be represented in type 'int'


To generate a diff of this commit:
cvs rdiff -u -r1.138 -r1.139 src/sys/ufs/lfs/lfs_alloc.c

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

Modified files:

Index: src/sys/ufs/lfs/lfs_alloc.c
diff -u src/sys/ufs/lfs/lfs_alloc.c:1.138 src/sys/ufs/lfs/lfs_alloc.c:1.139
--- src/sys/ufs/lfs/lfs_alloc.c:1.138	Fri Jan 17 20:08:10 2020
+++ src/sys/ufs/lfs/lfs_alloc.c	Sat Feb 22 00:32:08 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_alloc.c,v 1.138 2020/01/17 20:08:10 ad Exp $	*/
+/*	$NetBSD: lfs_alloc.c,v 1.139 2020/02/22 00:32:08 kamil Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_alloc.c,v 1.138 2020/01/17 20:08:10 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_alloc.c,v 1.139 2020/02/22 00:32:08 kamil Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_quota.h"
@@ -95,16 +95,16 @@ __KERNEL_RCSID(0, "$NetBSD: lfs_alloc.c,
 #define SET_BITMAP_FREE(F, I) do { \
 	DLOG((DLOG_ALLOC, "lfs: ino %d wrd %d bit %d set\n", (int)(I), 	\
 	 (int)((I) >> BMSHIFT), (int)((I) & BMMASK)));		\
-	(F)->lfs_ino_bitmap[(I) >> BMSHIFT] |= (1 << ((I) & BMMASK));	\
+	(F)->lfs_ino_bitmap[(I) >> BMSHIFT] |= (1U << ((I) & BMMASK));	\
 } while (0)
 #define CLR_BITMAP_FREE(F, I) do { \
 	DLOG((DLOG_ALLOC, "lfs: ino %d wrd %d bit %d clr\n", (int)(I), 	\
 	 (int)((I) >> BMSHIFT), (int)((I) & BMMASK)));		\
-	(F)->lfs_ino_bitmap[(I) >> BMSHIFT] &= ~(1 << ((I) & BMMASK));	\
+	(F)->lfs_ino_bitmap[(I) >> BMSHIFT] &= ~(1U << ((I) & BMMASK));	\
 } while(0)
 
 #define ISSET_BITMAP_FREE(F, I) \
-	((F)->lfs_ino_bitmap[(I) >> BMSHIFT] & (1 << ((I) & BMMASK)))
+	((F)->lfs_ino_bitmap[(I) >> BMSHIFT] & (1U << ((I) & BMMASK)))
 
 /*
  * Add a new block to the Ifile, to accommodate future file creations.



CVS commit: src/sys/ufs/ffs

2020-02-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Feb 18 17:50:32 UTC 2020

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

Log Message:
Fix non-DIAGNOSTIC build with UVM_PAGE_TRKOWN.


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

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

Modified files:

Index: src/sys/ufs/ffs/ffs_alloc.c
diff -u src/sys/ufs/ffs/ffs_alloc.c:1.164 src/sys/ufs/ffs/ffs_alloc.c:1.165
--- src/sys/ufs/ffs/ffs_alloc.c:1.164	Sun Apr 14 15:55:24 2019
+++ src/sys/ufs/ffs/ffs_alloc.c	Tue Feb 18 17:50:32 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_alloc.c,v 1.164 2019/04/14 15:55:24 kardel Exp $	*/
+/*	$NetBSD: ffs_alloc.c,v 1.165 2020/02/18 17:50:32 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.164 2019/04/14 15:55:24 kardel Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.165 2020/02/18 17:50:32 riastradh Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -208,7 +208,7 @@ ffs_alloc(struct inode *ip, daddr_t lbn,
 	ffs_lblktosize(fs, (voff_t)lbn) < round_page(vp->v_size) &&
 	((vp->v_vflag & VV_MAPPED) != 0 || (size & PAGE_MASK) != 0 ||
 	 ffs_blkoff(fs, size) != 0)) {
-		struct vm_page *pg;
+		struct vm_page *pg __diagused;
 		struct uvm_object *uobj = >v_uobj;
 		voff_t off = trunc_page(ffs_lblktosize(fs, lbn));
 		voff_t endoff = round_page(ffs_lblktosize(fs, lbn) + size);
@@ -328,7 +328,7 @@ ffs_realloccg(struct inode *ip, daddr_t 
 	 */
 
 	if (ITOV(ip)->v_type == VREG) {
-		struct vm_page *pg;
+		struct vm_page *pg __diagused;
 		struct uvm_object *uobj = (ip)->v_uobj;
 		voff_t off = trunc_page(ffs_lblktosize(fs, lbprev));
 		voff_t endoff = round_page(ffs_lblktosize(fs, lbprev) + osize);



CVS commit: src/sys/ufs/lfs

2019-12-20 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Fri Dec 20 20:54:48 UTC 2019

Modified Files:
src/sys/ufs/lfs: lfs_pages.c

Log Message:
Fix lfs_putpages() for bsize < nbpg.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/ufs/lfs/lfs_pages.c

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

Modified files:

Index: src/sys/ufs/lfs/lfs_pages.c
diff -u src/sys/ufs/lfs/lfs_pages.c:1.17 src/sys/ufs/lfs/lfs_pages.c:1.18
--- src/sys/ufs/lfs/lfs_pages.c:1.17	Sun Dec 15 21:11:35 2019
+++ src/sys/ufs/lfs/lfs_pages.c	Fri Dec 20 20:54:48 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_pages.c,v 1.17 2019/12/15 21:11:35 ad Exp $	*/
+/*	$NetBSD: lfs_pages.c,v 1.18 2019/12/20 20:54:48 ad Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2019 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_pages.c,v 1.17 2019/12/15 21:11:35 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_pages.c,v 1.18 2019/12/20 20:54:48 ad Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -310,7 +310,8 @@ check_dirty(struct lfs *fs, struct vnode
   (pg->flags & PG_CLEAN) == 0);
 			dirty += tdirty;
 		}
-		if (nonexistent >= pages_per_block) {
+		if ((pages_per_block > 0 && nonexistent >= pages_per_block) ||
+		(pages_per_block == 0 && nonexistent > 0)) {
 			soff += MAX(PAGE_SIZE, lfs_sb_getbsize(fs));
 			continue;
 		}
@@ -755,9 +756,6 @@ retry:
 		KASSERT(mutex_owned(vp->v_interlock));
 		if (check_dirty(fs, vp, startoffset, endoffset, blkeof,
 ap->a_flags, 0, ) < 0) {
-			mutex_exit(vp->v_interlock);
-			/* XXX why? --ks */
-			mutex_enter(vp->v_interlock);
 			write_and_wait(fs, vp, busypg, seglocked, NULL);
 			if (!seglocked) {
 mutex_exit(vp->v_interlock);



CVS commit: src/sys/ufs/lfs

2019-12-08 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sun Dec  8 19:24:26 UTC 2019

Modified Files:
src/sys/ufs/lfs: lfs_segment.c

Log Message:
Avoid thundering herd: cv_broadcast(>b_busy) -> cv_signal(>b_busy)


To generate a diff of this commit:
cvs rdiff -u -r1.278 -r1.279 src/sys/ufs/lfs/lfs_segment.c

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

Modified files:

Index: src/sys/ufs/lfs/lfs_segment.c
diff -u src/sys/ufs/lfs/lfs_segment.c:1.278 src/sys/ufs/lfs/lfs_segment.c:1.279
--- src/sys/ufs/lfs/lfs_segment.c:1.278	Mon Sep  3 16:29:37 2018
+++ src/sys/ufs/lfs/lfs_segment.c	Sun Dec  8 19:24:26 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_segment.c,v 1.278 2018/09/03 16:29:37 riastradh Exp $	*/
+/*	$NetBSD: lfs_segment.c,v 1.279 2019/12/08 19:24:26 ad Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_segment.c,v 1.278 2018/09/03 16:29:37 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_segment.c,v 1.279 2019/12/08 19:24:26 ad Exp $");
 
 #ifdef DEBUG
 # define vndebug(vp, str) do {		\
@@ -2197,7 +2197,7 @@ lfs_writeseg(struct lfs *fs, struct segm
 		if (unbusybp != NULL) {
 			unbusybp->b_cflags &= ~BC_BUSY;
 			if (unbusybp->b_cflags & BC_WANTED)
-cv_broadcast(>b_busy);
+cv_signal(>b_busy);
 		}
 	}
 	mutex_exit(_lock);



CVS commit: src/sys/ufs/ufs

2019-05-05 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun May  5 15:07:12 UTC 2019

Modified Files:
src/sys/ufs/ufs: dir.h ufs_lookup.c

Log Message:
Add more comments to explain what we are doing.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sys/ufs/ufs/dir.h
cvs rdiff -u -r1.149 -r1.150 src/sys/ufs/ufs/ufs_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/ufs/ufs/dir.h
diff -u src/sys/ufs/ufs/dir.h:1.26 src/sys/ufs/ufs/dir.h:1.27
--- src/sys/ufs/ufs/dir.h:1.26	Sat May  4 21:48:53 2019
+++ src/sys/ufs/ufs/dir.h	Sun May  5 11:07:12 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: dir.h,v 1.26 2019/05/05 01:48:53 christos Exp $	*/
+/*	$NetBSD: dir.h,v 1.27 2019/05/05 15:07:12 christos Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -109,7 +109,9 @@ struct	direct {
  * The UFS_DIRSIZ macro gives the minimum record length which will hold
  * the directory entry.  This requires the amount of space in struct direct
  * without the d_name field, plus enough space for the name with a terminating
- * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
+ * NUL byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
+ * The UFS_NAMEPAD macro gives the number bytes of padding needed including
+ * the NUL terminating byte.
  */
 #define DIR_ROUNDUP	4
 #define UFS_NAMEROUNDUP(namlen)	(((namlen) + DIR_ROUNDUP) & ~(DIR_ROUNDUP - 1))

Index: src/sys/ufs/ufs/ufs_lookup.c
diff -u src/sys/ufs/ufs/ufs_lookup.c:1.149 src/sys/ufs/ufs/ufs_lookup.c:1.150
--- src/sys/ufs/ufs/ufs_lookup.c:1.149	Sat May  4 21:48:53 2019
+++ src/sys/ufs/ufs/ufs_lookup.c	Sun May  5 11:07:12 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_lookup.c,v 1.149 2019/05/05 01:48:53 christos Exp $	*/
+/*	$NetBSD: ufs_lookup.c,v 1.150 2019/05/05 15:07:12 christos Exp $	*/
 
 /*
  * Copyright (c) 1989, 1993
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ufs_lookup.c,v 1.149 2019/05/05 01:48:53 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_lookup.c,v 1.150 2019/05/05 15:07:12 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ffs.h"
@@ -799,7 +799,7 @@ ufs_makedirentry(struct inode *ip, struc
 	newdirp->d_namlen = namelen;
 	memcpy(newdirp->d_name, cnp->cn_nameptr, namelen);
 
-	/* Zero out padding */
+	/* NUL terminate and zero out padding */
 	memset(>d_name[namelen], 0, UFS_NAMEPAD(namelen));
 
 	if (FSFMT(ITOV(ip)))



CVS commit: src/sys/ufs/ufs

2019-05-04 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun May  5 01:48:53 UTC 2019

Modified Files:
src/sys/ufs/ufs: dir.h ufs_lookup.c

Log Message:
Zero out all the dirent padding not just one byte, to avoid kernel memory
disclosure (from https://svnweb.freebsd.org/base?view=revision=347066)


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/ufs/ufs/dir.h
cvs rdiff -u -r1.148 -r1.149 src/sys/ufs/ufs/ufs_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/ufs/ufs/dir.h
diff -u src/sys/ufs/ufs/dir.h:1.25 src/sys/ufs/ufs/dir.h:1.26
--- src/sys/ufs/ufs/dir.h:1.25	Tue Sep  1 02:16:03 2015
+++ src/sys/ufs/ufs/dir.h	Sat May  4 21:48:53 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: dir.h,v 1.25 2015/09/01 06:16:03 dholland Exp $	*/
+/*	$NetBSD: dir.h,v 1.26 2019/05/05 01:48:53 christos Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -111,8 +111,11 @@ struct	direct {
  * without the d_name field, plus enough space for the name with a terminating
  * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
  */
+#define DIR_ROUNDUP	4
+#define UFS_NAMEROUNDUP(namlen)	(((namlen) + DIR_ROUNDUP) & ~(DIR_ROUNDUP - 1))
+#define UFS_NAMEPAD(namlen)	(DIR_ROUNDUP - ((namlen) & (DIR_ROUNDUP - 1)))
 #define	UFS_DIRECTSIZ(namlen) \
-	((sizeof(struct direct) - (FFS_MAXNAMLEN+1)) + (((namlen)+1 + 3) &~ 3))
+	((sizeof(struct direct) - (FFS_MAXNAMLEN+1)) + UFS_NAMEROUNDUP(namlen))
 
 #if (BYTE_ORDER == LITTLE_ENDIAN)
 #define UFS_DIRSIZ(oldfmt, dp, needswap)	\

Index: src/sys/ufs/ufs/ufs_lookup.c
diff -u src/sys/ufs/ufs/ufs_lookup.c:1.148 src/sys/ufs/ufs/ufs_lookup.c:1.149
--- src/sys/ufs/ufs/ufs_lookup.c:1.148	Fri Oct 27 08:25:15 2017
+++ src/sys/ufs/ufs/ufs_lookup.c	Sat May  4 21:48:53 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_lookup.c,v 1.148 2017/10/27 12:25:15 joerg Exp $	*/
+/*	$NetBSD: ufs_lookup.c,v 1.149 2019/05/05 01:48:53 christos Exp $	*/
 
 /*
  * Copyright (c) 1989, 1993
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ufs_lookup.c,v 1.148 2017/10/27 12:25:15 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_lookup.c,v 1.149 2019/05/05 01:48:53 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ffs.h"
@@ -793,10 +793,15 @@ void
 ufs_makedirentry(struct inode *ip, struct componentname *cnp,
 struct direct *newdirp)
 {
+	size_t namelen = cnp->cn_namelen;
+
 	newdirp->d_ino = ip->i_number;
-	newdirp->d_namlen = cnp->cn_namelen;
-	memcpy(newdirp->d_name, cnp->cn_nameptr, (size_t)cnp->cn_namelen);
-	newdirp->d_name[cnp->cn_namelen] = '\0';
+	newdirp->d_namlen = namelen;
+	memcpy(newdirp->d_name, cnp->cn_nameptr, namelen);
+
+	/* Zero out padding */
+	memset(>d_name[namelen], 0, UFS_NAMEPAD(namelen));
+
 	if (FSFMT(ITOV(ip)))
 		newdirp->d_type = 0;
 	else



CVS commit: src/sys/ufs/ffs

2019-04-14 Thread Frank Kardel
Module Name:src
Committed By:   kardel
Date:   Sun Apr 14 15:55:24 UTC 2019

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

Log Message:
PR/53990, PR/52380, PR/52102: UFS2 cylinder group inode allocation botch

Fix rare allocation botch in ffs_nodealloccg().

Conditions:
   a) less than
#_of_initialized_inodes(cg->cg_initediblk)
- inodes_per_filesystem_block
  are allocated in the cylinder group
   b) cg->cg_irotor points to a uninterupted run of
  allocated inodes in the inode bitmap up to the
  end of dynamically initialized inodes
  (cg->cg_initediblk)

In this case the next inode after this run was returned
without initializing the respective inode block. As the
block is not initialized these inodes could trigger panics
on inode consistency due to old (uninitialized) disk data.

In very rare cases data loss could occur when
the uninitialized inode block is initialized via the
normal mechanism.
Further conditions to occur after the above:
   c) no panic
   d) no (forced) fsck
   e) and more than cg->cg_initediblk - inodes_per_filesystem_block
  allocated inodes.

Fix:
Always insure allocation always in initialized inode range
extending the initialized inode range as needed.

Add KASSERTMSG() safeguards.

ok hannken@


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

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

Modified files:

Index: src/sys/ufs/ffs/ffs_alloc.c
diff -u src/sys/ufs/ffs/ffs_alloc.c:1.163 src/sys/ufs/ffs/ffs_alloc.c:1.164
--- src/sys/ufs/ffs/ffs_alloc.c:1.163	Mon Dec 10 20:48:34 2018
+++ src/sys/ufs/ffs/ffs_alloc.c	Sun Apr 14 15:55:24 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_alloc.c,v 1.163 2018/12/10 20:48:34 jdolecek Exp $	*/
+/*	$NetBSD: ffs_alloc.c,v 1.164 2019/04/14 15:55:24 kardel Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.163 2018/12/10 20:48:34 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.164 2019/04/14 15:55:24 kardel Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -1259,7 +1259,7 @@ ffs_nodealloccg(struct inode *ip, int cg
 	struct buf *bp, *ibp;
 	u_int8_t *inosused;
 	int error, start, len, loc, map, i;
-	int32_t initediblk;
+	int32_t initediblk, maxiblk, irotor;
 	daddr_t nalloc;
 	struct ufs2_dinode *dp2;
 	const int needswap = UFS_FSNEEDSWAP(fs);
@@ -1271,7 +1271,13 @@ ffs_nodealloccg(struct inode *ip, int cg
 		return (0);
 	mutex_exit(>um_lock);
 	ibp = NULL;
-	initediblk = -1;
+	if (fs->fs_magic == FS_UFS2_MAGIC) {
+		initediblk = -1;
+	} else {
+		initediblk = fs->fs_ipg;
+	}
+	maxiblk = initediblk;
+
 retry:
 	error = bread(ip->i_devvp, FFS_FSBTODB(fs, cgtod(fs, cg)),
 		(int)fs->fs_cgsize, B_MODIFY, );
@@ -1291,7 +1297,8 @@ retry:
 	 * Check to see if we need to initialize more inodes.
 	 */
 	if (fs->fs_magic == FS_UFS2_MAGIC && ibp == NULL) {
-		initediblk = ufs_rw32(cgp->cg_initediblk, needswap);
+	initediblk = ufs_rw32(cgp->cg_initediblk, needswap);
+		maxiblk = initediblk;
 		nalloc = fs->fs_ipg - ufs_rw32(cgp->cg_cs.cs_nifree, needswap);
 		if (nalloc + FFS_INOPB(fs) > initediblk &&
 		initediblk < ufs_rw32(cgp->cg_niblk, needswap)) {
@@ -1307,6 +1314,9 @@ retry:
 			FFS_NOBLK, fs->fs_bsize, false, );
 			if (error)
 goto fail;
+
+			maxiblk += FFS_INOPB(fs);
+			
 			goto retry;
 		}
 	}
@@ -1316,14 +1326,22 @@ retry:
 	(fs->fs_old_flags & FS_FLAGS_UPDATED))
 		cgp->cg_time = ufs_rw64(time_second, needswap);
 	inosused = cg_inosused(cgp, needswap);
+	
 	if (ipref) {
 		ipref %= fs->fs_ipg;
-		if (isclr(inosused, ipref))
+		/* safeguard to stay in (to be) allocated range */
+		if (ipref < maxiblk && isclr(inosused, ipref))
 			goto gotit;
 	}
-	start = ufs_rw32(cgp->cg_irotor, needswap) / NBBY;
-	len = howmany(fs->fs_ipg - ufs_rw32(cgp->cg_irotor, needswap),
-		NBBY);
+
+	irotor = ufs_rw32(cgp->cg_irotor, needswap); 
+
+	KASSERTMSG(irotor < initediblk, "%s: allocation botch: cg=%d, irotor %d"
+		   " out of bounds, initediblk=%d",
+		   __func__, cg, irotor, initediblk);
+
+	start = irotor / NBBY;
+	len = howmany(maxiblk - irotor, NBBY);
 	loc = skpc(0xff, len, [start]);
 	if (loc == 0) {
 		len = start + 1;
@@ -1341,9 +1359,17 @@ retry:
 	if (map == 0) {
 		panic("%s: block not in map: fs=%s", __func__, fs->fs_fsmnt);
 	}
+	
 	ipref = i * NBBY + ffs(map) - 1;
+
 	cgp->cg_irotor = ufs_rw32(ipref, needswap);
+
 gotit:
+	KASSERTMSG(ipref < maxiblk, "%s: allocation botch: cg=%d attempt to "
+		   "allocate inode index %d beyond max allocated index %d"
+		   " of %d inodes/cg",
+		   __func__, cg, (int)ipref, maxiblk, cgp->cg_niblk);
+
 	UFS_WAPBL_REGISTER_INODE(ip->i_ump->um_mountp, cg * fs->fs_ipg + ipref,
 	mode);
 	/*



CVS commit: src/sys/ufs/ufs

2019-02-24 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Mon Feb 25 06:00:40 UTC 2019

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

Log Message:
Revert -r1.244-245 of ufs_vnops.c; they are wrong.
Fix the mistake in -r1.243 that made them look like reasonable changes.

(this does not affect whether the -r1.243 change works with the union
mount path in libc, but fixes an immediate hazard)


To generate a diff of this commit:
cvs rdiff -u -r1.245 -r1.246 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/ufs/ufs_vnops.c
diff -u src/sys/ufs/ufs/ufs_vnops.c:1.245 src/sys/ufs/ufs/ufs_vnops.c:1.246
--- src/sys/ufs/ufs/ufs_vnops.c:1.245	Mon Feb 25 00:51:24 2019
+++ src/sys/ufs/ufs/ufs_vnops.c	Mon Feb 25 06:00:40 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_vnops.c,v 1.245 2019/02/25 00:51:24 christos Exp $	*/
+/*	$NetBSD: ufs_vnops.c,v 1.246 2019/02/25 06:00:40 dholland Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ufs_vnops.c,v 1.245 2019/02/25 00:51:24 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_vnops.c,v 1.246 2019/02/25 06:00:40 dholland Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -1246,7 +1246,7 @@ ufs_readdir(void *v)
 	size_t		numcookies, maxcookies;
 	/* disk buffer */
 	off_t		physstart, physend;
-	size_t		skipstart;
+	size_t		skipstart, dropend;
 	char		*rawbuf;
 	size_t		rawbufmax, rawbytes;
 	struct uio	rawuio;
@@ -1277,11 +1277,13 @@ ufs_readdir(void *v)
 	}
 
 	skipstart = startoffset - physstart;
+	dropend = endoffset - physend;
 
 	/* how much to actually read */
 	rawbufmax = callerbytes + skipstart;
 	if (rawbufmax < callerbytes)
 		return EINVAL;
+	rawbufmax -= dropend;
 
 	if (rawbufmax < _DIRENT_MINSIZE(rawdp)) {
 		/* no room for even one struct direct */



CVS commit: src/sys/ufs/ufs

2019-02-24 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Feb 25 00:51:24 UTC 2019

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

Log Message:
drop unused


To generate a diff of this commit:
cvs rdiff -u -r1.244 -r1.245 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/ufs/ufs_vnops.c
diff -u src/sys/ufs/ufs/ufs_vnops.c:1.244 src/sys/ufs/ufs/ufs_vnops.c:1.245
--- src/sys/ufs/ufs/ufs_vnops.c:1.244	Sun Feb 24 19:11:13 2019
+++ src/sys/ufs/ufs/ufs_vnops.c	Sun Feb 24 19:51:24 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_vnops.c,v 1.244 2019/02/25 00:11:13 christos Exp $	*/
+/*	$NetBSD: ufs_vnops.c,v 1.245 2019/02/25 00:51:24 christos Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ufs_vnops.c,v 1.244 2019/02/25 00:11:13 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_vnops.c,v 1.245 2019/02/25 00:51:24 christos Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -1246,7 +1246,7 @@ ufs_readdir(void *v)
 	size_t		numcookies, maxcookies;
 	/* disk buffer */
 	off_t		physstart, physend;
-	size_t		skipstart, dropend;
+	size_t		skipstart;
 	char		*rawbuf;
 	size_t		rawbufmax, rawbytes;
 	struct uio	rawuio;
@@ -1277,7 +1277,6 @@ ufs_readdir(void *v)
 	}
 
 	skipstart = startoffset - physstart;
-	dropend = endoffset - physend;
 
 	/* how much to actually read */
 	rawbufmax = callerbytes + skipstart;



CVS commit: src/sys/ufs/ufs

2019-02-24 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Feb 25 00:11:13 UTC 2019

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

Log Message:
remove junk assignment.


To generate a diff of this commit:
cvs rdiff -u -r1.243 -r1.244 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/ufs/ufs_vnops.c
diff -u src/sys/ufs/ufs/ufs_vnops.c:1.243 src/sys/ufs/ufs/ufs_vnops.c:1.244
--- src/sys/ufs/ufs/ufs_vnops.c:1.243	Sun Feb 24 14:06:40 2019
+++ src/sys/ufs/ufs/ufs_vnops.c	Sun Feb 24 19:11:13 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_vnops.c,v 1.243 2019/02/24 19:06:40 mlelstv Exp $	*/
+/*	$NetBSD: ufs_vnops.c,v 1.244 2019/02/25 00:11:13 christos Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ufs_vnops.c,v 1.243 2019/02/24 19:06:40 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_vnops.c,v 1.244 2019/02/25 00:11:13 christos Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -1283,7 +1283,6 @@ ufs_readdir(void *v)
 	rawbufmax = callerbytes + skipstart;
 	if (rawbufmax < callerbytes)
 		return EINVAL;
-	rawbuf -= dropend;
 
 	if (rawbufmax < _DIRENT_MINSIZE(rawdp)) {
 		/* no room for even one struct direct */



CVS commit: src/sys/ufs/ufs

2019-02-24 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Feb 24 19:06:40 UTC 2019

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

Log Message:
Reading a directory may trigger a panic when the buffer is too small.
Adjust necessary checks.

While here, also check for arithmetic overflow.

Reported-by: syzbot+88ecace8bff241690...@syzkaller.appspotmail.com


To generate a diff of this commit:
cvs rdiff -u -r1.242 -r1.243 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/ufs/ufs_vnops.c
diff -u src/sys/ufs/ufs/ufs_vnops.c:1.242 src/sys/ufs/ufs/ufs_vnops.c:1.243
--- src/sys/ufs/ufs/ufs_vnops.c:1.242	Tue Jan  1 10:06:55 2019
+++ src/sys/ufs/ufs/ufs_vnops.c	Sun Feb 24 19:06:40 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_vnops.c,v 1.242 2019/01/01 10:06:55 hannken Exp $	*/
+/*	$NetBSD: ufs_vnops.c,v 1.243 2019/02/24 19:06:40 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ufs_vnops.c,v 1.242 2019/01/01 10:06:55 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_vnops.c,v 1.243 2019/02/24 19:06:40 mlelstv Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -1268,19 +1268,28 @@ ufs_readdir(void *v)
 	}
 
 	/* round start and end down to block boundaries */
-	physstart = startoffset & ~(off_t)(ump->um_dirblksiz - 1);
-	physend = endoffset & ~(off_t)(ump->um_dirblksiz - 1);
+	physstart = rounddown2(startoffset, ump->um_dirblksiz);
+	physend = rounddown2(endoffset, ump->um_dirblksiz);
+
+	if (physstart >= physend) {
+		/* Need at least one block */
+		return EINVAL;
+	}
+
 	skipstart = startoffset - physstart;
 	dropend = endoffset - physend;
 
-	if (callerbytes - dropend < _DIRENT_MINSIZE(rawdp)) {
+	/* how much to actually read */
+	rawbufmax = callerbytes + skipstart;
+	if (rawbufmax < callerbytes)
+		return EINVAL;
+	rawbuf -= dropend;
+
+	if (rawbufmax < _DIRENT_MINSIZE(rawdp)) {
 		/* no room for even one struct direct */
 		return EINVAL;
 	}
 
-	/* how much to actually read */
-	rawbufmax = callerbytes + skipstart - dropend;
-
 	/* read it */
 	rawbuf = kmem_alloc(rawbufmax, KM_SLEEP);
 	rawiov.iov_base = rawbuf;



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/ufs/lfs

2019-01-09 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Jan 10 06:31:04 UTC 2019

Modified Files:
src/sys/ufs/lfs: lfs.h

Log Message:
Update comment (overlooked in r1.179).
>From Jos� Luis Rodr�guez Garc�a in PR kern/53849.


To generate a diff of this commit:
cvs rdiff -u -r1.203 -r1.204 src/sys/ufs/lfs/lfs.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/ufs/lfs/lfs.h
diff -u src/sys/ufs/lfs/lfs.h:1.203 src/sys/ufs/lfs/lfs.h:1.204
--- src/sys/ufs/lfs/lfs.h:1.203	Wed Jul 26 16:42:37 2017
+++ src/sys/ufs/lfs/lfs.h	Thu Jan 10 06:31:04 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs.h,v 1.203 2017/07/26 16:42:37 maya Exp $	*/
+/*	$NetBSD: lfs.h,v 1.204 2019/01/10 06:31:04 martin Exp $	*/
 
 /*  from NetBSD: dinode.h,v 1.25 2016/01/22 23:06:10 dholland Exp  */
 /*  from NetBSD: dir.h,v 1.25 2015/09/01 06:16:03 dholland Exp  */
@@ -467,7 +467,7 @@ struct lfs64_dinode {
 	int64_t		di_ib[ULFS_NIADDR]; /* 208: Indirect disk blocks. */
 	uint64_t	di_modrev;	/* 232: i_modrev for NFSv4 */
 	uint64_t	di_inumber;	/* 240: Inode number */
-	uint64_t	di_spare[1];	/* 244: Reserved; currently unused */
+	uint64_t	di_spare[1];	/* 248: Reserved; currently unused */
 };
 
 union lfs_dinode {



CVS commit: src/sys/ufs

2018-12-10 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Mon Dec 10 20:48:34 UTC 2018

Modified Files:
src/sys/ufs/ffs: ffs_alloc.c
src/sys/ufs/ufs: ufs_inode.c ufs_readwrite.c ufs_vnops.c ufs_wapbl.h

Log Message:
put back UFS_WAPBL_JUNLOCK_ASSERT(), the underlying rw_write_held() check
doesn't actually have a race since it checks if the rwlock is held by
current lwp


To generate a diff of this commit:
cvs rdiff -u -r1.162 -r1.163 src/sys/ufs/ffs/ffs_alloc.c
cvs rdiff -u -r1.104 -r1.105 src/sys/ufs/ufs/ufs_inode.c
cvs rdiff -u -r1.122 -r1.123 src/sys/ufs/ufs/ufs_readwrite.c
cvs rdiff -u -r1.240 -r1.241 src/sys/ufs/ufs/ufs_vnops.c
cvs rdiff -u -r1.15 -r1.16 src/sys/ufs/ufs/ufs_wapbl.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/ufs/ffs/ffs_alloc.c
diff -u src/sys/ufs/ffs/ffs_alloc.c:1.162 src/sys/ufs/ffs/ffs_alloc.c:1.163
--- src/sys/ufs/ffs/ffs_alloc.c:1.162	Mon Dec 10 19:29:41 2018
+++ src/sys/ufs/ffs/ffs_alloc.c	Mon Dec 10 20:48:34 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_alloc.c,v 1.162 2018/12/10 19:29:41 jdolecek Exp $	*/
+/*	$NetBSD: ffs_alloc.c,v 1.163 2018/12/10 20:48:34 jdolecek Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.162 2018/12/10 19:29:41 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.163 2018/12/10 20:48:34 jdolecek Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -566,6 +566,8 @@ ffs_valloc(struct vnode *pvp, int mode, 
 	ino_t ino, ipref;
 	int cg, error;
 
+	UFS_WAPBL_JUNLOCK_ASSERT(pvp->v_mount);
+
 	pip = VTOI(pvp);
 	fs = pip->i_fs;
 	ump = pip->i_ump;

Index: src/sys/ufs/ufs/ufs_inode.c
diff -u src/sys/ufs/ufs/ufs_inode.c:1.104 src/sys/ufs/ufs/ufs_inode.c:1.105
--- src/sys/ufs/ufs/ufs_inode.c:1.104	Mon Dec 10 19:29:41 2018
+++ src/sys/ufs/ufs/ufs_inode.c	Mon Dec 10 20:48:34 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_inode.c,v 1.104 2018/12/10 19:29:41 jdolecek Exp $	*/
+/*	$NetBSD: ufs_inode.c,v 1.105 2018/12/10 20:48:34 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ufs_inode.c,v 1.104 2018/12/10 19:29:41 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_inode.c,v 1.105 2018/12/10 20:48:34 jdolecek Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -86,6 +86,8 @@ ufs_inactive(void *v)
 	int allerror = 0, error;
 	bool wapbl_locked = false;
 
+	UFS_WAPBL_JUNLOCK_ASSERT(mp);
+
 	/*
 	 * Ignore inodes related to stale file handles.
 	 */
@@ -296,6 +298,8 @@ ufs_truncate_retry(struct vnode *vp, uin
 	struct mount *mp = vp->v_mount;
 	int error = 0;
 
+	UFS_WAPBL_JUNLOCK_ASSERT(mp);
+
 	/*
 	 * Truncate might temporarily fail, loop until done.
 	 */

Index: src/sys/ufs/ufs/ufs_readwrite.c
diff -u src/sys/ufs/ufs/ufs_readwrite.c:1.122 src/sys/ufs/ufs/ufs_readwrite.c:1.123
--- src/sys/ufs/ufs/ufs_readwrite.c:1.122	Mon Dec 10 19:29:41 2018
+++ src/sys/ufs/ufs/ufs_readwrite.c	Mon Dec 10 20:48:34 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_readwrite.c,v 1.122 2018/12/10 19:29:41 jdolecek Exp $	*/
+/*	$NetBSD: ufs_readwrite.c,v 1.123 2018/12/10 20:48:34 jdolecek Exp $	*/
 
 /*-
  * Copyright (c) 1993
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: ufs_readwrite.c,v 1.122 2018/12/10 19:29:41 jdolecek Exp $");
+__KERNEL_RCSID(1, "$NetBSD: ufs_readwrite.c,v 1.123 2018/12/10 20:48:34 jdolecek Exp $");
 
 #ifdef LFS_READWRITE
 #define	FS			struct lfs
@@ -291,6 +291,7 @@ WRITE(void *v)
 	KASSERT(uio->uio_rw == UIO_WRITE);
 	KASSERT(vp->v_type == VREG);
 	KASSERT(!ISSET(ioflag, IO_JOURNALLOCKED));
+	UFS_WAPBL_JUNLOCK_ASSERT(vp->v_mount);
 
 	if (ioflag & IO_APPEND)
 		uio->uio_offset = ip->i_size;

Index: src/sys/ufs/ufs/ufs_vnops.c
diff -u src/sys/ufs/ufs/ufs_vnops.c:1.240 src/sys/ufs/ufs/ufs_vnops.c:1.241
--- src/sys/ufs/ufs/ufs_vnops.c:1.240	Mon Dec 10 19:29:41 2018
+++ src/sys/ufs/ufs/ufs_vnops.c	Mon Dec 10 20:48:34 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_vnops.c,v 1.240 2018/12/10 19:29:41 jdolecek Exp $	*/
+/*	$NetBSD: ufs_vnops.c,v 1.241 2018/12/10 20:48:34 jdolecek Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ufs_vnops.c,v 1.240 2018/12/10 19:29:41 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_vnops.c,v 1.241 2018/12/10 20:48:34 jdolecek Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -460,6 +460,8 @@ ufs_setattr(void *v)
 		return (EINVAL);
 	}
 
+	UFS_WAPBL_JUNLOCK_ASSERT(vp->v_mount);
+
 	if (vap->va_flags != VNOVAL) {
 		if (vp->v_mount->mnt_flag & MNT_RDONLY) {
 			error = EROFS;
@@ -1779,6 +1781,8 @@ ufs_makeinode(struct vattr *vap, struct 
 	struct vnode	*tvp;
 	int		error;
 
+	UFS_WAPBL_JUNLOCK_ASSERT(dvp->v_mount);
+
 	error = vcache_new(dvp->v_mount, dvp, vap, cnp->cn_cred, );
 	if (error)
 		return error;

Index: 

CVS commit: src/sys/ufs

2018-12-10 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Mon Dec 10 19:29:41 UTC 2018

Modified Files:
src/sys/ufs/ffs: ffs_alloc.c ffs_inode.c ffs_vfsops.c ffs_wapbl.c
src/sys/ufs/ufs: ufs_inode.c ufs_readwrite.c ufs_vnops.c ufs_wapbl.h

Log Message:
make UFS_WAPBL_JLOCK_ASSERT() #ifdef DIAGNOSTIC, same as the underlying
function KASSERT(), so that it actually does something; fix code using
it to actually pass correct params, so that it compiles

remove UFS_WAPBL_JUNLOCK_ASSERT(), as that is inherently racy (it's
okay on those places if the rwlock is held by other lwp); depend
on the RW_ASSERT()/LOCKDEBUG inside rw_enter() to catch the case
with wapbl rwlock held by current lwp


To generate a diff of this commit:
cvs rdiff -u -r1.161 -r1.162 src/sys/ufs/ffs/ffs_alloc.c
cvs rdiff -u -r1.124 -r1.125 src/sys/ufs/ffs/ffs_inode.c
cvs rdiff -u -r1.359 -r1.360 src/sys/ufs/ffs/ffs_vfsops.c
cvs rdiff -u -r1.42 -r1.43 src/sys/ufs/ffs/ffs_wapbl.c
cvs rdiff -u -r1.103 -r1.104 src/sys/ufs/ufs/ufs_inode.c
cvs rdiff -u -r1.121 -r1.122 src/sys/ufs/ufs/ufs_readwrite.c
cvs rdiff -u -r1.239 -r1.240 src/sys/ufs/ufs/ufs_vnops.c
cvs rdiff -u -r1.14 -r1.15 src/sys/ufs/ufs/ufs_wapbl.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/ufs/ffs/ffs_alloc.c
diff -u src/sys/ufs/ffs/ffs_alloc.c:1.161 src/sys/ufs/ffs/ffs_alloc.c:1.162
--- src/sys/ufs/ffs/ffs_alloc.c:1.161	Mon Sep  3 16:29:37 2018
+++ src/sys/ufs/ffs/ffs_alloc.c	Mon Dec 10 19:29:41 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_alloc.c,v 1.161 2018/09/03 16:29:37 riastradh Exp $	*/
+/*	$NetBSD: ffs_alloc.c,v 1.162 2018/12/10 19:29:41 jdolecek Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.161 2018/09/03 16:29:37 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.162 2018/12/10 19:29:41 jdolecek Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -566,8 +566,6 @@ ffs_valloc(struct vnode *pvp, int mode, 
 	ino_t ino, ipref;
 	int cg, error;
 
-	UFS_WAPBL_JUNLOCK_ASSERT(pvp->v_mount);
-
 	pip = VTOI(pvp);
 	fs = pip->i_fs;
 	ump = pip->i_ump;

Index: src/sys/ufs/ffs/ffs_inode.c
diff -u src/sys/ufs/ffs/ffs_inode.c:1.124 src/sys/ufs/ffs/ffs_inode.c:1.125
--- src/sys/ufs/ffs/ffs_inode.c:1.124	Sat Mar 18 05:26:40 2017
+++ src/sys/ufs/ffs/ffs_inode.c	Mon Dec 10 19:29:41 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_inode.c,v 1.124 2017/03/18 05:26:40 riastradh Exp $	*/
+/*	$NetBSD: ffs_inode.c,v 1.125 2018/12/10 19:29:41 jdolecek Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_inode.c,v 1.124 2017/03/18 05:26:40 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_inode.c,v 1.125 2018/12/10 19:29:41 jdolecek Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -220,7 +220,7 @@ ffs_truncate(struct vnode *ovp, off_t le
 	struct ufsmount *ump = oip->i_ump;
 	void *dcookie;
 
-	UFS_WAPBL_JLOCK_ASSERT(ip->i_ump->um_mountp);
+	UFS_WAPBL_JLOCK_ASSERT(ump->um_mountp);
 
 	if (ovp->v_type == VCHR || ovp->v_type == VBLK ||
 	ovp->v_type == VFIFO || ovp->v_type == VSOCK) {

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.359 src/sys/ufs/ffs/ffs_vfsops.c:1.360
--- src/sys/ufs/ffs/ffs_vfsops.c:1.359	Mon Dec 10 14:46:24 2018
+++ src/sys/ufs/ffs/ffs_vfsops.c	Mon Dec 10 19:29:41 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.359 2018/12/10 14:46:24 maxv Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.360 2018/12/10 19:29:41 jdolecek Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.359 2018/12/10 14:46:24 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.360 2018/12/10 19:29:41 jdolecek Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -2334,7 +2334,7 @@ ffs_cgupdate(struct ufsmount *mp, int wa
 	void *space;
 	int i, size, error = 0, allerror = 0;
 
-	UFS_WAPBL_JLOCK_ASSERT(mp);
+	UFS_WAPBL_JLOCK_ASSERT(mp->um_mountp);
 
 	allerror = ffs_sbupdate(mp, waitfor);
 	blks = howmany(fs->fs_cssize, fs->fs_fsize);

Index: src/sys/ufs/ffs/ffs_wapbl.c
diff -u src/sys/ufs/ffs/ffs_wapbl.c:1.42 src/sys/ufs/ffs/ffs_wapbl.c:1.43
--- src/sys/ufs/ffs/ffs_wapbl.c:1.42	Mon Sep  3 16:29:37 2018
+++ src/sys/ufs/ffs/ffs_wapbl.c	Mon Dec 10 19:29:41 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_wapbl.c,v 1.42 2018/09/03 16:29:37 riastradh Exp $	*/
+/*	$NetBSD: ffs_wapbl.c,v 1.43 2018/12/10 19:29:41 jdolecek Exp $	*/
 
 /*-
  * Copyright (c) 2003,2006,2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_wapbl.c,v 1.42 2018/09/03 16:29:37 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_wapbl.c,v 1.43 2018/12/10 19:29:41 jdolecek Exp $");
 
 #define WAPBL_INTERNAL
 
@@ -176,7 +176,7 @@ 

CVS commit: src/sys/ufs/lfs

2018-08-11 Thread Zafer Aydogan
Module Name:src
Committed By:   zafer
Date:   Sat Aug 11 20:16:21 UTC 2018

Modified Files:
src/sys/ufs/lfs: lfs_vnops.c

Log Message:
In lfs_mkdir fix wrong return path in case of EMLINK which causes a panic. 
Also, check earlier before setting up dirop.


To generate a diff of this commit:
cvs rdiff -u -r1.321 -r1.322 src/sys/ufs/lfs/lfs_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/lfs/lfs_vnops.c
diff -u src/sys/ufs/lfs/lfs_vnops.c:1.321 src/sys/ufs/lfs/lfs_vnops.c:1.322
--- src/sys/ufs/lfs/lfs_vnops.c:1.321	Sun Aug 20 05:37:03 2017
+++ src/sys/ufs/lfs/lfs_vnops.c	Sat Aug 11 20:16:21 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_vnops.c,v 1.321 2017/08/20 05:37:03 maya Exp $	*/
+/*	$NetBSD: lfs_vnops.c,v 1.322 2018/08/11 20:16:21 zafer Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -125,7 +125,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.321 2017/08/20 05:37:03 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.322 2018/08/11 20:16:21 zafer Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -959,6 +959,11 @@ lfs_mkdir(void *v)
 	if (fs->lfs_ronly) {
 		return EROFS;
 	}
+
+	if ((nlink_t)dp->i_nlink >= LINK_MAX) {
+		return EMLINK;
+	}
+
 	dirblksiz = fs->um_dirblksiz;
 	/* XXX dholland 20150911 I believe this to be true, but... */
 	//KASSERT(dirblksiz == LFS_DIRBLKSIZ);
@@ -967,11 +972,6 @@ lfs_mkdir(void *v)
 	if (error)
 		return error;
 
-	if ((nlink_t)dp->i_nlink >= LINK_MAX) {
-		error = EMLINK;
-		goto out;
-	}
-
 	/*
 	 * Must simulate part of lfs_makeinode here to acquire the inode,
 	 * but not have it entered in the parent directory. The entry is



CVS commit: src/sys/ufs/ffs

2018-07-18 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Jul 19 05:09:34 UTC 2018

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

Log Message:
Avoid using magic numbers for arguments of workqueue_create (NFC)


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

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

Modified files:

Index: src/sys/ufs/ffs/ffs_alloc.c
diff -u src/sys/ufs/ffs/ffs_alloc.c:1.159 src/sys/ufs/ffs/ffs_alloc.c:1.160
--- src/sys/ufs/ffs/ffs_alloc.c:1.159	Thu Dec  7 21:53:41 2017
+++ src/sys/ufs/ffs/ffs_alloc.c	Thu Jul 19 05:09:34 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_alloc.c,v 1.159 2017/12/07 21:53:41 chs Exp $	*/
+/*	$NetBSD: ffs_alloc.c,v 1.160 2018/07/19 05:09:34 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.159 2017/12/07 21:53:41 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.160 2018/07/19 05:09:34 ozaki-r Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -1641,7 +1641,7 @@ ffs_discard_init(struct vnode *devvp, st
 
 	ts = kmem_zalloc(sizeof (*ts), KM_SLEEP);
 	error = workqueue_create(>wq, "trimwq", ffs_discardcb, ts,
- 0, 0, 0);
+ PRI_USER, IPL_NONE, 0);
 	if (error) {
 		kmem_free(ts, sizeof (*ts));
 		return NULL;



CVS commit: src/sys/ufs/ffs

2018-07-18 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Wed Jul 18 22:40:56 UTC 2018

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

Log Message:
ffs_superblock_validate - check fs_old_size too.

Now I can mount OpenWindows Version 3 CD from 1991.


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

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

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.357 src/sys/ufs/ffs/ffs_vfsops.c:1.358
--- src/sys/ufs/ffs/ffs_vfsops.c:1.357	Mon May 28 21:04:38 2018
+++ src/sys/ufs/ffs/ffs_vfsops.c	Wed Jul 18 22:40:56 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.357 2018/05/28 21:04:38 chs Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.358 2018/07/18 22:40:56 uwe Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.357 2018/05/28 21:04:38 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.358 2018/07/18 22:40:56 uwe Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -971,7 +971,7 @@ ffs_superblock_validate(struct fs *fs)
 	 * XXX: these values are just zero-checked to prevent obvious
 	 * bugs. We need more strict checks.
 	 */
-	if (fs->fs_size == 0)
+	if (fs->fs_size == 0 && fs->fs_old_size == 0)
 		return 0;
 	if (fs->fs_cssize == 0)
 		return 0;



CVS commit: src/sys/ufs/ffs

2018-07-03 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Jul  4 02:02:15 UTC 2018

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

Log Message:
Avoid Undefined Behavior in ffs_clusteracct()

Change the type of 'bit' variable from int to unsigned int and use unsigned
values consistently.

sys/ufs/ffs/ffs_subr.c:336:10, shift exponent -1 is negative

Detected with Kernel Undefined Behavior Sanitizer.

Reported by 


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/sys/ufs/ffs/ffs_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/ufs/ffs/ffs_subr.c
diff -u src/sys/ufs/ffs/ffs_subr.c:1.49 src/sys/ufs/ffs/ffs_subr.c:1.50
--- src/sys/ufs/ffs/ffs_subr.c:1.49	Sat May  7 11:59:08 2016
+++ src/sys/ufs/ffs/ffs_subr.c	Wed Jul  4 02:02:15 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_subr.c,v 1.49 2016/05/07 11:59:08 maxv Exp $	*/
+/*	$NetBSD: ffs_subr.c,v 1.50 2018/07/04 02:02:15 kamil Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -36,7 +36,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_subr.c,v 1.49 2016/05/07 11:59:08 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_subr.c,v 1.50 2018/07/04 02:02:15 kamil Exp $");
 
 #include 
 
@@ -287,7 +287,8 @@ ffs_clusteracct(struct fs *fs, struct cg
 	int32_t *sump;
 	int32_t *lp;
 	u_char *freemapp, *mapp;
-	int i, start, end, forw, back, map, bit;
+	int i, start, end, forw, back, map;
+	unsigned int bit;
 	const int needswap = UFS_FSNEEDSWAP(fs);
 
 	/* KASSERT(mutex_owned(>um_lock)); */
@@ -312,7 +313,7 @@ ffs_clusteracct(struct fs *fs, struct cg
 		end = ufs_rw32(cgp->cg_nclusterblks, needswap);
 	mapp = [start / NBBY];
 	map = *mapp++;
-	bit = 1 << (start % NBBY);
+	bit = 1U << (start % NBBY);
 	for (i = start; i < end; i++) {
 		if ((map & bit) == 0)
 			break;
@@ -333,7 +334,7 @@ ffs_clusteracct(struct fs *fs, struct cg
 		end = -1;
 	mapp = [start / NBBY];
 	map = *mapp--;
-	bit = 1 << (start % NBBY);
+	bit = 1U << (start % NBBY);
 	for (i = start; i > end; i--) {
 		if ((map & bit) == 0)
 			break;
@@ -341,7 +342,7 @@ ffs_clusteracct(struct fs *fs, struct cg
 			bit >>= 1;
 		} else {
 			map = *mapp--;
-			bit = 1 << (NBBY - 1);
+			bit = 1U << (NBBY - 1);
 		}
 	}
 	back = start - i;



CVS commit: src/sys/ufs/lfs

2018-06-09 Thread Zafer Aydogan
Module Name:src
Committed By:   zafer
Date:   Sat Jun  9 18:48:31 UTC 2018

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

Log Message:
Add missing b_cflags and b_oflags.
Ok dholland@
Addresses PR kern/42342 by Yoshihiro Nakajima


To generate a diff of this commit:
cvs rdiff -u -r1.141 -r1.142 src/sys/ufs/lfs/lfs_bio.c
cvs rdiff -u -r1.276 -r1.277 src/sys/ufs/lfs/lfs_segment.c

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

Modified files:

Index: src/sys/ufs/lfs/lfs_bio.c
diff -u src/sys/ufs/lfs/lfs_bio.c:1.141 src/sys/ufs/lfs/lfs_bio.c:1.142
--- src/sys/ufs/lfs/lfs_bio.c:1.141	Sat Jun 10 05:29:36 2017
+++ src/sys/ufs/lfs/lfs_bio.c	Sat Jun  9 18:48:31 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_bio.c,v 1.141 2017/06/10 05:29:36 maya Exp $	*/
+/*	$NetBSD: lfs_bio.c,v 1.142 2018/06/09 18:48:31 zafer Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2008 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_bio.c,v 1.141 2017/06/10 05:29:36 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_bio.c,v 1.142 2018/06/09 18:48:31 zafer Exp $");
 
 #include 
 #include 
@@ -420,8 +420,7 @@ lfs_bwrite_ext(struct buf *bp, int flags
 	ASSERT_MAYBE_SEGLOCK(fs);
 	KASSERT(bp->b_cflags & BC_BUSY);
 	KASSERT(flags & BW_CLEAN || !LFS_IS_MALLOC_BUF(bp));
-	KASSERT(((bp->b_oflags | bp->b_flags) & (BO_DELWRI|B_LOCKED))
-	!= BO_DELWRI);
+	KASSERT((bp->b_flags & B_LOCKED) || !(bp->b_oflags & BO_DELWRI));
 
 	/*
 	 * Don't write *any* blocks if we're mounted read-only, or

Index: src/sys/ufs/lfs/lfs_segment.c
diff -u src/sys/ufs/lfs/lfs_segment.c:1.276 src/sys/ufs/lfs/lfs_segment.c:1.277
--- src/sys/ufs/lfs/lfs_segment.c:1.276	Wed Jun  6 01:49:09 2018
+++ src/sys/ufs/lfs/lfs_segment.c	Sat Jun  9 18:48:31 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_segment.c,v 1.276 2018/06/06 01:49:09 maya Exp $	*/
+/*	$NetBSD: lfs_segment.c,v 1.277 2018/06/09 18:48:31 zafer Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_segment.c,v 1.276 2018/06/06 01:49:09 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_segment.c,v 1.277 2018/06/09 18:48:31 zafer Exp $");
 
 #ifdef DEBUG
 # define vndebug(vp, str) do {		\
@@ -1408,13 +1408,13 @@ loop:
 			continue;
 		}
 #ifdef DIAGNOSTIC
-# ifdef LFS_USE_B_INVAL
-		if ((bp->b_flags & BC_INVAL) != 0 && bp->b_iodone == NULL) {
+# ifdef LFS_USE_BC_INVAL
+		if ((bp->b_cflags & BC_INVAL) != 0 && bp->b_iodone == NULL) {
 			DLOG((DLOG_SEG, "lfs_gather: lbn %" PRId64
 			  " is BC_INVAL\n", bp->b_lblkno));
 			VOP_PRINT(bp->b_vp);
 		}
-# endif /* LFS_USE_B_INVAL */
+# endif /* LFS_USE_BC_INVAL */
 		if (!(bp->b_oflags & BO_DELWRI))
 			panic("lfs_gather: bp not BO_DELWRI");
 		if (!(bp->b_flags & B_LOCKED)) {
@@ -2106,7 +2106,7 @@ lfs_writeseg(struct lfs *fs, struct segm
 	LFS_WRITESEGENTRY(sup, fs, sp->seg_number, bp); /* Ifile */
 
 	/*
-	 * Mark blocks B_BUSY, to prevent then from being changed between
+	 * Mark blocks BC_BUSY, to prevent then from being changed between
 	 * the checksum computation and the actual write.
 	 *
 	 * If we are cleaning, check indirect blocks for UNWRITTEN, and if
@@ -2217,7 +2217,7 @@ lfs_writeseg(struct lfs *fs, struct segm
 		/* Loop through gop_write cluster blocks */
 		for (byteoffset = 0; byteoffset < (*bpp)->b_bcount;
 		 byteoffset += lfs_sb_getbsize(fs)) {
-#ifdef LFS_USE_B_INVAL
+#ifdef LFS_USE_BC_INVAL
 			if (((*bpp)->b_cflags & BC_INVAL) != 0 &&
 			(*bpp)->b_iodone != NULL) {
 if (copyin((void *)(*bpp)->b_saveaddr +
@@ -2228,7 +2228,7 @@ lfs_writeseg(struct lfs *fs, struct segm
 		(*bpp)->b_lblkno);
 }
 			} else
-#endif /* LFS_USE_B_INVAL */
+#endif /* LFS_USE_BC_INVAL */
 			{
 sum = lfs_cksum_part((char *)
 (*bpp)->b_data + byteoffset, el_size, sum);
@@ -2320,9 +2320,9 @@ lfs_writeseg(struct lfs *fs, struct segm
 			bp->b_bcount, bp->b_blkno,
 			sp->seg_number);
 
-#ifdef LFS_USE_B_INVAL
+#ifdef LFS_USE_BC_INVAL
 			/*
-			 * Fake buffers from the cleaner are marked as B_INVAL.
+			 * Fake buffers from the cleaner are marked as BC_INVAL.
 			 * We need to copy the data from user space rather than
 			 * from the buffer indicated.
 			 * XXX == what do I do on an error?
@@ -2333,7 +2333,7 @@ lfs_writeseg(struct lfs *fs, struct segm
 	panic("lfs_writeseg: "
 	"copyin failed [2]");
 			} else
-#endif /* LFS_USE_B_INVAL */
+#endif /* LFS_USE_BC_INVAL */
 			if (cl->flags & LFS_CL_MALLOC) {
 /* copy data into our cluster. */
 memcpy(p, bp->b_data, bp->b_bcount);
@@ -2590,8 +2590,7 @@ lfs_cluster_aiodone(struct buf *bp)
 			tbp->b_flags |= B_ASYNC; /* for biodone */
 		}
 
-		if (((tbp->b_flags | tbp->b_oflags) &
-		(B_LOCKED | BO_DELWRI)) == B_LOCKED)
+		if ((tbp->b_flags & B_LOCKED) && !(tbp->b_oflags & BO_DELWRI))
 			LFS_UNLOCK_BUF(tbp);
 
 		if 

CVS commit: src/sys/ufs/chfs

2018-02-07 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Feb  7 08:50:13 UTC 2018

Modified Files:
src/sys/ufs/chfs: ebh.c

Log Message:
Remove unnecessary assertions

KASSERT(!rw_lock_held()) just before rw_destroy() is useless because
rw_destroy does more strict check and provides better information on
failure.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/ufs/chfs/ebh.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/chfs/ebh.c
diff -u src/sys/ufs/chfs/ebh.c:1.6 src/sys/ufs/chfs/ebh.c:1.7
--- src/sys/ufs/chfs/ebh.c:1.6	Sat Feb  7 04:21:11 2015
+++ src/sys/ufs/chfs/ebh.c	Wed Feb  7 08:50:13 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ebh.c,v 1.6 2015/02/07 04:21:11 christos Exp $	*/
+/*	$NetBSD: ebh.c,v 1.7 2018/02/07 08:50:13 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -656,7 +656,6 @@ leb_read_unlock(struct chfs_ebh *ebh, in
 	if (le->users == 0) {
 		le = RB_REMOVE(ltree_rbtree, >ltree, le);
 		if (le) {
-			KASSERT(!rw_lock_held(>mutex));
 			rw_destroy(>mutex);
 
 			kmem_free(le, sizeof(struct chfs_ltree_entry));
@@ -713,7 +712,6 @@ leb_write_unlock(struct chfs_ebh *ebh, i
 	if (le->users == 0) {
 		RB_REMOVE(ltree_rbtree, >ltree, le);
 
-		KASSERT(!rw_lock_held(>mutex));
 		rw_destroy(>mutex);
 
 		kmem_free(le, sizeof(struct chfs_ltree_entry));



CVS commit: src/sys/ufs/chfs

2018-01-29 Thread Sevan Janiyan
Module Name:src
Committed By:   sevan
Date:   Mon Jan 29 15:48:50 UTC 2018

Modified Files:
src/sys/ufs/chfs: chfs_pool.c

Log Message:
Drop commended out include to a hardcoded path in root's home directory.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/ufs/chfs/chfs_pool.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/chfs/chfs_pool.c
diff -u src/sys/ufs/chfs/chfs_pool.c:1.2 src/sys/ufs/chfs/chfs_pool.c:1.3
--- src/sys/ufs/chfs/chfs_pool.c:1.2	Tue Feb 28 02:48:39 2012
+++ src/sys/ufs/chfs/chfs_pool.c	Mon Jan 29 15:48:50 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: chfs_pool.c,v 1.2 2012/02/28 02:48:39 christos Exp $	*/
+/*	$NetBSD: chfs_pool.c,v 1.3 2018/01/29 15:48:50 sevan Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -43,7 +43,6 @@
 #include 
 
 #include "chfs.h"
-//#include 
 
 /* - */
 



CVS commit: src/sys/ufs/ffs

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

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

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


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

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

Modified files:

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



CVS commit: src/sys/ufs/ufs

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

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

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


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

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

Modified files:

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



CVS commit: src/sys/ufs/ffs

2017-12-07 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Thu Dec  7 21:53:41 UTC 2017

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

Log Message:
fix the UVM_PAGE_TRKOWN page-locking assertion at the top of ffs_alloc()
to work right for multi-threaded processes.


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

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

Modified files:

Index: src/sys/ufs/ffs/ffs_alloc.c
diff -u src/sys/ufs/ffs/ffs_alloc.c:1.158 src/sys/ufs/ffs/ffs_alloc.c:1.159
--- src/sys/ufs/ffs/ffs_alloc.c:1.158	Sun Aug 13 21:00:58 2017
+++ src/sys/ufs/ffs/ffs_alloc.c	Thu Dec  7 21:53:41 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_alloc.c,v 1.158 2017/08/13 21:00:58 mlelstv Exp $	*/
+/*	$NetBSD: ffs_alloc.c,v 1.159 2017/12/07 21:53:41 chs Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.158 2017/08/13 21:00:58 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.159 2017/12/07 21:53:41 chs Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -203,10 +203,12 @@ ffs_alloc(struct inode *ip, daddr_t lbn,
 	 * be locked by the current thread.
 	 */
 
-	if (ITOV(ip)->v_type == VREG &&
-	ffs_lblktosize(fs, (voff_t)lbn) < round_page(ITOV(ip)->v_size)) {
+	struct vnode *vp = ITOV(ip);
+	if (vp->v_type == VREG &&
+	ffs_lblktosize(fs, (voff_t)lbn) < round_page(vp->v_size) &&
+	((vp->v_vflag & VV_MAPPED) != 0 || (size & PAGE_MASK) != 0 ||
+	 ffs_blkoff(fs, size) != 0)) {
 		struct vm_page *pg;
-		struct vnode *vp = ITOV(ip);
 		struct uvm_object *uobj = >v_uobj;
 		voff_t off = trunc_page(ffs_lblktosize(fs, lbn));
 		voff_t endoff = round_page(ffs_lblktosize(fs, lbn) + size);
@@ -214,10 +216,8 @@ ffs_alloc(struct inode *ip, daddr_t lbn,
 		mutex_enter(uobj->vmobjlock);
 		while (off < endoff) {
 			pg = uvm_pagelookup(uobj, off);
-			KASSERT((pg == NULL && (vp->v_vflag & VV_MAPPED) == 0 &&
- (size & PAGE_MASK) == 0 && 
- ffs_blkoff(fs, size) == 0) ||
-(pg != NULL && pg->owner == curproc->p_pid &&
+			KASSERT((pg != NULL && pg->owner_tag != NULL &&
+ pg->owner == curproc->p_pid &&
  pg->lowner == curlwp->l_lid));
 			off += PAGE_SIZE;
 		}



CVS commit: src/sys/ufs/ffs

2017-11-15 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Nov 15 21:21:18 UTC 2017

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

Log Message:
PR/52728: Izumi Tsutsui: "mount -u /dev/ /" triggers kernel panic
Simplify the control flow of the mount code and make sure that the
mountfrom argument can be converted to a block device in the update
case.
XXX: pullup-8


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

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

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.354 src/sys/ufs/ffs/ffs_vfsops.c:1.355
--- src/sys/ufs/ffs/ffs_vfsops.c:1.354	Sun Aug 20 08:51:38 2017
+++ src/sys/ufs/ffs/ffs_vfsops.c	Wed Nov 15 16:21:18 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.354 2017/08/20 12:51:38 maya Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.355 2017/11/15 21:21:18 christos Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.354 2017/08/20 12:51:38 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.355 2017/11/15 21:21:18 christos Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -418,12 +418,13 @@ ffs_mount(struct mount *mp, const char *
 		return EINVAL;
 	}
 
+	ump = VFSTOUFS(mp);
+	if ((mp->mnt_flag & (MNT_GETARGS|MNT_UPDATE)) && ump == NULL) {
+		DPRINTF("no ump");
+		return EIO;
+	}
+
 	if (mp->mnt_flag & MNT_GETARGS) {
-		ump = VFSTOUFS(mp);
-		if (ump == NULL) {
-			DPRINTF("no ump");
-			return EIO;
-		}
 		args->fspec = NULL;
 		*data_len = sizeof *args;
 		return 0;
@@ -432,7 +433,13 @@ ffs_mount(struct mount *mp, const char *
 	update = mp->mnt_flag & MNT_UPDATE;
 
 	/* Check arguments */
-	if (args->fspec != NULL) {
+	if (args->fspec == NULL) {
+		if (!update) {
+			/* New mounts must have a filename for the device */
+			DPRINTF("no filename for mount");
+			return EINVAL;
+		}
+	} else {
 		/*
 		 * Look up the name and verify that it's sane.
 		 */
@@ -443,48 +450,43 @@ ffs_mount(struct mount *mp, const char *
 			return error;
 		}
 
-		if (!update) {
-			/*
-			 * Be sure this is a valid block device
-			 */
-			if (devvp->v_type != VBLK) {
-DPRINTF("non block device %d", devvp->v_type);
-error = ENOTBLK;
-			} else if (bdevsw_lookup(devvp->v_rdev) == NULL) {
-DPRINTF("can't find block device 0x%jx",
-devvp->v_rdev);
-error = ENXIO;
-			}
-		} else {
+		/*
+		 * Be sure this is a valid block device
+		 */
+		if (devvp->v_type != VBLK) {
+			DPRINTF("non block device %d", devvp->v_type);
+			error = ENOTBLK;
+			goto fail;
+		}
+
+		if (bdevsw_lookup(devvp->v_rdev) == NULL) {
+			DPRINTF("can't find block device 0x%jx",
+			devvp->v_rdev);
+			error = ENXIO;
+			goto fail;
+		}
+
+		if (update) {
 			/*
 			 * Be sure we're still naming the same device
 			 * used for our initial mount
 			 */
-			ump = VFSTOUFS(mp);
-			if (devvp != ump->um_devvp) {
-if (devvp->v_rdev != ump->um_devvp->v_rdev) {
-	DPRINTF("wrong device 0x%jx != 0x%jx",
-	(uintmax_t)devvp->v_rdev,
-	(uintmax_t)ump->um_devvp->v_rdev);
-	error = EINVAL;
-} else {
-	vrele(devvp);
-	devvp = ump->um_devvp;
-	vref(devvp);
-}
+			if (devvp != ump->um_devvp &&
+			devvp->v_rdev != ump->um_devvp->v_rdev) {
+DPRINTF("wrong device 0x%jx != 0x%jx",
+(uintmax_t)devvp->v_rdev,
+(uintmax_t)ump->um_devvp->v_rdev);
+error = EINVAL;
+goto fail;
 			}
+			vrele(devvp);
+			devvp = NULL;
 		}
-	} else {
-		if (!update) {
-			/* New mounts must have a filename for the device */
-			DPRINTF("no filename for mount");
-			return EINVAL;
-		} else {
-			/* Use the extant mount */
-			ump = VFSTOUFS(mp);
-			devvp = ump->um_devvp;
-			vref(devvp);
-		}
+	}
+
+	if (devvp == NULL) {
+		devvp = ump->um_devvp;
+		vref(devvp);
 	}
 
 	/*
@@ -495,25 +497,17 @@ ffs_mount(struct mount *mp, const char *
 	 * updating the mount is okay (for example, as far as securelevel goes)
 	 * which leaves us with the normal check.
 	 */
-	if (error == 0) {
-		accessmode = VREAD;
-		if (update ?
-		(mp->mnt_iflag & IMNT_WANTRDWR) != 0 :
-		(mp->mnt_flag & MNT_RDONLY) == 0)
-			accessmode |= VWRITE;
-		vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
-		error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_MOUNT,
-		KAUTH_REQ_SYSTEM_MOUNT_DEVICE, mp, devvp,
-		KAUTH_ARG(accessmode));
-		if (error) {
-			DPRINTF("kauth returned %d", error);
-		}
-		VOP_UNLOCK(devvp);
-	}
-
+	accessmode = VREAD;
+	if (update ? (mp->mnt_iflag & IMNT_WANTRDWR) != 0 :
+	(mp->mnt_flag & MNT_RDONLY) == 0)
+		accessmode |= VWRITE;
+	vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
+	error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_MOUNT,
+	KAUTH_REQ_SYSTEM_MOUNT_DEVICE, mp, devvp, KAUTH_ARG(accessmode));
+	VOP_UNLOCK(devvp);
 	if (error) {
-		

CVS commit: src/sys/ufs/chfs

2017-11-14 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Nov 14 22:06:40 UTC 2017

Modified Files:
src/sys/ufs/chfs: chfs_vfsops.c

Log Message:
Fix up chfs_mountfs error branches.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/ufs/chfs/chfs_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/chfs/chfs_vfsops.c
diff -u src/sys/ufs/chfs/chfs_vfsops.c:1.16 src/sys/ufs/chfs/chfs_vfsops.c:1.17
--- src/sys/ufs/chfs/chfs_vfsops.c:1.16	Fri Feb 17 08:31:26 2017
+++ src/sys/ufs/chfs/chfs_vfsops.c	Tue Nov 14 22:06:40 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: chfs_vfsops.c,v 1.16 2017/02/17 08:31:26 hannken Exp $	*/
+/*	$NetBSD: chfs_vfsops.c,v 1.17 2017/11/14 22:06:40 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -227,7 +227,7 @@ chfs_mountfs(struct vnode *devvp, struct
 	err = vinvalbuf(devvp, V_SAVE, cred, l, 0, 0);
 	VOP_UNLOCK(devvp);
 	if (err)
-		return (err);
+		goto fail0;
 
 	/* Setup device. */
 	flash_major = cdevsw_lookup_major(_cdevsw);
@@ -241,10 +241,8 @@ chfs_mountfs(struct vnode *devvp, struct
 		major(dev), flash_major);
 		err = ENODEV;
 	}
-	if (err) {
-		vrele(devvp);
-		return (err);
-	}
+	if (err)
+		goto fail0;
 
 	/* Connect CHFS to UFS. */
 	ump = kmem_zalloc(sizeof(struct ufsmount), KM_SLEEP);
@@ -262,7 +260,7 @@ chfs_mountfs(struct vnode *devvp, struct
 	err = ebh_open(chmp->chm_ebh, devvp->v_rdev);
 	if (err) {
 		dbg("error while opening flash\n");
-		goto fail;
+		goto fail1;
 	}
 
 	//TODO check flash sizes
@@ -320,10 +318,8 @@ chfs_mountfs(struct vnode *devvp, struct
 
 	if (err) {
 		/* Armageddon and return. */
-		chfs_vnocache_hash_destroy(chmp->chm_vnocache_hash);
-		ebh_close(chmp->chm_ebh);
 		err = EIO;
-		goto fail;
+		goto fail2;
 	}
 
 	/* Initialize UFS. */
@@ -359,10 +355,31 @@ chfs_mountfs(struct vnode *devvp, struct
 	spec_node_setmountedfs(devvp, mp);
 	return 0;
 
-fail:
+fail2:
+	KASSERT(TAILQ_EMPTY(>chm_erase_pending_queue));
+	KASSERT(TAILQ_EMPTY(>chm_erasable_pending_wbuf_queue));
+	KASSERT(TAILQ_EMPTY(>chm_very_dirty_queue));
+	KASSERT(TAILQ_EMPTY(>chm_dirty_queue));
+	KASSERT(TAILQ_EMPTY(>chm_clean_queue));
+	KASSERT(TAILQ_EMPTY(>chm_free_queue));
+	rw_destroy(>chm_lock_wbuf);
+	kmem_free(chmp->chm_wbuf, chmp->chm_wbuf_pagesize);
+	mutex_destroy(>chm_lock_vnocache);
+	mutex_destroy(>chm_lock_sizes);
+	mutex_destroy(>chm_lock_mountfields);
+	kmem_free(chmp->chm_blocks, chmp->chm_ebh->peb_nr *
+	sizeof(struct chfs_eraseblock));
+	chfs_vnocache_hash_destroy(chmp->chm_vnocache_hash);
+	ebh_close(chmp->chm_ebh);
+
+fail1:
 	kmem_free(chmp->chm_ebh, sizeof(struct chfs_ebh));
+	mutex_destroy(>um_lock);
 	kmem_free(chmp, sizeof(struct chfs_mount));
 	kmem_free(ump, sizeof(struct ufsmount));
+
+fail0:
+	KASSERT(err);
 	return err;
 }
 



CVS commit: src/sys/ufs/chfs

2017-11-09 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Nov  9 22:16:39 UTC 2017

Modified Files:
src/sys/ufs/chfs: chfs_malloc.c

Log Message:
use PR_WAITOK everywhere.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/ufs/chfs/chfs_malloc.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/chfs/chfs_malloc.c
diff -u src/sys/ufs/chfs/chfs_malloc.c:1.4 src/sys/ufs/chfs/chfs_malloc.c:1.5
--- src/sys/ufs/chfs/chfs_malloc.c:1.4	Fri Oct 19 08:44:39 2012
+++ src/sys/ufs/chfs/chfs_malloc.c	Thu Nov  9 17:16:38 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: chfs_malloc.c,v 1.4 2012/10/19 12:44:39 ttoth Exp $	*/
+/*	$NetBSD: chfs_malloc.c,v 1.5 2017/11/09 22:16:38 christos Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -314,7 +314,7 @@ struct chfs_flash_vnode*
 chfs_alloc_flash_vnode(void)
 {
 	struct chfs_flash_vnode *ret;
-	ret = pool_cache_get(chfs_flash_vnode_cache, 0);
+	ret = pool_cache_get(chfs_flash_vnode_cache, PR_WAITOK);
 	return ret;
 }
 
@@ -330,7 +330,7 @@ struct chfs_flash_dirent_node*
 chfs_alloc_flash_dirent(void)
 {
 	struct chfs_flash_dirent_node *ret;
-	ret = pool_cache_get(chfs_flash_dirent_cache, 0);
+	ret = pool_cache_get(chfs_flash_dirent_cache, PR_WAITOK);
 	return ret;
 }
 
@@ -346,7 +346,7 @@ struct chfs_flash_data_node*
 chfs_alloc_flash_dnode(void)
 {
 	struct chfs_flash_data_node *ret;
-	ret = pool_cache_get(chfs_flash_dnode_cache, 0);
+	ret = pool_cache_get(chfs_flash_dnode_cache, PR_WAITOK);
 	return ret;
 }
 
@@ -362,7 +362,7 @@ struct chfs_node_frag*
 chfs_alloc_node_frag(void)
 {
 	struct chfs_node_frag *ret;
-	ret = pool_cache_get(chfs_node_frag_cache, 0);
+	ret = pool_cache_get(chfs_node_frag_cache, PR_WAITOK);
 	return ret;
 }
 
@@ -378,7 +378,7 @@ struct chfs_tmp_dnode *
 chfs_alloc_tmp_dnode(void)
 {
 	struct chfs_tmp_dnode *ret;
-	ret = pool_cache_get(chfs_tmp_dnode_cache, 0);
+	ret = pool_cache_get(chfs_tmp_dnode_cache, PR_WAITOK);
 	ret->next = NULL;
 	return ret;
 }
@@ -395,7 +395,7 @@ struct chfs_tmp_dnode_info *
 chfs_alloc_tmp_dnode_info(void)
 {
 	struct chfs_tmp_dnode_info *ret;
-	ret = pool_cache_get(chfs_tmp_dnode_info_cache, 0);
+	ret = pool_cache_get(chfs_tmp_dnode_info_cache, PR_WAITOK);
 	ret->tmpnode = NULL;
 	return ret;
 }



CVS commit: src/sys/ufs/ufs

2017-10-25 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Wed Oct 25 18:06:01 UTC 2017

Modified Files:
src/sys/ufs/ufs: quota2.h

Log Message:
fix tyop, PR kern/52653 by Edgar Fuss


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/ufs/ufs/quota2.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/ufs/ufs/quota2.h
diff -u src/sys/ufs/ufs/quota2.h:1.9 src/sys/ufs/ufs/quota2.h:1.10
--- src/sys/ufs/ufs/quota2.h:1.9	Sun Feb  5 14:19:04 2012
+++ src/sys/ufs/ufs/quota2.h	Wed Oct 25 18:06:01 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: quota2.h,v 1.9 2012/02/05 14:19:04 dholland Exp $ */
+/* $NetBSD: quota2.h,v 1.10 2017/10/25 18:06:01 jdolecek Exp $ */
 /*-
   * Copyright (c) 2010 Manuel Bouyer
   * All rights reserved.
@@ -56,7 +56,7 @@ struct quota2_val {
 
 /*
  * On-disk description of a user or group quota
- * These entries are keept as linked list, either in one of the hash HEAD,
+ * These entries are kept as linked list, either in one of the hash HEAD,
  * or in the free list.
  */
 



CVS commit: src/sys/ufs/ffs

2017-08-20 Thread Maya Rashish
Module Name:src
Committed By:   maya
Date:   Sun Aug 20 12:51:39 UTC 2017

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

Log Message:
print mode as octal for readability


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

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

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.353 src/sys/ufs/ffs/ffs_vfsops.c:1.354
--- src/sys/ufs/ffs/ffs_vfsops.c:1.353	Mon Apr 17 08:32:01 2017
+++ src/sys/ufs/ffs/ffs_vfsops.c	Sun Aug 20 12:51:38 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.353 2017/04/17 08:32:01 hannken Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.354 2017/08/20 12:51:38 maya Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.353 2017/04/17 08:32:01 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.354 2017/08/20 12:51:38 maya Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -2132,7 +2132,7 @@ ffs_newvnode(struct mount *mp, struct vn
 
 	ip = VTOI(vp);
 	if (ip->i_mode) {
-		panic("%s: dup alloc ino=%" PRId64 " on %s: mode %x/%x "
+		panic("%s: dup alloc ino=%" PRId64 " on %s: mode %o/%o "
 		"gen %x/%x size %" PRIx64 " blocks %" PRIx64,
 		__func__, ino, fs->fs_fsmnt, DIP(ip, mode), ip->i_mode,
 		DIP(ip, gen), ip->i_gen, DIP(ip, size), DIP(ip, blocks));



CVS commit: src/sys/ufs/ufs

2017-08-20 Thread Maya Rashish
Module Name:src
Committed By:   maya
Date:   Sun Aug 20 12:09:06 UTC 2017

Modified Files:
src/sys/ufs/ufs: inode.h

Log Message:
update the comment to the current IFMT/permissions location


To generate a diff of this commit:
cvs rdiff -u -r1.75 -r1.76 src/sys/ufs/ufs/inode.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/ufs/ufs/inode.h
diff -u src/sys/ufs/ufs/inode.h:1.75 src/sys/ufs/ufs/inode.h:1.76
--- src/sys/ufs/ufs/inode.h:1.75	Sun Aug 14 11:31:41 2016
+++ src/sys/ufs/ufs/inode.h	Sun Aug 20 12:09:06 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: inode.h,v 1.75 2016/08/14 11:31:41 jdolecek Exp $	*/
+/*	$NetBSD: inode.h,v 1.76 2017/08/20 12:09:06 maya Exp $	*/
 
 /*
  * Copyright (c) 1982, 1989, 1993
@@ -144,7 +144,7 @@ struct inode {
 	 * These fields are currently only used by FFS and LFS,
 	 * do NOT use them with ext2fs.
 	 */
-	u_int16_t i_mode;	/* IFMT, permissions; see below. */
+	u_int16_t i_mode;	/* IFMT, permissions; see dinode.h. */
 	int16_t   i_nlink;	/* File link count. */
 	u_int64_t i_size;	/* File byte count. */
 	u_int32_t i_flags;	/* Status flags (chflags). */



CVS commit: src/sys/ufs/lfs

2017-08-19 Thread Maya Rashish
Module Name:src
Committed By:   maya
Date:   Sun Aug 20 05:37:03 UTC 2017

Modified Files:
src/sys/ufs/lfs: lfs_vnops.c

Log Message:
Fix typo in comment


To generate a diff of this commit:
cvs rdiff -u -r1.320 -r1.321 src/sys/ufs/lfs/lfs_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/lfs/lfs_vnops.c
diff -u src/sys/ufs/lfs/lfs_vnops.c:1.320 src/sys/ufs/lfs/lfs_vnops.c:1.321
--- src/sys/ufs/lfs/lfs_vnops.c:1.320	Sat Aug 19 12:01:08 2017
+++ src/sys/ufs/lfs/lfs_vnops.c	Sun Aug 20 05:37:03 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_vnops.c,v 1.320 2017/08/19 12:01:08 maya Exp $	*/
+/*	$NetBSD: lfs_vnops.c,v 1.321 2017/08/20 05:37:03 maya Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -125,7 +125,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.320 2017/08/19 12:01:08 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.321 2017/08/20 05:37:03 maya Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -473,7 +473,7 @@ lfs_fsync(void *v)
 	}
 
 	/*
-	 * If a vnode is bring cleaned, flush it out before we try to
+	 * If a vnode is being cleaned, flush it out before we try to
 	 * reuse it.  This prevents the cleaner from writing files twice
 	 * in the same partial segment, causing an accounting underflow.
 	 */



CVS commit: src/sys/ufs/lfs

2017-08-19 Thread Maya Rashish
Module Name:src
Committed By:   maya
Date:   Sun Aug 20 00:03:12 UTC 2017

Modified Files:
src/sys/ufs/lfs: lfs_segment.c

Log Message:
XXX question our double-flushing of dirops


To generate a diff of this commit:
cvs rdiff -u -r1.274 -r1.275 src/sys/ufs/lfs/lfs_segment.c

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

Modified files:

Index: src/sys/ufs/lfs/lfs_segment.c
diff -u src/sys/ufs/lfs/lfs_segment.c:1.274 src/sys/ufs/lfs/lfs_segment.c:1.275
--- src/sys/ufs/lfs/lfs_segment.c:1.274	Wed Jul 26 16:42:37 2017
+++ src/sys/ufs/lfs/lfs_segment.c	Sun Aug 20 00:03:12 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_segment.c,v 1.274 2017/07/26 16:42:37 maya Exp $	*/
+/*	$NetBSD: lfs_segment.c,v 1.275 2017/08/20 00:03:12 maya Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_segment.c,v 1.274 2017/07/26 16:42:37 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_segment.c,v 1.275 2017/08/20 00:03:12 maya Exp $");
 
 #ifdef DEBUG
 # define vndebug(vp, str) do {		\
@@ -661,7 +661,11 @@ lfs_segwrite(struct mount *mp, int flags
 error = lfs_writevnodes(fs, mp, sp, VN_DIROP);
 if (um_error == 0)
 	um_error = error;
-/* In case writevnodes errored out */
+/*
+ * In case writevnodes errored out
+ * XXX why are we always doing this and not
+ * just on error?
+ */
 lfs_flush_dirops(fs);
 ssp = (SEGSUM *)(sp->segsum);
 lfs_ss_setflags(fs, ssp,



CVS commit: src/sys/ufs/lfs

2017-08-19 Thread Maya Rashish
Module Name:src
Committed By:   maya
Date:   Sat Aug 19 14:22:49 UTC 2017

Modified Files:
src/sys/ufs/lfs: lfs_pages.c

Log Message:
Ask some question about the code in a XXX comment


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/ufs/lfs/lfs_pages.c

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

Modified files:

Index: src/sys/ufs/lfs/lfs_pages.c
diff -u src/sys/ufs/lfs/lfs_pages.c:1.14 src/sys/ufs/lfs/lfs_pages.c:1.15
--- src/sys/ufs/lfs/lfs_pages.c:1.14	Sat Jun 10 05:29:36 2017
+++ src/sys/ufs/lfs/lfs_pages.c	Sat Aug 19 14:22:49 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_pages.c,v 1.14 2017/06/10 05:29:36 maya Exp $	*/
+/*	$NetBSD: lfs_pages.c,v 1.15 2017/08/19 14:22:49 maya Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_pages.c,v 1.14 2017/06/10 05:29:36 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_pages.c,v 1.15 2017/08/19 14:22:49 maya Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -728,8 +728,11 @@ retry:
 		mutex_enter(vp->v_interlock);
 		lfs_writer_leave(fs);
 
-		/* The flush will have cleaned out this vnode as well,
-		   no need to do more to it. */
+		/*
+		 * The flush will have cleaned out this vnode as well,
+		 *  no need to do more to it.
+		 *  XXX then why are we falling through and continuing?
+		 */
 	}
 
 	/*



CVS commit: src/sys/ufs/lfs

2017-08-19 Thread Maya Rashish
Module Name:src
Committed By:   maya
Date:   Sat Aug 19 12:01:08 UTC 2017

Modified Files:
src/sys/ufs/lfs: lfs_vnops.c

Log Message:
Not much point doing anything after a panic call


To generate a diff of this commit:
cvs rdiff -u -r1.319 -r1.320 src/sys/ufs/lfs/lfs_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/lfs/lfs_vnops.c
diff -u src/sys/ufs/lfs/lfs_vnops.c:1.319 src/sys/ufs/lfs/lfs_vnops.c:1.320
--- src/sys/ufs/lfs/lfs_vnops.c:1.319	Sat Aug 19 11:27:42 2017
+++ src/sys/ufs/lfs/lfs_vnops.c	Sat Aug 19 12:01:08 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_vnops.c,v 1.319 2017/08/19 11:27:42 maya Exp $	*/
+/*	$NetBSD: lfs_vnops.c,v 1.320 2017/08/19 12:01:08 maya Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -125,7 +125,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.319 2017/08/19 11:27:42 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.320 2017/08/19 12:01:08 maya Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -1451,11 +1451,8 @@ lfs_reclaim(void *v)
 		ip->i_state &= ~IN_PAGING;
 		TAILQ_REMOVE(>lfs_pchainhd, ip, i_lfs_pchain);
 	}
-	if (vp->v_uflag & VU_DIROP) {
+	if (vp->v_uflag & VU_DIROP)
 		panic("reclaimed vnode is VU_DIROP");
-		vp->v_uflag &= ~VU_DIROP;
-		TAILQ_REMOVE(>lfs_dchainhd, ip, i_lfs_dchain);
-	}
 	mutex_exit(_lock);
 
 	pool_put(_dinode_pool, ip->i_din);



CVS commit: src/sys/ufs/lfs

2017-08-19 Thread Maya Rashish
Module Name:src
Committed By:   maya
Date:   Sat Aug 19 11:27:42 UTC 2017

Modified Files:
src/sys/ufs/lfs: lfs_alloc.c lfs_vnops.c

Log Message:
Consistently use {,UN}MARK_VNODE macros rather than function calls.


To generate a diff of this commit:
cvs rdiff -u -r1.136 -r1.137 src/sys/ufs/lfs/lfs_alloc.c
cvs rdiff -u -r1.318 -r1.319 src/sys/ufs/lfs/lfs_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/lfs/lfs_alloc.c
diff -u src/sys/ufs/lfs/lfs_alloc.c:1.136 src/sys/ufs/lfs/lfs_alloc.c:1.137
--- src/sys/ufs/lfs/lfs_alloc.c:1.136	Sat Jun 10 05:29:36 2017
+++ src/sys/ufs/lfs/lfs_alloc.c	Sat Aug 19 11:27:42 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_alloc.c,v 1.136 2017/06/10 05:29:36 maya Exp $	*/
+/*	$NetBSD: lfs_alloc.c,v 1.137 2017/08/19 11:27:42 maya Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_alloc.c,v 1.136 2017/06/10 05:29:36 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_alloc.c,v 1.137 2017/08/19 11:27:42 maya Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_quota.h"
@@ -510,7 +510,7 @@ lfs_vfree(struct vnode *vp, ino_t ino, i
 	 * not updated together in one function? (and why do both exist,
 	 * anyway?)
 	 */
-	lfs_unmark_vnode(vp);
+	UNMARK_VNODE(vp);
 
 	mutex_enter(_lock);
 	if (vp->v_uflag & VU_DIROP) {

Index: src/sys/ufs/lfs/lfs_vnops.c
diff -u src/sys/ufs/lfs/lfs_vnops.c:1.318 src/sys/ufs/lfs/lfs_vnops.c:1.319
--- src/sys/ufs/lfs/lfs_vnops.c:1.318	Wed Jul 26 16:42:37 2017
+++ src/sys/ufs/lfs/lfs_vnops.c	Sat Aug 19 11:27:42 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_vnops.c,v 1.318 2017/07/26 16:42:37 maya Exp $	*/
+/*	$NetBSD: lfs_vnops.c,v 1.319 2017/08/19 11:27:42 maya Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -125,7 +125,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.318 2017/07/26 16:42:37 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.319 2017/08/19 11:27:42 maya Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -374,7 +374,7 @@ lfs_makeinode(struct vattr *vap, struct 
 		vrele(tvp);
 		return error;
 	}
-	lfs_mark_vnode(tvp);
+	MARK_VNODE(tvp);
 	*vpp = tvp;
 	ip = VTOI(tvp);
 	ip->i_state |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
@@ -419,7 +419,7 @@ lfs_makeinode(struct vattr *vap, struct 
 	DIP_ASSIGN(ip, nlink, 0);
 	ip->i_state |= IN_CHANGE;
 	/* If IN_ADIROP, account for it */
-	lfs_unmark_vnode(tvp);
+	UNMARK_VNODE(tvp);
 	vput(tvp);
 	return (error);
 }
@@ -526,7 +526,7 @@ lfs_inactive(void *v)
 
 	KASSERT(VOP_ISLOCKED(ap->a_vp) == LK_EXCLUSIVE);
 
-	lfs_unmark_vnode(ap->a_vp);
+	UNMARK_VNODE(ap->a_vp);
 
 	/*
 	 * The Ifile is only ever inactivated on unmount.
@@ -989,7 +989,7 @@ lfs_mkdir(void *v)
 	}
 
 	tvp = *ap->a_vpp;
-	lfs_mark_vnode(tvp);
+	MARK_VNODE(tvp);
 	ip = VTOI(tvp);
 	ip->i_state |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
 	ip->i_nlink = 2;
@@ -1064,7 +1064,7 @@ lfs_mkdir(void *v)
 		DIP_ASSIGN(ip, nlink, 0);
 		ip->i_state |= IN_CHANGE;
 		/* If IN_ADIROP, account for it */
-		lfs_unmark_vnode(tvp);
+		UNMARK_VNODE(tvp);
 		vput(tvp);
 	}
 



CVS commit: src/sys/ufs/ffs

2017-08-13 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Aug 13 21:00:58 UTC 2017

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

Log Message:
Don't time out the discard work queue here. Either destroying a work queue
with pending work items panics or accessing freed resources from the work
item will crash. The timeout needs to be handled gracefully by the driver
that implements the discard operation.

Fixes parts of PR 50725.


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

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

Modified files:

Index: src/sys/ufs/ffs/ffs_alloc.c
diff -u src/sys/ufs/ffs/ffs_alloc.c:1.157 src/sys/ufs/ffs/ffs_alloc.c:1.158
--- src/sys/ufs/ffs/ffs_alloc.c:1.157	Wed Jul 12 09:30:16 2017
+++ src/sys/ufs/ffs/ffs_alloc.c	Sun Aug 13 21:00:58 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_alloc.c,v 1.157 2017/07/12 09:30:16 hannken Exp $	*/
+/*	$NetBSD: ffs_alloc.c,v 1.158 2017/08/13 21:00:58 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.157 2017/07/12 09:30:16 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.158 2017/08/13 21:00:58 mlelstv Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -1659,17 +1659,14 @@ ffs_discard_finish(void *vts, int flags)
 {
 	struct discarddata *ts = vts;
 	struct discardopdata *td = NULL;
-	int res = 0;
 
 	/* wait for workqueue to drain */
 	mutex_enter(>wqlk);
 	if (ts->wqcnt) {
 		ts->wqdraining = 1;
-		res = cv_timedwait(>wqcv, >wqlk, mstohz(5000));
+		cv_wait(>wqcv, >wqlk);
 	}
 	mutex_exit(>wqlk);
-	if (res)
-		printf("ffs_discarddata drain timeout\n");
 
 	mutex_enter(>entrylk);
 	if (ts->entry) {



CVS commit: src/sys/ufs

2017-08-07 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Mon Aug  7 06:53:49 UTC 2017

Modified Files:
src/sys/ufs/lfs: ulfs_vnops.c
src/sys/ufs/ufs: ufs_vnops.c

Log Message:
Tidy up ufs_readdir. First step only; there's plenty more that could be
done to improve this code.


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/sys/ufs/lfs/ulfs_vnops.c
cvs rdiff -u -r1.237 -r1.238 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/lfs/ulfs_vnops.c
diff -u src/sys/ufs/lfs/ulfs_vnops.c:1.50 src/sys/ufs/lfs/ulfs_vnops.c:1.51
--- src/sys/ufs/lfs/ulfs_vnops.c:1.50	Fri Aug  4 07:27:42 2017
+++ src/sys/ufs/lfs/ulfs_vnops.c	Mon Aug  7 06:53:49 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ulfs_vnops.c,v 1.50 2017/08/04 07:27:42 maya Exp $	*/
+/*	$NetBSD: ulfs_vnops.c,v 1.51 2017/08/07 06:53:49 dholland Exp $	*/
 /*  from NetBSD: ufs_vnops.c,v 1.232 2016/05/19 18:32:03 riastradh Exp  */
 
 /*-
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ulfs_vnops.c,v 1.50 2017/08/04 07:27:42 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ulfs_vnops.c,v 1.51 2017/08/07 06:53:49 dholland Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_lfs.h"
@@ -769,129 +769,173 @@ ulfs_readdir(void *v)
 		kauth_cred_t	a_cred;
 		int		*a_eofflag;
 		off_t		**a_cookies;
-		int		*ncookies;
+		int		*a_ncookies;
 	} */ *ap = v;
+
+	/* vnode and fs */
 	struct vnode	*vp = ap->a_vp;
-	LFS_DIRHEADER	*cdp, *ecdp;
-	struct dirent	*ndp;
-	char		*cdbuf, *ndbuf, *endp;
-	struct uio	auio, *uio;
-	struct iovec	aiov;
-	int		error;
-	size_t		count, ccount, rcount, cdbufsz, ndbufsz;
-	off_t		off, *ccp;
-	off_t		startoff;
-	size_t		skipbytes;
 	struct ulfsmount *ump = VFSTOULFS(vp->v_mount);
 	struct lfs *fs = ump->um_lfs;
+	/* caller's buffer */
+	struct uio	*calleruio = ap->a_uio;
+	off_t		startoffset, endoffset;
+	size_t		callerbytes;
+	off_t		curoffset;
+	/* dirent production buffer */
+	char		*direntbuf;
+	size_t		direntbufmax;
+	struct dirent	*dirent, *stopdirent;
+	/* output cookies array */
+	off_t		*cookies;
+	size_t		numcookies, maxcookies;
+	/* disk buffer */
+	off_t		physstart, physend;
+	size_t		skipstart, dropend;
+	char		*rawbuf;
+	size_t		rawbufmax, rawbytes;
+	struct uio	rawuio;
+	struct iovec	rawiov;
+	LFS_DIRHEADER	*rawdp, *stoprawdp;
+	/* general */
+	int		error;
 
 	KASSERT(VOP_ISLOCKED(vp));
 
-	uio = ap->a_uio;
-	count = uio->uio_resid;
-	rcount = count - ((uio->uio_offset + count) & (fs->um_dirblksiz - 1));
+	/* figure out where we want to read */
+	callerbytes = calleruio->uio_resid;
+	startoffset = calleruio->uio_offset;
+	endoffset = startoffset + callerbytes;
 
-	if (rcount < LFS_DIRECTSIZ(fs, 0) || count < _DIRENT_MINSIZE(ndp))
+	if (callerbytes < _DIRENT_MINSIZE(dirent)) {
+		/* no room for even one struct dirent */
 		return EINVAL;
+	}
 
-	startoff = uio->uio_offset & ~(fs->um_dirblksiz - 1);
-	skipbytes = uio->uio_offset - startoff;
-	rcount += skipbytes;
-
-	auio.uio_iov = 
-	auio.uio_iovcnt = 1;
-	auio.uio_offset = startoff;
-	auio.uio_resid = rcount;
-	UIO_SETUP_SYSSPACE();
-	auio.uio_rw = UIO_READ;
-	cdbufsz = rcount;
-	cdbuf = kmem_alloc(cdbufsz, KM_SLEEP);
-	aiov.iov_base = cdbuf;
-	aiov.iov_len = rcount;
-	error = VOP_READ(vp, , 0, ap->a_cred);
+	/* round start and end down to block boundaries */
+	physstart = startoffset & ~(off_t)(fs->um_dirblksiz - 1);
+	physend = endoffset & ~(off_t)(fs->um_dirblksiz - 1);
+	skipstart = startoffset - physstart;
+	dropend = endoffset - physend;
+
+	if (callerbytes - dropend < LFS_DIRECTSIZ(fs, 0)) {
+		/* no room for even one dirheader + name */
+		return EINVAL;
+	}
+
+	/* how much to actually read */
+	rawbufmax = callerbytes + skipstart - dropend;
+
+	/* read it */
+	rawbuf = kmem_alloc(rawbufmax, KM_SLEEP);
+	rawiov.iov_base = rawbuf;
+	rawiov.iov_len = rawbufmax;
+	rawuio.uio_iov = 
+	rawuio.uio_iovcnt = 1;
+	rawuio.uio_offset = physstart;
+	rawuio.uio_resid = rawbufmax;
+	UIO_SETUP_SYSSPACE();
+	rawuio.uio_rw = UIO_READ;
+	error = VOP_READ(vp, , 0, ap->a_cred);
 	if (error != 0) {
-		kmem_free(cdbuf, cdbufsz);
+		kmem_free(rawbuf, rawbufmax);
 		return error;
 	}
+	rawbytes = rawbufmax - rawuio.uio_resid;
 
-	rcount -= auio.uio_resid;
+	/* the raw entries to iterate over */
+	rawdp = (LFS_DIRHEADER *)(void *)rawbuf;
+	stoprawdp = (LFS_DIRHEADER *)(void *)[rawbytes];
 
-	cdp = (LFS_DIRHEADER *)(void *)cdbuf;
-	ecdp = (LFS_DIRHEADER *)(void *)[rcount];
+	/* allocate space to produce dirents into */
+	direntbufmax = callerbytes;
+	direntbuf = kmem_alloc(direntbufmax, KM_SLEEP);
 
-	ndbufsz = count;
-	ndbuf = kmem_alloc(ndbufsz, KM_SLEEP);
-	ndp = (struct dirent *)(void *)ndbuf;
-	endp = [count];
+	/* the dirents to iterate over */
+	dirent = (struct dirent *)(void *)direntbuf;
+	stopdirent = (struct dirent *)(void *)[direntbufmax];
 
-	off = uio->uio_offset;
+	/* the output "cookies" (seek positions of directory entries) 

CVS commit: src/sys/ufs/lfs

2017-08-04 Thread Maya Rashish
Module Name:src
Committed By:   maya
Date:   Fri Aug  4 07:27:42 UTC 2017

Modified Files:
src/sys/ufs/lfs: ulfs_vnops.c

Log Message:
fix buffer overflow/KASSERT when cookies are supplied
lfs no longer uses the ffs-style struct direct, use the correct minimum
size

from dholland
XXX more wrong


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/sys/ufs/lfs/ulfs_vnops.c

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

Modified files:

Index: src/sys/ufs/lfs/ulfs_vnops.c
diff -u src/sys/ufs/lfs/ulfs_vnops.c:1.49 src/sys/ufs/lfs/ulfs_vnops.c:1.50
--- src/sys/ufs/lfs/ulfs_vnops.c:1.49	Sat Jun 10 05:29:36 2017
+++ src/sys/ufs/lfs/ulfs_vnops.c	Fri Aug  4 07:27:42 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ulfs_vnops.c,v 1.49 2017/06/10 05:29:36 maya Exp $	*/
+/*	$NetBSD: ulfs_vnops.c,v 1.50 2017/08/04 07:27:42 maya Exp $	*/
 /*  from NetBSD: ufs_vnops.c,v 1.232 2016/05/19 18:32:03 riastradh Exp  */
 
 /*-
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ulfs_vnops.c,v 1.49 2017/06/10 05:29:36 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ulfs_vnops.c,v 1.50 2017/08/04 07:27:42 maya Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_lfs.h"
@@ -826,7 +826,7 @@ ulfs_readdir(void *v)
 
 	off = uio->uio_offset;
 	if (ap->a_cookies) {
-		ccount = rcount / _DIRENT_RECLEN(ndp, 1);
+		ccount = rcount / LFS_DIRECTSIZ(fs, 1);
 		ccp = *(ap->a_cookies) = malloc(ccount * sizeof(*ccp),
 		M_TEMP, M_WAITOK);
 	} else {



CVS commit: src/sys/ufs/ext2fs

2017-07-30 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Jul 30 14:23:54 UTC 2017

Modified Files:
src/sys/ufs/ext2fs: ext2fs_vfsops.c

Log Message:
kmem_xyz(sizeof(struct foo)) --> kmem_xyz(sizeof(*foo))

No change to amd64 binary.


To generate a diff of this commit:
cvs rdiff -u -r1.209 -r1.210 src/sys/ufs/ext2fs/ext2fs_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/ext2fs/ext2fs_vfsops.c
diff -u src/sys/ufs/ext2fs/ext2fs_vfsops.c:1.209 src/sys/ufs/ext2fs/ext2fs_vfsops.c:1.210
--- src/sys/ufs/ext2fs/ext2fs_vfsops.c:1.209	Sun May 28 16:38:55 2017
+++ src/sys/ufs/ext2fs/ext2fs_vfsops.c	Sun Jul 30 14:23:54 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ext2fs_vfsops.c,v 1.209 2017/05/28 16:38:55 hannken Exp $	*/
+/*	$NetBSD: ext2fs_vfsops.c,v 1.210 2017/07/30 14:23:54 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1989, 1991, 1993, 1994
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ext2fs_vfsops.c,v 1.209 2017/05/28 16:38:55 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ext2fs_vfsops.c,v 1.210 2017/07/30 14:23:54 riastradh Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_compat_netbsd.h"
@@ -675,7 +675,7 @@ ext2fs_mountfs(struct vnode *devvp, stru
 	if (error)
 		goto out;
 	fs = (struct ext2fs *)bp->b_data;
-	m_fs = kmem_zalloc(sizeof(struct m_ext2fs), KM_SLEEP);
+	m_fs = kmem_zalloc(sizeof(*m_fs), KM_SLEEP);
 	e2fs_sbload(fs, _fs->e2fs);
 
 	brelse(bp, 0);
@@ -684,7 +684,7 @@ ext2fs_mountfs(struct vnode *devvp, stru
 	/* Once swapped, validate and fill in the superblock. */
 	error = ext2fs_sbfill(m_fs, ronly);
 	if (error) {
-		kmem_free(m_fs, sizeof(struct m_ext2fs));
+		kmem_free(m_fs, sizeof(*m_fs));
 		goto out;
 	}
 	m_fs->e2fs_ronly = ronly;
@@ -755,7 +755,7 @@ out:
 	if (bp != NULL)
 		brelse(bp, 0);
 	if (ump) {
-		kmem_free(ump->um_e2fs, sizeof(struct m_ext2fs));
+		kmem_free(ump->um_e2fs, sizeof(*m_fs));
 		kmem_free(ump, sizeof(*ump));
 		mp->mnt_data = NULL;
 	}



CVS commit: src/sys/ufs/lfs

2017-07-26 Thread Maya Rashish
Module Name:src
Committed By:   maya
Date:   Wed Jul 26 16:42:37 UTC 2017

Modified Files:
src/sys/ufs/lfs: lfs.h lfs_extern.h lfs_segment.c lfs_subr.c
lfs_syscalls.c lfs_vfsops.c lfs_vnops.c

Log Message:
change lfs_nextsegsleep and lfs_allclean_wakeup to use condvar

XXX had to use lfs_lock in lfs_segwait, removed kernel_lock, is this
appropriate?


To generate a diff of this commit:
cvs rdiff -u -r1.202 -r1.203 src/sys/ufs/lfs/lfs.h
cvs rdiff -u -r1.112 -r1.113 src/sys/ufs/lfs/lfs_extern.h
cvs rdiff -u -r1.273 -r1.274 src/sys/ufs/lfs/lfs_segment.c
cvs rdiff -u -r1.96 -r1.97 src/sys/ufs/lfs/lfs_subr.c
cvs rdiff -u -r1.174 -r1.175 src/sys/ufs/lfs/lfs_syscalls.c
cvs rdiff -u -r1.359 -r1.360 src/sys/ufs/lfs/lfs_vfsops.c
cvs rdiff -u -r1.317 -r1.318 src/sys/ufs/lfs/lfs_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/lfs/lfs.h
diff -u src/sys/ufs/lfs/lfs.h:1.202 src/sys/ufs/lfs/lfs.h:1.203
--- src/sys/ufs/lfs/lfs.h:1.202	Mon Jun  5 01:01:42 2017
+++ src/sys/ufs/lfs/lfs.h	Wed Jul 26 16:42:37 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs.h,v 1.202 2017/06/05 01:01:42 maya Exp $	*/
+/*	$NetBSD: lfs.h,v 1.203 2017/07/26 16:42:37 maya Exp $	*/
 
 /*  from NetBSD: dinode.h,v 1.25 2016/01/22 23:06:10 dholland Exp  */
 /*  from NetBSD: dir.h,v 1.25 2015/09/01 06:16:03 dholland Exp  */
@@ -1047,7 +1047,7 @@ struct lfs {
 	/* XXX: should be replaced with a condvar */
 	int lfs_availsleep;
 	/* This one replaces _nextseg... all ditto */
-	int lfs_nextsegsleep;
+	kcondvar_t lfs_nextsegsleep;
 
 	/* Cleaner lwp, set on first bmapv syscall. */
 	struct lwp *lfs_cleaner_thread;

Index: src/sys/ufs/lfs/lfs_extern.h
diff -u src/sys/ufs/lfs/lfs_extern.h:1.112 src/sys/ufs/lfs/lfs_extern.h:1.113
--- src/sys/ufs/lfs/lfs_extern.h:1.112	Thu Jun  8 01:23:01 2017
+++ src/sys/ufs/lfs/lfs_extern.h	Wed Jul 26 16:42:37 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_extern.h,v 1.112 2017/06/08 01:23:01 chs Exp $	*/
+/*	$NetBSD: lfs_extern.h,v 1.113 2017/07/26 16:42:37 maya Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -109,7 +109,7 @@ __BEGIN_DECLS
 
 #if defined(_KERNEL)
 
-extern int lfs_allclean_wakeup;
+extern kcondvar_t lfs_allclean_wakeup;
 extern struct pool lfs_inode_pool;		/* memory pool for inodes */
 extern struct pool lfs_dinode_pool;		/* memory pool for dinodes */
 extern struct pool lfs_inoext_pool;	/* memory pool for inode extension */

Index: src/sys/ufs/lfs/lfs_segment.c
diff -u src/sys/ufs/lfs/lfs_segment.c:1.273 src/sys/ufs/lfs/lfs_segment.c:1.274
--- src/sys/ufs/lfs/lfs_segment.c:1.273	Wed Jul 26 15:07:27 2017
+++ src/sys/ufs/lfs/lfs_segment.c	Wed Jul 26 16:42:37 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_segment.c,v 1.273 2017/07/26 15:07:27 maya Exp $	*/
+/*	$NetBSD: lfs_segment.c,v 1.274 2017/07/26 16:42:37 maya Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_segment.c,v 1.273 2017/07/26 15:07:27 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_segment.c,v 1.274 2017/07/26 16:42:37 maya Exp $");
 
 #ifdef DEBUG
 # define vndebug(vp, str) do {		\
@@ -145,7 +145,7 @@ int	 lfs_writevnodes(struct lfs *fs, str
 static void lfs_shellsort(struct lfs *, struct buf **, union lfs_blocks *,
 			  int, int);
 
-int	lfs_allclean_wakeup;		/* Cleaner wakeup address. */
+kcondvar_t	lfs_allclean_wakeup;	/* Cleaner wakeup address. */
 int	lfs_writeindir = 1;		/* whether to flush indir on non-ckp */
 int	lfs_clean_vnhead = 0;		/* Allow freeing to head of vn list */
 int	lfs_dirvcount = 0;		/* # active dirops */

Index: src/sys/ufs/lfs/lfs_subr.c
diff -u src/sys/ufs/lfs/lfs_subr.c:1.96 src/sys/ufs/lfs/lfs_subr.c:1.97
--- src/sys/ufs/lfs/lfs_subr.c:1.96	Wed Jul 26 14:38:59 2017
+++ src/sys/ufs/lfs/lfs_subr.c	Wed Jul 26 16:42:37 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_subr.c,v 1.96 2017/07/26 14:38:59 maya Exp $	*/
+/*	$NetBSD: lfs_subr.c,v 1.97 2017/07/26 16:42:37 maya Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_subr.c,v 1.96 2017/07/26 14:38:59 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_subr.c,v 1.97 2017/07/26 16:42:37 maya Exp $");
 
 #include 
 #include 
@@ -649,6 +649,6 @@ lfs_wakeup_cleaner(struct lfs *fs)
 	if (fs->lfs_nowrap > 0)
 		return;
 
-	wakeup(>lfs_nextsegsleep);
-	wakeup(_allclean_wakeup);
+	cv_broadcast(>lfs_nextsegsleep);
+	cv_broadcast(_allclean_wakeup);
 }

Index: src/sys/ufs/lfs/lfs_syscalls.c
diff -u src/sys/ufs/lfs/lfs_syscalls.c:1.174 src/sys/ufs/lfs/lfs_syscalls.c:1.175
--- src/sys/ufs/lfs/lfs_syscalls.c:1.174	Mon Apr 17 08:32:01 2017
+++ src/sys/ufs/lfs/lfs_syscalls.c	Wed Jul 26 16:42:37 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_syscalls.c,v 1.174 2017/04/17 08:32:01 hannken Exp $	*/
+/*	$NetBSD: lfs_syscalls.c,v 1.175 

CVS commit: src/sys/ufs/lfs

2017-07-26 Thread Maya Rashish
Module Name:src
Committed By:   maya
Date:   Wed Jul 26 15:07:27 UTC 2017

Modified Files:
src/sys/ufs/lfs: lfs_segment.c

Log Message:
Revert r1.272 fix to PR kern/52301, the performance hit is making things
unusable.


To generate a diff of this commit:
cvs rdiff -u -r1.272 -r1.273 src/sys/ufs/lfs/lfs_segment.c

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

Modified files:

Index: src/sys/ufs/lfs/lfs_segment.c
diff -u src/sys/ufs/lfs/lfs_segment.c:1.272 src/sys/ufs/lfs/lfs_segment.c:1.273
--- src/sys/ufs/lfs/lfs_segment.c:1.272	Thu Jun 15 14:37:30 2017
+++ src/sys/ufs/lfs/lfs_segment.c	Wed Jul 26 15:07:27 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_segment.c,v 1.272 2017/06/15 14:37:30 maya Exp $	*/
+/*	$NetBSD: lfs_segment.c,v 1.273 2017/07/26 15:07:27 maya Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_segment.c,v 1.272 2017/06/15 14:37:30 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_segment.c,v 1.273 2017/07/26 15:07:27 maya Exp $");
 
 #ifdef DEBUG
 # define vndebug(vp, str) do {		\
@@ -603,6 +603,7 @@ lfs_segwrite(struct mount *mp, int flags
 	SEGUSE *segusep;
 	int do_ckp, did_ckp, error;
 	unsigned n, segleft, maxseg, sn, i, curseg;
+	int writer_set = 0;
 	int dirty;
 	int redo;
 	SEGSUM *ssp;
@@ -627,8 +628,6 @@ lfs_segwrite(struct mount *mp, int flags
 	if (do_ckp)
 		flags &= ~SEGM_SINGLE;
 
-	lfs_writer_enter(fs, "lfs segwrite");
-
 	lfs_seglock(fs, flags | (do_ckp ? SEGM_CKP : 0));
 	sp = fs->lfs_sp;
 	if (sp->seg_flags & (SEGM_CLEAN | SEGM_CKP))
@@ -654,7 +653,11 @@ lfs_segwrite(struct mount *mp, int flags
 break;
 			}
 
-			if (do_ckp) {
+			if (do_ckp || fs->lfs_dirops == 0) {
+if (!writer_set) {
+	lfs_writer_enter(fs, "lfs writer");
+	writer_set = 1;
+}
 error = lfs_writevnodes(fs, mp, sp, VN_DIROP);
 if (um_error == 0)
 	um_error = error;
@@ -803,7 +806,8 @@ lfs_segwrite(struct mount *mp, int flags
 
 	/* Note Ifile no longer needs to be written */
 	fs->lfs_doifile = 0;
-	lfs_writer_leave(fs);
+	if (writer_set)
+		lfs_writer_leave(fs);
 
 	/*
 	 * If we didn't write the Ifile, we didn't really do anything.



CVS commit: src/sys/ufs/lfs

2017-07-26 Thread Maya Rashish
Module Name:src
Committed By:   maya
Date:   Wed Jul 26 14:39:00 UTC 2017

Modified Files:
src/sys/ufs/lfs: lfs_subr.c

Log Message:
Deduplicate sanity check that seglock is held on segunlock


To generate a diff of this commit:
cvs rdiff -u -r1.95 -r1.96 src/sys/ufs/lfs/lfs_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/ufs/lfs/lfs_subr.c
diff -u src/sys/ufs/lfs/lfs_subr.c:1.95 src/sys/ufs/lfs/lfs_subr.c:1.96
--- src/sys/ufs/lfs/lfs_subr.c:1.95	Mon Jun 19 12:09:37 2017
+++ src/sys/ufs/lfs/lfs_subr.c	Wed Jul 26 14:38:59 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_subr.c,v 1.95 2017/06/19 12:09:37 maya Exp $	*/
+/*	$NetBSD: lfs_subr.c,v 1.96 2017/07/26 14:38:59 maya Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_subr.c,v 1.95 2017/06/19 12:09:37 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_subr.c,v 1.96 2017/07/26 14:38:59 maya Exp $");
 
 #include 
 #include 
@@ -430,7 +430,10 @@ lfs_segunlock(struct lfs *fs)
 	sp = fs->lfs_sp;
 
 	mutex_enter(_lock);
-	KASSERT(LFS_SEGLOCK_HELD(fs));
+
+	if (!LFS_SEGLOCK_HELD(fs))
+		panic("lfs seglock not held");
+
 	if (fs->lfs_seglock == 1) {
 		if ((sp->seg_flags & (SEGM_PROT | SEGM_CLEAN)) == 0)
 			do_unmark_dirop = 1;
@@ -534,9 +537,6 @@ lfs_segunlock(struct lfs *fs)
 		rw_exit(>lfs_fraglock);
 		if (do_unmark_dirop)
 			lfs_unmark_dirop(fs);
-	} else if (fs->lfs_seglock == 0) {
-		mutex_exit(_lock);
-		panic ("Seglock not held");
 	} else {
 		--fs->lfs_seglock;
 		mutex_exit(_lock);



CVS commit: src/sys/ufs/ffs

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

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

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


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

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

Modified files:

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



CVS commit: src/sys/ufs/lfs

2017-06-19 Thread Maya Rashish
Module Name:src
Committed By:   maya
Date:   Mon Jun 19 12:09:37 UTC 2017

Modified Files:
src/sys/ufs/lfs: lfs_subr.c

Log Message:
Ifdef out KDASSERT which fires on my machine.


To generate a diff of this commit:
cvs rdiff -u -r1.94 -r1.95 src/sys/ufs/lfs/lfs_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/ufs/lfs/lfs_subr.c
diff -u src/sys/ufs/lfs/lfs_subr.c:1.94 src/sys/ufs/lfs/lfs_subr.c:1.95
--- src/sys/ufs/lfs/lfs_subr.c:1.94	Sat Jun 10 05:29:36 2017
+++ src/sys/ufs/lfs/lfs_subr.c	Mon Jun 19 12:09:37 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_subr.c,v 1.94 2017/06/10 05:29:36 maya Exp $	*/
+/*	$NetBSD: lfs_subr.c,v 1.95 2017/06/19 12:09:37 maya Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_subr.c,v 1.94 2017/06/10 05:29:36 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_subr.c,v 1.95 2017/06/19 12:09:37 maya Exp $");
 
 #include 
 #include 
@@ -261,10 +261,12 @@ lfs_free(struct lfs *fs, void *p, int ty
 		}
 	}
 
+#ifdef notyet /* XXX this assert fires */
 	for (int i = 0; i < LFS_N_TOTAL; i++) {
 		KDASSERTMSG(fs->lfs_resblk[i].p == p,
 		"lfs_free: inconsistent reserved block");
 	}
+#endif
 
 	mutex_exit(_lock);
 



CVS commit: src/sys/ufs/lfs

2017-06-15 Thread Maya Rashish
Module Name:src
Committed By:   maya
Date:   Thu Jun 15 14:37:31 UTC 2017

Modified Files:
src/sys/ufs/lfs: lfs_segment.c

Log Message:
It isn't safe to drain dirops with seglock held, it'll deadlock if there
are any dirops. drain before grabbing seglock.

lfs_dirops == 0 is always true (as we already drained dirops), so omit
that part of the comparison.

Fixes a lot of LFS deadlocks. PR kern/52301

Many thanks to dholland for help analyzing coredumps


To generate a diff of this commit:
cvs rdiff -u -r1.271 -r1.272 src/sys/ufs/lfs/lfs_segment.c

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

Modified files:

Index: src/sys/ufs/lfs/lfs_segment.c
diff -u src/sys/ufs/lfs/lfs_segment.c:1.271 src/sys/ufs/lfs/lfs_segment.c:1.272
--- src/sys/ufs/lfs/lfs_segment.c:1.271	Mon Jun 12 15:02:32 2017
+++ src/sys/ufs/lfs/lfs_segment.c	Thu Jun 15 14:37:30 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_segment.c,v 1.271 2017/06/12 15:02:32 maya Exp $	*/
+/*	$NetBSD: lfs_segment.c,v 1.272 2017/06/15 14:37:30 maya Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_segment.c,v 1.271 2017/06/12 15:02:32 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_segment.c,v 1.272 2017/06/15 14:37:30 maya Exp $");
 
 #ifdef DEBUG
 # define vndebug(vp, str) do {		\
@@ -603,7 +603,6 @@ lfs_segwrite(struct mount *mp, int flags
 	SEGUSE *segusep;
 	int do_ckp, did_ckp, error;
 	unsigned n, segleft, maxseg, sn, i, curseg;
-	int writer_set = 0;
 	int dirty;
 	int redo;
 	SEGSUM *ssp;
@@ -628,6 +627,8 @@ lfs_segwrite(struct mount *mp, int flags
 	if (do_ckp)
 		flags &= ~SEGM_SINGLE;
 
+	lfs_writer_enter(fs, "lfs segwrite");
+
 	lfs_seglock(fs, flags | (do_ckp ? SEGM_CKP : 0));
 	sp = fs->lfs_sp;
 	if (sp->seg_flags & (SEGM_CLEAN | SEGM_CKP))
@@ -653,11 +654,7 @@ lfs_segwrite(struct mount *mp, int flags
 break;
 			}
 
-			if (do_ckp || fs->lfs_dirops == 0) {
-if (!writer_set) {
-	lfs_writer_enter(fs, "lfs writer");
-	writer_set = 1;
-}
+			if (do_ckp) {
 error = lfs_writevnodes(fs, mp, sp, VN_DIROP);
 if (um_error == 0)
 	um_error = error;
@@ -806,8 +803,7 @@ lfs_segwrite(struct mount *mp, int flags
 
 	/* Note Ifile no longer needs to be written */
 	fs->lfs_doifile = 0;
-	if (writer_set)
-		lfs_writer_leave(fs);
+	lfs_writer_leave(fs);
 
 	/*
 	 * If we didn't write the Ifile, we didn't really do anything.



CVS commit: src/sys/ufs/lfs

2017-06-12 Thread Maya Rashish
Module Name:src
Committed By:   maya
Date:   Mon Jun 12 15:02:32 UTC 2017

Modified Files:
src/sys/ufs/lfs: lfs_segment.c

Log Message:
Use continue to denote the no-op loop to match netbsd style
newline for extra clarity.


To generate a diff of this commit:
cvs rdiff -u -r1.270 -r1.271 src/sys/ufs/lfs/lfs_segment.c

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

Modified files:

Index: src/sys/ufs/lfs/lfs_segment.c
diff -u src/sys/ufs/lfs/lfs_segment.c:1.270 src/sys/ufs/lfs/lfs_segment.c:1.271
--- src/sys/ufs/lfs/lfs_segment.c:1.270	Sat Jun 10 05:29:36 2017
+++ src/sys/ufs/lfs/lfs_segment.c	Mon Jun 12 15:02:32 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_segment.c,v 1.270 2017/06/10 05:29:36 maya Exp $	*/
+/*	$NetBSD: lfs_segment.c,v 1.271 2017/06/12 15:02:32 maya Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_segment.c,v 1.270 2017/06/10 05:29:36 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_segment.c,v 1.271 2017/06/12 15:02:32 maya Exp $");
 
 #ifdef DEBUG
 # define vndebug(vp, str) do {		\
@@ -1381,7 +1381,8 @@ loop:
 	for (bp = LIST_FIRST(>v_dirtyblkhd);
 	 bp && LIST_NEXT(bp, b_vnbufs) != NULL;
 	 bp = LIST_NEXT(bp, b_vnbufs))
-		/* nothing */;
+		continue;
+
 	for (; bp && bp != BEG_OF_LIST; bp = nbp) {
 		nbp = BACK_BUF(bp);
 #else /* LFS_NO_BACKBUF_HACK */



  1   2   3   4   5   6   7   8   >