tech-kern archive

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

Removal of recursive vnode locks



With mount_domount() the last consumer of recursive vnode locks has left.

I propose to completely remove the concept of recursive vnode locks by
eliminating vn_setrecurse(), vn_restorerecurse() and LK_CANRECURSE.

A diff is attached.

Comments or objections anyone?

-- 
Juergen Hannken-Illjes - hannken%eis.cs.tu-bs.de@localhost - TU Braunschweig 
(Germany)


Index: distrib/sets/lists/comp/mi
===================================================================
RCS file: /cvsroot/src/distrib/sets/lists/comp/mi,v
retrieving revision 1.1466
diff -p -u -4 -r1.1466 mi
--- distrib/sets/lists/comp/mi  14 Jun 2010 14:50:47 -0000      1.1466
+++ distrib/sets/lists/comp/mi  15 Jun 2010 19:18:01 -0000
@@ -9878,10 +9878,10 @@
 ./usr/share/man/cat9/vn_open.0                 comp-sys-catman         .cat
 ./usr/share/man/cat9/vn_poll.0                 comp-sys-catman         .cat
 ./usr/share/man/cat9/vn_rdwr.0                 comp-sys-catman         .cat
 ./usr/share/man/cat9/vn_read.0                 comp-sys-catman         .cat
-./usr/share/man/cat9/vn_restorerecurse.0       comp-sys-catman         .cat
-./usr/share/man/cat9/vn_setrecurse.0           comp-sys-catman         .cat
+./usr/share/man/cat9/vn_restorerecurse.0       comp-sys-catman         obsolete
+./usr/share/man/cat9/vn_setrecurse.0           comp-sys-catman         obsolete
 ./usr/share/man/cat9/vn_start_write.0          comp-obsolete           obsolete
 ./usr/share/man/cat9/vn_stat.0                 comp-sys-catman         .cat
 ./usr/share/man/cat9/vn_statfile.0             comp-sys-catman         .cat
 ./usr/share/man/cat9/vn_write.0                        comp-sys-catman         
.cat
@@ -15580,10 +15580,10 @@
 ./usr/share/man/html9/vn_open.html             comp-sys-htmlman        html
 ./usr/share/man/html9/vn_poll.html             comp-sys-htmlman        html
 ./usr/share/man/html9/vn_rdwr.html             comp-sys-htmlman        html
 ./usr/share/man/html9/vn_read.html             comp-sys-htmlman        html
-./usr/share/man/html9/vn_restorerecurse.html   comp-sys-htmlman        html
-./usr/share/man/html9/vn_setrecurse.html       comp-sys-htmlman        html
+./usr/share/man/html9/vn_restorerecurse.html   comp-sys-htmlman        obsolete
+./usr/share/man/html9/vn_setrecurse.html       comp-sys-htmlman        obsolete
 ./usr/share/man/html9/vn_stat.html             comp-sys-htmlman        html
 ./usr/share/man/html9/vn_statfile.html         comp-sys-htmlman        html
 ./usr/share/man/html9/vn_write.html            comp-sys-htmlman        html
 ./usr/share/man/html9/vn_writechk.html         comp-sys-htmlman        html
@@ -21535,10 +21535,10 @@
 ./usr/share/man/man9/vn_open.9                 comp-sys-man            .man
 ./usr/share/man/man9/vn_poll.9                 comp-sys-man            .man
 ./usr/share/man/man9/vn_rdwr.9                 comp-sys-man            .man
 ./usr/share/man/man9/vn_read.9                 comp-sys-man            .man
-./usr/share/man/man9/vn_restorerecurse.9       comp-sys-man            .man
-./usr/share/man/man9/vn_setrecurse.9           comp-sys-man            .man
+./usr/share/man/man9/vn_restorerecurse.9       comp-sys-man            obsolete
+./usr/share/man/man9/vn_setrecurse.9           comp-sys-man            obsolete
 ./usr/share/man/man9/vn_start_write.9          comp-obsolete           obsolete
 ./usr/share/man/man9/vn_stat.9                 comp-sys-man            .man
 ./usr/share/man/man9/vn_statfile.9             comp-sys-man            .man
 ./usr/share/man/man9/vn_write.9                        comp-sys-man            
.man
Index: doc/CHANGES
===================================================================
RCS file: /cvsroot/src/doc/CHANGES,v
retrieving revision 1.1402
diff -p -u -4 -r1.1402 CHANGES
--- doc/CHANGES 9 Jun 2010 05:00:25 -0000       1.1402
+++ doc/CHANGES 15 Jun 2010 19:18:12 -0000
@@ -627,4 +627,5 @@ Changes from NetBSD 5.0 to NetBSD 6.0:
        vnode(9): Remove member v_vnlock. [hannken 20100605]
        acpi(4): Updated ACPICA to 20100528. [jruoho 20100606]
        ofppc: Support Gigabit Ethernet Controller for MV64361 on PegasosII
                by mvgbe@gt.  [kiyohara 20100609]
+       vnsubr(9): Remove recursive vnode locks. [hannken 20100615]
Index: share/man/man9/Makefile
===================================================================
RCS file: /cvsroot/src/share/man/man9/Makefile,v
retrieving revision 1.332
diff -p -u -4 -r1.332 Makefile
--- share/man/man9/Makefile     8 Jun 2010 05:40:27 -0000       1.332
+++ share/man/man9/Makefile     15 Jun 2010 19:20:07 -0000
@@ -867,11 +867,9 @@ MLINKS+=vnsubr.9 vn_bwrite.9 \
        vnsubr.9 vn_isunder.9 \
        vnsubr.9 vn_lock.9 \
        vnsubr.9 vn_markexec.9 \
        vnsubr.9 vn_marktext.9 \
-       vnsubr.9 vn_restorerecurse.9 \
        vnsubr.9 vn_rdwr.9 \
-       vnsubr.9 vn_setrecurse.9 \
        vnsubr.9 vn_stat.9 \
        vnsubr.9 vn_open.9 \
        vnsubr.9 vn_writechk.9
 MLINKS+=workqueue.9 workqueue_create.9 \
Index: share/man/man9/vnsubr.9
===================================================================
RCS file: /cvsroot/src/share/man/man9/vnsubr.9,v
retrieving revision 1.38
diff -p -u -4 -r1.38 vnsubr.9
--- share/man/man9/vnsubr.9     2 Jun 2009 18:09:34 -0000       1.38
+++ share/man/man9/vnsubr.9     15 Jun 2010 19:20:08 -0000
@@ -26,9 +26,9 @@
 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd June 2, 2009
+.Dd June 16, 2010
 .Dt VNSUBR 9
 .Os
 .Sh NAME
 .Nm vnsubr ,
@@ -39,10 +39,8 @@
 .Nm vn_lock ,
 .Nm vn_markexec ,
 .Nm vn_marktext ,
 .Nm vn_rdwr ,
-.Nm vn_restorerecurse ,
-.Nm vn_setrecurse ,
 .Nm vn_open ,
 .Nm vn_stat ,
 .Nm vn_writechk
 .Nd high-level convenience functions for vnode operations
@@ -63,12 +61,8 @@
 .Ft void
 .Fn vn_markexec "struct vnode *vp"
 .Ft void
 .Fn vn_marktext "struct vnode *vp"
-.Ft u_int
-.Fn vn_setrecurse "struct vnode *vp"
-.Ft void
-.Fn vn_restorerecurse "struct vnode *vp" "u_int flags"
 .Ft int
 .Fn vn_open "struct nameidata *ndp" "int fmode" "int cmode"
 .Ft int
 .Fo vn_rdwr
@@ -154,22 +148,8 @@ as containing executable code of a runni
 .It Fn vn_marktext "vp"
 Common code to mark the vnode
 .Fa vp
 as being the text of a running process.
-.It Fn vn_setrecurse "vp"
-Common code to enable
-.Dv LK_CANRECURSE
-on the vnode lock for vnode
-.Fa vp .
-.Fn vn_setrecurse
-returns the new
-.Xr lockmgr 9
-flags after the update.
-.It Fn vn_restorerecurse "vp" "flags"
-Common code to restore the vnode lock flags for the vnode
-.Fa vp .
-It is called when done with
-.Fn vn_setrecurse .
 .It Fn vn_open "ndp" "fmode" "cmode"
 Common code for vnode open operations.
 The pathname is described in the nameidata pointer (see
 .Xr namei 9 ) .
Index: sys/fs/unionfs/unionfs_subr.c
===================================================================
RCS file: /cvsroot/src/sys/fs/unionfs/unionfs_subr.c,v
retrieving revision 1.6
diff -p -u -4 -r1.6 unionfs_subr.c
--- sys/fs/unionfs/unionfs_subr.c       6 Jun 2010 08:01:31 -0000       1.6
+++ sys/fs/unionfs/unionfs_subr.c       15 Jun 2010 19:20:43 -0000
@@ -472,9 +472,8 @@ unionfs_relookup_for_rename(struct vnode
  */
 static void
 unionfs_node_update(struct unionfs_node *unp, struct vnode *uvp)
 {
-       int             count, lockcnt;
        struct vnode   *vp;
        struct vnode   *lvp;
 
        vp = UNIONFSTOV(unp);
@@ -484,15 +483,11 @@ unionfs_node_update(struct unionfs_node 
         * lock update
         */
        mutex_enter(&vp->v_interlock);
        unp->un_uppervp = uvp;
-       lockcnt = lvp->v_lock.vl_recursecnt +
-           rw_write_held(&lvp->v_lock.vl_lock);
-       if (lockcnt <= 0)
+       if (! rw_write_held(&lvp->v_lock.vl_lock))
                panic("unionfs: no exclusive lock");
        mutex_exit(&vp->v_interlock);
-       for (count = 1; count < lockcnt; count++)
-               vn_lock(uvp, LK_EXCLUSIVE | LK_CANRECURSE | LK_RETRY);
 }
 
 /*
  * Create a new shadow dir.
Index: sys/kern/vfs_subr.c
===================================================================
RCS file: /cvsroot/src/sys/kern/vfs_subr.c,v
retrieving revision 1.404
diff -p -u -4 -r1.404 vfs_subr.c
--- sys/kern/vfs_subr.c 6 Jun 2010 08:01:31 -0000       1.404
+++ sys/kern/vfs_subr.c 15 Jun 2010 19:20:44 -0000
@@ -2737,13 +2737,13 @@ vprint(const char *label, struct vnode *
        if (label != NULL)
                printf("%s: ", label);
        printf("vnode @ %p, flags (%s)\n\ttag %s(%d), type %s(%d), "
            "usecount %d, writecount %d, holdcount %d\n"
-           "\tfreelisthd %p, mount %p, data %p lock %p recursecnt %d\n",
+           "\tfreelisthd %p, mount %p, data %p lock %p\n",
            vp, bf, ARRAY_PRINT(vp->v_tag, vnode_tags), vp->v_tag,
            ARRAY_PRINT(vp->v_type, vnode_types), vp->v_type,
            vp->v_usecount, vp->v_writecount, vp->v_holdcnt,
-           vp->v_freelisthd, vp->v_mount, vp->v_data, vl, vl->vl_recursecnt);
+           vp->v_freelisthd, vp->v_mount, vp->v_data, vl);
        if (vp->v_data != NULL) {
                printf("\t");
                VOP_PRINT(vp);
        }
@@ -2927,9 +2927,9 @@ setrootfstime(time_t t)
 int
 vlockmgr(struct vnlock *vl, int flags)
 {
 
-       KASSERT((flags & ~(LK_CANRECURSE | LK_NOWAIT | LK_TYPE_MASK)) == 0);
+       KASSERT((flags & ~(LK_NOWAIT | LK_TYPE_MASK)) == 0);
 
        switch (flags & LK_TYPE_MASK) {
        case LK_SHARED:
                if (rw_tryenter(&vl->vl_lock, RW_READER)) {
@@ -2944,25 +2944,15 @@ vlockmgr(struct vnlock *vl, int flags)
        case LK_EXCLUSIVE:
                if (rw_tryenter(&vl->vl_lock, RW_WRITER)) {
                        return 0;
                }
-               if ((vl->vl_canrecurse || (flags & LK_CANRECURSE) != 0) &&
-                   rw_write_held(&vl->vl_lock)) {
-                       vl->vl_recursecnt++;
-                       return 0;
-               }
                if ((flags & LK_NOWAIT) != 0) {
                        return EBUSY;
                }
                rw_enter(&vl->vl_lock, RW_WRITER);
                return 0;
 
        case LK_RELEASE:
-               if (vl->vl_recursecnt != 0) {
-                       KASSERT(rw_write_held(&vl->vl_lock));
-                       vl->vl_recursecnt--;
-                       return 0;
-               }
                rw_exit(&vl->vl_lock);
                return 0;
 
        default:
Index: sys/kern/vfs_vnops.c
===================================================================
RCS file: /cvsroot/src/sys/kern/vfs_vnops.c,v
retrieving revision 1.172
diff -p -u -4 -r1.172 vfs_vnops.c
--- sys/kern/vfs_vnops.c        6 Jun 2010 08:01:31 -0000       1.172
+++ sys/kern/vfs_vnops.c        15 Jun 2010 19:20:44 -0000
@@ -771,10 +771,9 @@ vn_lock(struct vnode *vp, int flags)
        KASSERT(vp->v_usecount > 0 || (flags & LK_INTERLOCK) != 0
            || (vp->v_iflag & VI_ONWORKLST) != 0);
 #endif
        KASSERT((flags &
-           ~(LK_INTERLOCK|LK_SHARED|LK_EXCLUSIVE|LK_NOWAIT|LK_RETRY|
-           LK_CANRECURSE))
+           ~(LK_INTERLOCK|LK_SHARED|LK_EXCLUSIVE|LK_NOWAIT|LK_RETRY))
            == 0);
 
 #ifdef DIAGNOSTIC
        if (wapbl_vphaswapbl(vp))
@@ -821,30 +820,8 @@ vn_closefile(file_t *fp)
        return vn_close(fp->f_data, fp->f_flag, fp->f_cred);
 }
 
 /*
- * Enable LK_CANRECURSE on lock. Return prior status.
- */
-u_int
-vn_setrecurse(struct vnode *vp)
-{
-
-       atomic_inc_uint(&vp->v_lock.vl_canrecurse);
-
-       return 0;
-}
-
-/*
- * Called when done with locksetrecurse.
- */
-void
-vn_restorerecurse(struct vnode *vp, u_int flags)
-{
-
-       atomic_dec_uint(&vp->v_lock.vl_canrecurse);
-}
-
-/*
  * Simplified in-kernel wrapper calls for extended attribute access.
  * Both calls pass in a NULL credential, authorizing a "kernel" access.
  * Set IO_NODELOCKED in ioflg if the vnode is already locked.
  */
Index: sys/sys/lock.h
===================================================================
RCS file: /cvsroot/src/sys/sys/lock.h,v
retrieving revision 1.83
diff -p -u -4 -r1.83 lock.h
--- sys/sys/lock.h      28 Apr 2008 20:24:10 -0000      1.83
+++ sys/sys/lock.h      15 Jun 2010 19:20:48 -0000
@@ -79,9 +79,8 @@
 #define        LK_RELEASE      0x00000006      /* release any type of lock */
 #define        LK_EXCLOTHER    0x00000008      /* other process holds lock */
 
 #define        LK_NOWAIT       0x00000010      /* do not sleep to await lock */
-#define        LK_CANRECURSE   0x00000040      /* this may be recursive lock 
attempt */
 #define        LK_INTERLOCK    0x00010000      /* unlock passed simple lock 
after
                                           getting lk_interlock */
 #define        LK_RETRY        0x00020000      /* vn_lock: retry until locked 
*/
 
Index: sys/sys/param.h
===================================================================
RCS file: /cvsroot/src/sys/sys/param.h,v
retrieving revision 1.365
diff -p -u -4 -r1.365 param.h
--- sys/sys/param.h     6 Jun 2010 08:01:32 -0000       1.365
+++ sys/sys/param.h     15 Jun 2010 19:20:48 -0000
@@ -62,9 +62,9 @@
  *     NetBSD-2.0H     (200080000) was changed on 20041001 to:
  *     2.99.9          (299000900)
  */
 
-#define        __NetBSD_Version__      599003000       /* NetBSD 5.99.30 */
+#define        __NetBSD_Version__      599003100       /* NetBSD 5.99.31 */
 
 #define __NetBSD_Prereq__(M,m,p) (((((M) * 100000000) + \
     (m) * 1000000) + (p) * 100) <= __NetBSD_Version__)
 
Index: sys/sys/vnode.h
===================================================================
RCS file: /cvsroot/src/sys/sys/vnode.h,v
retrieving revision 1.219
diff -p -u -4 -r1.219 vnode.h
--- sys/sys/vnode.h     6 Jun 2010 08:01:32 -0000       1.219
+++ sys/sys/vnode.h     15 Jun 2010 19:20:49 -0000
@@ -123,10 +123,8 @@ LIST_HEAD(buflists, buf);
 TAILQ_HEAD(vnodelst, vnode);
 
 struct vnlock {
        krwlock_t       vl_lock;
-       u_int           vl_canrecurse;
-       u_int           vl_recursecnt;
 };
 
 /*
  * Reading or writing any of these items requires holding the appropriate
@@ -615,10 +613,8 @@ int        vn_open(struct nameidata *, int, in
 int    vn_rdwr(enum uio_rw, struct vnode *, void *, int, off_t, enum uio_seg,
     int, kauth_cred_t, size_t *, struct lwp *);
 int    vn_readdir(struct file *, char *, int, u_int, int *, struct lwp *,
     off_t **, int *);
-void   vn_restorerecurse(struct vnode *, u_int);
-u_int  vn_setrecurse(struct vnode *);
 int    vn_stat(struct vnode *, struct stat *);
 int    vn_kqfilter(struct file *, struct knote *);
 int    vn_writechk(struct vnode *);
 int    vn_openchk(struct vnode *, kauth_cred_t, int);


Home | Main Index | Thread Index | Old Index