linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: dhowells@redhat.com, nfsv4@linux-nfs.org, linux-fsdevel@vger.kernel.org
Subject: [PATCH 38/41] NFS: Read pages from FS-Cache into an NFS inode [ver #48]
Date: Fri, 03 Apr 2009 16:57:51 +0100	[thread overview]
Message-ID: <20090403155751.28714.23551.stgit@warthog.procyon.org.uk> (raw)
In-Reply-To: <20090403155436.28714.23368.stgit@warthog.procyon.org.uk>

Read pages from an FS-Cache data storage object representing an inode into an
NFS 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>
---

 fs/nfs/fscache.c |  112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/nfs/fscache.h |   47 +++++++++++++++++++++++
 fs/nfs/read.c    |   18 +++++++++
 3 files changed, 177 insertions(+), 0 deletions(-)


diff --git a/fs/nfs/fscache.c b/fs/nfs/fscache.c
index f673d35..3a30566 100644
--- a/fs/nfs/fscache.c
+++ b/fs/nfs/fscache.c
@@ -381,3 +381,115 @@ void __nfs_fscache_invalidate_page(struct page *page, struct inode *inode)
 	nfs_add_fscache_stats(page->mapping->host,
 			      NFSIOS_FSCACHE_PAGES_UNCACHED, 1);
 }
+
+/*
+ * Handle completion of a page being read from the cache.
+ * - Called in process (keventd) context.
+ */
+static void nfs_readpage_from_fscache_complete(struct page *page,
+					       void *context,
+					       int error)
+{
+	dfprintk(FSCACHE,
+		 "NFS: readpage_from_fscache_complete (0x%p/0x%p/%d)\n",
+		 page, context, error);
+
+	/* if the read completes with an error, we just unlock the page and let
+	 * the VM reissue the readpage */
+	if (!error) {
+		SetPageUptodate(page);
+		unlock_page(page);
+	} else {
+		error = nfs_readpage_async(context, page->mapping->host, page);
+		if (error)
+			unlock_page(page);
+	}
+}
+
+/*
+ * Retrieve a page from fscache
+ */
+int __nfs_readpage_from_fscache(struct nfs_open_context *ctx,
+				struct inode *inode, struct page *page)
+{
+	int ret;
+
+	dfprintk(FSCACHE,
+		 "NFS: readpage_from_fscache(fsc:%p/p:%p(i:%lx f:%lx)/0x%p)\n",
+		 NFS_I(inode)->fscache, page, page->index, page->flags, inode);
+
+	ret = fscache_read_or_alloc_page(NFS_I(inode)->fscache,
+					 page,
+					 nfs_readpage_from_fscache_complete,
+					 ctx,
+					 GFP_KERNEL);
+
+	switch (ret) {
+	case 0: /* read BIO submitted (page in fscache) */
+		dfprintk(FSCACHE,
+			 "NFS:    readpage_from_fscache: BIO submitted\n");
+		nfs_add_fscache_stats(inode, NFSIOS_FSCACHE_PAGES_READ_OK, 1);
+		return ret;
+
+	case -ENOBUFS: /* inode not in cache */
+	case -ENODATA: /* page not in cache */
+		nfs_add_fscache_stats(inode, NFSIOS_FSCACHE_PAGES_READ_FAIL, 1);
+		dfprintk(FSCACHE,
+			 "NFS:    readpage_from_fscache %d\n", ret);
+		return 1;
+
+	default:
+		dfprintk(FSCACHE, "NFS:    readpage_from_fscache %d\n", ret);
+		nfs_add_fscache_stats(inode, NFSIOS_FSCACHE_PAGES_READ_FAIL, 1);
+	}
+	return ret;
+}
+
+/*
+ * Retrieve a set of pages from fscache
+ */
+int __nfs_readpages_from_fscache(struct nfs_open_context *ctx,
+				 struct inode *inode,
+				 struct address_space *mapping,
+				 struct list_head *pages,
+				 unsigned *nr_pages)
+{
+	int ret, npages = *nr_pages;
+
+	dfprintk(FSCACHE, "NFS: nfs_getpages_from_fscache (0x%p/%u/0x%p)\n",
+		 NFS_I(inode)->fscache, npages, inode);
+
+	ret = fscache_read_or_alloc_pages(NFS_I(inode)->fscache,
+					  mapping, pages, nr_pages,
+					  nfs_readpage_from_fscache_complete,
+					  ctx,
+					  mapping_gfp_mask(mapping));
+	if (*nr_pages < npages)
+		nfs_add_fscache_stats(inode, NFSIOS_FSCACHE_PAGES_READ_OK,
+				      npages);
+	if (*nr_pages > 0)
+		nfs_add_fscache_stats(inode, NFSIOS_FSCACHE_PAGES_READ_FAIL,
+				      *nr_pages);
+
+	switch (ret) {
+	case 0: /* read submitted to the cache for all pages */
+		BUG_ON(!list_empty(pages));
+		BUG_ON(*nr_pages != 0);
+		dfprintk(FSCACHE,
+			 "NFS: nfs_getpages_from_fscache: submitted\n");
+
+		return ret;
+
+	case -ENOBUFS: /* some pages aren't cached and can't be */
+	case -ENODATA: /* some pages aren't cached */
+		dfprintk(FSCACHE,
+			 "NFS: nfs_getpages_from_fscache: no page: %d\n", ret);
+		return 1;
+
+	default:
+		dfprintk(FSCACHE,
+			 "NFS: nfs_getpages_from_fscache: ret  %d\n", ret);
+	}
+
+	return ret;
+}
diff --git a/fs/nfs/fscache.h b/fs/nfs/fscache.h
index e29613a..099349c 100644
--- a/fs/nfs/fscache.h
+++ b/fs/nfs/fscache.h
@@ -86,6 +86,12 @@ extern void nfs_fscache_reset_inode_cookie(struct inode *);
 extern void __nfs_fscache_invalidate_page(struct page *, struct inode *);
 extern int nfs_fscache_release_page(struct page *, gfp_t);
 
+extern int __nfs_readpage_from_fscache(struct nfs_open_context *,
+				       struct inode *, struct page *);
+extern int __nfs_readpages_from_fscache(struct nfs_open_context *,
+					struct inode *, struct address_space *,
+					struct list_head *, unsigned *);
+
 /*
  * wait for a page to complete writing to the cache
  */
@@ -107,6 +113,32 @@ static inline void nfs_fscache_invalidate_page(struct page *page,
 		__nfs_fscache_invalidate_page(page, inode);
 }
 
+/*
+ * Retrieve a page from an inode data storage object.
+ */
+static inline int nfs_readpage_from_fscache(struct nfs_open_context *ctx,
+					    struct inode *inode,
+					    struct page *page)
+{
+	if (NFS_I(inode)->fscache)
+		return __nfs_readpage_from_fscache(ctx, inode, page);
+	return -ENOBUFS;
+}
+
+/*
+ * Retrieve a set of pages from an inode data storage object.
+ */
+static inline int nfs_readpages_from_fscache(struct nfs_open_context *ctx,
+					     struct inode *inode,
+					     struct address_space *mapping,
+					     struct list_head *pages,
+					     unsigned *nr_pages)
+{
+	if (NFS_I(inode)->fscache)
+		return __nfs_readpages_from_fscache(ctx, inode, mapping, pages,
+						    nr_pages);
+	return -ENOBUFS;
+}
 
 #else /* CONFIG_NFS_FSCACHE */
 static inline int nfs_fscache_register(void) { return 0; }
@@ -138,5 +170,20 @@ static inline void nfs_fscache_invalidate_page(struct page *page,
 static inline void nfs_fscache_wait_on_page_write(struct nfs_inode *nfsi,
 						  struct page *page) {}
 
+static inline int nfs_readpage_from_fscache(struct nfs_open_context *ctx,
+					    struct inode *inode,
+					    struct page *page)
+{
+	return -ENOBUFS;
+}
+static inline int nfs_readpages_from_fscache(struct nfs_open_context *ctx,
+					     struct inode *inode,
+					     struct address_space *mapping,
+					     struct list_head *pages,
+					     unsigned *nr_pages)
+{
+	return -ENOBUFS;
+}
+
 #endif /* CONFIG_NFS_FSCACHE */
 #endif /* _NFS_FSCACHE_H */
diff --git a/fs/nfs/read.c b/fs/nfs/read.c
index 98b7400..e18ba79 100644
--- a/fs/nfs/read.c
+++ b/fs/nfs/read.c
@@ -24,6 +24,7 @@
 
 #include "internal.h"
 #include "iostat.h"
+#include "fscache.h"
 
 #define NFSDBG_FACILITY		NFSDBG_PAGECACHE
 
@@ -510,8 +511,15 @@ int nfs_readpage(struct file *file, struct page *page)
 	} else
 		ctx = get_nfs_open_context(nfs_file_open_context(file));
 
+	if (!IS_SYNC(inode)) {
+		error = nfs_readpage_from_fscache(ctx, inode, page);
+		if (error == 0)
+			goto out;
+	}
+
 	error = nfs_readpage_async(ctx, inode, page);
 
+out:
 	put_nfs_open_context(ctx);
 	return error;
 out_unlock:
@@ -584,6 +592,15 @@ int nfs_readpages(struct file *filp, struct address_space *mapping,
 			return -EBADF;
 	} else
 		desc.ctx = get_nfs_open_context(nfs_file_open_context(filp));
+
+	/* attempt to read as many of the pages as possible from the cache
+	 * - this returns -ENOBUFS immediately if the cookie is negative
+	 */
+	ret = nfs_readpages_from_fscache(desc.ctx, inode, mapping,
+					 pages, &nr_pages);
+	if (ret == 0)
+		goto read_complete; /* all pages were read */
+
 	if (rsize < PAGE_CACHE_SIZE)
 		nfs_pageio_init(&pgio, inode, nfs_pagein_multi, rsize, 0);
 	else
@@ -594,6 +611,7 @@ int nfs_readpages(struct file *filp, struct address_space *mapping,
 	nfs_pageio_complete(&pgio);
 	npages = (pgio.pg_bytes_written + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
 	nfs_add_stats(inode, NFSIOS_READPAGES, npages);
+read_complete:
 	put_nfs_open_context(desc.ctx);
 out:
 	return ret;


  parent reply	other threads:[~2009-04-03 15:57 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-03 15:54 [PATCH 00/41] Permit filesystem local caching [ver #48] David Howells
2009-04-03 15:54 ` [PATCH 01/41] Create a dynamically sized pool of threads for doing very slow work items " David Howells
2009-04-03 15:54 ` [PATCH 02/41] Make slow-work thread pool actually dynamic " David Howells
2009-04-03 15:54 ` [PATCH 03/41] Make the slow work pool configurable " David Howells
2009-04-03 15:54 ` [PATCH 04/41] Document the slow work thread pool " David Howells
2009-04-03 15:55 ` [PATCH 05/41] FS-Cache: Release page->private after failed readahead " David Howells
2009-04-04  6:00   ` Nick Piggin
2009-04-03 15:55 ` [PATCH 06/41] FS-Cache: Recruit a page flags for cache management " David Howells
2009-04-04  6:04   ` Nick Piggin
2009-04-03 15:55 ` [PATCH 07/41] FS-Cache: Add the FS-Cache netfs API and documentation " David Howells
2009-04-03 15:55 ` [PATCH 08/41] FS-Cache: Add the FS-Cache cache backend " David Howells
2009-04-03 15:55 ` [PATCH 09/41] FS-Cache: Add main configuration option, module entry points and debugging " David Howells
2009-04-03 15:55 ` [PATCH 10/41] FS-Cache: Add use of /proc and presentation of statistics " David Howells
2009-04-04 17:39   ` Christoph Hellwig
2009-04-03 15:55 ` [PATCH 11/41] FS-Cache: Root index definition " David Howells
2009-04-03 15:55 ` [PATCH 12/41] FS-Cache: Add cache tag handling " David Howells
2009-04-03 15:55 ` [PATCH 13/41] FS-Cache: Add cache management " David Howells
2009-04-03 15:55 ` [PATCH 14/41] FS-Cache: Provide a slab for cookie allocation " David Howells
2009-04-03 15:55 ` [PATCH 15/41] FS-Cache: Add netfs registration " David Howells
2009-04-03 15:55 ` [PATCH 16/41] FS-Cache: Bit waiting helpers " David Howells
2009-04-03 15:56 ` [PATCH 17/41] FS-Cache: Object management state machine " David Howells
2009-04-03 15:56 ` [PATCH 18/41] FS-Cache: Implement the cookie management part of the netfs API " David Howells
2009-04-03 15:56 ` [PATCH 19/41] FS-Cache: Add and document asynchronous operation handling " David Howells
2009-04-03 15:56 ` [PATCH 20/41] FS-Cache: Implement data I/O part of netfs API " David Howells
2009-04-03 15:56 ` [PATCH 21/41] CacheFiles: Permit the page lock state to be monitored " David Howells
2009-04-04  6:09   ` Nick Piggin
2009-04-04 14:22     ` Nick Piggin
2009-04-04 22:13     ` David Howells
2009-04-06  8:31       ` Nick Piggin
2009-04-04 11:31   ` David Howells
2009-04-06  9:34     ` Nick Piggin
2009-04-03 15:56 ` [PATCH 22/41] CacheFiles: Export things for CacheFiles " David Howells
2009-04-03 15:56 ` [PATCH 23/41] CacheFiles: A cache that backs onto a mounted filesystem " David Howells
2009-04-03 15:56 ` [PATCH 24/41] FS-Cache: Make kAFS use FS-Cache " David Howells
2009-04-03 15:56 ` [PATCH 25/41] NFS: Add comment banners to some NFS functions " David Howells
2009-04-03 15:56 ` [PATCH 26/41] NFS: Add FS-Cache option bit and debug bit " David Howells
2009-04-03 15:56 ` [PATCH 27/41] NFS: Permit local filesystem caching to be enabled for NFS " David Howells
2009-04-03 15:57 ` [PATCH 28/41] NFS: Register NFS for caching and retrieve the top-level index " David Howells
2009-04-03 15:57 ` [PATCH 29/41] NFS: Define and create server-level objects " David Howells
2009-04-03 15:57 ` [PATCH 30/41] NFS: Define and create superblock-level " David Howells
2009-04-03 15:57 ` [PATCH 31/41] NFS: Define and create inode-level cache " David Howells
2009-04-03 15:57 ` [PATCH 32/41] NFS: Use local disk inode cache " David Howells
2009-04-03 15:57 ` [PATCH 33/41] NFS: Invalidate FsCache page flags when cache removed " David Howells
2009-04-03 15:57 ` [PATCH 34/41] NFS: Add some new I/O counters for FS-Cache doing things for NFS " David Howells
2009-04-03 15:57 ` [PATCH 35/41] NFS: FS-Cache page management " David Howells
2009-04-03 15:57 ` [PATCH 36/41] NFS: Add read context retention for FS-Cache to call back with " David Howells
2009-04-03 15:57 ` [PATCH 37/41] NFS: nfs_readpage_async() needs to be accessible as a fallback for local caching " David Howells
2009-04-03 15:57 ` David Howells [this message]
2009-04-03 15:57 ` [PATCH 39/41] NFS: Store pages from an NFS inode into a local cache " David Howells
2009-04-03 15:58 ` [PATCH 40/41] NFS: Display local caching state " David Howells
2009-04-03 15:58 ` [PATCH 41/41] NFS: Add mount options to enable local caching on NFS " David Howells

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090403155751.28714.23551.stgit@warthog.procyon.org.uk \
    --to=dhowells@redhat.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nfsv4@linux-nfs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).