Module Name:    src
Committed By:   hannken
Date:           Thu Feb 13 09:55:04 UTC 2014

Modified Files:
        src/sys/fs/union: union.h union_subr.c union_vnops.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/fs/union/union.h
cvs rdiff -u -r1.60 -r1.61 src/sys/fs/union/union_subr.c
cvs rdiff -u -r1.53 -r1.54 src/sys/fs/union/union_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/fs/union/union.h
diff -u src/sys/fs/union/union.h:1.24 src/sys/fs/union/union.h:1.25
--- src/sys/fs/union/union.h:1.24	Mon Nov  5 17:24:11 2012
+++ src/sys/fs/union/union.h	Thu Feb 13 09:55:04 2014
@@ -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 @@ struct union_node {
 	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 *,

Index: src/sys/fs/union/union_subr.c
diff -u src/sys/fs/union/union_subr.c:1.60 src/sys/fs/union/union_subr.c:1.61
--- src/sys/fs/union/union_subr.c:1.60	Fri Feb  7 15:29:22 2014
+++ src/sys/fs/union/union_subr.c	Thu Feb 13 09:55:04 2014
@@ -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 @@ found:
 			vrele(uppervp);
 		}
 
-		if (un->un_uppervp)
-			un->un_flags &= ~UN_KLOCK;
-
 		/*
 		 * Save information about the lower layer.
 		 * This needs to keep track of pathname

Index: src/sys/fs/union/union_vnops.c
diff -u src/sys/fs/union/union_vnops.c:1.53 src/sys/fs/union/union_vnops.c:1.54
--- src/sys/fs/union/union_vnops.c:1.53	Thu Feb 13 09:50:31 2014
+++ src/sys/fs/union/union_vnops.c	Thu Feb 13 09:55:04 2014
@@ -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 @@ union_remove(void *v)
 		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 @@ union_link(void *v)
 		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 @@ union_rename(void *v)
 	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 @@ union_rename(void *v)
 
 		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 @@ union_rename(void *v)
 		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 @@ out:
 	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 @@ union_rmdir(void *v)
 		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 @@ union_lock(void *v)
 		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 @@ union_unlock(void *v)
 
 	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

Reply via email to