Source-Changes-HG archive

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

[src/trunk]: src/sys/fs/adosfs Change adosfs from hashlist to vcache.



details:   https://anonhg.NetBSD.org/src/rev/5b13347bb14a
branches:  trunk
changeset: 331197:5b13347bb14a
user:      hannken <hannken%NetBSD.org@localhost>
date:      Tue Aug 05 08:50:54 2014 +0000

description:
Change adosfs from hashlist to vcache.
- point ap->block to real file header block for hard links.

diffstat:

 sys/fs/adosfs/adosfs.h   |    8 +---
 sys/fs/adosfs/adutil.c   |   58 +------------------------
 sys/fs/adosfs/advfsops.c |  108 +++++++++++++++++++++++-----------------------
 sys/fs/adosfs/advnops.c  |    6 +-
 4 files changed, 59 insertions(+), 121 deletions(-)

diffs (truncated from 364 to 300 lines):

diff -r 7029d7d38d46 -r 5b13347bb14a sys/fs/adosfs/adosfs.h
--- a/sys/fs/adosfs/adosfs.h    Tue Aug 05 08:39:39 2014 +0000
+++ b/sys/fs/adosfs/adosfs.h    Tue Aug 05 08:50:54 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: adosfs.h,v 1.12 2012/10/03 07:20:50 mlelstv Exp $      */
+/*     $NetBSD: adosfs.h,v 1.13 2014/08/05 08:50:54 hannken Exp $      */
 
 /*
  * Copyright (c) 1994 Christian E. Hopps
@@ -73,7 +73,6 @@
  */
 struct anode {
        struct genfs_node gnode;
-       LIST_ENTRY(anode) link;
        enum anode_type type;
        char name[ADMAXNAMELEN+1];      /* (r/d/f) name for object */
        struct datestamp mtimev;        /* (r) volume modified */
@@ -112,7 +111,6 @@
 #define ANODEHASHSZ (512)
 
 struct adosfsmount {
-       LIST_HEAD(anodechain, anode) anodetab[ANODEHASHSZ];
        struct mount *mp;       /* owner mount */
        u_int32_t dostype;      /* type of volume */
        u_long rootb;           /* root block number */
@@ -169,10 +167,6 @@
 int adunixprot(int);
 int adosfs_getblktype(struct adosfsmount *, struct buf *);
 
-struct vnode *adosfs_ahashget(struct mount *, ino_t);
-void adosfs_ainshash(struct adosfsmount *, struct anode *);
-void adosfs_aremhash(struct anode *);
-
 int adosfs_lookup(void *);
 
 extern int (**adosfs_vnodeop_p)(void *);
diff -r 7029d7d38d46 -r 5b13347bb14a sys/fs/adosfs/adutil.c
--- a/sys/fs/adosfs/adutil.c    Tue Aug 05 08:39:39 2014 +0000
+++ b/sys/fs/adosfs/adutil.c    Tue Aug 05 08:50:54 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: adutil.c,v 1.16 2014/02/27 16:51:37 hannken Exp $      */
+/*     $NetBSD: adutil.c,v 1.17 2014/08/05 08:50:54 hannken Exp $      */
 
 /*
  * Copyright (c) 1994 Christian E. Hopps
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: adutil.c,v 1.16 2014/02/27 16:51:37 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: adutil.c,v 1.17 2014/08/05 08:50:54 hannken Exp $");
 
 #include <sys/param.h>
 #include <sys/vnode.h>
@@ -47,62 +47,8 @@
 /*
  * look for anode in the mount's hash table, return locked.
  */
-#define AHASH(an) ((an) & (ANODEHASHSZ - 1))
 static int CapitalChar(int, int);
 
-extern kmutex_t adosfs_hashlock;
-
-struct vnode *
-adosfs_ahashget(struct mount *mp, ino_t an)
-{
-       struct anodechain *hp;
-       struct anode *ap;
-       struct vnode *vp;
-
-       hp = &VFSTOADOSFS(mp)->anodetab[AHASH(an)];
-
-start_over:
-       mutex_enter(&adosfs_hashlock);
-       for (ap = hp->lh_first; ap != NULL; ap = ap->link.le_next) {
-               if (ap->block == an) {
-                       vp = ATOV(ap);
-                       mutex_enter(vp->v_interlock);
-                       mutex_exit(&adosfs_hashlock);
-                       if (vget(vp, LK_EXCLUSIVE))
-                               goto start_over;
-                       return (ATOV(ap));
-               }
-       }
-       mutex_exit(&adosfs_hashlock);
-       return (NULL);
-}
-
-/*
- * insert in hash table and lock
- *
- * ap->vp must have been initialized before this call.
- */
-void
-adosfs_ainshash(struct adosfsmount *amp, struct anode *ap)
-{
-       int error __diagused;
-
-       error = VOP_LOCK(ATOV(ap), LK_EXCLUSIVE);
-       KASSERT(error == 0);
-
-       mutex_enter(&adosfs_hashlock);
-       LIST_INSERT_HEAD(&amp->anodetab[AHASH(ap->block)], ap, link);
-       mutex_exit(&adosfs_hashlock);
-}
-
-void
-adosfs_aremhash(struct anode *ap)
-{
-       mutex_enter(&adosfs_hashlock);
-       LIST_REMOVE(ap, link);
-       mutex_exit(&adosfs_hashlock);
-}
-
 int
 adosfs_getblktype(struct adosfsmount *amp, struct buf *bp)
 {
diff -r 7029d7d38d46 -r 5b13347bb14a sys/fs/adosfs/advfsops.c
--- a/sys/fs/adosfs/advfsops.c  Tue Aug 05 08:39:39 2014 +0000
+++ b/sys/fs/adosfs/advfsops.c  Tue Aug 05 08:50:54 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: advfsops.c,v 1.70 2014/04/16 18:55:18 maxv Exp $       */
+/*     $NetBSD: advfsops.c,v 1.71 2014/08/05 08:50:54 hannken Exp $    */
 
 /*
  * Copyright (c) 1994 Christian E. Hopps
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: advfsops.c,v 1.70 2014/04/16 18:55:18 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: advfsops.c,v 1.71 2014/08/05 08:50:54 hannken Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_compat_netbsd.h"
@@ -70,8 +70,6 @@
 int adosfs_mountfs(struct vnode *, struct mount *, struct lwp *);
 int adosfs_loadbitmap(struct adosfsmount *);
 
-kmutex_t adosfs_hashlock;
-
 struct pool adosfs_node_pool;
 
 MALLOC_JUSTDEFINE(M_ANODE, "adosfs anode","adosfs anode structures and tables");
@@ -169,7 +167,7 @@
        struct buf *bp;
        struct vnode *rvp;
        size_t bitmap_sz = 0;
-       int error, i;
+       int error;
        uint64_t numsecs;
        unsigned secsize;
        unsigned long secsperblk, blksperdisk, resvblks;
@@ -264,12 +262,6 @@
        mp->mnt_flag |= MNT_LOCAL;
 
        /*
-        * init anode table.
-        */
-       for (i = 0; i < ANODEHASHSZ; i++)
-               LIST_INIT(&amp->anodetab[i]);
-
-       /*
         * get the root anode, if not a valid fs this will fail.
         */
        if ((error = VFS_ROOT(mp, &rvp)) != 0)
@@ -371,50 +363,55 @@
 }
 
 /*
- * lookup an anode, check mount's hash table if not found, create
- * return locked and referenced al la vget(vp, 1);
+ * lookup an anode, if not found, create
+ * return locked and referenced al la vget(vp, LK_EXCLUSIVE);
  */
 int
 adosfs_vget(struct mount *mp, ino_t an, struct vnode **vpp)
 {
+       int error;
+
+       error = vcache_get(mp, &an, sizeof(an), vpp);
+       if (error)
+               return error;
+       error = vn_lock(*vpp, LK_EXCLUSIVE);
+       if (error) {
+               vrele(*vpp);
+               *vpp = NULL;
+               return error;
+       }
+       return 0;
+}
+
+/*
+ * Initialize this vnode / anode pair.
+ * Caller assures no other thread will try to load this inode.
+ */
+int
+adosfs_loadvnode(struct mount *mp, struct vnode *vp,
+    const void *key, size_t key_len, const void **new_key)
+{
        struct adosfsmount *amp;
-       struct vnode *vp;
        struct anode *ap;
        struct buf *bp;
+       ino_t an;
        char *nam, *tmp;
        int namlen, error;
 
-       error = 0;
+       KASSERT(key_len == sizeof(an));
+       memcpy(&an, key, key_len);
        amp = VFSTOADOSFS(mp);
-       bp = NULL;
 
-       /*
-        * check hash table. we are done if found
-        */
-       if ((*vpp = adosfs_ahashget(mp, an)) != NULL)
-               return (0);
+       if ((error = bread(amp->devvp, an * amp->bsize / DEV_BSIZE,
+                          amp->bsize, NOCRED, 0, &bp)) != 0)
+               return error;
 
-       error = getnewvnode(VT_ADOSFS, mp, adosfs_vnodeop_p, NULL, &vp);
-       if (error)
-               return (error);
-
-       /*
-        * setup, insert in hash, and lock before io.
-        */
-       vp->v_data = ap = pool_get(&adosfs_node_pool, PR_WAITOK);
+       ap = pool_get(&adosfs_node_pool, PR_WAITOK);
        memset(ap, 0, sizeof(struct anode));
        ap->vp = vp;
        ap->amp = amp;
        ap->block = an;
        ap->nwords = amp->nwords;
-       genfs_node_init(vp, &adosfs_genfsops);
-       adosfs_ainshash(amp, ap);
-
-       if ((error = bread(amp->devvp, an * amp->bsize / DEV_BSIZE,
-                          amp->bsize, NOCRED, 0, &bp)) != 0) {
-               vput(vp);
-               return (error);
-       }
 
        /*
         * get type and fill rest in based on that.
@@ -468,9 +465,8 @@
                ap->fsize = namlen;
                break;
        default:
-               brelse(bp, 0);
-               vput(vp);
-               return (EINVAL);
+               error = EINVAL;
+               goto bad;
        }
 
        /*
@@ -488,9 +484,8 @@
                printf("adosfs: aget: name length too long blk %llu\n",
                    (unsigned long long)an);
 #endif
-               brelse(bp, 0);
-               vput(vp);
-               return (EINVAL);
+               error = EINVAL;
+               goto bad;
        }
        memcpy(ap->name, nam, namlen);
        ap->name[namlen] = 0;
@@ -531,15 +526,9 @@
                bp = NULL;
                error = bread(amp->devvp, ap->linkto * amp->bsize / DEV_BSIZE,
                    amp->bsize, NOCRED, 0, &bp);
-               if (error) {
-                       vput(vp);
-                       return (error);
-               }
+               if (error)
+                       goto bad;
                ap->fsize = adoswordn(bp, ap->nwords - 47);
-               /*
-                * Should ap->block be set to the real file header block?
-                */
-               ap->block = ap->linkto;
        }
 
        if (ap->type == AROOT) {
@@ -586,10 +575,20 @@
        ap->mtime.mins = adoswordn(bp, ap->nwords - 22);
        ap->mtime.ticks = adoswordn(bp, ap->nwords - 21);
 
-       *vpp = vp;
        brelse(bp, 0);
+       vp->v_tag = VT_ADOSFS;
+       vp->v_op = adosfs_vnodeop_p;
+       vp->v_data = ap;
+       genfs_node_init(vp, &adosfs_genfsops);



Home | Main Index | Thread Index | Old Index