Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Clean up vnode lock operations:



details:   https://anonhg.NetBSD.org/src/rev/c970499886ed
branches:  trunk
changeset: 755826:c970499886ed
user:      hannken <hannken%NetBSD.org@localhost>
date:      Thu Jun 24 07:54:46 2010 +0000

description:
Clean up vnode lock operations:

 - VOP_LOCK(vp, flags): Limit the set of allowed flags to LK_EXCLUSIVE,
   LK_SHARED and LK_NOWAIT.  LK_INTERLOCK is no longer allowed as it
   makes no sense here.

- VOP_ISLOCKED(vp): Remove the for some time unused return value
  LK_EXCLOTHER.  Mark this operation as "diagnostic only".
  Making a lock decision based on this operation is no longer allowed.

Discussed on tech-kern.

diffstat:

 share/man/man9/vnodeops.9      |  20 +++++++++++++++-----
 sys/coda/coda_vnops.c          |   5 +++--
 sys/fs/nilfs/nilfs_vnops.c     |  21 +++++++++++++--------
 sys/fs/udf/udf_vnops.c         |  20 ++++++++++++--------
 sys/fs/unionfs/unionfs_subr.c  |   2 +-
 sys/fs/unionfs/unionfs_vnops.c |  15 +--------------
 sys/kern/vfs_subr.c            |  16 +++++-----------
 sys/miscfs/genfs/genfs_vnops.c |   9 ++-------
 sys/nfs/nfs_vfsops.c           |  13 +++++++++----
 sys/sys/lock.h                 |   3 +--
 sys/ufs/lfs/lfs_subr.c         |  10 +++++-----
 sys/ufs/lfs/lfs_vnops.c        |  27 ++++++++++++++++-----------
 12 files changed, 83 insertions(+), 78 deletions(-)

diffs (truncated from 504 to 300 lines):

diff -r ba8cd12f1cae -r c970499886ed share/man/man9/vnodeops.9
--- a/share/man/man9/vnodeops.9 Thu Jun 24 04:21:58 2010 +0000
+++ b/share/man/man9/vnodeops.9 Thu Jun 24 07:54:46 2010 +0000
@@ -1,4 +1,4 @@
-.\"     $NetBSD: vnodeops.9,v 1.78 2010/05/19 13:20:32 pooka Exp $
+.\"     $NetBSD: vnodeops.9,v 1.79 2010/06/24 07:54:46 hannken Exp $
 .\"
 .\" Copyright (c) 2001, 2005, 2006 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,7 +27,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd May 19, 2010
+.Dd June 24, 2010
 .Dt VNODEOPS 9
 .Os
 .Sh NAME
@@ -1063,9 +1063,16 @@
 is the vnode of the file to be locked.
 The argument
 .Fa flags
-is a set of
-.Xr lockmgr 9
-flags.
+is
+.Dv LK_EXCLUSIVE
+to take the lock exclusively or
+.Dv LK_SHARED
+to take a shared lock.
+If
+.Fa flags
+contains
+.Dv LK_NOWAIT
+and the lock is busy, the operation will return immediately with an error code.
 If the operation is successful zero is returned, otherwise an
 appropriate error code is returned.
 .Fn VOP_LOCK
@@ -1100,6 +1107,9 @@
 .Dv LK_SHARED
 or 0 for lock held exclusively by the calling thread, shared lock held
 by anyone or unlocked, respectively.
+.Pp
+This function must never be used to make locking decisions at run time:
+it is provided only for diagnostic purposes.
 .It Fn VOP_BMAP "vp" "bn" "vpp" "bnp" "runp"
 Convert the logical block number
 .Fa bn
diff -r ba8cd12f1cae -r c970499886ed sys/coda/coda_vnops.c
--- a/sys/coda/coda_vnops.c     Thu Jun 24 04:21:58 2010 +0000
+++ b/sys/coda/coda_vnops.c     Thu Jun 24 07:54:46 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: coda_vnops.c,v 1.71 2009/11/23 02:13:44 rmind Exp $    */
+/*     $NetBSD: coda_vnops.c,v 1.72 2010/06/24 07:54:46 hannken Exp $  */
 
 /*
  *
@@ -46,7 +46,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: coda_vnops.c,v 1.71 2009/11/23 02:13:44 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: coda_vnops.c,v 1.72 2010/06/24 07:54:46 hannken Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -2018,6 +2018,7 @@
         * lock, and if we should serialize getpages calls by some
         * mechanism.
         */
+       /* XXX VOP_ISLOCKED() may not be used for lock decisions. */
        waslocked = VOP_ISLOCKED(vp);
 
        /* Drop the vmobject lock. */
diff -r ba8cd12f1cae -r c970499886ed sys/fs/nilfs/nilfs_vnops.c
--- a/sys/fs/nilfs/nilfs_vnops.c        Thu Jun 24 04:21:58 2010 +0000
+++ b/sys/fs/nilfs/nilfs_vnops.c        Thu Jun 24 07:54:46 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nilfs_vnops.c,v 1.4 2010/01/08 11:35:08 pooka Exp $ */
+/* $NetBSD: nilfs_vnops.c,v 1.5 2010/06/24 07:54:46 hannken Exp $ */
 
 /*
  * Copyright (c) 2008, 2009 Reinoud Zandijk
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__KERNEL_RCSID(0, "$NetBSD: nilfs_vnops.c,v 1.4 2010/01/08 11:35:08 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nilfs_vnops.c,v 1.5 2010/06/24 07:54:46 hannken Exp $");
 #endif /* not lint */
 
 
@@ -1161,14 +1161,22 @@
        nilfs_node = VTOI(vp);
 
        error = VOP_GETATTR(vp, &vap, FSCRED);
-       if (error)
+       if (error) {
+               VOP_UNLOCK(vp, 0);
                return error;
+       }
 
        /* check link count overflow */
-       if (vap.va_nlink >= (1<<16)-1)  /* uint16_t */
+       if (vap.va_nlink >= (1<<16)-1) {        /* uint16_t */
+               VOP_UNLOCK(vp, 0);
                return EMLINK;
+       }
 
-       return nilfs_dir_attach(dir_node->ump, dir_node, nilfs_node, &vap, cnp);
+       error = nilfs_dir_attach(dir_node->ump, dir_node, nilfs_node,
+           &vap, cnp);
+       if (error)
+               VOP_UNLOCK(vp, 0);
+       return error;
 }
 
 int
@@ -1188,9 +1196,6 @@
        if (error)
                VOP_ABORTOP(dvp, cnp);
 
-       if ((vp != dvp) && (VOP_ISLOCKED(vp) == LK_EXCLUSIVE))
-               VOP_UNLOCK(vp, 0);
-
        VN_KNOTE(vp, NOTE_LINK);
        VN_KNOTE(dvp, NOTE_WRITE);
        vput(dvp);
diff -r ba8cd12f1cae -r c970499886ed sys/fs/udf/udf_vnops.c
--- a/sys/fs/udf/udf_vnops.c    Thu Jun 24 04:21:58 2010 +0000
+++ b/sys/fs/udf/udf_vnops.c    Thu Jun 24 07:54:46 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: udf_vnops.c,v 1.57 2010/01/08 11:35:09 pooka Exp $ */
+/* $NetBSD: udf_vnops.c,v 1.58 2010/06/24 07:54:46 hannken Exp $ */
 
 /*
  * Copyright (c) 2006, 2008 Reinoud Zandijk
@@ -32,7 +32,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__KERNEL_RCSID(0, "$NetBSD: udf_vnops.c,v 1.57 2010/01/08 11:35:09 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: udf_vnops.c,v 1.58 2010/06/24 07:54:46 hannken Exp $");
 #endif /* not lint */
 
 
@@ -1509,14 +1509,21 @@
        udf_node = VTOI(vp);
 
        error = VOP_GETATTR(vp, &vap, FSCRED);
-       if (error)
+       if (error) {
+               VOP_UNLOCK(vp, 0);
                return error;
+       }
 
        /* check link count overflow */
-       if (vap.va_nlink >= (1<<16)-1)  /* uint16_t */
+       if (vap.va_nlink >= (1<<16)-1) {        /* uint16_t */
+               VOP_UNLOCK(vp, 0);
                return EMLINK;
+       }
 
-       return udf_dir_attach(dir_node->ump, dir_node, udf_node, &vap, cnp);
+       error = udf_dir_attach(dir_node->ump, dir_node, udf_node, &vap, cnp);
+       if (error)
+               VOP_UNLOCK(vp, 0);
+       return error;
 }
 
 int
@@ -1536,9 +1543,6 @@
        if (error)
                VOP_ABORTOP(dvp, cnp);
 
-       if ((vp != dvp) && (VOP_ISLOCKED(vp) == LK_EXCLUSIVE))
-               VOP_UNLOCK(vp, 0);
-
        VN_KNOTE(vp, NOTE_LINK);
        VN_KNOTE(dvp, NOTE_WRITE);
        vput(dvp);
diff -r ba8cd12f1cae -r c970499886ed sys/fs/unionfs/unionfs_subr.c
--- a/sys/fs/unionfs/unionfs_subr.c     Thu Jun 24 04:21:58 2010 +0000
+++ b/sys/fs/unionfs/unionfs_subr.c     Thu Jun 24 07:54:46 2010 +0000
@@ -484,7 +484,7 @@
         */
        mutex_enter(&vp->v_interlock);
        unp->un_uppervp = uvp;
-       KASSERT(rw_write_held(&lvp->v_lock.vl_lock));
+       KASSERT(VOP_ISLOCKED(lvp) == LK_EXCLUSIVE);
        mutex_exit(&vp->v_interlock);
 }
 
diff -r ba8cd12f1cae -r c970499886ed sys/fs/unionfs/unionfs_vnops.c
--- a/sys/fs/unionfs/unionfs_vnops.c    Thu Jun 24 04:21:58 2010 +0000
+++ b/sys/fs/unionfs/unionfs_vnops.c    Thu Jun 24 07:54:46 2010 +0000
@@ -471,7 +471,6 @@
 {
        struct vop_close_args *ap = v;
        int             error;
-       int             locked;
        struct unionfs_node *unp;
        struct unionfs_node_status *unsp;
        kauth_cred_t   cred;
@@ -479,14 +478,10 @@
 
        UNIONFS_INTERNAL_DEBUG("unionfs_close: enter\n");
 
-       locked = 0;
+       KASSERT(VOP_ISLOCKED(ap->a_vp) == LK_EXCLUSIVE);
        unp = VTOUNIONFS(ap->a_vp);
        cred = ap->a_cred;
 
-       if (VOP_ISLOCKED(ap->a_vp) != LK_EXCLUSIVE) {
-               vn_lock(ap->a_vp, LK_EXCLUSIVE | LK_RETRY);
-               locked = 1;
-       }
        unionfs_get_node_status(unp, &unsp);
 
        if (unsp->uns_lower_opencnt <= 0 && unsp->uns_upper_opencnt <= 0) {
@@ -522,9 +517,6 @@
 unionfs_close_abort:
        unionfs_tryrem_node_status(unp, unsp);
 
-       if (locked != 0)
-               VOP_UNLOCK(ap->a_vp, 0);
-
        UNIONFS_INTERNAL_DEBUG("unionfs_close: leave (%d)\n", error);
 
        return (error);
@@ -1538,11 +1530,6 @@
        flags = ap->a_flags;
        error = 0;
 
-       if ((flags & LK_INTERLOCK) != 0) {
-               mutex_exit(&ap->a_vp->v_interlock);
-               flags &= ~LK_INTERLOCK;
-       }
-
        if (lvp != NULLVP) {
                error = VOP_LOCK(lvp, flags);
        }
diff -r ba8cd12f1cae -r c970499886ed sys/kern/vfs_subr.c
--- a/sys/kern/vfs_subr.c       Thu Jun 24 04:21:58 2010 +0000
+++ b/sys/kern/vfs_subr.c       Thu Jun 24 07:54:46 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_subr.c,v 1.405 2010/06/18 16:29:02 hannken Exp $   */
+/*     $NetBSD: vfs_subr.c,v 1.406 2010/06/24 07:54:47 hannken Exp $   */
 
 /*-
  * Copyright (c) 1997, 1998, 2004, 2005, 2007, 2008 The NetBSD Foundation, Inc.
@@ -91,7 +91,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.405 2010/06/18 16:29:02 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.406 2010/06/24 07:54:47 hannken Exp $");
 
 #include "opt_ddb.h"
 #include "opt_compat_netbsd.h"
@@ -347,15 +347,8 @@
                }
                if (!mutex_tryenter(&vp->v_interlock))
                        continue;
-               /*
-                * Our lwp might hold the underlying vnode
-                * locked, so don't try to reclaim a VI_LAYER
-                * node if it's locked.
-                */
-               if ((vp->v_iflag & VI_XLOCK) == 0 &&
-                   ((vp->v_iflag & VI_LAYER) == 0 || VOP_ISLOCKED(vp) == 0)) {
+               if ((vp->v_iflag & VI_XLOCK) == 0)
                        break;
-               }
                mutex_exit(&vp->v_interlock);
        }
 
@@ -1901,7 +1894,8 @@
        active = (vp->v_usecount > 1);
 
        /* XXXAD should not lock vnode under layer */
-       VOP_LOCK(vp, LK_EXCLUSIVE | LK_INTERLOCK);
+       mutex_exit(&vp->v_interlock);
+       VOP_LOCK(vp, LK_EXCLUSIVE);
 
        /*
         * Clean out any cached data associated with the vnode.
diff -r ba8cd12f1cae -r c970499886ed sys/miscfs/genfs/genfs_vnops.c
--- a/sys/miscfs/genfs/genfs_vnops.c    Thu Jun 24 04:21:58 2010 +0000
+++ b/sys/miscfs/genfs/genfs_vnops.c    Thu Jun 24 07:54:46 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: genfs_vnops.c,v 1.178 2010/06/06 08:01:31 hannken Exp $        */
+/*     $NetBSD: genfs_vnops.c,v 1.179 2010/06/24 07:54:47 hannken Exp $        */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -57,7 +57,7 @@
  */
 
 #include <sys/cdefs.h>



Home | Main Index | Thread Index | Old Index