Source-Changes-HG archive

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

[src/trunk]: src/sys Merge the remaining changes from the ad-namecache branch...



details:   https://anonhg.NetBSD.org/src/rev/9559a1315097
branches:  trunk
changeset: 850459:9559a1315097
user:      ad <ad%NetBSD.org@localhost>
date:      Sat Apr 04 20:49:30 2020 +0000

description:
Merge the remaining changes from the ad-namecache branch, affecting namei()
and getcwd():

- push vnode locking back as far as possible.
- do most lookups directly in the namecache, avoiding vnode locks & refs.
- don't block new refs to vnodes across VOP_INACTIVE().
- get shared locks for VOP_LOOKUP() if the file system supports it.
- correct lock types for VOP_ACCESS() / VOP_GETATTR() in a few places.

Possible future enhancements:

- make the lookups lockless.
- support dotdot lookups by being lockless and inferring absence of chroot.
- maybe make it work for layered file systems.
- avoid vnode references at the root & cwd.

diffstat:

 sys/fs/cd9660/cd9660_lookup.c     |    7 +-
 sys/fs/cd9660/cd9660_vfsops.c     |    6 +-
 sys/fs/msdosfs/msdosfs_lookup.c   |    8 +-
 sys/fs/msdosfs/msdosfs_vfsops.c   |    5 +-
 sys/fs/tmpfs/tmpfs_subr.c         |    8 +-
 sys/fs/tmpfs/tmpfs_vfsops.c       |    7 +-
 sys/kern/vfs_cache.c              |    8 +-
 sys/kern/vfs_getcwd.c             |  194 +++++------
 sys/kern/vfs_lookup.c             |  615 +++++++++++++++++++++++++++----------
 sys/kern/vfs_syscalls.c           |   12 +-
 sys/kern/vfs_vnode.c              |   23 +-
 sys/miscfs/genfs/layer_vnops.c    |    5 +-
 sys/miscfs/nullfs/null_vfsops.c   |    5 +-
 sys/miscfs/procfs/procfs_vfsops.c |    6 +-
 sys/sys/fstypes.h                 |    6 +-
 sys/sys/namei.src                 |   27 +-
 sys/ufs/chfs/chfs_vnops.c         |    6 +-
 sys/ufs/ext2fs/ext2fs_lookup.c    |   24 +-
 sys/ufs/ext2fs/ext2fs_vfsops.c    |    6 +-
 sys/ufs/ffs/ffs_vfsops.c          |    9 +-
 sys/ufs/lfs/lfs_vfsops.c          |    5 +-
 sys/ufs/lfs/ulfs_lookup.c         |   25 +-
 sys/ufs/ufs/ufs_lookup.c          |   26 +-
 sys/ufs/ufs/ufs_vnops.c           |    9 +-
 24 files changed, 670 insertions(+), 382 deletions(-)

diffs (truncated from 2108 to 300 lines):

diff -r 3564e997bc11 -r 9559a1315097 sys/fs/cd9660/cd9660_lookup.c
--- a/sys/fs/cd9660/cd9660_lookup.c     Sat Apr 04 20:47:56 2020 +0000
+++ b/sys/fs/cd9660/cd9660_lookup.c     Sat Apr 04 20:49:30 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cd9660_lookup.c,v 1.30 2015/03/28 19:24:05 maxv Exp $  */
+/*     $NetBSD: cd9660_lookup.c,v 1.31 2020/04/04 20:49:30 ad Exp $    */
 
 /*-
  * Copyright (c) 1989, 1993, 1994
@@ -39,7 +39,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cd9660_lookup.c,v 1.30 2015/03/28 19:24:05 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cd9660_lookup.c,v 1.31 2020/04/04 20:49:30 ad Exp $");
 
 #include <sys/param.h>
 #include <sys/namei.h>
@@ -152,6 +152,9 @@
                         cnp->cn_nameiop, cnp->cn_flags, NULL, vpp)) {
                return *vpp == NULLVP ? ENOENT : 0;
        }
+       /* May need to restart the lookup with an exclusive lock. */
+       if (VOP_ISLOCKED(vdp) != LK_EXCLUSIVE)
+               return ENOLCK;
 
        len = cnp->cn_namelen;
        name = cnp->cn_nameptr;
diff -r 3564e997bc11 -r 9559a1315097 sys/fs/cd9660/cd9660_vfsops.c
--- a/sys/fs/cd9660/cd9660_vfsops.c     Sat Apr 04 20:47:56 2020 +0000
+++ b/sys/fs/cd9660/cd9660_vfsops.c     Sat Apr 04 20:49:30 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cd9660_vfsops.c,v 1.95 2020/03/16 21:20:09 pgoyette Exp $      */
+/*     $NetBSD: cd9660_vfsops.c,v 1.96 2020/04/04 20:49:30 ad Exp $    */
 
 /*-
  * Copyright (c) 1994
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cd9660_vfsops.c,v 1.95 2020/03/16 21:20:09 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cd9660_vfsops.c,v 1.96 2020/04/04 20:49:30 ad Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_compat_netbsd.h"
@@ -446,7 +446,7 @@
        mp->mnt_stat.f_fsid = mp->mnt_stat.f_fsidx.__fsid_val[0];
        mp->mnt_stat.f_namemax = ISO_MAXNAMLEN;
        mp->mnt_flag |= MNT_LOCAL;
-       mp->mnt_iflag |= IMNT_MPSAFE;
+       mp->mnt_iflag |= IMNT_MPSAFE | IMNT_SHRLOOKUP;
        mp->mnt_dev_bshift = iso_bsize;
        mp->mnt_fs_bshift = isomp->im_bshift;
        isomp->im_mountp = mp;
diff -r 3564e997bc11 -r 9559a1315097 sys/fs/msdosfs/msdosfs_lookup.c
--- a/sys/fs/msdosfs/msdosfs_lookup.c   Sat Apr 04 20:47:56 2020 +0000
+++ b/sys/fs/msdosfs/msdosfs_lookup.c   Sat Apr 04 20:49:30 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msdosfs_lookup.c,v 1.35 2016/01/30 09:59:27 mlelstv Exp $      */
+/*     $NetBSD: msdosfs_lookup.c,v 1.36 2020/04/04 20:49:30 ad Exp $   */
 
 /*-
  * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
@@ -52,7 +52,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: msdosfs_lookup.c,v 1.35 2016/01/30 09:59:27 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: msdosfs_lookup.c,v 1.36 2020/04/04 20:49:30 ad Exp $");
 
 #include <sys/param.h>
 
@@ -161,6 +161,10 @@
                return *vpp == NULLVP ? ENOENT: 0;
        }
 
+       /* May need to restart the lookup with an exclusive lock. */
+       if (VOP_ISLOCKED(vdp) != LK_EXCLUSIVE)
+               return ENOLCK;
+
        /*
         * If they are going after the . or .. entry in the root directory,
         * they won't find it.  DOS filesystems don't have them in the root
diff -r 3564e997bc11 -r 9559a1315097 sys/fs/msdosfs/msdosfs_vfsops.c
--- a/sys/fs/msdosfs/msdosfs_vfsops.c   Sat Apr 04 20:47:56 2020 +0000
+++ b/sys/fs/msdosfs/msdosfs_vfsops.c   Sat Apr 04 20:49:30 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msdosfs_vfsops.c,v 1.133 2020/03/16 21:20:10 pgoyette Exp $    */
+/*     $NetBSD: msdosfs_vfsops.c,v 1.134 2020/04/04 20:49:30 ad Exp $  */
 
 /*-
  * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
@@ -48,7 +48,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: msdosfs_vfsops.c,v 1.133 2020/03/16 21:20:10 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: msdosfs_vfsops.c,v 1.134 2020/04/04 20:49:30 ad Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_compat_netbsd.h"
@@ -868,6 +868,7 @@
        mp->mnt_stat.f_fsid = mp->mnt_stat.f_fsidx.__fsid_val[0];
        mp->mnt_stat.f_namemax = MSDOSFS_NAMEMAX(pmp);
        mp->mnt_flag |= MNT_LOCAL;
+       mp->mnt_iflag |= IMNT_SHRLOOKUP;
        mp->mnt_dev_bshift = pmp->pm_bnshift;
        mp->mnt_fs_bshift = pmp->pm_cnshift;
 
diff -r 3564e997bc11 -r 9559a1315097 sys/fs/tmpfs/tmpfs_subr.c
--- a/sys/fs/tmpfs/tmpfs_subr.c Sat Apr 04 20:47:56 2020 +0000
+++ b/sys/fs/tmpfs/tmpfs_subr.c Sat Apr 04 20:49:30 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tmpfs_subr.c,v 1.107 2020/03/14 13:37:49 ad Exp $      */
+/*     $NetBSD: tmpfs_subr.c,v 1.108 2020/04/04 20:49:30 ad Exp $      */
 
 /*
  * Copyright (c) 2005-2013 The NetBSD Foundation, Inc.
@@ -73,7 +73,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tmpfs_subr.c,v 1.107 2020/03/14 13:37:49 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tmpfs_subr.c,v 1.108 2020/04/04 20:49:30 ad Exp $");
 
 #include <sys/param.h>
 #include <sys/cprng.h>
@@ -147,6 +147,8 @@
        vp->v_data = node;
        node->tn_vnode = vp;
        uvm_vnp_setsize(vp, node->tn_size);
+       KASSERT(node->tn_mode != VNOVAL);
+       cache_enter_id(vp, node->tn_mode, node->tn_uid, node->tn_gid);
 }
 
 /*
@@ -1039,6 +1041,7 @@
        node->tn_mode = (mode & ALLPERMS);
        tmpfs_update(vp, TMPFS_UPDATE_CTIME);
        VN_KNOTE(vp, NOTE_ATTRIB);
+       cache_enter_id(vp, node->tn_mode, node->tn_uid, node->tn_gid);
        return 0;
 }
 
@@ -1083,6 +1086,7 @@
        node->tn_gid = gid;
        tmpfs_update(vp, TMPFS_UPDATE_CTIME);
        VN_KNOTE(vp, NOTE_ATTRIB);
+       cache_enter_id(vp, node->tn_mode, node->tn_uid, node->tn_gid);
        return 0;
 }
 
diff -r 3564e997bc11 -r 9559a1315097 sys/fs/tmpfs/tmpfs_vfsops.c
--- a/sys/fs/tmpfs/tmpfs_vfsops.c       Sat Apr 04 20:47:56 2020 +0000
+++ b/sys/fs/tmpfs/tmpfs_vfsops.c       Sat Apr 04 20:49:30 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tmpfs_vfsops.c,v 1.76 2020/01/17 20:08:08 ad Exp $     */
+/*     $NetBSD: tmpfs_vfsops.c,v 1.77 2020/04/04 20:49:30 ad Exp $     */
 
 /*
  * Copyright (c) 2005, 2006, 2007 The NetBSD Foundation, Inc.
@@ -42,7 +42,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tmpfs_vfsops.c,v 1.76 2020/01/17 20:08:08 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tmpfs_vfsops.c,v 1.77 2020/04/04 20:49:30 ad Exp $");
 
 #include <sys/param.h>
 #include <sys/atomic.h>
@@ -182,7 +182,8 @@
        mp->mnt_stat.f_namemax = TMPFS_MAXNAMLEN;
        mp->mnt_fs_bshift = PAGE_SHIFT;
        mp->mnt_dev_bshift = DEV_BSHIFT;
-       mp->mnt_iflag |= IMNT_MPSAFE | IMNT_CAN_RWTORO;
+       mp->mnt_iflag |= IMNT_MPSAFE | IMNT_CAN_RWTORO | IMNT_SHRLOOKUP |
+           IMNT_NCLOOKUP;
        vfs_getnewfsid(mp);
 
        /* Allocate the tmpfs mount structure and fill it. */
diff -r 3564e997bc11 -r 9559a1315097 sys/kern/vfs_cache.c
--- a/sys/kern/vfs_cache.c      Sat Apr 04 20:47:56 2020 +0000
+++ b/sys/kern/vfs_cache.c      Sat Apr 04 20:49:30 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_cache.c,v 1.136 2020/03/30 19:15:28 ad Exp $       */
+/*     $NetBSD: vfs_cache.c,v 1.137 2020/04/04 20:49:30 ad Exp $       */
 
 /*-
  * Copyright (c) 2008, 2019, 2020 The NetBSD Foundation, Inc.
@@ -172,7 +172,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_cache.c,v 1.136 2020/03/30 19:15:28 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_cache.c,v 1.137 2020/04/04 20:49:30 ad Exp $");
 
 #define __NAMECACHE_PRIVATE
 #ifdef _KERNEL_OPT
@@ -624,7 +624,6 @@
  * names in the cache.  The node locks are chained along the way: a parent's
  * lock is not dropped until the child's is acquired.
  */
-#ifdef notyet
 bool
 cache_lookup_linked(struct vnode *dvp, const char *name, size_t namelen,
                    struct vnode **vn_ret, krwlock_t **plock,
@@ -721,7 +720,6 @@
        *vn_ret = ncp->nc_vp;
        return true;
 }
-#endif /* notyet */
 
 /*
  * Scan cache looking for name of directory entry pointing at vp.
@@ -967,7 +965,6 @@
  * information, missing some updates, so always check the mount flag
  * instead of looking for !VNOVAL.
  */
-#ifdef notyet
 bool
 cache_have_id(struct vnode *vp)
 {
@@ -982,7 +979,6 @@
                return false;
        }
 }
-#endif /* notyet */
 
 /*
  * Name cache initialization, from vfs_init() when the system is booting.
diff -r 3564e997bc11 -r 9559a1315097 sys/kern/vfs_getcwd.c
--- a/sys/kern/vfs_getcwd.c     Sat Apr 04 20:47:56 2020 +0000
+++ b/sys/kern/vfs_getcwd.c     Sat Apr 04 20:49:30 2020 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: vfs_getcwd.c,v 1.56 2020/03/22 14:38:37 ad Exp $ */
+/* $NetBSD: vfs_getcwd.c,v 1.57 2020/04/04 20:49:30 ad Exp $ */
 
 /*-
- * Copyright (c) 1999 The NetBSD Foundation, Inc.
+ * Copyright (c) 1999, 2020 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_getcwd.c,v 1.56 2020/03/22 14:38:37 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_getcwd.c,v 1.57 2020/04/04 20:49:30 ad Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -87,7 +87,7 @@
  * On exit, *uvpp is either NULL or is a locked vnode reference.
  */
 static int
-getcwd_scandir(struct vnode **lvpp, struct vnode **uvpp, char **bpp,
+getcwd_scandir(struct vnode *lvp, struct vnode **uvpp, char **bpp,
     char *bufp, struct lwp *l)
 {
        int     error = 0;
@@ -101,12 +101,14 @@
        ino_t   fileno;
        struct vattr va;
        struct vnode *uvp = NULL;
-       struct vnode *lvp = *lvpp;
        kauth_cred_t cred = l->l_cred;
        struct componentname cn;
        int len, reclen;
        tries = 0;
 
+       /* Need exclusive for UFS VOP_GETATTR (itimes) & VOP_LOOKUP. */
+       KASSERT(VOP_ISLOCKED(lvp) == LK_EXCLUSIVE);
+
        /*
         * If we want the filename, get some info we need while the
         * current directory is still locked.
@@ -114,8 +116,7 @@
        if (bufp != NULL) {
                error = VOP_GETATTR(lvp, &va, cred);
                if (error) {
-                       vput(lvp);
-                       *lvpp = NULL;
+                       VOP_UNLOCK(lvp);
                        *uvpp = NULL;
                        return error;
                }
@@ -134,24 +135,14 @@
 
        /* At this point, lvp is locked  */
        error = VOP_LOOKUP(lvp, uvpp, &cn);
-       vput(lvp);
+       VOP_UNLOCK(lvp);
        if (error) {
-               *lvpp = NULL;
                *uvpp = NULL;
                return error;
        }
        uvp = *uvpp;



Home | Main Index | Thread Index | Old Index