Module Name:    src
Committed By:   hannken
Date:           Wed Mar 12 09:39:23 UTC 2014

Modified Files:
        src/sys/miscfs/genfs: layer_vnops.c

Log Message:
Restructure layer_lock() to always lock before testing for dead node.
Use ISSET() to test flags, add assertions.


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/sys/miscfs/genfs/layer_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/miscfs/genfs/layer_vnops.c
diff -u src/sys/miscfs/genfs/layer_vnops.c:1.55 src/sys/miscfs/genfs/layer_vnops.c:1.56
--- src/sys/miscfs/genfs/layer_vnops.c:1.55	Thu Feb 27 16:51:38 2014
+++ src/sys/miscfs/genfs/layer_vnops.c	Wed Mar 12 09:39:23 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: layer_vnops.c,v 1.55 2014/02/27 16:51:38 hannken Exp $	*/
+/*	$NetBSD: layer_vnops.c,v 1.56 2014/03/12 09:39:23 hannken Exp $	*/
 
 /*
  * Copyright (c) 1999 National Aeronautics & Space Administration
@@ -170,7 +170,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: layer_vnops.c,v 1.55 2014/02/27 16:51:38 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: layer_vnops.c,v 1.56 2014/03/12 09:39:23 hannken Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -718,15 +718,23 @@ layer_lock(void *v)
 	int flags = ap->a_flags;
 	int error;
 
-	if ((flags & LK_NOWAIT) != 0) {
-		if (!mutex_tryenter(vp->v_interlock))
-			return EBUSY;
-		if ((vp->v_iflag & (VI_XLOCK | VI_CLEAN)) != 0) {
+	if (ISSET(flags, LK_NOWAIT)) {
+		error = VOP_LOCK(lowervp, flags);
+		if (error)
+			return error;
+		if (mutex_tryenter(vp->v_interlock)) {
+			if (ISSET(vp->v_iflag, VI_XLOCK))
+				error = EBUSY;
+			else if (ISSET(vp->v_iflag, VI_CLEAN))
+				error = ENOENT;
+			else
+				error = 0;
 			mutex_exit(vp->v_interlock);
-			return EBUSY;
-		}
-		mutex_exit(vp->v_interlock);
-		return VOP_LOCK(lowervp, flags);
+		} else
+			error = EBUSY;
+		if (error)
+			VOP_UNLOCK(lowervp);
+		return error;
 	}
 
 	error = VOP_LOCK(lowervp, flags);
@@ -734,10 +742,10 @@ layer_lock(void *v)
 		return error;
 
 	mutex_enter(vp->v_interlock);
-	if ((vp->v_iflag & (VI_XLOCK | VI_CLEAN)) != 0) {
+	if (ISSET(vp->v_iflag, VI_XLOCK) || ISSET(vp->v_iflag, VI_CLEAN)) {
 		VOP_UNLOCK(lowervp);
-		if ((vp->v_iflag & VI_XLOCK))
-			vwait(vp, VI_XLOCK);
+		vwait(vp, VI_XLOCK);
+		KASSERT(ISSET(vp->v_iflag, VI_CLEAN));
 		mutex_exit(vp->v_interlock);
 		return ENOENT;
 	}

Reply via email to