Source-Changes-HG archive

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

[src/trunk]: src/sys/fs/puffs Add name and atttribute cache with filesytem pr...



details:   https://anonhg.NetBSD.org/src/rev/68f4e6a59b56
branches:  trunk
changeset: 778688:68f4e6a59b56
user:      manu <manu%NetBSD.org@localhost>
date:      Sun Apr 08 15:04:41 2012 +0000

description:
Add name and atttribute cache with filesytem provided TTL.
lookup, create, mknod, mkdir, symlink, getattr and setattr messages
have been extended so that attributes and their TTL can be provided
by the filesytem. lookup, create, mknod, mkdir, and symlink messages
are also extended so that the filesystem can provide name TTL.

diffstat:

 sys/fs/puffs/puffs_msgif.h  |   23 +++-
 sys/fs/puffs/puffs_node.c   |    7 +-
 sys/fs/puffs/puffs_sys.h    |    9 +-
 sys/fs/puffs/puffs_vfsops.c |    7 +-
 sys/fs/puffs/puffs_vnops.c  |  268 +++++++++++++++++++++++++++++++++++--------
 5 files changed, 254 insertions(+), 60 deletions(-)

diffs (truncated from 636 to 300 lines):

diff -r 4d44d1fa8a69 -r 68f4e6a59b56 sys/fs/puffs/puffs_msgif.h
--- a/sys/fs/puffs/puffs_msgif.h        Sun Apr 08 13:14:29 2012 +0000
+++ b/sys/fs/puffs/puffs_msgif.h        Sun Apr 08 15:04:41 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: puffs_msgif.h,v 1.77 2011/09/27 01:48:57 christos Exp $        */
+/*     $NetBSD: puffs_msgif.h,v 1.78 2012/04/08 15:04:41 manu Exp $    */
 
 /*
  * Copyright (c) 2005, 2006, 2007  Antti Kantee.  All Rights Reserved.
@@ -159,8 +159,9 @@
 #define PUFFS_KFLAG_WTCACHE            0x08    /* write-through page cache */
 #define PUFFS_KFLAG_IAONDEMAND         0x10    /* inactive only on demand  */
 #define PUFFS_KFLAG_LOOKUP_FULLPNBUF   0x20    /* full pnbuf in lookup     */
-#define PUFFS_KFLAG_MASK               0x3f
 #define PUFFS_KFLAG_NOCACHE_ATTR       0x40    /* no attrib cache (unused) */
+#define PUFFS_KFLAG_CACHE_FS_TTL       0x80    /* cache use TTL from FS    */
+#define PUFFS_KFLAG_MASK               0xbf
 
 #define PUFFS_FHFLAG_DYNAMIC           0x01
 #define PUFFS_FHFLAG_NFSV2             0x02
@@ -360,6 +361,10 @@
        enum vtype              pvnr_vtype;             /* IN   */
        voff_t                  pvnr_size;              /* IN   */
        dev_t                   pvnr_rdev;              /* IN   */
+       /* Used only if PUFFS_KFLAG_CACHE_USE_TTL */
+       struct vattr            pvnr_va;                /* IN   */
+       struct timespec         pvnr_va_ttl;            /* IN   */
+       struct timespec         pvnr_cn_ttl;            /* IN   */
 };
 
 struct puffs_vnmsg_create {
@@ -370,6 +375,9 @@
 
        struct vattr            pvnr_va;                /* OUT  */
        puffs_cookie_t          pvnr_newnode;           /* IN   */
+       /* Used only if PUFFS_KFLAG_CACHE_USE_TTL */
+       struct timespec         pvnr_va_ttl;            /* IN   */
+       struct timespec         pvnr_cn_ttl;            /* IN   */
 };
 
 struct puffs_vnmsg_mknod {
@@ -380,6 +388,9 @@
 
        struct vattr            pvnr_va;                /* OUT  */
        puffs_cookie_t          pvnr_newnode;           /* IN   */
+       /* Used only if PUFFS_KFLAG_CACHE_USE_TTL */
+       struct timespec         pvnr_va_ttl;            /* IN   */
+       struct timespec         pvnr_cn_ttl;            /* IN   */
 };
 
 struct puffs_vnmsg_open {
@@ -410,6 +421,8 @@
 
        struct puffs_kcred      pvnr_cred;              /* OUT  */
        struct vattr            pvnr_va;                /* IN/OUT (op depend) */
+       /* Used only if PUFFS_KFLAG_CACHE_USE_TTL */
+       struct timespec         pvnr_va_ttl;            /* IN   */
 };
 
 #define puffs_vnmsg_read puffs_vnmsg_rw
@@ -480,6 +493,9 @@
 
        struct vattr            pvnr_va;                /* OUT  */
        puffs_cookie_t          pvnr_newnode;           /* IN   */
+       /* Used only if PUFFS_KFLAG_CACHE_USE_TTL */
+       struct timespec         pvnr_va_ttl;            /* IN   */
+       struct timespec         pvnr_cn_ttl;            /* IN   */
 };
 
 struct puffs_vnmsg_rmdir {
@@ -522,6 +538,9 @@
        struct vattr            pvnr_va;                /* OUT  */
        puffs_cookie_t          pvnr_newnode;           /* IN   */
        char                    pvnr_link[MAXPATHLEN];  /* OUT  */
+       /* Used only if PUFFS_KFLAG_CACHE_USE_TTL */
+       struct timespec         pvnr_va_ttl;            /* IN   */
+       struct timespec         pvnr_cn_ttl;            /* IN   */
 };
 
 struct puffs_vnmsg_readdir {
diff -r 4d44d1fa8a69 -r 68f4e6a59b56 sys/fs/puffs/puffs_node.c
--- a/sys/fs/puffs/puffs_node.c Sun Apr 08 13:14:29 2012 +0000
+++ b/sys/fs/puffs/puffs_node.c Sun Apr 08 15:04:41 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: puffs_node.c,v 1.23 2012/01/19 08:14:41 manu Exp $     */
+/*     $NetBSD: puffs_node.c,v 1.24 2012/04/08 15:04:41 manu Exp $     */
 
 /*
  * Copyright (c) 2005, 2006, 2007  Antti Kantee.  All Rights Reserved.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: puffs_node.c,v 1.23 2012/01/19 08:14:41 manu Exp $");
+__KERNEL_RCSID(0, "$NetBSD: puffs_node.c,v 1.24 2012/04/08 15:04:41 manu Exp $");
 
 #include <sys/param.h>
 #include <sys/hash.h>
@@ -63,6 +63,7 @@
                                             puffs_cookie_t);
 
 struct pool puffs_pnpool;
+struct pool puffs_vapool;
 
 /*
  * Grab a vnode, intialize all the puffs-dependent stuff.
@@ -483,6 +484,8 @@
                mutex_destroy(&pn->pn_mtx);
                mutex_destroy(&pn->pn_sizemtx);
                seldestroy(&pn->pn_sel);
+               if (pn->pn_va_cache != NULL)
+                       pool_put(&puffs_vapool, pn->pn_va_cache);
                pool_put(&puffs_pnpool, pn);
        } else {
                mutex_exit(&pn->pn_mtx);
diff -r 4d44d1fa8a69 -r 68f4e6a59b56 sys/fs/puffs/puffs_sys.h
--- a/sys/fs/puffs/puffs_sys.h  Sun Apr 08 13:14:29 2012 +0000
+++ b/sys/fs/puffs/puffs_sys.h  Sun Apr 08 15:04:41 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: puffs_sys.h,v 1.78 2011/08/29 04:12:45 manu Exp $      */
+/*     $NetBSD: puffs_sys.h,v 1.79 2012/04/08 15:04:41 manu Exp $      */
 
 /*
  * Copyright (c) 2005, 2006  Antti Kantee.  All Rights Reserved.
@@ -53,6 +53,7 @@
 extern const struct vnodeopv_desc puffs_msgop_opv_desc;
 
 extern struct pool puffs_pnpool;
+extern struct pool puffs_vapool;
 
 #ifdef DEBUG
 #ifndef PUFFSDEBUG
@@ -89,6 +90,8 @@
     (((pmp)->pmp_flags & PUFFS_KFLAG_NOCACHE_PAGE) == 0)
 #define PUFFS_USE_FULLPNBUF(pmp)       \
     ((pmp)->pmp_flags & PUFFS_KFLAG_LOOKUP_FULLPNBUF)
+#define PUFFS_USE_FS_TTL(pmp)  \
+    ((pmp)->pmp_flags & PUFFS_KFLAG_CACHE_FS_TTL)
 
 #define PUFFS_WCACHEINFO(pmp)  0
 
@@ -210,6 +213,10 @@
        struct lockf *  pn_lockf;
 
        kmutex_t        pn_sizemtx;     /* size modification mutex      */
+       
+       int             pn_cn_timeout;  /* path cache */
+       int             pn_va_timeout;  /* attribute cache */
+       struct vattr *  pn_va_cache;    /* attribute cache */
 
        LIST_ENTRY(puffs_node) pn_hashent;
 };
diff -r 4d44d1fa8a69 -r 68f4e6a59b56 sys/fs/puffs/puffs_vfsops.c
--- a/sys/fs/puffs/puffs_vfsops.c       Sun Apr 08 13:14:29 2012 +0000
+++ b/sys/fs/puffs/puffs_vfsops.c       Sun Apr 08 15:04:41 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: puffs_vfsops.c,v 1.100 2011/10/19 01:39:29 manu Exp $  */
+/*     $NetBSD: puffs_vfsops.c,v 1.101 2012/04/08 15:04:41 manu Exp $  */
 
 /*
  * Copyright (c) 2005, 2006  Antti Kantee.  All Rights Reserved.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: puffs_vfsops.c,v 1.100 2011/10/19 01:39:29 manu Exp $");
+__KERNEL_RCSID(0, "$NetBSD: puffs_vfsops.c,v 1.101 2012/04/08 15:04:41 manu Exp $");
 
 #include <sys/param.h>
 #include <sys/mount.h>
@@ -763,6 +763,8 @@
 
        pool_init(&puffs_pnpool, sizeof(struct puffs_node), 0, 0, 0,
            "puffpnpl", &pool_allocator_nointr, IPL_NONE);
+       pool_init(&puffs_vapool, sizeof(struct vattr), 0, 0, 0,
+           "puffvapl", &pool_allocator_nointr, IPL_NONE);
        puffs_msgif_init();
 }
 
@@ -772,6 +774,7 @@
 
        puffs_msgif_destroy();
        pool_destroy(&puffs_pnpool);
+       pool_destroy(&puffs_vapool);
 }
 
 int
diff -r 4d44d1fa8a69 -r 68f4e6a59b56 sys/fs/puffs/puffs_vnops.c
--- a/sys/fs/puffs/puffs_vnops.c        Sun Apr 08 13:14:29 2012 +0000
+++ b/sys/fs/puffs/puffs_vnops.c        Sun Apr 08 15:04:41 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: puffs_vnops.c,v 1.164 2012/03/16 23:13:48 jakllsch Exp $       */
+/*     $NetBSD: puffs_vnops.c,v 1.165 2012/04/08 15:04:41 manu 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.164 2012/03/16 23:13:48 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: puffs_vnops.c,v 1.165 2012/04/08 15:04:41 manu Exp $");
 
 #include <sys/param.h>
 #include <sys/buf.h>
@@ -40,6 +40,7 @@
 #include <sys/namei.h>
 #include <sys/vnode.h>
 #include <sys/proc.h>
+#include <sys/kernel.h> /* For hz, hardclock_ticks */
 
 #include <uvm/uvm.h>
 
@@ -410,6 +411,8 @@
 static void callinactive(struct puffs_mount *, puffs_cookie_t, int);
 static void callreclaim(struct puffs_mount *, puffs_cookie_t);
 static int  flushvncache(struct vnode *, off_t, off_t, bool);
+static void update_va(struct vnode *, struct vattr *, struct vattr *,
+                     struct timespec *, struct timespec *);
 
 
 #define PUFFS_ABORT_LOOKUP     1
@@ -455,6 +458,8 @@
  * don't want to think of the consequences for the time being.
  */
 
+#define TTL_TO_TIMEOUT(ts) \
+    (hardclock_ticks + (ts->tv_sec * hz) + (ts->tv_nsec * hz / 1000000000))
 int
 puffs_vnop_lookup(void *v)
 {
@@ -467,14 +472,16 @@
        PUFFS_MSG_VARS(vn, lookup);
        struct puffs_mount *pmp;
        struct componentname *cnp;
-       struct vnode *vp, *dvp;
-       struct puffs_node *dpn;
+       struct vnode *vp, *dvp, *cvp;
+       struct puffs_node *dpn, *cpn;
        int isdot;
        int error;
 
        pmp = MPTOPUFFSMP(ap->a_dvp->v_mount);
        cnp = ap->a_cnp;
        dvp = ap->a_dvp;
+       cvp = NULL;
+       cpn = NULL;
        *ap->a_vpp = NULL;
 
        /* r/o fs?  we check create later to handle EEXIST */
@@ -494,7 +501,31 @@
        if (PUFFS_USE_NAMECACHE(pmp)) {
                error = cache_lookup(dvp, ap->a_vpp, cnp);
 
-               if (error >= 0)
+               if ((error == 0) && PUFFS_USE_FS_TTL(pmp)) {
+
+                       cvp = *ap->a_vpp;
+                       cpn = VPTOPP(cvp);
+                       if (hardclock_ticks > cpn->pn_cn_timeout) {
+                               cache_purge1(cvp, NULL, PURGE_CHILDREN);
+
+                               /*
+                                * cached vnode (cvp) is still locked
+                                * so that we can reuse it upon a new
+                                * successful lookup. 
+                                */
+                               *ap->a_vpp = NULL;
+                               error = -1;
+                       }
+               }
+
+               /*
+                * Do not use negative caching, since the filesystem
+                * provides no TTL for it.
+                */
+               if ((error == ENOENT) && PUFFS_USE_FS_TTL(pmp))
+                       error = -1;
+
+               if (error >= 0) 
                        return error;
        }
 
@@ -503,12 +534,18 @@
                if (cnp->cn_nameiop == RENAME && (cnp->cn_flags & ISLASTCN))
                        return EISDIR;
 
+               if (cvp != NULL) 
+                       vput(cvp);
+
                vp = ap->a_dvp;
                vref(vp);
                *ap->a_vpp = vp;
                return 0;
        }
 
+       if (cvp != NULL)
+               mutex_enter(&cpn->pn_sizemtx);
+
        PUFFS_MSG_ALLOC(vn, lookup);



Home | Main Index | Thread Index | Old Index