Module Name: src
Committed By: hannken
Date: Mon Mar 17 09:31:35 UTC 2014
Modified Files:
src/sys/ufs/ufs: ufs_quota1.c
Log Message:
Change quota1_handle_cmd_quotaon() and q1sync() to use vfs_vnode_iterator.
To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 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.18 src/sys/ufs/ufs/ufs_quota1.c:1.19
--- src/sys/ufs/ufs/ufs_quota1.c:1.18 Thu Feb 2 03:00:48 2012
+++ src/sys/ufs/ufs/ufs_quota1.c Mon Mar 17 09:31:35 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: ufs_quota1.c,v 1.18 2012/02/02 03:00:48 matt Exp $ */
+/* $NetBSD: ufs_quota1.c,v 1.19 2014/03/17 09:31:35 hannken 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.18 2012/02/02 03:00:48 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_quota1.c,v 1.19 2014/03/17 09:31:35 hannken Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
@@ -304,7 +304,8 @@ quota1_handle_cmd_quotaon(struct lwp *l,
const char *fname)
{
struct mount *mp = ump->um_mountp;
- struct vnode *vp, **vpp, *mvp;
+ struct vnode *vp, **vpp;
+ struct vnode_iterator *marker;
struct dquot *dq;
int error;
struct pathbuf *pb;
@@ -366,41 +367,33 @@ quota1_handle_cmd_quotaon(struct lwp *l,
ump->umq1_itime[type] = dq->dq_itime;
dqrele(NULLVP, dq);
}
- /* Allocate a marker vnode. */
- mvp = vnalloc(mp);
/*
* Search vnodes associated with this mount point,
* adding references to quota file being opened.
* NB: only need to add dquot's for inodes being modified.
*/
- mutex_enter(&mntvnode_lock);
-again:
- for (vp = TAILQ_FIRST(&mp->mnt_vnodelist); vp; vp = vunmark(mvp)) {
- vmark(mvp, vp);
+ vfs_vnode_iterator_init(mp, &marker);
+ while (vfs_vnode_iterator_next(marker, &vp)) {
+ error = vn_lock(vp, LK_EXCLUSIVE);
+ if (error) {
+ vrele(vp);
+ continue;
+ }
mutex_enter(vp->v_interlock);
- if (VTOI(vp) == NULL || vp->v_mount != mp || vismarker(vp) ||
- vp->v_type == VNON || vp->v_writecount == 0 ||
- (vp->v_iflag & (VI_XLOCK | VI_CLEAN)) != 0) {
+ if (VTOI(vp) == NULL || vp->v_type == VNON ||
+ vp->v_writecount == 0) {
mutex_exit(vp->v_interlock);
+ vput(vp);
continue;
}
- mutex_exit(&mntvnode_lock);
- if (vget(vp, LK_EXCLUSIVE)) {
- mutex_enter(&mntvnode_lock);
- (void)vunmark(mvp);
- goto again;
- }
+ mutex_exit(vp->v_interlock);
if ((error = getinoquota(VTOI(vp))) != 0) {
vput(vp);
- mutex_enter(&mntvnode_lock);
- (void)vunmark(mvp);
break;
}
vput(vp);
- mutex_enter(&mntvnode_lock);
}
- mutex_exit(&mntvnode_lock);
- vnfree(mvp);
+ vfs_vnode_iterator_destroy(marker);
mutex_enter(&dqlock);
ump->umq1_qflags[type] &= ~QTF_OPENING;
@@ -421,21 +414,18 @@ quota1_handle_cmd_quotaoff(struct lwp *l
{
struct mount *mp = ump->um_mountp;
struct vnode *vp;
- struct vnode *qvp, *mvp;
+ struct vnode *qvp;
+ struct vnode_iterator *marker;
struct dquot *dq;
struct inode *ip;
kauth_cred_t cred;
int i, error;
- /* Allocate a marker vnode. */
- mvp = vnalloc(mp);
-
mutex_enter(&dqlock);
while ((ump->umq1_qflags[type] & (QTF_CLOSING | QTF_OPENING)) != 0)
cv_wait(&dqcv, &dqlock);
if ((qvp = ump->um_quotas[type]) == NULLVP) {
mutex_exit(&dqlock);
- vnfree(mvp);
return (0);
}
ump->umq1_qflags[type] |= QTF_CLOSING;
@@ -445,31 +435,24 @@ quota1_handle_cmd_quotaoff(struct lwp *l
* Search vnodes associated with this mount point,
* deleting any references to quota file being closed.
*/
- mutex_enter(&mntvnode_lock);
-again:
- for (vp = TAILQ_FIRST(&mp->mnt_vnodelist); vp; vp = vunmark(mvp)) {
- vmark(mvp, vp);
- mutex_enter(vp->v_interlock);
- if (VTOI(vp) == NULL || vp->v_mount != mp || vismarker(vp) ||
- vp->v_type == VNON ||
- (vp->v_iflag & (VI_XLOCK | VI_CLEAN)) != 0) {
- mutex_exit(vp->v_interlock);
+ vfs_vnode_iterator_init(mp, &marker);
+ while (vfs_vnode_iterator_next(marker, &vp)) {
+ error = vn_lock(vp, LK_EXCLUSIVE);
+ if (error) {
+ vrele(vp);
continue;
}
- mutex_exit(&mntvnode_lock);
- if (vget(vp, LK_EXCLUSIVE)) {
- mutex_enter(&mntvnode_lock);
- (void)vunmark(mvp);
- goto again;
- }
ip = VTOI(vp);
+ if (ip == NULL || vp->v_type == VNON) {
+ vput(vp);
+ continue;
+ }
dq = ip->i_dquot[type];
ip->i_dquot[type] = NODQUOT;
dqrele(vp, dq);
vput(vp);
- mutex_enter(&mntvnode_lock);
}
- mutex_exit(&mntvnode_lock);
+ vfs_vnode_iterator_destroy(marker);
#ifdef DIAGNOSTIC
dqflush(qvp);
#endif
@@ -759,7 +742,8 @@ int
q1sync(struct mount *mp)
{
struct ufsmount *ump = VFSTOUFS(mp);
- struct vnode *vp, *mvp;
+ struct vnode *vp;
+ struct vnode_iterator *marker;
struct dquot *dq;
int i, error;
@@ -773,32 +757,19 @@ q1sync(struct mount *mp)
if (i == MAXQUOTAS)
return (0);
- /* Allocate a marker vnode. */
- mvp = vnalloc(mp);
-
/*
* Search vnodes associated with this mount point,
* synchronizing any modified dquot structures.
*/
- mutex_enter(&mntvnode_lock);
- again:
- for (vp = TAILQ_FIRST(&mp->mnt_vnodelist); vp; vp = vunmark(mvp)) {
- vmark(mvp, vp);
- mutex_enter(vp->v_interlock);
- if (VTOI(vp) == NULL || vp->v_mount != mp || vismarker(vp) ||
- vp->v_type == VNON ||
- (vp->v_iflag & (VI_XLOCK | VI_CLEAN)) != 0) {
- mutex_exit(vp->v_interlock);
+ vfs_vnode_iterator_init(mp, &marker);
+ while (vfs_vnode_iterator_next(marker, &vp)) {
+ error = vn_lock(vp, LK_EXCLUSIVE);
+ if (error) {
+ vrele(vp);
continue;
}
- mutex_exit(&mntvnode_lock);
- error = vget(vp, LK_EXCLUSIVE | LK_NOWAIT);
- if (error) {
- mutex_enter(&mntvnode_lock);
- if (error == ENOENT) {
- (void)vunmark(mvp);
- goto again;
- }
+ if (VTOI(vp) == NULL || vp->v_type == VNON) {
+ vput(vp);
continue;
}
for (i = 0; i < MAXQUOTAS; i++) {
@@ -811,10 +782,8 @@ q1sync(struct mount *mp)
mutex_exit(&dq->dq_interlock);
}
vput(vp);
- mutex_enter(&mntvnode_lock);
}
- mutex_exit(&mntvnode_lock);
- vnfree(mvp);
+ vfs_vnode_iterator_destroy(marker);
return (0);
}