CVS commit: [bouyer-quota2] src/sys/ufs/ufs

2011-02-18 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Fri Feb 18 11:46:43 UTC 2011

Modified Files:
src/sys/ufs/ufs [bouyer-quota2]: ufs_quota2.c

Log Message:
Only use B_MODIFY when needed, avoid unecessery copy on write when using
snapshots.


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.15 -r1.1.2.16 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.1.2.15 src/sys/ufs/ufs/ufs_quota2.c:1.1.2.16
--- src/sys/ufs/ufs/ufs_quota2.c:1.1.2.15	Sat Feb 12 21:48:09 2011
+++ src/sys/ufs/ufs/ufs_quota2.c	Fri Feb 18 11:46:43 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: ufs_quota2.c,v 1.1.2.15 2011/02/12 21:48:09 bouyer Exp $ */
+/* $NetBSD: ufs_quota2.c,v 1.1.2.16 2011/02/18 11:46:43 bouyer Exp $ */
 /*-
   * Copyright (c) 2010 Manuel Bouyer
   * All rights reserved.
@@ -28,7 +28,7 @@
   */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ufs_quota2.c,v 1.1.2.15 2011/02/12 21:48:09 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_quota2.c,v 1.1.2.16 2011/02/18 11:46:43 bouyer Exp $");
 
 #include 
 #include 
@@ -64,7 +64,7 @@
  */
 
 static int quota2_bwrite(struct mount *, struct buf *);
-static int getinoquota2(struct inode *, int, struct buf **,
+static int getinoquota2(struct inode *, bool, bool, struct buf **,
 struct quota2_entry **);
 static int getq2h(struct ufsmount *, int, struct buf **,
 struct quota2_header **, int);
@@ -321,7 +321,7 @@
 }
 
 static int
-getinoquota2(struct inode *ip, int alloc, struct buf **bpp,
+getinoquota2(struct inode *ip, bool alloc, bool modify, struct buf **bpp,
 struct quota2_entry **q2ep)
 {
 	int error;
@@ -365,7 +365,7 @@
 		}
 
 		if ((dq->dq2_lblkno | dq->dq2_blkoff) == 0) {
-			if (alloc == 0) {
+			if (!alloc) {
 continue;
 			}
 			/* need to alloc a new on-disk quot */
@@ -377,7 +377,8 @@
 return error;
 		} else {
 			error = getq2e(ump, i, dq->dq2_lblkno,
-			dq->dq2_blkoff, &bpp[i], &q2ep[i], B_MODIFY);
+			dq->dq2_blkoff, &bpp[i], &q2ep[i],
+			modify ? B_MODIFY : 0);
 			if (error)
 return error;
 		}
@@ -400,7 +401,7 @@
 	const int needswap = UFS_MPNEEDSWAP(ump);
 	int i;
 
-	if ((error = getinoquota2(ip, change > 0, bp, q2e)) != 0)
+	if ((error = getinoquota2(ip, change > 0, change != 0, bp, q2e)) != 0)
 		return error;
 	if (change == 0) {
 		for (i = 0; i < MAXQUOTAS; i++) {



CVS commit: [bouyer-quota2] src/sys/ufs/ufs

2011-02-14 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Mon Feb 14 15:38:16 UTC 2011

Modified Files:
src/sys/ufs/ufs [bouyer-quota2]: ufs_inode.c

Log Message:
Update quota in the same WAPBL transaction as we write mode=0 back to inode.


To generate a diff of this commit:
cvs rdiff -u -r1.83.4.1 -r1.83.4.2 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.83.4.1 src/sys/ufs/ufs/ufs_inode.c:1.83.4.2
--- src/sys/ufs/ufs/ufs_inode.c:1.83.4.1	Thu Jan 20 14:25:03 2011
+++ src/sys/ufs/ufs/ufs_inode.c	Mon Feb 14 15:38:16 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_inode.c,v 1.83.4.1 2011/01/20 14:25:03 bouyer Exp $	*/
+/*	$NetBSD: ufs_inode.c,v 1.83.4.2 2011/02/14 15:38:16 bouyer Exp $	*/
 
 /*
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ufs_inode.c,v 1.83.4.1 2011/01/20 14:25:03 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_inode.c,v 1.83.4.2 2011/02/14 15:38:16 bouyer Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -103,9 +103,6 @@
 		if (error)
 			goto out;
 		logged = 1;
-#if defined(QUOTA) || defined(QUOTA2)
-		(void)chkiq(ip, -1, NOCRED, 0);
-#endif
 #ifdef UFS_EXTATTR
 		ufs_extattr_vnode_inactive(vp, curlwp);
 #endif
@@ -140,6 +137,9 @@
 			if (!error)
 error = UFS_TRUNCATE(vp, (off_t)0, 0, NOCRED);
 		}
+#if defined(QUOTA) || defined(QUOTA2)
+		(void)chkiq(ip, -1, NOCRED, 0);
+#endif
 		DIP_ASSIGN(ip, rdev, 0);
 		mode = ip->i_mode;
 		ip->i_mode = 0;



CVS commit: [bouyer-quota2] src/sys/ufs/ufs

2011-02-12 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Sun Feb 13 00:11:09 UTC 2011

Modified Files:
src/sys/ufs/ufs [bouyer-quota2]: ufs_quota.c

Log Message:
Fix memory leak


To generate a diff of this commit:
cvs rdiff -u -r1.68.4.13 -r1.68.4.14 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.68.4.13 src/sys/ufs/ufs/ufs_quota.c:1.68.4.14
--- src/sys/ufs/ufs/ufs_quota.c:1.68.4.13	Sat Feb 12 21:48:09 2011
+++ src/sys/ufs/ufs/ufs_quota.c	Sun Feb 13 00:11:09 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_quota.c,v 1.68.4.13 2011/02/12 21:48:09 bouyer Exp $	*/
+/*	$NetBSD: ufs_quota.c,v 1.68.4.14 2011/02/13 00:11:09 bouyer Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993, 1995
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ufs_quota.c,v 1.68.4.13 2011/02/12 21:48:09 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_quota.c,v 1.68.4.14 2011/02/13 00:11:09 bouyer Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_quota.h"
@@ -301,8 +301,10 @@
 			if (!prop_dictionary_get_cstring_nocopy(data, "id",
 			&idstr))
 continue;
-			if (strcmp(idstr, "default"))
-continue;
+			if (strcmp(idstr, "default")) {
+error = EINVAL;
+goto err;
+			}
 			id = 0;
 			defaultq = 1;
 		} else {
@@ -311,10 +313,8 @@
 		error = quota_get_auth(mp, l, id);
 		if (error == EPERM)
 			continue;
-		if (error != 0) {
-			prop_object_release(replies);
-			return error;
-		}
+		if (error != 0) 
+			goto err;
 #ifdef QUOTA
 		if (ump->um_flags & UFS_QUOTA)
 			error = quota1_handle_cmd_get(ump, type, id, defaultq,
@@ -329,17 +329,22 @@
 #endif
 			panic("quota_handle_cmd_get: no support ?");
 		
-		if (error && error != ENOENT) {
-			prop_object_release(replies);
-			return error;
-		}
+		if (error == ENOENT)
+			continue;
+		if (error != 0)
+			goto err;
 	}
+	prop_object_iterator_release(iter);
 	if (!prop_dictionary_set_and_rel(cmddict, "data", replies)) {
 		error = ENOMEM;
 	} else {
 		error = 0;
 	}
 	return error;
+err:
+	prop_object_iterator_release(iter);
+	prop_object_release(replies);
+	return error;
 }
 
 static int 
@@ -380,10 +385,8 @@
 		}
 		error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_FS_QUOTA,
 		KAUTH_REQ_SYSTEM_FS_QUOTA_MANAGE, mp, KAUTH_ARG(id), NULL);
-		if (error != 0) {
-			prop_object_release(replies);
-			return error;
-		}
+		if (error != 0)
+			goto err;
 #ifdef QUOTA
 		if (ump->um_flags & UFS_QUOTA)
 			error = quota1_handle_cmd_set(ump, type, id, defaultq,
@@ -398,17 +401,20 @@
 #endif
 			panic("quota_handle_cmd_get: no support ?");
 		
-		if (error && error != ENOENT) {
-			prop_object_release(replies);
-			return error;
-		}
+		if (error && error != ENOENT)
+			goto err;
 	}
+	prop_object_iterator_release(iter);
 	if (!prop_dictionary_set_and_rel(cmddict, "data", replies)) {
 		error = ENOMEM;
 	} else {
 		error = 0;
 	}
 	return error;
+err:
+	prop_object_iterator_release(iter);
+	prop_object_release(replies);
+	return error;
 }
 
 static int 
@@ -449,10 +455,8 @@
 		}
 		error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_FS_QUOTA,
 		KAUTH_REQ_SYSTEM_FS_QUOTA_MANAGE, mp, KAUTH_ARG(id), NULL);
-		if (error != 0) {
-			prop_object_release(replies);
-			return error;
-		}
+		if (error != 0)
+			goto err;
 #ifdef QUOTA2
 		if (ump->um_flags & UFS_QUOTA2) {
 			error = quota2_handle_cmd_clear(ump, type, id, defaultq,
@@ -461,17 +465,20 @@
 #endif
 			panic("quota_handle_cmd_get: no support ?");
 		
-		if (error && error != ENOENT) {
-			prop_object_release(replies);
-			return error;
-		}
+		if (error && error != ENOENT)
+			goto err;
 	}
+	prop_object_iterator_release(iter);
 	if (!prop_dictionary_set_and_rel(cmddict, "data", replies)) {
 		error = ENOMEM;
 	} else {
 		error = 0;
 	}
 	return error;
+err:
+	prop_object_iterator_release(iter);
+	prop_object_release(replies);
+	return error;
 }
 
 static int 



CVS commit: [bouyer-quota2] src/sys/ufs/ufs

2011-02-11 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Fri Feb 11 16:55:35 UTC 2011

Modified Files:
src/sys/ufs/ufs [bouyer-quota2]: ufs_quota2.c

Log Message:
walk_list: make sure we don't try to read the same quota disk block again
without releasing it first


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.13 -r1.1.2.14 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.1.2.13 src/sys/ufs/ufs/ufs_quota2.c:1.1.2.14
--- src/sys/ufs/ufs/ufs_quota2.c:1.1.2.13	Thu Feb 10 16:16:05 2011
+++ src/sys/ufs/ufs/ufs_quota2.c	Fri Feb 11 16:55:35 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: ufs_quota2.c,v 1.1.2.13 2011/02/10 16:16:05 bouyer Exp $ */
+/* $NetBSD: ufs_quota2.c,v 1.1.2.14 2011/02/11 16:55:35 bouyer Exp $ */
 /*-
   * Copyright (c) 2010 Manuel Bouyer
   * All rights reserved.
@@ -28,7 +28,7 @@
   */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ufs_quota2.c,v 1.1.2.13 2011/02/10 16:16:05 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_quota2.c,v 1.1.2.14 2011/02/11 16:55:35 bouyer Exp $");
 
 #include 
 #include 
@@ -155,7 +155,7 @@
 	struct buf *bp, *obp = hbp;
 	int ret = 0, ret2 = 0;
 	struct quota2_entry *q2e;
-	daddr_t lblkno, blkoff;
+	daddr_t lblkno, blkoff, olblkno = 0;
 
 	KASSERT(mutex_owner(&dqlock));
 
@@ -165,6 +165,9 @@
 		if (lblkno == 0) {
 			/* in the header block */
 			bp = hbp;
+		} else if (lblkno == olblkno) {
+			/* still in the same buf */
+			bp = obp;
 		} else {
 			ret = bread(ump->um_quotas[type], lblkno, 
 			ump->umq2_bsize,
@@ -192,6 +195,7 @@
 	brelse(obp, 0);
 			}
 			obp = bp;
+			olblkno = lblkno;
 			offp = &(q2e->q2e_next);
 			off = ufs_rw64(*offp, needswap);
 		}



CVS commit: [bouyer-quota2] src/sys/ufs/ufs

2011-02-11 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Fri Feb 11 11:38:44 UTC 2011

Modified Files:
src/sys/ufs/ufs [bouyer-quota2]: quota2_prop.c

Log Message:
Remove key "quota version", it doesn't serve any purpose


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.4 -r1.1.2.5 src/sys/ufs/ufs/quota2_prop.c

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_prop.c
diff -u src/sys/ufs/ufs/quota2_prop.c:1.1.2.4 src/sys/ufs/ufs/quota2_prop.c:1.1.2.5
--- src/sys/ufs/ufs/quota2_prop.c:1.1.2.4	Mon Jan 31 15:24:10 2011
+++ src/sys/ufs/ufs/quota2_prop.c	Fri Feb 11 11:38:44 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: quota2_prop.c,v 1.1.2.4 2011/01/31 15:24:10 bouyer Exp $ */
+/* $NetBSD: quota2_prop.c,v 1.1.2.5 2011/02/11 11:38:44 bouyer Exp $ */
 /*-
   * Copyright (c) 2010 Manuel Bouyer
   * All rights reserved.
@@ -134,12 +134,6 @@
 	if (prop_number_integer_value(pn) != 1)
 		return EINVAL;
 
-	pn = prop_dictionary_get(qdict, "quota version");
-	if (pn == NULL)
-		return EINVAL;
-	if (prop_number_integer_value(pn) != 2)
-		return EINVAL;
-
 	o = prop_dictionary_get(qdict, "commands");
 	if (o == NULL)
 		return ENOMEM;
@@ -183,9 +177,6 @@
 	if (!prop_dictionary_set_uint8(dict, "interface version", 1)) {
 		goto err;
 	}
-	if (!prop_dictionary_set_uint8(dict, "quota version", 2)) {
-		goto err;
-	}
 	return dict;
 err:
 	prop_object_release(dict);
@@ -247,7 +238,6 @@
 err:
 	prop_object_release(dict1);
 	return NULL;
-	
 }
 
 prop_dictionary_t



CVS commit: [bouyer-quota2] src/sys/ufs/ufs

2011-02-10 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Thu Feb 10 16:16:05 UTC 2011

Modified Files:
src/sys/ufs/ufs [bouyer-quota2]: ufs_quota2.c

Log Message:
Unless the filestystem is mounted MNT_SYNCHRONOUS, use bdwrite()
to write back updated quota entries.


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.12 -r1.1.2.13 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.1.2.12 src/sys/ufs/ufs/ufs_quota2.c:1.1.2.13
--- src/sys/ufs/ufs/ufs_quota2.c:1.1.2.12	Wed Feb  9 21:17:17 2011
+++ src/sys/ufs/ufs/ufs_quota2.c	Thu Feb 10 16:16:05 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: ufs_quota2.c,v 1.1.2.12 2011/02/09 21:17:17 bouyer Exp $ */
+/* $NetBSD: ufs_quota2.c,v 1.1.2.13 2011/02/10 16:16:05 bouyer Exp $ */
 /*-
   * Copyright (c) 2010 Manuel Bouyer
   * All rights reserved.
@@ -28,7 +28,7 @@
   */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ufs_quota2.c,v 1.1.2.12 2011/02/09 21:17:17 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_quota2.c,v 1.1.2.13 2011/02/10 16:16:05 bouyer Exp $");
 
 #include 
 #include 
@@ -63,6 +63,7 @@
  * the locking order is dq_interlock -> dqlock
  */
 
+static int quota2_bwrite(struct mount *, struct buf *);
 static int getinoquota2(struct inode *, int, struct buf **,
 struct quota2_entry **);
 static int getq2h(struct ufsmount *, int, struct buf **,
@@ -77,6 +78,17 @@
 static const char *valtypes[] = INITQLNAMES;
 
 static int
+quota2_bwrite(struct mount *mp, struct buf *bp)
+{
+	if (mp->mnt_flag & MNT_SYNCHRONOUS)
+		return bwrite(bp);
+	else {
+		bdwrite(bp);
+		return 0;
+	}
+}
+
+static int
 getq2h(struct ufsmount *ump, int type,
 struct buf **bpp, struct quota2_header **q2hp, int flags)
 {
@@ -170,12 +182,12 @@
 			/* callback changed parent's pointer, redo */
 			off = ufs_rw64(*offp, needswap);
 			if (bp != hbp && bp != obp)
-ret2 = VOP_BWRITE(bp);
+ret2 = bwrite(bp);
 		} else {
 			/* parent if now current */
 			if (obp != bp && obp != hbp) {
 if (flags & B_MODIFY)
-	ret2 = VOP_BWRITE(obp);
+	ret2 = bwrite(obp);
 else
 	brelse(obp, 0);
 			}
@@ -192,7 +204,7 @@
 	}
 	if (obp != hbp) {
 		if (flags & B_MODIFY)
-			ret2 = VOP_BWRITE(obp);
+			ret2 = bwrite(obp);
 		else
 			brelse(obp, 0);
 	}
@@ -263,7 +275,7 @@
 		uvm_vnp_setsize(vp, ip->i_size);
 		quota2_addfreeq2e(q2h, bp->b_data, size, ump->umq2_bsize,
 		needswap);
-		error = VOP_BWRITE(bp);
+		error = bwrite(bp);
 		error2 = UFS_UPDATE(vp, NULL, NULL, UPDATE_WAIT);
 		if (error || error2) {
 			brelse(hbp, 0);
@@ -297,7 +309,7 @@
 	q2e->q2e_next = q2h->q2h_entries[uid & hash_mask];
 	q2h->q2h_entries[uid & hash_mask] = ufs_rw64(offset, needswap);
 	if (hbp != bp) {
-		VOP_BWRITE(hbp);
+		bwrite(hbp);
 	}
 	*q2ep = q2e;
 	*bpp = bp;
@@ -404,7 +416,7 @@
 			else
 ncurblks += change;
 			q2vp->q2v_cur = ufs_rw64(ncurblks, needswap);
-			VOP_BWRITE(bp[i]);
+			quota2_bwrite(mp, bp[i]);
 			mutex_exit(&dq->dq_interlock);
 		}
 		return 0;
@@ -479,7 +491,7 @@
 			q2vp = &q2e[i]->q2e_val[vtype];
 			ncurblks = ufs_rw64(q2vp->q2v_cur, needswap);
 			q2vp->q2v_cur = ufs_rw64(ncurblks + change, needswap);
-			VOP_BWRITE(bp[i]);
+			quota2_bwrite(mp, bp[i]);
 		} else
 			brelse(bp[i], 0);
 		mutex_exit(&dq->dq_interlock);
@@ -532,7 +544,7 @@
 		}
 		quota2_ufs_rwq2e(&q2e, &q2h->q2h_defentry, needswap);
 		mutex_exit(&dqlock);
-		VOP_BWRITE(bp);
+		quota2_bwrite(ump->um_mountp, bp);
 		goto out_wapbl;
 	}
 
@@ -560,7 +572,7 @@
 		goto out_il;
 	}
 	quota2_ufs_rwq2e(&q2e, q2ep, needswap);
-	VOP_BWRITE(bp);
+	quota2_bwrite(ump->um_mountp, bp);
 
 out_il:
 	mutex_exit(&dq->dq_interlock);
@@ -660,7 +672,7 @@
 			q2e.q2e_val[i].q2v_grace;
 			q2ep->q2e_val[i].q2v_time = 0;
 		}
-		VOP_BWRITE(bp);
+		quota2_bwrite(ump->um_mountp, bp);
 		goto out_wapbl;
 	}
 	/* we can free it. release bp so we can walk the list */
@@ -678,7 +690,7 @@
 	&q2h->q2h_entries[id & hash_mask], B_MODIFY, &c,
 	dq2clear_callback);
 
-	VOP_BWRITE(hbp);
+	bwrite(hbp);
 
 out_dqlock:
 	mutex_exit(&dqlock);



CVS commit: [bouyer-quota2] src/sys/ufs/ufs

2011-02-09 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Wed Feb  9 21:17:17 UTC 2011

Modified Files:
src/sys/ufs/ufs [bouyer-quota2]: ufs_quota2.c

Log Message:
Make sure to not try to close the quota vnodes twice.


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.11 -r1.1.2.12 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.1.2.11 src/sys/ufs/ufs/ufs_quota2.c:1.1.2.12
--- src/sys/ufs/ufs/ufs_quota2.c:1.1.2.11	Wed Feb  9 11:18:30 2011
+++ src/sys/ufs/ufs/ufs_quota2.c	Wed Feb  9 21:17:17 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: ufs_quota2.c,v 1.1.2.11 2011/02/09 11:18:30 bouyer Exp $ */
+/* $NetBSD: ufs_quota2.c,v 1.1.2.12 2011/02/09 21:17:17 bouyer Exp $ */
 /*-
   * Copyright (c) 2010 Manuel Bouyer
   * All rights reserved.
@@ -28,7 +28,7 @@
   */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ufs_quota2.c,v 1.1.2.11 2011/02/09 11:18:30 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_quota2.c,v 1.1.2.12 2011/02/09 21:17:17 bouyer Exp $");
 
 #include 
 #include 
@@ -213,7 +213,7 @@
 		return 0;
 
 	for (i = 0; i < MAXQUOTAS; i++) {
-		if (ump->um_quotas[i]) {
+		if (ump->um_quotas[i] != NULLVP) {
 			error = vn_close(ump->um_quotas[i], FREAD|FWRITE,
 			ump->um_cred[i]);
 			if (error) {
@@ -222,6 +222,7 @@
 return error;
 			}
 		}
+		ump->um_quotas[i] = NULLVP;
 	}
 	return 0;
 }



CVS commit: [bouyer-quota2] src/sys/ufs/ufs

2011-02-09 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Wed Feb  9 17:43:53 UTC 2011

Modified Files:
src/sys/ufs/ufs [bouyer-quota2]: ufs_quota1.c

Log Message:
Make it actually work.


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.5 -r1.1.2.6 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.1.2.5 src/sys/ufs/ufs/ufs_quota1.c:1.1.2.6
--- src/sys/ufs/ufs/ufs_quota1.c:1.1.2.5	Wed Feb  9 16:15:01 2011
+++ src/sys/ufs/ufs/ufs_quota1.c	Wed Feb  9 17:43:53 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_quota1.c,v 1.1.2.5 2011/02/09 16:15:01 bouyer Exp $	*/
+/*	$NetBSD: ufs_quota1.c,v 1.1.2.6 2011/02/09 17:43:53 bouyer Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993, 1995
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ufs_quota1.c,v 1.1.2.5 2011/02/09 16:15:01 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_quota1.c,v 1.1.2.6 2011/02/09 17:43:53 bouyer Exp $");
 
 #include 
 #include 
@@ -325,9 +325,9 @@
 
 	vpp = &ump->um_quotas[type];
 
-	error = pathbuf_copyin(fname, &pb);
-	if (error) {
-		return error;
+	pb = pathbuf_create(fname);
+	if (pb == NULL) {
+		return ENOMEM;
 	}
 	NDINIT(&nd, LOOKUP, FOLLOW, pb);
 	if ((error = vn_open(&nd, FREAD|FWRITE, 0)) != 0) {
@@ -518,8 +518,16 @@
 	dqblk2q2e(&dq->dq_un.dq1_dqb, &q2e);
 	dqrele(NULLVP, dq);
 	if (defaultq) {
-		q2e.q2e_val[QL_BLOCK].q2v_grace = q2e.q2e_val[QL_BLOCK].q2v_time;
-		q2e.q2e_val[QL_FILE].q2v_grace = q2e.q2e_val[QL_FILE].q2v_time;
+		if (q2e.q2e_val[QL_BLOCK].q2v_time > 0)
+			q2e.q2e_val[QL_BLOCK].q2v_grace =
+			q2e.q2e_val[QL_BLOCK].q2v_time;
+		else
+			q2e.q2e_val[QL_BLOCK].q2v_grace = MAX_DQ_TIME;
+		if (q2e.q2e_val[QL_FILE].q2v_time > 0)
+			q2e.q2e_val[QL_FILE].q2v_grace =
+			q2e.q2e_val[QL_FILE].q2v_time;
+		else
+			q2e.q2e_val[QL_FILE].q2v_grace = MAX_DQ_TIME;
 	}
 	dict = q2etoprop(&q2e, defaultq);
 	if (dict == NULL)
@@ -550,10 +558,12 @@
 		if ((error = dqget(NULLVP, id, ump, type, &dq)) != 0)
 			return error;
 		mutex_enter(&dq->dq_interlock);
-		ump->umq1_btime[type] = dq->dq_btime =
-		q2e.q2e_val[QL_BLOCK].q2v_grace;
-		ump->umq1_itime[type] = dq->dq_itime =
-		q2e.q2e_val[QL_FILE].q2v_grace;
+		if (q2e.q2e_val[QL_BLOCK].q2v_grace > 0)
+			ump->umq1_btime[type] = dq->dq_btime =
+			q2e.q2e_val[QL_BLOCK].q2v_grace;
+		if (q2e.q2e_val[QL_FILE].q2v_grace > 0)
+			ump->umq1_itime[type] = dq->dq_itime =
+			q2e.q2e_val[QL_FILE].q2v_grace;
 		mutex_exit(&dq->dq_interlock);
 		dq->dq_flags |= DQ_MOD;
 		dqrele(NULLVP, dq);



CVS commit: [bouyer-quota2] src/sys/ufs/ufs

2011-02-09 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Wed Feb  9 12:01:20 UTC 2011

Modified Files:
src/sys/ufs/ufs [bouyer-quota2]: ufs_quota1.c

Log Message:
Fix typo


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.3 -r1.1.2.4 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.1.2.3 src/sys/ufs/ufs/ufs_quota1.c:1.1.2.4
--- src/sys/ufs/ufs/ufs_quota1.c:1.1.2.3	Tue Feb  8 20:00:53 2011
+++ src/sys/ufs/ufs/ufs_quota1.c	Wed Feb  9 12:01:20 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_quota1.c,v 1.1.2.3 2011/02/08 20:00:53 bouyer Exp $	*/
+/*	$NetBSD: ufs_quota1.c,v 1.1.2.4 2011/02/09 12:01:20 bouyer Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993, 1995
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ufs_quota1.c,v 1.1.2.3 2011/02/08 20:00:53 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_quota1.c,v 1.1.2.4 2011/02/09 12:01:20 bouyer Exp $");
 
 #include 
 #include 
@@ -701,7 +701,7 @@
 	struct uio auio;
 	int error;
 
-	KASSERT(mutex_locked(&dq->dq_interlock));
+	KASSERT(mutex_owned(&dq->dq_interlock));
 	vn_lock(dqvp, LK_EXCLUSIVE | LK_RETRY);
 	auio.uio_iov = &aiov;
 	auio.uio_iovcnt = 1;



CVS commit: [bouyer-quota2] src/sys/ufs/ufs

2011-02-09 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Wed Feb  9 11:37:17 UTC 2011

Modified Files:
src/sys/ufs/ufs [bouyer-quota2]: ufs_vfsops.c

Log Message:
Fix build without quotas


To generate a diff of this commit:
cvs rdiff -u -r1.40.8.1 -r1.40.8.2 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.40.8.1 src/sys/ufs/ufs/ufs_vfsops.c:1.40.8.2
--- src/sys/ufs/ufs/ufs_vfsops.c:1.40.8.1	Thu Jan 20 14:25:03 2011
+++ src/sys/ufs/ufs/ufs_vfsops.c	Wed Feb  9 11:37:16 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_vfsops.c,v 1.40.8.1 2011/01/20 14:25:03 bouyer Exp $	*/
+/*	$NetBSD: ufs_vfsops.c,v 1.40.8.2 2011/02/09 11:37:16 bouyer Exp $	*/
 
 /*
  * Copyright (c) 1991, 1993, 1994
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ufs_vfsops.c,v 1.40.8.1 2011/01/20 14:25:03 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_vfsops.c,v 1.40.8.2 2011/02/09 11:37:16 bouyer Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -106,7 +106,7 @@
 
 #if !defined(QUOTA) && !defined(QUOTA2)
 	(void) mp;
-	(void) pref;
+	(void) dict;
 	(void) l;
 	return (EOPNOTSUPP);
 #else



CVS commit: [bouyer-quota2] src/sys/ufs/ufs

2011-02-08 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Tue Feb  8 20:09:56 UTC 2011

Modified Files:
src/sys/ufs/ufs [bouyer-quota2]: ufs_quota.h

Log Message:
Remove unused prototypes


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.6 -r1.1.2.7 src/sys/ufs/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/ufs_quota.h
diff -u src/sys/ufs/ufs/ufs_quota.h:1.1.2.6 src/sys/ufs/ufs/ufs_quota.h:1.1.2.7
--- src/sys/ufs/ufs/ufs_quota.h:1.1.2.6	Tue Feb  8 20:00:53 2011
+++ src/sys/ufs/ufs/ufs_quota.h	Tue Feb  8 20:09:56 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_quota.h,v 1.1.2.6 2011/02/08 20:00:53 bouyer Exp $	*/
+/*	$NetBSD: ufs_quota.h,v 1.1.2.7 2011/02/08 20:09:56 bouyer Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993, 1995
@@ -119,8 +119,6 @@
 
 int chkdq1(struct inode *, int64_t, kauth_cred_t, int);
 int chkiq1(struct inode *, int32_t, kauth_cred_t, int);
-int getquota1(struct mount *, u_long, int, struct dqblk *);
-int setquota1(struct mount *, u_long, int, struct dqblk *);
 int q1sync(struct mount *);
 int dq1get(struct vnode *, u_long, struct ufsmount *, int, struct dquot *);
 int dq1sync(struct vnode *, struct dquot *);



CVS commit: [bouyer-quota2] src/sys/ufs/ufs

2011-02-07 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Mon Feb  7 20:30:39 UTC 2011

Modified Files:
src/sys/ufs/ufs [bouyer-quota2]: ufs_quota.c ufs_quota.h ufs_quota2.c

Log Message:
Implement clear command (quota2 only), which either free the specified
quota2 entry (if both disk and inode usage are 0) or revert its limits to
the default quota entry.


To generate a diff of this commit:
cvs rdiff -u -r1.68.4.7 -r1.68.4.8 src/sys/ufs/ufs/ufs_quota.c
cvs rdiff -u -r1.1.2.4 -r1.1.2.5 src/sys/ufs/ufs/ufs_quota.h
cvs rdiff -u -r1.1.2.8 -r1.1.2.9 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.68.4.7 src/sys/ufs/ufs/ufs_quota.c:1.68.4.8
--- src/sys/ufs/ufs/ufs_quota.c:1.68.4.7	Mon Jan 31 21:09:53 2011
+++ src/sys/ufs/ufs/ufs_quota.c	Mon Feb  7 20:30:39 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_quota.c,v 1.68.4.7 2011/01/31 21:09:53 bouyer Exp $	*/
+/*	$NetBSD: ufs_quota.c,v 1.68.4.8 2011/02/07 20:30:39 bouyer Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993, 1995
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ufs_quota.c,v 1.68.4.7 2011/01/31 21:09:53 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_quota.c,v 1.68.4.8 2011/02/07 20:30:39 bouyer Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_quota.h"
@@ -68,6 +68,8 @@
 prop_dictionary_t, int, prop_array_t);
 static int quota_handle_cmd_getall(struct mount *, struct lwp *,
 prop_dictionary_t, int, prop_array_t);
+static int quota_handle_cmd_clear(struct mount *, struct lwp *,
+prop_dictionary_t, int, prop_array_t);
 /*
  * Initialize the quota fields of an inode.
  */
@@ -169,6 +171,10 @@
 		error = quota_handle_cmd_getall(mp, l, cmddict, q2type, datas);
 		goto end;
 	}
+	if (strcmp(cmd, "clear") == 0) {
+		error = quota_handle_cmd_clear(mp, l, cmddict, q2type, datas);
+		goto end;
+	}
 	error = EOPNOTSUPP;
 end:
 	error = (prop_dictionary_set_int8(cmddict, "return",
@@ -371,6 +377,69 @@
 }
 
 static int 
+quota_handle_cmd_clear(struct mount *mp, struct lwp *l, 
+prop_dictionary_t cmddict, int type, prop_array_t datas)
+{
+	prop_array_t replies;
+	prop_object_iterator_t iter;
+	prop_dictionary_t data;
+	uint32_t id;
+	struct ufsmount *ump = VFSTOUFS(mp);
+	int error, defaultq = 0;
+	const char *idstr;
+
+	if ((ump->um_flags & UFS_QUOTA2) == 0)
+		return EOPNOTSUPP;
+	
+	replies = prop_array_create();
+	if (replies == NULL)
+		return ENOMEM;
+
+	iter = prop_array_iterator(datas);
+	if (iter == NULL) {
+		prop_object_release(replies);
+		return ENOMEM;
+	}
+	while ((data = prop_object_iterator_next(iter)) != NULL) {
+		if (!prop_dictionary_get_uint32(data, "id", &id)) {
+			if (!prop_dictionary_get_cstring_nocopy(data, "id",
+			&idstr))
+continue;
+			if (strcmp(idstr, "default"))
+continue;
+			id = 0;
+			defaultq = 1;
+		} else {
+			defaultq = 0;
+		}
+		error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_FS_QUOTA,
+		KAUTH_REQ_SYSTEM_FS_QUOTA_MANAGE, mp, KAUTH_ARG(id), NULL);
+		if (error != 0) {
+			prop_object_release(replies);
+			return error;
+		}
+#ifdef QUOTA2
+		if (ump->um_flags & UFS_QUOTA2) {
+			error = quota2_handle_cmd_clear(ump, type, id, defaultq,
+			data);
+		} else
+#endif
+			panic("quota_handle_cmd_get: no support ?");
+		
+		if (error && error != ENOENT) {
+			prop_object_release(replies);
+			return error;
+		}
+	}
+	if (!prop_dictionary_set_and_rel(cmddict, "data", replies)) {
+		error = ENOMEM;
+	} else {
+		error = 0;
+	}
+	return error;
+}
+
+static int 
 quota_handle_cmd_getall(struct mount *mp, struct lwp *l, 
 prop_dictionary_t cmddict, int type, prop_array_t datas)
 {

Index: src/sys/ufs/ufs/ufs_quota.h
diff -u src/sys/ufs/ufs/ufs_quota.h:1.1.2.4 src/sys/ufs/ufs/ufs_quota.h:1.1.2.5
--- src/sys/ufs/ufs/ufs_quota.h:1.1.2.4	Mon Jan 31 15:24:10 2011
+++ src/sys/ufs/ufs/ufs_quota.h	Mon Feb  7 20:30:39 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_quota.h,v 1.1.2.4 2011/01/31 15:24:10 bouyer Exp $	*/
+/*	$NetBSD: ufs_quota.h,v 1.1.2.5 2011/02/07 20:30:39 bouyer Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993, 1995
@@ -129,6 +129,7 @@
 int chkiq2(struct inode *, int32_t, kauth_cred_t, int);
 int quota2_handle_cmd_get(struct ufsmount *, int, int, int, prop_array_t);
 int quota2_handle_cmd_set(struct ufsmount *, int, int, int, prop_dictionary_t);
+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 *);
 int dq2get(struct vnode *, u_long, struct ufsmount *, int, struct dquot *);

Index: src/sys/ufs/ufs/ufs_quota2.c
diff -u src/sys/ufs/ufs/ufs_quota2.c:1.1.2.8 src/sys/ufs/ufs/ufs_quota2.c:1.1.2.9
--- src/sys/ufs/ufs/ufs_quota2.c:1.1.2.8	Mon Feb  7 16:24:13 2011
+++ src/sys/ufs/ufs/ufs_quota2.c	Mon Feb  7 20:30:39 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: ufs_quota

CVS commit: [bouyer-quota2] src/sys/ufs/ufs

2011-02-07 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Mon Feb  7 16:24:13 UTC 2011

Modified Files:
src/sys/ufs/ufs [bouyer-quota2]: ufs_quota2.c

Log Message:
Create a WAPBL transaction when setting quotas.


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.7 -r1.1.2.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_quota2.c
diff -u src/sys/ufs/ufs/ufs_quota2.c:1.1.2.7 src/sys/ufs/ufs/ufs_quota2.c:1.1.2.8
--- src/sys/ufs/ufs/ufs_quota2.c:1.1.2.7	Thu Feb  3 15:56:16 2011
+++ src/sys/ufs/ufs/ufs_quota2.c	Mon Feb  7 16:24:13 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: ufs_quota2.c,v 1.1.2.7 2011/02/03 15:56:16 bouyer Exp $ */
+/* $NetBSD: ufs_quota2.c,v 1.1.2.8 2011/02/07 16:24:13 bouyer Exp $ */
 /*-
   * Copyright (c) 2010 Manuel Bouyer
   * All rights reserved.
@@ -28,7 +28,7 @@
   */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ufs_quota2.c,v 1.1.2.7 2011/02/03 15:56:16 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_quota2.c,v 1.1.2.8 2011/02/07 16:24:13 bouyer Exp $");
 
 #include 
 #include 
@@ -502,29 +502,33 @@
 
 	if (ump->um_quotas[type] == NULLVP)
 		return ENODEV;
+	error = UFS_WAPBL_BEGIN(ump->um_mountp);
+	if (error)
+		return error;
+	
 	if (defaultq) {
 		mutex_enter(&dqlock);
 		error = getq2h(ump, type, &bp, &q2h, B_MODIFY);
 		if (error) {
 			mutex_exit(&dqlock);
-			return error;
+			goto out_wapbl;
 		}
 		quota2_ufs_rwq2e(&q2h->q2h_defentry, &q2e, needswap);
 		error = quota2_dict_update_q2e_limits(data, &q2e);
 		if (error) {
 			mutex_exit(&dqlock);
 			brelse(bp, 0);
-			return error;
+			goto out_wapbl;
 		}
 		quota2_ufs_rwq2e(&q2e, &q2h->q2h_defentry, needswap);
 		mutex_exit(&dqlock);
 		VOP_BWRITE(bp);
-		return error;
+		goto out_wapbl;
 	}
 
 	error = dqget(NULLVP, id, ump, type, &dq);
 	if (error)
-		return error;
+		goto out_wapbl;
 
 	if (dq->dq2_lblkno == 0 && dq->dq2_blkoff == 0) {
 		/* need to alloc a new on-disk quot */
@@ -537,7 +541,7 @@
 	}
 	if (error) {
 		dqrele(NULLVP, dq);
-		return error;
+		goto out_wapbl;
 	}
 	mutex_enter(&dq->dq_interlock);
 	quota2_ufs_rwq2e(q2ep, &q2e, needswap);
@@ -546,13 +550,15 @@
 		mutex_exit(&dq->dq_interlock);
 		dqrele(NULLVP, dq);
 		brelse(bp, 0);
-		return error;
+		goto out_wapbl;
 	}
 	quota2_ufs_rwq2e(&q2e, q2ep, needswap);
 	mutex_exit(&dq->dq_interlock);
 	dqrele(NULLVP, dq);
 	VOP_BWRITE(bp);
-	
+
+out_wapbl:
+	UFS_WAPBL_END(ump->um_mountp);
 	return error;
 }
 



CVS commit: [bouyer-quota2] src/sys/ufs/ufs

2011-01-31 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Mon Jan 31 21:09:54 UTC 2011

Modified Files:
src/sys/ufs/ufs [bouyer-quota2]: ufs_quota.c

Log Message:
On command with multiple data, make sure to reset 'defaultq' to 0.


To generate a diff of this commit:
cvs rdiff -u -r1.68.4.6 -r1.68.4.7 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.68.4.6 src/sys/ufs/ufs/ufs_quota.c:1.68.4.7
--- src/sys/ufs/ufs/ufs_quota.c:1.68.4.6	Mon Jan 31 15:24:10 2011
+++ src/sys/ufs/ufs/ufs_quota.c	Mon Jan 31 21:09:53 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_quota.c,v 1.68.4.6 2011/01/31 15:24:10 bouyer Exp $	*/
+/*	$NetBSD: ufs_quota.c,v 1.68.4.7 2011/01/31 21:09:53 bouyer Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993, 1995
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ufs_quota.c,v 1.68.4.6 2011/01/31 15:24:10 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_quota.c,v 1.68.4.7 2011/01/31 21:09:53 bouyer Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_quota.h"
@@ -266,6 +266,8 @@
 continue;
 			id = 0;
 			defaultq = 1;
+		} else {
+			defaultq = 0;
 		}
 		error = quota_get_auth(mp, l, id);
 		if (error == EPERM)
@@ -333,6 +335,8 @@
 continue;
 			id = 0;
 			defaultq = 1;
+		} else {
+			defaultq = 0;
 		}
 		error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_FS_QUOTA,
 		KAUTH_REQ_SYSTEM_FS_QUOTA_MANAGE, mp, KAUTH_ARG(id), NULL);



CVS commit: [bouyer-quota2] src/sys/ufs/ufs

2011-01-31 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Mon Jan 31 15:24:11 UTC 2011

Modified Files:
src/sys/ufs/ufs [bouyer-quota2]: quota1_subr.c quota2_prop.c
quota2_subr.c ufs_quota.c ufs_quota.h ufs_quota1.c ufs_quota2.c

Log Message:
Catch up with Q2V -> QL renaming
Enforce limits for quota2.
pass quota type (*QUOTA) and limit type (QL_*) to
KAUTH_REQ_SYSTEM_FS_QUOTA_NOLIMIT, to make it possible to skip
limit checks for some quota type only if a listener wants to.


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.1 -r1.1.2.2 src/sys/ufs/ufs/quota1_subr.c \
src/sys/ufs/ufs/ufs_quota1.c
cvs rdiff -u -r1.1.2.3 -r1.1.2.4 src/sys/ufs/ufs/quota2_prop.c \
src/sys/ufs/ufs/quota2_subr.c src/sys/ufs/ufs/ufs_quota.h
cvs rdiff -u -r1.68.4.5 -r1.68.4.6 src/sys/ufs/ufs/ufs_quota.c
cvs rdiff -u -r1.1.2.5 -r1.1.2.6 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/quota1_subr.c
diff -u src/sys/ufs/ufs/quota1_subr.c:1.1.2.1 src/sys/ufs/ufs/quota1_subr.c:1.1.2.2
--- src/sys/ufs/ufs/quota1_subr.c:1.1.2.1	Fri Jan 28 23:31:16 2011
+++ src/sys/ufs/ufs/quota1_subr.c	Mon Jan 31 15:24:10 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: quota1_subr.c,v 1.1.2.1 2011/01/28 23:31:16 bouyer Exp $ */
+/* $NetBSD: quota1_subr.c,v 1.1.2.2 2011/01/31 15:24:10 bouyer Exp $ */
 /*-
   * Copyright (c) 2010 Manuel Bouyer
   * All rights reserved.
@@ -28,7 +28,7 @@
   */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: quota1_subr.c,v 1.1.2.1 2011/01/28 23:31:16 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: quota1_subr.c,v 1.1.2.2 2011/01/31 15:24:10 bouyer Exp $");
 
 #include 
 #include 
@@ -61,35 +61,35 @@
 void
 dqblk2q2e(const struct dqblk *dqblk, struct quota2_entry *q2e)
 {
-	q2e->q2e_val[Q2V_BLOCK].q2v_hardlimit =
+	q2e->q2e_val[QL_BLOCK].q2v_hardlimit =
 	dqblk2q2e_limit(dqblk->dqb_bhardlimit);
-	q2e->q2e_val[Q2V_BLOCK].q2v_softlimit =
+	q2e->q2e_val[QL_BLOCK].q2v_softlimit =
 	dqblk2q2e_limit(dqblk->dqb_bsoftlimit);
-	q2e->q2e_val[Q2V_BLOCK].q2v_cur   = dqblk->dqb_curblocks;
-	q2e->q2e_val[Q2V_BLOCK].q2v_time  = dqblk->dqb_btime;
+	q2e->q2e_val[QL_BLOCK].q2v_cur   = dqblk->dqb_curblocks;
+	q2e->q2e_val[QL_BLOCK].q2v_time  = dqblk->dqb_btime;
 
-	q2e->q2e_val[Q2V_FILE].q2v_hardlimit =
+	q2e->q2e_val[QL_FILE].q2v_hardlimit =
 	dqblk2q2e_limit(dqblk->dqb_ihardlimit);
-	q2e->q2e_val[Q2V_FILE].q2v_softlimit =
+	q2e->q2e_val[QL_FILE].q2v_softlimit =
 	dqblk2q2e_limit(dqblk->dqb_isoftlimit);
-	q2e->q2e_val[Q2V_FILE].q2v_cur   = dqblk->dqb_curinodes;
-	q2e->q2e_val[Q2V_FILE].q2v_time  = dqblk->dqb_itime;
+	q2e->q2e_val[QL_FILE].q2v_cur   = dqblk->dqb_curinodes;
+	q2e->q2e_val[QL_FILE].q2v_time  = dqblk->dqb_itime;
 }
 
 void
 q2e2dqblk(const struct quota2_entry *q2e, struct dqblk *dqblk)
 {
 	dqblk->dqb_bhardlimit =
-	q2e2dqblk_limit(q2e->q2e_val[Q2V_BLOCK].q2v_hardlimit);
+	q2e2dqblk_limit(q2e->q2e_val[QL_BLOCK].q2v_hardlimit);
 	dqblk->dqb_bsoftlimit =
-	q2e2dqblk_limit(q2e->q2e_val[Q2V_BLOCK].q2v_softlimit);
-	dqblk->dqb_curblocks  = q2e->q2e_val[Q2V_BLOCK].q2v_cur;
-	dqblk->dqb_btime  = q2e->q2e_val[Q2V_BLOCK].q2v_time;
+	q2e2dqblk_limit(q2e->q2e_val[QL_BLOCK].q2v_softlimit);
+	dqblk->dqb_curblocks  = q2e->q2e_val[QL_BLOCK].q2v_cur;
+	dqblk->dqb_btime  = q2e->q2e_val[QL_BLOCK].q2v_time;
 
 	dqblk->dqb_ihardlimit =
-	q2e2dqblk_limit(q2e->q2e_val[Q2V_FILE].q2v_hardlimit);
+	q2e2dqblk_limit(q2e->q2e_val[QL_FILE].q2v_hardlimit);
 	dqblk->dqb_isoftlimit =
-	q2e2dqblk_limit(q2e->q2e_val[Q2V_FILE].q2v_softlimit);
-	dqblk->dqb_curinodes  = q2e->q2e_val[Q2V_FILE].q2v_cur;
-	dqblk->dqb_itime  = q2e->q2e_val[Q2V_FILE].q2v_time;
+	q2e2dqblk_limit(q2e->q2e_val[QL_FILE].q2v_softlimit);
+	dqblk->dqb_curinodes  = q2e->q2e_val[QL_FILE].q2v_cur;
+	dqblk->dqb_itime  = q2e->q2e_val[QL_FILE].q2v_time;
 }
Index: src/sys/ufs/ufs/ufs_quota1.c
diff -u src/sys/ufs/ufs/ufs_quota1.c:1.1.2.1 src/sys/ufs/ufs/ufs_quota1.c:1.1.2.2
--- src/sys/ufs/ufs/ufs_quota1.c:1.1.2.1	Thu Jan 20 14:25:03 2011
+++ src/sys/ufs/ufs/ufs_quota1.c	Mon Jan 31 15:24:10 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_quota1.c,v 1.1.2.1 2011/01/20 14:25:03 bouyer Exp $	*/
+/*	$NetBSD: ufs_quota1.c,v 1.1.2.2 2011/01/31 15:24:10 bouyer Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993, 1995
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ufs_quota1.c,v 1.1.2.1 2011/01/20 14:25:03 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_quota1.c,v 1.1.2.2 2011/01/31 15:24:10 bouyer Exp $");
 
 #include 
 #include 
@@ -88,12 +88,13 @@
 		}
 		return (0);
 	}
-	if ((flags & FORCE) == 0 &&
-	kauth_authorize_system(cred, KAUTH_SYSTEM_FS_QUOTA,
-	KAUTH_REQ_SYSTEM_FS_QUOTA_NOLIMIT, NULL, NULL, NULL) != 0) {
-		for (i = 0; i < MAXQUOTAS; i++) {
-			if ((dq = ip->i_dquot[i]) == NODQUOT)
-continue;
+	for (i = 0; i < MAXQUOTAS; i++) {
+		if ((

CVS commit: [bouyer-quota2] src/sys/ufs/ufs

2011-01-31 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Mon Jan 31 15:19:21 UTC 2011

Modified Files:
src/sys/ufs/ufs [bouyer-quota2]: quota.h quota2.h

Log Message:
Rename defininition for limits Q2V_* to QL_* and move from quota2.h to quota.h.


To generate a diff of this commit:
cvs rdiff -u -r1.25.64.1 -r1.25.64.2 src/sys/ufs/ufs/quota.h
cvs rdiff -u -r1.1.2.4 -r1.1.2.5 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/quota.h
diff -u src/sys/ufs/ufs/quota.h:1.25.64.1 src/sys/ufs/ufs/quota.h:1.25.64.2
--- src/sys/ufs/ufs/quota.h:1.25.64.1	Thu Jan 20 14:25:03 2011
+++ src/sys/ufs/ufs/quota.h	Mon Jan 31 15:19:21 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: quota.h,v 1.25.64.1 2011/01/20 14:25:03 bouyer Exp $	*/
+/*	$NetBSD: quota.h,v 1.25.64.2 2011/01/31 15:19:21 bouyer Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1993
@@ -54,13 +54,23 @@
 #define	GRPQUOTA	1	/* element used for group quotas */
 
 /*
- * Definitions for the default names of the quotas files.
+ * Definitions for the default names of the quotas files/quota types.
  */
 #define INITQFNAMES { \
 	"user",		/* USRQUOTA */ \
 	"group",	/* GRPQUOTA */ \
 	"undefined", \
 }
+
+/* definition of limits types for each quota */
+#define QL_BLOCK 0
+#define QL_FILE  1
+#define N_QL 2
+
+#define INITQLNAMES  {"block", "file", "undefined" }
+
+
+
 #ifdef _KERNEL
 
 #include 

Index: src/sys/ufs/ufs/quota2.h
diff -u src/sys/ufs/ufs/quota2.h:1.1.2.4 src/sys/ufs/ufs/quota2.h:1.1.2.5
--- src/sys/ufs/ufs/quota2.h:1.1.2.4	Sat Jan 29 23:22:00 2011
+++ src/sys/ufs/ufs/quota2.h	Mon Jan 31 15:19:21 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: quota2.h,v 1.1.2.4 2011/01/29 23:22:00 bouyer Exp $ */
+/* $NetBSD: quota2.h,v 1.1.2.5 2011/01/31 15:19:21 bouyer Exp $ */
 /*-
   * Copyright (c) 2010 Manuel Bouyer
   * All rights reserved.
@@ -55,11 +55,6 @@
 	int64_t q2v_time; /* grace expiration date for softlimit overflow */
 	int64_t q2v_grace; /* allowed time for softlimit overflow */
 };
-#define Q2V_BLOCK 0
-#define Q2V_FILE  1
-#define NQ2V  2
-
-#define QUOTA2_VALNAMES_INIT {"block", "file"}
 
 /*
  * Description of a user or group quota
@@ -69,7 +64,7 @@
 
 struct quota2_entry {
 	/* block & inode limits and status */
-	struct quota2_val q2e_val[NQ2V];
+	struct quota2_val q2e_val[N_QL];
 	/* pointer to next entry for this list (offset in the file) */
 	uint64_t q2e_next;
 	/* ownerchip information */



CVS commit: [bouyer-quota2] src/sys/ufs/ufs

2011-01-29 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Sun Jan 30 00:25:20 UTC 2011

Modified Files:
src/sys/ufs/ufs [bouyer-quota2]: quota2_prop.c quota2_prop.h
ufs_quota.c ufs_quota.h ufs_quota2.c

Log Message:
Implement 'set' command for quota2.


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.2 -r1.1.2.3 src/sys/ufs/ufs/quota2_prop.c \
src/sys/ufs/ufs/quota2_prop.h src/sys/ufs/ufs/ufs_quota.h
cvs rdiff -u -r1.68.4.3 -r1.68.4.4 src/sys/ufs/ufs/ufs_quota.c
cvs rdiff -u -r1.1.2.4 -r1.1.2.5 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_prop.c
diff -u src/sys/ufs/ufs/quota2_prop.c:1.1.2.2 src/sys/ufs/ufs/quota2_prop.c:1.1.2.3
--- src/sys/ufs/ufs/quota2_prop.c:1.1.2.2	Fri Jan 21 16:58:06 2011
+++ src/sys/ufs/ufs/quota2_prop.c	Sun Jan 30 00:25:19 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: quota2_prop.c,v 1.1.2.2 2011/01/21 16:58:06 bouyer Exp $ */
+/* $NetBSD: quota2_prop.c,v 1.1.2.3 2011/01/30 00:25:19 bouyer Exp $ */
 /*-
   * Copyright (c) 2010 Manuel Bouyer
   * All rights reserved.
@@ -72,6 +72,22 @@
 }
 
 int
+quota2_dict_update_q2e_limits(prop_dictionary_t data, struct quota2_entry *q2e)
+{
+	int i, error;
+	prop_dictionary_t val;
+	for (i = 0; i < NQ2V; i++) {
+		val = prop_dictionary_get_dict(data, quota2_valnames[i]);
+		if (val == NULL)
+			continue;
+		error = quota2_dict_get_q2v_limits(val, &q2e->q2e_val[i], 1);
+		if (error)
+			return error;
+	}
+	return 0;
+}
+
+int
 quota2_dict_get_q2v_usage(prop_dictionary_t dict, struct quota2_val *q2v)
 {
 	uint64_t vu;
Index: src/sys/ufs/ufs/quota2_prop.h
diff -u src/sys/ufs/ufs/quota2_prop.h:1.1.2.2 src/sys/ufs/ufs/quota2_prop.h:1.1.2.3
--- src/sys/ufs/ufs/quota2_prop.h:1.1.2.2	Fri Jan 21 16:58:06 2011
+++ src/sys/ufs/ufs/quota2_prop.h	Sun Jan 30 00:25:19 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: quota2_prop.h,v 1.1.2.2 2011/01/21 16:58:06 bouyer Exp $ */
+/* $NetBSD: quota2_prop.h,v 1.1.2.3 2011/01/30 00:25:19 bouyer Exp $ */
 /*-
   * Copyright (c) 2010 Manuel Bouyer
   * All rights reserved.
@@ -32,6 +32,7 @@
 
 prop_dictionary_t prop_dictionary_get_dict(prop_dictionary_t, const char *);
 int quota2_dict_get_q2v_limits(prop_dictionary_t, struct quota2_val *, bool);
+int quota2_dict_update_q2e_limits(prop_dictionary_t, struct quota2_entry *);
 int quota2_dict_get_q2v_usage(prop_dictionary_t, struct quota2_val *);
 int quota2_dict_get_q2e_usage(prop_dictionary_t, struct quota2_entry *);
 int quota2_get_cmds(prop_dictionary_t, prop_array_t *);
Index: src/sys/ufs/ufs/ufs_quota.h
diff -u src/sys/ufs/ufs/ufs_quota.h:1.1.2.2 src/sys/ufs/ufs/ufs_quota.h:1.1.2.3
--- src/sys/ufs/ufs/ufs_quota.h:1.1.2.2	Fri Jan 21 16:58:06 2011
+++ src/sys/ufs/ufs/ufs_quota.h	Sun Jan 30 00:25:20 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_quota.h,v 1.1.2.2 2011/01/21 16:58:06 bouyer Exp $	*/
+/*	$NetBSD: ufs_quota.h,v 1.1.2.3 2011/01/30 00:25:20 bouyer Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993, 1995
@@ -128,8 +128,8 @@
 
 int chkdq2(struct inode *, int64_t, kauth_cred_t, int);
 int chkiq2(struct inode *, int32_t, kauth_cred_t, int);
-int quota2_handle_cmd_get(struct ufsmount *, int, int, int,
-prop_array_t);
+int quota2_handle_cmd_get(struct ufsmount *, int, int, int, prop_array_t);
+int quota2_handle_cmd_set(struct ufsmount *, int, int, int, prop_dictionary_t);
 int quota2_handle_cmd_getall(struct ufsmount *, int, prop_array_t);
 int q2sync(struct mount *);
 int dq2get(struct vnode *, u_long, struct ufsmount *, int, struct dquot *);

Index: src/sys/ufs/ufs/ufs_quota.c
diff -u src/sys/ufs/ufs/ufs_quota.c:1.68.4.3 src/sys/ufs/ufs/ufs_quota.c:1.68.4.4
--- src/sys/ufs/ufs/ufs_quota.c:1.68.4.3	Sat Jan 29 23:22:00 2011
+++ src/sys/ufs/ufs/ufs_quota.c	Sun Jan 30 00:25:19 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_quota.c,v 1.68.4.3 2011/01/29 23:22:00 bouyer Exp $	*/
+/*	$NetBSD: ufs_quota.c,v 1.68.4.4 2011/01/30 00:25:19 bouyer Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993, 1995
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ufs_quota.c,v 1.68.4.3 2011/01/29 23:22:00 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_quota.c,v 1.68.4.4 2011/01/30 00:25:19 bouyer Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_quota.h"
@@ -62,6 +62,8 @@
 
 static int quota_handle_cmd_get(struct mount *, struct lwp *,
 prop_dictionary_t, int, prop_array_t);
+static int quota_handle_cmd_set(struct mount *, struct lwp *,
+prop_dictionary_t, int, prop_array_t);
 static int quota_handle_cmd_getall(struct mount *, struct lwp *,
 prop_dictionary_t, int, prop_array_t);
 /*
@@ -153,6 +155,10 @@
 		error = quota_handle_cmd_get(mp, l, cmddict, q2type, datas);
 		goto end;
 	}
+	if (strcmp(cmd, "set") == 0) {
+		error = quota_handle_cmd_set(mp, l, cmddict, q2type, datas);
+		goto end;
+	}
 	if (strcmp(cmd, "getall") == 0) {
 		error = quota_handle_cmd_getall(mp, l, cmddict, q2type, datas);
 		goto end;
@@

CVS commit: [bouyer-quota2] src/sys/ufs/ufs

2011-01-29 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Sat Jan 29 23:22:00 UTC 2011

Modified Files:
src/sys/ufs/ufs [bouyer-quota2]: quota2.h ufs_quota.c ufs_quota2.c

Log Message:
Describe how the on-disk structures are protected from concurent access,
and try to implement it.


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.3 -r1.1.2.4 src/sys/ufs/ufs/quota2.h \
src/sys/ufs/ufs/ufs_quota2.c
cvs rdiff -u -r1.68.4.2 -r1.68.4.3 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/quota2.h
diff -u src/sys/ufs/ufs/quota2.h:1.1.2.3 src/sys/ufs/ufs/quota2.h:1.1.2.4
--- src/sys/ufs/ufs/quota2.h:1.1.2.3	Fri Jan 28 18:36:06 2011
+++ src/sys/ufs/ufs/quota2.h	Sat Jan 29 23:22:00 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: quota2.h,v 1.1.2.3 2011/01/28 18:36:06 bouyer Exp $ */
+/* $NetBSD: quota2.h,v 1.1.2.4 2011/01/29 23:22:00 bouyer Exp $ */
 /*-
   * Copyright (c) 2010 Manuel Bouyer
   * All rights reserved.
@@ -41,6 +41,12 @@
  * superblock
  */
 
+/*
+ * The quota file is comprised of 2 parts, the header and the entries.
+ * The header contains global informations, and head of list of quota entries.
+ * A quota entry can either be in the free list, or one of the hash lists.
+ */
+
 /* description of a block or inode quota */
 struct quota2_val {
 	uint64_t q2v_hardlimit; /* absolute limit */
Index: src/sys/ufs/ufs/ufs_quota2.c
diff -u src/sys/ufs/ufs/ufs_quota2.c:1.1.2.3 src/sys/ufs/ufs/ufs_quota2.c:1.1.2.4
--- src/sys/ufs/ufs/ufs_quota2.c:1.1.2.3	Fri Jan 28 18:36:06 2011
+++ src/sys/ufs/ufs/ufs_quota2.c	Sat Jan 29 23:22:00 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: ufs_quota2.c,v 1.1.2.3 2011/01/28 18:36:06 bouyer Exp $ */
+/* $NetBSD: ufs_quota2.c,v 1.1.2.4 2011/01/29 23:22:00 bouyer Exp $ */
 /*-
   * Copyright (c) 2010 Manuel Bouyer
   * All rights reserved.
@@ -28,12 +28,13 @@
   */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ufs_quota2.c,v 1.1.2.3 2011/01/28 18:36:06 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_quota2.c,v 1.1.2.4 2011/01/29 23:22:00 bouyer Exp $");
 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -52,6 +53,16 @@
 #include 
 #include 
 
+/*
+ * LOCKING:
+ * Data in the entries are protected by the associated struct dquot's
+ * dq_interlock (this means we can't read or change a quota entry without
+ * grabing a dquot for it).
+ * The header and lists (including pointers in the data entries, and q2e_uid)
+ * are protected by the global dqlock.
+ * the locking order is dq_interlock -> dqlock
+ */
+
 static int getinoquota2(struct inode *, int, struct buf **,
 struct quota2_entry **);
 static int getq2h(struct ufsmount *, int, struct buf **,
@@ -71,6 +82,7 @@
 	struct buf *bp;
 	struct quota2_header *q2h;
 
+	KASSERT(mutex_owned(&dqlock));
 	error = bread(ump->um_quotas[type], 0, ump->umq2_bsize,
 	ump->um_cred[type], flags, &bp);
 	if (error)
@@ -214,6 +226,7 @@
 	u_long hash_mask;
 	const int needswap = UFS_MPNEEDSWAP(ump);
 
+	KASSERT(mutex_owned(&dqlock));
 	error = getq2h(ump, type, &hbp, &q2h, B_MODIFY);
 	if (error)
 		return error;
@@ -318,8 +331,10 @@
 continue;
 			}
 			/* need to alloc a new on-disk quot */
+			mutex_enter(&dqlock);
 			error = quota2_q2ealloc(ump, i, ino_ids[i], dq,
 			&bpp[i], &q2ep[i]);
+			mutex_exit(&dqlock);
 			if (error)
 return error;
 		} else {
@@ -394,14 +409,51 @@
 	return quota2_check(ip, Q2V_FILE, change, cred, flags);
 }
 
+static int
+quota2_array_add_q2e(struct ufsmount *ump, int type,
+int id, prop_array_t replies)
+{
+	struct dquot *dq;
+	int error;
+	struct quota2_entry *q2ep, q2e;
+	struct buf  *bp;
+	const int needswap = UFS_MPNEEDSWAP(ump);
+	prop_dictionary_t dict;
+
+	error = dqget(NULLVP, id, ump, type, &dq);
+	if (error)
+		return error;
+
+	if (dq->dq2_lblkno == 0 && dq->dq2_blkoff == 0) {
+		dqrele(NULLVP, dq);
+		return ENOENT;
+	}
+	error = getq2e(ump, type, dq->dq2_lblkno, dq->dq2_blkoff,
+	&bp, &q2ep, 0);
+	if (error) {
+		dqrele(NULLVP, dq);
+		return error;
+	}
+	mutex_enter(&dq->dq_interlock);
+	quota2_ufs_rwq2e(q2ep, &q2e, needswap);
+	mutex_exit(&dq->dq_interlock);
+	dqrele(NULLVP, dq);
+	brelse(bp, 0);
+	dict = q2etoprop(&q2e, 0);
+	if (dict == NULL)
+		return ENOMEM;
+	if (!prop_array_add_and_rel(replies, dict))
+		return ENOMEM;
+	return 0;
+}
+
 int
 quota2_handle_cmd_get(struct ufsmount *ump, int type, int id,
 int defaultq, prop_array_t replies)
 {
-	struct dquot *dq;
 	int error;
 	struct quota2_header *q2h;
-	struct quota2_entry *q2ep, q2e;
+	struct quota2_entry q2e;
 	struct buf *bp;
 	prop_dictionary_t dict;
 	const int needswap = UFS_MPNEEDSWAP(ump);
@@ -415,53 +467,46 @@
 			mutex_exit(&dqlock);
 			return error;
 		}
-		q2ep = &q2h->q2h_defentry;
-	} else {
-		error = dqget(NULLVP, id, ump, type, &dq);
-
-		if (error)
-			return error;
-
-		if (dq->dq2_lblkno == 0 && dq->dq2_blkoff == 0) {
-			dqrele(NULL

CVS commit: [bouyer-quota2] src/sys/ufs/ufs

2011-01-28 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Fri Jan 28 23:31:16 UTC 2011

Modified Files:
src/sys/ufs/ufs [bouyer-quota2]: quota1.h
Added Files:
src/sys/ufs/ufs [bouyer-quota2]: quota1_subr.c

Log Message:
Add conversion functions between old and new format.


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.1 -r1.1.2.2 src/sys/ufs/ufs/quota1.h
cvs rdiff -u -r0 -r1.1.2.1 src/sys/ufs/ufs/quota1_subr.c

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

Modified files:

Index: src/sys/ufs/ufs/quota1.h
diff -u src/sys/ufs/ufs/quota1.h:1.1.2.1 src/sys/ufs/ufs/quota1.h:1.1.2.2
--- src/sys/ufs/ufs/quota1.h:1.1.2.1	Thu Jan 20 14:25:03 2011
+++ src/sys/ufs/ufs/quota1.h	Fri Jan 28 23:31:16 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: quota1.h,v 1.1.2.1 2011/01/20 14:25:03 bouyer Exp $	*/
+/*	$NetBSD: quota1.h,v 1.1.2.2 2011/01/28 23:31:16 bouyer Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1993
@@ -92,4 +92,8 @@
 	int32_t	  dqb_itime;		/* time limit for excessive files */
 };
 
+/* quota1_subr.c */
+void dqblk2q2e(const struct dqblk *, struct quota2_entry *);
+void q2e2dqblk(const struct quota2_entry *, struct dqblk *);
+
 #endif /* !_UFS_UFS_QUOTA1_H_ */

Added files:

Index: src/sys/ufs/ufs/quota1_subr.c
diff -u /dev/null src/sys/ufs/ufs/quota1_subr.c:1.1.2.1
--- /dev/null	Fri Jan 28 23:31:16 2011
+++ src/sys/ufs/ufs/quota1_subr.c	Fri Jan 28 23:31:16 2011
@@ -0,0 +1,95 @@
+/* $NetBSD: quota1_subr.c,v 1.1.2.1 2011/01/28 23:31:16 bouyer Exp $ */
+/*-
+  * Copyright (c) 2010 Manuel Bouyer
+  * All rights reserved.
+  * This software is distributed under the following condiions
+  * compliant with the NetBSD foundation policy.
+  *
+  * Redistribution and use in source and binary forms, with or without
+  * modification, are permitted provided that the following conditions
+  * are met:
+  * 1. Redistributions of source code must retain the above copyright
+  *notice, this list of conditions and the following disclaimer.
+  * 2. Redistributions in binary form must reproduce the above copyright
+  *notice, this list of conditions and the following disclaimer in the
+  *documentation and/or other materials provided with the distribution.
+  *
+  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+  * POSSIBILITY OF SUCH DAMAGE.
+  */
+
+#include 
+__KERNEL_RCSID(0, "$NetBSD: quota1_subr.c,v 1.1.2.1 2011/01/28 23:31:16 bouyer Exp $");
+
+#include 
+#include 
+
+#include 
+#include 
+
+static uint64_t
+dqblk2q2e_limit(uint32_t lim)
+{
+	if (lim == 0)
+		return UQUAD_MAX;
+	else if (lim == 1)
+		return 0;
+	else
+		return lim;
+}
+
+static uint32_t
+q2e2dqblk_limit(uint64_t lim)
+{
+	if (lim == UQUAD_MAX)
+		return 0;
+	else if (lim == 0)
+		return 1;
+	else
+		return lim;
+}
+
+void
+dqblk2q2e(const struct dqblk *dqblk, struct quota2_entry *q2e)
+{
+	q2e->q2e_val[Q2V_BLOCK].q2v_hardlimit =
+	dqblk2q2e_limit(dqblk->dqb_bhardlimit);
+	q2e->q2e_val[Q2V_BLOCK].q2v_softlimit =
+	dqblk2q2e_limit(dqblk->dqb_bsoftlimit);
+	q2e->q2e_val[Q2V_BLOCK].q2v_cur   = dqblk->dqb_curblocks;
+	q2e->q2e_val[Q2V_BLOCK].q2v_time  = dqblk->dqb_btime;
+
+	q2e->q2e_val[Q2V_FILE].q2v_hardlimit =
+	dqblk2q2e_limit(dqblk->dqb_ihardlimit);
+	q2e->q2e_val[Q2V_FILE].q2v_softlimit =
+	dqblk2q2e_limit(dqblk->dqb_isoftlimit);
+	q2e->q2e_val[Q2V_FILE].q2v_cur   = dqblk->dqb_curinodes;
+	q2e->q2e_val[Q2V_FILE].q2v_time  = dqblk->dqb_itime;
+}
+
+void
+q2e2dqblk(const struct quota2_entry *q2e, struct dqblk *dqblk)
+{
+	dqblk->dqb_bhardlimit =
+	q2e2dqblk_limit(q2e->q2e_val[Q2V_BLOCK].q2v_hardlimit);
+	dqblk->dqb_bsoftlimit =
+	q2e2dqblk_limit(q2e->q2e_val[Q2V_BLOCK].q2v_softlimit);
+	dqblk->dqb_curblocks  = q2e->q2e_val[Q2V_BLOCK].q2v_cur;
+	dqblk->dqb_btime  = q2e->q2e_val[Q2V_BLOCK].q2v_time;
+
+	dqblk->dqb_ihardlimit =
+	q2e2dqblk_limit(q2e->q2e_val[Q2V_FILE].q2v_hardlimit);
+	dqblk->dqb_isoftlimit =
+	q2e2dqblk_limit(q2e->q2e_val[Q2V_FILE].q2v_softlimit);
+	dqblk->dqb_curinodes  = q2e->q2e_val[Q2V_FILE].q2v_cur;
+	dqblk->dqb_itime  = q2e->q2e_val[Q2V_FILE].q2v_time;
+}



CVS commit: [bouyer-quota2] src/sys/ufs/ufs

2011-01-28 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Fri Jan 28 23:30:35 UTC 2011

Modified Files:
src/sys/ufs/ufs [bouyer-quota2]: quota2_subr.c

Log Message:
Add RCSID


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.2 -r1.1.2.3 src/sys/ufs/ufs/quota2_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/ufs/quota2_subr.c
diff -u src/sys/ufs/ufs/quota2_subr.c:1.1.2.2 src/sys/ufs/ufs/quota2_subr.c:1.1.2.3
--- src/sys/ufs/ufs/quota2_subr.c:1.1.2.2	Fri Jan 28 18:36:06 2011
+++ src/sys/ufs/ufs/quota2_subr.c	Fri Jan 28 23:30:34 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: quota2_subr.c,v 1.1.2.2 2011/01/28 18:36:06 bouyer Exp $ */
+/* $NetBSD: quota2_subr.c,v 1.1.2.3 2011/01/28 23:30:34 bouyer Exp $ */
 /*-
   * Copyright (c) 2010 Manuel Bouyer
   * All rights reserved.
@@ -27,6 +27,9 @@
   * POSSIBILITY OF SUCH DAMAGE.
   */
 
+#include 
+__KERNEL_RCSID(0, "$NetBSD: quota2_subr.c,v 1.1.2.3 2011/01/28 23:30:34 bouyer Exp $");
+
 #include 
 #include 
 



CVS commit: [bouyer-quota2] src/sys/ufs/ufs

2011-01-28 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Fri Jan 28 18:36:06 UTC 2011

Modified Files:
src/sys/ufs/ufs [bouyer-quota2]: quota2.h quota2_subr.c ufs_quota2.c

Log Message:
Introduce quota2_ufs_rwq2v() and quota2_ufs_rwq2e() functions, which
byteswap a quota2_val or quota2_entry if needed.
Use this to get quota2_entry in host order before calling q2etoprop().

quota2_walk_list() will byteswap the offset if needed to leave
it in FS byte order in callers.


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.2 -r1.1.2.3 src/sys/ufs/ufs/quota2.h \
src/sys/ufs/ufs/ufs_quota2.c
cvs rdiff -u -r1.1.2.1 -r1.1.2.2 src/sys/ufs/ufs/quota2_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/ufs/quota2.h
diff -u src/sys/ufs/ufs/quota2.h:1.1.2.2 src/sys/ufs/ufs/quota2.h:1.1.2.3
--- src/sys/ufs/ufs/quota2.h:1.1.2.2	Fri Jan 21 16:58:06 2011
+++ src/sys/ufs/ufs/quota2.h	Fri Jan 28 18:36:06 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: quota2.h,v 1.1.2.2 2011/01/21 16:58:06 bouyer Exp $ */
+/* $NetBSD: quota2.h,v 1.1.2.3 2011/01/28 18:36:06 bouyer Exp $ */
 /*-
   * Copyright (c) 2010 Manuel Bouyer
   * All rights reserved.
@@ -97,4 +97,6 @@
 /* quota2_subr.c */
 void quota2_addfreeq2e(struct quota2_header *, void *, uint64_t, uint64_t, int);
 void quota2_create_blk0(uint64_t, void *bp, int, int, int);
+void quota2_ufs_rwq2v(const struct quota2_val *, struct quota2_val *, int);
+void quota2_ufs_rwq2e(const struct quota2_entry *, struct quota2_entry *, int);
 #endif /*  _UFS_UFS_QUOTA2_H_ */
Index: src/sys/ufs/ufs/ufs_quota2.c
diff -u src/sys/ufs/ufs/ufs_quota2.c:1.1.2.2 src/sys/ufs/ufs/ufs_quota2.c:1.1.2.3
--- src/sys/ufs/ufs/ufs_quota2.c:1.1.2.2	Fri Jan 21 16:58:06 2011
+++ src/sys/ufs/ufs/ufs_quota2.c	Fri Jan 28 18:36:06 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: ufs_quota2.c,v 1.1.2.2 2011/01/21 16:58:06 bouyer Exp $ */
+/* $NetBSD: ufs_quota2.c,v 1.1.2.3 2011/01/28 18:36:06 bouyer Exp $ */
 /*-
   * Copyright (c) 2010 Manuel Bouyer
   * All rights reserved.
@@ -28,7 +28,7 @@
   */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ufs_quota2.c,v 1.1.2.2 2011/01/21 16:58:06 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_quota2.c,v 1.1.2.3 2011/01/28 18:36:06 bouyer Exp $");
 
 #include 
 #include 
@@ -401,9 +401,10 @@
 	struct dquot *dq;
 	int error;
 	struct quota2_header *q2h;
-	struct quota2_entry *q2e;
+	struct quota2_entry *q2ep, q2e;
 	struct buf *bp;
 	prop_dictionary_t dict;
+	const int needswap = UFS_MPNEEDSWAP(ump);
 
 	if (ump->um_quotas[type] == NULLVP)
 		return ENODEV;
@@ -414,7 +415,7 @@
 			mutex_exit(&dqlock);
 			return error;
 		}
-		q2e = &q2h->q2h_defentry;
+		q2ep = &q2h->q2h_defentry;
 	} else {
 		error = dqget(NULLVP, id, ump, type, &dq);
 
@@ -426,11 +427,12 @@
 			return ENOENT;
 		}
 		error = getq2e(ump, type, dq->dq2_lblkno, dq->dq2_blkoff,
-		&bp, &q2e, 0);
+		&bp, &q2ep, 0);
 		if (error)
 			return error;
 	}
-	dict = q2etoprop(q2e, defaultq);
+	quota2_ufs_rwq2e(q2ep, &q2e, needswap);
+	dict = q2etoprop(&q2e, defaultq);
 	if (defaultq)
 		mutex_exit(&dqlock);
 	else
@@ -448,12 +450,15 @@
 
 static int
 quota2_getall_callback(struct ufsmount *ump, uint64_t *offp,
-struct quota2_entry *q2e, uint64_t off, void *v)
+struct quota2_entry *q2ep, uint64_t off, void *v)
 {
 	prop_array_t replies = v;
 	prop_dictionary_t dict;
+	const int needswap = UFS_MPNEEDSWAP(ump);
+	struct quota2_entry q2e;
 
-	dict = q2etoprop(q2e, 0);	
+	quota2_ufs_rwq2e(q2ep, &q2e, needswap);
+	dict = q2etoprop(&q2e, 0);	
 	if (!prop_array_add_and_rel(replies, dict)) {
 		return ENOMEM;
 	}
@@ -465,6 +470,7 @@
 {
 	int error;
 	struct quota2_header *q2h;
+	struct quota2_entry q2e;
 	struct buf *hbp;
 	prop_dictionary_t dict;
 	uint64_t offset;
@@ -477,14 +483,15 @@
 	error = getq2h(ump, type, &hbp, &q2h, 0);
 	if (error)
 		return error;
-	dict = q2etoprop(&q2h->q2h_defentry, 1);
+	quota2_ufs_rwq2e(&q2h->q2h_defentry, &q2e, needswap);
+	dict = q2etoprop(&q2e, 1);
 	if (!prop_array_add_and_rel(replies, dict)) {
 		brelse(hbp, 0);
 		return ENOMEM;
 	}
 	quota2_hash_size = ufs_rw16(q2h->q2h_hash_size, needswap);
 	for (i = 0; i < quota2_hash_size ; i++) {
-		offset = ufs_rw64(q2h->q2h_entries[i], needswap);
+		offset = q2h->q2h_entries[i], needswap;
 		error = quota2_walk_list(ump, hbp, type, &offset, 0, replies,
 		quota2_getall_callback);
 		if (error)
@@ -533,7 +540,6 @@
 	int error;
 	daddr_t offset;
 	u_long hash_mask;
-	const int needswap = UFS_MPNEEDSWAP(ump);
 	struct dq2get_callback c = {
 		.id = id,
 		.dq = dq
@@ -545,7 +551,7 @@
 		goto out_mutex;
 	/* look for our entry */
 	hash_mask = ((1 << q2h->q2h_hash_shift) - 1);
-	offset = ufs_rw64(q2h->q2h_entries[id & hash_mask], needswap);
+	offset = q2h->q2h_entries[id & hash_mask];
 	error = quota2_walk_list(ump, bp, type, &offset, 0, (void *)&c,
 	dq2get_callback);
 	brelse(bp, 0);

Index: src/sys/ufs/ufs/quota2_subr.c
diff -u src/sys/