Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/fs/union Get rid of UN_KLOCK to keep a lock on vput(). ...
details: https://anonhg.NetBSD.org/src/rev/6a9ba55fb2f3
branches: trunk
changeset: 326689:6a9ba55fb2f3
user: hannken <hannken%NetBSD.org@localhost>
date: Thu Feb 13 09:55:04 2014 +0000
description:
Get rid of UN_KLOCK to keep a lock on vput(). It is not really needed
and makes the source difficult to read. Always hold references to the
union nodes until the operation is done.
diffstat:
sys/fs/union/union.h | 3 +-
sys/fs/union/union_subr.c | 7 +---
sys/fs/union/union_vnops.c | 68 +++++++++++++++++++++------------------------
3 files changed, 35 insertions(+), 43 deletions(-)
diffs (212 lines):
diff -r 8e34b849dec2 -r 6a9ba55fb2f3 sys/fs/union/union.h
--- a/sys/fs/union/union.h Thu Feb 13 09:50:31 2014 +0000
+++ b/sys/fs/union/union.h Thu Feb 13 09:55:04 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: union.h,v 1.24 2012/11/05 17:24:11 dholland Exp $ */
+/* $NetBSD: union.h,v 1.25 2014/02/13 09:55:04 hannken Exp $ */
/*
* Copyright (c) 1994 The Regents of the University of California.
@@ -134,7 +134,6 @@
off_t un_lowersz; /* l: size of lower object */
};
-#define UN_KLOCK 0x08 /* Keep upper node locked on vput */
#define UN_CACHED 0x10 /* In union cache */
extern int union_allocvp(struct vnode **, struct mount *,
diff -r 8e34b849dec2 -r 6a9ba55fb2f3 sys/fs/union/union_subr.c
--- a/sys/fs/union/union_subr.c Thu Feb 13 09:50:31 2014 +0000
+++ b/sys/fs/union/union_subr.c Thu Feb 13 09:55:04 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: union_subr.c,v 1.60 2014/02/07 15:29:22 hannken Exp $ */
+/* $NetBSD: union_subr.c,v 1.61 2014/02/13 09:55:04 hannken Exp $ */
/*
* Copyright (c) 1994
@@ -72,7 +72,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: union_subr.c,v 1.60 2014/02/07 15:29:22 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: union_subr.c,v 1.61 2014/02/13 09:55:04 hannken Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -439,9 +439,6 @@
vrele(uppervp);
}
- if (un->un_uppervp)
- un->un_flags &= ~UN_KLOCK;
-
/*
* Save information about the lower layer.
* This needs to keep track of pathname
diff -r 8e34b849dec2 -r 6a9ba55fb2f3 sys/fs/union/union_vnops.c
--- a/sys/fs/union/union_vnops.c Thu Feb 13 09:50:31 2014 +0000
+++ b/sys/fs/union/union_vnops.c Thu Feb 13 09:55:04 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: union_vnops.c,v 1.53 2014/02/13 09:50:31 hannken Exp $ */
+/* $NetBSD: union_vnops.c,v 1.54 2014/02/13 09:55:04 hannken Exp $ */
/*
* Copyright (c) 1992, 1993, 1994, 1995
@@ -72,7 +72,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: union_vnops.c,v 1.53 2014/02/13 09:50:31 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: union_vnops.c,v 1.54 2014/02/13 09:55:04 hannken Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -1156,18 +1156,19 @@
struct vnode *dvp = dun->un_uppervp;
struct vnode *vp = un->un_uppervp;
+ /*
+ * Account for VOP_REMOVE to vrele dvp and vp.
+ * Note: VOP_REMOVE will unlock dvp and vp.
+ */
vref(dvp);
- dun->un_flags |= UN_KLOCK;
- vput(ap->a_dvp);
vref(vp);
- un->un_flags |= UN_KLOCK;
- vput(ap->a_vp);
-
if (union_dowhiteout(un, cnp->cn_cred))
cnp->cn_flags |= DOWHITEOUT;
error = VOP_REMOVE(dvp, vp, cnp);
if (!error)
union_removed_upper(un);
+ vrele(ap->a_dvp);
+ vrele(ap->a_vp);
} else {
error = union_mkwhiteout(
MOUNTTOUNIONMOUNT(UNIONTOV(dun)->v_mount),
@@ -1258,11 +1259,15 @@
return (error);
}
+ /*
+ * Account for VOP_LINK to vrele dvp.
+ * Note: VOP_LINK will unlock dvp.
+ */
vref(dvp);
- dun->un_flags |= UN_KLOCK;
- vput(ap->a_dvp);
+ error = VOP_LINK(dvp, vp, cnp);
+ vrele(ap->a_dvp);
- return (VOP_LINK(dvp, vp, cnp));
+ return error;
}
int
@@ -1283,6 +1288,11 @@
struct vnode *tdvp = ap->a_tdvp;
struct vnode *tvp = ap->a_tvp;
+ /*
+ * Account for VOP_RENAME to vrele all nodes.
+ * Note: VOP_RENAME will unlock tdvp.
+ */
+
if (fdvp->v_op == union_vnodeop_p) { /* always true */
struct union_node *un = VTOUNION(fdvp);
if (un->un_uppervp == NULLVP) {
@@ -1330,8 +1340,6 @@
tdvp = un->un_uppervp;
vref(tdvp);
- un->un_flags |= UN_KLOCK;
- vput(ap->a_tdvp);
}
if (tvp != NULLVP && tvp->v_op == union_vnodeop_p) {
@@ -1340,9 +1348,7 @@
tvp = un->un_uppervp;
if (tvp != NULLVP) {
vref(tvp);
- un->un_flags |= UN_KLOCK;
}
- vput(ap->a_tvp);
}
error = VOP_RENAME(fdvp, fvp, ap->a_fcnp, tdvp, tvp, ap->a_tcnp);
@@ -1362,6 +1368,12 @@
if (fvp != ap->a_fvp) {
vrele(ap->a_fvp);
}
+ if (tdvp != ap->a_tdvp) {
+ vrele(ap->a_tdvp);
+ }
+ if (tvp != ap->a_tvp) {
+ vrele(ap->a_tvp);
+ }
return (error);
}
@@ -1428,18 +1440,19 @@
struct vnode *dvp = dun->un_uppervp;
struct vnode *vp = un->un_uppervp;
+ /*
+ * Account for VOP_RMDIR to vrele dvp and vp.
+ * Note: VOP_RMDIR will unlock dvp and vp.
+ */
vref(dvp);
- dun->un_flags |= UN_KLOCK;
- vput(ap->a_dvp);
vref(vp);
- un->un_flags |= UN_KLOCK;
- vput(ap->a_vp);
-
if (union_dowhiteout(un, cnp->cn_cred))
cnp->cn_flags |= DOWHITEOUT;
error = VOP_RMDIR(dvp, vp, ap->a_cnp);
if (!error)
union_removed_upper(un);
+ vrele(ap->a_dvp);
+ vrele(ap->a_vp);
} else {
error = union_mkwhiteout(
MOUNTTOUNIONMOUNT(UNIONTOV(dun)->v_mount),
@@ -1621,23 +1634,11 @@
else
VOP_UNLOCK(vp);
}
- KASSERT((un->un_flags & UN_KLOCK) == 0);
mutex_exit(&un->un_lock);
return error;
}
-/*
- * When operations want to vput() a union node yet retain a lock on
- * the upper vnode (say, to do some further operations like link(),
- * mkdir(), ...), they set UN_KLOCK on the union node, then call
- * vput() which calls VOP_UNLOCK() and comes here. union_unlock()
- * unlocks the union node (leaving the upper vnode alone), clears the
- * KLOCK flag, and then returns to vput(). The caller then does whatever
- * is left to do with the upper vnode, and ensures that it gets unlocked.
- *
- * If UN_KLOCK isn't set, then the upper vnode is unlocked here.
- */
int
union_unlock(void *v)
{
@@ -1650,11 +1651,6 @@
un = VTOUNION(ap->a_vp);
vp = LOCKVP(ap->a_vp);
- if ((un->un_flags & UN_KLOCK) == UN_KLOCK) {
- KASSERT(vp != ap->a_vp);
- un->un_flags &= ~UN_KLOCK;
- return 0;
- }
if (vp == ap->a_vp)
genfs_unlock(ap);
else
Home |
Main Index |
Thread Index |
Old Index