Source-Changes-HG archive

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

[src/trunk]: src/sys Make vget always return vnode unlocked.



details:   https://anonhg.NetBSD.org/src/rev/6742af8699d5
branches:  trunk
changeset: 337572:6742af8699d5
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Mon Apr 20 13:44:16 2015 +0000

description:
Make vget always return vnode unlocked.

Convert callers who want locks to use vn_lock afterward.

Add extra argument so the compiler will report stragglers.

diffstat:

 sys/fs/adosfs/advfsops.c       |   6 +++---
 sys/fs/tmpfs/tmpfs_subr.c      |   7 ++++---
 sys/fs/udf/udf_subr.c          |  14 +++++++++++---
 sys/fs/union/union_subr.c      |   6 +++---
 sys/kern/vfs_cache.c           |  10 +++++-----
 sys/kern/vfs_mount.c           |   6 +++---
 sys/kern/vfs_vnode.c           |  19 +++++++------------
 sys/miscfs/specfs/spec_vnops.c |   8 ++++----
 sys/miscfs/syncfs/sync_subr.c  |  20 +++++++++++++-------
 sys/sys/vnode.h                |   4 ++--
 sys/ufs/lfs/lfs_segment.c      |   6 +++---
 sys/ufs/lfs/lfs_syscalls.c     |   9 +++++----
 sys/ufs/lfs/ulfs_ihash.c       |  14 +++++++++++---
 13 files changed, 74 insertions(+), 55 deletions(-)

diffs (truncated from 464 to 300 lines):

diff -r 80938c06a01a -r 6742af8699d5 sys/fs/adosfs/advfsops.c
--- a/sys/fs/adosfs/advfsops.c  Mon Apr 20 13:12:24 2015 +0000
+++ b/sys/fs/adosfs/advfsops.c  Mon Apr 20 13:44:16 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: advfsops.c,v 1.73 2015/03/28 19:24:05 maxv Exp $       */
+/*     $NetBSD: advfsops.c,v 1.74 2015/04/20 13:44:16 riastradh Exp $  */
 
 /*
  * Copyright (c) 1994 Christian E. Hopps
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: advfsops.c,v 1.73 2015/03/28 19:24:05 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: advfsops.c,v 1.74 2015/04/20 13:44:16 riastradh Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_compat_netbsd.h"
@@ -364,7 +364,7 @@
 
 /*
  * lookup an anode, if not found, create
- * return locked and referenced al la vget(vp, LK_EXCLUSIVE);
+ * return locked and referenced
  */
 int
 adosfs_vget(struct mount *mp, ino_t an, struct vnode **vpp)
diff -r 80938c06a01a -r 6742af8699d5 sys/fs/tmpfs/tmpfs_subr.c
--- a/sys/fs/tmpfs/tmpfs_subr.c Mon Apr 20 13:12:24 2015 +0000
+++ b/sys/fs/tmpfs/tmpfs_subr.c Mon Apr 20 13:44:16 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tmpfs_subr.c,v 1.97 2014/09/08 14:49:46 gson Exp $     */
+/*     $NetBSD: tmpfs_subr.c,v 1.98 2015/04/20 13:44:16 riastradh Exp $        */
 
 /*
  * Copyright (c) 2005-2013 The NetBSD Foundation, Inc.
@@ -74,7 +74,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tmpfs_subr.c,v 1.97 2014/09/08 14:49:46 gson Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tmpfs_subr.c,v 1.98 2015/04/20 13:44:16 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/cprng.h>
@@ -282,11 +282,12 @@
                atomic_or_32(&node->tn_gen, TMPFS_RECLAIMING_BIT);
                mutex_enter(vp->v_interlock);
                mutex_exit(&node->tn_vlock);
-               error = vget(vp, LK_EXCLUSIVE);
+               error = vget(vp, 0, true /* wait */);
                if (error == ENOENT) {
                        mutex_enter(&node->tn_vlock);
                        goto again;
                }
+               vn_lock(vp, LK_EXCLUSIVE);
                atomic_and_32(&node->tn_gen, ~TMPFS_RECLAIMING_BIT);
                *vpp = vp;
                return error;
diff -r 80938c06a01a -r 6742af8699d5 sys/fs/udf/udf_subr.c
--- a/sys/fs/udf/udf_subr.c     Mon Apr 20 13:12:24 2015 +0000
+++ b/sys/fs/udf/udf_subr.c     Mon Apr 20 13:44:16 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: udf_subr.c,v 1.129 2015/04/06 08:39:23 hannken Exp $ */
+/* $NetBSD: udf_subr.c,v 1.130 2015/04/20 13:44:16 riastradh Exp $ */
 
 /*
  * Copyright (c) 2006, 2008 Reinoud Zandijk
@@ -29,7 +29,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__KERNEL_RCSID(0, "$NetBSD: udf_subr.c,v 1.129 2015/04/06 08:39:23 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: udf_subr.c,v 1.130 2015/04/20 13:44:16 riastradh Exp $");
 #endif /* not lint */
 
 
@@ -6361,7 +6361,7 @@
                }
 
                mutex_exit(&mntvnode_lock);
-               error = vget(vp, LK_EXCLUSIVE | LK_NOWAIT);
+               error = vget(vp, LK_NOWAIT, false /* !wait */);
                if (error) {
                        mutex_enter(&mntvnode_lock);
                        if (error == ENOENT)
@@ -6369,6 +6369,14 @@
                        *ndirty += 1;
                        continue;
                }
+               error = vn_lock(vp, LK_EXCLUSIVE | LK_NOWAIT);
+               if (error) {
+                       KASSERT(error == EBUSY);
+                       vrele(vp);
+                       mutex_enter(&mntvnode_lock);
+                       *ndirty += 1;
+                       continue;
+               }
 
                switch (pass) {
                case 1:
diff -r 80938c06a01a -r 6742af8699d5 sys/fs/union/union_subr.c
--- a/sys/fs/union/union_subr.c Mon Apr 20 13:12:24 2015 +0000
+++ b/sys/fs/union/union_subr.c Mon Apr 20 13:44:16 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: union_subr.c,v 1.71 2015/02/24 16:08:01 hannken Exp $  */
+/*     $NetBSD: union_subr.c,v 1.72 2015/04/20 13:44:16 riastradh Exp $        */
 
 /*
  * Copyright (c) 1994
@@ -72,7 +72,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: union_subr.c,v 1.71 2015/02/24 16:08:01 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: union_subr.c,v 1.72 2015/04/20 13:44:16 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -991,7 +991,7 @@
 
        if ((un->un_lowervp != NULLVP) &&
            (vp->v_type == un->un_lowervp->v_type)) {
-               if (vget(un->un_lowervp, 0) == 0)
+               if (vget(un->un_lowervp, 0, true /* wait */) == 0)
                        return (un->un_lowervp);
        }
 
diff -r 80938c06a01a -r 6742af8699d5 sys/kern/vfs_cache.c
--- a/sys/kern/vfs_cache.c      Mon Apr 20 13:12:24 2015 +0000
+++ b/sys/kern/vfs_cache.c      Mon Apr 20 13:44:16 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_cache.c,v 1.105 2015/01/16 20:10:25 dennis Exp $   */
+/*     $NetBSD: vfs_cache.c,v 1.106 2015/04/20 13:44:16 riastradh Exp $        */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -58,7 +58,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_cache.c,v 1.105 2015/01/16 20:10:25 dennis Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_cache.c,v 1.106 2015/04/20 13:44:16 riastradh Exp $");
 
 #include "opt_ddb.h"
 #include "opt_revcache.h"
@@ -555,7 +555,7 @@
        /*
         * Unlocked except for the vnode interlock.  Call vget().
         */
-       error = vget(vp, LK_NOWAIT);
+       error = vget(vp, LK_NOWAIT, false /* !wait */);
        if (error) {
                KASSERT(error == EBUSY);
                /*
@@ -636,7 +636,7 @@
        /*
         * Unlocked except for the vnode interlock.  Call vget().
         */
-       error = vget(vp, LK_NOWAIT);
+       error = vget(vp, LK_NOWAIT, false /* !wait */);
        if (error) {
                KASSERT(error == EBUSY);
                /*
@@ -724,7 +724,7 @@
                        mutex_enter(dvp->v_interlock);
                        mutex_exit(&ncp->nc_lock); 
                        mutex_exit(namecache_lock);
-                       error = vget(dvp, LK_NOWAIT);
+                       error = vget(dvp, LK_NOWAIT, false /* !wait */);
                        if (error) {
                                KASSERT(error == EBUSY);
                                if (bufp)
diff -r 80938c06a01a -r 6742af8699d5 sys/kern/vfs_mount.c
--- a/sys/kern/vfs_mount.c      Mon Apr 20 13:12:24 2015 +0000
+++ b/sys/kern/vfs_mount.c      Mon Apr 20 13:44:16 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_mount.c,v 1.33 2015/03/09 15:35:11 pooka Exp $     */
+/*     $NetBSD: vfs_mount.c,v 1.34 2015/04/20 13:44:16 riastradh Exp $ */
 
 /*-
  * Copyright (c) 1997-2011 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.33 2015/03/09 15:35:11 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.34 2015/04/20 13:44:16 riastradh Exp $");
 
 #define _VFS_VNODE_PRIVATE
 
@@ -404,7 +404,7 @@
                TAILQ_INSERT_AFTER(&mp->mnt_vnodelist, vp, mvp, v_mntvnodes);
                mvp->v_usecount = 1;
                mutex_exit(&mntvnode_lock);
-               error = vget(vp, 0);
+               error = vget(vp, 0, true /* wait */);
                KASSERT(error == 0 || error == ENOENT);
        } while (error != 0);
 
diff -r 80938c06a01a -r 6742af8699d5 sys/kern/vfs_vnode.c
--- a/sys/kern/vfs_vnode.c      Mon Apr 20 13:12:24 2015 +0000
+++ b/sys/kern/vfs_vnode.c      Mon Apr 20 13:44:16 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_vnode.c,v 1.40 2015/03/17 09:38:21 hannken Exp $   */
+/*     $NetBSD: vfs_vnode.c,v 1.41 2015/04/20 13:44:16 riastradh Exp $ */
 
 /*-
  * Copyright (c) 1997-2011 The NetBSD Foundation, Inc.
@@ -116,7 +116,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.40 2015/03/17 09:38:21 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.41 2015/04/20 13:44:16 riastradh Exp $");
 
 #define _VFS_VNODE_PRIVATE
 
@@ -518,13 +518,14 @@
  * vnode is no longer usable.
  */
 int
-vget(vnode_t *vp, int flags)
+vget(vnode_t *vp, int flags, bool waitok)
 {
        int error = 0;
 
        KASSERT((vp->v_iflag & VI_MARKER) == 0);
        KASSERT(mutex_owned(vp->v_interlock));
-       KASSERT((flags & ~(LK_SHARED|LK_EXCLUSIVE|LK_NOWAIT)) == 0);
+       KASSERT((flags & ~LK_NOWAIT) == 0);
+       KASSERT(waitok == ((flags & LK_NOWAIT) == 0));
 
        /*
         * Before adding a reference, we must remove the vnode
@@ -555,16 +556,10 @@
        }
 
        /*
-        * Ok, we got it in good shape.  Just locking left.
+        * Ok, we got it in good shape.
         */
        KASSERT((vp->v_iflag & VI_CLEAN) == 0);
        mutex_exit(vp->v_interlock);
-       if (flags & (LK_EXCLUSIVE | LK_SHARED)) {
-               error = vn_lock(vp, flags);
-               if (error != 0) {
-                       vrele(vp);
-               }
-       }
        return error;
 }
 
@@ -1247,7 +1242,7 @@
                vp = node->vn_vnode;
                mutex_enter(vp->v_interlock);
                mutex_exit(&vcache.lock);
-               error = vget(vp, 0);
+               error = vget(vp, 0, true /* wait */);
                if (error == ENOENT)
                        goto again;
                if (error == 0)
diff -r 80938c06a01a -r 6742af8699d5 sys/miscfs/specfs/spec_vnops.c
--- a/sys/miscfs/specfs/spec_vnops.c    Mon Apr 20 13:12:24 2015 +0000
+++ b/sys/miscfs/specfs/spec_vnops.c    Mon Apr 20 13:44:16 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: spec_vnops.c,v 1.146 2015/03/28 19:24:06 maxv Exp $    */
+/*     $NetBSD: spec_vnops.c,v 1.147 2015/04/20 13:44:16 riastradh Exp $       */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -58,7 +58,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: spec_vnops.c,v 1.146 2015/03/28 19:24:06 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spec_vnops.c,v 1.147 2015/04/20 13:44:16 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/proc.h>
@@ -309,7 +309,7 @@
                mutex_enter(vp->v_interlock);
        }
        mutex_exit(&device_lock);
-       error = vget(vp, 0);
+       error = vget(vp, 0, true /* wait */);
        if (error != 0)
                return error;
        *vpp = vp;
@@ -344,7 +344,7 @@
        }
        mutex_enter(vq->v_interlock);
        mutex_exit(&device_lock);
-       error = vget(vq, 0);
+       error = vget(vq, 0, true /* wait */);
        if (error != 0)
                return error;
        *vpp = vq;
diff -r 80938c06a01a -r 6742af8699d5 sys/miscfs/syncfs/sync_subr.c
--- a/sys/miscfs/syncfs/sync_subr.c     Mon Apr 20 13:12:24 2015 +0000



Home | Main Index | Thread Index | Old Index