Source-Changes-HG archive

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

[src/trunk]: src - Make VI_XLOCK, VI_CLEAN and VI_LOCKSHARE private to kern/v...



details:   https://anonhg.NetBSD.org/src/rev/58e32ffe95e2
branches:  trunk
changeset: 328031:58e32ffe95e2
user:      hannken <hannken%NetBSD.org@localhost>
date:      Mon Mar 24 13:42:40 2014 +0000

description:
- Make VI_XLOCK, VI_CLEAN and VI_LOCKSHARE private to kern/vfs_*.c.
- Make vwait() static.
- Add  vdead_check() to check a vnode for being or becoming dead.

Discussed on tech-kern.

Welcome to 6.99.38

diffstat:

 distrib/sets/lists/comp/mi     |   5 +++-
 share/man/man9/Makefile        |   3 +-
 share/man/man9/vnode.9         |  26 +++++++++++++++++++++++-
 sys/fs/puffs/puffs_vnops.c     |   8 +++---
 sys/fs/union/union_vnops.c     |  22 +++++++-------------
 sys/kern/vfs_vnode.c           |  32 ++++++++++++++++++++++++++++--
 sys/miscfs/genfs/genfs_vnops.c |  39 +++++++++++++++----------------------
 sys/miscfs/genfs/layer_vnops.c |  22 +++++++-------------
 sys/miscfs/specfs/spec_vnops.c |  43 +++++++++++++++++++----------------------
 sys/sys/param.h                |   4 +-
 sys/sys/vnode.h                |  10 ++++++--
 sys/ufs/ext2fs/ext2fs_vnops.c  |   6 ++--
 sys/ufs/ffs/ffs_vnops.c        |   6 ++--
 sys/ufs/lfs/lfs_segment.c      |  15 +++++++------
 sys/ufs/lfs/lfs_syscalls.c     |  10 ++++----
 sys/ufs/lfs/lfs_vfsops.c       |  11 ++++++---
 sys/ufs/lfs/lfs_vnops.c        |  20 +++++++++++-------
 usr.sbin/pstat/pstat.8         |  12 +---------
 usr.sbin/pstat/pstat.c         |   5 +--
 19 files changed, 166 insertions(+), 133 deletions(-)

diffs (truncated from 911 to 300 lines):

diff -r 08bdb0c9f518 -r 58e32ffe95e2 distrib/sets/lists/comp/mi
--- a/distrib/sets/lists/comp/mi        Mon Mar 24 10:46:58 2014 +0000
+++ b/distrib/sets/lists/comp/mi        Mon Mar 24 13:42:40 2014 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: mi,v 1.1885 2014/03/22 11:24:35 skrll Exp $
+#      $NetBSD: mi,v 1.1886 2014/03/24 13:42:40 hannken Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -10977,6 +10977,7 @@
 ./usr/share/man/cat9/vdevgone.0                        comp-sys-catman         .cat
 ./usr/share/man/cat9/veriexec.0                        comp-sys-catman         .cat
 ./usr/share/man/cat9/vfinddev.0                        comp-sys-catman         .cat
+./usr/share/man/cat9/vdead_check.0             comp-sys-catman         .cat
 ./usr/share/man/cat9/vflush.0                  comp-sys-catman         .cat
 ./usr/share/man/cat9/vflushbuf.0               comp-sys-catman         .cat
 ./usr/share/man/cat9/vfs.0                     comp-sys-catman         .cat
@@ -17630,6 +17631,7 @@
 ./usr/share/man/html9/vdevgone.html            comp-sys-htmlman        html
 ./usr/share/man/html9/veriexec.html            comp-sys-htmlman        html
 ./usr/share/man/html9/vfinddev.html            comp-sys-htmlman        html
+./usr/share/man/html9/vdead_check.html         comp-sys-htmlman        html
 ./usr/share/man/html9/vflush.html              comp-sys-htmlman        html
 ./usr/share/man/html9/vflushbuf.html           comp-sys-htmlman        html
 ./usr/share/man/html9/vfs.html                 comp-sys-htmlman        html
@@ -24522,6 +24524,7 @@
 ./usr/share/man/man9/vdevgone.9                        comp-sys-man            .man
 ./usr/share/man/man9/veriexec.9                        comp-sys-man            .man
 ./usr/share/man/man9/vfinddev.9                        comp-sys-man            .man
+./usr/share/man/man9/vdead_check.9             comp-sys-man            .man
 ./usr/share/man/man9/vflush.9                  comp-sys-man            .man
 ./usr/share/man/man9/vflushbuf.9               comp-sys-man            .man
 ./usr/share/man/man9/vfs.9                     comp-sys-man            .man
diff -r 08bdb0c9f518 -r 58e32ffe95e2 share/man/man9/Makefile
--- a/share/man/man9/Makefile   Mon Mar 24 10:46:58 2014 +0000
+++ b/share/man/man9/Makefile   Mon Mar 24 13:42:40 2014 +0000
@@ -1,4 +1,4 @@
-#       $NetBSD: Makefile,v 1.376 2014/03/22 11:24:36 skrll Exp $
+#       $NetBSD: Makefile,v 1.377 2014/03/24 13:42:40 hannken Exp $
 
 #      Makefile for section 9 (kernel function and variable) manual pages.
 
@@ -898,6 +898,7 @@
        vnode.9 vrecycle.9 \
        vnode.9 vgone.9 \
        vnode.9 vgonel.9 \
+       vnode.9 vdead_check.9 \
        vnode.9 vflush.9 \
        vnode.9 vaccess.9 \
        vnode.9 bdevvp.9 \
diff -r 08bdb0c9f518 -r 58e32ffe95e2 share/man/man9/vnode.9
--- a/share/man/man9/vnode.9    Mon Mar 24 10:46:58 2014 +0000
+++ b/share/man/man9/vnode.9    Mon Mar 24 13:42:40 2014 +0000
@@ -1,4 +1,4 @@
-.\"     $NetBSD: vnode.9,v 1.60 2014/03/05 09:37:29 hannken Exp $
+.\"     $NetBSD: vnode.9,v 1.61 2014/03/24 13:42:40 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 March 5, 2014
+.Dd March 24, 2014
 .Dt VNODE 9
 .Os
 .Sh NAME
@@ -44,6 +44,7 @@
 .Nm vrecycle ,
 .Nm vgone ,
 .Nm vgonel ,
+.Nm vdead_check ,
 .Nm vflush ,
 .Nm vaccess ,
 .Nm bdevvp ,
@@ -85,6 +86,8 @@
 .Ft void
 .Fn vgonel "struct vnode *vp" "struct lwp *l"
 .Ft int
+.Fn vdead_check "struct vnode *vp" "int flags"
+.Ft int
 .Fn vflush "struct mount *mp" "struct vnode *skipvp" "int flags"
 .Ft int
 .Fn vaccess "enum vtype type" "mode_t file_mode" "uid_t uid" "gid_t gid" "mode_t acc_mode" "kauth_cred_t cred"
@@ -630,6 +633,25 @@
 Eliminate all activity associated with the locked vnode
 .Fa vp
 in preparation for recycling.
+.It Fn vdead_check "vp" "flags"
+Check the vnode
+.Fa vp
+for being or becoming dead.
+Returns
+.Er ENOENT
+for a dead vnode and zero otherwise.
+If
+.Fa flags
+is
+.Dv VDEAD_NOWAIT
+it will return
+.Er EBUSY
+if the vnode is becoming dead and the function will not sleep.
+.Pp
+Whenever this function returns a non-zero value all future calls
+for this
+.Fa vp
+will also return a non-zero value.
 .It Fn vflush "mp" "skipvp" "flags"
 Remove any vnodes in the vnode table belonging to mount point
 .Fa mp .
diff -r 08bdb0c9f518 -r 58e32ffe95e2 sys/fs/puffs/puffs_vnops.c
--- a/sys/fs/puffs/puffs_vnops.c        Mon Mar 24 10:46:58 2014 +0000
+++ b/sys/fs/puffs/puffs_vnops.c        Mon Mar 24 13:42:40 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: puffs_vnops.c,v 1.180 2014/02/07 15:29:21 hannken Exp $        */
+/*     $NetBSD: puffs_vnops.c,v 1.181 2014/03/24 13:42:40 hannken Exp $        */
 
 /*
  * Copyright (c) 2005, 2006, 2007  Antti Kantee.  All Rights Reserved.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: puffs_vnops.c,v 1.180 2014/02/07 15:29:21 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: puffs_vnops.c,v 1.181 2014/03/24 13:42:40 hannken Exp $");
 
 #include <sys/param.h>
 #include <sys/buf.h>
@@ -1692,7 +1692,7 @@
         */
        if (dofaf == 0) {
                mutex_enter(vp->v_interlock);
-               if (vp->v_iflag & VI_XLOCK)
+               if (vdead_check(vp, VDEAD_NOWAIT) != 0)
                        dofaf = 1;
                mutex_exit(vp->v_interlock);
        }
@@ -2601,7 +2601,7 @@
         */
        if (BUF_ISWRITE(bp)) {
                mutex_enter(vp->v_interlock);
-               if (vp->v_iflag & VI_XLOCK)
+               if (vdead_check(vp, VDEAD_NOWAIT) != 0)
                        dofaf = 1;
                if (pn->pn_stat & PNODE_FAF)
                        dofaf = 1;
diff -r 08bdb0c9f518 -r 58e32ffe95e2 sys/fs/union/union_vnops.c
--- a/sys/fs/union/union_vnops.c        Mon Mar 24 10:46:58 2014 +0000
+++ b/sys/fs/union/union_vnops.c        Mon Mar 24 13:42:40 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: union_vnops.c,v 1.58 2014/03/12 09:40:05 hannken Exp $ */
+/*     $NetBSD: union_vnops.c,v 1.59 2014/03/24 13:42:40 hannken Exp $ */
 
 /*
  * Copyright (c) 1992, 1993, 1994, 1995
@@ -72,7 +72,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: union_vnops.c,v 1.58 2014/03/12 09:40:05 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: union_vnops.c,v 1.59 2014/03/24 13:42:40 hannken Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -1636,12 +1636,7 @@
                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;
+                       error = vdead_check(vp, VDEAD_NOWAIT);
                        mutex_exit(vp->v_interlock);
                } else
                        error = EBUSY;
@@ -1665,15 +1660,14 @@
        mutex_exit(&un->un_lock);
 
        mutex_enter(vp->v_interlock);
-       if (ISSET(vp->v_iflag, VI_XLOCK) || ISSET(vp->v_iflag, VI_CLEAN)) {
+       error = vdead_check(vp, VDEAD_NOWAIT);
+       if (error) {
                union_unlock1(vp, lockvp);
-               vwait(vp, VI_XLOCK);
-               KASSERT(ISSET(vp->v_iflag, VI_CLEAN));
-               mutex_exit(vp->v_interlock);
-               return ENOENT;
+               error = vdead_check(vp, 0);
+               KASSERT(error == ENOENT);
        }
        mutex_exit(vp->v_interlock);
-       return 0;
+       return error;
 }
 
 int
diff -r 08bdb0c9f518 -r 58e32ffe95e2 sys/kern/vfs_vnode.c
--- a/sys/kern/vfs_vnode.c      Mon Mar 24 10:46:58 2014 +0000
+++ b/sys/kern/vfs_vnode.c      Mon Mar 24 13:42:40 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_vnode.c,v 1.34 2014/03/17 09:27:37 hannken Exp $   */
+/*     $NetBSD: vfs_vnode.c,v 1.35 2014/03/24 13:42:40 hannken 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.34 2014/03/17 09:27:37 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.35 2014/03/24 13:42:40 hannken Exp $");
 
 #define _VFS_VNODE_PRIVATE
 
@@ -176,6 +176,7 @@
 static void            vrele_thread(void *);
 static void            vnpanic(vnode_t *, const char *, ...)
     __printflike(2, 3);
+static void            vwait(vnode_t *, int);
 
 /* Routines having to do with the management of the vnode table. */
 extern int             (**dead_vnodeop_p)(void *);
@@ -1140,10 +1141,35 @@
 }
 
 /*
+ * Test a vnode for being or becoming dead.  Returns one of:
+ * EBUSY:  vnode is becoming dead, with "flags == VDEAD_NOWAIT" only.
+ * ENOENT: vnode is dead.
+ * 0:      otherwise.
+ *
+ * Whenever this function returns a non-zero value all future
+ * calls will also return a non-zero value.
+ */
+int
+vdead_check(struct vnode *vp, int flags)
+{
+
+       KASSERT(mutex_owned(vp->v_interlock));
+       if (ISSET(vp->v_iflag, VI_XLOCK)) {
+               if (ISSET(flags, VDEAD_NOWAIT))
+                       return EBUSY;
+               vwait(vp, VI_XLOCK);
+               KASSERT(ISSET(vp->v_iflag, VI_CLEAN));
+       }
+       if (ISSET(vp->v_iflag, VI_CLEAN))
+               return ENOENT;
+       return 0;
+}
+
+/*
  * Wait for a vnode (typically with VI_XLOCK set) to be cleaned or
  * recycled.
  */
-void
+static void
 vwait(vnode_t *vp, int flags)
 {
 
diff -r 08bdb0c9f518 -r 58e32ffe95e2 sys/miscfs/genfs/genfs_vnops.c
--- a/sys/miscfs/genfs/genfs_vnops.c    Mon Mar 24 10:46:58 2014 +0000
+++ b/sys/miscfs/genfs/genfs_vnops.c    Mon Mar 24 13:42:40 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: genfs_vnops.c,v 1.191 2014/03/12 09:38:51 hannken Exp $        */
+/*     $NetBSD: genfs_vnops.c,v 1.192 2014/03/24 13:42:40 hannken Exp $        */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -57,7 +57,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: genfs_vnops.c,v 1.191 2014/03/12 09:38:51 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: genfs_vnops.c,v 1.192 2014/03/24 13:42:40 hannken Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -297,12 +297,9 @@
                if (! rw_tryenter(&vp->v_lock, op))
                        return EBUSY;
                if (mutex_tryenter(vp->v_interlock)) {
-                       if (ISSET(vp->v_iflag, VI_XLOCK))
-                               error = EBUSY;
-                       else {
-                               KASSERT(ISSET(vp->v_iflag, VI_CLEAN));
-                               error = (ISSET(flags, LK_RETRY) ? 0 : ENOENT);
-                       }
+                       error = vdead_check(vp, VDEAD_NOWAIT);
+                       if (error == ENOENT && ISSET(flags, LK_RETRY))
+                               error = 0;
                        mutex_exit(vp->v_interlock);
                } else
                        error = EBUSY;
@@ -313,14 +310,16 @@
 
        rw_enter(&vp->v_lock, op);



Home | Main Index | Thread Index | Old Index