From 6a9301d933d5e1505bd93b4348d16986ecd617f0 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Sun, 21 Feb 2010 23:40:43 -0800 Subject: [PATCH] kernel - NFS - Add the 'cache' flag to enable swapcache on a NFS mount * The current round of swapcache work doesn't propagate the cache flag across mount points so NFS needs a cache mount flag. --- sbin/mount_nfs/mount_nfs.c | 6 +++++- sys/vfs/nfs/nfs.h | 2 +- sys/vfs/nfs/nfs_vnops.c | 13 +++++++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/sbin/mount_nfs/mount_nfs.c b/sbin/mount_nfs/mount_nfs.c index 51a3ee8a46..b2d79bdb43 100644 --- a/sbin/mount_nfs/mount_nfs.c +++ b/sbin/mount_nfs/mount_nfs.c @@ -76,7 +76,7 @@ #define ALTF_KERB 0x10 #define ALTF_NFSV3 0x20 #define ALTF_RDIRPLUS 0x40 -#define ALTF_UNUSED080 0x80 +#define ALTF_CACHE 0x80 #define ALTF_RESVPORT 0x100 #define ALTF_SEQPACKET 0x200 #define ALTF_UNUSED400 0x400 @@ -114,6 +114,7 @@ struct mntopt mopts[] = { { "acregmax=", 0, ALTF_ACREGMAX, 1 }, { "acdirmin=", 0, ALTF_ACDIRMIN, 1 }, { "acdirmax=", 0, ALTF_ACDIRMAX, 1 }, + { "cache", 0, ALTF_CACHE, 1 }, MOPT_NULL }; @@ -249,6 +250,9 @@ set_flags(int* altflags, int* nfsflags, int dir) F(ACREGMAX); F(ACDIRMIN); F(ACDIRMAX); +#ifdef NFSMNT_CACHE + F(CACHE); +#endif #undef F #undef F2 diff --git a/sys/vfs/nfs/nfs.h b/sys/vfs/nfs/nfs.h index 5e7102199e..d0fa2c5284 100644 --- a/sys/vfs/nfs/nfs.h +++ b/sys/vfs/nfs/nfs.h @@ -165,7 +165,7 @@ struct nfs_args { #define NFSMNT_NFSV3 0x00000200 /* Use NFS Version 3 protocol */ #define NFSMNT_KERB 0x00000400 /* Use Kerberos authentication */ #define NFSMNT_DUMBTIMR 0x00000800 /* Don't estimate rtt dynamically */ -#define NFSMNT_UNUSED1000 0x00001000 /* set lease term (nqnfs) */ +#define NFSMNT_CACHE 0x00001000 /* enable swapcache */ #define NFSMNT_READAHEAD 0x00002000 /* set read ahead */ #define NFSMNT_DEADTHRESH 0x00004000 /* set dead server retry thresh */ #define NFSMNT_RESVPORT 0x00008000 /* Allocate a reserved port */ diff --git a/sys/vfs/nfs/nfs_vnops.c b/sys/vfs/nfs/nfs_vnops.c index dcd47e4c78..3b5685da82 100644 --- a/sys/vfs/nfs/nfs_vnops.c +++ b/sys/vfs/nfs/nfs_vnops.c @@ -643,12 +643,14 @@ nfs_getattr(struct vop_getattr_args *ap) { struct vnode *vp = ap->a_vp; struct nfsnode *np = VTONFS(vp); + struct nfsmount *nmp; int error = 0; thread_t td = curthread; struct nfsm_info info; info.mrep = NULL; info.v3 = NFS_ISV3(vp); + nmp = VFSTONFS(vp->v_mount); /* * Update local times for special files. @@ -659,13 +661,13 @@ nfs_getattr(struct vop_getattr_args *ap) * First look in the cache. */ if (nfs_getattrcache(vp, ap->a_vap) == 0) - return (0); + goto done; if (info.v3 && nfsaccess_cache_timeout > 0) { nfsstats.accesscache_misses++; nfs3_access_otw(vp, NFSV3ACCESS_ALL, td, nfs_vpcred(vp, ND_CHECK)); if (nfs_getattrcache(vp, ap->a_vap) == 0) - return (0); + goto done; } nfsstats.rpccnt[NFSPROC_GETATTR]++; @@ -678,6 +680,13 @@ nfs_getattr(struct vop_getattr_args *ap) } m_freem(info.mrep); info.mrep = NULL; +done: + /* + * NFS doesn't support chflags flags. If the nfs mount was + * made -o cache set the UF_CACHE bit for swapcache. + */ + if ((nmp->nm_flag & NFSMNT_CACHE) && (vp->v_flag & VROOT)) + ap->a_vap->va_flags |= UF_CACHE; nfsmout: return (error); } -- 2.11.4.GIT