aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2009-04-03 11:42:45 -0400
committerDavid Howells <dhowells@redhat.com>2009-04-03 11:42:45 -0400
commit7f8e05f60c87646e12c761fef61dd71a7e67112e (patch)
treef33bfcd5b4662a48890e8245362b381437be76fb /fs
parent9a9fc1c03315f1606596e55b4096d39e2079a041 (diff)
NFS: Store pages from an NFS inode into a local cache
Store pages from an NFS inode into the cache data storage object associated with that inode. Signed-off-by: David Howells <dhowells@redhat.com> Acked-by: Steve Dickson <steved@redhat.com> Acked-by: Trond Myklebust <Trond.Myklebust@netapp.com> Acked-by: Al Viro <viro@zeniv.linux.org.uk> Tested-by: Daire Byrne <Daire.Byrne@framestore.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/nfs/fscache.c28
-rw-r--r--fs/nfs/fscache.h16
-rw-r--r--fs/nfs/read.c5
3 files changed, 49 insertions, 0 deletions
diff --git a/fs/nfs/fscache.c b/fs/nfs/fscache.c
index 3a3056657858..379be678cb7e 100644
--- a/fs/nfs/fscache.c
+++ b/fs/nfs/fscache.c
@@ -493,3 +493,31 @@ int __nfs_readpages_from_fscache(struct nfs_open_context *ctx,
493 493
494 return ret; 494 return ret;
495} 495}
496
497/*
498 * Store a newly fetched page in fscache
499 * - PG_fscache must be set on the page
500 */
501void __nfs_readpage_to_fscache(struct inode *inode, struct page *page, int sync)
502{
503 int ret;
504
505 dfprintk(FSCACHE,
506 "NFS: readpage_to_fscache(fsc:%p/p:%p(i:%lx f:%lx)/%d)\n",
507 NFS_I(inode)->fscache, page, page->index, page->flags, sync);
508
509 ret = fscache_write_page(NFS_I(inode)->fscache, page, GFP_KERNEL);
510 dfprintk(FSCACHE,
511 "NFS: readpage_to_fscache: p:%p(i:%lu f:%lx) ret %d\n",
512 page, page->index, page->flags, ret);
513
514 if (ret != 0) {
515 fscache_uncache_page(NFS_I(inode)->fscache, page);
516 nfs_add_fscache_stats(inode,
517 NFSIOS_FSCACHE_PAGES_WRITTEN_FAIL, 1);
518 nfs_add_fscache_stats(inode, NFSIOS_FSCACHE_PAGES_UNCACHED, 1);
519 } else {
520 nfs_add_fscache_stats(inode,
521 NFSIOS_FSCACHE_PAGES_WRITTEN_OK, 1);
522 }
523}
diff --git a/fs/nfs/fscache.h b/fs/nfs/fscache.h
index 099349c171ca..1ec3ebb0efcd 100644
--- a/fs/nfs/fscache.h
+++ b/fs/nfs/fscache.h
@@ -91,6 +91,7 @@ extern int __nfs_readpage_from_fscache(struct nfs_open_context *,
91extern int __nfs_readpages_from_fscache(struct nfs_open_context *, 91extern int __nfs_readpages_from_fscache(struct nfs_open_context *,
92 struct inode *, struct address_space *, 92 struct inode *, struct address_space *,
93 struct list_head *, unsigned *); 93 struct list_head *, unsigned *);
94extern void __nfs_readpage_to_fscache(struct inode *, struct page *, int);
94 95
95/* 96/*
96 * wait for a page to complete writing to the cache 97 * wait for a page to complete writing to the cache
@@ -140,6 +141,19 @@ static inline int nfs_readpages_from_fscache(struct nfs_open_context *ctx,
140 return -ENOBUFS; 141 return -ENOBUFS;
141} 142}
142 143
144/*
145 * Store a page newly fetched from the server in an inode data storage object
146 * in the cache.
147 */
148static inline void nfs_readpage_to_fscache(struct inode *inode,
149 struct page *page,
150 int sync)
151{
152 if (PageFsCache(page))
153 __nfs_readpage_to_fscache(inode, page, sync);
154}
155
156
143#else /* CONFIG_NFS_FSCACHE */ 157#else /* CONFIG_NFS_FSCACHE */
144static inline int nfs_fscache_register(void) { return 0; } 158static inline int nfs_fscache_register(void) { return 0; }
145static inline void nfs_fscache_unregister(void) {} 159static inline void nfs_fscache_unregister(void) {}
@@ -184,6 +198,8 @@ static inline int nfs_readpages_from_fscache(struct nfs_open_context *ctx,
184{ 198{
185 return -ENOBUFS; 199 return -ENOBUFS;
186} 200}
201static inline void nfs_readpage_to_fscache(struct inode *inode,
202 struct page *page, int sync) {}
187 203
188#endif /* CONFIG_NFS_FSCACHE */ 204#endif /* CONFIG_NFS_FSCACHE */
189#endif /* _NFS_FSCACHE_H */ 205#endif /* _NFS_FSCACHE_H */
diff --git a/fs/nfs/read.c b/fs/nfs/read.c
index e18ba792872f..4ace3c50a8eb 100644
--- a/fs/nfs/read.c
+++ b/fs/nfs/read.c
@@ -140,6 +140,11 @@ int nfs_readpage_async(struct nfs_open_context *ctx, struct inode *inode,
140 140
141static void nfs_readpage_release(struct nfs_page *req) 141static void nfs_readpage_release(struct nfs_page *req)
142{ 142{
143 struct inode *d_inode = req->wb_context->path.dentry->d_inode;
144
145 if (PageUptodate(req->wb_page))
146 nfs_readpage_to_fscache(d_inode, req->wb_page, 0);
147
143 unlock_page(req->wb_page); 148 unlock_page(req->wb_page);
144 149
145 dprintk("NFS: read done (%s/%Ld %d@%Ld)\n", 150 dprintk("NFS: read done (%s/%Ld %d@%Ld)\n",