CVS commit: src/sys/ufs/ufs

2012-02-12 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Mon Feb 13 06:23:41 UTC 2012

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

Log Message:
Fix another problem with quota cursor iteration. ok riz


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/ufs/ufs/ufs_quota2.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_quota2.c
diff -u src/sys/ufs/ufs/ufs_quota2.c:1.33 src/sys/ufs/ufs/ufs_quota2.c:1.34
--- src/sys/ufs/ufs/ufs_quota2.c:1.33	Sun Feb  5 14:19:04 2012
+++ src/sys/ufs/ufs/ufs_quota2.c	Mon Feb 13 06:23:41 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: ufs_quota2.c,v 1.33 2012/02/05 14:19:04 dholland Exp $ */
+/* $NetBSD: ufs_quota2.c,v 1.34 2012/02/13 06:23:41 dholland Exp $ */
 /*-
   * Copyright (c) 2010 Manuel Bouyer
   * All rights reserved.
@@ -26,7 +26,7 @@
   */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_quota2.c,v 1.33 2012/02/05 14:19:04 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_quota2.c,v 1.34 2012/02/13 06:23:41 dholland Exp $);
 
 #include sys/buf.h
 #include sys/param.h
@@ -957,6 +957,7 @@ struct q2cursor_getids {
 	unsigned skip;		/* number of ids to skip over */
 	unsigned new_skip;	/* number of ids to skip over next time */
 	unsigned skipped;	/* number skipped so far */
+	int stopped;		/* true if we stopped quota_walk_list early */
 };
 
 /*
@@ -1109,6 +1110,7 @@ q2cursor_getids_callback(struct ufsmount
 	gi-new_skip++;
 	if (gi-state-numids = gi-state-maxids) {
 		/* got enough ids, stop now */
+		gi-stopped = 1;
 		return Q2WL_ABORT;
 	}
 	return 0;
@@ -1175,11 +1177,16 @@ q2cursor_getkeys(struct ufsmount *ump, i
 		gi.skip = cursor-q2c_uidpos;
 		gi.new_skip = gi.skip;
 		gi.skipped = 0;
+		gi.stopped = 0;
 		offset = q2h-q2h_entries[cursor-q2c_hashpos];
 
 		error = quota2_walk_list(ump, hbp, idtype, offset, 0, gi,
 		q2cursor_getids_callback);
-		if (error == Q2WL_ABORT) {
+		KASSERT(error != Q2WL_ABORT);
+		if (error) {
+			break;
+		}
+		if (gi.stopped) {
 			/* callback stopped before reading whole chain */
 			cursor-q2c_uidpos = gi.new_skip;
 			/* if we didn't get both halves, back up */
@@ -1187,10 +1194,6 @@ q2cursor_getkeys(struct ufsmount *ump, i
 KASSERT(cursor-q2c_uidpos  0);
 cursor-q2c_uidpos--;
 			}
-			/* not an error */
-			error = 0;
-		} else if (error) {
-			break;
 		} else {
 			/* read whole chain */
 			/* if we got both halves of the last id, advance */



CVS commit: src/sys/ufs/ufs

2012-02-01 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Thu Feb  2 03:00:49 UTC 2012

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

Log Message:
Make this compile on vax (uninitialized use warning).


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 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.17 src/sys/ufs/ufs/ufs_quota1.c:1.18
--- src/sys/ufs/ufs/ufs_quota1.c:1.17	Wed Feb  1 05:43:54 2012
+++ src/sys/ufs/ufs/ufs_quota1.c	Thu Feb  2 03:00:48 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_quota1.c,v 1.17 2012/02/01 05:43:54 dholland Exp $	*/
+/*	$NetBSD: ufs_quota1.c,v 1.18 2012/02/02 03:00:48 matt Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993, 1995
@@ -35,7 +35,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_quota1.c,v 1.17 2012/02/01 05:43:54 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_quota1.c,v 1.18 2012/02/02 03:00:48 matt Exp $);
 
 #include sys/param.h
 #include sys/kernel.h
@@ -611,19 +611,17 @@ quota1_handle_cmd_put(struct ufsmount *u
 	dqb.dqb_curinodes = dq-dq_curinodes;
 	dqb.dqb_btime = dq-dq_btime;
 	dqb.dqb_itime = dq-dq_itime;
-	switch (key-qk_objtype) {
-	case QUOTA_OBJTYPE_BLOCKS:
+	if (key-qk_objtype == QUOTA_OBJTYPE_BLOCKS) {
 		dqb.dqb_bsoftlimit = quota1_encode_limit(val-qv_softlimit);
 		dqb.dqb_bhardlimit = quota1_encode_limit(val-qv_hardlimit);
 		dqb.dqb_isoftlimit = dq-dq_isoftlimit;
 		dqb.dqb_ihardlimit = dq-dq_ihardlimit;
-		break;
-	case QUOTA_OBJTYPE_FILES:
+	} else {
+		KASSERT(key-qk_objtype == QUOTA_OBJTYPE_FILES);
 		dqb.dqb_bsoftlimit = dq-dq_bsoftlimit;
 		dqb.dqb_bhardlimit = dq-dq_bhardlimit;
 		dqb.dqb_isoftlimit = quota1_encode_limit(val-qv_softlimit);
 		dqb.dqb_ihardlimit = quota1_encode_limit(val-qv_hardlimit);
-		break;
 	}
 	if (dq-dq_id == 0  val-qv_grace != QUOTA_NOTIME) {
 		/* also update grace time if available */



CVS commit: src/sys/ufs/ufs

2012-01-31 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Wed Feb  1 05:10:45 UTC 2012

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

Log Message:
Fix problems in cursor iteration that came to light when iterating one
value at a time, instead of in bulk. Yeah, repquota should do bulk get,
but it doesn't yet.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/ufs/ufs/ufs_quota2.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_quota2.c
diff -u src/sys/ufs/ufs/ufs_quota2.c:1.30 src/sys/ufs/ufs/ufs_quota2.c:1.31
--- src/sys/ufs/ufs/ufs_quota2.c:1.30	Sun Jan 29 07:21:00 2012
+++ src/sys/ufs/ufs/ufs_quota2.c	Wed Feb  1 05:10:44 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: ufs_quota2.c,v 1.30 2012/01/29 07:21:00 dholland Exp $ */
+/* $NetBSD: ufs_quota2.c,v 1.31 2012/02/01 05:10:44 dholland Exp $ */
 /*-
   * Copyright (c) 2010 Manuel Bouyer
   * All rights reserved.
@@ -26,7 +26,7 @@
   */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_quota2.c,v 1.30 2012/01/29 07:21:00 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_quota2.c,v 1.31 2012/02/01 05:10:44 dholland Exp $);
 
 #include sys/buf.h
 #include sys/param.h
@@ -1158,7 +1158,10 @@ q2cursor_getkeys(struct ufsmount *ump, i
 	/* If we haven't done the defaults yet, that goes first. */
 	if (cursor-q2c_defaults_done == 0) {
 		q2cursor_addid(state, idtype, QUOTA_DEFAULTID);
-		cursor-q2c_defaults_done = 1;
+		/* if we read both halves, mark it done */
+		if (state-numids  state-maxids || !state-skiplast) {
+			cursor-q2c_defaults_done = 1;
+		}
 	}
 
 	gi.state = state;
@@ -1181,14 +1184,22 @@ q2cursor_getkeys(struct ufsmount *ump, i
 		if (error == Q2WL_ABORT) {
 			/* callback stopped before reading whole chain */
 			cursor-q2c_uidpos = gi.new_skip;
+			/* if we didn't get both halves, back up */
+			if (state-numids == state-maxids  state-skiplast){
+KASSERT(cursor-q2c_uidpos  0);
+cursor-q2c_uidpos--;
+			}
 			/* not an error */
 			error = 0;
 		} else if (error) {
 			break;
 		} else {
-			/* read whole chain, advance to next */
-			cursor-q2c_uidpos = 0;
-			cursor-q2c_hashpos++;
+			/* read whole chain */
+			/* if we got both halves of the last id, advance */
+			if (state-numids  state-maxids || !state-skiplast){
+cursor-q2c_uidpos = 0;
+cursor-q2c_hashpos++;
+			}
 		}
 	}
 



CVS commit: src/sys/ufs/ufs

2012-01-29 Thread Izumi Tsutsui
Module Name:src
Committed By:   tsutsui
Date:   Sun Jan 29 08:49:02 UTC 2012

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

Log Message:
Fix errors in !defined(QUOTA)  !defined(QUOTA2) case.


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 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.48 src/sys/ufs/ufs/ufs_vfsops.c:1.49
--- src/sys/ufs/ufs/ufs_vfsops.c:1.48	Sun Jan 29 07:16:54 2012
+++ src/sys/ufs/ufs/ufs_vfsops.c	Sun Jan 29 08:49:01 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_vfsops.c,v 1.48 2012/01/29 07:16:54 dholland Exp $	*/
+/*	$NetBSD: ufs_vfsops.c,v 1.49 2012/01/29 08:49:01 tsutsui Exp $	*/
 
 /*
  * Copyright (c) 1991, 1993, 1994
@@ -37,7 +37,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_vfsops.c,v 1.48 2012/01/29 07:16:54 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_vfsops.c,v 1.49 2012/01/29 08:49:01 tsutsui Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -102,15 +102,13 @@ ufs_root(struct mount *mp, struct vnode 
 int
 ufs_quotactl(struct mount *mp, struct vfs_quotactl_args *args)
 {
-	struct lwp *l = curlwp;
 
 #if !defined(QUOTA)  !defined(QUOTA2)
 	(void) mp;
-	(void) cmddict;
-	(void) dummy;
-	(void) l;
+	(void) args;
 	return (EOPNOTSUPP);
 #else
+	struct lwp *l = curlwp;
 	int error;
 
 	/* Mark the mount busy, as we're passing it to kauth(9). */



CVS commit: src/sys/ufs/ufs

2012-01-29 Thread Lars Heidieker
Module Name:src
Committed By:   para
Date:   Sun Jan 29 11:59:14 UTC 2012

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

Log Message:
sprinkel some #ifdef QUOTA2 to avoid unused variables


To generate a diff of this commit:
cvs rdiff -u -r1.104 -r1.105 src/sys/ufs/ufs/ufs_quota.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_quota.c
diff -u src/sys/ufs/ufs/ufs_quota.c:1.104 src/sys/ufs/ufs/ufs_quota.c:1.105
--- src/sys/ufs/ufs/ufs_quota.c:1.104	Sun Jan 29 07:16:53 2012
+++ src/sys/ufs/ufs/ufs_quota.c	Sun Jan 29 11:59:14 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_quota.c,v 1.104 2012/01/29 07:16:53 dholland Exp $	*/
+/*	$NetBSD: ufs_quota.c,v 1.105 2012/01/29 11:59:14 para Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993, 1995
@@ -35,7 +35,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_quota.c,v 1.104 2012/01/29 07:16:53 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_quota.c,v 1.105 2012/01/29 11:59:14 para Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_quota.h
@@ -430,7 +430,9 @@ static int 
 quota_handle_cmd_cursoropen(struct mount *mp, struct lwp *l, 
 struct vfs_quotactl_args *args)
 {
+#ifdef QUOTA2
 	struct ufsmount *ump = VFSTOUFS(mp);
+#endif
 	struct quotakcursor *cursor;
 	int error;
 
@@ -456,7 +458,9 @@ static int 
 quota_handle_cmd_cursorclose(struct mount *mp, struct lwp *l, 
 struct vfs_quotactl_args *args)
 {
+#ifdef QUOTA2
 	struct ufsmount *ump = VFSTOUFS(mp);
+#endif
 	struct quotakcursor *cursor;
 	int error;
 
@@ -482,7 +486,9 @@ static int 
 quota_handle_cmd_cursorskipidtype(struct mount *mp, struct lwp *l, 
 struct vfs_quotactl_args *args)
 {
+#ifdef QUOTA2
 	struct ufsmount *ump = VFSTOUFS(mp);
+#endif
 	struct quotakcursor *cursor;
 	int idtype;
 	int error;
@@ -505,7 +511,9 @@ static int 
 quota_handle_cmd_cursoratend(struct mount *mp, struct lwp *l, 
 struct vfs_quotactl_args *args)
 {
+#ifdef QUOTA2
 	struct ufsmount *ump = VFSTOUFS(mp);
+#endif
 	struct quotakcursor *cursor;
 	int *ret;
 	int error;
@@ -528,7 +536,9 @@ static int 
 quota_handle_cmd_cursorrewind(struct mount *mp, struct lwp *l, 
 struct vfs_quotactl_args *args)
 {
+#ifdef QUOTA2
 	struct ufsmount *ump = VFSTOUFS(mp);
+#endif
 	struct quotakcursor *cursor;
 	int error;
 



CVS commit: src/sys/ufs/ufs

2012-01-28 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sun Jan 29 06:42:14 UTC 2012

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

Log Message:
Whitespace.


To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.79 src/sys/ufs/ufs/ufs_quota.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_quota.c
diff -u src/sys/ufs/ufs/ufs_quota.c:1.78 src/sys/ufs/ufs/ufs_quota.c:1.79
--- src/sys/ufs/ufs/ufs_quota.c:1.78	Sun Jan 29 06:41:41 2012
+++ src/sys/ufs/ufs/ufs_quota.c	Sun Jan 29 06:42:14 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_quota.c,v 1.78 2012/01/29 06:41:41 dholland Exp $	*/
+/*	$NetBSD: ufs_quota.c,v 1.79 2012/01/29 06:42:14 dholland Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993, 1995
@@ -35,7 +35,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_quota.c,v 1.78 2012/01/29 06:41:41 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_quota.c,v 1.79 2012/01/29 06:42:14 dholland Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_quota.h
@@ -242,25 +242,23 @@ quota_handle_cmd_get(struct mount *mp, s
 	if ((ump-um_flags  (UFS_QUOTA|UFS_QUOTA2)) == 0)
 		return EOPNOTSUPP;
 	
-	/* avoid whitespace diffs */ {
-		error = quota_get_auth(mp, l, qk-qk_id);
-		if (error != 0) 
-			return error;
+	error = quota_get_auth(mp, l, qk-qk_id);
+	if (error != 0) 
+		return error;
 #ifdef QUOTA
-		if (ump-um_flags  UFS_QUOTA) {
-			error = quota1_handle_cmd_get(ump, qk, ret);
-		} else
+	if (ump-um_flags  UFS_QUOTA) {
+		error = quota1_handle_cmd_get(ump, qk, ret);
+	} else
 #endif
 #ifdef QUOTA2
-		if (ump-um_flags  UFS_QUOTA2) {
-			error = quota2_handle_cmd_get(ump, qk, ret);
-		} else
+	if (ump-um_flags  UFS_QUOTA2) {
+		error = quota2_handle_cmd_get(ump, qk, ret);
+	} else
 #endif
-			panic(quota_handle_cmd_get: no support ?);
+		panic(quota_handle_cmd_get: no support ?);
 		
-		if (error != 0)
-			return error;
-	}
+	if (error != 0)
+		return error;
 
 	return error;
 }



CVS commit: src/sys/ufs/ufs

2012-01-28 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sun Jan 29 06:46:17 UTC 2012

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

Log Message:
For QUOTACTL_SET in quota1, use the quotaval data instead of proplib.


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 src/sys/ufs/ufs/ufs_quota.c
cvs rdiff -u -r1.5 -r1.6 src/sys/ufs/ufs/ufs_quota.h
cvs rdiff -u -r1.11 -r1.12 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_quota.c
diff -u src/sys/ufs/ufs/ufs_quota.c:1.80 src/sys/ufs/ufs/ufs_quota.c:1.81
--- src/sys/ufs/ufs/ufs_quota.c:1.80	Sun Jan 29 06:44:33 2012
+++ src/sys/ufs/ufs/ufs_quota.c	Sun Jan 29 06:46:16 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_quota.c,v 1.80 2012/01/29 06:44:33 dholland Exp $	*/
+/*	$NetBSD: ufs_quota.c,v 1.81 2012/01/29 06:46:16 dholland Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993, 1995
@@ -35,7 +35,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_quota.c,v 1.80 2012/01/29 06:44:33 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_quota.c,v 1.81 2012/01/29 06:46:16 dholland Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_quota.h
@@ -271,6 +271,8 @@ quota_handle_cmd_set(struct mount *mp, s
 	id_t id;
 	int defaultq;
 	int q2type;
+	const struct quotaval *blocks;
+	const struct quotaval *files;
 	prop_dictionary_t data;
 	int error;
 
@@ -278,6 +280,8 @@ quota_handle_cmd_set(struct mount *mp, s
 	id = args-u.set.qc_id;
 	defaultq = args-u.set.qc_defaultq;
 	q2type = args-u.set.qc_q2type;
+	blocks = args-u.set.qc_blocks;
+	files = args-u.set.qc_files;
 	data = args-u.set.qc_data;
 
 	KASSERT(prop_object_type(data) == PROP_TYPE_DICTIONARY);
@@ -294,7 +298,7 @@ quota_handle_cmd_set(struct mount *mp, s
 #ifdef QUOTA
 		if (ump-um_flags  UFS_QUOTA)
 			error = quota1_handle_cmd_set(ump, q2type, id, defaultq,
-			data);
+			blocks, files);
 		else
 #endif
 #ifdef QUOTA2

Index: src/sys/ufs/ufs/ufs_quota.h
diff -u src/sys/ufs/ufs/ufs_quota.h:1.5 src/sys/ufs/ufs/ufs_quota.h:1.6
--- src/sys/ufs/ufs/ufs_quota.h:1.5	Sun Jan 29 06:41:41 2012
+++ src/sys/ufs/ufs/ufs_quota.h	Sun Jan 29 06:46:16 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_quota.h,v 1.5 2012/01/29 06:41:41 dholland Exp $	*/
+/*	$NetBSD: ufs_quota.h,v 1.6 2012/01/29 06:46:16 dholland Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993, 1995
@@ -115,7 +115,8 @@ int dq1get(struct vnode *, u_long, struc
 int dq1sync(struct vnode *, struct dquot *);
 int quota1_handle_cmd_get(struct ufsmount *, const struct quotakey *,
 struct quotaval *);
-int quota1_handle_cmd_set(struct ufsmount *, int, int, int, prop_dictionary_t);
+int quota1_handle_cmd_set(struct ufsmount *, int, int, int,
+const struct quotaval *, const struct quotaval *);
 int quota1_handle_cmd_quotaon(struct lwp *, struct ufsmount *, int,
 const char *);
 int quota1_handle_cmd_quotaoff(struct lwp *, struct ufsmount *, int);

Index: src/sys/ufs/ufs/ufs_quota1.c
diff -u src/sys/ufs/ufs/ufs_quota1.c:1.11 src/sys/ufs/ufs/ufs_quota1.c:1.12
--- src/sys/ufs/ufs/ufs_quota1.c:1.11	Sun Jan 29 06:45:26 2012
+++ src/sys/ufs/ufs/ufs_quota1.c	Sun Jan 29 06:46:16 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_quota1.c,v 1.11 2012/01/29 06:45:26 dholland Exp $	*/
+/*	$NetBSD: ufs_quota1.c,v 1.12 2012/01/29 06:46:16 dholland Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993, 1995
@@ -35,7 +35,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_quota1.c,v 1.11 2012/01/29 06:45:26 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_quota1.c,v 1.12 2012/01/29 06:46:16 dholland Exp $);
 
 #include sys/param.h
 #include sys/kernel.h
@@ -543,25 +543,22 @@ quota1_handle_cmd_get(struct ufsmount *u
 	return 0;
 }
 
+static uint32_t
+quota1_encode_limit(uint64_t lim)
+{
+	if (lim == QUOTA_NOLIMIT || lim = 0x) {
+		return 0;
+	}
+	return lim;
+}
+
 int
 quota1_handle_cmd_set(struct ufsmount *ump, int type, int id,
-int defaultq, prop_dictionary_t data)
+int defaultq, const struct quotaval *blocks, const struct quotaval *files)
 {
 	struct dquot *dq;
 	struct dqblk dqb;
 	int error;
-	uint64_t bval[2];
-	uint64_t ival[2];
-	const char *val_limitsonly_grace[] = {QUOTADICT_LIMIT_GTIME};
-#define Q1_GTIME 0
-	const char *val_limitsonly_softhard[] =
-	{QUOTADICT_LIMIT_SOFT, QUOTADICT_LIMIT_HARD};
-#define Q1_SOFT 0
-#define Q1_HARD 1
-
-	uint64_t *valuesp[QUOTA_NLIMITS];
-	valuesp[QUOTA_LIMIT_BLOCK] = bval;
-	valuesp[QUOTA_LIMIT_FILE] = ival;
 
 	if (ump-um_quotas[type] == NULLVP)
 		return ENODEV;
@@ -569,28 +566,20 @@ quota1_handle_cmd_set(struct ufsmount *u
 	if (defaultq) {
 		/* just update grace times */
 		KASSERT(id == 0);
-		error = proptoquota64(data, valuesp, val_limitsonly_grace, 1,
-		ufs_quota_limit_names, QUOTA_NLIMITS);
-		if (error)
-			return error;
 		if ((error = dqget(NULLVP, id, ump, type, dq)) != 0)
 			return error;
 		

CVS commit: src/sys/ufs/ufs

2012-01-28 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sun Jan 29 06:46:50 UTC 2012

Modified Files:
src/sys/ufs/ufs: ufs_quota.c ufs_quota.h ufs_quota2.c

Log Message:
For QUOTACTL_SET in quota2, use the quotaval data instead of proplib.


To generate a diff of this commit:
cvs rdiff -u -r1.81 -r1.82 src/sys/ufs/ufs/ufs_quota.c
cvs rdiff -u -r1.6 -r1.7 src/sys/ufs/ufs/ufs_quota.h
cvs rdiff -u -r1.7 -r1.8 src/sys/ufs/ufs/ufs_quota2.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_quota.c
diff -u src/sys/ufs/ufs/ufs_quota.c:1.81 src/sys/ufs/ufs/ufs_quota.c:1.82
--- src/sys/ufs/ufs/ufs_quota.c:1.81	Sun Jan 29 06:46:16 2012
+++ src/sys/ufs/ufs/ufs_quota.c	Sun Jan 29 06:46:49 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_quota.c,v 1.81 2012/01/29 06:46:16 dholland Exp $	*/
+/*	$NetBSD: ufs_quota.c,v 1.82 2012/01/29 06:46:49 dholland Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993, 1995
@@ -35,7 +35,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_quota.c,v 1.81 2012/01/29 06:46:16 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_quota.c,v 1.82 2012/01/29 06:46:49 dholland Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_quota.h
@@ -304,7 +304,7 @@ quota_handle_cmd_set(struct mount *mp, s
 #ifdef QUOTA2
 		if (ump-um_flags  UFS_QUOTA2) {
 			error = quota2_handle_cmd_set(ump, q2type, id, defaultq,
-			data);
+			blocks, files);
 		} else
 #endif
 			panic(quota_handle_cmd_get: no support ?);

Index: src/sys/ufs/ufs/ufs_quota.h
diff -u src/sys/ufs/ufs/ufs_quota.h:1.6 src/sys/ufs/ufs/ufs_quota.h:1.7
--- src/sys/ufs/ufs/ufs_quota.h:1.6	Sun Jan 29 06:46:16 2012
+++ src/sys/ufs/ufs/ufs_quota.h	Sun Jan 29 06:46:50 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_quota.h,v 1.6 2012/01/29 06:46:16 dholland Exp $	*/
+/*	$NetBSD: ufs_quota.h,v 1.7 2012/01/29 06:46:50 dholland Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993, 1995
@@ -125,7 +125,8 @@ int chkdq2(struct inode *, int64_t, kaut
 int chkiq2(struct inode *, int32_t, kauth_cred_t, int);
 int quota2_handle_cmd_get(struct ufsmount *, const struct quotakey *,
 struct quotaval *);
-int quota2_handle_cmd_set(struct ufsmount *, int, int, int, prop_dictionary_t);
+int quota2_handle_cmd_set(struct ufsmount *, int, int, int,
+const struct quotaval *, const struct quotaval *);
 int quota2_handle_cmd_clear(struct ufsmount *, int, int, int, prop_dictionary_t);
 int quota2_handle_cmd_getall(struct ufsmount *, int, prop_array_t);
 int q2sync(struct mount *);

Index: src/sys/ufs/ufs/ufs_quota2.c
diff -u src/sys/ufs/ufs/ufs_quota2.c:1.7 src/sys/ufs/ufs/ufs_quota2.c:1.8
--- src/sys/ufs/ufs/ufs_quota2.c:1.7	Sun Jan 29 06:41:42 2012
+++ src/sys/ufs/ufs/ufs_quota2.c	Sun Jan 29 06:46:50 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: ufs_quota2.c,v 1.7 2012/01/29 06:41:42 dholland Exp $ */
+/* $NetBSD: ufs_quota2.c,v 1.8 2012/01/29 06:46:50 dholland Exp $ */
 /*-
   * Copyright (c) 2010 Manuel Bouyer
   * All rights reserved.
@@ -26,7 +26,7 @@
   */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_quota2.c,v 1.7 2012/01/29 06:41:42 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_quota2.c,v 1.8 2012/01/29 06:46:50 dholland Exp $);
 
 #include sys/buf.h
 #include sys/param.h
@@ -74,32 +74,24 @@ static int quota2_walk_list(struct ufsmo
 int (*func)(struct ufsmount *, uint64_t *, struct quota2_entry *,
   uint64_t, void *));
 
-static int quota2_dict_update_q2e_limits(prop_dictionary_t,
-struct quota2_entry *);
 static prop_dictionary_t q2etoprop(struct quota2_entry *, int);
 
 static const char *limnames[] = INITQLNAMES;
 
-static int
-quota2_dict_update_q2e_limits(prop_dictionary_t data,
+static void
+quota2_dict_update_q2e_limits(const struct quotaval *blocks,
+const struct quotaval *files,
 struct quota2_entry *q2e)
 {
-	const char *val_limitsonly_names[] = INITQVNAMES_LIMITSONLY;
-
-	int i, error;
-	prop_dictionary_t val;
-
-	for (i = 0; i  N_QL; i++) {
-		if (!prop_dictionary_get_dict(data, limnames[i], val))
-			return EINVAL;
-		error = quotaprop_dict_get_uint64(val,
-		q2e-q2e_val[i].q2v_hardlimit,
-		val_limitsonly_names, N_QV, true);
-		if (error)
-			return error;
-	}
-	return 0;
+	q2e-q2e_val[QL_BLOCK].q2v_hardlimit = blocks-qv_hardlimit;
+	q2e-q2e_val[QL_BLOCK].q2v_softlimit = blocks-qv_softlimit;
+	q2e-q2e_val[QL_BLOCK].q2v_grace = blocks-qv_grace;
+
+	q2e-q2e_val[QL_FILE].q2v_hardlimit = blocks-qv_hardlimit;
+	q2e-q2e_val[QL_FILE].q2v_softlimit = blocks-qv_softlimit;
+	q2e-q2e_val[QL_FILE].q2v_grace = blocks-qv_grace;
 }
+
 static prop_dictionary_t
 q2etoprop(struct quota2_entry *q2e, int def)
 {
@@ -621,7 +613,7 @@ chkiq2(struct inode *ip, int32_t change,
 
 int
 quota2_handle_cmd_set(struct ufsmount *ump, int type, int id,
-int defaultq, prop_dictionary_t data)
+int defaultq, const struct quotaval *blocks, const struct quotaval *files)
 {
 	int error;
 	struct dquot *dq;
@@ -644,12 

CVS commit: src/sys/ufs/ufs

2012-01-28 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sun Jan 29 06:50:15 UTC 2012

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

Log Message:
Whitespace.


To generate a diff of this commit:
cvs rdiff -u -r1.85 -r1.86 src/sys/ufs/ufs/ufs_quota.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_quota.c
diff -u src/sys/ufs/ufs/ufs_quota.c:1.85 src/sys/ufs/ufs/ufs_quota.c:1.86
--- src/sys/ufs/ufs/ufs_quota.c:1.85	Sun Jan 29 06:49:43 2012
+++ src/sys/ufs/ufs/ufs_quota.c	Sun Jan 29 06:50:15 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_quota.c,v 1.85 2012/01/29 06:49:43 dholland Exp $	*/
+/*	$NetBSD: ufs_quota.c,v 1.86 2012/01/29 06:50:15 dholland Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993, 1995
@@ -35,7 +35,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_quota.c,v 1.85 2012/01/29 06:49:43 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_quota.c,v 1.86 2012/01/29 06:50:15 dholland Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_quota.h
@@ -285,28 +285,25 @@ quota_handle_cmd_put(struct mount *mp, s
 		kauth_id = 0;
 	}
 
-	/* avoid whitespace changes */
-	{
-		error = kauth_authorize_system(l-l_cred, KAUTH_SYSTEM_FS_QUOTA,
-		KAUTH_REQ_SYSTEM_FS_QUOTA_MANAGE, mp, KAUTH_ARG(kauth_id),
-		NULL);
-		if (error != 0)
-			goto err;
+	error = kauth_authorize_system(l-l_cred, KAUTH_SYSTEM_FS_QUOTA,
+	KAUTH_REQ_SYSTEM_FS_QUOTA_MANAGE, mp, KAUTH_ARG(kauth_id),
+	NULL);
+	if (error != 0)
+		goto err;
 #ifdef QUOTA
-		if (ump-um_flags  UFS_QUOTA)
-			error = quota1_handle_cmd_put(ump, qk, qv);
-		else
+	if (ump-um_flags  UFS_QUOTA)
+		error = quota1_handle_cmd_put(ump, qk, qv);
+	else
 #endif
 #ifdef QUOTA2
-		if (ump-um_flags  UFS_QUOTA2) {
-			error = quota2_handle_cmd_put(ump, qk, qv);
-		} else
+	if (ump-um_flags  UFS_QUOTA2) {
+		error = quota2_handle_cmd_put(ump, qk, qv);
+	} else
 #endif
-			panic(quota_handle_cmd_get: no support ?);
+		panic(quota_handle_cmd_get: no support ?);
 		
-		if (error  error != ENOENT)
-			goto err;
-	}
+	if (error  error != ENOENT)
+		goto err;
 
 	return 0;
  err:



CVS commit: src/sys/ufs/ufs

2012-01-28 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sun Jan 29 07:03:47 UTC 2012

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

Log Message:
Teach quota2 QUOTACTL_GETALL to start in the middle, step 1.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/ufs/ufs/ufs_quota2.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_quota2.c
diff -u src/sys/ufs/ufs/ufs_quota2.c:1.18 src/sys/ufs/ufs/ufs_quota2.c:1.19
--- src/sys/ufs/ufs/ufs_quota2.c:1.18	Sun Jan 29 07:02:06 2012
+++ src/sys/ufs/ufs/ufs_quota2.c	Sun Jan 29 07:03:47 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: ufs_quota2.c,v 1.18 2012/01/29 07:02:06 dholland Exp $ */
+/* $NetBSD: ufs_quota2.c,v 1.19 2012/01/29 07:03:47 dholland Exp $ */
 /*-
   * Copyright (c) 2010 Manuel Bouyer
   * All rights reserved.
@@ -26,7 +26,7 @@
   */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_quota2.c,v 1.18 2012/01/29 07:02:06 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_quota2.c,v 1.19 2012/01/29 07:03:47 dholland Exp $);
 
 #include sys/buf.h
 #include sys/param.h
@@ -956,7 +956,12 @@ quota2_handle_cmd_get(struct ufsmount *u
 }
 
 struct ufsq2_cursor {
-	uint32_t q2c_magic;
+	uint32_t q2c_magic;	/* magic number */
+	int q2c_hashsize;	/* size of hash table at last go */
+
+	int q2c_defaults_done;	/* true if we've returned the default values */
+	int q2c_hashpos;	/* slot to start at in hash table */
+	int q2c_blocks_done;	/* true if we've returned the blocks value */
 };
 
 #define Q2C_MAGIC (0xbeebe111)
@@ -1010,6 +1015,7 @@ quota2_handle_cmd_getall(struct ufsmount
 	const int needswap = UFS_MPNEEDSWAP(ump);
 	struct getuids gu;
 	id_t junkid;
+	struct quotaval qv;
 	unsigned num, maxnum;
 
 	cursor = Q2CURSOR(qkc);
@@ -1026,9 +1032,21 @@ quota2_handle_cmd_getall(struct ufsmount
 		mutex_exit(dqlock);
 		return error;
 	}
-	quota2_ufs_rwq2e(q2h-q2h_defentry, q2e, needswap);
-	q2e_to_quotaval(q2e, 1, junkid, QL_BLOCK, result-qr_defblocks);
-	q2e_to_quotaval(q2e, 1, junkid, QL_FILE, result-qr_deffiles);
+
+	if (cursor-q2c_defaults_done == 0) {
+		quota2_ufs_rwq2e(q2h-q2h_defentry, q2e, needswap);
+		if (cursor-q2c_blocks_done == 0) {
+			q2e_to_quotaval(q2e, 1, junkid, QL_BLOCK, qv);
+			result-qr_defblocks = qv;
+			cursor-q2c_blocks_done = 1;
+		}
+		if (cursor-q2c_blocks_done == 1) {
+			q2e_to_quotaval(q2e, 1, junkid, QL_FILE, qv);
+			result-qr_deffiles = qv;
+			cursor-q2c_blocks_done = 0;
+			cursor-q2c_defaults_done = 1;
+		}
+	}
 
 	/*
 	 * we can't directly get entries as we can't walk the list
@@ -1038,7 +1056,22 @@ quota2_handle_cmd_getall(struct ufsmount
 	 */
 	memset(gu, 0, sizeof(gu));
 	quota2_hash_size = ufs_rw16(q2h-q2h_hash_size, needswap);
-	for (i = 0; i  quota2_hash_size ; i++) {
+
+	/* if the table size has changed, make the caller start over */
+	if (cursor-q2c_hashsize == 0) {
+		cursor-q2c_hashsize = quota2_hash_size;
+	} else if (cursor-q2c_hashsize != quota2_hash_size) {
+		error = EDEADLK;
+		goto fail;
+	}
+
+	/* why are these variables signed? */
+	if (cursor-q2c_hashpos  0) {
+		error = EINVAL;
+		goto fail;
+	}
+
+	for (i = cursor-q2c_hashpos; i  quota2_hash_size ; i++) {
 		offset = q2h-q2h_entries[i];
 		error = quota2_walk_list(ump, hbp, idtype, offset, 0, gu,
 		quota2_getuids_callback);
@@ -1048,7 +1081,9 @@ quota2_handle_cmd_getall(struct ufsmount
 			break;
 		}
 	}
+	cursor-q2c_hashpos = i;
 
+fail:
 	mutex_exit(dqlock);
 	brelse(hbp, 0);
 	if (error)
@@ -1085,6 +1120,10 @@ quota2_handle_cmd_cursoropen(struct ufsm
 	cursor = Q2CURSOR(qkc);
 
 	cursor-q2c_magic = Q2C_MAGIC;
+	cursor-q2c_hashsize = 0;
+	cursor-q2c_hashpos = 0;
+	cursor-q2c_defaults_done = 0;
+	cursor-q2c_blocks_done = 0;
 	return 0;
 }
 
@@ -1098,6 +1137,8 @@ quota2_handle_cmd_cursorclose(struct ufs
 		return EINVAL;
 	}
 
+	/* nothing to do */
+
 	return 0;
 }
 



CVS commit: src/sys/ufs/ufs

2012-01-28 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sun Jan 29 07:04:22 UTC 2012

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

Log Message:
Teach quota2 QUOTACTL_GETALL to start in the middle, step 2.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/ufs/ufs/ufs_quota2.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_quota2.c
diff -u src/sys/ufs/ufs/ufs_quota2.c:1.19 src/sys/ufs/ufs/ufs_quota2.c:1.20
--- src/sys/ufs/ufs/ufs_quota2.c:1.19	Sun Jan 29 07:03:47 2012
+++ src/sys/ufs/ufs/ufs_quota2.c	Sun Jan 29 07:04:21 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: ufs_quota2.c,v 1.19 2012/01/29 07:03:47 dholland Exp $ */
+/* $NetBSD: ufs_quota2.c,v 1.20 2012/01/29 07:04:21 dholland Exp $ */
 /*-
   * Copyright (c) 2010 Manuel Bouyer
   * All rights reserved.
@@ -26,7 +26,7 @@
   */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_quota2.c,v 1.19 2012/01/29 07:03:47 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_quota2.c,v 1.20 2012/01/29 07:04:21 dholland Exp $);
 
 #include sys/buf.h
 #include sys/param.h
@@ -961,6 +961,7 @@ struct ufsq2_cursor {
 
 	int q2c_defaults_done;	/* true if we've returned the default values */
 	int q2c_hashpos;	/* slot to start at in hash table */
+	int q2c_uidpos;		/* number of ids we've handled */
 	int q2c_blocks_done;	/* true if we've returned the blocks value */
 };
 
@@ -968,11 +969,34 @@ struct ufsq2_cursor {
 
 #define Q2CURSOR(qkc) ((struct ufsq2_cursor *)qkc-u.qkc_space[0])
 
+static int
+q2cursor_check(struct ufsq2_cursor *cursor)
+{
+	if (cursor-q2c_magic != Q2C_MAGIC) {
+		return EINVAL;
+	}
+	if (cursor-q2c_hashsize  0) {
+		return EINVAL;
+	}
+
+	if (cursor-q2c_defaults_done != 0  cursor-q2c_defaults_done != 1) {
+		return EINVAL;
+	}
+	if (cursor-q2c_hashpos  0 || cursor-q2c_uidpos  0) {
+		return EINVAL;
+	}
+	if (cursor-q2c_blocks_done != 0  cursor-q2c_blocks_done != 1) {
+		return EINVAL;
+	}
+	return 0;
+}
 
 struct getuids {
 	long nuids; /* number of uids in array */
 	long size;  /* size of array */
 	uid_t *uids; /* array of uids, dynamically allocated */
+	long skip;
+	long seen;
 };
 
 static int
@@ -985,6 +1009,10 @@ quota2_getuids_callback(struct ufsmount 
 	const int needswap = UFS_MPNEEDSWAP(ump);
 #endif
 
+	if (gu-skip  0) {
+		gu-skip--;
+		return 0;
+	}
 	if (gu-nuids == gu-size) {
 		newuids = realloc(gu-uids, gu-size + PAGE_SIZE, M_TEMP,
 		M_WAITOK);
@@ -997,6 +1025,7 @@ quota2_getuids_callback(struct ufsmount 
 	}
 	gu-uids[gu-nuids] = ufs_rw32(q2ep-q2e_uid, needswap);
 	gu-nuids++;
+	gu-seen++;
 	return 0;
 }
 
@@ -1019,12 +1048,14 @@ quota2_handle_cmd_getall(struct ufsmount
 	unsigned num, maxnum;
 
 	cursor = Q2CURSOR(qkc);
-	if (cursor-q2c_magic != Q2C_MAGIC) {
-		return EINVAL;
+	error = q2cursor_check(cursor);
+	if (error) {
+		return error;
 	}
 
-	if (ump-um_quotas[idtype] == NULLVP)
+	if (ump-um_quotas[idtype] == NULLVP) {
 		return ENODEV;
+	}
 
 	mutex_enter(dqlock);
 	error = getq2h(ump, idtype, hbp, q2h, 0);
@@ -1065,14 +1096,11 @@ quota2_handle_cmd_getall(struct ufsmount
 		goto fail;
 	}
 
-	/* why are these variables signed? */
-	if (cursor-q2c_hashpos  0) {
-		error = EINVAL;
-		goto fail;
-	}
-
+	gu.skip = cursor-q2c_uidpos;
+	gu.seen = 0;
 	for (i = cursor-q2c_hashpos; i  quota2_hash_size ; i++) {
 		offset = q2h-q2h_entries[i];
+		gu.seen = 0;
 		error = quota2_walk_list(ump, hbp, idtype, offset, 0, gu,
 		quota2_getuids_callback);
 		if (error) {
@@ -1082,6 +1110,7 @@ quota2_handle_cmd_getall(struct ufsmount
 		}
 	}
 	cursor-q2c_hashpos = i;
+	cursor-q2c_uidpos = gu.seen;
 
 fail:
 	mutex_exit(dqlock);
@@ -1121,8 +1150,10 @@ quota2_handle_cmd_cursoropen(struct ufsm
 
 	cursor-q2c_magic = Q2C_MAGIC;
 	cursor-q2c_hashsize = 0;
-	cursor-q2c_hashpos = 0;
+
 	cursor-q2c_defaults_done = 0;
+	cursor-q2c_hashpos = 0;
+	cursor-q2c_uidpos = 0;
 	cursor-q2c_blocks_done = 0;
 	return 0;
 }
@@ -1131,10 +1162,12 @@ int
 quota2_handle_cmd_cursorclose(struct ufsmount *ump, struct quotakcursor *qkc)
 {
 	struct ufsq2_cursor *cursor;
+	int error;
 
 	cursor = Q2CURSOR(qkc);
-	if (cursor-q2c_magic != Q2C_MAGIC) {
-		return EINVAL;
+	error = q2cursor_check(cursor);
+	if (error) {
+		return error;
 	}
 
 	/* nothing to do */



CVS commit: src/sys/ufs/ufs

2012-01-28 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sun Jan 29 07:08:00 UTC 2012

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

Log Message:
Fix a preexisting array overrun and a preexisting free twice exposed
by cleanup and testing.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/ufs/ufs/ufs_quota2.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_quota2.c
diff -u src/sys/ufs/ufs/ufs_quota2.c:1.23 src/sys/ufs/ufs/ufs_quota2.c:1.24
--- src/sys/ufs/ufs/ufs_quota2.c:1.23	Sun Jan 29 07:07:22 2012
+++ src/sys/ufs/ufs/ufs_quota2.c	Sun Jan 29 07:08:00 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: ufs_quota2.c,v 1.23 2012/01/29 07:07:22 dholland Exp $ */
+/* $NetBSD: ufs_quota2.c,v 1.24 2012/01/29 07:08:00 dholland Exp $ */
 /*-
   * Copyright (c) 2010 Manuel Bouyer
   * All rights reserved.
@@ -26,7 +26,7 @@
   */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_quota2.c,v 1.23 2012/01/29 07:07:22 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_quota2.c,v 1.24 2012/01/29 07:08:00 dholland Exp $);
 
 #include sys/buf.h
 #include sys/param.h
@@ -1000,7 +1000,7 @@ q2cursor_check(struct ufsq2_cursor *curs
 
 struct getuids {
 	long nuids; /* number of uids in array */
-	long size;  /* size of array */
+	long maxuids;  /* number of uids allocated */
 	uid_t *uids; /* array of uids, dynamically allocated */
 	long skip;
 	long seen;
@@ -1013,6 +1013,7 @@ quota2_getuids_callback(struct ufsmount 
 {
 	struct getuids *gu = v;
 	uid_t *newuids;
+	long newmax;
 #ifdef FFS_EI
 	const int needswap = UFS_MPNEEDSWAP(ump);
 #endif
@@ -1021,15 +1022,15 @@ quota2_getuids_callback(struct ufsmount 
 		gu-skip--;
 		return 0;
 	}
-	if (gu-nuids == gu-size) {
-		newuids = realloc(gu-uids, gu-size + PAGE_SIZE, M_TEMP,
-		M_WAITOK);
+	if (gu-nuids == gu-maxuids) {
+		newmax = gu-maxuids + PAGE_SIZE / sizeof(uid_t);
+		newuids = realloc(gu-uids, newmax * sizeof(gu-uids[0]),
+		M_TEMP, M_WAITOK);
 		if (newuids == NULL) {
-			free(gu-uids, M_TEMP);
 			return ENOMEM;
 		}
 		gu-uids = newuids;
-		gu-size += (PAGE_SIZE / sizeof(uid_t));
+		gu-maxuids = newmax;
 	}
 	gu-uids[gu-nuids] = ufs_rw32(q2ep-q2e_uid, needswap);
 	gu-nuids++;



CVS commit: src/sys/ufs/ufs

2012-01-28 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sun Jan 29 07:16:54 UTC 2012

Modified Files:
src/sys/ufs/ufs: quota2.h ufs_quota.c ufs_quota1.c ufs_quota2.c
ufs_vfsops.c

Log Message:
Remove references to quota/quotaprop.h in src/sys/ufs.
The remaining references in the kernel are in vfs_quotactl.c, the
compat_50 code for the old quotactl (to be fixed up), and the
code compiled from src/common/lib/libquota.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/ufs/ufs/quota2.h
cvs rdiff -u -r1.103 -r1.104 src/sys/ufs/ufs/ufs_quota.c
cvs rdiff -u -r1.15 -r1.16 src/sys/ufs/ufs/ufs_quota1.c
cvs rdiff -u -r1.26 -r1.27 src/sys/ufs/ufs/ufs_quota2.c
cvs rdiff -u -r1.47 -r1.48 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/quota2.h
diff -u src/sys/ufs/ufs/quota2.h:1.5 src/sys/ufs/ufs/quota2.h:1.6
--- src/sys/ufs/ufs/quota2.h:1.5	Tue Jun  7 14:56:13 2011
+++ src/sys/ufs/ufs/quota2.h	Sun Jan 29 07:16:53 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: quota2.h,v 1.5 2011/06/07 14:56:13 bouyer Exp $ */
+/* $NetBSD: quota2.h,v 1.6 2012/01/29 07:16:53 dholland Exp $ */
 /*-
   * Copyright (c) 2010 Manuel Bouyer
   * All rights reserved.
@@ -81,7 +81,10 @@ struct quota2_val {
 #define N_QL 2
 #define QL_BLOCK 0
 #define QL_FILE 1
-#define INITQLNAMES {QUOTADICT_LTYPE_BLOCK, QUOTADICT_LTYPE_FILE}
+#define INITQLNAMES { \
+	[QL_BLOCK] = block,	\
+	[QL_FILE] =  file,	\
+}
 
 struct quota2_entry {
 	/* block  inode limits and status */

Index: src/sys/ufs/ufs/ufs_quota.c
diff -u src/sys/ufs/ufs/ufs_quota.c:1.103 src/sys/ufs/ufs/ufs_quota.c:1.104
--- src/sys/ufs/ufs/ufs_quota.c:1.103	Sun Jan 29 07:14:38 2012
+++ src/sys/ufs/ufs/ufs_quota.c	Sun Jan 29 07:16:53 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_quota.c,v 1.103 2012/01/29 07:14:38 dholland Exp $	*/
+/*	$NetBSD: ufs_quota.c,v 1.104 2012/01/29 07:16:53 dholland Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993, 1995
@@ -35,7 +35,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_quota.c,v 1.103 2012/01/29 07:14:38 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_quota.c,v 1.104 2012/01/29 07:16:53 dholland Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_quota.h
@@ -56,7 +56,6 @@ __KERNEL_RCSID(0, $NetBSD: ufs_quota.c,
 #include ufs/ufs/ufsmount.h
 #include ufs/ufs/ufs_extern.h
 #include ufs/ufs/ufs_quota.h
-#include quota/quotaprop.h
 
 kmutex_t dqlock;
 kcondvar_t dqcv;

Index: src/sys/ufs/ufs/ufs_quota1.c
diff -u src/sys/ufs/ufs/ufs_quota1.c:1.15 src/sys/ufs/ufs/ufs_quota1.c:1.16
--- src/sys/ufs/ufs/ufs_quota1.c:1.15	Sun Jan 29 06:49:44 2012
+++ src/sys/ufs/ufs/ufs_quota1.c	Sun Jan 29 07:16:53 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_quota1.c,v 1.15 2012/01/29 06:49:44 dholland Exp $	*/
+/*	$NetBSD: ufs_quota1.c,v 1.16 2012/01/29 07:16:53 dholland Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993, 1995
@@ -35,7 +35,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_quota1.c,v 1.15 2012/01/29 06:49:44 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_quota1.c,v 1.16 2012/01/29 07:16:53 dholland Exp $);
 
 #include sys/param.h
 #include sys/kernel.h
@@ -47,7 +47,6 @@ __KERNEL_RCSID(0, $NetBSD: ufs_quota1.c
 #include sys/mount.h
 #include sys/kauth.h
 
-#include quota/quotaprop.h
 #include ufs/ufs/quota1.h
 #include ufs/ufs/inode.h
 #include ufs/ufs/ufsmount.h

Index: src/sys/ufs/ufs/ufs_quota2.c
diff -u src/sys/ufs/ufs/ufs_quota2.c:1.26 src/sys/ufs/ufs/ufs_quota2.c:1.27
--- src/sys/ufs/ufs/ufs_quota2.c:1.26	Sun Jan 29 07:09:52 2012
+++ src/sys/ufs/ufs/ufs_quota2.c	Sun Jan 29 07:16:54 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: ufs_quota2.c,v 1.26 2012/01/29 07:09:52 dholland Exp $ */
+/* $NetBSD: ufs_quota2.c,v 1.27 2012/01/29 07:16:54 dholland Exp $ */
 /*-
   * Copyright (c) 2010 Manuel Bouyer
   * All rights reserved.
@@ -26,7 +26,7 @@
   */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_quota2.c,v 1.26 2012/01/29 07:09:52 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_quota2.c,v 1.27 2012/01/29 07:16:54 dholland Exp $);
 
 #include sys/buf.h
 #include sys/param.h
@@ -51,7 +51,6 @@ __KERNEL_RCSID(0, $NetBSD: ufs_quota2.c
 #include ufs/ufs/ufs_extern.h
 #include ufs/ufs/ufs_quota.h
 #include ufs/ufs/ufs_wapbl.h
-#include quota/quotaprop.h
 
 /*
  * LOCKING:

Index: src/sys/ufs/ufs/ufs_vfsops.c
diff -u src/sys/ufs/ufs/ufs_vfsops.c:1.47 src/sys/ufs/ufs/ufs_vfsops.c:1.48
--- src/sys/ufs/ufs/ufs_vfsops.c:1.47	Sun Jan 29 07:14:39 2012
+++ src/sys/ufs/ufs/ufs_vfsops.c	Sun Jan 29 07:16:54 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_vfsops.c,v 1.47 2012/01/29 07:14:39 dholland Exp $	*/
+/*	$NetBSD: ufs_vfsops.c,v 1.48 2012/01/29 07:16:54 dholland Exp $	*/
 
 /*
  * Copyright (c) 1991, 1993, 1994
@@ -37,7 +37,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_vfsops.c,v 1.47 2012/01/29 07:14:39 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_vfsops.c,v 1.48 

CVS commit: src/sys/ufs/ufs

2012-01-28 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sun Jan 29 07:17:41 UTC 2012

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

Log Message:
Remove now-unused declarations from quota2.h.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 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.6 src/sys/ufs/ufs/quota2.h:1.7
--- src/sys/ufs/ufs/quota2.h:1.6	Sun Jan 29 07:16:53 2012
+++ src/sys/ufs/ufs/quota2.h	Sun Jan 29 07:17:41 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: quota2.h,v 1.6 2012/01/29 07:16:53 dholland Exp $ */
+/* $NetBSD: quota2.h,v 1.7 2012/01/29 07:17:41 dholland Exp $ */
 /*-
   * Copyright (c) 2010 Manuel Bouyer
   * All rights reserved.
@@ -55,23 +55,6 @@ struct quota2_val {
 	int64_t q2v_grace; /* allowed time for softlimit overflow */
 };
 
-/* NAMES for the above in the plist */
-#define INITQVNAMES_ALL { \
-QUOTADICT_LIMIT_HARD, \
-QUOTADICT_LIMIT_SOFT, \
-QUOTADICT_LIMIT_USAGE, \
-QUOTADICT_LIMIT_ETIME, \
-QUOTADICT_LIMIT_GTIME \
-}
-#define INITQVNAMES_LIMITSONLY { \
-QUOTADICT_LIMIT_HARD, \
-QUOTADICT_LIMIT_SOFT, \
-NULL, \
-NULL, \
-QUOTADICT_LIMIT_GTIME \
-}
-
-#define N_QV 5
 /*
  * On-disk description of a user or group quota
  * These entries are keept as linked list, either in one of the hash HEAD,



CVS commit: src/sys/ufs/ufs

2012-01-28 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sun Jan 29 07:18:17 UTC 2012

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

Log Message:
Remove #if 0'd proplib-related code.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/ufs/ufs/ufs_quota2.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_quota2.c
diff -u src/sys/ufs/ufs/ufs_quota2.c:1.27 src/sys/ufs/ufs/ufs_quota2.c:1.28
--- src/sys/ufs/ufs/ufs_quota2.c:1.27	Sun Jan 29 07:16:54 2012
+++ src/sys/ufs/ufs/ufs_quota2.c	Sun Jan 29 07:18:17 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: ufs_quota2.c,v 1.27 2012/01/29 07:16:54 dholland Exp $ */
+/* $NetBSD: ufs_quota2.c,v 1.28 2012/01/29 07:18:17 dholland Exp $ */
 /*-
   * Copyright (c) 2010 Manuel Bouyer
   * All rights reserved.
@@ -26,7 +26,7 @@
   */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_quota2.c,v 1.27 2012/01/29 07:16:54 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_quota2.c,v 1.28 2012/01/29 07:18:17 dholland Exp $);
 
 #include sys/buf.h
 #include sys/param.h
@@ -74,10 +74,6 @@ static int quota2_walk_list(struct ufsmo
 int (*func)(struct ufsmount *, uint64_t *, struct quota2_entry *,
   uint64_t, void *));
 
-#if 0
-static prop_dictionary_t q2etoprop(struct quota2_entry *, int);
-#endif
-
 static const char *limnames[] = INITQLNAMES;
 
 static void
@@ -93,44 +89,6 @@ quota2_dict_update_q2e_limits(int objtyp
 	q2e-q2e_val[objtype].q2v_grace = val-qv_grace;
 }
 
-#if 0
-static prop_dictionary_t
-q2etoprop(struct quota2_entry *q2e, int def)
-{
-	const char *val_names[] = INITQVNAMES_ALL;
-	prop_dictionary_t dict1 = prop_dictionary_create();
-	prop_dictionary_t dict2;
-	int i;
-
-	if (dict1 == NULL)
-		return NULL;
-
-	if (def) {
-		if (!prop_dictionary_set_cstring_nocopy(dict1, id,
-		default)) {
-			goto err;
-		}
-	} else {
-		if (!prop_dictionary_set_uint32(dict1, id, q2e-q2e_uid)) {
-			goto err;
-		}
-	}
-	for (i = 0; i  N_QL; i++) {
-		dict2 = limits64toprop(q2e-q2e_val[i].q2v_hardlimit,
-		val_names, N_QV);
-		if (dict2 == NULL)
-			goto err;
-		if (!prop_dictionary_set_and_rel(dict1, limnames[i], dict2))
-			goto err;
-	}
-	return dict1;
-
-err:
-	prop_object_release(dict1);
-	return NULL;
-}
-#endif
-
 /*
  * Convert internal representation to FS-independent representation.
  * (Note that while the two types are currently identical, the



CVS commit: src/sys/ufs/ufs

2012-01-28 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sun Jan 29 07:20:27 UTC 2012

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

Log Message:
quota2_check_limit() is used in only one place, so don't stuff it in a
header file.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/ufs/ufs/quota2.h
cvs rdiff -u -r1.28 -r1.29 src/sys/ufs/ufs/ufs_quota2.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/quota2.h
diff -u src/sys/ufs/ufs/quota2.h:1.7 src/sys/ufs/ufs/quota2.h:1.8
--- src/sys/ufs/ufs/quota2.h:1.7	Sun Jan 29 07:17:41 2012
+++ src/sys/ufs/ufs/quota2.h	Sun Jan 29 07:20:27 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: quota2.h,v 1.7 2012/01/29 07:17:41 dholland Exp $ */
+/* $NetBSD: quota2.h,v 1.8 2012/01/29 07:20:27 dholland Exp $ */
 /*-
   * Copyright (c) 2010 Manuel Bouyer
   * All rights reserved.
@@ -28,7 +28,6 @@
 #ifndef _UFS_UFS_QUOTA2_H_
 #define _UFS_UFS_QUOTA2_H_
 #include ufs/ufs/quota.h
-#include quota/quota.h
 
 
 /* New disk quota implementation. In this implementation, the quota datas
@@ -108,10 +107,4 @@ void quota2_create_blk0(uint64_t, void *
 void quota2_ufs_rwq2v(const struct quota2_val *, struct quota2_val *, int);
 void quota2_ufs_rwq2e(const struct quota2_entry *, struct quota2_entry *, int);
 
-__inline static int __unused
-quota2_check_limit(struct quota2_val *q2v, uint64_t change, time_t now)
-{
-	return quota_check_limit(q2v-q2v_cur, change, q2v-q2v_softlimit,
-	q2v-q2v_hardlimit, q2v-q2v_time, now);
-}
 #endif /*  _UFS_UFS_QUOTA2_H_ */

Index: src/sys/ufs/ufs/ufs_quota2.c
diff -u src/sys/ufs/ufs/ufs_quota2.c:1.28 src/sys/ufs/ufs/ufs_quota2.c:1.29
--- src/sys/ufs/ufs/ufs_quota2.c:1.28	Sun Jan 29 07:18:17 2012
+++ src/sys/ufs/ufs/ufs_quota2.c	Sun Jan 29 07:20:27 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: ufs_quota2.c,v 1.28 2012/01/29 07:18:17 dholland Exp $ */
+/* $NetBSD: ufs_quota2.c,v 1.29 2012/01/29 07:20:27 dholland Exp $ */
 /*-
   * Copyright (c) 2010 Manuel Bouyer
   * All rights reserved.
@@ -26,7 +26,7 @@
   */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_quota2.c,v 1.28 2012/01/29 07:18:17 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_quota2.c,v 1.29 2012/01/29 07:20:27 dholland Exp $);
 
 #include sys/buf.h
 #include sys/param.h
@@ -52,6 +52,8 @@ __KERNEL_RCSID(0, $NetBSD: ufs_quota2.c
 #include ufs/ufs/ufs_quota.h
 #include ufs/ufs/ufs_wapbl.h
 
+#include quota/quota.h	/* XXX for quota_check_limit */
+
 /*
  * LOCKING:
  * Data in the entries are protected by the associated struct dquot's
@@ -433,6 +435,13 @@ getinoquota2(struct inode *ip, bool allo
 	return 0;
 }
 
+__inline static int __unused
+quota2_check_limit(struct quota2_val *q2v, uint64_t change, time_t now)
+{
+	return quota_check_limit(q2v-q2v_cur, change, q2v-q2v_softlimit,
+	q2v-q2v_hardlimit, q2v-q2v_time, now);
+}
+
 static int
 quota2_check(struct inode *ip, int vtype, int64_t change, kauth_cred_t cred,
 int flags)



CVS commit: src/sys/ufs/ufs

2012-01-28 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sun Jan 29 07:21:00 UTC 2012

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

Log Message:
Clean up quota2 cursoring, as promised earlier.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/ufs/ufs/ufs_quota2.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_quota2.c
diff -u src/sys/ufs/ufs/ufs_quota2.c:1.29 src/sys/ufs/ufs/ufs_quota2.c:1.30
--- src/sys/ufs/ufs/ufs_quota2.c:1.29	Sun Jan 29 07:20:27 2012
+++ src/sys/ufs/ufs/ufs_quota2.c	Sun Jan 29 07:21:00 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: ufs_quota2.c,v 1.29 2012/01/29 07:20:27 dholland Exp $ */
+/* $NetBSD: ufs_quota2.c,v 1.30 2012/01/29 07:21:00 dholland Exp $ */
 /*-
   * Copyright (c) 2010 Manuel Bouyer
   * All rights reserved.
@@ -26,13 +26,12 @@
   */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_quota2.c,v 1.29 2012/01/29 07:20:27 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_quota2.c,v 1.30 2012/01/29 07:21:00 dholland Exp $);
 
 #include sys/buf.h
 #include sys/param.h
 #include sys/kernel.h
 #include sys/systm.h
-#include sys/malloc.h
 #include sys/namei.h
 #include sys/file.h
 #include sys/proc.h
@@ -794,17 +793,16 @@ out_dq:
 }
 
 static int
-quota2_result_add_q2e(struct ufsmount *ump, int idtype,
-int id, struct quotakey *keys, struct quotaval *vals, unsigned pos,
-int skipfirst, int skiplast)
+quota2_fetch_q2e(struct ufsmount *ump, const struct quotakey *qk,
+struct quota2_entry *ret)
 {
 	struct dquot *dq;
 	int error;
-	struct quota2_entry *q2ep, q2e;
-	struct buf  *bp;
+	struct quota2_entry *q2ep;
+	struct buf *bp;
 	const int needswap = UFS_MPNEEDSWAP(ump);
 
-	error = dqget(NULLVP, id, ump, idtype, dq);
+	error = dqget(NULLVP, qk-qk_id, ump, qk-qk_idtype, dq);
 	if (error)
 		return error;
 
@@ -814,39 +812,23 @@ quota2_result_add_q2e(struct ufsmount *u
 		dqrele(NULLVP, dq);
 		return ENOENT;
 	}
-	error = getq2e(ump, idtype, dq-dq2_lblkno, dq-dq2_blkoff,
+	error = getq2e(ump, qk-qk_idtype, dq-dq2_lblkno, dq-dq2_blkoff,
 	bp, q2ep, 0);
 	if (error) {
 		mutex_exit(dq-dq_interlock);
 		dqrele(NULLVP, dq);
 		return error;
 	}
-	quota2_ufs_rwq2e(q2ep, q2e, needswap);
+	quota2_ufs_rwq2e(q2ep, ret, needswap);
 	brelse(bp, 0);
 	mutex_exit(dq-dq_interlock);
 	dqrele(NULLVP, dq);
 
-	if (skipfirst == 0) {
-		keys[pos].qk_idtype = idtype;
-		keys[pos].qk_objtype = QUOTA_OBJTYPE_BLOCKS;
-		q2e_to_quotaval(q2e, 0, keys[pos].qk_id,
-QL_BLOCK, vals[pos]);
-		pos++;
-	}
-
-	if (skiplast == 0) {
-		keys[pos].qk_idtype = idtype;
-		keys[pos].qk_objtype = QUOTA_OBJTYPE_FILES;
-		q2e_to_quotaval(q2e, 0, keys[pos].qk_id,
-QL_FILE, vals[pos]);
-		pos++;
-	}
-
 	return 0;
 }
 
 static int
-quota2_fetch_q2e(struct ufsmount *ump, const struct quotakey *qk,
+quota2_fetch_quotaval(struct ufsmount *ump, const struct quotakey *qk,
 struct quotaval *ret)
 {
 	struct dquot *dq;
@@ -923,11 +905,17 @@ quota2_handle_cmd_get(struct ufsmount *u
 qk-qk_objtype, ret);
 		(void)id2;
 	} else
-		error = quota2_fetch_q2e(ump, qk, ret);
+		error = quota2_fetch_quotaval(ump, qk, ret);
 	
 	return error;
 }
 
+/*
+ * Cursor structure we used.
+ *
+ * This will get stored in userland between calls so we must not assume
+ * it isn't arbitrarily corrupted.
+ */
 struct ufsq2_cursor {
 	uint32_t q2c_magic;	/* magic number */
 	int q2c_hashsize;	/* size of hash table at last go */
@@ -940,10 +928,54 @@ struct ufsq2_cursor {
 	int q2c_blocks_done;	/* true if we've returned the blocks value */
 };
 
+/*
+ * State of a single cursorget call, or at least the part of it that
+ * needs to be passed around.
+ */
+struct q2cursor_state {
+	/* data return pointers */
+	struct quotakey *keys;
+	struct quotaval *vals;
+
+	/* key/value counters */
+	unsigned maxkeyvals;
+	unsigned numkeys;	/* number of keys assigned */
+
+	/* ID to key/value conversion state */
+	int skipfirst;		/* if true skip first key/value */
+	int skiplast;		/* if true skip last key/value */
+
+	/* ID counters */
+	unsigned maxids;	/* maximum number of IDs to handle */
+	unsigned numids;	/* number of IDs handled */
+};
+
+/*
+ * Additional structure for getids callback.
+ */
+struct q2cursor_getids {
+	struct q2cursor_state *state;
+	int idtype;
+	unsigned skip;		/* number of ids to skip over */
+	unsigned new_skip;	/* number of ids to skip over next time */
+	unsigned skipped;	/* number skipped so far */
+};
+
+/*
+ * Cursor-related functions
+ */
+
+/* magic number */
 #define Q2C_MAGIC (0xbeebe111)
 
+/* extract cursor from caller form */
 #define Q2CURSOR(qkc) ((struct ufsq2_cursor *)qkc-u.qkc_space[0])
 
+/*
+ * Check that a cursor we're handed is something like valid. If
+ * someone munges it and it still passes these checks, they'll get
+ * partial or odd results back but won't break anything.
+ */
 static int
 q2cursor_check(struct ufsq2_cursor *cursor)
 {
@@ -972,108 

CVS commit: src/sys/ufs

2012-01-27 Thread Lars Heidieker
Module Name:src
Committed By:   para
Date:   Fri Jan 27 19:22:50 UTC 2012

Modified Files:
src/sys/ufs/ext2fs: ext2fs_inode.c ext2fs_lookup.c
src/sys/ufs/ffs: ffs_inode.c ffs_vfsops.c
src/sys/ufs/ufs: ufs_extattr.c ufs_vfsops.c ufs_vnops.c ufs_wapbl.c

Log Message:
converting readdir in ffs ext2fs from malloc(9) to kmem(9)
while there allocate ufs mount structs from kmem(9) too
preceding kmem-vmem-pool-patch

releng@ acknowledged


To generate a diff of this commit:
cvs rdiff -u -r1.74 -r1.75 src/sys/ufs/ext2fs/ext2fs_inode.c
cvs rdiff -u -r1.66 -r1.67 src/sys/ufs/ext2fs/ext2fs_lookup.c
cvs rdiff -u -r1.108 -r1.109 src/sys/ufs/ffs/ffs_inode.c
cvs rdiff -u -r1.272 -r1.273 src/sys/ufs/ffs/ffs_vfsops.c
cvs rdiff -u -r1.35 -r1.36 src/sys/ufs/ufs/ufs_extattr.c
cvs rdiff -u -r1.42 -r1.43 src/sys/ufs/ufs/ufs_vfsops.c
cvs rdiff -u -r1.206 -r1.207 src/sys/ufs/ufs/ufs_vnops.c
cvs rdiff -u -r1.22 -r1.23 src/sys/ufs/ufs/ufs_wapbl.c

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

Modified files:

Index: src/sys/ufs/ext2fs/ext2fs_inode.c
diff -u src/sys/ufs/ext2fs/ext2fs_inode.c:1.74 src/sys/ufs/ext2fs/ext2fs_inode.c:1.75
--- src/sys/ufs/ext2fs/ext2fs_inode.c:1.74	Thu Jun 16 09:21:03 2011
+++ src/sys/ufs/ext2fs/ext2fs_inode.c	Fri Jan 27 19:22:48 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: ext2fs_inode.c,v 1.74 2011/06/16 09:21:03 hannken Exp $	*/
+/*	$NetBSD: ext2fs_inode.c,v 1.75 2012/01/27 19:22:48 para Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -60,7 +60,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ext2fs_inode.c,v 1.74 2011/06/16 09:21:03 hannken Exp $);
+__KERNEL_RCSID(0, $NetBSD: ext2fs_inode.c,v 1.75 2012/01/27 19:22:48 para Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -70,7 +70,7 @@ __KERNEL_RCSID(0, $NetBSD: ext2fs_inode
 #include sys/buf.h
 #include sys/vnode.h
 #include sys/kernel.h
-#include sys/malloc.h
+#include sys/kmem.h
 #include sys/trace.h
 #include sys/resourcevar.h
 #include sys/kauth.h
@@ -499,7 +499,7 @@ ext2fs_indirtrunc(struct inode *ip, dadd
 	bap = (int32_t *)bp-b_data;	/* XXX ondisk32 */
 	if (lastbn = 0) {
 		/* XXX ondisk32 */
-		copy = malloc(fs-e2fs_bsize, M_TEMP, M_WAITOK);
+		copy = kmem_alloc(fs-e2fs_bsize, KM_SLEEP);
 		memcpy((void *)copy, (void *)bap, (u_int)fs-e2fs_bsize);
 		memset((void *)bap[last + 1], 0,
 			(u_int)(NINDIR(fs) - (last + 1)) * sizeof (uint32_t));
@@ -548,7 +548,7 @@ ext2fs_indirtrunc(struct inode *ip, dadd
 	}
 
 	if (copy != NULL) {
-		free(copy, M_TEMP);
+		kmem_free(copy, fs-e2fs_bsize);
 	} else {
 		brelse(bp, BC_INVAL);
 	}

Index: src/sys/ufs/ext2fs/ext2fs_lookup.c
diff -u src/sys/ufs/ext2fs/ext2fs_lookup.c:1.66 src/sys/ufs/ext2fs/ext2fs_lookup.c:1.67
--- src/sys/ufs/ext2fs/ext2fs_lookup.c:1.66	Tue Jul 12 16:59:48 2011
+++ src/sys/ufs/ext2fs/ext2fs_lookup.c	Fri Jan 27 19:22:48 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: ext2fs_lookup.c,v 1.66 2011/07/12 16:59:48 dholland Exp $	*/
+/*	$NetBSD: ext2fs_lookup.c,v 1.67 2012/01/27 19:22:48 para Exp $	*/
 
 /*
  * Modified for NetBSD 1.2E
@@ -48,7 +48,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ext2fs_lookup.c,v 1.66 2011/07/12 16:59:48 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: ext2fs_lookup.c,v 1.67 2012/01/27 19:22:48 para Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -57,6 +57,7 @@ __KERNEL_RCSID(0, $NetBSD: ext2fs_looku
 #include sys/file.h
 #include sys/mount.h
 #include sys/vnode.h
+#include sys/kmem.h
 #include sys/malloc.h
 #include sys/dirent.h
 #include sys/kauth.h
@@ -167,15 +168,14 @@ ext2fs_readdir(void *v)
 	aiov.iov_len = e2fs_count;
 	auio.uio_resid = e2fs_count;
 	UIO_SETUP_SYSSPACE(auio);
-	dirbuf = malloc(e2fs_count, M_TEMP, M_WAITOK);
-	dstd = malloc(sizeof(struct dirent), M_TEMP, M_WAITOK | M_ZERO);
+	dirbuf = kmem_alloc(e2fs_count, KM_SLEEP);
+	dstd = kmem_zalloc(sizeof(struct dirent), KM_SLEEP);
 	if (ap-a_ncookies) {
 		nc = e2fs_count / _DIRENT_MINSIZE((struct dirent *)0);
 		ncookies = nc;
 		cookies = malloc(sizeof (off_t) * ncookies, M_TEMP, M_WAITOK);
 		*ap-a_cookies = cookies;
 	}
-	memset(dirbuf, 0, e2fs_count);
 	aiov.iov_base = dirbuf;
 
 	error = VOP_READ(ap-a_vp, auio, 0, ap-a_cred);
@@ -209,8 +209,8 @@ ext2fs_readdir(void *v)
 		/* we need to correct uio_offset */
 		uio-uio_offset = off;
 	}
-	free(dirbuf, M_TEMP);
-	free(dstd, M_TEMP);
+	kmem_free(dirbuf, e2fs_count);
+	kmem_free(dstd, sizeof(*dstd));
 	*ap-a_eofflag = ext2fs_size(VTOI(ap-a_vp)) = uio-uio_offset;
 	if (ap-a_ncookies) {
 		if (error) {

Index: src/sys/ufs/ffs/ffs_inode.c
diff -u src/sys/ufs/ffs/ffs_inode.c:1.108 src/sys/ufs/ffs/ffs_inode.c:1.109
--- src/sys/ufs/ffs/ffs_inode.c:1.108	Wed Nov 23 19:42:10 2011
+++ src/sys/ufs/ffs/ffs_inode.c	Fri Jan 27 19:22:49 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_inode.c,v 1.108 2011/11/23 19:42:10 bouyer Exp $	*/
+/*	$NetBSD: ffs_inode.c,v 1.109 2012/01/27 19:22:49 para Exp $	*/
 
 /*-
  * Copyright (c) 2008 The 

CVS commit: src/sys/ufs/chfs

2012-01-16 Thread Adam Hoka
Module Name:src
Committed By:   ahoka
Date:   Mon Jan 16 12:17:56 UTC 2012

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

Log Message:
cleanup macros


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/ufs/chfs/chfs_wbuf.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_wbuf.c
diff -u src/sys/ufs/chfs/chfs_wbuf.c:1.2 src/sys/ufs/chfs/chfs_wbuf.c:1.3
--- src/sys/ufs/chfs/chfs_wbuf.c:1.2	Thu Nov 24 20:50:33 2011
+++ src/sys/ufs/chfs/chfs_wbuf.c	Mon Jan 16 12:17:55 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: chfs_wbuf.c,v 1.2 2011/11/24 20:50:33 agc Exp $	*/
+/*	$NetBSD: chfs_wbuf.c,v 1.3 2012/01/16 12:17:55 ahoka Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -35,28 +35,19 @@
 #include dev/flash/flash.h
 #include sys/uio.h
 #include chfs.h
-//#include /root/xipffs/netbsd.chfs/chfs.h
 
-#define DBG_WBUF 1
+#define DBG_WBUF 1		/* XXX unused, but should be */
 
 #define PAD(x) (((x)+3)~3)
 
-#define EB_ADDRESS(x) ( ((unsigned long)(x) / chmp-chm_ebh-eb_size) * chmp-chm_ebh-eb_size )
+#define EB_ADDRESS(x) ( rounddown((x), chmp-chm_ebh-eb_size) )
 
-#define PAGE_DIV(x) ( ((unsigned long)(x) / (unsigned long)(chmp-chm_wbuf_pagesize)) * (unsigned long)(chmp-chm_wbuf_pagesize) )
-#define PAGE_MOD(x) ( (unsigned long)(x) % (unsigned long)(chmp-chm_wbuf_pagesize) )
-
-/*
-// test functions
-int wbuf_test(void);
-void wbuf_test_erase_flash(struct chfs_mount*);
-void wbuf_test_callback(struct erase_instruction*);
-*/
+#define PAGE_DIV(x) ( rounddown((x), chmp-chm_wbuf_pagesize) )
+#define PAGE_MOD(x) ( (x) % (chmp-chm_wbuf_pagesize) )
 
 #define NOPAD	0
 #define SETPAD	1
 
-
 /**
  * chfs_flush_wbuf - write wbuf to the flash
  * @chmp: super block info



CVS commit: src/sys/ufs/chfs

2012-01-16 Thread Adam Hoka
Module Name:src
Committed By:   ahoka
Date:   Mon Jan 16 12:28:47 UTC 2012

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

Log Message:
use enum instead of macros
add some input validation
cleanup


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/ufs/chfs/chfs_wbuf.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_wbuf.c
diff -u src/sys/ufs/chfs/chfs_wbuf.c:1.3 src/sys/ufs/chfs/chfs_wbuf.c:1.4
--- src/sys/ufs/chfs/chfs_wbuf.c:1.3	Mon Jan 16 12:17:55 2012
+++ src/sys/ufs/chfs/chfs_wbuf.c	Mon Jan 16 12:28:47 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: chfs_wbuf.c,v 1.3 2012/01/16 12:17:55 ahoka Exp $	*/
+/*	$NetBSD: chfs_wbuf.c,v 1.4 2012/01/16 12:28:47 ahoka Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -45,54 +45,65 @@
 #define PAGE_DIV(x) ( rounddown((x), chmp-chm_wbuf_pagesize) )
 #define PAGE_MOD(x) ( (x) % (chmp-chm_wbuf_pagesize) )
 
-#define NOPAD	0
-#define SETPAD	1
+enum {
+	WBUF_NOPAD,
+	WBUF_SETPAD
+};
 
 /**
  * chfs_flush_wbuf - write wbuf to the flash
  * @chmp: super block info
- * @pad: padding (NOPAD / SETPAD)
+ * @pad: padding (WBUF_NOPAD / WBUF_SETPAD)
  * Returns zero in case of success.
  */
 static int
 chfs_flush_wbuf(struct chfs_mount *chmp, int pad)
 {
-	int ret=0;
-	size_t retlen = 0;
+	int ret;
+	size_t retlen;
+	struct chfs_node_ref *nref;
+	struct chfs_flash_padding_node* padnode;
 
 	KASSERT(mutex_owned(chmp-chm_lock_mountfields));
 	KASSERT(mutex_owned(chmp-chm_lock_sizes));
 	KASSERT(rw_write_held(chmp-chm_lock_wbuf));
+	KASSERT(pad == WBUF_SETPAD || pad == WBUF_NOPAD);
 
-	if (pad) {
+	if (pad == WBUF_SETPAD) {
 		chmp-chm_wbuf_len = PAD(chmp-chm_wbuf_len);
-		memset(chmp-chm_wbuf + chmp-chm_wbuf_len, 0, chmp-chm_wbuf_pagesize - chmp-chm_wbuf_len);
+		memset(chmp-chm_wbuf + chmp-chm_wbuf_len, 0,
+		chmp-chm_wbuf_pagesize - chmp-chm_wbuf_len);
 
-		struct chfs_flash_padding_node* padnode = (void*)(chmp-chm_wbuf + chmp-chm_wbuf_len);
+		padnode = (void *)(chmp-chm_wbuf + chmp-chm_wbuf_len);
 		padnode-magic = htole16(CHFS_FS_MAGIC_BITMASK);
 		padnode-type = htole16(CHFS_NODETYPE_PADDING);
-		padnode-length = htole32(chmp-chm_wbuf_pagesize - chmp-chm_wbuf_len);
-		padnode-hdr_crc = htole32(crc32(0, (uint8_t *)padnode, sizeof(*padnode)-4));
+		padnode-length = htole32(chmp-chm_wbuf_pagesize
+		- chmp-chm_wbuf_len);
+		padnode-hdr_crc = htole32(crc32(0, (uint8_t *)padnode,
+			sizeof(*padnode)-4));
 
-		struct chfs_node_ref *nref;
 		nref = chfs_alloc_node_ref(chmp-chm_nextblock);
 		nref-nref_offset = chmp-chm_wbuf_ofs + chmp-chm_wbuf_len;
 		nref-nref_offset = CHFS_GET_OFS(nref-nref_offset) |
 		CHFS_OBSOLETE_NODE_MASK;
 		chmp-chm_wbuf_len = chmp-chm_wbuf_pagesize;
 
-		chfs_change_size_free(chmp, chmp-chm_nextblock, -padnode-length);
-		chfs_change_size_wasted(chmp, chmp-chm_nextblock, padnode-length);
+		chfs_change_size_free(chmp, chmp-chm_nextblock,
+		-padnode-length);
+		chfs_change_size_wasted(chmp, chmp-chm_nextblock,
+		padnode-length);
 	}
 
-	ret = chfs_write_leb(chmp, chmp-chm_nextblock-lnr, chmp-chm_wbuf, chmp-chm_wbuf_ofs, chmp-chm_wbuf_len, retlen);
-	if(ret) {
+	ret = chfs_write_leb(chmp, chmp-chm_nextblock-lnr, chmp-chm_wbuf,
+	chmp-chm_wbuf_ofs, chmp-chm_wbuf_len, retlen);
+	if (ret) {
 		return ret;
 	}
 
-	memset(chmp-chm_wbuf,0xff,chmp-chm_wbuf_pagesize);
+	memset(chmp-chm_wbuf, 0xff, chmp-chm_wbuf_pagesize);
 	chmp-chm_wbuf_ofs += chmp-chm_wbuf_pagesize;
 	chmp-chm_wbuf_len = 0;
+
 	return 0;
 }
 
@@ -156,7 +167,7 @@ chfs_write_wbuf(struct chfs_mount* chmp,
 
 	if (EB_ADDRESS(to) != EB_ADDRESS(chmp-chm_wbuf_ofs)) {
 		if (chmp-chm_wbuf_len) {
-			ret = chfs_flush_wbuf(chmp, SETPAD);
+			ret = chfs_flush_wbuf(chmp, WBUF_SETPAD);
 			if (ret)
 goto outerr;
 		}
@@ -179,7 +190,7 @@ chfs_write_wbuf(struct chfs_mount* chmp,
 		/* take care of alignement to next page*/
 		if (!chmp-chm_wbuf_len) {
 			chmp-chm_wbuf_len += chmp-chm_wbuf_pagesize;
-			ret = chfs_flush_wbuf(chmp, NOPAD);
+			ret = chfs_flush_wbuf(chmp, WBUF_NOPAD);
 			if (ret)
 goto outerr;
 		}
@@ -193,7 +204,7 @@ chfs_write_wbuf(struct chfs_mount* chmp,
 
 		wbuf_retlen = chfs_fill_wbuf(chmp, v, vlen);
 		if (chmp-chm_wbuf_len == chmp-chm_wbuf_pagesize) {
-			ret = chfs_flush_wbuf(chmp, NOPAD);
+			ret = chfs_flush_wbuf(chmp, WBUF_NOPAD);
 			if (ret) {
 goto outerr;
 			}
@@ -213,14 +224,14 @@ chfs_write_wbuf(struct chfs_mount* chmp,
 		}
 		wbuf_retlen = chfs_fill_wbuf(chmp, v, vlen);
 		if (chmp-chm_wbuf_len == chmp-chm_wbuf_pagesize) {
-			ret = chfs_flush_wbuf(chmp, NOPAD);
+			ret = chfs_flush_wbuf(chmp, WBUF_NOPAD);
 			if (ret)
 goto outerr;
 		}
 
 		// if we write the last vector, we flush with padding
 		/*if (invec == count-1) {
-		  ret = chfs_flush_wbuf(chmp, SETPAD);
+		  ret = chfs_flush_wbuf(chmp, WBUF_SETPAD);
 		  if (ret)
 		  goto outerr;
 		  }*/
@@ -243,7 

CVS commit: src/sys/ufs/lfs

2012-01-14 Thread Konrad Schroder
Module Name:src
Committed By:   perseant
Date:   Sun Jan 15 04:42:04 UTC 2012

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

Log Message:
Corrections to part of rev 1.140. lfs_bmapv, not lfs_markv, marks vnodes
LFSI_BMAP and recycles them.  This greatly reduces the writing leakage
occurring when the filesystem has no space available for non-cleaning
writes.


To generate a diff of this commit:
cvs rdiff -u -r1.140 -r1.141 src/sys/ufs/lfs/lfs_syscalls.c

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

Modified files:

Index: src/sys/ufs/lfs/lfs_syscalls.c
diff -u src/sys/ufs/lfs/lfs_syscalls.c:1.140 src/sys/ufs/lfs/lfs_syscalls.c:1.141
--- src/sys/ufs/lfs/lfs_syscalls.c:1.140	Mon Jan  2 22:10:45 2012
+++ src/sys/ufs/lfs/lfs_syscalls.c	Sun Jan 15 04:42:04 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_syscalls.c,v 1.140 2012/01/02 22:10:45 perseant Exp $	*/
+/*	$NetBSD: lfs_syscalls.c,v 1.141 2012/01/15 04:42:04 perseant Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007, 2007, 2008
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: lfs_syscalls.c,v 1.140 2012/01/02 22:10:45 perseant Exp $);
+__KERNEL_RCSID(0, $NetBSD: lfs_syscalls.c,v 1.141 2012/01/15 04:42:04 perseant Exp $);
 
 #ifndef LFS
 # define LFS		/* for prototypes in syscallargs.h */
@@ -291,17 +291,6 @@ lfs_markv(struct proc *p, fsid_t *fsidp,
 			 */
 			if (v_daddr != LFS_UNUSED_DADDR) {
 lfs_vunref(vp);
-/*
- * If the vnode has LFSI_BMAP, it was
- * not found in the cache.  Dump it so
- * we can reuse the vnode.
- * XXX If we knew what segment we were
- * XXX supposed to be looking for, we
- * XXX would be able to be more selective
- * XXX here.
- */
-if (ip-i_lfs_iflags  LFSI_BMAP)
-	vrecycle(vp, NULL, NULL);
 numrefed--;
 			}
 
@@ -719,6 +708,8 @@ lfs_bmapv(struct proc *p, fsid_t *fsidp,
 			 */
 			if (v_daddr != LFS_UNUSED_DADDR) {
 lfs_vunref(vp);
+if (VTOI(vp)-i_lfs_iflags  LFSI_BMAP)
+	vrecycle(vp, NULL, NULL);
 numrefed--;
 			}
 
@@ -1139,6 +1130,11 @@ lfs_fastvget(struct mount *mp, ino_t ino
 	ufs_ihashins(ip);
 	mutex_exit(ufs_hashlock);
 
+#ifdef notyet
+	/* Not found in the cache = this vnode was loaded only for cleaning. */
+	ip-i_lfs_iflags |= LFSI_BMAP;
+#endif
+
 	/*
 	 * XXX
 	 * This may not need to be here, logically it should go down with



CVS commit: src/sys/ufs/ffs

2012-01-03 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Tue Jan  3 15:44:00 UTC 2012

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

Log Message:
Display current mount point, rather than previous one, when printing
the replaying log to disk message.

OK dholland@

Fixes PR kern/39609


To generate a diff of this commit:
cvs rdiff -u -r1.271 -r1.272 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.271 src/sys/ufs/ffs/ffs_vfsops.c:1.272
--- src/sys/ufs/ffs/ffs_vfsops.c:1.271	Mon Nov 14 18:35:14 2011
+++ src/sys/ufs/ffs/ffs_vfsops.c	Tue Jan  3 15:44:00 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.271 2011/11/14 18:35:14 hannken Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.272 2012/01/03 15:44:00 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.271 2011/11/14 18:35:14 hannken Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.272 2012/01/03 15:44:00 pgoyette Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -524,7 +524,7 @@ ffs_mount(struct mount *mp, const char *
 #ifdef WAPBL
 			if (fs-fs_flags  FS_DOWAPBL) {
 printf(%s: replaying log to disk\n,
-fs-fs_fsmnt);
+mp-mnt_stat.f_mntonname);
 KDASSERT(mp-mnt_wapbl_replay);
 error = wapbl_replay_write(mp-mnt_wapbl_replay,
 			   devvp);



CVS commit: src/sys/ufs/lfs

2012-01-03 Thread Konrad Schroder
Module Name:src
Committed By:   perseant
Date:   Wed Jan  4 02:48:58 UTC 2012

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

Log Message:
lfs_writerd thread exits when no more LFSs are mounted.


To generate a diff of this commit:
cvs rdiff -u -r1.292 -r1.293 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.292 src/sys/ufs/lfs/lfs_vfsops.c:1.293
--- src/sys/ufs/lfs/lfs_vfsops.c:1.292	Mon Jan  2 22:10:45 2012
+++ src/sys/ufs/lfs/lfs_vfsops.c	Wed Jan  4 02:48:58 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_vfsops.c,v 1.292 2012/01/02 22:10:45 perseant Exp $	*/
+/*	$NetBSD: lfs_vfsops.c,v 1.293 2012/01/04 02:48:58 perseant Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007, 2007
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: lfs_vfsops.c,v 1.292 2012/01/02 22:10:45 perseant Exp $);
+__KERNEL_RCSID(0, $NetBSD: lfs_vfsops.c,v 1.293 2012/01/04 02:48:58 perseant Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_lfs.h
@@ -524,14 +524,12 @@ lfs_writerd(void *arg)
  			vfs_unbusy(mp, false, nmp);
  		}
 		if (lfsc + skipc == 0) {
-#ifdef notyet
 			mutex_enter(lfs_lock);
 			lfs_writer_daemon = 0;
 			lfs_writer_lid = 0;
 			mutex_exit(lfs_lock);
 			mutex_exit(mountlist_lock);
 			break;
-#endif
 		}
  		mutex_exit(mountlist_lock);
  
@@ -545,6 +543,9 @@ lfs_writerd(void *arg)
 	if (vfs != NULL)
 		vfs-vfs_refcount--;
 	mutex_exit(vfs_list_lock);
+
+	/* Done! */
+	kthread_exit(0);
 }
 
 /*



CVS commit: src/sys/ufs

2012-01-02 Thread Konrad Schroder
Module Name:src
Committed By:   perseant
Date:   Mon Jan  2 22:10:45 UTC 2012

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

Log Message:
* Remove PGO_RECLAIM during lfs_putpages()' call to genfs_putpages(),
  to avoid a live lock in the latter when reclaiming a vnode with
  dirty pages.

* Add a new segment flag, SEGM_RECLAIM, to note when a segment is
  being written for vnode reclamation, and record which inode is being
  reclaimed, to aid in forensic debugging.

* Add a new segment flag, SEGM_SINGLE, so that opportunistic writes
  can write a single segment's worth of blocks and then stop, rather
  than writing all the way up to the cleaner's reserved number of
  segments.

* Add assert statements to check mutex ownership is the way it ought
  to be, mostly in lfs_putpages; fix problems uncovered by this.

* Don't clear VU_DIROP until the inode actually makes its way to disk,
  avoiding a problem where dirop inodes could become separated
  (uncovered by a modified version of the ckckp forensic regression
  test).

* Move the vfs_getopsbyname() call into lfs_writerd.  Prepare code to
  make lfs_writerd notice when there are no more LFSs, and exit losing
  the reference, so that, in theory, the module can be unloaded.  This
  code is not enabled, since it causes a crash on exit.

* Set IN_MODIFIED on inodes flushed by lfs_flush_dirops.  Really we
  only need to set IN_MODIFIED if we are going to write them again
  (e.g., to write pages); need to think about this more.

Finally, several changes to help avoid no clean segments panics:

* In lfs_bmapv, note when a vnode is loaded only to discover whether
  its blocks are live, so it can immediately be recycled.  Since the
  cleaner will try to choose ~empty segments over full ones, this
  prevents the cleaner from (1) filling the vnode cache with junk, and
  (2) squeezing any unwritten writes to disk and running the fs out of
  segments.

* Overestimate by half the amount of metadata that will be required
  to fill the clean segments.  This will make the disk appear smaller,
  but should help avoid a no clean segments panic.

* Rearrange lfs_writerd.  In particular, lfs_writerd now pays
  attention to the number of clean segments available, and holds off
  writing until there is room.


To generate a diff of this commit:
cvs rdiff -u -r1.134 -r1.135 src/sys/ufs/lfs/lfs.h
cvs rdiff -u -r1.120 -r1.121 src/sys/ufs/lfs/lfs_bio.c
cvs rdiff -u -r1.96 -r1.97 src/sys/ufs/lfs/lfs_extern.h
cvs rdiff -u -r1.222 -r1.223 src/sys/ufs/lfs/lfs_segment.c
cvs rdiff -u -r1.76 -r1.77 src/sys/ufs/lfs/lfs_subr.c
cvs rdiff -u -r1.139 -r1.140 src/sys/ufs/lfs/lfs_syscalls.c
cvs rdiff -u -r1.291 -r1.292 src/sys/ufs/lfs/lfs_vfsops.c
cvs rdiff -u -r1.238 -r1.239 src/sys/ufs/lfs/lfs_vnops.c
cvs rdiff -u -r1.58 -r1.59 src/sys/ufs/ufs/inode.h
cvs rdiff -u -r1.100 -r1.101 src/sys/ufs/ufs/ufs_readwrite.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.134 src/sys/ufs/lfs/lfs.h:1.135
--- src/sys/ufs/lfs/lfs.h:1.134	Mon Jul 11 08:27:40 2011
+++ src/sys/ufs/lfs/lfs.h	Mon Jan  2 22:10:44 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs.h,v 1.134 2011/07/11 08:27:40 hannken Exp $	*/
+/*	$NetBSD: lfs.h,v 1.135 2012/01/02 22:10:44 perseant Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -592,6 +592,7 @@ struct segsum_v1 {
 #define	SS_CONT		0x02		/* more partials to finish this write*/
 #define	SS_CLEAN	0x04		/* written by the cleaner */
 #define	SS_RFW		0x08		/* written by the roll-forward agent */
+#define	SS_RECLAIM	0x10		/* written by the roll-forward agent */
 	u_int16_t ss_flags;		/* 24: used for directory operations */
 	u_int16_t ss_pad;		/* 26: extra space */
 	/* FINFO's and inode daddr's... */
@@ -608,7 +609,8 @@ struct segsum {
 	u_int16_t ss_nfinfo;		/* 20: number of file info structures */
 	u_int16_t ss_ninos;		/* 22: number of inodes in summary */
 	u_int16_t ss_flags;		/* 24: used for directory operations */
-	u_int8_t  ss_pad[6];		/* 26: extra space */
+	u_int8_t  ss_pad[2];		/* 26: extra space */
+	u_int32_t ss_reclino;   /* 28: inode being reclaimed */
 	u_int64_t ss_serial;		/* 32: serial number */
 	u_int64_t ss_create;		/* 40: time stamp */
 	/* FINFO's and inode daddr's... */
@@ -840,6 +842,8 @@ struct lfs {
 	int lfs_nowrap;			/* Suspend log wrap */
 	int lfs_wrappass;		/* Allow first log wrap requester to pass */
 	int lfs_wrapstatus;		/* Wrap status */
+	int lfs_reclino;		/* Inode being reclaimed */
+	int lfs_startseg;   /* Segment we started writing at */
 	LIST_HEAD(, segdelta) lfs_segdhd;	/* List of pending trunc accounting events */
 };
 
@@ -945,13 +949,15 @@ struct segment {
 	u_int32_t seg_number;		/* number 

CVS commit: src/sys/ufs/chfs

2011-11-28 Thread Adam Hoka
Module Name:src
Committed By:   ahoka
Date:   Mon Nov 28 12:50:07 UTC 2011

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

Log Message:
cleanup, some style and remove leftover code


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/ufs/chfs/chfs.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/chfs.h
diff -u src/sys/ufs/chfs/chfs.h:1.3 src/sys/ufs/chfs/chfs.h:1.4
--- src/sys/ufs/chfs/chfs.h:1.3	Thu Nov 24 21:38:44 2011
+++ src/sys/ufs/chfs/chfs.h	Mon Nov 28 12:50:07 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: chfs.h,v 1.3 2011/11/24 21:38:44 ahoka Exp $	*/
+/*	$NetBSD: chfs.h,v 1.4 2011/11/28 12:50:07 ahoka Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -310,7 +310,8 @@ struct chfs_eraseblock
 	struct chfs_node_ref *first_node;
 	struct chfs_node_ref *last_node;
 
-	struct chfs_node_ref *gc_node; /* Next block to be garbage collected */
+	/* Next block to be garbage collected */
+	struct chfs_node_ref *gc_node;
 };
 
 TAILQ_HEAD(chfs_eraseblock_queue, chfs_eraseblock);
@@ -349,21 +350,15 @@ struct garbage_collector_thread {
  * @very_dirty_queue: queue of very dirty eraseblocks
  * @erase_pending_queue: queue of eraseblocks waiting for erasing
  * @erasable_pending_wbuf_queue: queue of eraseblocks waiting for erasing and
- *  have data to write to them
+ * 			  	 have data to write to them
  * @nextblock: next eraseblock to write to
- *
  * @nr_free_blocks: number of free blocks on the free_queue
  * @nr_erasable_blocks: number of blocks that can be erased and are on the
- * 		erasable_queue
- *
+ *			erasable_queue
  */
 struct chfs_mount {
 	struct mount *chm_fsmp;
-//	dev_t dev;
-//	struct vnode *devvp;
-
 	struct chfs_ebh *chm_ebh;
-//	int chm_fl_index;
 	int chm_fs_version;
 	uint64_t chm_gbl_version;
 	ino_t chm_max_vno;
@@ -448,30 +443,15 @@ struct chfs_mount {
 	krwlock_t chm_lock_wbuf;
 };
 
-#define sleep_on_spinunlock(s)		  \
-	do {  \
-		kmutex_t sleep_mtx;	  \
-		kcondvar_t sleep_cnd;	  \
-		cv_init(sleep_cnd, sleep_cnd);			  \
-		mutex_init(sleep_mtx, MUTEX_DEFAULT, IPL_NONE);	  \
-		mutex_spin_exit(s);	  \
-		mutex_enter(sleep_mtx);  \
-		cv_timedwait(sleep_cnd, sleep_mtx, mstohz(50));	  \
-		mutex_exit(sleep_mtx);	  \
-		mutex_destroy(sleep_mtx);  \
-		cv_destroy(sleep_cnd);	  \
-	} while (0)
-#undef sleep_on_spinunlock
-
 /*
  * TODO we should move here all of these from the bottom of the file
  * Macros/functions to convert from generic data structures to chfs
  * specific ones.
  */
 
-#define	CHFS_OFFSET_DOT	0
+#define	CHFS_OFFSET_DOT		0
 #define	CHFS_OFFSET_DOTDOT	1
-#define CHFS_OFFSET_EOF	2
+#define CHFS_OFFSET_EOF		2
 #define CHFS_OFFSET_FIRST	3
 
 
@@ -480,21 +460,32 @@ struct chfs_mount {
 /* chfs_build.c */
 void chfs_calc_trigger_levels(struct chfs_mount *);
 int chfs_build_filesystem(struct chfs_mount *);
-void chfs_build_set_vnodecache_nlink(struct chfs_mount *chmp,struct chfs_vnode_cache *vc);
-void chfs_build_remove_unlinked_vnode(struct chfs_mount *chmp,struct chfs_vnode_cache *vc, struct chfs_dirent_list *unlinked);
+void chfs_build_set_vnodecache_nlink(struct chfs_mount *,
+struct chfs_vnode_cache *);
+void chfs_build_remove_unlinked_vnode(struct chfs_mount *,
+struct chfs_vnode_cache *, struct chfs_dirent_list *);
 
 /* chfs_scan.c */
 int chfs_scan_eraseblock(struct chfs_mount *, struct chfs_eraseblock *);
-struct chfs_vnode_cache *chfs_scan_make_vnode_cache(struct chfs_mount *chmp, ino_t vno);
-int chfs_scan_check_node_hdr(struct chfs_flash_node_hdr *nhdr);
-int chfs_scan_check_vnode(struct chfs_mount *chmp, struct chfs_eraseblock *cheb, void *buf, off_t ofs);
-int chfs_scan_mark_dirent_obsolete(struct chfs_mount *chmp,struct chfs_vnode_cache *vc, struct chfs_dirent *fd);
-void chfs_add_fd_to_list(struct chfs_mount *chmp,struct chfs_dirent *new, struct chfs_vnode_cache *pvc);
-int chfs_scan_check_dirent_node(struct chfs_mount *chmp, struct chfs_eraseblock *cheb, void *buf, off_t ofs);
-int chfs_scan_check_data_node(struct chfs_mount *chmp, struct chfs_eraseblock *cheb, void *buf, off_t ofs);
-int chfs_scan_classify_cheb(struct chfs_mount *chmp,struct chfs_eraseblock *cheb);
+struct chfs_vnode_cache *chfs_scan_make_vnode_cache(struct chfs_mount *,
+ino_t);
+int chfs_scan_check_node_hdr(struct chfs_flash_node_hdr *);
+int chfs_scan_check_vnode(struct chfs_mount *,
+struct chfs_eraseblock *, void *, off_t);
+int chfs_scan_mark_dirent_obsolete(struct chfs_mount *,
+struct chfs_vnode_cache *, struct chfs_dirent *);
+void chfs_add_fd_to_list(struct chfs_mount *,
+struct chfs_dirent *, struct chfs_vnode_cache *);
+int chfs_scan_check_dirent_node(struct chfs_mount *,
+struct chfs_eraseblock *, void *, off_t);
+int chfs_scan_check_data_node(struct chfs_mount *,
+struct 

CVS commit: src/sys/ufs/chfs

2011-11-25 Thread Adam Hoka
Module Name:src
Committed By:   ahoka
Date:   Fri Nov 25 11:15:25 UTC 2011

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

Log Message:
Don't shadow some stupid function defined globally in random platforms.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 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.1 src/sys/ufs/chfs/ebh.c:1.2
--- src/sys/ufs/chfs/ebh.c:1.1	Thu Nov 24 15:51:32 2011
+++ src/sys/ufs/chfs/ebh.c	Fri Nov 25 11:15:24 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ebh.c,v 1.1 2011/11/24 15:51:32 ahoka Exp $	*/
+/*	$NetBSD: ebh.c,v 1.2 2011/11/25 11:15:24 ahoka Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -1369,16 +1369,17 @@ nand_process_eb(struct chfs_ebh *ebh, st
 {
 	int err, erase_cnt, leb_status;
 	uint64_t max_serial;
-	bool isbad;
+	/* isbad() is defined on some ancient platforms, heh */
+	bool is_bad;
 
 	/* Check block is bad */
 	err = flash_block_isbad(ebh-flash_dev,
-	pebnr * ebh-flash_if-erasesize, isbad);
+	pebnr * ebh-flash_if-erasesize, is_bad);
 	if (err) {
 		chfs_err(checking block is bad failed\n);
 		return err;
 	}
-	if (isbad) {
+	if (is_bad) {
 		si-bad_peb_cnt++;
 		return 0;
 	}



CVS commit: src/sys/ufs/chfs

2011-11-24 Thread Adam Hoka
Module Name:src
Committed By:   ahoka
Date:   Thu Nov 24 19:14:31 UTC 2011

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

Log Message:
fix build failure on amd64 due to incorrect format string


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/ufs/chfs/chfs.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/chfs.h
diff -u src/sys/ufs/chfs/chfs.h:1.1 src/sys/ufs/chfs/chfs.h:1.2
--- src/sys/ufs/chfs/chfs.h:1.1	Thu Nov 24 15:51:31 2011
+++ src/sys/ufs/chfs/chfs.h	Thu Nov 24 19:14:30 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: chfs.h,v 1.1 2011/11/24 15:51:31 ahoka Exp $	*/
+/*	$NetBSD: chfs.h,v 1.2 2011/11/24 19:14:30 ahoka Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -528,7 +528,8 @@ chfs_nref_to_vc(struct chfs_node_ref *nr
 	//dbg(NREF_TO_VC: GET IT\n);
 	//dbg(nref_next: %p, lnr: %u, ofs: %u\n, nref-nref_next, nref-nref_lnr, nref-nref_offset);
 	struct chfs_vnode_cache *vc = (struct chfs_vnode_cache *) nref;
-	dbg(vno: %llu, pvno: %llu, hv: %llu, nlink: %u\n, vc-vno, vc-pvno, vc-highest_version, vc-nlink);
+	dbg(vno: %ju, pvno: %ju, hv: %ju, nlink: %u\n, (intmax_t )vc-vno,
+	(intmax_t )vc-pvno, (intmax_t )vc-highest_version, vc-nlink);
 	//return ((struct chfs_vnode_cache *)nref);
 	return vc;
 }



CVS commit: src/sys/ufs/chfs

2011-11-24 Thread Alistair G. Crooks
Module Name:src
Committed By:   agc
Date:   Thu Nov 24 20:50:33 UTC 2011

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

Log Message:
quick workaround for compilation bug on amd64


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/ufs/chfs/chfs_wbuf.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_wbuf.c
diff -u src/sys/ufs/chfs/chfs_wbuf.c:1.1 src/sys/ufs/chfs/chfs_wbuf.c:1.2
--- src/sys/ufs/chfs/chfs_wbuf.c:1.1	Thu Nov 24 15:51:32 2011
+++ src/sys/ufs/chfs/chfs_wbuf.c	Thu Nov 24 20:50:33 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: chfs_wbuf.c,v 1.1 2011/11/24 15:51:32 ahoka Exp $	*/
+/*	$NetBSD: chfs_wbuf.c,v 1.2 2011/11/24 20:50:33 agc Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -176,7 +176,8 @@ chfs_write_wbuf(struct chfs_mount* chmp,
 	//dbg(3. wbuf ofs: %zu, len: %zu\n, chmp-chm_wbuf_ofs, chmp-chm_wbuf_len);
 
 	if (to != PAD(chmp-chm_wbuf_ofs + chmp-chm_wbuf_len)) {
-		dbg(to: %llu != %zu\n, to, PAD(chmp-chm_wbuf_ofs + chmp-chm_wbuf_len));
+		dbg(to: %llu != %zu\n, (unsigned long long)to,
+			PAD(chmp-chm_wbuf_ofs + chmp-chm_wbuf_len));
 		dbg(Non-contiguous write\n);
 		panic(BUG\n);
 	}



CVS commit: src/sys/ufs/chfs

2011-11-24 Thread Alistair G. Crooks
Module Name:src
Committed By:   agc
Date:   Thu Nov 24 21:09:37 UTC 2011

Modified Files:
src/sys/ufs/chfs: chfs_gc.c chfs_readinode.c chfs_scan.c chfs_subr.c
chfs_vfsops.c chfs_vnode.c chfs_vnops.c chfs_write.c

Log Message:
quick workaround to make this compile, with thanks to Hisashi Fujinaka for the
nudge.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/ufs/chfs/chfs_gc.c \
src/sys/ufs/chfs/chfs_readinode.c src/sys/ufs/chfs/chfs_scan.c \
src/sys/ufs/chfs/chfs_subr.c src/sys/ufs/chfs/chfs_vfsops.c \
src/sys/ufs/chfs/chfs_vnode.c src/sys/ufs/chfs/chfs_vnops.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_gc.c
diff -u src/sys/ufs/chfs/chfs_gc.c:1.1 src/sys/ufs/chfs/chfs_gc.c:1.2
--- src/sys/ufs/chfs/chfs_gc.c:1.1	Thu Nov 24 15:51:31 2011
+++ src/sys/ufs/chfs/chfs_gc.c	Thu Nov 24 21:09:37 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: chfs_gc.c,v 1.1 2011/11/24 15:51:31 ahoka Exp $	*/
+/*	$NetBSD: chfs_gc.c,v 1.2 2011/11/24 21:09:37 agc Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -208,7 +208,7 @@ chfs_gc_fetch_inode(struct chfs_mount *c
 	struct vnode *vp = NULL;
 	struct chfs_vnode_cache *vc;
 	struct chfs_inode *ip;
-	dbg_gc(fetch inode %llu\n, vno);
+	dbg_gc(fetch inode %llu\n, (unsigned long long)vno);
 
 	if (unlinked) {
 		dbg_gc(unlinked\n);
@@ -439,14 +439,16 @@ chfs_gcollect_pass(struct chfs_mount *ch
 			mutex_exit(chmp-chm_lock_sizes);
 			mutex_exit(chmp-chm_lock_mountfields);
 			dbg_gc(checked_vno (#%llu)  max_vno (#%llu)\n,
-			chmp-chm_checked_vno, chmp-chm_max_vno);
+			(unsigned long long)chmp-chm_checked_vno,
+			(unsigned long long)chmp-chm_max_vno);
 			return ENOSPC;
 		}
 
 		mutex_exit(chmp-chm_lock_sizes);
 
 		mutex_enter(chmp-chm_lock_vnocache);
-		dbg_gc(checking vno #%llu\n, chmp-chm_checked_vno);
+		dbg_gc(checking vno #%llu\n,
+			(unsigned long long)chmp-chm_checked_vno);
 		dbg_gc(get vnode cache\n);
 		vc = chfs_vnode_cache_get(chmp, chmp-chm_checked_vno++);
 
@@ -600,7 +602,7 @@ chfs_gcollect_pass(struct chfs_mount *ch
 		mutex_exit(chmp-chm_lock_mountfields);
 		panic(CHFS BUG - vc state unchecked,
 		 checking or gc (vno #%llu, num #%d)\n,
-		vc-vno, vc-state);
+		(unsigned long long)vc-vno, vc-state);
 
 case VNO_STATE_READING:
 		mutex_exit(chmp-chm_lock_vnocache);
@@ -896,7 +898,8 @@ chfs_gcollect_live(struct chfs_mount *ch
 	} else {
 		dbg_gc(Nref at leb #%u offset 0x%08x wasn't in node list
 		 for ino #%llu\n,
-		nref-nref_lnr, CHFS_GET_OFS(nref-nref_offset), ip-ino);
+		nref-nref_lnr, CHFS_GET_OFS(nref-nref_offset),
+		(unsigned long long)ip-ino);
 		if (CHFS_REF_OBSOLETE(nref)) {
 			dbg_gc(But it's obsolete so we don't mind
 			 too much.\n);
Index: src/sys/ufs/chfs/chfs_readinode.c
diff -u src/sys/ufs/chfs/chfs_readinode.c:1.1 src/sys/ufs/chfs/chfs_readinode.c:1.2
--- src/sys/ufs/chfs/chfs_readinode.c:1.1	Thu Nov 24 15:51:31 2011
+++ src/sys/ufs/chfs/chfs_readinode.c	Thu Nov 24 21:09:37 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: chfs_readinode.c,v 1.1 2011/11/24 15:51:31 ahoka Exp $	*/
+/*	$NetBSD: chfs_readinode.c,v 1.2 2011/11/24 21:09:37 agc Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -391,8 +391,11 @@ chfs_add_tmp_dnode_to_tree(struct chfs_m
 tmp_td-node-ofs + tmp_td-node-size = end_ofs) {
 /* New node entirely overlapped by 'this' */
 if (!chfs_check_td_node(chmp, tmp_td)) {
-	dbg(this version: %llu\n, tmp_td-version);
-	dbg(this ofs: %llu, size: %u\n, tmp_td-node-ofs, tmp_td-node-size);
+	dbg(this version: %llu\n,
+		(unsigned long long)tmp_td-version);
+	dbg(this ofs: %llu, size: %u\n,
+		(unsigned long long)tmp_td-node-ofs,
+		tmp_td-node-size);
 	dbg(calling kill td 4\n);
 	chfs_kill_td(chmp, newtd);
 	return 0;
@@ -895,7 +898,7 @@ chfs_build_fragtree(struct chfs_mount *c
 } else {
 	if (tmp_td-version  high_ver) {
 		high_ver = tmp_td-version;
-		dbg(highver: %llu\n, high_ver);
+		dbg(highver: %llu\n, (unsigned long long)high_ver);
 		rii-latest_ref = tmp_td-node-nref;
 	}
 
@@ -959,8 +962,10 @@ retry:
 		break;
 	case VNO_STATE_PRESENT:
 	case VNO_STATE_READING:
-		chfs_err(Reading inode #%llu in state %d!\n, vc-vno, vc-state);
-		chfs_err(wants to read a nonexistent ino %llu\n, vc-vno);
+		chfs_err(Reading inode #%llu in state %d!\n,
+			(unsigned long long)vc-vno, vc-state);
+		chfs_err(wants to read a nonexistent ino %llu\n,
+			(unsigned long long)vc-vno);
 		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.1 src/sys/ufs/chfs/chfs_scan.c:1.2
--- src/sys/ufs/chfs/chfs_scan.c:1.1	Thu Nov 24 15:51:31 2011
+++ src/sys/ufs/chfs/chfs_scan.c	Thu Nov 24 21:09:37 2011
@@ -1,4 

CVS commit: src/sys/ufs/chfs

2011-11-24 Thread Alistair G. Crooks
Module Name:src
Committed By:   agc
Date:   Thu Nov 24 21:22:39 UTC 2011

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

Log Message:
i missed a file - quick workaround for compilation bugs on amd64


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/ufs/chfs/chfs_build.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.1 src/sys/ufs/chfs/chfs_build.c:1.2
--- src/sys/ufs/chfs/chfs_build.c:1.1	Thu Nov 24 15:51:31 2011
+++ src/sys/ufs/chfs/chfs_build.c	Thu Nov 24 21:22:39 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: chfs_build.c,v 1.1 2011/11/24 15:51:31 ahoka Exp $	*/
+/*	$NetBSD: chfs_build.c,v 1.2 2011/11/24 21:22:39 agc Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -91,7 +91,8 @@ chfs_build_set_vnodecache_nlink(struct c
 			if (child_vc-pvno) {
 chfs_err(found a hard link: child dir: %s
 , (vno: %llu) of dir vno: %llu\n,
-fd-name, fd-vno, vc-vno);
+fd-name, (unsigned long long)fd-vno,
+(unsigned long long)vc-vno);
 			} else {
 //dbg(child_vc-pvno =
 //	vc-vno; pvno = %d\n, child_vc-pvno);
@@ -119,7 +120,7 @@ chfs_build_remove_unlinked_vnode(struct 
 	struct chfs_dirent *fd, *tmpfd;
 
 	dbg(START\n);
-	dbg(vno: %llu\n, vc-vno);
+	dbg(vno: %llu\n, (unsigned long long)vc-vno);
 
 	nref = vc-dnode;
 	KASSERT(mutex_owned(chmp-chm_lock_mountfields));
@@ -144,8 +145,8 @@ chfs_build_remove_unlinked_vnode(struct 
 			struct chfs_vnode_cache *child_vc;
 //			fd = vc-scan_dirents;
 			dbg(dirent dump:\n);
-			dbg( -vno: %llu\n, fd-vno);
-			dbg( -version: %llu\n, fd-version);
+			dbg( -vno: %llu\n, (unsigned long long)fd-vno);
+			dbg( -version: %llu\n, (unsigned long long)fd-version);
 			dbg( -nhash:   0x%x\n, fd-nhash);
 			dbg( -nsize:   %d\n, fd-nsize);
 			dbg( -name:%s\n, fd-name);
@@ -310,7 +311,7 @@ chfs_build_filesystem(struct chfs_mount 
 	for (i = 0; i  VNODECACHE_SIZE; i++) {
 		vc = chmp-chm_vnocache_hash[i];
 		while (vc) {
-			dbg(vc-vno: %llu\n, vc-vno);
+			dbg(vc-vno: %llu\n, (unsigned long long)vc-vno);
 			if (!TAILQ_EMPTY(vc-scan_dirents))
 chfs_build_set_vnodecache_nlink(chmp, vc);
 			vc = vc-next;



CVS commit: src/sys/ufs/chfs

2011-11-24 Thread Adam Hoka
Module Name:src
Committed By:   ahoka
Date:   Thu Nov 24 21:38:44 UTC 2011

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

Log Message:
disable dbg messages (they break the build on amd64)


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/ufs/chfs/chfs.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/chfs.h
diff -u src/sys/ufs/chfs/chfs.h:1.2 src/sys/ufs/chfs/chfs.h:1.3
--- src/sys/ufs/chfs/chfs.h:1.2	Thu Nov 24 19:14:30 2011
+++ src/sys/ufs/chfs/chfs.h	Thu Nov 24 21:38:44 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: chfs.h,v 1.2 2011/11/24 19:14:30 ahoka Exp $	*/
+/*	$NetBSD: chfs.h,v 1.3 2011/11/24 21:38:44 ahoka Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -38,8 +38,10 @@
 #ifndef __CHFS_H__
 #define __CHFS_H__
 
+#if 0
 #define DBG_MSG
 #define DBG_MSG_GC
+#endif
 
 #include sys/param.h
 #include sys/kernel.h



CVS commit: src/sys/ufs

2011-11-23 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Wed Nov 23 19:42:10 UTC 2011

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

Log Message:
If ufs_balloc_range() fails, make sure to call ?fs_truncate() to
reset v_writesize to the right value.
If v_writesize is left larger than the allocated blocks, we may have
the same issue as the one described in
http://mail-index.netbsd.org/tech-kern/2010/02/02/msg007156.html


To generate a diff of this commit:
cvs rdiff -u -r1.107 -r1.108 src/sys/ufs/ffs/ffs_inode.c
cvs rdiff -u -r1.125 -r1.126 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/ffs/ffs_inode.c
diff -u src/sys/ufs/ffs/ffs_inode.c:1.107 src/sys/ufs/ffs/ffs_inode.c:1.108
--- src/sys/ufs/ffs/ffs_inode.c:1.107	Thu Jun 16 09:21:03 2011
+++ src/sys/ufs/ffs/ffs_inode.c	Wed Nov 23 19:42:10 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_inode.c,v 1.107 2011/06/16 09:21:03 hannken Exp $	*/
+/*	$NetBSD: ffs_inode.c,v 1.108 2011/11/23 19:42:10 bouyer Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_inode.c,v 1.107 2011/06/16 09:21:03 hannken Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_inode.c,v 1.108 2011/11/23 19:42:10 bouyer Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -269,8 +269,11 @@ ffs_truncate(struct vnode *ovp, off_t le
 			uvm_vnp_setwritesize(ovp, eob);
 			error = ufs_balloc_range(ovp, osize, eob - osize,
 			cred, aflag);
-			if (error)
+			if (error) {
+(void) ffs_truncate(ovp, osize,
+ioflag  IO_SYNC, cred);
 return error;
+			}
 			if (ioflag  IO_SYNC) {
 mutex_enter(ovp-v_interlock);
 VOP_PUTPAGES(ovp,

Index: src/sys/ufs/lfs/lfs_inode.c
diff -u src/sys/ufs/lfs/lfs_inode.c:1.125 src/sys/ufs/lfs/lfs_inode.c:1.126
--- src/sys/ufs/lfs/lfs_inode.c:1.125	Mon Jul 11 08:27:40 2011
+++ src/sys/ufs/lfs/lfs_inode.c	Wed Nov 23 19:42:10 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_inode.c,v 1.125 2011/07/11 08:27:40 hannken Exp $	*/
+/*	$NetBSD: lfs_inode.c,v 1.126 2011/11/23 19:42:10 bouyer Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: lfs_inode.c,v 1.125 2011/07/11 08:27:40 hannken Exp $);
+__KERNEL_RCSID(0, $NetBSD: lfs_inode.c,v 1.126 2011/11/23 19:42:10 bouyer Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_quota.h
@@ -276,8 +276,11 @@ lfs_truncate(struct vnode *ovp, off_t le
 uvm_vnp_setwritesize(ovp, eob);
 error = ufs_balloc_range(ovp, osize,
 eob - osize, cred, aflags);
-if (error)
+if (error) {
+	(void) lfs_truncate(ovp, osize,
+		ioflag  IO_SYNC, cred);
 	return error;
+}
 if (ioflag  IO_SYNC) {
 	mutex_enter(ovp-v_interlock);
 	VOP_PUTPAGES(ovp,



CVS commit: src/sys/ufs/ffs

2011-11-13 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Nov 13 23:10:40 UTC 2011

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

Log Message:
use getdiskinfo()


To generate a diff of this commit:
cvs rdiff -u -r1.269 -r1.270 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.269 src/sys/ufs/ffs/ffs_vfsops.c:1.270
--- src/sys/ufs/ffs/ffs_vfsops.c:1.269	Fri Oct  7 05:35:07 2011
+++ src/sys/ufs/ffs/ffs_vfsops.c	Sun Nov 13 18:10:34 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.269 2011/10/07 09:35:07 hannken Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.270 2011/11/13 23:10:34 christos Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.269 2011/10/07 09:35:07 hannken Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.270 2011/11/13 23:10:34 christos Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -79,6 +79,7 @@ __KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c
 #include sys/mount.h
 #include sys/buf.h
 #include sys/device.h
+#include sys/disk.h
 #include sys/mbuf.h
 #include sys/file.h
 #include sys/disklabel.h
@@ -614,7 +615,7 @@ ffs_reload(struct mount *mp, kauth_cred_
 	void *space;
 	struct buf *bp;
 	struct fs *fs, *newfs;
-	struct partinfo dpart;
+	struct dkwedge_info dkw;
 	int i, bsize, blks, error;
 	int32_t *lp;
 	struct ufsmount *ump;
@@ -683,10 +684,9 @@ ffs_reload(struct mount *mp, kauth_cred_
 	/* First check to see if this is tagged as an Apple UFS filesystem
 	 * in the disklabel
 	 */
-	if ((VOP_IOCTL(devvp, DIOCGPART, dpart, FREAD, cred) == 0) 
-		(dpart.part-p_fstype == FS_APPLEUFS)) {
+	if (getdiskinfo(devvp, dkw) == 0 
+	strcmp(dkw.dkw_ptype, DKW_PTYPE_APPLEUFS) == 0)
 		ump-um_flags |= UFS_ISAPPLEUFS;
-	}
 #ifdef APPLE_UFS
 	else {
 		/* Manually look for an apple ufs label, and if a valid one
@@ -852,7 +852,7 @@ ffs_mountfs(struct vnode *devvp, struct 
 	struct buf *bp;
 	struct fs *fs;
 	dev_t dev;
-	struct partinfo dpart;
+	struct dkwedge_info dkw;
 	void *space;
 	daddr_t sblockloc, fsblockloc;
 	int blks, fstype;
@@ -1061,10 +1061,9 @@ ffs_mountfs(struct vnode *devvp, struct 
 	/* First check to see if this is tagged as an Apple UFS filesystem
 	 * in the disklabel
 	 */
-	if ((VOP_IOCTL(devvp, DIOCGPART, dpart, FREAD, cred) == 0) 
-		(dpart.part-p_fstype == FS_APPLEUFS)) {
+	if (getdiskinfo(devvp, dkw) == 0 
+	strcmp(dkw.dkw_ptype, DKW_PTYPE_APPLEUFS) == 0)
 		ump-um_flags |= UFS_ISAPPLEUFS;
-	}
 #ifdef APPLE_UFS
 	else {
 		/* Manually look for an apple ufs label, and if a valid one



CVS commit: src/sys/ufs/ufs

2011-10-09 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Sun Oct  9 21:15:34 UTC 2011

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

Log Message:
add forward declarations for the VOP args structures
so that fstat can include this file.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/ufs/ufs/extattr.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/extattr.h
diff -u src/sys/ufs/ufs/extattr.h:1.9 src/sys/ufs/ufs/extattr.h:1.10
--- src/sys/ufs/ufs/extattr.h:1.9	Fri Jun 17 14:23:52 2011
+++ src/sys/ufs/ufs/extattr.h	Sun Oct  9 21:15:34 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: extattr.h,v 1.9 2011/06/17 14:23:52 manu Exp $	*/
+/*	$NetBSD: extattr.h,v 1.10 2011/10/09 21:15:34 chs Exp $	*/
 
 /*-
  * Copyright (c) 1999-2001 Robert N. M. Watson
@@ -110,9 +110,13 @@ int	ufs_extattr_autostart(struct mount *
 void	ufs_extattr_stop(struct mount *mp, struct lwp *l);
 int	ufs_extattrctl(struct mount *mp, int cmd, struct vnode *filename,
 	int attrnamespace, const char *attrname);
+struct vop_getextattr_args;
 int	ufs_getextattr(struct vop_getextattr_args *ap);
+struct vop_deleteextattr_args;
 int	ufs_deleteextattr(struct vop_deleteextattr_args *ap);
+struct vop_setextattr_args;
 int	ufs_setextattr(struct vop_setextattr_args *ap);
+struct vop_listextattr_args;
 int	ufs_listextattr(struct vop_listextattr_args *ap);
 void	ufs_extattr_vnode_inactive(struct vnode *vp, struct lwp *l);
 



CVS commit: src/sys/ufs/ufs

2011-09-26 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Sep 27 01:30:54 UTC 2011

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

Log Message:
use FFS_MAXNAMLEN instead of NAME_MAX, making sure that it matches with
EXT2FS_MAXNAMLEN and LFS_MAXNAMLEN.


To generate a diff of this commit:
cvs rdiff -u -r1.202 -r1.203 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.202 src/sys/ufs/ufs/ufs_vnops.c:1.203
--- src/sys/ufs/ufs/ufs_vnops.c:1.202	Wed Aug  3 06:03:51 2011
+++ src/sys/ufs/ufs/ufs_vnops.c	Mon Sep 26 21:30:54 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_vnops.c,v 1.202 2011/08/03 10:03:51 hannken Exp $	*/
+/*	$NetBSD: ufs_vnops.c,v 1.203 2011/09/27 01:30:54 christos Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_vnops.c,v 1.202 2011/08/03 10:03:51 hannken Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_vnops.c,v 1.203 2011/09/27 01:30:54 christos Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -108,6 +108,8 @@ __KERNEL_RCSID(0, $NetBSD: ufs_vnops.c,
 #include ufs/ffs/ffs_extern.h
 #include ufs/lfs/lfs_extern.h
 
+CTASSERT(EXT2FS_MAXNAMLEN == FFS_MAXNAMLEN);
+CTASSERT(LFS_MAXNAMLEN == FFS_MAXNAMLEN);
 #include uvm/uvm.h
 
 static int ufs_chmod(struct vnode *, int, kauth_cred_t, struct lwp *);
@@ -2706,7 +2708,7 @@ ufs_pathconf(void *v)
 		*ap-a_retval = LINK_MAX;
 		return (0);
 	case _PC_NAME_MAX:
-		*ap-a_retval = NAME_MAX;
+		*ap-a_retval = FFS_MAXNAMLEN;
 		return (0);
 	case _PC_PATH_MAX:
 		*ap-a_retval = PATH_MAX;



CVS commit: src/sys/ufs/ufs

2011-09-26 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Sep 27 01:43:39 UTC 2011

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

Log Message:
it is __CTASSERT()


To generate a diff of this commit:
cvs rdiff -u -r1.203 -r1.204 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.203 src/sys/ufs/ufs/ufs_vnops.c:1.204
--- src/sys/ufs/ufs/ufs_vnops.c:1.203	Mon Sep 26 21:30:54 2011
+++ src/sys/ufs/ufs/ufs_vnops.c	Mon Sep 26 21:43:39 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_vnops.c,v 1.203 2011/09/27 01:30:54 christos Exp $	*/
+/*	$NetBSD: ufs_vnops.c,v 1.204 2011/09/27 01:43:39 christos Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_vnops.c,v 1.203 2011/09/27 01:30:54 christos Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_vnops.c,v 1.204 2011/09/27 01:43:39 christos Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -108,10 +108,11 @@ __KERNEL_RCSID(0, $NetBSD: ufs_vnops.c,
 #include ufs/ffs/ffs_extern.h
 #include ufs/lfs/lfs_extern.h
 
-CTASSERT(EXT2FS_MAXNAMLEN == FFS_MAXNAMLEN);
-CTASSERT(LFS_MAXNAMLEN == FFS_MAXNAMLEN);
 #include uvm/uvm.h
 
+__CTASSERT(EXT2FS_MAXNAMLEN == FFS_MAXNAMLEN);
+__CTASSERT(LFS_MAXNAMLEN == FFS_MAXNAMLEN);
+
 static int ufs_chmod(struct vnode *, int, kauth_cred_t, struct lwp *);
 static int ufs_chown(struct vnode *, uid_t, gid_t, kauth_cred_t,
 struct lwp *);



CVS commit: src/sys/ufs/ufs

2011-09-26 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Sep 27 02:10:32 UTC 2011

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

Log Message:
include the proper headers to make {LFS,EXT2FS}_MAXNAMLEN visible


To generate a diff of this commit:
cvs rdiff -u -r1.204 -r1.205 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.204 src/sys/ufs/ufs/ufs_vnops.c:1.205
--- src/sys/ufs/ufs/ufs_vnops.c:1.204	Mon Sep 26 21:43:39 2011
+++ src/sys/ufs/ufs/ufs_vnops.c	Mon Sep 26 22:10:32 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_vnops.c,v 1.204 2011/09/27 01:43:39 christos Exp $	*/
+/*	$NetBSD: ufs_vnops.c,v 1.205 2011/09/27 02:10:32 christos Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_vnops.c,v 1.204 2011/09/27 01:43:39 christos Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_vnops.c,v 1.205 2011/09/27 02:10:32 christos Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -105,8 +105,10 @@ __KERNEL_RCSID(0, $NetBSD: ufs_vnops.c,
 #include ufs/ufs/dirhash.h
 #endif
 #include ufs/ext2fs/ext2fs_extern.h
+#include ufs/ext2fs/ext2fs_dir.h
 #include ufs/ffs/ffs_extern.h
 #include ufs/lfs/lfs_extern.h
+#include ufs/lfs/lfs.h
 
 #include uvm/uvm.h
 



CVS commit: src/sys/ufs

2011-09-20 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Tue Sep 20 14:01:33 UTC 2011

Modified Files:
src/sys/ufs/ffs: ffs_alloc.c
src/sys/ufs/lfs: lfs_vnops.c
src/sys/ufs/ufs: ufs_inode.c

Log Message:
strengthen the assertions about pages existing during block allocation,
which were incorrectly relaxed last year.  add some comments so that
the intent of these is hopefully clearer.

in ufs_balloc_range(), don't free pages or mark them dirty if
allocating their backing store failed.  this fixes PR 45369.


To generate a diff of this commit:
cvs rdiff -u -r1.128 -r1.129 src/sys/ufs/ffs/ffs_alloc.c
cvs rdiff -u -r1.237 -r1.238 src/sys/ufs/lfs/lfs_vnops.c
cvs rdiff -u -r1.87 -r1.88 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_alloc.c
diff -u src/sys/ufs/ffs/ffs_alloc.c:1.128 src/sys/ufs/ffs/ffs_alloc.c:1.129
--- src/sys/ufs/ffs/ffs_alloc.c:1.128	Sun Jun 12 03:36:00 2011
+++ src/sys/ufs/ffs/ffs_alloc.c	Tue Sep 20 14:01:32 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_alloc.c,v 1.128 2011/06/12 03:36:00 rmind Exp $	*/
+/*	$NetBSD: ffs_alloc.c,v 1.129 2011/09/20 14:01:32 chs Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -70,11 +70,12 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_alloc.c,v 1.128 2011/06/12 03:36:00 rmind Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_alloc.c,v 1.129 2011/09/20 14:01:32 chs Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
 #include opt_quota.h
+#include opt_uvm_page_trkown.h
 #endif
 
 #include sys/param.h
@@ -100,6 +101,10 @@
 #include ufs/ffs/fs.h
 #include ufs/ffs/ffs_extern.h
 
+#ifdef UVM_PAGE_TRKOWN
+#include uvm/uvm.h
+#endif
+
 static daddr_t ffs_alloccg(struct inode *, int, daddr_t, int, int);
 static daddr_t ffs_alloccgblk(struct inode *, struct buf *, daddr_t, int);
 static ino_t ffs_dirpref(struct inode *);
@@ -184,17 +189,36 @@
 	KASSERT(mutex_owned(ump-um_lock));
 
 #ifdef UVM_PAGE_TRKOWN
+
+	/*
+	 * Sanity-check that allocations within the file size
+	 * do not allow other threads to read the stale contents
+	 * of newly allocated blocks.
+	 * Usually pages will exist to cover the new allocation.
+	 * There is an optimization in ffs_write() where we skip
+	 * creating pages if several conditions are met:
+	 *  - the file must not be mapped (in any user address space).
+	 *  - the write must cover whole pages and whole blocks.
+	 * If those conditions are not met then pages must exist and
+	 * be locked by the current thread.
+	 */
+
 	if (ITOV(ip)-v_type == VREG 
 	lblktosize(fs, (voff_t)lbn)  round_page(ITOV(ip)-v_size)) {
 		struct vm_page *pg;
-		struct uvm_object *uobj = ITOV(ip)-v_uobj;
+		struct vnode *vp = ITOV(ip);
+		struct uvm_object *uobj = vp-v_uobj;
 		voff_t off = trunc_page(lblktosize(fs, lbn));
 		voff_t endoff = round_page(lblktosize(fs, lbn) + size);
 
 		mutex_enter(uobj-vmobjlock);
 		while (off  endoff) {
 			pg = uvm_pagelookup(uobj, off);
-			KASSERT(pg == NULL || pg-owner == curproc-p_pid);
+			KASSERT((pg == NULL  (vp-v_vflag  VV_MAPPED) == 0 
+ (size  PAGE_MASK) == 0  
+ blkoff(fs, size) == 0) ||
+(pg != NULL  pg-owner == curproc-p_pid 
+ pg-lowner == curlwp-l_lid));
 			off += PAGE_SIZE;
 		}
 		mutex_exit(uobj-vmobjlock);
@@ -292,6 +316,18 @@
 	KASSERT(mutex_owned(ump-um_lock));
 
 #ifdef UVM_PAGE_TRKOWN
+
+	/*
+	 * Sanity-check that allocations within the file size
+	 * do not allow other threads to read the stale contents
+	 * of newly allocated blocks.
+	 * Unlike in ffs_alloc(), here pages must always exist
+	 * for such allocations, because only the last block of a file
+	 * can be a fragment and ffs_write() will reallocate the
+	 * fragment to the new size using ufs_balloc_range(),
+	 * which always creates pages to cover blocks it allocates.
+	 */
+
 	if (ITOV(ip)-v_type == VREG) {
 		struct vm_page *pg;
 		struct uvm_object *uobj = ITOV(ip)-v_uobj;
@@ -301,8 +337,8 @@
 		mutex_enter(uobj-vmobjlock);
 		while (off  endoff) {
 			pg = uvm_pagelookup(uobj, off);
-			KASSERT(pg == NULL || pg-owner == curproc-p_pid);
-			KASSERT((pg-flags  PG_CLEAN) == 0);
+			KASSERT(pg-owner == curproc-p_pid 
+pg-lowner == curlwp-l_lid);
 			off += PAGE_SIZE;
 		}
 		mutex_exit(uobj-vmobjlock);

Index: src/sys/ufs/lfs/lfs_vnops.c
diff -u src/sys/ufs/lfs/lfs_vnops.c:1.237 src/sys/ufs/lfs/lfs_vnops.c:1.238
--- src/sys/ufs/lfs/lfs_vnops.c:1.237	Tue Jul 12 16:59:48 2011
+++ src/sys/ufs/lfs/lfs_vnops.c	Tue Sep 20 14:01:33 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_vnops.c,v 1.237 2011/07/12 16:59:48 dholland Exp $	*/
+/*	$NetBSD: lfs_vnops.c,v 1.238 2011/09/20 14:01:33 chs Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,10 +60,11 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: lfs_vnops.c,v 1.237 2011/07/12 16:59:48 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: lfs_vnops.c,v 

CVS commit: src/sys/ufs/ufs

2011-09-19 Thread Greg Troxel
Module Name:src
Committed By:   gdt
Date:   Mon Sep 19 11:18:02 UTC 2011

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

Log Message:
Remove prototype for the departed wapbl_ufs_rename.

ok dholland@


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 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/ufs/ufs_wapbl.h
diff -u src/sys/ufs/ufs/ufs_wapbl.h:1.6 src/sys/ufs/ufs/ufs_wapbl.h:1.7
--- src/sys/ufs/ufs/ufs_wapbl.h:1.6	Wed Nov 18 12:22:48 2009
+++ src/sys/ufs/ufs/ufs_wapbl.h	Mon Sep 19 11:18:01 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_wapbl.h,v 1.6 2009/11/18 12:22:48 yamt Exp $	*/
+/*	$NetBSD: ufs_wapbl.h,v 1.7 2011/09/19 11:18:01 gdt Exp $	*/
 
 /*-
  * Copyright (c) 2003,2006,2008 The NetBSD Foundation, Inc.
@@ -90,8 +90,6 @@
 #error Undefine WAPBL_DEBUG_INODES or update the code.  Have a nice day.
 #endif
 
-int	wapbl_ufs_rename(void *v);
-
 #ifdef WAPBL_DEBUG_INODES
 void	ufs_wapbl_verify_inodes(struct mount *, const char *);
 #endif



CVS commit: src/sys/ufs/ufs

2011-07-29 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jul 29 22:18:57 UTC 2011

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

Log Message:
In ufs_rename, declare oldparent and newparent ino_t, not int.

XXX There should be an automatic test for this somewhere.

ok dholland


To generate a diff of this commit:
cvs rdiff -u -r1.200 -r1.201 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.200 src/sys/ufs/ufs/ufs_vnops.c:1.201
--- src/sys/ufs/ufs/ufs_vnops.c:1.200	Mon Jul 18 06:45:47 2011
+++ src/sys/ufs/ufs/ufs_vnops.c	Fri Jul 29 22:18:56 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_vnops.c,v 1.200 2011/07/18 06:45:47 dholland Exp $	*/
+/*	$NetBSD: ufs_vnops.c,v 1.201 2011/07/29 22:18:56 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_vnops.c,v 1.200 2011/07/18 06:45:47 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_vnops.c,v 1.201 2011/07/29 22:18:56 riastradh Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -1317,7 +1317,8 @@
 	struct inode		*ip, *txp, *fxp, *tdp, *fdp;
 	struct mount		*mp;
 	struct direct		*newdir;
-	int			doingdirectory, oldparent, newparent, error;
+	int			doingdirectory, error;
+	ino_t			oldparent, newparent;
 
 	struct ufs_lookup_results from_ulr, to_ulr;
 
@@ -1327,7 +1328,8 @@
 	fdvp = ap-a_fdvp;
 	tcnp = ap-a_tcnp;
 	fcnp = ap-a_fcnp;
-	doingdirectory = oldparent = newparent = error = 0;
+	doingdirectory = error = 0;
+	oldparent = newparent = 0;
 
 	/* save the supplemental lookup results as they currently exist */
 	from_ulr = VTOI(fdvp)-i_crap;



CVS commit: src/sys/ufs/ufs

2011-07-18 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Mon Jul 18 06:45:47 UTC 2011

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

Log Message:
Eliminate the old ufs_rename. The only reason the WAPBL one was
different is that in order to avoid issues with the WAPBL journal lock
the wrong locking had to be changed to different wrong locking. This
is now moot.

I have not hand-validated that the current two copies of rename are
equivalent, or that the locking fixes merged with the old rename
produce code that is textually identical (modulo WAPBL calls that do
nothing when WAPBL is turned off) to the WAPBL rename... but I did
this check when preparing my previous round of rename patches last
year and all updates since have been applied to both.


To generate a diff of this commit:
cvs rdiff -u -r1.199 -r1.200 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.199 src/sys/ufs/ufs/ufs_vnops.c:1.200
--- src/sys/ufs/ufs/ufs_vnops.c:1.199	Mon Jul 18 06:45:27 2011
+++ src/sys/ufs/ufs/ufs_vnops.c	Mon Jul 18 06:45:47 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_vnops.c,v 1.199 2011/07/18 06:45:27 dholland Exp $	*/
+/*	$NetBSD: ufs_vnops.c,v 1.200 2011/07/18 06:45:47 dholland Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_vnops.c,v 1.199 2011/07/18 06:45:27 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_vnops.c,v 1.200 2011/07/18 06:45:47 dholland Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -1300,15 +1300,9 @@
  *directory was moved and the parent of the destination
  *is different from the source, patch the .. entry in the
  *directory.
- *
- * WAPBL NOTE: wapbl_ufs_rename derived from ufs_rename in ufs_vnops.c
- * ufs_vnops.c netbsd cvs revision 1.108
- * which has the berkeley copyright above
- * changes introduced to ufs_rename since netbsd cvs revision 1.164
- * will need to be ported into wapbl_ufs_rename
  */
 int
-wapbl_ufs_rename(void *v)
+ufs_rename(void *v)
 {
 	struct vop_rename_args  /* {
 		struct vnode		*a_fdvp;
@@ -1970,406 +1964,6 @@
 }
 
 int
-ufs_rename(void *v)
-{
-	struct vop_rename_args  /* {
-		struct vnode		*a_fdvp;
-		struct vnode		*a_fvp;
-		struct componentname	*a_fcnp;
-		struct vnode		*a_tdvp;
-		struct vnode		*a_tvp;
-		struct componentname	*a_tcnp;
-	} */ *ap = v;
-	struct vnode		*tvp, *tdvp, *fvp, *fdvp;
-	struct componentname	*tcnp, *fcnp;
-	struct inode		*ip, *xp, *dp;
-	struct mount		*mp;
-	struct direct		*newdir;
-	int			doingdirectory, oldparent, newparent, error;
-	struct ufs_lookup_results from_ulr, to_ulr;
-
-#ifdef WAPBL
-	if (ap-a_tdvp-v_mount-mnt_wapbl)
-		return wapbl_ufs_rename(v);
-#endif
-
-	tvp = ap-a_tvp;
-	tdvp = ap-a_tdvp;
-	fvp = ap-a_fvp;
-	fdvp = ap-a_fdvp;
-	tcnp = ap-a_tcnp;
-	fcnp = ap-a_fcnp;
-	doingdirectory = oldparent = newparent = error = 0;
-
-	/* save the supplemental lookup results as they currently exist */
-	from_ulr = VTOI(fdvp)-i_crap;
-	to_ulr = VTOI(tdvp)-i_crap;
-	UFS_CHECK_CRAPCOUNTER(VTOI(fdvp));
-	UFS_CHECK_CRAPCOUNTER(VTOI(tdvp));
-
-	/*
-	 * Check for cross-device rename.
-	 */
-	if ((fvp-v_mount != tdvp-v_mount) ||
-	(tvp  (fvp-v_mount != tvp-v_mount))) {
-		error = EXDEV;
- abortit:
-		VOP_ABORTOP(tdvp, tcnp); /* XXX, why not in NFS? */
-		if (tdvp == tvp)
-			vrele(tdvp);
-		else
-			vput(tdvp);
-		if (tvp)
-			vput(tvp);
-		VOP_ABORTOP(fdvp, fcnp); /* XXX, why not in NFS? */
-		vrele(fdvp);
-		vrele(fvp);
-		return (error);
-	}
-
-	/*
-	 * Check if just deleting a link name.
-	 */
-	if (tvp  ((VTOI(tvp)-i_flags  (IMMUTABLE | APPEND)) ||
-	(VTOI(tdvp)-i_flags  APPEND))) {
-		error = EPERM;
-		goto abortit;
-	}
-	if (fvp == tvp) {
-		if (fvp-v_type == VDIR) {
-			error = EINVAL;
-			goto abortit;
-		}
-
-		/* Release destination completely. */
-		VOP_ABORTOP(tdvp, tcnp);
-		vput(tdvp);
-		vput(tvp);
-
-		/* Delete source. */
-		vrele(fvp);
-		fcnp-cn_flags = ~(MODMASK);
-		fcnp-cn_flags |= LOCKPARENT | LOCKLEAF;
-		fcnp-cn_nameiop = DELETE;
-		vn_lock(fdvp, LK_EXCLUSIVE | LK_RETRY);
-		if ((error = relookup(fdvp, fvp, fcnp, 0))) {
-			vput(fdvp);
-			return (error);
-		}
-		return (VOP_REMOVE(fdvp, fvp, fcnp));
-	}
-	if ((error = vn_lock(fvp, LK_EXCLUSIVE)) != 0)
-		goto abortit;
-	dp = VTOI(fdvp);
-	ip = VTOI(fvp);
-	if ((nlink_t) ip-i_nlink = LINK_MAX) {
-		VOP_UNLOCK(fvp);
-		error = EMLINK;
-		goto abortit;
-	}
-	if ((ip-i_flags  (IMMUTABLE | APPEND)) ||
-		(dp-i_flags  APPEND)) {
-		VOP_UNLOCK(fvp);
-		error = EPERM;
-		goto abortit;
-	}
-	if ((ip-i_mode  IFMT) == IFDIR) {
-		/*
-		 * Avoid ., .., and aliases of . for obvious reasons.
-		 */
-		if ((fcnp-cn_namelen == 1  fcnp-cn_nameptr[0] == '.') ||
-		dp == ip ||
-		(fcnp-cn_flags  ISDOTDOT) ||
-		(tcnp-cn_flags  ISDOTDOT) ||
-		(ip-i_flag  

CVS commit: src/sys/ufs/ufs

2011-07-18 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Mon Jul 18 06:46:05 UTC 2011

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

Log Message:
Remove some unneeded rename-related static const data.
(Why didn't gcc warn that this was unused?)


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

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

Modified files:

Index: src/sys/ufs/ufs/ufs_wapbl.c
diff -u src/sys/ufs/ufs/ufs_wapbl.c:1.21 src/sys/ufs/ufs/ufs_wapbl.c:1.22
--- src/sys/ufs/ufs/ufs_wapbl.c:1.21	Mon Jul 18 06:45:28 2011
+++ src/sys/ufs/ufs/ufs_wapbl.c	Mon Jul 18 06:46:05 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: ufs_wapbl.c,v 1.21 2011/07/18 06:45:28 dholland Exp $ */
+/*  $NetBSD: ufs_wapbl.c,v 1.22 2011/07/18 06:46:05 dholland Exp $ */
 
 /*-
  * Copyright (c) 2003,2006,2008 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_wapbl.c,v 1.21 2011/07/18 06:45:28 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_wapbl.c,v 1.22 2011/07/18 06:46:05 dholland Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -101,14 +101,6 @@
 
 #include uvm/uvm.h
 
-/*
- * A virgin directory (no blushing please).
- */
-static const struct dirtemplate mastertemplate = {
-	0,	12,		DT_DIR,	1,	.,
-	0,	DIRBLKSIZ - 12,	DT_DIR,	2,	..
-};
-
 #ifdef WAPBL_DEBUG_INODES
 #error WAPBL_DEBUG_INODES: not functional before ufs_wapbl.c is updated
 void



CVS commit: src/sys/ufs/ufs

2011-07-17 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sun Jul 17 22:14:47 UTC 2011

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

Log Message:
minor amendment to previous


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

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

Modified files:

Index: src/sys/ufs/ufs/ufs_wapbl.c
diff -u src/sys/ufs/ufs/ufs_wapbl.c:1.17 src/sys/ufs/ufs/ufs_wapbl.c:1.18
--- src/sys/ufs/ufs/ufs_wapbl.c:1.17	Sun Jul 17 22:07:59 2011
+++ src/sys/ufs/ufs/ufs_wapbl.c	Sun Jul 17 22:14:47 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: ufs_wapbl.c,v 1.17 2011/07/17 22:07:59 dholland Exp $ */
+/*  $NetBSD: ufs_wapbl.c,v 1.18 2011/07/17 22:14:47 dholland Exp $ */
 
 /*-
  * Copyright (c) 2003,2006,2008 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_wapbl.c,v 1.17 2011/07/17 22:07:59 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_wapbl.c,v 1.18 2011/07/17 22:14:47 dholland Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -246,7 +246,9 @@
 			VOP_UNLOCK(v1);
 		}
 		VOP_UNLOCK(d1);
-		vrele(v1);
+		if (v1) {
+			vrele(v1);
+		}
 		return ENOENT;
 	}
 	error = do_relookup(d2, ulr2, v2, cn2);
@@ -268,7 +270,9 @@
 			VOP_UNLOCK(v1);
 		}
 		VOP_UNLOCK(d1);
-		vrele(v1);
+		if (v1) {
+			vrele(v1);
+		}
 		return error;
 	}
 	if (v1  v1-v_type != VDIR  v1 != v2) {



CVS commit: src/sys/ufs/ufs

2011-07-17 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Mon Jul 18 01:14:27 UTC 2011

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

Log Message:
More rename tidying.


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

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

Modified files:

Index: src/sys/ufs/ufs/ufs_wapbl.c
diff -u src/sys/ufs/ufs/ufs_wapbl.c:1.19 src/sys/ufs/ufs/ufs_wapbl.c:1.20
--- src/sys/ufs/ufs/ufs_wapbl.c:1.19	Mon Jul 18 01:14:04 2011
+++ src/sys/ufs/ufs/ufs_wapbl.c	Mon Jul 18 01:14:27 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: ufs_wapbl.c,v 1.19 2011/07/18 01:14:04 dholland Exp $ */
+/*  $NetBSD: ufs_wapbl.c,v 1.20 2011/07/18 01:14:27 dholland Exp $ */
 
 /*-
  * Copyright (c) 2003,2006,2008 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_wapbl.c,v 1.19 2011/07/18 01:14:04 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_wapbl.c,v 1.20 2011/07/18 01:14:27 dholland Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -371,18 +371,7 @@
 	 */
 	if (fdvp-v_mount != tdvp-v_mount) {
 		error = EXDEV;
- abortit:
-		VOP_ABORTOP(fdvp, fcnp); /* XXX, why not in NFS? */
-		VOP_ABORTOP(tdvp, tcnp); /* XXX, why not in NFS? */
-		vrele(tdvp);
-		if (tvp) {
-			vrele(tvp);
-		}
-		vrele(fdvp);
-		if (fvp) {
-			vrele(fvp);
-		}
-		return (error);
+		goto abort;
 	}
 
 	/*
@@ -392,7 +381,7 @@
 	(fcnp-cn_namelen == 1  fcnp-cn_nameptr[0] == '.') ||
 	(tcnp-cn_namelen == 1  tcnp-cn_nameptr[0] == '.')) {
 		error = EINVAL;
-		goto abortit;
+		goto abort;
 	}
 	
 	/*
@@ -411,7 +400,7 @@
 			/* directory has been rmdir'd */
 			VOP_UNLOCK(fdvp);
 			error = ENOENT;
-			goto abortit;
+			goto abort;
 		}
 
 		error = do_relookup(fdvp, from_ulr, fvp, fcnp);
@@ -421,7 +410,7 @@
 		}
 		if (error) {
 			VOP_UNLOCK(fdvp);
-			goto abortit;
+			goto abort;
 		}
 
 		/*
@@ -443,7 +432,7 @@
 		error = do_relookup(tdvp, to_ulr, tvp, tcnp);
 		if (error  error != ENOENT) {
 			VOP_UNLOCK(fdvp);
-			goto abortit;
+			goto abort;
 		}
 		if (error == ENOENT) {
 			/*
@@ -483,7 +472,7 @@
 		error = ufs_parentcheck(fdvp, tdvp, fcnp-cn_cred,
 	found_fdvp, illegal_fvp);
 		if (error) {
-			goto abortit;
+			goto abort;
 		}
 
 		/* Must lock in tree order. */
@@ -507,23 +496,14 @@
 			if (illegal_fvp) {
 vrele(illegal_fvp);
 			}
-			goto abortit;
+			goto abort;
 		}
 		KASSERT(fvp != NULL);
 
 		if (illegal_fvp  fvp == illegal_fvp) {
 			vrele(illegal_fvp);
 			error = EINVAL;
-		abort_withlocks:
-			VOP_UNLOCK(fdvp);
-			if (tdvp != fdvp) {
-VOP_UNLOCK(tdvp);
-			}
-			VOP_UNLOCK(fvp);
-			if (tvp  tvp != fvp) {
-VOP_UNLOCK(tvp);
-			}
-			goto abortit;
+			goto abort_withlocks;
 		}
 
 		if (illegal_fvp) {
@@ -620,26 +600,22 @@
 	mp = fdvp-v_mount;
 	fstrans_start(mp, FSTRANS_SHARED);
 
+	if (oldparent != tdp-i_number)
+		newparent = tdp-i_number;
+
 	/*
 	 * If .. must be changed (ie the directory gets a new
 	 * parent) the user must have write permission in the source
 	 * so as to be able to change ...
 	 */
-	error = VOP_ACCESS(fvp, VWRITE, tcnp-cn_cred);
-
-	if (oldparent != tdp-i_number)
-		newparent = tdp-i_number;
 	if (doingdirectory  newparent) {
-		if (error)	/* write access check above */
+		error = VOP_ACCESS(fvp, VWRITE, tcnp-cn_cred);
+		if (error)
 			goto out;
 	}
 
-	/*
-	 * This was moved up to before the journal lock to
-	 * avoid potential deadlock
-	 */
-	fcnp-cn_flags = ~(MODMASK);
-	fcnp-cn_flags |= LOCKPARENT | LOCKLEAF;
+	KASSERT(fdvp != tvp);
+
 	if (newparent) {
 		/* Check for the rename(foo/foo, foo) case. */
 		if (fdvp == tvp) {
@@ -974,6 +950,29 @@
 
 	fstrans_done(mp);
 	return (error);
+
+ abort_withlocks:
+	VOP_UNLOCK(fdvp);
+	if (tdvp != fdvp) {
+		VOP_UNLOCK(tdvp);
+	}
+	VOP_UNLOCK(fvp);
+	if (tvp  tvp != fvp) {
+		VOP_UNLOCK(tvp);
+	}
+
+ abort:
+	VOP_ABORTOP(fdvp, fcnp); /* XXX, why not in NFS? */
+	VOP_ABORTOP(tdvp, tcnp); /* XXX, why not in NFS? */
+	vrele(tdvp);
+	if (tvp) {
+		vrele(tvp);
+	}
+	vrele(fdvp);
+	if (fvp) {
+		vrele(fvp);
+	}
+	return (error);
 }
 
 #ifdef WAPBL_DEBUG_INODES



CVS commit: src/sys/ufs/ufs

2011-07-17 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Mon Jul 18 01:52:55 UTC 2011

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

Log Message:
Add the long essay on rename locking from my earlier patch set as a
big comment, and expand it some for clarity.


To generate a diff of this commit:
cvs rdiff -u -r1.196 -r1.197 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.196 src/sys/ufs/ufs/ufs_vnops.c:1.197
--- src/sys/ufs/ufs/ufs_vnops.c:1.196	Mon Jul 18 01:13:33 2011
+++ src/sys/ufs/ufs/ufs_vnops.c	Mon Jul 18 01:52:55 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_vnops.c,v 1.196 2011/07/18 01:13:33 dholland Exp $	*/
+/*	$NetBSD: ufs_vnops.c,v 1.197 2011/07/18 01:52:55 dholland Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_vnops.c,v 1.196 2011/07/18 01:13:33 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_vnops.c,v 1.197 2011/07/18 01:52:55 dholland Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -972,6 +972,137 @@
  *is different from the source, patch the .. entry in the
  *directory.
  */
+
+/*
+ * Notes on rename locking:
+ *
+ * We lock parent vnodes before child vnodes. This means in particular
+ * that if A is above B in the directory tree then A must be locked
+ * before B. (This is true regardless of how many steps appear in
+ * between, because an arbitrary number of other processes could lock
+ * parent/child in between and establish a lock cycle and deadlock.)
+ *
+ * Therefore, if tdvp is above fdvp we must lock tdvp first; if fdvp
+ * is above tdvp we must lock fdvp first; and if they're
+ * incommensurate it doesn't matter. (But, we rely on the fact that
+ * there's a whole-volume rename lock to prevent deadlock among groups
+ * of renames upon overlapping sets of incommensurate vnodes.)
+ *
+ * In addition to establishing lock ordering the parent check also
+ * serves to rule out cases where someone tries to move a directory
+ * underneath itself, e.g. rename(a/b, a/b/c). If allowed to
+ * proceed such renames would detach portions of the directory tree
+ * and make fsck very unhappy.
+ *
+ * Note that it is an error for *fvp* to be above tdvp; however,
+ * *fdvp* can be above tdvp, as in rename(a/b, a/c/d).
+ *
+ * The parent check searches up the tree from tdvp until it either
+ * finds fdvp or the root of the volume. It also returns the vnode it
+ * saw immediately before fdvp, if any. Later on (after looking up
+ * fvp) we will check to see if this *is* fvp and if so fail.
+ *
+ * If the parent check finds fdvp, it means fdvp is above tdvp, so we
+ * lock fdvp first and then tdvp. Otherwise, either tdvp is above fdvp
+ * or they're incommensurate and we lock tdvp first.
+ *
+ * In either case each of the child vnodes has to be looked up and
+ * locked immediately after its parent. The cases
+ *
+ *   fdvp/fvp/[.../]tdvp/tvp
+ *   tdvp/tvp/[.../]fdvp/fvp
+ *
+ * can cause deadlock otherwise. Note that both of these are error
+ * cases; the first fails the parent check and the second fails
+ * because tvp isn't empty. The parent check case is handled before
+ * we start locking; however, the nonempty case requires locking tvp
+ * to find out safely that it's nonempty.
+ *
+ * Therefore the procedure is either
+ *
+ *   lock fdvp
+ *   lookup fvp
+ *   lock fvp
+ *   lock tdvp
+ *   lookup tvp
+ *   lock tvp
+ *
+ * or
+ *
+ *   lock tdvp
+ *   lookup tvp
+ *   lock tvp
+ *   lock fdvp
+ *   lookup fvp
+ *   lock fvp
+ *
+ * This could in principle be simplified by always looking up fvp
+ * last; because of the parent check we know by the time we start
+ * locking that fvp cannot be directly above tdvp, so (given the
+ * whole-volume rename lock and other assumptions) it's safe to lock
+ * tdvp before fvp. This would allow the following scheme:
+ *
+ *   lock fdvp
+ *   lock tdvp
+ * or
+ *   lock tdvp
+ *   lock fdvp
+ *
+ * then
+ *   lookup tvp
+ *   lock tvp
+ *   lookup fvp
+ *   check if fvp is above of tdvp, fail if so
+ *   lock fvp
+ *
+ * which is much, much simpler.
+ *
+ * However, current levels of vfs namei/lookup sanity do not permit
+ * this. It is impossible currently to look up fvp without locking it.
+ * (It gets locked regardless of whether LOCKLEAF is set; without
+ * LOCKLEAF it just gets unlocked again, which doesn't help.)
+ *
+ * Therefore, because we must look up fvp to know if it's above tdvp,
+ * which locks fvp, we must, at least in the case where fdvp is above
+ * tdvp, do that before locking tdvp. The longer scheme does that; the
+ * simpler scheme is not safe.
+ *
+ * Note that for now we aren't doing lookup() but relookup(); however,
+ * the differences are minor.
+ *
+ * On top of all the above, just to make everything more
+ * exciting, any two 

CVS commit: src/sys/ufs/ufs

2011-07-17 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Mon Jul 18 02:35:11 UTC 2011

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

Log Message:
ok, it is clear that at least vput(vp) needs to go before fstrans_done().
I hoping vput(dvp) doesn't, because if it does that will vastly complicate
future vfs locking cleanup.


To generate a diff of this commit:
cvs rdiff -u -r1.197 -r1.198 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.197 src/sys/ufs/ufs/ufs_vnops.c:1.198
--- src/sys/ufs/ufs/ufs_vnops.c:1.197	Mon Jul 18 01:52:55 2011
+++ src/sys/ufs/ufs/ufs_vnops.c	Mon Jul 18 02:35:11 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_vnops.c,v 1.197 2011/07/18 01:52:55 dholland Exp $	*/
+/*	$NetBSD: ufs_vnops.c,v 1.198 2011/07/18 02:35:11 dholland Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_vnops.c,v 1.197 2011/07/18 01:52:55 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_vnops.c,v 1.198 2011/07/18 02:35:11 dholland Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -1763,9 +1763,9 @@
 #endif
  out:
 	VN_KNOTE(vp, NOTE_DELETE);
+	vput(vp);
 	fstrans_done(dvp-v_mount);
 	vput(dvp);
-	vput(vp);
 	return (error);
 }
 



CVS commit: src/sys/ufs/ufs

2011-07-14 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Thu Jul 14 16:27:43 UTC 2011

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

Log Message:
Clean up handling of ufs_lookup_results in rename.


To generate a diff of this commit:
cvs rdiff -u -r1.192 -r1.193 src/sys/ufs/ufs/ufs_vnops.c
cvs rdiff -u -r1.15 -r1.16 src/sys/ufs/ufs/ufs_wapbl.c

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

Modified files:

Index: src/sys/ufs/ufs/ufs_vnops.c
diff -u src/sys/ufs/ufs/ufs_vnops.c:1.192 src/sys/ufs/ufs/ufs_vnops.c:1.193
--- src/sys/ufs/ufs/ufs_vnops.c:1.192	Tue Jul 12 16:59:49 2011
+++ src/sys/ufs/ufs/ufs_vnops.c	Thu Jul 14 16:27:43 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_vnops.c,v 1.192 2011/07/12 16:59:49 dholland Exp $	*/
+/*	$NetBSD: ufs_vnops.c,v 1.193 2011/07/14 16:27:43 dholland Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_vnops.c,v 1.192 2011/07/12 16:59:49 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_vnops.c,v 1.193 2011/07/14 16:27:43 dholland Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -989,6 +989,7 @@
 	struct mount		*mp;
 	struct direct		*newdir;
 	int			doingdirectory, oldparent, newparent, error;
+	struct ufs_lookup_results from_ulr, to_ulr;
 
 #ifdef WAPBL
 	if (ap-a_tdvp-v_mount-mnt_wapbl)
@@ -1003,6 +1004,12 @@
 	fcnp = ap-a_fcnp;
 	doingdirectory = oldparent = newparent = error = 0;
 
+	/* save the supplemental lookup results as they currently exist */
+	from_ulr = VTOI(fdvp)-i_crap;
+	to_ulr = VTOI(tdvp)-i_crap;
+	UFS_CHECK_CRAPCOUNTER(VTOI(fdvp));
+	UFS_CHECK_CRAPCOUNTER(VTOI(tdvp));
+
 	/*
 	 * Check for cross-device rename.
 	 */
@@ -1145,6 +1152,11 @@
 			goto out;
 		}
 		dp = VTOI(tdvp);
+
+		/* update the supplemental reasults */
+		to_ulr = dp-i_crap;
+		UFS_CHECK_CRAPCOUNTER(dp);
+
 		xp = NULL;
 		if (tvp)
 			xp = VTOI(tvp);
@@ -1182,7 +1194,7 @@
 		}
 		newdir = pool_cache_get(ufs_direct_cache, PR_WAITOK);
 		ufs_makedirentry(ip, tcnp, newdir);
-		error = ufs_direnter(tdvp, VTOI(tdvp)-i_crap,
+		error = ufs_direnter(tdvp, to_ulr,
  NULL, newdir, tcnp, NULL);
 		pool_cache_put(ufs_direct_cache, newdir);
 		if (error != 0) {
@@ -1239,7 +1251,7 @@
 			error = EISDIR;
 			goto bad;
 		}
-		if ((error = ufs_dirrewrite(dp, dp-i_crap.ulr_offset,
+		if ((error = ufs_dirrewrite(dp, to_ulr.ulr_offset,
 		xp, ip-i_number,
 		IFTODT(ip-i_mode), doingdirectory  newparent ?
 		newparent : doingdirectory, IN_CHANGE | IN_UPDATE)) != 0)
@@ -1282,6 +1294,10 @@
 		vrele(ap-a_fvp);
 		goto out2;
 	}
+	/* update supplemental lookup results */
+	from_ulr = VTOI(fdvp)-i_crap;
+	UFS_CHECK_CRAPCOUNTER(VTOI(fdvp));
+
 	if (fvp != NULL) {
 		xp = VTOI(fvp);
 		dp = VTOI(fdvp);
@@ -1316,15 +1332,11 @@
 		 */
 		if (doingdirectory  newparent) {
 			KASSERT(dp != NULL);
-
-			/* match old behavior; probably dead assignment XXX */
-			xp-i_crap.ulr_offset = mastertemplate.dot_reclen;
-
 			ufs_dirrewrite(xp, mastertemplate.dot_reclen,
 			dp, newparent, DT_DIR, 0, IN_CHANGE);
 			cache_purge(fdvp);
 		}
-		error = ufs_dirremove(fdvp, VTOI(fdvp)-i_crap,
+		error = ufs_dirremove(fdvp, from_ulr,
   xp, fcnp-cn_flags, 0);
 		xp-i_flag = ~IN_RENAME;
 	}

Index: src/sys/ufs/ufs/ufs_wapbl.c
diff -u src/sys/ufs/ufs/ufs_wapbl.c:1.15 src/sys/ufs/ufs/ufs_wapbl.c:1.16
--- src/sys/ufs/ufs/ufs_wapbl.c:1.15	Tue Jul 12 16:59:49 2011
+++ src/sys/ufs/ufs/ufs_wapbl.c	Thu Jul 14 16:27:43 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: ufs_wapbl.c,v 1.15 2011/07/12 16:59:49 dholland Exp $ */
+/*  $NetBSD: ufs_wapbl.c,v 1.16 2011/07/14 16:27:43 dholland Exp $ */
 
 /*-
  * Copyright (c) 2003,2006,2008 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_wapbl.c,v 1.15 2011/07/12 16:59:49 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_wapbl.c,v 1.16 2011/07/14 16:27:43 dholland Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -113,6 +113,41 @@
 };
 
 /*
+ * Check if either entry referred to by FROM_ULR is within the range
+ * of entries named by TO_ULR.
+ */
+static int
+ulr_overlap(const struct ufs_lookup_results *from_ulr,
+	const struct ufs_lookup_results *to_ulr)
+{
+	doff_t from_start, from_prevstart;
+	doff_t to_start, to_end;
+
+	/*
+	 * FROM is a DELETE result; offset points to the entry to
+	 * remove and subtracting count gives the previous entry.
+	 */
+	from_start = from_ulr-ulr_offset - from_ulr-ulr_count;
+	from_prevstart = from_ulr-ulr_offset;
+
+	/*
+	 * TO is a RENAME (thus non-DELETE) result; offset points
+	 * to the beginning of a region to write in, and adding
+	 * count gives the end of the region.
+	 */
+	to_start = to_ulr-ulr_offset;
+	to_end = to_ulr-ulr_offset + to_ulr-ulr_count;
+
+	if (from_prevstart = to_start  from_prevstart  to_end) {
+		return 1;
+	}
+	if (from_start = to_start  from_start  to_end) {
+		return 

CVS commit: src/sys/ufs

2011-07-12 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue Jul 12 16:59:49 UTC 2011

Modified Files:
src/sys/ufs/ext2fs: ext2fs_extern.h ext2fs_lookup.c ext2fs_vnops.c
src/sys/ufs/lfs: lfs_vnops.c
src/sys/ufs/ufs: ufs_extern.h ufs_lookup.c ufs_vnops.c ufs_wapbl.c

Log Message:
Pass the ufs_lookup_results pointer around instead of fetching it from
the inode in the guts of ufs. Now, in VOPs where i_crap is used it is
used (directly) only immediately on entry to the VOP call and then
passed around by reference.

Except for rename, which needs explicit sorting out. The code in
ufs_wapbl_rename is unchanged in behavior but I'm increasingly
inclined to think it's wrong.


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/sys/ufs/ext2fs/ext2fs_extern.h
cvs rdiff -u -r1.65 -r1.66 src/sys/ufs/ext2fs/ext2fs_lookup.c
cvs rdiff -u -r1.99 -r1.100 src/sys/ufs/ext2fs/ext2fs_vnops.c
cvs rdiff -u -r1.236 -r1.237 src/sys/ufs/lfs/lfs_vnops.c
cvs rdiff -u -r1.64 -r1.65 src/sys/ufs/ufs/ufs_extern.h
cvs rdiff -u -r1.108 -r1.109 src/sys/ufs/ufs/ufs_lookup.c
cvs rdiff -u -r1.191 -r1.192 src/sys/ufs/ufs/ufs_vnops.c
cvs rdiff -u -r1.14 -r1.15 src/sys/ufs/ufs/ufs_wapbl.c

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

Modified files:

Index: src/sys/ufs/ext2fs/ext2fs_extern.h
diff -u src/sys/ufs/ext2fs/ext2fs_extern.h:1.42 src/sys/ufs/ext2fs/ext2fs_extern.h:1.43
--- src/sys/ufs/ext2fs/ext2fs_extern.h:1.42	Wed Oct 21 17:37:21 2009
+++ src/sys/ufs/ext2fs/ext2fs_extern.h	Tue Jul 12 16:59:48 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ext2fs_extern.h,v 1.42 2009/10/21 17:37:21 pooka Exp $	*/
+/*	$NetBSD: ext2fs_extern.h,v 1.43 2011/07/12 16:59:48 dholland Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993, 1994
@@ -118,10 +118,12 @@
 int ext2fs_readdir(void *);
 int ext2fs_lookup(void *);
 int ext2fs_direnter(struct inode *, struct vnode *,
+			 const struct ufs_lookup_results *,
 			 struct componentname *);
-int ext2fs_dirremove(struct vnode *, struct componentname *);
-int ext2fs_dirrewrite(struct inode *, struct inode *,
-			   struct componentname *);
+int ext2fs_dirremove(struct vnode *, const struct ufs_lookup_results *,
+		 struct componentname *);
+int ext2fs_dirrewrite(struct inode *, const struct ufs_lookup_results *,
+			   struct inode *, struct componentname *);
 int ext2fs_dirempty(struct inode *, ino_t, kauth_cred_t);
 int ext2fs_checkpath(struct inode *, struct inode *, kauth_cred_t);
 

Index: src/sys/ufs/ext2fs/ext2fs_lookup.c
diff -u src/sys/ufs/ext2fs/ext2fs_lookup.c:1.65 src/sys/ufs/ext2fs/ext2fs_lookup.c:1.66
--- src/sys/ufs/ext2fs/ext2fs_lookup.c:1.65	Tue Jul 12 02:22:13 2011
+++ src/sys/ufs/ext2fs/ext2fs_lookup.c	Tue Jul 12 16:59:48 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ext2fs_lookup.c,v 1.65 2011/07/12 02:22:13 dholland Exp $	*/
+/*	$NetBSD: ext2fs_lookup.c,v 1.66 2011/07/12 16:59:48 dholland Exp $	*/
 
 /*
  * Modified for NetBSD 1.2E
@@ -48,7 +48,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ext2fs_lookup.c,v 1.65 2011/07/12 02:22:13 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: ext2fs_lookup.c,v 1.66 2011/07/12 16:59:48 dholland Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -747,7 +747,9 @@
  * entry is to be obtained.
  */
 int
-ext2fs_direnter(struct inode *ip, struct vnode *dvp, struct componentname *cnp)
+ext2fs_direnter(struct inode *ip, struct vnode *dvp,
+		const struct ufs_lookup_results *ulr,
+		struct componentname *cnp)
 {
 	struct ext2fs_direct *ep, *nep;
 	struct inode *dp;
@@ -760,13 +762,9 @@
 	char *dirbuf;
 	struct ufsmount *ump = VFSTOUFS(dvp-v_mount);
 	int dirblksiz = ump-um_dirblksiz;
-	struct ufs_lookup_results *ulr;
 
 	dp = VTOI(dvp);
 
-	ulr = dp-i_crap;
-	UFS_CHECK_CRAPCOUNTER(dp);
-
 	newdir.e2d_ino = h2fs32(ip-i_number);
 	newdir.e2d_namlen = cnp-cn_namelen;
 	if (ip-i_e2fs-e2fs.e2fs_rev  E2FS_REV0 
@@ -893,20 +891,16 @@
  * to the size of the previous entry.
  */
 int
-ext2fs_dirremove(struct vnode *dvp, struct componentname *cnp)
+ext2fs_dirremove(struct vnode *dvp, const struct ufs_lookup_results *ulr,
+		 struct componentname *cnp)
 {
 	struct inode *dp;
 	struct ext2fs_direct *ep;
 	struct buf *bp;
 	int error;
-	struct ufs_lookup_results *ulr;
 
 	dp = VTOI(dvp);
 
-	/* XXX should handle this material another way */
-	ulr = dp-i_crap;
-	UFS_CHECK_CRAPCOUNTER(dp);
-
 	if (ulr-ulr_count == 0) {
 		/*
 		 * First entry in block: set d_ino to zero.
@@ -939,18 +933,13 @@
  * set up by a call to namei.
  */
 int
-ext2fs_dirrewrite(struct inode *dp, struct inode *ip,
-struct componentname *cnp)
+ext2fs_dirrewrite(struct inode *dp, const struct ufs_lookup_results *ulr,
+struct inode *ip, struct componentname *cnp)
 {
 	struct buf *bp;
 	struct ext2fs_direct *ep;
 	struct vnode *vdp = ITOV(dp);
 	int error;
-	struct ufs_lookup_results *ulr;
-
-	/* XXX should handle this material another way */
-	ulr = dp-i_crap;
-	UFS_CHECK_CRAPCOUNTER(dp);
 
 	error = 

CVS commit: src/sys/ufs

2011-07-11 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue Jul 12 02:22:14 UTC 2011

Modified Files:
src/sys/ufs/ext2fs: ext2fs_lookup.c
src/sys/ufs/ufs: inode.h ufs_lookup.c ufs_vnops.c ufs_wapbl.c

Log Message:
Currently, ufs_lookup produces five auxiliary results that are left in
the vnode when lookup returns and fished out again later.

1. Create struct ufs_lookup_results to hold these.

2. Call the ufs_lookup_results instance in struct inode i_crap to be
clear about exactly what's going on, and to distinguish the lookup
results from respectable members of struct inode.

3. Update references to these members in the directory access
subroutines.

4. Include preliminary infrastructure for checking that the i_crap
being used is still valid when it's used. This doesn't actually do
anything yet.

5. Update the way ufs_wapbl_rename manipulates these elements to use
the new data structures. I have not changed the manipulation; it may
or may not be correct but I continue to suspect that it is not.

The word of the day is stigmergy.


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 src/sys/ufs/ext2fs/ext2fs_lookup.c
cvs rdiff -u -r1.57 -r1.58 src/sys/ufs/ufs/inode.h
cvs rdiff -u -r1.107 -r1.108 src/sys/ufs/ufs/ufs_lookup.c
cvs rdiff -u -r1.190 -r1.191 src/sys/ufs/ufs/ufs_vnops.c
cvs rdiff -u -r1.13 -r1.14 src/sys/ufs/ufs/ufs_wapbl.c

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

Modified files:

Index: src/sys/ufs/ext2fs/ext2fs_lookup.c
diff -u src/sys/ufs/ext2fs/ext2fs_lookup.c:1.64 src/sys/ufs/ext2fs/ext2fs_lookup.c:1.65
--- src/sys/ufs/ext2fs/ext2fs_lookup.c:1.64	Mon Jul 11 08:27:39 2011
+++ src/sys/ufs/ext2fs/ext2fs_lookup.c	Tue Jul 12 02:22:13 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ext2fs_lookup.c,v 1.64 2011/07/11 08:27:39 hannken Exp $	*/
+/*	$NetBSD: ext2fs_lookup.c,v 1.65 2011/07/12 02:22:13 dholland Exp $	*/
 
 /*
  * Modified for NetBSD 1.2E
@@ -48,7 +48,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ext2fs_lookup.c,v 1.64 2011/07/11 08:27:39 hannken Exp $);
+__KERNEL_RCSID(0, $NetBSD: ext2fs_lookup.c,v 1.65 2011/07/12 02:22:13 dholland Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -290,6 +290,7 @@
 	struct ufsmount *ump = dp-i_ump;
 	int dirblksiz = ump-um_dirblksiz;
 	ino_t foundino;
+	struct ufs_lookup_results *results;
 
 	flags = cnp-cn_flags;
 
@@ -298,6 +299,14 @@
 	*vpp = NULL;
 
 	/*
+	 * Produce the auxiliary lookup results into i_crap. Increment
+	 * its serial number so elsewhere we can tell if we're using
+	 * stale results. This should not be done this way. XXX.
+	 */
+	results = dp-i_crap;
+	dp-i_crapcounter++;
+
+	/*
 	 * Check accessiblity of directory.
 	 */
 	if ((error = VOP_ACCESS(vdp, VEXEC, cred)) != 0)
@@ -343,34 +352,34 @@
 	 * of simplicity.
 	 */
 	bmask = vdp-v_mount-mnt_stat.f_iosize - 1;
-	if (nameiop != LOOKUP || dp-i_diroff == 0 ||
-	dp-i_diroff = ext2fs_size(dp)) {
+	if (nameiop != LOOKUP || results-ulr_diroff == 0 ||
+	results-ulr_diroff = ext2fs_size(dp)) {
 		entryoffsetinblock = 0;
-		dp-i_offset = 0;
+		results-ulr_offset = 0;
 		numdirpasses = 1;
 	} else {
-		dp-i_offset = dp-i_diroff;
-		if ((entryoffsetinblock = dp-i_offset  bmask) 
-		(error = ext2fs_blkatoff(vdp, (off_t)dp-i_offset, NULL, bp)))
+		results-ulr_offset = results-ulr_diroff;
+		if ((entryoffsetinblock = results-ulr_offset  bmask) 
+		(error = ext2fs_blkatoff(vdp, (off_t)results-ulr_offset, NULL, bp)))
 			return (error);
 		numdirpasses = 2;
 		nchstats.ncs_2passes++;
 	}
-	prevoff = dp-i_offset;
+	prevoff = results-ulr_offset;
 	endsearch = roundup(ext2fs_size(dp), dirblksiz);
 	enduseful = 0;
 
 searchloop:
-	while (dp-i_offset  endsearch) {
+	while (results-ulr_offset  endsearch) {
 		if (curcpu()-ci_schedstate.spc_flags  SPCF_SHOULDYIELD)
 			preempt();
 		/*
 		 * If necessary, get the next directory block.
 		 */
-		if ((dp-i_offset  bmask) == 0) {
+		if ((results-ulr_offset  bmask) == 0) {
 			if (bp != NULL)
 brelse(bp, 0);
-			error = ext2fs_blkatoff(vdp, (off_t)dp-i_offset, NULL,
+			error = ext2fs_blkatoff(vdp, (off_t)results-ulr_offset, NULL,
 			bp);
 			if (error != 0)
 return (error);
@@ -400,9 +409,9 @@
 		 ext2fs_dirbadentry(vdp, ep, entryoffsetinblock))) {
 			int i;
 
-			ufs_dirbad(dp, dp-i_offset, mangled entry);
+			ufs_dirbad(dp, results-ulr_offset, mangled entry);
 			i = dirblksiz - (entryoffsetinblock  (dirblksiz - 1));
-			dp-i_offset += i;
+			results-ulr_offset += i;
 			entryoffsetinblock += i;
 			continue;
 		}
@@ -421,15 +430,15 @@
 			if (size  0) {
 if (size = slotneeded) {
 	slotstatus = FOUND;
-	slotoffset = dp-i_offset;
+	slotoffset = results-ulr_offset;
 	slotsize = fs2h16(ep-e2d_reclen);
 } else if (slotstatus == NONE) {
 	slotfreespace += size;
 	if (slotoffset == -1)
-		slotoffset = dp-i_offset;
+		slotoffset = results-ulr_offset;
 	if (slotfreespace = 

CVS commit: src/sys/ufs/ufs

2011-07-07 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Thu Jul  7 14:56:45 UTC 2011

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

Log Message:
Fix locking protocol to avoid a panic on extattrctl stop and on umount.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/ufs/ufs/ufs_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/ufs/ufs_extattr.c
diff -u src/sys/ufs/ufs/ufs_extattr.c:1.34 src/sys/ufs/ufs/ufs_extattr.c:1.35
--- src/sys/ufs/ufs/ufs_extattr.c:1.34	Mon Jul  4 08:07:32 2011
+++ src/sys/ufs/ufs/ufs_extattr.c	Thu Jul  7 14:56:45 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_extattr.c,v 1.34 2011/07/04 08:07:32 manu Exp $	*/
+/*	$NetBSD: ufs_extattr.c,v 1.35 2011/07/07 14:56:45 manu Exp $	*/
 
 /*-
  * Copyright (c) 1999-2002 Robert N. M. Watson
@@ -48,7 +48,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_extattr.c,v 1.34 2011/07/04 08:07:32 manu Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_extattr.c,v 1.35 2011/07/07 14:56:45 manu Exp $);
 
 #ifdef _KERNEL_OPT
 #include opt_ffs.h
@@ -133,6 +133,7 @@
 	if (ump-um_extattr.uepm_lockcnt != 0) {
 		KASSERT(mutex_owned(ump-um_extattr.uepm_lock));
 		ump-um_extattr.uepm_lockcnt--;
+		return;
 	}
 	mutex_exit(ump-um_extattr.uepm_lock);
 }



CVS commit: src/sys/ufs/ffs

2011-07-01 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Fri Jul  1 14:28:22 UTC 2011

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

Log Message:
ffs_copyonwrite(): If the write is to the in-file-system journal
there is no need to lock and check the snapshots.


To generate a diff of this commit:
cvs rdiff -u -r1.116 -r1.117 src/sys/ufs/ffs/ffs_snapshot.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_snapshot.c
diff -u src/sys/ufs/ffs/ffs_snapshot.c:1.116 src/sys/ufs/ffs/ffs_snapshot.c:1.117
--- src/sys/ufs/ffs/ffs_snapshot.c:1.116	Sun Jun 12 03:36:00 2011
+++ src/sys/ufs/ffs/ffs_snapshot.c	Fri Jul  1 14:28:21 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_snapshot.c,v 1.116 2011/06/12 03:36:00 rmind Exp $	*/
+/*	$NetBSD: ffs_snapshot.c,v 1.117 2011/07/01 14:28:21 hannken Exp $	*/
 
 /*
  * Copyright 2000 Marshall Kirk McKusick. All Rights Reserved.
@@ -38,7 +38,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_snapshot.c,v 1.116 2011/06/12 03:36:00 rmind Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_snapshot.c,v 1.117 2011/07/01 14:28:21 hannken Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -1896,9 +1896,9 @@
 		return 0;
 	}
 	/*
-	 * First check to see if it is after the file system or
-	 * in the preallocated list.
-	 * By doing this check we avoid several potential deadlocks.
+	 * First check to see if it is after the file system,
+	 * in the journal or in the preallocated list.
+	 * By doing these checks we avoid several potential deadlocks.
 	 */
 	fs = ip-i_fs;
 	lbn = fragstoblks(fs, dbtofsb(fs, bp-b_blkno));
@@ -1906,6 +1906,20 @@
 		mutex_exit(si-si_lock);
 		return 0;
 	}
+	if ((fs-fs_flags  FS_DOWAPBL) 
+	fs-fs_journal_location == UFS_WAPBL_JOURNALLOC_IN_FILESYSTEM) {
+		off_t blk_off, log_start, log_end;
+
+		log_start = (off_t)fs-fs_journallocs[UFS_WAPBL_INFS_ADDR] *
+		fs-fs_journallocs[UFS_WAPBL_INFS_BLKSZ];
+		log_end = log_start + fs-fs_journallocs[UFS_WAPBL_INFS_COUNT] *
+		fs-fs_journallocs[UFS_WAPBL_INFS_BLKSZ];
+		blk_off = dbtob(bp-b_blkno);
+		if (blk_off = log_start  blk_off  log_end) {
+			mutex_exit(si-si_lock);
+			return 0;
+		}
+	}
 	snapblklist = si-si_snapblklist;
 	upper = (snapblklist != NULL ? snapblklist[0] - 1 : 0);
 	lower = 1;



CVS commit: src/sys/ufs/ffs

2011-06-21 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Wed Jun 22 04:01:33 UTC 2011

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

Log Message:
fix an off by one array overflow found by GCC 4.5.3.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/ufs/ffs/ffs_appleufs.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_appleufs.c
diff -u src/sys/ufs/ffs/ffs_appleufs.c:1.10 src/sys/ufs/ffs/ffs_appleufs.c:1.11
--- src/sys/ufs/ffs/ffs_appleufs.c:1.10	Sat Apr 24 19:58:13 2010
+++ src/sys/ufs/ffs/ffs_appleufs.c	Wed Jun 22 04:01:33 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_appleufs.c,v 1.10 2010/04/24 19:58:13 dbj Exp $	*/
+/*	$NetBSD: ffs_appleufs.c,v 1.11 2011/06/22 04:01:33 mrg Exp $	*/
 
 /*
  * Copyright (c) 2002 Darrin B. Jewell
@@ -26,7 +26,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_appleufs.c,v 1.10 2010/04/24 19:58:13 dbj Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_appleufs.c,v 1.11 2011/06/22 04:01:33 mrg Exp $);
 
 #include sys/param.h
 #include sys/time.h
@@ -108,7 +108,7 @@
 		n-ul_namelen = APPLEUFS_MAX_LABEL_NAME;
 	}
 	/* if len is max, will set ul_unused1 */
-	n-ul_name[n-ul_namelen] = '\0';
+	n-ul_name[n-ul_namelen - 1] = '\0';
 
 #ifdef DEBUG
 	printf(%s: found APPLE UFS label v%d: \%s\\n,



CVS commit: src/sys/ufs/ufs

2011-06-15 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Wed Jun 15 12:54:32 UTC 2011

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

Log Message:
Improve UFS1 extended attributes usability
- autocreate attribute backing file for new attributes
- autoload attributes when issuing extattrctl start
- when autoloading attributes, do not display garbage warning when looking
up entries that got ENOENT


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/ufs/ufs/ufs_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/ufs/ufs_extattr.c
diff -u src/sys/ufs/ufs/ufs_extattr.c:1.30 src/sys/ufs/ufs/ufs_extattr.c:1.31
--- src/sys/ufs/ufs/ufs_extattr.c:1.30	Sun Jun 12 03:36:02 2011
+++ src/sys/ufs/ufs/ufs_extattr.c	Wed Jun 15 12:54:32 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_extattr.c,v 1.30 2011/06/12 03:36:02 rmind Exp $	*/
+/*	$NetBSD: ufs_extattr.c,v 1.31 2011/06/15 12:54:32 manu Exp $	*/
 
 /*-
  * Copyright (c) 1999-2002 Robert N. M. Watson
@@ -48,7 +48,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_extattr.c,v 1.30 2011/06/12 03:36:02 rmind Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_extattr.c,v 1.31 2011/06/15 12:54:32 manu Exp $);
 
 #ifdef _KERNEL_OPT
 #include opt_ffs.h
@@ -99,6 +99,8 @@
 		struct lwp *l);
 static int	ufs_extattr_rm(struct vnode *vp, int attrnamespace,
 		const char *name, kauth_cred_t cred, struct lwp *l);
+static struct ufs_extattr_list_entry *ufs_extattr_find_attr(struct ufsmount *,
+		int, const char *);
 
 /*
  * Per-FS attribute lock protecting attribute operations.
@@ -147,6 +149,142 @@
 	return (1);
 }
 
+#ifdef UFS_EXTATTR_AUTOCREATE
+/*
+ * Autocreate an attribute storage
+ */
+static struct ufs_extattr_list_entry *
+ufs_extattr_autocreate_attr(struct vnode *vp, int attrnamespace,
+const char *attrname, struct lwp *l)
+{
+	struct mount *mp = vp-v_mount;
+	struct ufsmount *ump = VFSTOUFS(mp);
+	struct vnode *backing_vp;
+	struct nameidata nd;
+	struct pathbuf *pb;
+	char *path;
+	struct ufs_extattr_fileheader uef;
+	struct ufs_extattr_list_entry *uele;
+	int error;
+
+	path = PNBUF_GET();
+
+	/* 
+	 * We only support system and user namespace autocreation
+	 */ 
+	switch (attrnamespace) {
+	case EXTATTR_NAMESPACE_SYSTEM:
+		(void)snprintf(path, PATH_MAX, %s/%s/%s/%s, 
+			   mp-mnt_stat.f_mntonname,
+			   UFS_EXTATTR_FSROOTSUBDIR,
+			   UFS_EXTATTR_SUBDIR_SYSTEM,
+			   attrname);
+		break;
+	case EXTATTR_NAMESPACE_USER:
+		(void)snprintf(path, PATH_MAX, %s/%s/%s/%s, 
+			   mp-mnt_stat.f_mntonname,
+			   UFS_EXTATTR_FSROOTSUBDIR,
+			   UFS_EXTATTR_SUBDIR_USER,
+			   attrname);
+		break;
+	default:
+		PNBUF_PUT(path);
+		return NULL;
+		break;
+	}
+
+	/*
+	 * When setting attribute on the root vnode, we get it 
+	 * already locked, and vn_open/namei/VFS_ROOT will try to
+	 * look it, causing a panic. Unlock it first.
+	 */ 
+	if (vp-v_vflag  VV_ROOT) {
+		KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
+		VOP_UNLOCK(vp);
+	}
+	KASSERT(VOP_ISLOCKED(vp) == 0);
+
+	pb = pathbuf_create(path);
+	NDINIT(nd, CREATE, LOCKPARENT, pb);
+	
+	error = vn_open(nd, O_CREAT|O_RDWR, 0600);
+
+	/*
+	 * Reacquire the lock on the vnode if it was root.
+	 */
+	KASSERT(VOP_ISLOCKED(vp) == 0);
+	if (vp-v_vflag  VV_ROOT)
+		vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
+	KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
+
+	if (error != 0) {
+		pathbuf_destroy(pb);
+		PNBUF_PUT(path);
+		return NULL;
+	}
+
+	KASSERT(nd.ni_vp != NULL);
+	KASSERT(VOP_ISLOCKED(nd.ni_vp) == LK_EXCLUSIVE);
+	KASSERT(VOP_ISLOCKED(nd.ni_dvp) == 0);
+
+	/*
+ 	 * backing_vp is the backing store. 
+	 */	
+	backing_vp = nd.ni_vp;
+	pathbuf_destroy(pb);
+	PNBUF_PUT(path);
+
+	uef.uef_magic = UFS_EXTATTR_MAGIC;
+	uef.uef_version = UFS_EXTATTR_VERSION;
+	uef.uef_size = UFS_EXTATTR_AUTOCREATE;
+
+	error = vn_rdwr(UIO_WRITE, backing_vp, uef, sizeof(uef), 0,
+		UIO_SYSSPACE, IO_NODELOCKED|IO_APPEND, 
+			l-l_cred, NULL, l);
+
+	VOP_UNLOCK(backing_vp);
+
+	if (error != 0) {
+		printf(%s: write uef header failed for %s, error = %d\n, 
+		   __func__, attrname, error);
+		vn_close(backing_vp, FREAD|FWRITE, l-l_cred);
+		return NULL;
+	}
+
+	/*
+	 * ufs_extattr_enable_with_open increases the vnode reference
+	 * count. Not sure why, but do the same here.
+	 */
+	vref(vp);
+
+	/*
+	 * Now enable attribute. 
+	 */
+	error = ufs_extattr_enable(ump,attrnamespace, attrname, backing_vp, l);
+	KASSERT(VOP_ISLOCKED(backing_vp) == 0);
+
+	if (error != 0) {
+		printf(%s: enable %s failed, error %d\n, 
+		   __func__, attrname, error);
+		vn_close(backing_vp, FREAD|FWRITE, l-l_cred);
+		return NULL;
+	}
+
+	uele = ufs_extattr_find_attr(ump, attrnamespace, attrname);
+	if (uele == NULL) {
+		printf(%s: atttribute %s created but not found!\n,
+		   __func__, attrname);
+		vn_close(backing_vp, FREAD|FWRITE, l-l_cred);
+		return NULL;
+	}
+
+	printf(%s: EA 

CVS commit: src/sys/ufs/ufs

2011-05-10 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Tue May 10 08:29:32 UTC 2011

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

Log Message:
Fix filesystem root leaked lock when using UFS_EXTATTR_AUTOSTART.
This way, statvfs(2) calls obtained by df(1) or umount(8) will no
longer sleep forever in the kernel to acquire the lock.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/ufs/ufs/ufs_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/ufs/ufs_extattr.c
diff -u src/sys/ufs/ufs/ufs_extattr.c:1.28 src/sys/ufs/ufs/ufs_extattr.c:1.29
--- src/sys/ufs/ufs/ufs_extattr.c:1.28	Tue Nov 30 10:30:04 2010
+++ src/sys/ufs/ufs/ufs_extattr.c	Tue May 10 08:29:32 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_extattr.c,v 1.28 2010/11/30 10:30:04 dholland Exp $	*/
+/*	$NetBSD: ufs_extattr.c,v 1.29 2011/05/10 08:29:32 manu Exp $	*/
 
 /*-
  * Copyright (c) 1999-2002 Robert N. M. Watson
@@ -48,7 +48,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_extattr.c,v 1.28 2010/11/30 10:30:04 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_extattr.c,v 1.29 2011/05/10 08:29:32 manu Exp $);
 
 #ifdef _KERNEL_OPT
 #include opt_ffs.h
@@ -287,7 +287,9 @@
 	error = ufs_lookup(vargs);
 	PNBUF_PUT(pnbuf);
 	if (error) {
-		VOP_UNLOCK(start_dvp);
+		if (lockparent == 0) {
+			VOP_UNLOCK(start_dvp);
+		}
 		return (error);
 	}
 #if 0
@@ -295,6 +297,9 @@
 		panic(ufs_extattr_lookup: target_vp == start_dvp);
 #endif
 
+	if ((target_vp != start_dvp)  (lockparent == 0))
+		 VOP_UNLOCK(start_dvp);
+
 	KASSERT(VOP_ISLOCKED(target_vp) == LK_EXCLUSIVE);
 	*vp = target_vp;
 	return (0);



CVS commit: src/sys/ufs/ffs

2011-05-08 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sun May  8 18:37:15 UTC 2011

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

Log Message:
Revert previous commit.  Locking the snapshot vnode while the file system
is suspended extends the suspension until the vnode gets unlocked by
the caller of ffs_snapshot().

Resuming the file system before expunging all snapshots and syncing the
snapshot creates races and deadlocks with journaling file systems at least.


To generate a diff of this commit:
cvs rdiff -u -r1.114 -r1.115 src/sys/ufs/ffs/ffs_snapshot.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_snapshot.c
diff -u src/sys/ufs/ffs/ffs_snapshot.c:1.114 src/sys/ufs/ffs/ffs_snapshot.c:1.115
--- src/sys/ufs/ffs/ffs_snapshot.c:1.114	Fri Apr 29 09:45:15 2011
+++ src/sys/ufs/ffs/ffs_snapshot.c	Sun May  8 18:37:15 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_snapshot.c,v 1.114 2011/04/29 09:45:15 hannken Exp $	*/
+/*	$NetBSD: ffs_snapshot.c,v 1.115 2011/05/08 18:37:15 hannken Exp $	*/
 
 /*
  * Copyright 2000 Marshall Kirk McKusick. All Rights Reserved.
@@ -38,7 +38,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_snapshot.c,v 1.114 2011/04/29 09:45:15 hannken Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_snapshot.c,v 1.115 2011/05/08 18:37:15 hannken Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -177,7 +177,7 @@
 	return EOPNOTSUPP;
 }
 #else /* defined(FFS_NO_SNAPSHOT) */
-	bool suspended = false, snapshot_locked = false;
+	bool suspended = false;
 	int error, redo = 0, snaploc;
 	void *sbbuf = NULL;
 	daddr_t *snaplist = NULL, snaplistsize = 0;
@@ -310,24 +310,6 @@
 	DIP_ASSIGN(ip, mtimensec, ts.tv_nsec);
 	ip-i_flag |= IN_CHANGE | IN_UPDATE;
 	/*
-	 * Lock the snapshot and resume file system.
-	 */
-	mutex_enter(si-si_snaplock);
-	mutex_enter(si-si_lock);
-	si-si_owner = curlwp;
-	mutex_exit(si-si_lock);
-	snapshot_locked = true;
-	KASSERT(suspended);
-	vfs_resume(vp-v_mount);
-	suspended = false;
-#ifdef DEBUG
-	getmicrotime(endtime);
-	timersub(endtime, starttime, endtime);
-	printf(%s: suspended %lld.%03d sec, redo %d of %d\n,
-	mp-mnt_stat.f_mntonname, (long long)endtime.tv_sec,
-	endtime.tv_usec / 1000, redo, fs-fs_ncg);
-#endif
-	/*
 	 * Copy allocation information from all snapshots and then
 	 * expunge them from our view.
 	 */
@@ -399,13 +381,17 @@
 	si-si_gen++;
 	mutex_exit(si-si_lock);
 
-	if (suspended)
+	if (suspended) {
+		VOP_UNLOCK(vp);
 		vfs_resume(vp-v_mount);
-	if (snapshot_locked) {
-		mutex_enter(si-si_lock);
-		si-si_owner = NULL;
-		mutex_exit(si-si_lock);
-		mutex_exit(si-si_snaplock);
+		vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
+#ifdef DEBUG
+		getmicrotime(endtime);
+		timersub(endtime, starttime, endtime);
+		printf(%s: suspended %lld.%03d sec, redo %d of %d\n,
+		mp-mnt_stat.f_mntonname, (long long)endtime.tv_sec,
+		endtime.tv_usec / 1000, redo, fs-fs_ncg);
+#endif
 	}
 	if (error) {
 		if (!UFS_WAPBL_BEGIN(mp)) {



CVS commit: src/sys/ufs/ufs

2011-04-30 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sat Apr 30 14:24:27 UTC 2011

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

Log Message:
ufs_mknod: change vnode type to VNON before it gets unlocked.  Closes a small
window where the vnode could have type VCHR but op vector ffs_vnodeop_p.


To generate a diff of this commit:
cvs rdiff -u -r1.188 -r1.189 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.188 src/sys/ufs/ufs/ufs_vnops.c:1.189
--- src/sys/ufs/ufs/ufs_vnops.c:1.188	Sun Apr 24 21:35:30 2011
+++ src/sys/ufs/ufs/ufs_vnops.c	Sat Apr 30 14:24:27 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_vnops.c,v 1.188 2011/04/24 21:35:30 rmind Exp $	*/
+/*	$NetBSD: ufs_vnops.c,v 1.189 2011/04/30 14:24:27 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_vnops.c,v 1.188 2011/04/24 21:35:30 rmind Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_vnops.c,v 1.189 2011/04/30 14:24:27 hannken Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -211,8 +211,8 @@
 	 * checked to see if it is an alias of an existing entry in
 	 * the inode cache.
 	 */
-	VOP_UNLOCK(*vpp);
 	(*vpp)-v_type = VNON;
+	VOP_UNLOCK(*vpp);
 	vgone(*vpp);
 	error = VFS_VGET(mp, ino, vpp);
 out:



CVS commit: src/sys/ufs/ffs

2011-04-27 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed Apr 27 07:24:53 UTC 2011

Modified Files:
src/sys/ufs/ffs: ffs_extern.h ffs_vfsops.c ffs_vnops.c

Log Message:
Cleanup ffs fsync and make devices on wapbl enabled file systems work here:

- Replace the ugly sync loop in ffs_full_fsync() and ffs_vfs_fsync() with
  vflushbuf().  This loop is a relic of softdeps and not needed anymore.

- Add ffs_spec_fsync() for device nodes on ffs file systems that calls
  spec_fsync() like all other file systems do and then updates the ctime.

Discussed on tech-kern.

Should fix PRs:
PR #41192 wapbl diagnostic panic during cgdconfig
PR #41977 kernel diagnostic assertion rw_lock_held(wl-wl_rwlock) failed
PR #42149 wapbl locking panic if watching DVD
PR #42551 Lockdebug assert in wapbl when running zpool


To generate a diff of this commit:
cvs rdiff -u -r1.76 -r1.77 src/sys/ufs/ffs/ffs_extern.h
cvs rdiff -u -r1.265 -r1.266 src/sys/ufs/ffs/ffs_vfsops.c
cvs rdiff -u -r1.117 -r1.118 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_extern.h
diff -u src/sys/ufs/ffs/ffs_extern.h:1.76 src/sys/ufs/ffs/ffs_extern.h:1.77
--- src/sys/ufs/ffs/ffs_extern.h:1.76	Sun Mar  6 17:08:38 2011
+++ src/sys/ufs/ffs/ffs_extern.h	Wed Apr 27 07:24:52 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_extern.h,v 1.76 2011/03/06 17:08:38 bouyer Exp $	*/
+/*	$NetBSD: ffs_extern.h,v 1.77 2011/04/27 07:24:52 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993, 1994
@@ -125,6 +125,7 @@
 int	ffs_read(void *);
 int	ffs_write(void *);
 int	ffs_fsync(void *);
+int	ffs_spec_fsync(void *);
 int	ffs_reclaim(void *);
 int	ffs_getpages(void *);
 void	ffs_gop_size(struct vnode *, off_t, off_t *, int);

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.265 src/sys/ufs/ffs/ffs_vfsops.c:1.266
--- src/sys/ufs/ffs/ffs_vfsops.c:1.265	Sun Mar 27 08:04:50 2011
+++ src/sys/ufs/ffs/ffs_vfsops.c	Wed Apr 27 07:24:53 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.265 2011/03/27 08:04:50 mlelstv Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.266 2011/04/27 07:24:53 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.265 2011/03/27 08:04:50 mlelstv Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.266 2011/04/27 07:24:53 hannken Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -2071,14 +2071,12 @@
 }
 
 /*
- * Synch vnode for a mounted file system.  This is called for foreign
- * vnodes, i.e. non-ffs.
+ * Synch vnode for a mounted file system.
  */
 static int
 ffs_vfs_fsync(vnode_t *vp, int flags)
 {
-	int error, passes, skipmeta, i, pflags;
-	buf_t *bp, *nbp;
+	int error, i, pflags;
 #ifdef WAPBL
 	struct mount *mp;
 #endif
@@ -2130,80 +2128,9 @@
 	}
 #endif /* WAPBL */
 
-	/*
-	 * Write out metadata for non-logging file systems. XXX This block
-	 * should be simplified now that softdep is gone.
-	 */
-	passes = NIADDR + 1;
-	skipmeta = 0;
-	if (flags  FSYNC_WAIT)
-		skipmeta = 1;
-
-loop:
-	mutex_enter(bufcache_lock);
-	LIST_FOREACH(bp, vp-v_dirtyblkhd, b_vnbufs) {
-		bp-b_cflags = ~BC_SCANNED;
-	}
-	for (bp = LIST_FIRST(vp-v_dirtyblkhd); bp; bp = nbp) {
-		nbp = LIST_NEXT(bp, b_vnbufs);
-		if (bp-b_cflags  (BC_BUSY | BC_SCANNED))
-			continue;
-		if ((bp-b_oflags  BO_DELWRI) == 0)
-			panic(ffs_fsync: not dirty);
-		if (skipmeta  bp-b_lblkno  0)
-			continue;
-		bp-b_cflags |= BC_BUSY | BC_VFLUSH | BC_SCANNED;
-		mutex_exit(bufcache_lock);
-		/*
-		 * On our final pass through, do all I/O synchronously
-		 * so that we can find out if our flush is failing
-		 * because of write errors.
-		 */
-		if (passes  0 || !(flags  FSYNC_WAIT))
-			(void) bawrite(bp);
-		else if ((error = bwrite(bp)) != 0)
-			return (error);
-		/*
-		 * Since we unlocked during the I/O, we need
-		 * to start from a known point.
-		 */
-		mutex_enter(bufcache_lock);
-		nbp = LIST_FIRST(vp-v_dirtyblkhd);
-	}
-	mutex_exit(bufcache_lock);
-	if (skipmeta) {
-		skipmeta = 0;
-		goto loop;
-	}
-
-	if ((flags  FSYNC_WAIT) != 0) {
-		mutex_enter(vp-v_interlock);
-		while (vp-v_numoutput) {
-			cv_wait(vp-v_cv, vp-v_interlock);
-		}
-		mutex_exit(vp-v_interlock);
-
-		if (!LIST_EMPTY(vp-v_dirtyblkhd)) {
-			/*
-			* Block devices associated with filesystems may
-			* have new I/O requests posted for them even if
-			* the vnode is locked, so no amount of trying will
-			* get them clean. Thus we give block devices a
-			* good effort, then just give up. For all other file
-			* types, go around and try again until it is clean.
-			*/
-			if (passes  0) {
-passes--;
-goto loop;
-			}
-#ifdef DIAGNOSTIC
-			if (vp-v_type != VBLK)
-vprint(ffs_fsync: dirty, vp);
-#endif
-		}
-	}
-
+	error = vflushbuf(vp, (flags  FSYNC_WAIT) != 0);
 	if (error == 0  (flags  FSYNC_CACHE) != 0) {
+		i = 1;
 		

CVS commit: src/sys/ufs/ffs

2011-04-23 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sat Apr 23 07:36:02 UTC 2011

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

Log Message:
Try to keep snapshot indirect blocks contiguous.

This speeds up snapshot creation by a factor of ~3 and reduces
the file system suspension time by a factor of ~5.


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 src/sys/ufs/ffs/ffs_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/ffs/ffs_balloc.c
diff -u src/sys/ufs/ffs/ffs_balloc.c:1.53 src/sys/ufs/ffs/ffs_balloc.c:1.54
--- src/sys/ufs/ffs/ffs_balloc.c:1.53	Sun Mar  6 17:08:38 2011
+++ src/sys/ufs/ffs/ffs_balloc.c	Sat Apr 23 07:36:02 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_balloc.c,v 1.53 2011/03/06 17:08:38 bouyer Exp $	*/
+/*	$NetBSD: ffs_balloc.c,v 1.54 2011/04/23 07:36:02 hannken Exp $	*/
 
 /*
  * Copyright (c) 2002 Networks Associates Technology, Inc.
@@ -41,7 +41,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_balloc.c,v 1.53 2011/03/06 17:08:38 bouyer Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_balloc.c,v 1.54 2011/04/23 07:36:02 hannken Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_quota.h
@@ -320,6 +320,10 @@
 			goto fail;
 		}
 		mutex_enter(ump-um_lock);
+		/* Try to keep snapshot indirect blocks contiguous. */
+		if (i == num  (ip-i_flags  SF_SNAPSHOT) != 0)
+			pref = ffs_blkpref_ufs1(ip, lbn, indirs[i-1].in_off,
+			flags | B_METAONLY, bap[0]);
 		if (pref == 0)
 			pref = ffs_blkpref_ufs1(ip, lbn, 0, flags | B_METAONLY,
 			NULL);
@@ -846,6 +850,10 @@
 			goto fail;
 		}
 		mutex_enter(ump-um_lock);
+		/* Try to keep snapshot indirect blocks contiguous. */
+		if (i == num  (ip-i_flags  SF_SNAPSHOT) != 0)
+			pref = ffs_blkpref_ufs2(ip, lbn, indirs[i-1].in_off,
+			flags | B_METAONLY, bap[0]);
 		if (pref == 0)
 			pref = ffs_blkpref_ufs2(ip, lbn, 0, flags | B_METAONLY,
 			NULL);



CVS commit: src/sys/ufs/ffs

2011-04-23 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sat Apr 23 08:23:52 UTC 2011

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

Log Message:
ffs_snapshot(): return an error if the node is an invalid snapshot.


To generate a diff of this commit:
cvs rdiff -u -r1.112 -r1.113 src/sys/ufs/ffs/ffs_snapshot.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_snapshot.c
diff -u src/sys/ufs/ffs/ffs_snapshot.c:1.112 src/sys/ufs/ffs/ffs_snapshot.c:1.113
--- src/sys/ufs/ffs/ffs_snapshot.c:1.112	Mon Apr 18 07:36:13 2011
+++ src/sys/ufs/ffs/ffs_snapshot.c	Sat Apr 23 08:23:52 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_snapshot.c,v 1.112 2011/04/18 07:36:13 hannken Exp $	*/
+/*	$NetBSD: ffs_snapshot.c,v 1.113 2011/04/23 08:23:52 hannken Exp $	*/
 
 /*
  * Copyright 2000 Marshall Kirk McKusick. All Rights Reserved.
@@ -38,7 +38,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_snapshot.c,v 1.112 2011/04/18 07:36:13 hannken Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_snapshot.c,v 1.113 2011/04/23 08:23:52 hannken Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -197,7 +197,9 @@
 	/*
 	 * If the vnode already is a snapshot, return.
 	 */
-	if ((VTOI(vp)-i_flags  (SF_SNAPSHOT | SF_SNAPINVAL)) == SF_SNAPSHOT) {
+	if ((VTOI(vp)-i_flags  SF_SNAPSHOT)) {
+		if ((VTOI(vp)-i_flags  SF_SNAPINVAL))
+			return EINVAL;
 		if (ctime) {
 			ctime-tv_sec = DIP(VTOI(vp), mtime);
 			ctime-tv_nsec = DIP(VTOI(vp), mtimensec);



CVS commit: src/sys/ufs/ffs

2011-04-18 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Mon Apr 18 07:36:14 UTC 2011

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

Log Message:
Preallocate all cylinder group blocks so we no longer redo ~50% of
the cylinder groups while the file system is suspended.
This was removed in error with Rev 1.16.

From Manuel Bouyer bou...@netbsd.org via tech-kern.


To generate a diff of this commit:
cvs rdiff -u -r1.111 -r1.112 src/sys/ufs/ffs/ffs_snapshot.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_snapshot.c
diff -u src/sys/ufs/ffs/ffs_snapshot.c:1.111 src/sys/ufs/ffs/ffs_snapshot.c:1.112
--- src/sys/ufs/ffs/ffs_snapshot.c:1.111	Sun Mar  6 17:08:38 2011
+++ src/sys/ufs/ffs/ffs_snapshot.c	Mon Apr 18 07:36:13 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_snapshot.c,v 1.111 2011/03/06 17:08:38 bouyer Exp $	*/
+/*	$NetBSD: ffs_snapshot.c,v 1.112 2011/04/18 07:36:13 hannken Exp $	*/
 
 /*
  * Copyright 2000 Marshall Kirk McKusick. All Rights Reserved.
@@ -38,7 +38,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_snapshot.c,v 1.111 2011/03/06 17:08:38 bouyer Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_snapshot.c,v 1.112 2011/04/18 07:36:13 hannken Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -405,7 +405,7 @@
 static int
 snapshot_setup(struct mount *mp, struct vnode *vp)
 {
-	int error, n, len, loc;
+	int error, n, len, loc, cg;
 	daddr_t blkno, numblks;
 	struct buf *ibp, *nbp;
 	struct fs *fs = VFSTOUFS(mp)-um_fs;
@@ -501,6 +501,28 @@
 		if (error)
 			goto out;
 		bawrite(nbp);
+		if (wbreak  0  (++n % wbreak) == 0) {
+			UFS_WAPBL_END(mp);
+			error = UFS_WAPBL_BEGIN(mp);
+			if (error)
+return error;
+		}
+	}
+	/*
+	 * Allocate all cylinder group blocks.
+	 */
+	for (cg = 0; cg  fs-fs_ncg; cg++) {
+		error = ffs_balloc(vp, lfragtosize(fs, cgtod(fs, cg)),
+		fs-fs_bsize, l-l_cred, 0, nbp);
+		if (error)
+			goto out;
+		bawrite(nbp);
+		if (wbreak  0  (++n % wbreak) == 0) {
+			UFS_WAPBL_END(mp);
+			error = UFS_WAPBL_BEGIN(mp);
+			if (error)
+return error;
+		}
 	}
 
 out:



CVS commit: src/sys/ufs/ffs

2011-04-15 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Fri Apr 15 15:54:12 UTC 2011

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

Log Message:
ffs_fsync: no need for wapbl_vptomp() here -- vnode is always VREG.


To generate a diff of this commit:
cvs rdiff -u -r1.116 -r1.117 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.116 src/sys/ufs/ffs/ffs_vnops.c:1.117
--- src/sys/ufs/ffs/ffs_vnops.c:1.116	Thu Aug 12 07:41:49 2010
+++ src/sys/ufs/ffs/ffs_vnops.c	Fri Apr 15 15:54:11 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vnops.c,v 1.116 2010/08/12 07:41:49 hannken Exp $	*/
+/*	$NetBSD: ffs_vnops.c,v 1.117 2011/04/15 15:54:11 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_vnops.c,v 1.116 2010/08/12 07:41:49 hannken Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_vnops.c,v 1.117 2011/04/15 15:54:11 hannken Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -282,19 +282,18 @@
 	int bsize;
 	daddr_t blk_high;
 	struct vnode *vp;
-#ifdef WAPBL
 	struct mount *mp;
-#endif
 
 	vp = ap-a_vp;
+	mp = vp-v_mount;
 
-	fstrans_start(vp-v_mount, FSTRANS_LAZY);
+	fstrans_start(mp, FSTRANS_LAZY);
 	if ((ap-a_offlo == 0  ap-a_offhi == 0) || (vp-v_type != VREG)) {
 		error = ffs_full_fsync(vp, ap-a_flags);
 		goto out;
 	}
 
-	bsize = vp-v_mount-mnt_stat.f_iosize;
+	bsize = mp-mnt_stat.f_iosize;
 	blk_high = ap-a_offhi / bsize;
 	if (ap-a_offhi % bsize != 0)
 		blk_high++;
@@ -312,7 +311,7 @@
 	}
 
 #ifdef WAPBL
-	mp = wapbl_vptomp(vp);
+	KASSERT(vp-v_type == VREG);
 	if (mp-mnt_wapbl) {
 		/*
 		 * Don't bother writing out metadata if the syncer is
@@ -321,7 +320,7 @@
 		 * VFS_SYNC().
 		 */
 		if ((ap-a_flags  (FSYNC_DATAONLY | FSYNC_LAZY)) != 0) {
-			fstrans_done(vp-v_mount);
+			fstrans_done(mp);
 			return 0;
 		}
 		error = 0;
@@ -330,7 +329,7 @@
  IN_MODIFIED | IN_ACCESSED)) {
 			error = UFS_WAPBL_BEGIN(mp);
 			if (error) {
-fstrans_done(vp-v_mount);
+fstrans_done(mp);
 return error;
 			}
 			error = ffs_update(vp, NULL, NULL, UPDATE_CLOSE |
@@ -338,11 +337,11 @@
 			UFS_WAPBL_END(mp);
 		}
 		if (error || (ap-a_flags  FSYNC_NOLOG) != 0) {
-			fstrans_done(vp-v_mount);
+			fstrans_done(mp);
 			return error;
 		}
 		error = wapbl_flush(mp-mnt_wapbl, 0);
-		fstrans_done(vp-v_mount);
+		fstrans_done(mp);
 		return error;
 	}
 #endif /* WAPBL */
@@ -389,7 +388,7 @@
 	}
 
 out:
-	fstrans_done(vp-v_mount);
+	fstrans_done(mp);
 	return error;
 }
 



CVS commit: src/sys/ufs/ufs

2011-04-04 Thread Adam Hoka
Module Name:src
Committed By:   ahoka
Date:   Mon Apr  4 21:46:15 UTC 2011

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

Log Message:
add struct ufid; so we can include it without ufs/inode.h


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/sys/ufs/ufs/ufs_extern.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/ufs_extern.h
diff -u src/sys/ufs/ufs/ufs_extern.h:1.63 src/sys/ufs/ufs/ufs_extern.h:1.64
--- src/sys/ufs/ufs/ufs_extern.h:1.63	Sun Mar  6 17:08:39 2011
+++ src/sys/ufs/ufs/ufs_extern.h	Mon Apr  4 21:46:15 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_extern.h,v 1.63 2011/03/06 17:08:39 bouyer Exp $	*/
+/*	$NetBSD: ufs_extern.h,v 1.64 2011/04/04 21:46:15 ahoka Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993, 1994
@@ -49,6 +49,7 @@
 struct mount;
 struct nameidata;
 struct lwp;
+struct ufid;
 struct ufs_args;
 struct ufsmount;
 struct uio;



CVS commit: src/sys/ufs/ffs

2011-03-27 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Mar 27 08:04:50 UTC 2011

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

Log Message:
Don't abort when APPLE_UFS autodetection cannot read the apple ufs label
due to sector size or alignment problems. Autodetection is only a safety
measure, you should mark the filesystem type in the BSD disklabel.


To generate a diff of this commit:
cvs rdiff -u -r1.264 -r1.265 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.264 src/sys/ufs/ffs/ffs_vfsops.c:1.265
--- src/sys/ufs/ffs/ffs_vfsops.c:1.264	Sun Mar  6 17:08:38 2011
+++ src/sys/ufs/ffs/ffs_vfsops.c	Sun Mar 27 08:04:50 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.264 2011/03/06 17:08:38 bouyer Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.265 2011/03/27 08:04:50 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.264 2011/03/06 17:08:38 bouyer Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.265 2011/03/27 08:04:50 mlelstv Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -678,17 +678,22 @@
 	else {
 		/* Manually look for an apple ufs label, and if a valid one
 		 * is found, then treat it like an Apple UFS filesystem anyway
+		 *
+		 * EINVAL is most probably a blocksize or alignment problem,
+		 * it is unlikely that this is an Apple UFS filesystem then.
 		 */
 		error = bread(devvp, (daddr_t)(APPLEUFS_LABEL_OFFSET / DEV_BSIZE),
 			APPLEUFS_LABEL_SIZE, cred, 0, bp);
-		if (error) {
+		if (error  error != EINVAL) {
 			brelse(bp, 0);
 			return (error);
 		}
-		error = ffs_appleufs_validate(fs-fs_fsmnt,
-			(struct appleufslabel *)bp-b_data, NULL);
-		if (error == 0)
-			ump-um_flags |= UFS_ISAPPLEUFS;
+		if (error == 0) {
+			error = ffs_appleufs_validate(fs-fs_fsmnt,
+(struct appleufslabel *)bp-b_data, NULL);
+			if (error == 0)
+ump-um_flags |= UFS_ISAPPLEUFS;
+		}
 		brelse(bp, 0);
 		bp = NULL;
 	}



CVS commit: src/sys/ufs/ufs

2011-03-25 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Fri Mar 25 10:25:17 UTC 2011

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

Log Message:
Don't include quota/quotaprop.h for tools.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/ufs/ufs/quota.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/quota.h
diff -u src/sys/ufs/ufs/quota.h:1.27 src/sys/ufs/ufs/quota.h:1.28
--- src/sys/ufs/ufs/quota.h:1.27	Thu Mar 24 17:05:45 2011
+++ src/sys/ufs/ufs/quota.h	Fri Mar 25 10:25:17 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: quota.h,v 1.27 2011/03/24 17:05:45 bouyer Exp $	*/
+/*	$NetBSD: quota.h,v 1.28 2011/03/25 10:25:17 bouyer Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1993
@@ -36,7 +36,6 @@
 
 #ifndef	_UFS_UFS_QUOTA_H_
 #define	_UFS_UFS_QUOTA_H_
-#include quota/quotaprop.h
 
 /*
  * These definitions are common to the original disk quota implementation
@@ -55,6 +54,8 @@
 #define	GRPQUOTA	1	/* element used for group quotas */
 
 
+#if !defined(HAVE_NBTOOL_CONFIG_H)
+#include quota/quotaprop.h
 __inline static int __unused
 ufsclass2qtype(int class)
 {
@@ -80,6 +81,7 @@
 		return -1;
 	}
 }
+#endif /* !defined(HAVE_NBTOOL_CONFIG_H) */
 
 #ifdef _KERNEL
 



CVS commit: src/sys/ufs/ufs

2011-03-09 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Wed Mar  9 18:12:04 UTC 2011

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

Log Message:
typo in comment


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 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.2 src/sys/ufs/ufs/quota2.h:1.3
--- src/sys/ufs/ufs/quota2.h:1.2	Sun Mar  6 17:08:39 2011
+++ src/sys/ufs/ufs/quota2.h	Wed Mar  9 18:12:04 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: quota2.h,v 1.2 2011/03/06 17:08:39 bouyer Exp $ */
+/* $NetBSD: quota2.h,v 1.3 2011/03/09 18:12:04 dholland Exp $ */
 /*-
   * Copyright (c) 2010 Manuel Bouyer
   * All rights reserved.
@@ -67,7 +67,7 @@
 	struct quota2_val q2e_val[N_QL];
 	/* pointer to next entry for this list (offset in the file) */
 	uint64_t q2e_next;
-	/* ownerchip information */
+	/* ownership information */
 	uint32_t q2e_uid;
 	uint32_t q2e_pad;
 };



CVS commit: src/sys/ufs

2011-03-05 Thread Mindaugas Rasiukevicius
Module Name:src
Committed By:   rmind
Date:   Sun Mar  6 04:46:27 UTC 2011

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

Log Message:
{ffs_nodealloccg,ext2fs_nodealloccg,ext2fs_mapsearch}: use XOR and ffs()
to find free bits in the inode and block bitmaps, instead of the loop.

Obtained from FreeBSD (changes by jhb).


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/sys/ufs/ext2fs/ext2fs_alloc.c
cvs rdiff -u -r1.125 -r1.126 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/ext2fs/ext2fs_alloc.c
diff -u src/sys/ufs/ext2fs/ext2fs_alloc.c:1.41 src/sys/ufs/ext2fs/ext2fs_alloc.c:1.42
--- src/sys/ufs/ext2fs/ext2fs_alloc.c:1.41	Mon Oct 19 18:41:17 2009
+++ src/sys/ufs/ext2fs/ext2fs_alloc.c	Sun Mar  6 04:46:26 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ext2fs_alloc.c,v 1.41 2009/10/19 18:41:17 bouyer Exp $	*/
+/*	$NetBSD: ext2fs_alloc.c,v 1.42 2011/03/06 04:46:26 rmind Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -60,7 +60,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ext2fs_alloc.c,v 1.41 2009/10/19 18:41:17 bouyer Exp $);
+__KERNEL_RCSID(0, $NetBSD: ext2fs_alloc.c,v 1.42 2011/03/06 04:46:26 rmind Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -470,16 +470,12 @@
 		}
 	}
 	i = start + len - loc;
-	map = ibp[i];
-	ipref = i * NBBY;
-	for (i = 1; i  (1  NBBY); i = 1, ipref++) {
-		if ((map  i) == 0) {
-			goto gotit;
-		}
+	map = ibp[i] ^ 0xff;
+	if (map == 0) {
+		printf(fs = %s\n, fs-e2fs_fsmnt);
+		panic(ext2fs_nodealloccg: block not in map);
 	}
-	printf(fs = %s\n, fs-e2fs_fsmnt);
-	panic(ext2fs_nodealloccg: block not in map);
-	/* NOTREACHED */
+	ipref = i * NBBY + ffs(map) - 1;
 gotit:
 	setbit(ibp, ipref);
 	fs-e2fs.e2fs_ficount--;
@@ -595,7 +591,6 @@
 static daddr_t
 ext2fs_mapsearch(struct m_ext2fs *fs, char *bbp, daddr_t bpref)
 {
-	daddr_t bno;
 	int start, len, loc, i, map;
 
 	/*
@@ -620,15 +615,12 @@
 		}
 	}
 	i = start + len - loc;
-	map = bbp[i];
-	bno = i * NBBY;
-	for (i = 1; i  (1  NBBY); i = 1, bno++) {
-		if ((map  i) == 0)
-			return (bno);
-	}
-	printf(fs = %s\n, fs-e2fs_fsmnt);
-	panic(ext2fs_mapsearch: block not in map);
-	/* NOTREACHED */
+	map = bbp[i] ^ 0xff;
+	if (map == 0) {
+		printf(fs = %s\n, fs-e2fs_fsmnt);
+		panic(ext2fs_mapsearch: block not in map);
+	}
+	return i * NBBY + ffs(map) - 1;
 }
 
 /*

Index: src/sys/ufs/ffs/ffs_alloc.c
diff -u src/sys/ufs/ffs/ffs_alloc.c:1.125 src/sys/ufs/ffs/ffs_alloc.c:1.126
--- src/sys/ufs/ffs/ffs_alloc.c:1.125	Sun Feb 21 13:55:58 2010
+++ src/sys/ufs/ffs/ffs_alloc.c	Sun Mar  6 04:46:26 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_alloc.c,v 1.125 2010/02/21 13:55:58 mlelstv Exp $	*/
+/*	$NetBSD: ffs_alloc.c,v 1.126 2011/03/06 04:46:26 rmind Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_alloc.c,v 1.125 2010/02/21 13:55:58 mlelstv Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_alloc.c,v 1.126 2011/03/06 04:46:26 rmind Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -1330,17 +1330,13 @@
 		}
 	}
 	i = start + len - loc;
-	map = inosused[i];
-	ipref = i * NBBY;
-	for (i = 1; i  (1  NBBY); i = 1, ipref++) {
-		if ((map  i) == 0) {
-			cgp-cg_irotor = ufs_rw32(ipref, needswap);
-			goto gotit;
-		}
+	map = inosused[i] ^ 0xff;
+	if (map == 0) {
+		printf(fs = %s\n, fs-fs_fsmnt);
+		panic(ffs_nodealloccg: block not in map);
 	}
-	printf(fs = %s\n, fs-fs_fsmnt);
-	panic(ffs_nodealloccg: block not in map);
-	/* NOTREACHED */
+	ipref = i * NBBY + ffs(map) - 1;
+	cgp-cg_irotor = ufs_rw32(ipref, needswap);
 gotit:
 	UFS_WAPBL_REGISTER_INODE(ip-i_ump-um_mountp, cg * fs-fs_ipg + ipref,
 	mode);



CVS commit: src/sys/ufs/ffs

2011-02-23 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed Feb 23 08:53:22 UTC 2011

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

Log Message:
Quiesce CC ('blkno' may be used uninitialized in this function).


To generate a diff of this commit:
cvs rdiff -u -r1.107 -r1.108 src/sys/ufs/ffs/ffs_snapshot.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_snapshot.c
diff -u src/sys/ufs/ffs/ffs_snapshot.c:1.107 src/sys/ufs/ffs/ffs_snapshot.c:1.108
--- src/sys/ufs/ffs/ffs_snapshot.c:1.107	Tue Feb 22 20:25:54 2011
+++ src/sys/ufs/ffs/ffs_snapshot.c	Wed Feb 23 08:53:21 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_snapshot.c,v 1.107 2011/02/22 20:25:54 he Exp $	*/
+/*	$NetBSD: ffs_snapshot.c,v 1.108 2011/02/23 08:53:21 hannken Exp $	*/
 
 /*
  * Copyright 2000 Marshall Kirk McKusick. All Rights Reserved.
@@ -38,7 +38,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_snapshot.c,v 1.107 2011/02/22 20:25:54 he Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_snapshot.c,v 1.108 2011/02/23 08:53:21 hannken Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -1826,6 +1826,8 @@
 	uint32_t gen;
 	int lower, upper, mid, snapshot_locked = 0, error = 0;
 
+	blkno = 0; /* XXX: GCC */
+
 	/*
 	 * Check for valid snapshots.
 	 */



CVS commit: src/sys/ufs/ffs

2011-02-23 Thread David Young
Module Name:src
Committed By:   dyoung
Date:   Wed Feb 23 17:05:33 UTC 2011

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

Log Message:
Initialize blkno to 0 right before the snapblkaddr() call that GCC does
not understand so that if ffs_copyonwrite() sprouts a new code path that
does not initialize blkno, the compiler has the chance to reveal it.


To generate a diff of this commit:
cvs rdiff -u -r1.108 -r1.109 src/sys/ufs/ffs/ffs_snapshot.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_snapshot.c
diff -u src/sys/ufs/ffs/ffs_snapshot.c:1.108 src/sys/ufs/ffs/ffs_snapshot.c:1.109
--- src/sys/ufs/ffs/ffs_snapshot.c:1.108	Wed Feb 23 08:53:21 2011
+++ src/sys/ufs/ffs/ffs_snapshot.c	Wed Feb 23 17:05:33 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_snapshot.c,v 1.108 2011/02/23 08:53:21 hannken Exp $	*/
+/*	$NetBSD: ffs_snapshot.c,v 1.109 2011/02/23 17:05:33 dyoung Exp $	*/
 
 /*
  * Copyright 2000 Marshall Kirk McKusick. All Rights Reserved.
@@ -38,7 +38,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_snapshot.c,v 1.108 2011/02/23 08:53:21 hannken Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_snapshot.c,v 1.109 2011/02/23 17:05:33 dyoung Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -1826,8 +1826,6 @@
 	uint32_t gen;
 	int lower, upper, mid, snapshot_locked = 0, error = 0;
 
-	blkno = 0; /* XXX: GCC */
-
 	/*
 	 * Check for valid snapshots.
 	 */
@@ -1898,6 +1896,7 @@
 			blkno = db_get(ip, lbn);
 		} else {
 			mutex_exit(si-si_lock);
+			blkno = 0; /* XXX: GCC */
 			if ((error = snapblkaddr(vp, lbn, blkno)) != 0) {
 mutex_enter(si-si_lock);
 break;



CVS commit: src/sys/ufs/ffs

2011-02-22 Thread Havard Eidnes
Module Name:src
Committed By:   he
Date:   Tue Feb 22 20:25:54 UTC 2011

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

Log Message:
Move blocks_in_journal() in under #ifndef FFS_NO_SNAPSHOT, all uses
are under that ifdef anyway; this allows build with FFS_NO_SNAPSHOT defined.


To generate a diff of this commit:
cvs rdiff -u -r1.106 -r1.107 src/sys/ufs/ffs/ffs_snapshot.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_snapshot.c
diff -u src/sys/ufs/ffs/ffs_snapshot.c:1.106 src/sys/ufs/ffs/ffs_snapshot.c:1.107
--- src/sys/ufs/ffs/ffs_snapshot.c:1.106	Mon Feb 21 09:29:21 2011
+++ src/sys/ufs/ffs/ffs_snapshot.c	Tue Feb 22 20:25:54 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_snapshot.c,v 1.106 2011/02/21 09:29:21 hannken Exp $	*/
+/*	$NetBSD: ffs_snapshot.c,v 1.107 2011/02/22 20:25:54 he Exp $	*/
 
 /*
  * Copyright 2000 Marshall Kirk McKusick. All Rights Reserved.
@@ -38,7 +38,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_snapshot.c,v 1.106 2011/02/21 09:29:21 hannken Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_snapshot.c,v 1.107 2011/02/22 20:25:54 he Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -115,7 +115,9 @@
 static int rwfsblk(struct vnode *, int, void *, daddr_t);
 static int syncsnap(struct vnode *);
 static int wrsnapblk(struct vnode *, void *, daddr_t);
+#if !defined(FFS_NO_SNAPSHOT)
 static int blocks_in_journal(struct fs *);
+#endif
 
 static inline bool is_active_snapshot(struct snap_info *, struct inode *);
 static inline daddr_t db_get(struct inode *, int);
@@ -1282,6 +1284,33 @@
 	UFS_WAPBL_END(mp);
 	return (0);
 }
+
+/*
+ * Number of blocks that fit into the journal or zero if not logging.
+ */
+static int
+blocks_in_journal(struct fs *fs)
+{
+	off_t bpj;
+
+	if ((fs-fs_flags  FS_DOWAPBL) == 0)
+		return 0;
+	bpj = 1;
+	if (fs-fs_journal_version == UFS_WAPBL_VERSION) {
+		switch (fs-fs_journal_location) {
+		case UFS_WAPBL_JOURNALLOC_END_PARTITION:
+			bpj = (off_t)fs-fs_journallocs[UFS_WAPBL_EPART_BLKSZ]*
+			fs-fs_journallocs[UFS_WAPBL_EPART_COUNT];
+			break;
+		case UFS_WAPBL_JOURNALLOC_IN_FILESYSTEM:
+			bpj = (off_t)fs-fs_journallocs[UFS_WAPBL_INFS_BLKSZ]*
+			fs-fs_journallocs[UFS_WAPBL_INFS_COUNT];
+			break;
+		}
+	}
+	bpj /= fs-fs_bsize;
+	return (bpj  0 ? bpj : 1);
+}
 #endif /* defined(FFS_NO_SNAPSHOT) */
 
 /*
@@ -2172,33 +2201,6 @@
 }
 
 /*
- * Number of blocks that fit into the journal or zero if not logging.
- */
-static int
-blocks_in_journal(struct fs *fs)
-{
-	off_t bpj;
-
-	if ((fs-fs_flags  FS_DOWAPBL) == 0)
-		return 0;
-	bpj = 1;
-	if (fs-fs_journal_version == UFS_WAPBL_VERSION) {
-		switch (fs-fs_journal_location) {
-		case UFS_WAPBL_JOURNALLOC_END_PARTITION:
-			bpj = (off_t)fs-fs_journallocs[UFS_WAPBL_EPART_BLKSZ]*
-			fs-fs_journallocs[UFS_WAPBL_EPART_COUNT];
-			break;
-		case UFS_WAPBL_JOURNALLOC_IN_FILESYSTEM:
-			bpj = (off_t)fs-fs_journallocs[UFS_WAPBL_INFS_BLKSZ]*
-			fs-fs_journallocs[UFS_WAPBL_INFS_COUNT];
-			break;
-		}
-	}
-	bpj /= fs-fs_bsize;
-	return (bpj  0 ? bpj : 1);
-}
-
-/*
  * Get/Put direct block from inode or buffer containing disk addresses. Take
  * care for fs type (UFS1/UFS2) and byte swapping. These functions should go
  * into a global include.



CVS commit: src/sys/ufs/ffs

2011-02-21 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Mon Feb 21 09:29:21 UTC 2011

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

Log Message:
Change the snapshot lock:
- No need to take the snapshot lock while the file system is suspended.
- Allow ffs_copyonwrite() one level of recursion with snapshots locked.
- Do the block address lookup with snapshots locked.
- Take the snapshot lock while removing a snapshot from the list.

While hunting deadlocks change the transaction scope for ffs_snapremove().
We could deadlock from UFS_WAPBL_BEGIN() with a buffer held.


To generate a diff of this commit:
cvs rdiff -u -r1.105 -r1.106 src/sys/ufs/ffs/ffs_snapshot.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_snapshot.c
diff -u src/sys/ufs/ffs/ffs_snapshot.c:1.105 src/sys/ufs/ffs/ffs_snapshot.c:1.106
--- src/sys/ufs/ffs/ffs_snapshot.c:1.105	Fri Feb 18 14:48:54 2011
+++ src/sys/ufs/ffs/ffs_snapshot.c	Mon Feb 21 09:29:21 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_snapshot.c,v 1.105 2011/02/18 14:48:54 bouyer Exp $	*/
+/*	$NetBSD: ffs_snapshot.c,v 1.106 2011/02/21 09:29:21 hannken Exp $	*/
 
 /*
  * Copyright 2000 Marshall Kirk McKusick. All Rights Reserved.
@@ -38,7 +38,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_snapshot.c,v 1.105 2011/02/18 14:48:54 bouyer Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_snapshot.c,v 1.106 2011/02/21 09:29:21 hannken Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -79,6 +79,7 @@
 struct snap_info {
 	kmutex_t si_lock;			/* Lock this snapinfo */
 	kmutex_t si_snaplock;			/* Snapshot vnode common lock */
+	lwp_t *si_owner;			/* Sanplock owner */
 	TAILQ_HEAD(inodelst, inode) si_snapshots; /* List of active snapshots */
 	daddr_t *si_snapblklist;		/* Snapshot block hints list */
 	uint32_t si_gen;			/* Incremented on change */
@@ -140,6 +141,7 @@
 	TAILQ_INIT(si-si_snapshots);
 	mutex_init(si-si_lock, MUTEX_DEFAULT, IPL_NONE);
 	mutex_init(si-si_snaplock, MUTEX_DEFAULT, IPL_NONE);
+	si-si_owner = NULL;
 	si-si_gen = 0;
 	si-si_snapblklist = NULL;
 
@@ -173,7 +175,6 @@
 }
 #else /* defined(FFS_NO_SNAPSHOT) */
 	bool suspended = false;
-	bool snapshot_locked = false;
 	int error, redo = 0, snaploc;
 	void *sbbuf = NULL;
 	daddr_t *snaplist = NULL, snaplistsize = 0;
@@ -269,11 +270,6 @@
 	if (error)
 		goto out;
 	/*
-	 * Acquire the snapshot lock.
-	 */
-	mutex_enter(si-si_snaplock);
-	snapshot_locked = true;
-	/*
 	 * Record snapshot inode. Since this is the newest snapshot,
 	 * it must be placed at the end of the list.
 	 */
@@ -376,8 +372,6 @@
 	si-si_gen++;
 	mutex_exit(si-si_lock);
 
-	if (snapshot_locked)
-		mutex_exit(si-si_snaplock);
 	if (suspended) {
 		vfs_resume(vp-v_mount);
 #ifdef DEBUG
@@ -1354,8 +1348,7 @@
 	struct snap_info *si;
 	struct lwp *l = curlwp;
 	daddr_t numblks, blkno, dblk;
-	int error, loc, last, n;
-	const int wbreak = blocks_in_journal(fs)/8;
+	int error, loc, last;
 
 	si = VFSTOUFS(mp)-um_snapinfo;
 	/*
@@ -1365,6 +1358,7 @@
 	 *
 	 * Clear copy-on-write flag if last snapshot.
 	 */
+	mutex_enter(si-si_snaplock);
 	mutex_enter(si-si_lock);
 	if (is_active_snapshot(si, ip)) {
 		TAILQ_REMOVE(si-si_snapshots, ip, i_nextsnap);
@@ -1374,18 +1368,22 @@
 			si-si_snapblklist = xp-i_snapblklist;
 			si-si_gen++;
 			mutex_exit(si-si_lock);
+			mutex_exit(si-si_snaplock);
 		} else {
 			si-si_snapblklist = 0;
 			si-si_gen++;
 			mutex_exit(si-si_lock);
+			mutex_exit(si-si_snaplock);
 			fscow_disestablish(mp, ffs_copyonwrite, devvp);
 		}
 		if (ip-i_snapblklist != NULL) {
 			free(ip-i_snapblklist, M_UFSMNT);
 			ip-i_snapblklist = NULL;
 		}
-	} else
+	} else {
 		mutex_exit(si-si_lock);
+		mutex_exit(si-si_snaplock);
+	}
 	/*
 	 * Clear all BLK_NOCOPY fields. Pass any block claims to other
 	 * snapshots that want them (see ffs_snapblkfree below).
@@ -1402,7 +1400,7 @@
 		}
 	}
 	numblks = howmany(ip-i_size, fs-fs_bsize);
-	for (blkno = NDADDR, n = 0; blkno  numblks; blkno += NINDIR(fs)) {
+	for (blkno = NDADDR; blkno  numblks; blkno += NINDIR(fs)) {
 		error = ffs_balloc(vp, lblktosize(fs, (off_t)blkno),
 		fs-fs_bsize, l-l_cred, B_METAONLY, ibp);
 		if (error)
@@ -1412,12 +1410,6 @@
 		else
 			last = fs-fs_size - blkno;
 		for (loc = 0; loc  last; loc++) {
-			if (wbreak  0  (++n % wbreak) == 0) {
-UFS_WAPBL_END(mp);
-error = UFS_WAPBL_BEGIN(mp);
-if (error)
-	panic(UFS_WAPBL_BEGIN failed);
-			}
 			dblk = idb_get(ip, ibp-b_data, loc);
 			if (dblk == BLK_NOCOPY || dblk == BLK_SNAP)
 idb_assign(ip, ibp-b_data, loc, 0);
@@ -1429,6 +1421,9 @@
 			}
 		}
 		bawrite(ibp);
+		UFS_WAPBL_END(mp);
+		error = UFS_WAPBL_BEGIN(mp);
+		KASSERT(error == 0);
 	}
 	/*
 	 * Clear snapshot flag and drop reference.
@@ -1469,25 +1464,18 @@
 	daddr_t lbn;
 	daddr_t blkno;
 	uint32_t gen;
-	int indiroff = 0, snapshot_locked = 0, error = 0, claimedblk = 0;
+	int indiroff = 0, error = 0, claimedblk = 

CVS commit: src/sys/ufs/ffs

2011-02-18 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Fri Feb 18 08:39:13 UTC 2011

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

Log Message:
Revert rev. 1.101.  Dead snapshots would hang around until unmount.

Adresses PR #44568 (WAPBL doens't play nice with snapshots).


To generate a diff of this commit:
cvs rdiff -u -r1.103 -r1.104 src/sys/ufs/ffs/ffs_snapshot.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_snapshot.c
diff -u src/sys/ufs/ffs/ffs_snapshot.c:1.103 src/sys/ufs/ffs/ffs_snapshot.c:1.104
--- src/sys/ufs/ffs/ffs_snapshot.c:1.103	Wed Feb 16 19:43:50 2011
+++ src/sys/ufs/ffs/ffs_snapshot.c	Fri Feb 18 08:39:13 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_snapshot.c,v 1.103 2011/02/16 19:43:50 hannken Exp $	*/
+/*	$NetBSD: ffs_snapshot.c,v 1.104 2011/02/18 08:39:13 hannken Exp $	*/
 
 /*
  * Copyright 2000 Marshall Kirk McKusick. All Rights Reserved.
@@ -38,7 +38,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_snapshot.c,v 1.103 2011/02/16 19:43:50 hannken Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_snapshot.c,v 1.104 2011/02/18 08:39:13 hannken Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -280,7 +280,6 @@
 	fs-fs_snapinum[snaploc] = ip-i_number;
 
 	mutex_enter(si-si_lock);
-	vref(vp);
 	if (is_active_snapshot(si, ip))
 		panic(ffs_snapshot: %PRIu64 already on list, ip-i_number);
 	TAILQ_INSERT_TAIL(si-si_snapshots, ip, i_nextsnap);
@@ -394,7 +393,8 @@
 			(void) ffs_truncate(vp, (off_t)0, 0, NOCRED);
 			UFS_WAPBL_END(mp);
 		}
-	}
+	} else
+		vref(vp);
 	return (error);
 }
 
@@ -1313,8 +1313,10 @@
 		if (xp == ip)
 			break;
 	mutex_exit(si-si_lock);
+	if (xp != NULL)
+		vrele(ITOV(ip));
 #ifdef DEBUG
-	if (snapdebug  xp == NULL)
+	else if (snapdebug)
 		printf(ffs_snapgone: lost snapshot vnode %llu\n,
 		(unsigned long long)ip-i_number);
 #endif
@@ -1382,7 +1384,6 @@
 			free(ip-i_snapblklist, M_UFSMNT);
 			ip-i_snapblklist = NULL;
 		}
-		vrele(vp);
 	} else
 		mutex_exit(si-si_lock);
 	/*
@@ -1763,25 +1764,28 @@
 ffs_snapshot_unmount(struct mount *mp)
 {
 	struct vnode *devvp = VFSTOUFS(mp)-um_devvp;
-	struct inode *ip;
+	struct inode *xp;
+	struct vnode *vp = NULL;
 	struct snap_info *si;
-	bool list_empty = true;
 
 	si = VFSTOUFS(mp)-um_snapinfo;
 	mutex_enter(si-si_lock);
-	while ((ip = TAILQ_FIRST(si-si_snapshots)) != 0) {
-		list_empty = false;
-		TAILQ_REMOVE(si-si_snapshots, ip, i_nextsnap);
-		if (ip-i_snapblklist == si-si_snapblklist)
+	while ((xp = TAILQ_FIRST(si-si_snapshots)) != 0) {
+		vp = ITOV(xp);
+		TAILQ_REMOVE(si-si_snapshots, xp, i_nextsnap);
+		if (xp-i_snapblklist == si-si_snapblklist)
 			si-si_snapblklist = NULL;
-		free(ip-i_snapblklist, M_UFSMNT);
-		si-si_gen++;
-		mutex_exit(si-si_lock);
-		vrele(ITOV(ip));
-		mutex_enter(si-si_lock);
+		free(xp-i_snapblklist, M_UFSMNT);
+		if (xp-i_nlink  0) {
+			si-si_gen++;
+			mutex_exit(si-si_lock);
+			vrele(vp);
+			mutex_enter(si-si_lock);
+		}
 	}
+	si-si_gen++;
 	mutex_exit(si-si_lock);
-	if (! list_empty)
+	if (vp)
 		fscow_disestablish(mp, ffs_copyonwrite, devvp);
 }
 



CVS commit: src/sys/ufs/ffs

2011-02-18 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Fri Feb 18 14:48:54 UTC 2011

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

Log Message:
Initialize error in snapshot_expunge(); if the list is empty error would
be returned uninitialized. t_snapshot_v2 was failing for me when
librumpffs was compiled DGB=-g.
No idea why gcc didn't catch this ...


To generate a diff of this commit:
cvs rdiff -u -r1.104 -r1.105 src/sys/ufs/ffs/ffs_snapshot.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_snapshot.c
diff -u src/sys/ufs/ffs/ffs_snapshot.c:1.104 src/sys/ufs/ffs/ffs_snapshot.c:1.105
--- src/sys/ufs/ffs/ffs_snapshot.c:1.104	Fri Feb 18 08:39:13 2011
+++ src/sys/ufs/ffs/ffs_snapshot.c	Fri Feb 18 14:48:54 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_snapshot.c,v 1.104 2011/02/18 08:39:13 hannken Exp $	*/
+/*	$NetBSD: ffs_snapshot.c,v 1.105 2011/02/18 14:48:54 bouyer Exp $	*/
 
 /*
  * Copyright 2000 Marshall Kirk McKusick. All Rights Reserved.
@@ -38,7 +38,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_snapshot.c,v 1.104 2011/02/18 08:39:13 hannken Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_snapshot.c,v 1.105 2011/02/18 14:48:54 bouyer Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -563,7 +563,7 @@
 snapshot_expunge(struct mount *mp, struct vnode *vp, struct fs *copy_fs,
 daddr_t *snaplistsize, daddr_t **snaplist)
 {
-	int cg, error, len, loc;
+	int cg, error = 0, len, loc;
 	daddr_t blkno, *blkp;
 	struct fs *fs = VFSTOUFS(mp)-um_fs;
 	struct inode *xp;



CVS commit: src/sys/ufs/ffs

2011-02-16 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed Feb 16 19:43:50 UTC 2011

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

Log Message:
Refine the scope of WAPBL transactions so we should no longer get
a wapbl_flush: current transaction too big to flush panic when
creating or removing snapshots on larger logging disks.

Adresses PR #44568 (WAPBL doens't play nice with snapshots).


To generate a diff of this commit:
cvs rdiff -u -r1.102 -r1.103 src/sys/ufs/ffs/ffs_snapshot.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_snapshot.c
diff -u src/sys/ufs/ffs/ffs_snapshot.c:1.102 src/sys/ufs/ffs/ffs_snapshot.c:1.103
--- src/sys/ufs/ffs/ffs_snapshot.c:1.102	Mon Dec 20 00:25:47 2010
+++ src/sys/ufs/ffs/ffs_snapshot.c	Wed Feb 16 19:43:50 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_snapshot.c,v 1.102 2010/12/20 00:25:47 matt Exp $	*/
+/*	$NetBSD: ffs_snapshot.c,v 1.103 2011/02/16 19:43:50 hannken Exp $	*/
 
 /*
  * Copyright 2000 Marshall Kirk McKusick. All Rights Reserved.
@@ -38,7 +38,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_snapshot.c,v 1.102 2010/12/20 00:25:47 matt Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_snapshot.c,v 1.103 2011/02/16 19:43:50 hannken Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -114,6 +114,7 @@
 static int rwfsblk(struct vnode *, int, void *, daddr_t);
 static int syncsnap(struct vnode *);
 static int wrsnapblk(struct vnode *, void *, daddr_t);
+static int blocks_in_journal(struct fs *);
 
 static inline bool is_active_snapshot(struct snap_info *, struct inode *);
 static inline daddr_t db_get(struct inode *, int);
@@ -403,11 +404,12 @@
 static int
 snapshot_setup(struct mount *mp, struct vnode *vp)
 {
-	int error, i, len, loc;
+	int error, n, len, loc;
 	daddr_t blkno, numblks;
 	struct buf *ibp, *nbp;
 	struct fs *fs = VFSTOUFS(mp)-um_fs;
 	struct lwp *l = curlwp;
+	const int wbreak = blocks_in_journal(fs)/8;
 
 	/*
 	 * Check mount, exclusive reference and owner.
@@ -452,13 +454,13 @@
 	error = UFS_WAPBL_BEGIN(mp);
 	if (error)
 		return error;
-	for (blkno = NDADDR, i = 0; blkno  numblks; blkno += NINDIR(fs)) {
+	for (blkno = NDADDR, n = 0; blkno  numblks; blkno += NINDIR(fs)) {
 		error = ffs_balloc(vp, lblktosize(fs, (off_t)blkno),
 		fs-fs_bsize, l-l_cred, B_METAONLY, ibp);
 		if (error)
 			goto out;
 		brelse(ibp, 0);
-		if ((++i % 16) == 0) {
+		if (wbreak  0  (++n % wbreak) == 0) {
 			UFS_WAPBL_END(mp);
 			error = UFS_WAPBL_BEGIN(mp);
 			if (error)
@@ -561,7 +563,6 @@
 snapshot_expunge(struct mount *mp, struct vnode *vp, struct fs *copy_fs,
 daddr_t *snaplistsize, daddr_t **snaplist)
 {
-	bool has_wapbl = false;
 	int cg, error, len, loc;
 	daddr_t blkno, *blkp;
 	struct fs *fs = VFSTOUFS(mp)-um_fs;
@@ -593,10 +594,6 @@
 	 */
 	*snaplistsize = fs-fs_ncg + howmany(fs-fs_cssize, fs-fs_bsize) +
 	FSMAXSNAP + 1 /* superblock */ + 1 /* last block */ + 1 /* size */;
-	error = UFS_WAPBL_BEGIN(mp);
-	if (error)
-		goto out;
-	has_wapbl = true;
 	mutex_enter(mntvnode_lock);
 	/*
 	 * NOTE: not using the TAILQ_FOREACH here since in this loop vgone()
@@ -648,19 +645,30 @@
 		if (loc  NDADDR) {
 			len = fragroundup(fs, blkoff(fs, xp-i_size));
 			if (len  0  len  fs-fs_bsize) {
+error = UFS_WAPBL_BEGIN(mp);
+if (error) {
+	(void)vunmark(mvp);
+	goto out;
+}
 ffs_blkfree_snap(copy_fs, vp, db_get(xp, loc),
 len, xp-i_number);
 blkno = db_get(xp, loc);
 db_assign(xp, loc, 0);
+UFS_WAPBL_END(mp);
 			}
 		}
 		*snaplistsize += 1;
 		error = expunge(vp, xp, copy_fs, fullacct, BLK_NOCOPY);
 		if (blkno)
 			db_assign(xp, loc, blkno);
-		if (!error)
-			error = ffs_freefile_snap(copy_fs, vp, xp-i_number,
-			xp-i_mode);
+		if (!error) {
+			error = UFS_WAPBL_BEGIN(mp);
+			if (!error) {
+error = ffs_freefile_snap(copy_fs, vp,
+xp-i_number, xp-i_mode);
+UFS_WAPBL_END(mp);
+			}
+		}
 		if (error) {
 			(void)vunmark(mvp);
 			goto out;
@@ -688,8 +696,6 @@
 	(*snaplist)[0] = blkp - (*snaplist)[0];
 
 out:
-	if (has_wapbl)
-		UFS_WAPBL_END(mp);
 	if (mvp != NULL)
 		vnfree(mvp);
 	if (logvp != NULL)
@@ -711,16 +717,13 @@
 snapshot_expunge_snap(struct mount *mp, struct vnode *vp,
 struct fs *copy_fs, daddr_t snaplistsize)
 {
-	int error, i;
+	int error = 0, i;
 	daddr_t numblks, *snaplist = NULL;
 	struct fs *fs = VFSTOUFS(mp)-um_fs;
 	struct inode *ip = VTOI(vp), *xp;
 	struct lwp *l = curlwp;
 	struct snap_info *si = VFSTOUFS(mp)-um_snapinfo;
 
-	error = UFS_WAPBL_BEGIN(mp);
-	if (error)
-		return error;
 	TAILQ_FOREACH(xp, si-si_snapshots, i_nextsnap) {
 		if (xp == ip)
 			break;
@@ -729,7 +732,11 @@
 			break;
 		if (xp-i_nlink != 0)
 			continue;
+		error = UFS_WAPBL_BEGIN(mp);
+		if (error)
+			break;
 		error = ffs_freefile_snap(copy_fs, vp, xp-i_number, xp-i_mode);
+		UFS_WAPBL_END(mp);
 		if (error)
 			break;
 	}
@@ -761,12 +768,10 @@
 		

CVS commit: src/sys/ufs/lfs

2011-01-05 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Jan  5 19:34:28 UTC 2011

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

Log Message:
Avoid NULL deref inside a KASSERT, as discussed on tech-kern.


To generate a diff of this commit:
cvs rdiff -u -r1.233 -r1.234 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.233 src/sys/ufs/lfs/lfs_vnops.c:1.234
--- src/sys/ufs/lfs/lfs_vnops.c:1.233	Sun Jan  2 05:09:32 2011
+++ src/sys/ufs/lfs/lfs_vnops.c	Wed Jan  5 19:34:27 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_vnops.c,v 1.233 2011/01/02 05:09:32 dholland Exp $	*/
+/*	$NetBSD: lfs_vnops.c,v 1.234 2011/01/05 19:34:27 martin Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: lfs_vnops.c,v 1.233 2011/01/02 05:09:32 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: lfs_vnops.c,v 1.234 2011/01/05 19:34:27 martin Exp $);
 
 #ifdef _KERNEL_OPT
 #include opt_compat_netbsd.h
@@ -1860,7 +1860,8 @@
 			 * blocks outside our area of interest or beyond
 			 * the end of file.
 			 */
-			KASSERT((curpg-flags  PG_MARKER) == 0);
+			KASSERT(curpg == NULL
+			|| (curpg-flags  PG_MARKER) == 0);
 			if (pages_per_block  1) {
 while (curpg 
 ((curpg-offset  fs-lfs_bmask) ||



CVS commit: src/sys/ufs/ffs

2010-12-24 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Fri Dec 24 13:38:58 UTC 2010

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

Log Message:
For update mounts the root vnode is already in use and we must not
free it. Since the mount persists even when the update fails,
this is not a problem either.


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

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

Modified files:

Index: src/sys/ufs/ffs/ffs_wapbl.c
diff -u src/sys/ufs/ffs/ffs_wapbl.c:1.16 src/sys/ufs/ffs/ffs_wapbl.c:1.17
--- src/sys/ufs/ffs/ffs_wapbl.c:1.16	Thu Dec 23 14:43:37 2010
+++ src/sys/ufs/ffs/ffs_wapbl.c	Fri Dec 24 13:38:57 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_wapbl.c,v 1.16 2010/12/23 14:43:37 mlelstv Exp $	*/
+/*	$NetBSD: ffs_wapbl.c,v 1.17 2010/12/24 13:38:57 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 2003,2006,2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_wapbl.c,v 1.16 2010/12/23 14:43:37 mlelstv Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_wapbl.c,v 1.17 2010/12/24 13:38:57 mlelstv Exp $);
 
 #define WAPBL_INTERNAL
 
@@ -608,13 +608,15 @@
 	if ((error = VFS_ROOT(mp, rvp)) != 0)
 		return error;
 
-	if ((error = UFS_VALLOC(rvp, 0 | S_IFREG, NOCRED, vp)) != 0) {
+	error = UFS_VALLOC(rvp, 0 | S_IFREG, NOCRED, vp);
+	if (mp-mnt_flag  MNT_UPDATE) {
+		vput(rvp);
+	} else {
 		VOP_UNLOCK(rvp);
 		vgone(rvp);
-		return error;
 	}
-	VOP_UNLOCK(rvp);
-	vgone(rvp);
+	if (error != 0)
+		return error;
 
 	vp-v_type = VREG;
 	ip = VTOI(vp);



CVS commit: src/sys/ufs/ffs

2010-12-23 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Thu Dec 23 14:43:37 UTC 2010

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

Log Message:
mount(2) doesn't remove vnodes from the freelist in the error path,
so that they get reused with a invalid pointer to a mount structure.

As a workaround, free the vnodes used to create the in-filesystem journal
immediately.


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

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

Modified files:

Index: src/sys/ufs/ffs/ffs_wapbl.c
diff -u src/sys/ufs/ffs/ffs_wapbl.c:1.15 src/sys/ufs/ffs/ffs_wapbl.c:1.16
--- src/sys/ufs/ffs/ffs_wapbl.c:1.15	Sat Feb 27 12:04:19 2010
+++ src/sys/ufs/ffs/ffs_wapbl.c	Thu Dec 23 14:43:37 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_wapbl.c,v 1.15 2010/02/27 12:04:19 mlelstv Exp $	*/
+/*	$NetBSD: ffs_wapbl.c,v 1.16 2010/12/23 14:43:37 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 2003,2006,2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_wapbl.c,v 1.15 2010/02/27 12:04:19 mlelstv Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_wapbl.c,v 1.16 2010/12/23 14:43:37 mlelstv Exp $);
 
 #define WAPBL_INTERNAL
 
@@ -609,10 +609,12 @@
 		return error;
 
 	if ((error = UFS_VALLOC(rvp, 0 | S_IFREG, NOCRED, vp)) != 0) {
-		vput(rvp);
+		VOP_UNLOCK(rvp);
+		vgone(rvp);
 		return error;
 	}
-	vput(rvp);
+	VOP_UNLOCK(rvp);
+	vgone(rvp);
 
 	vp-v_type = VREG;
 	ip = VTOI(vp);
@@ -634,7 +636,8 @@
 		 */
 		ip-i_nlink = 0;
 		DIP_ASSIGN(ip, nlink, 0);
-		vput(vp);
+		VOP_UNLOCK(vp);
+		vgone(vp);
 
 		return error;
 	}
@@ -643,7 +646,8 @@
 	 * Now that we have the place-holder inode for the journal,
 	 * we don't need the vnode ever again.
 	 */
-	vput(vp);
+	VOP_UNLOCK(vp);
+	vgone(vp);
 
 	return 0;
 }



CVS commit: src/sys/ufs/lfs

2010-12-17 Thread Eduardo Horvath
Module Name:src
Committed By:   eeh
Date:   Sat Dec 18 00:01:46 UTC 2010

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

Log Message:
Byebye deadlock.


To generate a diff of this commit:
cvs rdiff -u -r1.231 -r1.232 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.231 src/sys/ufs/lfs/lfs_vnops.c:1.232
--- src/sys/ufs/lfs/lfs_vnops.c:1.231	Wed Aug  4 10:43:53 2010
+++ src/sys/ufs/lfs/lfs_vnops.c	Sat Dec 18 00:01:46 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_vnops.c,v 1.231 2010/08/04 10:43:53 hannken Exp $	*/
+/*	$NetBSD: lfs_vnops.c,v 1.232 2010/12/18 00:01:46 eeh Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: lfs_vnops.c,v 1.231 2010/08/04 10:43:53 hannken Exp $);
+__KERNEL_RCSID(0, $NetBSD: lfs_vnops.c,v 1.232 2010/12/18 00:01:46 eeh Exp $);
 
 #ifdef _KERNEL_OPT
 #include opt_compat_netbsd.h
@@ -2205,16 +2205,19 @@
 	 * Pagedaemon can't actually write LFS pages; wake up
 	 * the writer to take care of that.  The writer will
 	 * notice the pager inode queue and act on that.
+	 *
+	 * XXX We must drop the vp-interlock before taking the lfs_lock or we
+	 * get a nasty deadlock with lfs_flush_pchain().
 	 */
 	if (pagedaemon) {
+		mutex_exit(vp-v_interlock);
 		mutex_enter(lfs_lock);
 		if (!(ip-i_flags  IN_PAGING)) {
 			ip-i_flags |= IN_PAGING;
 			TAILQ_INSERT_TAIL(fs-lfs_pchainhd, ip, i_lfs_pchain);
-		}
+		} 
 		wakeup(lfs_writer_daemon);
 		mutex_exit(lfs_lock);
-		mutex_exit(vp-v_interlock);
 		preempt();
 		return EWOULDBLOCK;
 	}



CVS commit: src/sys/ufs/ffs

2010-12-12 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sun Dec 12 10:28:22 UTC 2010

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

Log Message:
syncsnap: Use bbusy() to take a buffer from v_dirtyblkhd.


To generate a diff of this commit:
cvs rdiff -u -r1.99 -r1.100 src/sys/ufs/ffs/ffs_snapshot.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_snapshot.c
diff -u src/sys/ufs/ffs/ffs_snapshot.c:1.99 src/sys/ufs/ffs/ffs_snapshot.c:1.100
--- src/sys/ufs/ffs/ffs_snapshot.c:1.99	Thu Jun 24 13:03:19 2010
+++ src/sys/ufs/ffs/ffs_snapshot.c	Sun Dec 12 10:28:22 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_snapshot.c,v 1.99 2010/06/24 13:03:19 hannken Exp $	*/
+/*	$NetBSD: ffs_snapshot.c,v 1.100 2010/12/12 10:28:22 hannken Exp $	*/
 
 /*
  * Copyright 2000 Marshall Kirk McKusick. All Rights Reserved.
@@ -38,7 +38,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_snapshot.c,v 1.99 2010/06/24 13:03:19 hannken Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_snapshot.c,v 1.100 2010/12/12 10:28:22 hannken Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -2081,9 +2081,14 @@
 
 	mutex_enter(bufcache_lock);
 	while ((bp = LIST_FIRST(vp-v_dirtyblkhd))) {
-		KASSERT((bp-b_cflags  BC_BUSY) == 0);
+		error = bbusy(bp, false, 0, NULL);
+		if (error == EPASSTHROUGH)
+			continue;
+		else if (error != 0) {
+			mutex_exit(bufcache_lock);
+			return error;
+		}
 		KASSERT(bp-b_bcount == fs-fs_bsize);
-		bp-b_cflags |= BC_BUSY;
 		mutex_exit(bufcache_lock);
 		error = rwfsblk(vp, B_WRITE, bp-b_data,
 		fragstoblks(fs, dbtofsb(fs, bp-b_blkno)));



CVS commit: src/sys/ufs/ffs

2010-12-12 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sun Dec 12 10:29:25 UTC 2010

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

Log Message:
Keep a reference to the snapshot vnode until it gets removed from the
snapshot list.


To generate a diff of this commit:
cvs rdiff -u -r1.100 -r1.101 src/sys/ufs/ffs/ffs_snapshot.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_snapshot.c
diff -u src/sys/ufs/ffs/ffs_snapshot.c:1.100 src/sys/ufs/ffs/ffs_snapshot.c:1.101
--- src/sys/ufs/ffs/ffs_snapshot.c:1.100	Sun Dec 12 10:28:22 2010
+++ src/sys/ufs/ffs/ffs_snapshot.c	Sun Dec 12 10:29:25 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_snapshot.c,v 1.100 2010/12/12 10:28:22 hannken Exp $	*/
+/*	$NetBSD: ffs_snapshot.c,v 1.101 2010/12/12 10:29:25 hannken Exp $	*/
 
 /*
  * Copyright 2000 Marshall Kirk McKusick. All Rights Reserved.
@@ -38,7 +38,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_snapshot.c,v 1.100 2010/12/12 10:28:22 hannken Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_snapshot.c,v 1.101 2010/12/12 10:29:25 hannken Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -278,6 +278,7 @@
 	fs-fs_snapinum[snaploc] = ip-i_number;
 
 	mutex_enter(si-si_lock);
+	vref(vp);
 	if (is_active_snapshot(si, ip))
 		panic(ffs_snapshot: %PRIu64 already on list, ip-i_number);
 	TAILQ_INSERT_TAIL(si-si_snapshots, ip, i_nextsnap);
@@ -391,8 +392,7 @@
 			(void) ffs_truncate(vp, (off_t)0, 0, NOCRED);
 			UFS_WAPBL_END(mp);
 		}
-	} else
-		vref(vp);
+	}
 	return (error);
 }
 
@@ -1269,10 +1269,8 @@
 		if (xp == ip)
 			break;
 	mutex_exit(si-si_lock);
-	if (xp != NULL)
-		vrele(ITOV(ip));
 #ifdef DEBUG
-	else if (snapdebug)
+	if (snapdebug  xp == NULL)
 		printf(ffs_snapgone: lost snapshot vnode %llu\n,
 		(unsigned long long)ip-i_number);
 #endif
@@ -1339,6 +1337,7 @@
 			free(ip-i_snapblklist, M_UFSMNT);
 			ip-i_snapblklist = NULL;
 		}
+		vrele(vp);
 	} else
 		mutex_exit(si-si_lock);
 	/*
@@ -1713,28 +1712,25 @@
 ffs_snapshot_unmount(struct mount *mp)
 {
 	struct vnode *devvp = VFSTOUFS(mp)-um_devvp;
-	struct inode *xp;
-	struct vnode *vp = NULL;
+	struct inode *ip;
 	struct snap_info *si;
+	bool list_empty = true;
 
 	si = VFSTOUFS(mp)-um_snapinfo;
 	mutex_enter(si-si_lock);
-	while ((xp = TAILQ_FIRST(si-si_snapshots)) != 0) {
-		vp = ITOV(xp);
-		TAILQ_REMOVE(si-si_snapshots, xp, i_nextsnap);
-		if (xp-i_snapblklist == si-si_snapblklist)
+	while ((ip = TAILQ_FIRST(si-si_snapshots)) != 0) {
+		list_empty = false;
+		TAILQ_REMOVE(si-si_snapshots, ip, i_nextsnap);
+		if (ip-i_snapblklist == si-si_snapblklist)
 			si-si_snapblklist = NULL;
-		free(xp-i_snapblklist, M_UFSMNT);
-		if (xp-i_nlink  0) {
-			si-si_gen++;
-			mutex_exit(si-si_lock);
-			vrele(vp);
-			mutex_enter(si-si_lock);
-		}
+		free(ip-i_snapblklist, M_UFSMNT);
+		si-si_gen++;
+		mutex_exit(si-si_lock);
+		vrele(ITOV(ip));
+		mutex_enter(si-si_lock);
 	}
-	si-si_gen++;
 	mutex_exit(si-si_lock);
-	if (vp)
+	if (! list_empty)
 		fscow_disestablish(mp, ffs_copyonwrite, devvp);
 }
 



CVS commit: src/sys/ufs/ffs

2010-08-12 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Thu Aug 12 07:41:49 UTC 2010

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

Log Message:
ffs_reclaim: don't free an already free inode.  This may happen when
 ffs_fhtovp() gets a free inode and releases it.


To generate a diff of this commit:
cvs rdiff -u -r1.115 -r1.116 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.115 src/sys/ufs/ffs/ffs_vnops.c:1.116
--- src/sys/ufs/ffs/ffs_vnops.c:1.115	Wed Jul 28 11:03:48 2010
+++ src/sys/ufs/ffs/ffs_vnops.c	Thu Aug 12 07:41:49 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vnops.c,v 1.115 2010/07/28 11:03:48 hannken Exp $	*/
+/*	$NetBSD: ffs_vnops.c,v 1.116 2010/08/12 07:41:49 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_vnops.c,v 1.115 2010/07/28 11:03:48 hannken Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_vnops.c,v 1.116 2010/08/12 07:41:49 hannken Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -594,7 +594,8 @@
 		fstrans_done(mp);
 		return error;
 	}
-	if (ip-i_nlink = 0  (vp-v_mount-mnt_flag  MNT_RDONLY) == 0)
+	if (ip-i_nlink = 0  ip-i_omode != 0 
+	(vp-v_mount-mnt_flag  MNT_RDONLY) == 0)
 		ffs_vfree(vp, ip-i_number, ip-i_omode);
 	UFS_WAPBL_END(mp);
 	if ((error = ufs_reclaim(vp)) != 0) {



CVS commit: src/sys/ufs/ffs

2010-08-09 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Mon Aug  9 15:50:13 UTC 2010

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

Log Message:
Return error if we try to mount a file system with block size  MAXBSIZE.

Note: there is a billion ways to make the kernel panic by trying
to mount a garbage file system and I don't imagine we'll ever get
close to fixing even half of them.  However, for this one failing
gracefully is a bonus since Xen DomU only does 32k MAXBSIZE and
the 64k MAXBSIZE file systems are out there (PR port-xen/43727).

Tested by compiling sys/rump with CPPFLAGS+=-DMAXPHYS=32768 (all
tests in tests/fs still pass).  I don't know how we're going to
translate this into an easy regression test, though.  Maybe with
a hacked newfs?


To generate a diff of this commit:
cvs rdiff -u -r1.260 -r1.261 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.260 src/sys/ufs/ffs/ffs_vfsops.c:1.261
--- src/sys/ufs/ffs/ffs_vfsops.c:1.260	Wed Jul 21 17:52:13 2010
+++ src/sys/ufs/ffs/ffs_vfsops.c	Mon Aug  9 15:50:13 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.260 2010/07/21 17:52:13 hannken Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.261 2010/08/09 15:50:13 pooka Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.260 2010/07/21 17:52:13 hannken Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.261 2010/08/09 15:50:13 pooka Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -828,6 +828,7 @@
 	int32_t *lp;
 	kauth_cred_t cred;
 	u_int32_t sbsize = 8192;	/* keep gcc happy*/
+	int32_t fsbsize;
 
 	dev = devvp-v_rdev;
 	cred = l ? l-l_cred : NOCRED;
@@ -886,21 +887,25 @@
 		if (fs-fs_magic == FS_UFS1_MAGIC) {
 			sbsize = fs-fs_sbsize;
 			fstype = UFS1;
+			fsbsize = fs-fs_bsize;
 #ifdef FFS_EI
 			needswap = 0;
 		} else if (fs-fs_magic == bswap32(FS_UFS1_MAGIC)) {
 			sbsize = bswap32(fs-fs_sbsize);
 			fstype = UFS1;
+			fsbsize = bswap32(fs-fs_bsize);
 			needswap = 1;
 #endif
 		} else if (fs-fs_magic == FS_UFS2_MAGIC) {
 			sbsize = fs-fs_sbsize;
 			fstype = UFS2;
+			fsbsize = fs-fs_bsize;
 #ifdef FFS_EI
 			needswap = 0;
 		} else if (fs-fs_magic == bswap32(FS_UFS2_MAGIC)) {
 			sbsize = bswap32(fs-fs_sbsize);
 			fstype = UFS2;
+			fsbsize = bswap32(fs-fs_bsize);
 			needswap = 1;
 #endif
 		} else
@@ -933,6 +938,13 @@
 		if (sbsize  MAXBSIZE || sbsize  sizeof(struct fs))
 			continue;
 
+		/* Check that we can handle the file system blocksize */
+		if (fsbsize  MAXBSIZE) {
+			printf(ffs_mountfs: block size (%d)  MAXBSIZE (%d),
+			fsbsize, MAXBSIZE);
+			continue;
+		}
+
 		/* Ok seems to be a good superblock */
 		break;
 	}



CVS commit: src/sys/ufs/ffs

2010-08-09 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Mon Aug  9 17:12:18 UTC 2010

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

Log Message:
add a linefeed to the previous


To generate a diff of this commit:
cvs rdiff -u -r1.261 -r1.262 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.261 src/sys/ufs/ffs/ffs_vfsops.c:1.262
--- src/sys/ufs/ffs/ffs_vfsops.c:1.261	Mon Aug  9 15:50:13 2010
+++ src/sys/ufs/ffs/ffs_vfsops.c	Mon Aug  9 17:12:18 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.261 2010/08/09 15:50:13 pooka Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.262 2010/08/09 17:12:18 pooka Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.261 2010/08/09 15:50:13 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.262 2010/08/09 17:12:18 pooka Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -940,7 +940,7 @@
 
 		/* Check that we can handle the file system blocksize */
 		if (fsbsize  MAXBSIZE) {
-			printf(ffs_mountfs: block size (%d)  MAXBSIZE (%d),
+			printf(ffs_mountfs: block size (%d)  MAXBSIZE (%d)\n,
 			fsbsize, MAXBSIZE);
 			continue;
 		}



CVS commit: src/sys/ufs/lfs

2010-08-04 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed Aug  4 10:43:53 UTC 2010

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

Log Message:
Free the on disk inodes in the reclaim routine.


To generate a diff of this commit:
cvs rdiff -u -r1.230 -r1.231 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.230 src/sys/ufs/lfs/lfs_vnops.c:1.231
--- src/sys/ufs/lfs/lfs_vnops.c:1.230	Thu Jul 29 10:54:51 2010
+++ src/sys/ufs/lfs/lfs_vnops.c	Wed Aug  4 10:43:53 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_vnops.c,v 1.230 2010/07/29 10:54:51 hannken Exp $	*/
+/*	$NetBSD: lfs_vnops.c,v 1.231 2010/08/04 10:43:53 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: lfs_vnops.c,v 1.230 2010/07/29 10:54:51 hannken Exp $);
+__KERNEL_RCSID(0, $NetBSD: lfs_vnops.c,v 1.231 2010/08/04 10:43:53 hannken Exp $);
 
 #ifdef _KERNEL_OPT
 #include opt_compat_netbsd.h
@@ -277,6 +277,10 @@
 	if (fs-lfs_ronly)
 		return 0;
 
+	/* If a removed vnode is being cleaned, no need to sync here. */
+	if ((ap-a_flags  FSYNC_RECLAIM) != 0  ip-i_mode == 0)
+		return 0;
+
 	/*
 	 * Trickle sync simply adds this vnode to the pager list, as if
 	 * the pagedaemon had requested a pageout.
@@ -1075,6 +1079,14 @@
 	struct lfs *fs = ip-i_lfs;
 	int error;
 
+	/*
+	 * The inode must be freed and updated before being removed
+	 * from its hash chain.  Other threads trying to gain a hold
+	 * on the inode will be stalled because it is locked (VI_XLOCK).
+	 */
+	if (ip-i_nlink = 0  (vp-v_mount-mnt_flag  MNT_RDONLY) == 0)
+		lfs_vfree(vp, ip-i_number, ip-i_omode);
+
 	mutex_enter(lfs_lock);
 	LFS_CLR_UINO(ip, IN_ALLMOD);
 	mutex_exit(lfs_lock);



CVS commit: src/sys/ufs/ext2fs

2010-07-26 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Tue Jul 27 05:15:56 UTC 2010

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

Log Message:
Make DEBUG_EXT2 work with 64-bit size_t.


To generate a diff of this commit:
cvs rdiff -u -r1.158 -r1.159 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.158 src/sys/ufs/ext2fs/ext2fs_vfsops.c:1.159
--- src/sys/ufs/ext2fs/ext2fs_vfsops.c:1.158	Wed Jul 21 17:52:13 2010
+++ src/sys/ufs/ext2fs/ext2fs_vfsops.c	Tue Jul 27 05:15:56 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: ext2fs_vfsops.c,v 1.158 2010/07/21 17:52:13 hannken Exp $	*/
+/*	$NetBSD: ext2fs_vfsops.c,v 1.159 2010/07/27 05:15:56 jakllsch Exp $	*/
 
 /*
  * Copyright (c) 1989, 1991, 1993, 1994
@@ -60,7 +60,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ext2fs_vfsops.c,v 1.158 2010/07/21 17:52:13 hannken Exp $);
+__KERNEL_RCSID(0, $NetBSD: ext2fs_vfsops.c,v 1.159 2010/07/27 05:15:56 jakllsch Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_compat_netbsd.h
@@ -682,7 +682,7 @@
 	ump = NULL;
 
 #ifdef DEBUG_EXT2
-	printf(ext2 sb size: %d\n, sizeof(struct ext2fs));
+	printf(ext2 sb size: %zu\n, sizeof(struct ext2fs));
 #endif
 	error = bread(devvp, SBLOCK, SBSIZE, cred, 0, bp);
 	if (error)
@@ -704,7 +704,7 @@
 	m_fs-e2fs_ronly = ronly;
 
 #ifdef DEBUG_EXT2
-	printf(ext2 ino size %d\n, EXT2_DINODE_SIZE(m_fs));
+	printf(ext2 ino size %zu\n, EXT2_DINODE_SIZE(m_fs));
 #endif
 	if (ronly == 0) {
 		if (m_fs-e2fs.e2fs_state == E2FS_ISCLEAN)



CVS commit: src/sys/ufs/lfs

2010-06-25 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Fri Jun 25 10:03:52 UTC 2010

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

Log Message:
Undo last commit and don't try to lock vnodes in lfs_unmark_dirop()
as we may deadlock trying to write the superblock.

Should fix PR #43503 Can't create device nodes on LFS.


To generate a diff of this commit:
cvs rdiff -u -r1.75 -r1.76 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.75 src/sys/ufs/lfs/lfs_subr.c:1.76
--- src/sys/ufs/lfs/lfs_subr.c:1.75	Thu Jun 24 07:54:47 2010
+++ src/sys/ufs/lfs/lfs_subr.c	Fri Jun 25 10:03:52 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_subr.c,v 1.75 2010/06/24 07:54:47 hannken Exp $	*/
+/*	$NetBSD: lfs_subr.c,v 1.76 2010/06/25 10:03:52 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: lfs_subr.c,v 1.75 2010/06/24 07:54:47 hannken Exp $);
+__KERNEL_RCSID(0, $NetBSD: lfs_subr.c,v 1.76 2010/06/25 10:03:52 hannken Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -362,8 +362,6 @@
 		nip = TAILQ_NEXT(ip, i_lfs_dchain);
 		vp = ITOV(ip);
 		if ((VTOI(vp)-i_flag  (IN_ADIROP | IN_ALLMOD)) == 0) {
-			if (vn_lock(vp, LK_EXCLUSIVE | LK_NOWAIT | LK_RETRY))
-continue;
 			--lfs_dirvcount;
 			--fs-lfs_dirvcount;
 			vp-v_uflag = ~VU_DIROP;
@@ -371,7 +369,7 @@
 			wakeup(lfs_dirvcount);
 			fs-lfs_unlockvp = vp;
 			mutex_exit(lfs_lock);
-			vput(vp);
+			vrele(vp);
 			mutex_enter(lfs_lock);
 			fs-lfs_unlockvp = NULL;
 		}



CVS commit: src/sys/ufs/ffs

2010-06-02 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed Jun  2 09:56:59 UTC 2010

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

Log Message:
Initialize the initial snap block list's count.

From Antti Kantee po...@netbsd.org.


To generate a diff of this commit:
cvs rdiff -u -r1.97 -r1.98 src/sys/ufs/ffs/ffs_snapshot.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_snapshot.c
diff -u src/sys/ufs/ffs/ffs_snapshot.c:1.97 src/sys/ufs/ffs/ffs_snapshot.c:1.98
--- src/sys/ufs/ffs/ffs_snapshot.c:1.97	Thu Oct 15 10:05:48 2009
+++ src/sys/ufs/ffs/ffs_snapshot.c	Wed Jun  2 09:56:59 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_snapshot.c,v 1.97 2009/10/15 10:05:48 hannken Exp $	*/
+/*	$NetBSD: ffs_snapshot.c,v 1.98 2010/06/02 09:56:59 hannken Exp $	*/
 
 /*
  * Copyright 2000 Marshall Kirk McKusick. All Rights Reserved.
@@ -38,7 +38,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_snapshot.c,v 1.97 2009/10/15 10:05:48 hannken Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_snapshot.c,v 1.98 2010/06/02 09:56:59 hannken Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -684,6 +684,7 @@
 		*blkp++ = blkno + loc;
 	for (; cg  fs-fs_ncg; cg++)
 		*blkp++ = fragstoblks(fs, cgtod(fs, cg));
+	(*snaplist)[0] = blkp - (*snaplist)[0];
 
 out:
 	if (has_wapbl)



CVS commit: src/sys/ufs/ufs

2010-05-25 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Tue May 25 11:02:07 UTC 2010

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

Log Message:
Add a comment describing an observed boom-crash-burn problem in
the code.  Fixing it will require a full tank of gas, half a pack
of cigarettes, sunglasses, darkness, and most importantly:
someone else.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/ufs/ufs/ufs_wapbl.c

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

Modified files:

Index: src/sys/ufs/ufs/ufs_wapbl.c
diff -u src/sys/ufs/ufs/ufs_wapbl.c:1.8 src/sys/ufs/ufs/ufs_wapbl.c:1.9
--- src/sys/ufs/ufs/ufs_wapbl.c:1.8	Tue Mar  2 14:45:55 2010
+++ src/sys/ufs/ufs/ufs_wapbl.c	Tue May 25 11:02:07 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: ufs_wapbl.c,v 1.8 2010/03/02 14:45:55 pooka Exp $ */
+/*  $NetBSD: ufs_wapbl.c,v 1.9 2010/05/25 11:02:07 pooka Exp $ */
 
 /*-
  * Copyright (c) 2003,2006,2008 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_wapbl.c,v 1.8 2010/03/02 14:45:55 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_wapbl.c,v 1.9 2010/05/25 11:02:07 pooka Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -371,6 +371,10 @@
 		error = ENOENT;	/* XXX ufs_rename sets 0 here */
 		goto out2;
 	}
+	/*
+	 * XXX: if fvp != a_fvp, a_fvp can now have 0 references and yet we
+	 * access a_fvp-inode via ip later.  boom.
+	 */
 	vrele(ap-a_fvp);
 
 	/* save directory lookup information in case tdvp == fdvp */



CVS commit: src/sys/ufs/ufs

2010-04-13 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Tue Apr 13 09:27:59 UTC 2010

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

Log Message:
Add fstrans transactions to ufs_close(), ufs_getattr(), ufs_chmod()
and ufs_chown().  These functions change file system state.


To generate a diff of this commit:
cvs rdiff -u -r1.181 -r1.182 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.181 src/sys/ufs/ufs/ufs_vnops.c:1.182
--- src/sys/ufs/ufs/ufs_vnops.c:1.181	Mon Mar 29 13:11:34 2010
+++ src/sys/ufs/ufs/ufs_vnops.c	Tue Apr 13 09:27:58 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_vnops.c,v 1.181 2010/03/29 13:11:34 pooka Exp $	*/
+/*	$NetBSD: ufs_vnops.c,v 1.182 2010/04/13 09:27:58 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_vnops.c,v 1.181 2010/03/29 13:11:34 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_vnops.c,v 1.182 2010/04/13 09:27:58 hannken Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -267,8 +267,10 @@
 
 	vp = ap-a_vp;
 	ip = VTOI(vp);
+	fstrans_start(vp-v_mount, FSTRANS_SHARED);
 	if (vp-v_usecount  1)
 		UFS_ITIMES(vp, NULL, NULL, NULL);
+	fstrans_done(vp-v_mount);
 	return (0);
 }
 
@@ -371,6 +373,7 @@
 	vp = ap-a_vp;
 	ip = VTOI(vp);
 	vap = ap-a_vap;
+	fstrans_start(vp-v_mount, FSTRANS_SHARED);
 	UFS_ITIMES(vp, NULL, NULL, NULL);
 
 	/*
@@ -420,6 +423,7 @@
 		vap-va_blocksize = vp-v_mount-mnt_stat.f_iosize;
 	vap-va_type = vp-v_type;
 	vap-va_filerev = ip-i_modrev;
+	fstrans_done(vp-v_mount);
 	return (0);
 }
 
@@ -671,11 +675,13 @@
 	if (error)
 		return (error);
 
+	fstrans_start(vp-v_mount, FSTRANS_SHARED);
 	ip-i_mode = ~ALLPERMS;
 	ip-i_mode |= (mode  ALLPERMS);
 	ip-i_flag |= IN_CHANGE;
 	DIP_ASSIGN(ip, mode, ip-i_mode);
 	UFS_WAPBL_UPDATE(vp, NULL, NULL, 0);
+	fstrans_done(vp-v_mount);
 	return (0);
 }
 
@@ -706,6 +712,7 @@
 	if (error)
 		return (error);
 
+	fstrans_start(vp-v_mount, FSTRANS_SHARED);
 #ifdef QUOTA
 	ogid = ip-i_gid;
 	ouid = ip-i_uid;
@@ -730,11 +737,13 @@
 	DIP_ASSIGN(ip, uid, ouid);
 	(void) chkdq(ip, change, cred, FORCE);
 	(void) chkiq(ip, 1, cred, FORCE);
+	fstrans_done(vp-v_mount);
 	return (error);
  good:
 #endif /* QUOTA */
 	ip-i_flag |= IN_CHANGE;
 	UFS_WAPBL_UPDATE(vp, NULL, NULL, 0);
+	fstrans_done(vp-v_mount);
 	return (0);
 }
 



CVS commit: src/sys/ufs/ufs

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

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

Log Message:
Allow ufs_inactive() while a file system is suspending.  Removes a possible
deadlock between vrele() and ffs_sync() during suspension.


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 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.79 src/sys/ufs/ufs/ufs_inode.c:1.80
--- src/sys/ufs/ufs/ufs_inode.c:1.79	Sun Feb  7 17:12:40 2010
+++ src/sys/ufs/ufs/ufs_inode.c	Mon Mar 15 09:20:10 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_inode.c,v 1.79 2010/02/07 17:12:40 bouyer Exp $	*/
+/*	$NetBSD: ufs_inode.c,v 1.80 2010/03/15 09:20:10 hannken Exp $	*/
 
 /*
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_inode.c,v 1.79 2010/02/07 17:12:40 bouyer Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_inode.c,v 1.80 2010/03/15 09:20:10 hannken Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -92,7 +92,7 @@
 	UFS_WAPBL_JUNLOCK_ASSERT(vp-v_mount);
 
 	transmp = vp-v_mount;
-	fstrans_start(transmp, FSTRANS_SHARED);
+	fstrans_start(transmp, FSTRANS_LAZY);
 	/*
 	 * Ignore inodes related to stale file handles.
 	 */



CVS commit: src/sys/ufs/ffs

2010-02-23 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Tue Feb 23 20:41:41 UTC 2010

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

Log Message:
Replace individual queries for partition information with
new helper function.
Use this information to query physical sector sizes for WAPBL
instead of hardcoded defaults.
No longer limits physical sector sizes to 512 bytes.


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

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

Modified files:

Index: src/sys/ufs/ffs/ffs_wapbl.c
diff -u src/sys/ufs/ffs/ffs_wapbl.c:1.13 src/sys/ufs/ffs/ffs_wapbl.c:1.14
--- src/sys/ufs/ffs/ffs_wapbl.c:1.13	Sun Sep 13 14:13:23 2009
+++ src/sys/ufs/ffs/ffs_wapbl.c	Tue Feb 23 20:41:41 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_wapbl.c,v 1.13 2009/09/13 14:13:23 bouyer Exp $	*/
+/*	$NetBSD: ffs_wapbl.c,v 1.14 2010/02/23 20:41:41 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 2003,2006,2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_wapbl.c,v 1.13 2009/09/13 14:13:23 bouyer Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_wapbl.c,v 1.14 2010/02/23 20:41:41 mlelstv Exp $);
 
 #define WAPBL_INTERNAL
 
@@ -45,7 +45,6 @@
 #include sys/mount.h
 #include sys/file.h
 #include sys/disk.h
-#include sys/disklabel.h
 #include sys/ioctl.h
 #include sys/errno.h
 #include sys/kauth.h
@@ -80,11 +79,12 @@
 static int wapbl_log_position(struct mount *, struct fs *, struct vnode *,
 daddr_t *, size_t *, size_t *, uint64_t *);
 static int wapbl_create_infs_log(struct mount *, struct fs *, struct vnode *,
-daddr_t *, size_t *, size_t *, uint64_t *);
+daddr_t *, size_t *, uint64_t *);
 static void wapbl_find_log_start(struct mount *, struct vnode *, off_t,
 daddr_t *, daddr_t *, size_t *);
 static int wapbl_remove_log(struct mount *);
-static int wapbl_allocate_log_file(struct mount *, struct vnode *);
+static int wapbl_allocate_log_file(struct mount *, struct vnode *,
+daddr_t *, size_t *, uint64_t *);
 
 /*
  * Return the super block layout format - UFS1 or UFS2.
@@ -330,13 +330,6 @@
 			if (error)
 return error;
 
-			/* XXX any other consistancy checks here? */
-			if (blksize != DEV_BSIZE) {
-printf(%s: bad blocksize %zu\n, __func__,
-blksize);
-return EINVAL;
-			}
-
 			error = wapbl_start(mp-mnt_wapbl, mp, devvp, off,
 			count, blksize, mp-mnt_wapbl_replay,
 			ffs_wapbl_sync_metadata,
@@ -502,10 +495,10 @@
 daddr_t *startp, size_t *countp, size_t *blksizep, uint64_t *extradatap)
 {
 	struct ufsmount *ump = VFSTOUFS(mp);
-	struct partinfo dpart;
 	daddr_t logstart, logend, desired_logsize;
-	size_t blksize;
-	int error;
+	uint64_t numsecs;
+	unsigned secsize;
+	int error, location;
 
 	if (fs-fs_journal_version == UFS_WAPBL_VERSION) {
 		switch (fs-fs_journal_location) {
@@ -544,48 +537,51 @@
 
 	/* Is there space after after filesystem on partition for log? */
 	logstart = fsbtodb(fs, fs-fs_size);
-	error = VOP_IOCTL(devvp, DIOCGPART, dpart, FREAD, FSCRED);
-	if (!error) {
-		logend  = dpart.part-p_size;
-		blksize = dpart.disklab-d_secsize;
-	} else {
-		struct dkwedge_info dkw;
-		error = VOP_IOCTL(devvp, DIOCGWEDGEINFO, dkw, FREAD, FSCRED);
-		if (error)
-			return error;
-
-		blksize = DEV_BSIZE;
-		logend = dkw.dkw_size;
-	}
+	error = getdisksize(devvp, numsecs, secsize);
+	if (error)
+		return error;
+	KDASSERT(secsize != 0);
+	logend = btodb(numsecs * secsize);
 
-	if ((logend - logstart) * blksize = desired_logsize) {
-		KDASSERT(blksize != 0);
+	if (dbtob(logend - logstart) = desired_logsize) {
 		DPRINTF(enough space, use end-of-partition log\n);
 
+		location = UFS_WAPBL_JOURNALLOC_END_PARTITION;
+		*blksizep = secsize;
+
 		*startp = logstart;
 		*countp = (logend - logstart);
-		*blksizep = blksize;
 		*extradatap = 0;
 
-		/* update superblock with log location */
-		fs-fs_journal_version = UFS_WAPBL_VERSION;
-		fs-fs_journal_location = UFS_WAPBL_JOURNALLOC_END_PARTITION;
-		fs-fs_journal_flags = 0;
 		fs-fs_journallocs[UFS_WAPBL_EPART_ADDR] = *startp;
 		fs-fs_journallocs[UFS_WAPBL_EPART_COUNT] = *countp;
 		fs-fs_journallocs[UFS_WAPBL_EPART_BLKSZ] = *blksizep;
 		fs-fs_journallocs[UFS_WAPBL_EPART_UNUSED] = *extradatap;
+	} else {
+		DPRINTF(end-of-partition has only % PRId64  free\n,
+		logend - logstart);
 
-		error = ffs_sbupdate(ump, MNT_WAIT);
-		return error;
+		location = UFS_WAPBL_JOURNALLOC_IN_FILESYSTEM;
+		*blksizep = secsize;
+
+		error = wapbl_create_infs_log(mp, fs, devvp,
+		  startp, countp, extradatap);
+		ffs_sync(mp, MNT_WAIT, FSCRED);
+
+		fs-fs_journallocs[UFS_WAPBL_INFS_ADDR] = *startp;
+		fs-fs_journallocs[UFS_WAPBL_INFS_COUNT] = *countp;
+		fs-fs_journallocs[UFS_WAPBL_INFS_BLKSZ] = *blksizep;
+		fs-fs_journallocs[UFS_WAPBL_INFS_INO] = *extradatap;
 	}
-	DPRINTF(end-of-partition has only % PRId64  free\n,
-	logend - logstart);
 
-	

CVS commit: src/sys/ufs/ffs

2010-02-21 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Feb 21 13:55:58 UTC 2010

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

Log Message:
For the UVM_PAGE_TRKOWN test do not require that the relevant pages
must exist.


To generate a diff of this commit:
cvs rdiff -u -r1.124 -r1.125 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.124 src/sys/ufs/ffs/ffs_alloc.c:1.125
--- src/sys/ufs/ffs/ffs_alloc.c:1.124	Thu May  7 19:26:09 2009
+++ src/sys/ufs/ffs/ffs_alloc.c	Sun Feb 21 13:55:58 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_alloc.c,v 1.124 2009/05/07 19:26:09 elad Exp $	*/
+/*	$NetBSD: ffs_alloc.c,v 1.125 2010/02/21 13:55:58 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_alloc.c,v 1.124 2009/05/07 19:26:09 elad Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_alloc.c,v 1.125 2010/02/21 13:55:58 mlelstv Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -194,8 +194,7 @@
 		mutex_enter(uobj-vmobjlock);
 		while (off  endoff) {
 			pg = uvm_pagelookup(uobj, off);
-			KASSERT(pg != NULL);
-			KASSERT(pg-owner == curproc-p_pid);
+			KASSERT(pg == NULL || pg-owner == curproc-p_pid);
 			off += PAGE_SIZE;
 		}
 		mutex_exit(uobj-vmobjlock);
@@ -302,8 +301,7 @@
 		mutex_enter(uobj-vmobjlock);
 		while (off  endoff) {
 			pg = uvm_pagelookup(uobj, off);
-			KASSERT(pg != NULL);
-			KASSERT(pg-owner == curproc-p_pid);
+			KASSERT(pg == NULL || pg-owner == curproc-p_pid);
 			KASSERT((pg-flags  PG_CLEAN) == 0);
 			off += PAGE_SIZE;
 		}



CVS commit: src/sys/ufs/lfs

2010-02-17 Thread Eduardo Horvath
Module Name:src
Committed By:   eeh
Date:   Thu Feb 18 01:14:01 UTC 2010

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

Log Message:
Fix root filesystem support.


To generate a diff of this commit:
cvs rdiff -u -r1.283 -r1.284 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.283 src/sys/ufs/lfs/lfs_vfsops.c:1.284
--- src/sys/ufs/lfs/lfs_vfsops.c:1.283	Tue Feb 16 23:20:30 2010
+++ src/sys/ufs/lfs/lfs_vfsops.c	Thu Feb 18 01:14:00 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_vfsops.c,v 1.283 2010/02/16 23:20:30 mlelstv Exp $	*/
+/*	$NetBSD: lfs_vfsops.c,v 1.284 2010/02/18 01:14:00 eeh Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007, 2007
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: lfs_vfsops.c,v 1.283 2010/02/16 23:20:30 mlelstv Exp $);
+__KERNEL_RCSID(0, $NetBSD: lfs_vfsops.c,v 1.284 2010/02/18 01:14:00 eeh Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_lfs.h
@@ -516,8 +516,10 @@
 lfs_mountroot(void)
 {
 	extern struct vnode *rootvp;
+	struct lfs *fs = NULL;/* LFS */
 	struct mount *mp;
 	struct lwp *l = curlwp;
+	struct ufsmount *ump;
 	int error;
 
 	if (device_class(root_device) != DV_DISK)
@@ -537,6 +539,10 @@
 	mutex_enter(mountlist_lock);
 	CIRCLEQ_INSERT_TAIL(mountlist, mp, mnt_list);
 	mutex_exit(mountlist_lock);
+	ump = VFSTOUFS(mp);
+	fs = ump-um_lfs;
+	memset(fs-lfs_fsmnt, 0, sizeof(fs-lfs_fsmnt));
+	(void)copystr(mp-mnt_stat.f_mntonname, fs-lfs_fsmnt, MNAMELEN - 1, 0);
 	(void)lfs_statvfs(mp, mp-mnt_stat);
 	vfs_unbusy(mp, false, NULL);
 	setrootfstime((time_t)(VFSTOUFS(mp)-um_lfs-lfs_tstamp));
@@ -597,8 +603,15 @@
 			 * used for our initial mount
 			 */
 			ump = VFSTOUFS(mp);
-			if (devvp != ump-um_devvp)
-error = EINVAL;
+			if (devvp != ump-um_devvp) {
+if (devvp-v_rdev != ump-um_devvp-v_rdev)
+	error = EINVAL;
+else {
+	vrele(devvp);
+	devvp = ump-um_devvp;
+	vref(devvp);
+}
+			}
 		}
 	} else {
 		if (!update) {



CVS commit: src/sys/ufs/ext2fs

2010-02-11 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Thu Feb 11 19:50:34 UTC 2010

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

Log Message:
There is no code left that uses disk size data, so don't query it.


To generate a diff of this commit:
cvs rdiff -u -r1.155 -r1.156 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.155 src/sys/ufs/ext2fs/ext2fs_vfsops.c:1.156
--- src/sys/ufs/ext2fs/ext2fs_vfsops.c:1.155	Sun Jan 31 10:37:57 2010
+++ src/sys/ufs/ext2fs/ext2fs_vfsops.c	Thu Feb 11 19:50:34 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: ext2fs_vfsops.c,v 1.155 2010/01/31 10:37:57 mlelstv Exp $	*/
+/*	$NetBSD: ext2fs_vfsops.c,v 1.156 2010/02/11 19:50:34 mlelstv Exp $	*/
 
 /*
  * Copyright (c) 1989, 1991, 1993, 1994
@@ -60,7 +60,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ext2fs_vfsops.c,v 1.155 2010/01/31 10:37:57 mlelstv Exp $);
+__KERNEL_RCSID(0, $NetBSD: ext2fs_vfsops.c,v 1.156 2010/02/11 19:50:34 mlelstv Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_compat_netbsd.h
@@ -522,8 +522,6 @@
 	struct m_ext2fs *fs;
 	struct ext2fs *newfs;
 	int i, error;
-	uint64_t numsecs;
-	unsigned secsize;
 	void *cp;
 	struct ufsmount *ump;
 
@@ -543,11 +541,6 @@
 	/*
 	 * Step 2: re-read superblock from disk.
 	 */
-	error = getdisksize(devvp, numsecs, secsize);
-	if (error) {
-		brelse(bp, 0);
-		return (error);
-	}
 	error = bread(devvp, SBLOCK, SBSIZE, NOCRED, 0, bp);
 	if (error) {
 		brelse(bp, 0);
@@ -669,8 +662,6 @@
 	struct m_ext2fs *m_fs;
 	dev_t dev;
 	int error, i, ronly;
-	uint64_t numsecs;
-	unsigned secsize;
 	kauth_cred_t cred;
 	struct proc *p;
 
@@ -686,9 +677,6 @@
 		return (error);
 
 	ronly = (mp-mnt_flag  MNT_RDONLY) != 0;
-	error = getdisksize(devvp, numsecs, secsize);
-	if (error)
-		return (error);
 
 	bp = NULL;
 	ump = NULL;



CVS commit: src/sys/ufs/ffs

2010-02-10 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Thu Feb 11 00:06:16 UTC 2010

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

Log Message:
There is no code left that uses disk size data, so don't query it.
This also failed when querying the simulated block device from mfs.
Fixes PR kern/42782.


To generate a diff of this commit:
cvs rdiff -u -r1.257 -r1.258 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.257 src/sys/ufs/ffs/ffs_vfsops.c:1.258
--- src/sys/ufs/ffs/ffs_vfsops.c:1.257	Fri Feb  5 20:03:36 2010
+++ src/sys/ufs/ffs/ffs_vfsops.c	Thu Feb 11 00:06:16 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.257 2010/02/05 20:03:36 mlelstv Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.258 2010/02/11 00:06:16 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.257 2010/02/05 20:03:36 mlelstv Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.258 2010/02/11 00:06:16 mlelstv Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -822,8 +822,6 @@
 	daddr_t sblockloc, fsblockloc;
 	int blks, fstype;
 	int error, i, bsize, ronly, bset = 0;
-	uint64_t numsecs;
-	unsigned secsize;
 #ifdef FFS_EI
 	int needswap = 0;		/* keep gcc happy */
 #endif
@@ -842,9 +840,6 @@
 		return (error);
 
 	ronly = (mp-mnt_flag  MNT_RDONLY) != 0;
-	error = getdisksize(devvp, numsecs, secsize);
-	if (error)
-		return (error);
 
 	bp = NULL;
 	ump = NULL;



CVS commit: src/sys/ufs

2010-02-07 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Sun Feb  7 17:12:40 UTC 2010

Modified Files:
src/sys/ufs/ext2fs: ext2fs_inode.c
src/sys/ufs/ffs: ffs_inode.c
src/sys/ufs/lfs: lfs_inode.c
src/sys/ufs/ufs: ufs_inode.c

Log Message:
- ufs_balloc_range(): on error, only PG_RELEASED the pages that were
  allocated to extend the file to the new size. Releasing all pages
  may release pages that contains previously-written data not yet flushed
  to disk. Should fix PR kern/35704
- {ffs,lfs,ext2fs}_truncate(): Even if the inode's size is the same as
  the new length, call uvm_vnp_setsize(). *_truncate() may have been
  called by *_write() in the error path (e.g. block allocation failure
  because of quota of file system full), and at this point v_writesize
  has been set to the desired size of the file and not reverted to the
  old size. Not adjusting v_writesize to the real size cause
  genfs_do_io() to write to disk past the real end of the file.


To generate a diff of this commit:
cvs rdiff -u -r1.70 -r1.71 src/sys/ufs/ext2fs/ext2fs_inode.c
cvs rdiff -u -r1.103 -r1.104 src/sys/ufs/ffs/ffs_inode.c
cvs rdiff -u -r1.120 -r1.121 src/sys/ufs/lfs/lfs_inode.c
cvs rdiff -u -r1.78 -r1.79 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/ext2fs/ext2fs_inode.c
diff -u src/sys/ufs/ext2fs/ext2fs_inode.c:1.70 src/sys/ufs/ext2fs/ext2fs_inode.c:1.71
--- src/sys/ufs/ext2fs/ext2fs_inode.c:1.70	Mon Oct 19 18:41:17 2009
+++ src/sys/ufs/ext2fs/ext2fs_inode.c	Sun Feb  7 17:12:40 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: ext2fs_inode.c,v 1.70 2009/10/19 18:41:17 bouyer Exp $	*/
+/*	$NetBSD: ext2fs_inode.c,v 1.71 2010/02/07 17:12:40 bouyer Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -60,7 +60,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ext2fs_inode.c,v 1.70 2009/10/19 18:41:17 bouyer Exp $);
+__KERNEL_RCSID(0, $NetBSD: ext2fs_inode.c,v 1.71 2010/02/07 17:12:40 bouyer Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -272,6 +272,8 @@
 		return (ext2fs_update(ovp, NULL, NULL, 0));
 	}
 	if (ext2fs_size(oip) == length) {
+		/* still do a uvm_vnp_setsize() as writesize may be larger */
+		uvm_vnp_setsize(ovp, length);
 		oip-i_flag |= IN_CHANGE | IN_UPDATE;
 		return (ext2fs_update(ovp, NULL, NULL, 0));
 	}

Index: src/sys/ufs/ffs/ffs_inode.c
diff -u src/sys/ufs/ffs/ffs_inode.c:1.103 src/sys/ufs/ffs/ffs_inode.c:1.104
--- src/sys/ufs/ffs/ffs_inode.c:1.103	Sun Feb 22 20:28:06 2009
+++ src/sys/ufs/ffs/ffs_inode.c	Sun Feb  7 17:12:40 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_inode.c,v 1.103 2009/02/22 20:28:06 ad Exp $	*/
+/*	$NetBSD: ffs_inode.c,v 1.104 2010/02/07 17:12:40 bouyer Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_inode.c,v 1.103 2009/02/22 20:28:06 ad Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_inode.c,v 1.104 2010/02/07 17:12:40 bouyer Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -238,6 +238,8 @@
 		return (ffs_update(ovp, NULL, NULL, 0));
 	}
 	if (oip-i_size == length) {
+		/* still do a uvm_vnp_setsize() as writesize may be larger */
+		uvm_vnp_setsize(ovp, length);
 		oip-i_flag |= IN_CHANGE | IN_UPDATE;
 		return (ffs_update(ovp, NULL, NULL, 0));
 	}

Index: src/sys/ufs/lfs/lfs_inode.c
diff -u src/sys/ufs/lfs/lfs_inode.c:1.120 src/sys/ufs/lfs/lfs_inode.c:1.121
--- src/sys/ufs/lfs/lfs_inode.c:1.120	Mon Apr 28 20:24:11 2008
+++ src/sys/ufs/lfs/lfs_inode.c	Sun Feb  7 17:12:40 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_inode.c,v 1.120 2008/04/28 20:24:11 martin Exp $	*/
+/*	$NetBSD: lfs_inode.c,v 1.121 2010/02/07 17:12:40 bouyer Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: lfs_inode.c,v 1.120 2008/04/28 20:24:11 martin Exp $);
+__KERNEL_RCSID(0, $NetBSD: lfs_inode.c,v 1.121 2010/02/07 17:12:40 bouyer Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_quota.h
@@ -226,8 +226,11 @@
 	/*
 	 * Just return and not update modification times.
 	 */
-	if (oip-i_size == length)
+	if (oip-i_size == length) {
+		/* still do a uvm_vnp_setsize() as writesize may be larger */
+		uvm_vnp_setsize(ovp, length);
 		return (0);
+	}
 
 	if (ovp-v_type == VLNK 
 	(oip-i_size  ump-um_maxsymlinklen ||

Index: src/sys/ufs/ufs/ufs_inode.c
diff -u src/sys/ufs/ufs/ufs_inode.c:1.78 src/sys/ufs/ufs/ufs_inode.c:1.79
--- src/sys/ufs/ufs/ufs_inode.c:1.78	Sun Feb 22 20:28:07 2009
+++ src/sys/ufs/ufs/ufs_inode.c	Sun Feb  7 17:12:40 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_inode.c,v 1.78 2009/02/22 20:28:07 ad Exp $	*/
+/*	$NetBSD: ufs_inode.c,v 1.79 2010/02/07 17:12:40 bouyer Exp $	*/
 
 /*
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_inode.c,v 1.78 2009/02/22 20:28:07 ad Exp $);

CVS commit: src/sys/ufs/ffs

2010-02-05 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Fri Feb  5 20:03:36 UTC 2010

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

Log Message:
Correct addressing of superblock updates.


To generate a diff of this commit:
cvs rdiff -u -r1.256 -r1.257 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.256 src/sys/ufs/ffs/ffs_vfsops.c:1.257
--- src/sys/ufs/ffs/ffs_vfsops.c:1.256	Sun Jan 31 10:54:10 2010
+++ src/sys/ufs/ffs/ffs_vfsops.c	Fri Feb  5 20:03:36 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.256 2010/01/31 10:54:10 mlelstv Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.257 2010/02/05 20:03:36 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.256 2010/01/31 10:54:10 mlelstv Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.257 2010/02/05 20:03:36 mlelstv Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -1931,7 +1931,7 @@
 	u_int32_t saveflag;
 
 	error = ffs_getblk(mp-um_devvp,
-	fs-fs_sblockloc  (fs-fs_fshift - fs-fs_fsbtodb), FFS_NOBLK,
+	fs-fs_sblockloc / DEV_BSIZE, FFS_NOBLK,
 	fs-fs_sbsize, false, bp);
 	if (error)
 		return error;



CVS commit: src/sys/ufs/ext2fs

2010-01-31 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Jan 31 10:36:20 UTC 2010

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

Log Message:
Replace individual queries for partition information with
new helper function.


To generate a diff of this commit:
cvs rdiff -u -r1.153 -r1.154 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.153 src/sys/ufs/ext2fs/ext2fs_vfsops.c:1.154
--- src/sys/ufs/ext2fs/ext2fs_vfsops.c:1.153	Fri Jan  8 11:35:11 2010
+++ src/sys/ufs/ext2fs/ext2fs_vfsops.c	Sun Jan 31 10:36:20 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: ext2fs_vfsops.c,v 1.153 2010/01/08 11:35:11 pooka Exp $	*/
+/*	$NetBSD: ext2fs_vfsops.c,v 1.154 2010/01/31 10:36:20 mlelstv Exp $	*/
 
 /*
  * Copyright (c) 1989, 1991, 1993, 1994
@@ -60,7 +60,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ext2fs_vfsops.c,v 1.153 2010/01/08 11:35:11 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: ext2fs_vfsops.c,v 1.154 2010/01/31 10:36:20 mlelstv Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_compat_netbsd.h
@@ -521,8 +521,9 @@
 	struct buf *bp;
 	struct m_ext2fs *fs;
 	struct ext2fs *newfs;
-	struct partinfo dpart;
-	int i, size, error;
+	int i, error;
+	uint64_t numsecs;
+	unsigned secsize;
 	void *cp;
 	struct ufsmount *ump;
 
@@ -542,11 +543,12 @@
 	/*
 	 * Step 2: re-read superblock from disk.
 	 */
-	if (VOP_IOCTL(devvp, DIOCGPART, dpart, FREAD, NOCRED) != 0)
-		size = DEV_BSIZE;
-	else
-		size = dpart.disklab-d_secsize;
-	error = bread(devvp, (daddr_t)(SBOFF / size), SBSIZE, NOCRED, 0, bp);
+	error = getdisksize(devvp, numsecs, secsize);
+	if (error) {
+		brelse(bp, 0);
+		return (error);
+	}
+	error = bread(devvp, (daddr_t)(SBOFF / secsize), SBSIZE, NOCRED, 0, bp);
 	if (error) {
 		brelse(bp, 0);
 		return (error);
@@ -667,8 +669,9 @@
 	struct ext2fs *fs;
 	struct m_ext2fs *m_fs;
 	dev_t dev;
-	struct partinfo dpart;
-	int error, i, size, ronly;
+	int error, i, ronly;
+	uint64_t numsecs;
+	unsigned secsize;
 	kauth_cred_t cred;
 	struct proc *p;
 
@@ -684,10 +687,9 @@
 		return (error);
 
 	ronly = (mp-mnt_flag  MNT_RDONLY) != 0;
-	if (VOP_IOCTL(devvp, DIOCGPART, dpart, FREAD, cred) != 0)
-		size = DEV_BSIZE;
-	else
-		size = dpart.disklab-d_secsize;
+	error = getdisksize(devvp, numsecs, secsize);
+	if (error)
+		return (error);
 
 	bp = NULL;
 	ump = NULL;
@@ -695,7 +697,7 @@
 #ifdef DEBUG_EXT2
 	printf(ext2 sb size: %d\n, sizeof(struct ext2fs));
 #endif
-	error = bread(devvp, (SBOFF / size), SBSIZE, cred, 0, bp);
+	error = bread(devvp, (SBOFF / secsize), SBSIZE, cred, 0, bp);
 	if (error)
 		goto out;
 	fs = (struct ext2fs *)bp-b_data;



CVS commit: src/sys/ufs/ext2fs

2010-01-31 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Jan 31 10:37:57 UTC 2010

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

Log Message:
Fix block shift to work with different device block sizes.


To generate a diff of this commit:
cvs rdiff -u -r1.154 -r1.155 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.154 src/sys/ufs/ext2fs/ext2fs_vfsops.c:1.155
--- src/sys/ufs/ext2fs/ext2fs_vfsops.c:1.154	Sun Jan 31 10:36:20 2010
+++ src/sys/ufs/ext2fs/ext2fs_vfsops.c	Sun Jan 31 10:37:57 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: ext2fs_vfsops.c,v 1.154 2010/01/31 10:36:20 mlelstv Exp $	*/
+/*	$NetBSD: ext2fs_vfsops.c,v 1.155 2010/01/31 10:37:57 mlelstv Exp $	*/
 
 /*
  * Copyright (c) 1989, 1991, 1993, 1994
@@ -60,7 +60,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ext2fs_vfsops.c,v 1.154 2010/01/31 10:36:20 mlelstv Exp $);
+__KERNEL_RCSID(0, $NetBSD: ext2fs_vfsops.c,v 1.155 2010/01/31 10:37:57 mlelstv Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_compat_netbsd.h
@@ -548,7 +548,7 @@
 		brelse(bp, 0);
 		return (error);
 	}
-	error = bread(devvp, (daddr_t)(SBOFF / secsize), SBSIZE, NOCRED, 0, bp);
+	error = bread(devvp, SBLOCK, SBSIZE, NOCRED, 0, bp);
 	if (error) {
 		brelse(bp, 0);
 		return (error);
@@ -568,8 +568,7 @@
 	fs-e2fs_ncg =
 	howmany(fs-e2fs.e2fs_bcount - fs-e2fs.e2fs_first_dblock,
 	fs-e2fs.e2fs_bpg);
-	/* XXX assume hw bsize = 512 */
-	fs-e2fs_fsbtodb = fs-e2fs.e2fs_log_bsize + 1;
+	fs-e2fs_fsbtodb = fs-e2fs.e2fs_log_bsize + LOG_MINBSIZE - DEV_BSHIFT;
 	fs-e2fs_bsize = MINBSIZE  fs-e2fs.e2fs_log_bsize;
 	fs-e2fs_bshift = LOG_MINBSIZE + fs-e2fs.e2fs_log_bsize;
 	fs-e2fs_qbmask = fs-e2fs_bsize - 1;
@@ -697,7 +696,7 @@
 #ifdef DEBUG_EXT2
 	printf(ext2 sb size: %d\n, sizeof(struct ext2fs));
 #endif
-	error = bread(devvp, (SBOFF / secsize), SBSIZE, cred, 0, bp);
+	error = bread(devvp, SBLOCK, SBSIZE, cred, 0, bp);
 	if (error)
 		goto out;
 	fs = (struct ext2fs *)bp-b_data;
@@ -731,8 +730,7 @@
 	m_fs-e2fs_ncg =
 	howmany(m_fs-e2fs.e2fs_bcount - m_fs-e2fs.e2fs_first_dblock,
 	m_fs-e2fs.e2fs_bpg);
-	/* XXX assume hw bsize = 512 */
-	m_fs-e2fs_fsbtodb = m_fs-e2fs.e2fs_log_bsize + 1;
+	m_fs-e2fs_fsbtodb = m_fs-e2fs.e2fs_log_bsize + LOG_MINBSIZE - DEV_BSHIFT;
 	m_fs-e2fs_bsize = MINBSIZE  m_fs-e2fs.e2fs_log_bsize;
 	m_fs-e2fs_bshift = LOG_MINBSIZE + m_fs-e2fs.e2fs_log_bsize;
 	m_fs-e2fs_qbmask = m_fs-e2fs_bsize - 1;



CVS commit: src/sys/ufs/ffs

2010-01-31 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Jan 31 10:50:23 UTC 2010

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

Log Message:
Replace individual queries for partition information with
new helper function.


To generate a diff of this commit:
cvs rdiff -u -r1.254 -r1.255 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.254 src/sys/ufs/ffs/ffs_vfsops.c:1.255
--- src/sys/ufs/ffs/ffs_vfsops.c:1.254	Fri Jan  8 11:35:11 2010
+++ src/sys/ufs/ffs/ffs_vfsops.c	Sun Jan 31 10:50:23 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.254 2010/01/08 11:35:11 pooka Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.255 2010/01/31 10:50:23 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.254 2010/01/08 11:35:11 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.255 2010/01/31 10:50:23 mlelstv Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -584,7 +584,9 @@
 	struct buf *bp;
 	struct fs *fs, *newfs;
 	struct partinfo dpart;
-	int i, blks, size, error;
+	int i, bsize, blks, error;
+	uint64_t numsecs;
+	unsigned secsize;
 	int32_t *lp;
 	struct ufsmount *ump;
 	daddr_t sblockloc;
@@ -606,12 +608,11 @@
 	 * Step 2: re-read superblock from disk.
 	 */
 	fs = ump-um_fs;
-	if (VOP_IOCTL(devvp, DIOCGPART, dpart, FREAD, NOCRED) != 0)
-		size = DEV_BSIZE;
-	else
-		size = dpart.disklab-d_secsize;
+	error = getdisksize(devvp, numsecs, secsize);
+	if (error)
+		secsize = DEV_BSIZE;
 	/* XXX we don't handle possibility that superblock moved. */
-	error = bread(devvp, fs-fs_sblockloc / size, fs-fs_sbsize,
+	error = bread(devvp, fs-fs_sblockloc / secsize, fs-fs_sbsize,
 		  NOCRED, 0, bp);
 	if (error) {
 		brelse(bp, 0);
@@ -664,7 +665,7 @@
 		/* Manually look for an apple ufs label, and if a valid one
 		 * is found, then treat it like an Apple UFS filesystem anyway
 		 */
-		error = bread(devvp, (daddr_t)(APPLEUFS_LABEL_OFFSET / size),
+		error = bread(devvp, (daddr_t)(APPLEUFS_LABEL_OFFSET / secsize),
 			APPLEUFS_LABEL_SIZE, cred, 0, bp);
 		if (error) {
 			brelse(bp, 0);
@@ -721,10 +722,10 @@
 	blks = howmany(fs-fs_cssize, fs-fs_fsize);
 	space = fs-fs_csp;
 	for (i = 0; i  blks; i += fs-fs_frag) {
-		size = fs-fs_bsize;
+		bsize = fs-fs_bsize;
 		if (i + fs-fs_frag  blks)
-			size = (blks - i) * fs-fs_fsize;
-		error = bread(devvp, fsbtodb(fs, fs-fs_csaddr + i), size,
+			bsize = (blks - i) * fs-fs_fsize;
+		error = bread(devvp, fsbtodb(fs, fs-fs_csaddr + i), bsize,
 			  NOCRED, 0, bp);
 		if (error) {
 			brelse(bp, 0);
@@ -733,11 +734,11 @@
 #ifdef FFS_EI
 		if (UFS_FSNEEDSWAP(fs))
 			ffs_csum_swap((struct csum *)bp-b_data,
-			(struct csum *)space, size);
+			(struct csum *)space, bsize);
 		else
 #endif
-			memcpy(space, bp-b_data, (size_t)size);
-		space = (char *)space + size;
+			memcpy(space, bp-b_data, (size_t)bsize);
+		space = (char *)space + bsize;
 		brelse(bp, 0);
 	}
 	if (fs-fs_snapinum[0] != 0)
@@ -824,7 +825,9 @@
 	void *space;
 	daddr_t sblockloc, fsblockloc;
 	int blks, fstype;
-	int error, i, size, ronly, bset = 0;
+	int error, i, bsize, ronly, bset = 0;
+	uint64_t numsecs;
+	unsigned secsize;
 #ifdef FFS_EI
 	int needswap = 0;		/* keep gcc happy */
 #endif
@@ -843,10 +846,9 @@
 		return (error);
 
 	ronly = (mp-mnt_flag  MNT_RDONLY) != 0;
-	if (VOP_IOCTL(devvp, DIOCGPART, dpart, FREAD, cred) != 0)
-		size = DEV_BSIZE;
-	else
-		size = dpart.disklab-d_secsize;
+	error = getdisksize(devvp, numsecs, secsize);
+	if (error)
+		return (error);
 
 	bp = NULL;
 	ump = NULL;
@@ -882,7 +884,7 @@
 			fs = NULL;
 			goto out;
 		}
-		error = bread(devvp, sblock_try[i] / size, SBLOCKSIZE, cred,
+		error = bread(devvp, sblock_try[i] / secsize, SBLOCKSIZE, cred,
 			  0, bp);
 		if (error) {
 			fs = NULL;
@@ -1104,18 +1106,18 @@
 			fs-fs_clean = 1;
 			fs-fs_fmod = 1;
 		}
-	size = fs-fs_cssize;
-	blks = howmany(size, fs-fs_fsize);
+	bsize = fs-fs_cssize;
+	blks = howmany(bsize, fs-fs_fsize);
 	if (fs-fs_contigsumsize  0)
-		size += fs-fs_ncg * sizeof(int32_t);
-	size += fs-fs_ncg * sizeof(*fs-fs_contigdirs);
-	space = malloc((u_long)size, M_UFSMNT, M_WAITOK);
+		bsize += fs-fs_ncg * sizeof(int32_t);
+	bsize += fs-fs_ncg * sizeof(*fs-fs_contigdirs);
+	space = malloc((u_long)bsize, M_UFSMNT, M_WAITOK);
 	fs-fs_csp = space;
 	for (i = 0; i  blks; i += fs-fs_frag) {
-		size = fs-fs_bsize;
+		bsize = fs-fs_bsize;
 		if (i + fs-fs_frag  blks)
-			size = (blks - i) * fs-fs_fsize;
-		error = bread(devvp, fsbtodb(fs, fs-fs_csaddr + i), size,
+			bsize = (blks - i) * fs-fs_fsize;
+		error = bread(devvp, fsbtodb(fs, fs-fs_csaddr + i), bsize,
 			  cred, 0, bp);
 		if (error) {
 			free(fs-fs_csp, M_UFSMNT);
@@ -1124,12 +1126,12 @@
 #ifdef FFS_EI
 		if (needswap)

CVS commit: src/sys/ufs/ffs

2010-01-31 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Jan 31 10:54:10 UTC 2010

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

Log Message:
Fix block shift to work with different device block sizes.

Unlike other filesystems this has some side issues because
the shift values are stored in the superblock and because
userland utitlies share the same fsbtodb macros.

- the kernel now ignores the value stored in the superblock.
- the macro adaption is only done for defined(_KERNEL) code.


To generate a diff of this commit:
cvs rdiff -u -r1.255 -r1.256 src/sys/ufs/ffs/ffs_vfsops.c
cvs rdiff -u -r1.54 -r1.55 src/sys/ufs/ffs/fs.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_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.255 src/sys/ufs/ffs/ffs_vfsops.c:1.256
--- src/sys/ufs/ffs/ffs_vfsops.c:1.255	Sun Jan 31 10:50:23 2010
+++ src/sys/ufs/ffs/ffs_vfsops.c	Sun Jan 31 10:54:10 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.255 2010/01/31 10:50:23 mlelstv Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.256 2010/01/31 10:54:10 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.255 2010/01/31 10:50:23 mlelstv Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.256 2010/01/31 10:54:10 mlelstv Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -585,8 +585,6 @@
 	struct fs *fs, *newfs;
 	struct partinfo dpart;
 	int i, bsize, blks, error;
-	uint64_t numsecs;
-	unsigned secsize;
 	int32_t *lp;
 	struct ufsmount *ump;
 	daddr_t sblockloc;
@@ -608,11 +606,9 @@
 	 * Step 2: re-read superblock from disk.
 	 */
 	fs = ump-um_fs;
-	error = getdisksize(devvp, numsecs, secsize);
-	if (error)
-		secsize = DEV_BSIZE;
+
 	/* XXX we don't handle possibility that superblock moved. */
-	error = bread(devvp, fs-fs_sblockloc / secsize, fs-fs_sbsize,
+	error = bread(devvp, fs-fs_sblockloc / DEV_BSIZE, fs-fs_sbsize,
 		  NOCRED, 0, bp);
 	if (error) {
 		brelse(bp, 0);
@@ -665,7 +661,7 @@
 		/* Manually look for an apple ufs label, and if a valid one
 		 * is found, then treat it like an Apple UFS filesystem anyway
 		 */
-		error = bread(devvp, (daddr_t)(APPLEUFS_LABEL_OFFSET / secsize),
+		error = bread(devvp, (daddr_t)(APPLEUFS_LABEL_OFFSET / DEV_BSIZE),
 			APPLEUFS_LABEL_SIZE, cred, 0, bp);
 		if (error) {
 			brelse(bp, 0);
@@ -884,7 +880,7 @@
 			fs = NULL;
 			goto out;
 		}
-		error = bread(devvp, sblock_try[i] / secsize, SBLOCKSIZE, cred,
+		error = bread(devvp, sblock_try[i] / DEV_BSIZE, SBLOCKSIZE, cred,
 			  0, bp);
 		if (error) {
 			fs = NULL;
@@ -1032,7 +1028,7 @@
 		/* Manually look for an apple ufs label, and if a valid one
 		 * is found, then treat it like an Apple UFS filesystem anyway
 		 */
-		error = bread(devvp, (daddr_t)(APPLEUFS_LABEL_OFFSET / size),
+		error = bread(devvp, (daddr_t)(APPLEUFS_LABEL_OFFSET / DEV_BSIZE),
 			APPLEUFS_LABEL_SIZE, cred, 0, bp);
 		if (error)
 			goto out;
@@ -1186,7 +1182,7 @@
 	ump-um_devvp = devvp;
 	ump-um_nindir = fs-fs_nindir;
 	ump-um_lognindir = ffs(fs-fs_nindir) - 1;
-	ump-um_bptrtodb = fs-fs_fsbtodb;
+	ump-um_bptrtodb = fs-fs_fshift - DEV_BSHIFT;
 	ump-um_seqinc = fs-fs_frag;
 	for (i = 0; i  MAXQUOTAS; i++)
 		ump-um_quotas[i] = NULLVP;

Index: src/sys/ufs/ffs/fs.h
diff -u src/sys/ufs/ffs/fs.h:1.54 src/sys/ufs/ffs/fs.h:1.55
--- src/sys/ufs/ffs/fs.h:1.54	Sun Jun 28 09:26:18 2009
+++ src/sys/ufs/ffs/fs.h	Sun Jan 31 10:54:10 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: fs.h,v 1.54 2009/06/28 09:26:18 ad Exp $	*/
+/*	$NetBSD: fs.h,v 1.55 2010/01/31 10:54:10 mlelstv Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1993
@@ -599,8 +599,13 @@
  * Turn file system block numbers into disk block addresses.
  * This maps file system blocks to device size blocks.
  */
+#if defined (_KERNEL)
+#define	fsbtodb(fs, b)	((b)  ((fs)-fs_fshift - DEV_BSHIFT))
+#define	dbtofsb(fs, b)	((b)  ((fs)-fs_fshift - DEV_BSHIFT))
+#else
 #define	fsbtodb(fs, b)	((b)  (fs)-fs_fsbtodb)
 #define	dbtofsb(fs, b)	((b)  (fs)-fs_fsbtodb)
+#endif
 
 /*
  * Cylinder group macros to locate things in cylinder groups.



<    2   3   4   5   6   7   8   >