It is time for the lockmgr() api to die. The api is only used by
filesystems, where it is a trivial change to use rrw locks instead. All
it needs is LK_* defines for the RW_* flags. (See the sys/lock.h hunk in
the diff below.)

The ffs regress tests display the same number of fail/ok results before
and after applying diff below, and I have done some manual testing with
various filesystems on amd64 and macppc.

Again, the purpose is to make filesystem code less scary and more
comprehensible.

Ok?

natano


Index: distrib/sets/lists/comp/mi
===================================================================
RCS file: /cvs/src/distrib/sets/lists/comp/mi,v
retrieving revision 1.1233
diff -u -p -r1.1233 mi
--- distrib/sets/lists/comp/mi  23 May 2016 00:59:55 -0000      1.1233
+++ distrib/sets/lists/comp/mi  29 May 2016 18:13:57 -0000
@@ -2712,7 +2712,6 @@
 ./usr/share/man/man9/kthread.9
 ./usr/share/man/man9/ktrace.9
 ./usr/share/man/man9/loadfirmware.9
-./usr/share/man/man9/lock.9
 ./usr/share/man/man9/log.9
 ./usr/share/man/man9/malloc.9
 ./usr/share/man/man9/mbuf.9
Index: share/man/man9/Makefile
===================================================================
RCS file: /cvs/src/share/man/man9/Makefile,v
retrieving revision 1.276
diff -u -p -r1.276 Makefile
--- share/man/man9/Makefile     25 Apr 2016 19:24:42 -0000      1.276
+++ share/man/man9/Makefile     29 May 2016 18:14:11 -0000
@@ -20,7 +20,7 @@ MAN=  aml_evalnode.9 atomic_add_int.9 ato
        ieee80211_radiotap.9 if_get.9 if_rxr_init.9 ifq_enqueue.9 \
        ifq_deq_begin.9 iic.9 intro.9 inittodr.9 intr_barrier.9 \
        kern.9 km_alloc.9 knote.9 kthread.9 ktrace.9 \
-       loadfirmware.9 lock.9 log.9 \
+       loadfirmware.9 log.9 \
        malloc.9 membar_sync.9 mbuf.9 mbuf_tags.9 md5.9 mi_switch.9 \
        microtime.9 ml_init.9 mq_init.9 mutex.9 \
        namei.9 \
Index: share/man/man9/VOP_LOOKUP.9
===================================================================
RCS file: /cvs/src/share/man/man9/VOP_LOOKUP.9,v
retrieving revision 1.35
diff -u -p -r1.35 VOP_LOOKUP.9
--- share/man/man9/VOP_LOOKUP.9 23 May 2016 09:31:28 -0000      1.35
+++ share/man/man9/VOP_LOOKUP.9 29 May 2016 18:14:11 -0000
@@ -1,6 +1,7 @@
 .\" $OpenBSD: VOP_LOOKUP.9,v 1.35 2016/05/23 09:31:28 natano Exp $
 .\"
 .\" Copyright (c) 2003 Ted Unangst
+.\" Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
 .\" All rights reserved.
 .\"
 .\" Redistribution and use in source and binary forms, with or without
@@ -565,16 +566,54 @@ to lock a vnode.
 It should not be used by other file system code.
 .Fn VOP_UNLOCK
 unlocks a vnode.
-.Fn VOP_ISLOCKED
-returns 1 if
-.Fa vp
-is locked and 0 if not.
-It should be used cautiously, as not all file systems implement locks
-effectively.
 Note the asymmetry between
 .Xr vn_lock 9
 and
 .Fn VOP_UNLOCK .
+.Pp
+.Fa flags
+may contain the following flags:
+.Pp
+.Bl -tag -width LK_RECURSEFAIL -compact -offset indent
+.It Dv LK_EXCLUSIVE
+Acquire an exclusive lock.
+.It Dv LK_SHARED
+Acquire a shared lock.
+.It Dv LK_NOWAIT
+Don't wait if the vnode lock is held by someone else
+(may still wait on reclamation lock).
+.It Dv LK_RECURSEFAIL
+Attempt at recursive lock fails.
+.It Dv LK_DRAIN
+Wait for all activity on the lock to end, then mark it decommissioned.
+This feature is used to ensure that no other activity can occur while the
+underlying object of a vnode is being cleaned out.
+Must be used in combination with
+.Dv LK_EXCLUSIVE .
+.El
+.Pp
+.Fn VOP_ISLOCKED
+returns one of the following values:
+.Pp
+.Bl -tag -width LK_EXCLUSIVE -compact -offset indent
+.It Dv LK_EXCLUSIVE
+.Fa vp
+is locked for exclusive access by the calling thread.
+.It Dv LK_EXCLOTHER
+.Fa vp
+is locked for exclusive access by a different thread.
+.It Dv LK_SHARED
+.Fa vp
+is locked for shared access.
+The current thread may be one of the threads that have it locked.
+.It 0
+.Fa vp
+is not locked.
+.El
+.Pp
+.Fn VOP_ISLOCKED
+should be used cautiously, as not all file systems implement locks
+effectively.
 .Pp
 .It Fn VOP_KQFILTER vp kn
 Register the
Index: share/man/man9/mutex.9
===================================================================
RCS file: /cvs/src/share/man/man9/mutex.9,v
retrieving revision 1.22
diff -u -p -r1.22 mutex.9
--- share/man/man9/mutex.9      13 Feb 2014 14:23:05 -0000      1.22
+++ share/man/man9/mutex.9      29 May 2016 18:14:11 -0000
@@ -104,7 +104,6 @@ function will return non-zero if it succ
 .Fa mtxp ,
 otherwise it will return 0.
 .Sh SEE ALSO
-.Xr lockmgr 9 ,
 .Xr msleep 9 ,
 .Xr rwlock 9 ,
 .Xr spl 9
Index: share/man/man9/rwlock.9
===================================================================
RCS file: /cvs/src/share/man/man9/rwlock.9,v
retrieving revision 1.17
diff -u -p -r1.17 rwlock.9
--- share/man/man9/rwlock.9     9 Jul 2014 18:00:09 -0000       1.17
+++ share/man/man9/rwlock.9     29 May 2016 18:14:11 -0000
@@ -183,8 +183,8 @@ can be called during autoconf, from proc
 .Pp
 All other functions can be called during autoconf or from process context.
 .Sh SEE ALSO
-.Xr lockmgr 9 ,
-.Xr mutex 9
+.Xr mutex 9 ,
+.Xr spl 9
 .Sh HISTORY
 The
 .Nm
Index: share/man/man9/vnsubr.9
===================================================================
RCS file: /cvs/src/share/man/man9/vnsubr.9,v
retrieving revision 1.11
diff -u -p -r1.11 vnsubr.9
--- share/man/man9/vnsubr.9     3 Sep 2011 22:59:07 -0000       1.11
+++ share/man/man9/vnsubr.9     29 May 2016 18:14:11 -0000
@@ -125,22 +125,17 @@ Instead, the
 .Xr vget 9
 function should be used.
 .Pp
-The
+In addition to the
 .Fa flags
-argument may contain the following flags:
+accepted by
+.Xr VOP_LOCK 9 ,
+the following flag may be used:
 .Pp
-.Bl -tag -width LK_EXCLUSIVE -offset indent -compact
+.Bl -tag -width LK_RETRY -offset indent -compact
 .It Dv LK_RETRY
 Return the vnode even if it has been reclaimed.
-.It Dv LK_NOWAIT
-Don't wait if the vnode lock is held by someone else
-(may still wait on reclamation lock).
 Must not be used with
-.Dv LK_RETRY .
-.It Dv LK_EXCLUSIVE
-Acquire an exclusive lock.
-.It Dv LK_SHARED
-Acquire a shared lock.
+.Dv LK_NOWAIT .
 .El
 .Pp
 The
Index: sys/isofs/cd9660/cd9660_node.c
===================================================================
RCS file: /cvs/src/sys/isofs/cd9660/cd9660_node.c,v
retrieving revision 1.30
diff -u -p -r1.30 cd9660_node.c
--- sys/isofs/cd9660/cd9660_node.c      19 Mar 2016 12:04:15 -0000      1.30
+++ sys/isofs/cd9660/cd9660_node.c      29 May 2016 18:14:12 -0000
@@ -146,7 +146,7 @@ cd9660_ihashins(ip)
        *ipp = ip;
        /* XXX locking unlock hash list? */
 
-       lockmgr(&ip->i_lock, LK_EXCLUSIVE, NULL);
+       rrw_enter(&ip->i_lock, RW_WRITE);
 
        return (0);
 }
Index: sys/isofs/cd9660/cd9660_node.h
===================================================================
RCS file: /cvs/src/sys/isofs/cd9660/cd9660_node.h,v
retrieving revision 1.19
diff -u -p -r1.19 cd9660_node.h
--- sys/isofs/cd9660/cd9660_node.h      2 Jun 2013 01:07:39 -0000       1.19
+++ sys/isofs/cd9660/cd9660_node.h      29 May 2016 18:14:12 -0000
@@ -66,7 +66,7 @@ struct iso_node {
        doff_t  i_diroff;       /* offset in dir, where we found last entry */
        doff_t  i_offset;       /* offset of free space in directory */
        cdino_t i_ino;          /* inode number of found directory */
-       struct  lock i_lock;    /* node lock */
+       struct  rrwlock i_lock; /* node lock */
 
        doff_t  iso_extent;     /* extent of file */
        doff_t  i_size;
Index: sys/isofs/cd9660/cd9660_vfsops.c
===================================================================
RCS file: /cvs/src/sys/isofs/cd9660/cd9660_vfsops.c,v
retrieving revision 1.79
diff -u -p -r1.79 cd9660_vfsops.c
--- sys/isofs/cd9660/cd9660_vfsops.c    22 May 2016 20:27:04 -0000      1.79
+++ sys/isofs/cd9660/cd9660_vfsops.c    29 May 2016 18:14:12 -0000
@@ -771,7 +771,7 @@ retry:
                return (error);
        }
        ip = malloc(sizeof(*ip), M_ISOFSNODE, M_WAITOK | M_ZERO);
-       lockinit(&ip->i_lock, PINOD, "isoinode", 0, 0);
+       rrw_init(&ip->i_lock, "isoinode");
        vp->v_data = ip;
        ip->i_vnode = vp;
        ip->i_dev = dev;
Index: sys/isofs/cd9660/cd9660_vnops.c
===================================================================
RCS file: /cvs/src/sys/isofs/cd9660/cd9660_vnops.c,v
retrieving revision 1.75
diff -u -p -r1.75 cd9660_vnops.c
--- sys/isofs/cd9660/cd9660_vnops.c     19 Mar 2016 12:04:15 -0000      1.75
+++ sys/isofs/cd9660/cd9660_vnops.c     29 May 2016 18:14:12 -0000
@@ -696,7 +696,7 @@ cd9660_lock(void *v)
        struct vop_lock_args *ap = v;
        struct vnode *vp = ap->a_vp;
 
-       return (lockmgr(&VTOI(vp)->i_lock, ap->a_flags, NULL));
+       return rrw_enter(&VTOI(vp)->i_lock, ap->a_flags & LK_RWFLAGS);
 }
 
 /*
@@ -708,7 +708,8 @@ cd9660_unlock(void *v)
        struct vop_unlock_args *ap = v;
        struct vnode *vp = ap->a_vp;
 
-       return (lockmgr(&VTOI(vp)->i_lock, LK_RELEASE, NULL));
+       rrw_exit(&VTOI(vp)->i_lock);
+       return 0;
 }
 
 /*
@@ -772,7 +773,7 @@ cd9660_islocked(void *v)
 {
        struct vop_islocked_args *ap = v;
 
-       return (lockstatus(&VTOI(ap->a_vp)->i_lock));
+       return rrw_status(&VTOI(ap->a_vp)->i_lock);
 }
 
 /*
Index: sys/isofs/udf/udf.h
===================================================================
RCS file: /cvs/src/sys/isofs/udf/udf.h,v
retrieving revision 1.20
diff -u -p -r1.20 udf.h
--- sys/isofs/udf/udf.h 18 Nov 2014 10:42:15 -0000      1.20
+++ sys/isofs/udf/udf.h 29 May 2016 18:14:12 -0000
@@ -41,7 +41,7 @@ struct unode {
        struct vnode *u_vnode;
        struct vnode *u_devvp;
        struct umount *u_ump;
-       struct lock u_lock;
+       struct rrwlock u_lock;
        dev_t u_dev;
        udfino_t u_ino;
        union {
Index: sys/isofs/udf/udf_vfsops.c
===================================================================
RCS file: /cvs/src/sys/isofs/udf/udf_vfsops.c,v
retrieving revision 1.51
diff -u -p -r1.51 udf_vfsops.c
--- sys/isofs/udf/udf_vfsops.c  22 May 2016 20:27:04 -0000      1.51
+++ sys/isofs/udf/udf_vfsops.c  29 May 2016 18:14:12 -0000
@@ -653,7 +653,7 @@ udf_vget(struct mount *mp, ino_t ino, st
        vp->v_data = up;
        vref(ump->um_devvp);
 
-       lockinit(&up->u_lock, PINOD, "unode", 0, 0);
+       rrw_init(&up->u_lock, "unode");
 
        /*
         * udf_hashins() will lock the vnode for us.
Index: sys/isofs/udf/udf_vnops.c
===================================================================
RCS file: /cvs/src/sys/isofs/udf/udf_vnops.c,v
retrieving revision 1.63
diff -u -p -r1.63 udf_vnops.c
--- sys/isofs/udf/udf_vnops.c   19 Mar 2016 12:04:15 -0000      1.63
+++ sys/isofs/udf/udf_vnops.c   29 May 2016 18:14:12 -0000
@@ -898,20 +898,19 @@ int
 udf_lock(void *v)
 {
        struct vop_lock_args *ap = v;
-
        struct vnode *vp = ap->a_vp;
 
-       return (lockmgr(&VTOU(vp)->u_lock, ap->a_flags, NULL));
+       return rrw_enter(&VTOU(vp)->u_lock, ap->a_flags & LK_RWFLAGS);
 }
 
 int
 udf_unlock(void *v)
 {
        struct vop_unlock_args *ap = v;
-
        struct vnode *vp = ap->a_vp;
 
-       return (lockmgr(&VTOU(vp)->u_lock, LK_RELEASE, NULL));
+       rrw_exit(&VTOU(vp)->u_lock);
+       return 0;
 }
 
 int
@@ -919,7 +918,7 @@ udf_islocked(void *v)
 {
        struct vop_islocked_args *ap = v;
 
-       return (lockstatus(&VTOU(ap->a_vp)->u_lock));
+       return rrw_status(&VTOU(ap->a_vp)->u_lock);
 }
 
 int
Index: sys/kern/kern_lock.c
===================================================================
RCS file: /cvs/src/sys/kern/kern_lock.c,v
retrieving revision 1.46
diff -u -p -r1.46 kern_lock.c
--- sys/kern/kern_lock.c        14 Sep 2014 14:17:25 -0000      1.46
+++ sys/kern/kern_lock.c        29 May 2016 18:14:12 -0000
@@ -45,63 +45,6 @@
 int __mp_lock_spinout = 200000000;
 #endif
 
-/*
- * Initialize a lock; required before use.
- */
-void
-lockinit(struct lock *lkp, int prio, char *wmesg, int timo, int flags)
-{
-       KASSERT(flags == 0);
-
-       memset(lkp, 0, sizeof(struct lock));
-       rrw_init(&lkp->lk_lck, wmesg);
-}
-
-int
-lockstatus(struct lock *lkp)
-{
-       switch (rrw_status(&lkp->lk_lck)) {
-       case RW_WRITE:
-               return (LK_EXCLUSIVE);
-       case RW_WRITE_OTHER:
-               return (LK_EXCLOTHER);
-       case RW_READ:
-               return (LK_SHARED);
-       case 0:
-       default:
-               return (0);
-       }
-}
-
-int
-lockmgr(struct lock *lkp, u_int flags, void *notused)
-{
-       int rwflags = 0;
-
-       KASSERT(!((flags & (LK_SHARED|LK_EXCLUSIVE)) ==
-           (LK_SHARED|LK_EXCLUSIVE)));
-       KASSERT(!((flags & (LK_CANRECURSE|LK_RECURSEFAIL)) ==
-           (LK_CANRECURSE|LK_RECURSEFAIL)));
-       KASSERT((flags & LK_RELEASE) ||
-           (flags & (LK_SHARED|LK_EXCLUSIVE|LK_DRAIN)));
-
-       if (flags & LK_RELEASE) {
-               rrw_exit(&lkp->lk_lck);
-               return (0);
-       }
-       if (flags & LK_SHARED)
-               rwflags |= RW_READ;
-       if (flags & (LK_EXCLUSIVE|LK_DRAIN))
-               rwflags |= RW_WRITE;
-       if (flags & LK_RECURSEFAIL)
-               rwflags |= RW_RECURSEFAIL;
-       if (flags & LK_NOWAIT)
-               rwflags |= RW_NOSLEEP;
-
-       return (rrw_enter(&lkp->lk_lck, rwflags));
-
-}
-
 #if defined(MULTIPROCESSOR)
 /*
  * Functions for manipulating the kernel_lock.  We put them here
Index: sys/kern/vfs_subr.c
===================================================================
RCS file: /cvs/src/sys/kern/vfs_subr.c,v
retrieving revision 1.247
diff -u -p -r1.247 vfs_subr.c
--- sys/kern/vfs_subr.c 26 May 2016 16:03:29 -0000      1.247
+++ sys/kern/vfs_subr.c 29 May 2016 18:14:12 -0000
@@ -957,7 +957,7 @@ vclean(struct vnode *vp, int flags, stru
         * For active vnodes, it ensures that no other activity can
         * occur while the underlying object is being cleaned out.
         */
-       VOP_LOCK(vp, LK_DRAIN, p);
+       VOP_LOCK(vp, LK_DRAIN | LK_EXCLUSIVE, p);
 
        /*
         * Clean out any VM data associated with the vnode.
Index: sys/kern/vfs_vnops.c
===================================================================
RCS file: /cvs/src/sys/kern/vfs_vnops.c,v
retrieving revision 1.84
diff -u -p -r1.84 vfs_vnops.c
--- sys/kern/vfs_vnops.c        19 Mar 2016 12:04:15 -0000      1.84
+++ sys/kern/vfs_vnops.c        29 May 2016 18:14:12 -0000
@@ -513,9 +513,6 @@ vn_lock(struct vnode *vp, int flags, str
 {
        int error;
 
-       if ((flags & LK_RECURSEFAIL) == 0)
-               flags |= LK_CANRECURSE;
-       
        do {
                if (vp->v_flag & VXLOCK) {
                        vp->v_flag |= VXWANT;
Index: sys/miscfs/fuse/fuse_vfsops.c
===================================================================
RCS file: /cvs/src/sys/miscfs/fuse/fuse_vfsops.c,v
retrieving revision 1.22
diff -u -p -r1.22 fuse_vfsops.c
--- sys/miscfs/fuse/fuse_vfsops.c       26 May 2016 16:03:29 -0000      1.22
+++ sys/miscfs/fuse/fuse_vfsops.c       29 May 2016 18:14:12 -0000
@@ -270,7 +270,7 @@ retry:
        }
 
        ip = malloc(sizeof(*ip), M_FUSEFS, M_WAITOK | M_ZERO);
-       lockinit(&ip->ufs_ino.i_lock, PINOD, "fuseinode", 0, 0);
+       rrw_init(&ip->ufs_ino.i_lock, "fuseinode");
        nvp->v_data = ip;
        ip->ufs_ino.i_vnode = nvp;
        ip->ufs_ino.i_dev = fmp->dev;
Index: sys/miscfs/fuse/fuse_vnops.c
===================================================================
RCS file: /cvs/src/sys/miscfs/fuse/fuse_vnops.c,v
retrieving revision 1.27
diff -u -p -r1.27 fuse_vnops.c
--- sys/miscfs/fuse/fuse_vnops.c        19 Mar 2016 12:04:15 -0000      1.27
+++ sys/miscfs/fuse/fuse_vnops.c        29 May 2016 18:14:12 -0000
@@ -1473,7 +1473,7 @@ fusefs_lock(void *v)
        struct vop_lock_args *ap = v;
        struct vnode *vp = ap->a_vp;
 
-       return (lockmgr(&VTOI(vp)->ufs_ino.i_lock, ap->a_flags, NULL));
+       return rrw_enter(&VTOI(vp)->ufs_ino.i_lock, ap->a_flags & LK_RWFLAGS);
 }
 
 int
@@ -1482,7 +1482,8 @@ fusefs_unlock(void *v)
        struct vop_unlock_args *ap = v;
        struct vnode *vp = ap->a_vp;
 
-       return (lockmgr(&VTOI(vp)->ufs_ino.i_lock, LK_RELEASE, NULL));
+       rrw_exit(&VTOI(vp)->ufs_ino.i_lock);
+       return 0;
 }
 
 int
@@ -1490,7 +1491,7 @@ fusefs_islocked(void *v)
 {
        struct vop_islocked_args *ap = v;
 
-       return (lockstatus(&VTOI(ap->a_vp)->ufs_ino.i_lock));
+       return rrw_status(&VTOI(ap->a_vp)->ufs_ino.i_lock);
 }
 
 int
Index: sys/msdosfs/denode.h
===================================================================
RCS file: /cvs/src/sys/msdosfs/denode.h,v
retrieving revision 1.28
diff -u -p -r1.28 denode.h
--- sys/msdosfs/denode.h        13 Jan 2016 10:00:55 -0000      1.28
+++ sys/msdosfs/denode.h        29 May 2016 18:14:12 -0000
@@ -149,7 +149,7 @@ struct denode {
        long de_refcnt;         /* reference count */
        struct msdosfsmount *de_pmp;    /* addr of our mount struct */
        struct lockf *de_lockf; /* byte level lock list */
-       struct lock de_lock;    /* denode lock */
+       struct rrwlock de_lock; /* denode lock */
        u_char de_Name[11];     /* name, from DOS directory entry */
        u_char de_Attributes;   /* attributes, from directory entry */
        u_char de_CTimeHundredth; /* creation time, 1/100th of a sec */
Index: sys/msdosfs/msdosfs_denode.c
===================================================================
RCS file: /cvs/src/sys/msdosfs/msdosfs_denode.c,v
retrieving revision 1.56
diff -u -p -r1.56 msdosfs_denode.c
--- sys/msdosfs/msdosfs_denode.c        19 Mar 2016 12:04:16 -0000      1.56
+++ sys/msdosfs/msdosfs_denode.c        29 May 2016 18:14:12 -0000
@@ -233,7 +233,7 @@ retry:
                return (error);
        }
        ldep = malloc(sizeof(*ldep), M_MSDOSFSNODE, M_WAITOK | M_ZERO);
-       lockinit(&ldep->de_lock, PINOD, "denode", 0, 0);
+       rrw_init(&ldep->de_lock, "denode");
        nvp->v_data = ldep;
        ldep->de_vnode = nvp;
        ldep->de_flag = 0;
Index: sys/msdosfs/msdosfs_vnops.c
===================================================================
RCS file: /cvs/src/sys/msdosfs/msdosfs_vnops.c,v
retrieving revision 1.111
diff -u -p -r1.111 msdosfs_vnops.c
--- sys/msdosfs/msdosfs_vnops.c 21 May 2016 18:11:36 -0000      1.111
+++ sys/msdosfs/msdosfs_vnops.c 29 May 2016 18:14:12 -0000
@@ -1721,7 +1721,7 @@ msdosfs_lock(void *v)
        struct vop_lock_args *ap = v;
        struct vnode *vp = ap->a_vp;
 
-       return (lockmgr(&VTODE(vp)->de_lock, ap->a_flags, NULL));
+       return rrw_enter(&VTODE(vp)->de_lock, ap->a_flags & LK_RWFLAGS);
 }
 
 int
@@ -1730,7 +1730,8 @@ msdosfs_unlock(void *v)
        struct vop_unlock_args *ap = v;
        struct vnode *vp = ap->a_vp;
 
-       return (lockmgr(&VTODE(vp)->de_lock, LK_RELEASE, NULL));
+       rrw_exit(&VTODE(vp)->de_lock);
+       return 0;
 }
 
 int
@@ -1738,7 +1739,7 @@ msdosfs_islocked(void *v)
 {
        struct vop_islocked_args *ap = v;
 
-       return (lockstatus(&VTODE(ap->a_vp)->de_lock));
+       return rrw_status(&VTODE(ap->a_vp)->de_lock);
 }
 
 /*
Index: sys/ntfs/ntfs_vfsops.c
===================================================================
RCS file: /cvs/src/sys/ntfs/ntfs_vfsops.c,v
retrieving revision 1.51
diff -u -p -r1.51 ntfs_vfsops.c
--- sys/ntfs/ntfs_vfsops.c      22 May 2016 20:27:04 -0000      1.51
+++ sys/ntfs/ntfs_vfsops.c      29 May 2016 18:14:12 -0000
@@ -522,7 +522,7 @@ ntfs_unmount(struct mount *mp, int mntfl
                ntmp->ntm_devvp->v_specmountpoint = NULL;
 
        /* lock the device vnode before calling VOP_CLOSE() */
-       VOP_LOCK(ntmp->ntm_devvp, LK_EXCLUSIVE | LK_RETRY, p);
+       vn_lock(ntmp->ntm_devvp, LK_EXCLUSIVE | LK_RETRY, p);
        vinvalbuf(ntmp->ntm_devvp, V_SAVE, NOCRED, p, 0, 0);
        (void)VOP_CLOSE(ntmp->ntm_devvp, ronly ? FREAD : FREAD|FWRITE,
            NOCRED, p);
Index: sys/sys/lock.h
===================================================================
RCS file: /cvs/src/sys/sys/lock.h,v
retrieving revision 1.26
diff -u -p -r1.26 lock.h
--- sys/sys/lock.h      23 Sep 2015 15:37:26 -0000      1.26
+++ sys/sys/lock.h      29 May 2016 18:14:12 -0000
@@ -40,25 +40,16 @@
 
 #include <sys/rwlock.h>
 
-struct lock {
-       struct rrwlock  lk_lck;
-};
+#define LK_EXCLUSIVE   RW_WRITE        /* exclusive lock */
+#define LK_SHARED      RW_READ         /* shared lock */
+#define LK_TYPE_MASK   (RW_WRITE|RW_READ) /* type of lock sought */
+#define LK_NOWAIT      RW_NOSLEEP      /* do not sleep to await lock */
+#define LK_RECURSEFAIL RW_RECURSEFAIL  /* fail if recursive exclusive lock */
+#define LK_EXCLOTHER   RW_WRITE_OTHER  /* exclusive lock held by some other 
thread */
+#define LK_RWFLAGS     
(RW_WRITE|RW_READ|RW_NOSLEEP|RW_RECURSEFAIL|RW_WRITE_OTHER)
 
-#define LK_SHARED      0x01    /* shared lock */
-#define LK_EXCLUSIVE   0x02    /* exclusive lock */
-#define LK_TYPE_MASK   0x03    /* type of lock sought */
-#define LK_DRAIN       0x04    /* wait for all lock activity to end */
-#define LK_RELEASE     0x08    /* release any type of lock */
-#define LK_NOWAIT      0x10    /* do not sleep to await lock */
-#define LK_CANRECURSE  0x20    /* allow recursive exclusive lock */
-#define LK_RECURSEFAIL 0x40    /* fail if recursive exclusive lock */
-#define LK_RETRY       0x80    /* vn_lock: retry until locked */
-
-/* for lockstatus() only */
-#define LK_EXCLOTHER   0x100   /* exclusive lock held by some other thread */
-
-void   lockinit(struct lock *, int, char *, int, int);
-int    lockmgr(struct lock *, u_int flags, void *);
-int    lockstatus(struct lock *);
+/* LK_ specific */
+#define LK_DRAIN       0x1000UL        /* wait for all lock activity to end */
+#define LK_RETRY       0x2000UL        /* vn_lock: retry until locked */
 
 #endif /* !_LOCK_H_ */
Index: sys/tmpfs/tmpfs.h
===================================================================
RCS file: /cvs/src/sys/tmpfs/tmpfs.h,v
retrieving revision 1.7
diff -u -p -r1.7 tmpfs.h
--- sys/tmpfs/tmpfs.h   17 Dec 2014 19:42:15 -0000      1.7
+++ sys/tmpfs/tmpfs.h   29 May 2016 18:14:12 -0000
@@ -94,7 +94,7 @@ typedef struct tmpfs_node {
         * no vnode has been allocated or it has been reclaimed).
         */
        struct rwlock           tn_nlock;       /* node lock */
-       struct lock             tn_vlock;       /* vnode lock */
+       struct rrwlock          tn_vlock;       /* vnode lock */
        struct vnode *          tn_vnode;
 
        /* Directory entry.  Only a hint, since hard link can have multiple. */
Index: sys/tmpfs/tmpfs_subr.c
===================================================================
RCS file: /cvs/src/sys/tmpfs/tmpfs_subr.c,v
retrieving revision 1.15
diff -u -p -r1.15 tmpfs_subr.c
--- sys/tmpfs/tmpfs_subr.c      6 Feb 2016 16:10:23 -0000       1.15
+++ sys/tmpfs/tmpfs_subr.c      29 May 2016 18:14:12 -0000
@@ -314,7 +314,7 @@ again:
                return error;
        }
 
-       lockinit(&node->tn_vlock, PINOD, "tnode", 0, 0);
+       rrw_init(&node->tn_vlock, "tnode");
        vp->v_type = node->tn_type;
 
        /* Type-specific initialization. */
Index: sys/tmpfs/tmpfs_vnops.c
===================================================================
RCS file: /cvs/src/sys/tmpfs/tmpfs_vnops.c,v
retrieving revision 1.26
diff -u -p -r1.26 tmpfs_vnops.c
--- sys/tmpfs/tmpfs_vnops.c     2 May 2016 20:06:58 -0000       1.26
+++ sys/tmpfs/tmpfs_vnops.c     29 May 2016 18:14:12 -0000
@@ -1194,7 +1194,7 @@ tmpfs_lock(void *v)
        struct vop_lock_args *ap = v;
        tmpfs_node_t *tnp = VP_TO_TMPFS_NODE(ap->a_vp);
 
-       return lockmgr(&tnp->tn_vlock, ap->a_flags, NULL);
+       return rrw_enter(&tnp->tn_vlock, ap->a_flags & LK_RWFLAGS);
 }
 
 int
@@ -1203,7 +1203,8 @@ tmpfs_unlock(void *v)
        struct vop_unlock_args *ap = v;
        tmpfs_node_t *tnp = VP_TO_TMPFS_NODE(ap->a_vp);
 
-       return lockmgr(&tnp->tn_vlock, LK_RELEASE, NULL);
+       rrw_exit(&tnp->tn_vlock);
+       return 0;
 }
 
 int
@@ -1212,7 +1213,7 @@ tmpfs_islocked(void *v)
        struct vop_islocked_args *ap = v;
        tmpfs_node_t *tnp = VP_TO_TMPFS_NODE(ap->a_vp);
 
-       return lockstatus(&tnp->tn_vlock);
+       return rrw_status(&tnp->tn_vlock);
 }
 
 /*
Index: sys/ufs/ext2fs/ext2fs_vfsops.c
===================================================================
RCS file: /cvs/src/sys/ufs/ext2fs/ext2fs_vfsops.c,v
retrieving revision 1.91
diff -u -p -r1.91 ext2fs_vfsops.c
--- sys/ufs/ext2fs/ext2fs_vfsops.c      22 May 2016 20:27:04 -0000      1.91
+++ sys/ufs/ext2fs/ext2fs_vfsops.c      29 May 2016 18:14:12 -0000
@@ -843,7 +843,7 @@ ext2fs_vget(struct mount *mp, ino_t ino,
        }
 
        ip = pool_get(&ext2fs_inode_pool, PR_WAITOK|PR_ZERO);
-       lockinit(&ip->i_lock, PINOD, "inode", 0, 0);
+       rrw_init(&ip->i_lock, "inode");
        vp->v_data = ip;
        ip->i_vnode = vp;
        ip->i_ump = ump;
Index: sys/ufs/ffs/ffs_vfsops.c
===================================================================
RCS file: /cvs/src/sys/ufs/ffs/ffs_vfsops.c,v
retrieving revision 1.158
diff -u -p -r1.158 ffs_vfsops.c
--- sys/ufs/ffs/ffs_vfsops.c    23 May 2016 09:31:28 -0000      1.158
+++ sys/ufs/ffs/ffs_vfsops.c    29 May 2016 18:14:12 -0000
@@ -1295,7 +1295,7 @@ retry:
        vp->v_flag |= VLOCKSWORK;
 #endif
        ip = pool_get(&ffs_ino_pool, PR_WAITOK|PR_ZERO);
-       lockinit(&ip->i_lock, PINOD, "inode", 0, 0);
+       rrw_init(&ip->i_lock, "inode");
        ip->i_ump = ump;
        vref(ip->i_devvp);
        vp->v_data = ip;
Index: sys/ufs/ufs/inode.h
===================================================================
RCS file: /cvs/src/sys/ufs/ufs/inode.h,v
retrieving revision 1.49
diff -u -p -r1.49 inode.h
--- sys/ufs/ufs/inode.h 14 Jul 2014 08:54:13 -0000      1.49
+++ sys/ufs/ufs/inode.h 29 May 2016 18:14:12 -0000
@@ -86,7 +86,7 @@ struct inode {
        struct   dquot *i_dquot[MAXQUOTAS]; /* Dquot structures. */
        u_quad_t i_modrev;      /* Revision level for NFS lease. */
        struct   lockf *i_lockf;/* Head of byte-level lock list. */
-       struct   lock i_lock;   /* Inode lock */
+       struct   rrwlock i_lock;/* Inode lock */
 
        /*
         * Side effects; used during directory lookup.
Index: sys/ufs/ufs/ufs_ihash.c
===================================================================
RCS file: /cvs/src/sys/ufs/ufs/ufs_ihash.c,v
retrieving revision 1.22
diff -u -p -r1.22 ufs_ihash.c
--- sys/ufs/ufs/ufs_ihash.c     14 Mar 2015 03:38:53 -0000      1.22
+++ sys/ufs/ufs/ufs_ihash.c     29 May 2016 18:14:12 -0000
@@ -138,7 +138,7 @@ ufs_ihashins(struct inode *ip)
        ufsino_t inum = ip->i_number;
 
        /* lock the inode, then put it on the appropriate hash list */
-       lockmgr(&ip->i_lock, LK_EXCLUSIVE, NULL);
+       rrw_enter(&ip->i_lock, RW_WRITE);
 
        /* XXXLOCKING lock hash list */
 
@@ -146,7 +146,7 @@ ufs_ihashins(struct inode *ip)
        LIST_FOREACH(curip, ipp, i_hash) {
                if (inum == curip->i_number && dev == curip->i_dev) {
                        /* XXXLOCKING unlock hash list? */
-                       lockmgr(&ip->i_lock, LK_RELEASE, NULL);
+                       rrw_exit(&ip->i_lock);
                        return (EEXIST);
                }
        }
Index: sys/ufs/ufs/ufs_vnops.c
===================================================================
RCS file: /cvs/src/sys/ufs/ufs/ufs_vnops.c,v
retrieving revision 1.127
diff -u -p -r1.127 ufs_vnops.c
--- sys/ufs/ufs/ufs_vnops.c     19 Mar 2016 12:04:16 -0000      1.127
+++ sys/ufs/ufs/ufs_vnops.c     29 May 2016 18:14:12 -0000
@@ -1538,7 +1538,7 @@ ufs_lock(void *v)
        struct vop_lock_args *ap = v;
        struct vnode *vp = ap->a_vp;
 
-       return (lockmgr(&VTOI(vp)->i_lock, ap->a_flags, NULL));
+       return rrw_enter(&VTOI(vp)->i_lock, ap->a_flags & LK_RWFLAGS);
 }
 
 /*
@@ -1550,7 +1550,8 @@ ufs_unlock(void *v)
        struct vop_unlock_args *ap = v;
        struct vnode *vp = ap->a_vp;
 
-       return (lockmgr(&VTOI(vp)->i_lock, LK_RELEASE, NULL));
+       rrw_exit(&VTOI(vp)->i_lock);
+       return 0;
 }
 
 /*
@@ -1561,7 +1562,7 @@ ufs_islocked(void *v)
 {
        struct vop_islocked_args *ap = v;
 
-       return (lockstatus(&VTOI(ap->a_vp)->i_lock));
+       return rrw_status(&VTOI(ap->a_vp)->i_lock);
 }
 
 /*

cvs rm share/man/man9/lock.9

Reply via email to