From 83393f7ead1f249ca73d192672050641ebcf7af8 Mon Sep 17 00:00:00 2001 From: dm Date: Tue, 17 Dec 1996 03:46:36 +0000 Subject: [PATCH] NFS attribute cache timeout mount param --- sys/nfs/nfs.h | 4 +++- sys/nfs/nfs_subs.c | 29 +++++++++++++++++++++++++++-- sys/nfs/nfs_vfsops.c | 42 +++++++++++++++++++++++++++++++++++++++--- sys/nfs/nfsmount.h | 6 +++++- sys/sys/mount.h | 34 ++++++++++++++++++++++++++++++++-- 5 files changed, 106 insertions(+), 9 deletions(-) diff --git a/sys/nfs/nfs.h b/sys/nfs/nfs.h index 1de0ee04b42..7055409babe 100644 --- a/sys/nfs/nfs.h +++ b/sys/nfs/nfs.h @@ -1,4 +1,4 @@ -/* $OpenBSD: nfs.h,v 1.5 1996/06/10 07:28:52 deraadt Exp $ */ +/* $OpenBSD: nfs.h,v 1.6 1996/12/17 03:46:37 dm Exp $ */ /* $NetBSD: nfs.h,v 1.10.4.1 1996/05/27 11:23:56 fvdl Exp $ */ /* @@ -127,11 +127,13 @@ /* * Set the attribute timeout based on how recently the file has been modified. */ +#if 0 /* replaced by nfs_attrtimeo() in nfs_subs.c */ #define NFS_ATTRTIMEO(np) \ ((((np)->n_flag & NMODIFIED) || \ (time.tv_sec - (np)->n_mtime) / 10 < NFS_MINATTRTIMO) ? NFS_MINATTRTIMO : \ ((time.tv_sec - (np)->n_mtime) / 10 > NFS_MAXATTRTIMO ? NFS_MAXATTRTIMO : \ (time.tv_sec - (np)->n_mtime) / 10)) +#endif /* * Expected allocation sizes for major data structures. If the actual size diff --git a/sys/nfs/nfs_subs.c b/sys/nfs/nfs_subs.c index 231f8e509ba..27e475c0ebc 100644 --- a/sys/nfs/nfs_subs.c +++ b/sys/nfs/nfs_subs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nfs_subs.c,v 1.13 1996/10/15 11:34:15 deraadt Exp $ */ +/* $OpenBSD: nfs_subs.c,v 1.14 1996/12/17 03:46:38 dm Exp $ */ /* $NetBSD: nfs_subs.c,v 1.27.4.3 1996/07/08 20:34:24 jtc Exp $ */ /* @@ -1321,6 +1321,31 @@ nfs_loadattrcache(vpp, mdp, dposp, vaper) return (0); } +inline int +nfs_attrtimeo (struct nfsnode *np) +{ + struct vnode *vp = np->n_vnode; + struct nfsmount *nmp = VFSTONFS(vp->v_mount); + int tenthage = (time.tv_sec - np->n_mtime) / 10; + int minto, maxto; + + if (vp->v_type == VDIR) { + maxto = nmp->nm_acdirmax; + minto = nmp->nm_acdirmin; + } + else { + maxto = nmp->nm_acregmax; + minto = nmp->nm_acregmin; + } + + if (np->n_flag & NMODIFIED || tenthage < minto) + return minto; + else if (tenthage < maxto) + return tenthage; + else + return maxto; +} + /* * Check the time stamp * If the cache is valid, copy contents to *vap and return 0 @@ -1334,7 +1359,7 @@ nfs_getattrcache(vp, vaper) register struct nfsnode *np = VTONFS(vp); register struct vattr *vap; - if ((time.tv_sec - np->n_attrstamp) >= NFS_ATTRTIMEO(np)) { + if ((time.tv_sec - np->n_attrstamp) >= nfs_attrtimeo(np)) { nfsstats.attrcache_misses++; return (ENOENT); } diff --git a/sys/nfs/nfs_vfsops.c b/sys/nfs/nfs_vfsops.c index 5e9fd779b7d..1b09ef1789a 100644 --- a/sys/nfs/nfs_vfsops.c +++ b/sys/nfs/nfs_vfsops.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nfs_vfsops.c,v 1.13 1996/09/21 11:06:22 deraadt Exp $ */ +/* $OpenBSD: nfs_vfsops.c,v 1.14 1996/12/17 03:46:39 dm Exp $ */ /* $NetBSD: nfs_vfsops.c,v 1.46.4.1 1996/05/25 22:40:35 fvdl Exp $ */ /* @@ -543,6 +543,29 @@ nfs_decode_args(nmp, argp) argp->deadthresh <= NQ_NEVERDEAD) nmp->nm_deadthresh = argp->deadthresh; + if (argp->flags & NFSMNT_ACTIMES) { + if (argp->acregmax > 0xffff) + nmp->nm_acregmax = 0xffff; + else if (argp->acregmax >= 0) + nmp->nm_acregmax = argp->acregmax; + if (argp->acregmin >= 0) { + if (argp->acregmin > nmp->nm_acregmax) + nmp->nm_acregmin = nmp->nm_acregmax; + else + nmp->nm_acregmin = argp->acregmin; + } + if (argp->acdirmax > 0xffff) + nmp->nm_acdirmax = 0xffff; + else if (argp->acdirmax >= 0) + nmp->nm_acdirmax = argp->acdirmax; + if (argp->acdirmin >= 0) { + if (argp->acdirmin > nmp->nm_acdirmax) + nmp->nm_acdirmin = nmp->nm_acdirmax; + else + nmp->nm_acdirmin = argp->acdirmin; + } + } + if (nmp->nm_so && adjsock) { nfs_disconnect(nmp); if (nmp->nm_sotype == SOCK_DGRAM) @@ -580,11 +603,20 @@ nfs_mount(mp, path, data, ndp, p) size_t len; u_char nfh[NFSX_V3FHMAX]; - error = copyin(data, (caddr_t)&args, sizeof (struct nfs_args)); + error = copyin (data, (caddr_t)&args, sizeof (args.version)); if (error) return (error); - if (args.version != NFS_ARGSVERSION) + if (args.version == 3) { + error = copyin (data, (caddr_t)&args, + sizeof (struct nfs_args3)); + args.flags &= ~NFSMNT_INTERNAL; + } + else if (args.version == NFS_ARGSVERSION) + error = copyin(data, (caddr_t)&args, sizeof (struct nfs_args)); + else return (EPROGMISMATCH); + if (error) + return (error); args.flags |= NFSMNT_RESVPORT; /* ALWAYS allocate one */ if (mp->mnt_flag & MNT_UPDATE) { register struct nfsmount *nmp = VFSTONFS(mp); @@ -674,6 +706,10 @@ mountnfs(argp, mp, nam, pth, hst, vpp) CIRCLEQ_INIT(&nmp->nm_timerhead); nmp->nm_inprog = NULLVP; nmp->nm_fhsize = argp->fhsize; + nmp->nm_acregmin = NFS_MINATTRTIMO; + nmp->nm_acregmax = NFS_MAXATTRTIMO; + nmp->nm_acdirmin = NFS_MINATTRTIMO; + nmp->nm_acdirmax = NFS_MAXATTRTIMO; bcopy((caddr_t)argp->fh, (caddr_t)nmp->nm_fh, argp->fhsize); #ifdef COMPAT_09 mp->mnt_stat.f_type = 2; diff --git a/sys/nfs/nfsmount.h b/sys/nfs/nfsmount.h index 12cae0aef94..290f83736b4 100644 --- a/sys/nfs/nfsmount.h +++ b/sys/nfs/nfsmount.h @@ -1,4 +1,4 @@ -/* $OpenBSD: nfsmount.h,v 1.3 1996/03/31 13:16:12 mickey Exp $ */ +/* $OpenBSD: nfsmount.h,v 1.4 1996/12/17 03:46:39 dm Exp $ */ /* $NetBSD: nfsmount.h,v 1.10 1996/02/18 11:54:03 fvdl Exp $ */ /* @@ -85,6 +85,10 @@ struct nfsmount { int nm_numuids; /* Number of nfsuid mappings */ TAILQ_HEAD(, nfsuid) nm_uidlruhead; /* Lists of nfsuid mappings */ LIST_HEAD(, nfsuid) nm_uidhashtbl[NFS_MUIDHASHSIZ]; + u_short nm_acregmin; /* Attr cache file recently modified */ + u_short nm_acregmax; /* ac file not recently modified */ + u_short nm_acdirmin; /* ac for dir recently modified */ + u_short nm_acdirmax; /* ac for dir not recently modified */ }; #ifdef _KERNEL diff --git a/sys/sys/mount.h b/sys/sys/mount.h index 68ed984626e..ca540840089 100644 --- a/sys/sys/mount.h +++ b/sys/sys/mount.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mount.h,v 1.10 1996/07/05 09:09:06 deraadt Exp $ */ +/* $OpenBSD: mount.h,v 1.11 1996/12/17 03:46:36 dm Exp $ */ /* $NetBSD: mount.h,v 1.48 1996/02/18 11:55:47 fvdl Exp $ */ /* @@ -306,7 +306,7 @@ struct iso_args { /* * Arguments to mount NFS */ -#define NFS_ARGSVERSION 3 /* change when nfs_args changes */ +#define NFS_ARGSVERSION 4 /* change when nfs_args changes */ struct nfs_args { int version; /* args structure version number */ struct sockaddr *addr; /* file server address */ @@ -326,6 +326,31 @@ struct nfs_args { int leaseterm; /* Term (sec) of lease */ int deadthresh; /* Retrans threshold */ char *hostname; /* server's name */ + int acregmin; /* Attr cache file recently modified */ + int acregmax; /* ac file not recently modified */ + int acdirmin; /* ac for dir recently modified */ + int acdirmax; /* ac for dir not recently modified */ +}; +/* NFS args version 3 (for backwards compatibility) */ +struct nfs_args3 { + int version; /* args structure version number */ + struct sockaddr *addr; /* file server address */ + int addrlen; /* length of address */ + int sotype; /* Socket type */ + int proto; /* and Protocol */ + u_char *fh; /* File handle to be mounted */ + int fhsize; /* Size, in bytes, of fh */ + int flags; /* flags */ + int wsize; /* write size in bytes */ + int rsize; /* read size in bytes */ + int readdirsize; /* readdir size in bytes */ + int timeo; /* initial timeout in .1 secs */ + int retrans; /* times to retry send */ + int maxgrouplist; /* Max. size of group list */ + int readahead; /* # of blocks to readahead */ + int leaseterm; /* Term (sec) of lease */ + int deadthresh; /* Retrans threshold */ + char *hostname; /* server's name */ }; /* @@ -349,6 +374,11 @@ struct nfs_args { #define NFSMNT_RESVPORT 0x00008000 /* Allocate a reserved port */ #define NFSMNT_RDIRPLUS 0x00010000 /* Use Readdirplus for V3 */ #define NFSMNT_READDIRSIZE 0x00020000 /* Set readdir size */ + +/* Flags valid only in mount syscall arguments */ +#define NFSMNT_ACTIMES 0x00040000 /* Args contain attr cache times*/ + +/* Flags valid only in kernel */ #define NFSMNT_INTERNAL 0xfffc0000 /* Bits set internally */ #define NFSMNT_HASWRITEVERF 0x00040000 /* Has write verifier for V3 */ #define NFSMNT_GOTPATHCONF 0x00080000 /* Got the V3 pathconf info */ -- 2.20.1