NFS: Clean up nfs_readpage() and nfs_readpages()
Subsystems (2)
PATCH 1/8 NFS: Clean up nfs_readpage() and nfs_readpages()
In prep for the new fscache netfs API, refactor nfs_readpage() and nfs_readpages() for future patches. No functional change.
--- fs/nfs/read.c | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-)
fs/nfs/read.c +23 -22
@@ -314,7 +314,7 @@ int nfs_readpage(struct file *file, struct page *page) {struct nfs_open_context *ctx;struct inode *inode =page_file_mapping (page)->host; -int error; +int ret;dprintk ("NFS: nfs_readpage (%p %ld@%lu)\n" , page,PAGE_SIZE ,page_index (page));
@@ -328,18 +328,18 @@ int nfs_readpage(struct file *file, struct page *page)* be any new pending writes generated at this point * for this page (other pages can be written to). */ - error =nfs_wb_page (inode, page); -if (error) + ret =nfs_wb_page (inode, page); +if (ret) goto out_unlock;if (PageUptodate (page)) goto out_unlock; - error = -ESTALE ; + ret = -ESTALE ;if (NFS_STALE (inode)) goto out_unlock;if (file ==NULL ) { - error = -EBADF ; + ret = -EBADF ; ctx =nfs_find_open_context (inode,NULL ,FMODE_READ );if (ctx ==NULL ) goto out_unlock;
@@ -347,24 +347,24 @@ int nfs_readpage(struct file *file, struct page *page) 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 ) + ret =nfs_readpage_from_fscache (ctx, inode, page); +if (ret ==0 ) goto out; }xchg (&ctx->error,0 ); - error =nfs_readpage_async (ctx, inode, page); -if (!error) { - error =wait_on_page_locked_killable (page); -if (!PageUptodate (page) && !error) - error =xchg (&ctx->error,0 ); + ret =nfs_readpage_async (ctx, inode, page); +if (!ret) { + ret =wait_on_page_locked_killable (page); +if (!PageUptodate (page) && !ret) + ret =xchg (&ctx->error,0 ); } out:put_nfs_open_context (ctx); -return error; +return ret; out_unlock:unlock_page (page); -return error; +return ret; }struct nfs_readdesc {
@@ -404,17 +404,15 @@ struct nfs_readdesc {return error; } -int nfs_readpages (struct file *filp,struct address_space *mapping, +int nfs_readpages (struct file *file,struct address_space *mapping,struct list_head *pages,unsigned nr_pages) {struct nfs_pageio_descriptor pgio;struct nfs_pgio_mirror *pgm; -struct nfs_readdesc desc = { - .pgio = &pgio, - }; +struct nfs_readdesc desc;struct inode *inode = mapping->host;unsigned long npages; -int ret = -ESTALE ; +int ret; dprintk("NFS: nfs_readpages (%s/%Lu %d)\n", inode->i_sb->s_id,
@@ -422,15 +420,17 @@ int nfs_readpages(struct file *filp, struct address_space *mapping, nr_pages);nfs_inc_stats (inode,NFSIOS_VFSREADPAGES ); + ret = -ESTALE ;if (NFS_STALE (inode)) goto out; -if (filp ==NULL ) { +if (file ==NULL ) { + ret = -EBADF ; desc.ctx =nfs_find_open_context (inode,NULL ,FMODE_READ );if (desc.ctx ==NULL ) -return -EBADF ; + goto out; }else - desc.ctx =get_nfs_open_context (nfs_file_open_context (filp)); + desc.ctx =get_nfs_open_context (nfs_file_open_context (file));/* attempt to read as many of the pages as possible from the cache * - this returns -ENOBUFS immediately if the cookie is negative
@@ -440,6 +440,7 @@ int nfs_readpages(struct file *filp, struct address_space *mapping,if (ret ==0 ) goto read_complete;/* all pages were read */ + desc.pgio = &pgio;nfs_pageio_init_read (&pgio, inode, false, &nfs_async_read_completion_ops);
Signature · 1 line
1.8.3.1
PATCH 2/8 NFS: In nfs_readpage() only increment NFSIOS_READPAGES when read succeeds
There is a small inconsistency with nfs_readpage() vs nfs_readpages() with regards to NFSIOS_READPAGES. In readpage we unconditionally increment NFSIOS_READPAGES at the top, which means even if the read fails. In readpages, we increment NFSIOS_READPAGES at the bottom based on how many pages were successfully read. Change readpage to be consistent with readpages and so NFSIOS_READPAGES only reflects successful, non-fscache reads.
--- fs/nfs/read.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/read.c +1 -1
@@ -319,7 +319,6 @@ int nfs_readpage(struct file *file, struct page *page)dprintk ("NFS: nfs_readpage (%p %ld@%lu)\n" , page,PAGE_SIZE ,page_index (page));nfs_inc_stats (inode,NFSIOS_VFSREADPAGE ); -nfs_add_stats (inode,NFSIOS_READPAGES ,1 );/* * Try to flush any pending writes to the file..
@@ -359,6 +358,7 @@ int nfs_readpage(struct file *file, struct page *page)if (!PageUptodate (page) && !ret) ret =xchg (&ctx->error,0 ); } +nfs_add_stats (inode,NFSIOS_READPAGES ,1 ); out:put_nfs_open_context (ctx);return ret;
Signature · 1 line
1.8.3.1
PATCH 3/8 NFS: Refactor nfs_readpage() and nfs_readpage_async() to use nfs_readdesc
In reply to Dave WysochanskiBoth nfs_readpage() and nfs_readpages() use similar code. This patch should be no functional change, and refactors nfs_readpage_async() to use nfs_readdesc to enable future merging of nfs_readpage_async() and nfs_readpage_async_filler().
--- fs/nfs/read.c | 62 ++++++++++++++++++++++++-------------------------- include/linux/nfs_fs.h | 3 +-- 2 files changed, 31 insertions(+), 34 deletions(-)
fs/nfs/read.c +30 -32
@@ -114,18 +114,23 @@ static void nfs_readpage_release(struct nfs_page *req, int error)nfs_release_request (req); } -int nfs_readpage_async (struct nfs_open_context *ctx,struct inode *inode, +struct nfs_readdesc { +struct nfs_pageio_descriptor pgio; +struct nfs_open_context *ctx; +}; + +int nfs_readpage_async (void *data,struct inode *inode,struct page *page) { +struct nfs_readdesc *desc = data;struct nfs_page *new;unsigned int len; -struct nfs_pageio_descriptor pgio;struct nfs_pgio_mirror *pgm; len =nfs_page_length (page);if (len ==0 )return nfs_return_empty_page (page); - new =nfs_create_request (ctx, page,0 , len); + new =nfs_create_request (desc->ctx, page,0 , len);if (IS_ERR (new)) {unlock_page (page);return PTR_ERR (new);
@@ -133,21 +138,21 @@ int nfs_readpage_async(struct nfs_open_context *ctx, struct inode *inode,if (len <PAGE_SIZE )zero_user_segment (page, len,PAGE_SIZE ); -nfs_pageio_init_read (&pgio, inode, false, +nfs_pageio_init_read (&desc->pgio, inode, false, &nfs_async_read_completion_ops); -if (!nfs_pageio_add_request (&pgio, new)) { +if (!nfs_pageio_add_request (&desc->pgio, new)) {nfs_list_remove_request (new); -nfs_readpage_release (new, pgio.pg_error); +nfs_readpage_release (new, desc->pgio.pg_error); } -nfs_pageio_complete (&pgio); +nfs_pageio_complete (&desc->pgio);/* It doesn't make sense to do mirrored reads! */ -WARN_ON_ONCE (pgio.pg_mirror_count !=1 ); +WARN_ON_ONCE (desc->pgio.pg_mirror_count !=1 ); - pgm = &pgio.pg_mirrors[0 ]; + pgm = &desc->pgio.pg_mirrors[0 ];NFS_I (inode)->read_io += pgm->pg_bytes_written; -return pgio.pg_error <0 ? pgio.pg_error :0 ; +return desc->pgio.pg_error <0 ? desc->pgio.pg_error :0 ; }static void nfs_page_group_set_uptodate (struct nfs_page *req)
@@ -312,7 +317,7 @@ static void nfs_readpage_result(struct rpc_task *task,*/ int nfs_readpage (struct file *file,struct page *page) { -struct nfs_open_context *ctx; +struct nfs_readdesc desc;struct inode *inode =page_file_mapping (page)->host;int ret;
@@ -339,39 +344,34 @@ int nfs_readpage(struct file *file, struct page *page)if (file ==NULL ) { ret = -EBADF ; - ctx =nfs_find_open_context (inode,NULL ,FMODE_READ ); -if (ctx ==NULL ) + desc.ctx =nfs_find_open_context (inode,NULL ,FMODE_READ ); +if (desc.ctx ==NULL ) goto out_unlock; }else - ctx =get_nfs_open_context (nfs_file_open_context (file)); + desc.ctx =get_nfs_open_context (nfs_file_open_context (file));if (!IS_SYNC (inode)) { - ret =nfs_readpage_from_fscache (ctx, inode, page); + ret =nfs_readpage_from_fscache (desc.ctx, inode, page);if (ret ==0 ) goto out; } -xchg (&ctx->error,0 ); - ret =nfs_readpage_async (ctx, inode, page); +xchg (&desc.ctx->error,0 ); + ret =nfs_readpage_async (&desc, inode, page);if (!ret) { ret =wait_on_page_locked_killable (page);if (!PageUptodate (page) && !ret) - ret =xchg (&ctx->error,0 ); + ret =xchg (&desc.ctx->error,0 ); }nfs_add_stats (inode,NFSIOS_READPAGES ,1 ); out: -put_nfs_open_context (ctx); +put_nfs_open_context (desc.ctx);return ret; out_unlock:unlock_page (page);return ret; } -struct nfs_readdesc { -struct nfs_pageio_descriptor *pgio; -struct nfs_open_context *ctx; -}; -static int readpage_async_filler (void *data,struct page *page) {
@@ -390,9 +390,9 @@ struct nfs_readdesc {if (len <PAGE_SIZE )zero_user_segment (page, len,PAGE_SIZE ); -if (!nfs_pageio_add_request (desc->pgio, new)) { +if (!nfs_pageio_add_request (&desc->pgio, new)) {nfs_list_remove_request (new); - error = desc->pgio->pg_error; + error = desc->pgio.pg_error;nfs_readpage_release (new, error); goto out; }
@@ -407,7 +407,6 @@ struct nfs_readdesc {int nfs_readpages (struct file *file,struct address_space *mapping,struct list_head *pages,unsigned nr_pages) { -struct nfs_pageio_descriptor pgio;struct nfs_pgio_mirror *pgm;struct nfs_readdesc desc;struct inode *inode = mapping->host;
@@ -440,17 +439,16 @@ int nfs_readpages(struct file *file, struct address_space *mapping,if (ret ==0 ) goto read_complete;/* all pages were read */ - desc.pgio = &pgio; -nfs_pageio_init_read (&pgio, inode, false, +nfs_pageio_init_read (&desc.pgio, inode, false, &nfs_async_read_completion_ops); ret =read_cache_pages (mapping, pages, readpage_async_filler, &desc); -nfs_pageio_complete (&pgio); +nfs_pageio_complete (&desc.pgio);/* It doesn't make sense to do mirrored reads! */ -WARN_ON_ONCE (pgio.pg_mirror_count !=1 ); +WARN_ON_ONCE (desc.pgio.pg_mirror_count !=1 ); - pgm = &pgio.pg_mirrors[0 ]; + pgm = &desc.pgio.pg_mirrors[0 ];NFS_I (inode)->read_io += pgm->pg_bytes_written; npages = (pgm->pg_bytes_written +PAGE_SIZE -1 ) >>PAGE_SHIFT ;
include/linux/nfs_fs.h +1 -2
@@ -570,8 +570,7 @@ extern int nfs_access_get_cached(struct inode *inode, const struct cred *cred, sextern int nfs_readpage (struct file *,struct page *);extern int nfs_readpages (struct file *,struct address_space *,struct list_head *,unsigned ); -extern int nfs_readpage_async (struct nfs_open_context *,struct inode *, -struct page *); +extern int nfs_readpage_async (void *,struct inode *,struct page *);/* * inline functions
Signature · 1 line
1.8.3.1
PATCH 4/8 NFS: Call readpage_async_filler() from nfs_readpage_async()
In reply to Dave WysochanskiRefactor slightly so nfs_readpage_async() calls into readpage_async_filler().
--- fs/nfs/read.c | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-)
fs/nfs/read.c +11 -17
@@ -119,31 +119,22 @@ struct nfs_readdesc {struct nfs_open_context *ctx; }; +static int readpage_async_filler (void *data,struct page *page); +int nfs_readpage_async (void *data,struct inode *inode,struct page *page) {struct nfs_readdesc *desc = data; -struct nfs_page *new; -unsigned int len;struct nfs_pgio_mirror *pgm; - - len =nfs_page_length (page); -if (len ==0 ) -return nfs_return_empty_page (page); - new =nfs_create_request (desc->ctx, page,0 , len); -if (IS_ERR (new)) { -unlock_page (page); -return PTR_ERR (new); - } -if (len <PAGE_SIZE ) -zero_user_segment (page, len,PAGE_SIZE ); +int error;nfs_pageio_init_read (&desc->pgio, inode, false, &nfs_async_read_completion_ops); -if (!nfs_pageio_add_request (&desc->pgio, new)) { -nfs_list_remove_request (new); -nfs_readpage_release (new, desc->pgio.pg_error); - } + + error =readpage_async_filler (desc, page); +if (error) + goto out; +nfs_pageio_complete (&desc->pgio);/* It doesn't make sense to do mirrored reads! */
@@ -153,6 +144,9 @@ int nfs_readpage_async(void *data, struct inode *inode,NFS_I (inode)->read_io += pgm->pg_bytes_written;return desc->pgio.pg_error <0 ? desc->pgio.pg_error :0 ; + +out: +return error; }static void nfs_page_group_set_uptodate (struct nfs_page *req)
Signature · 1 line
1.8.3.1
PATCH 5/8 NFS: Add nfs_pageio_complete_read() and remove nfs_readpage_async()
In reply to Dave WysochanskiAdd nfs_pageio_complete_read() and call this from both nfs_readpage() and nfs_readpages(), since the submission and accounting is the same for both functions.
--- fs/nfs/fscache.c | 4 -- fs/nfs/read.c | 137 ++++++++++++++++++++++--------------------------- include/linux/nfs_fs.h | 1 - 3 files changed, 61 insertions(+), 81 deletions(-)
fs/nfs/fscache.c +0 -4
@@ -390,10 +390,6 @@ static void nfs_readpage_from_fscache_complete(struct page *page,if (!error) {SetPageUptodate (page);unlock_page (page); - }else { - error =nfs_readpage_async (context, page->mapping->host, page); -if (error) -unlock_page (page); } }
fs/nfs/read.c +61 -76
191 lines not on this page · raw message
include/linux/nfs_fs.h +0 -1
@@ -570,7 +570,6 @@ extern int nfs_access_get_cached(struct inode *inode, const struct cred *cred, sextern int nfs_readpage (struct file *,struct page *);extern int nfs_readpages (struct file *,struct address_space *,struct list_head *,unsigned ); -extern int nfs_readpage_async (void *,struct inode *,struct page *);/* * inline functions
Signature · 1 line
1.8.3.1
PATCH 6/8 NFS: Allow internal use of read structs and functions
In reply to Dave WysochanskiThe conversion of the NFS read paths to the new fscache API will require use of a few read structs and functions, so move these declarations as required.
--- fs/nfs/internal.h | 8 ++++++++ fs/nfs/read.c | 13 ++++--------- 2 files changed, 12 insertions(+), 9 deletions(-)
fs/nfs/internal.h +8 -0
@@ -457,9 +457,17 @@ extern char *nfs_path(char **p, struct dentry *dentry,struct nfs_pgio_completion_ops ;/* read.c */ +extern const struct nfs_pgio_completion_ops nfs_async_read_completion_ops;extern void nfs_pageio_init_read (struct nfs_pageio_descriptor *pgio,struct inode *inode,bool force_mds,const struct nfs_pgio_completion_ops *compl_ops); +struct nfs_readdesc { +struct nfs_pageio_descriptor pgio; +struct nfs_open_context *ctx; +}; +extern int readpage_async_filler (void *data,struct page *page); +extern void nfs_pageio_complete_read (struct nfs_pageio_descriptor *pgio, +struct inode *inode);extern void nfs_read_prepare (struct rpc_task *task,void *calldata);extern void nfs_pageio_reset_read_mds (struct nfs_pageio_descriptor *pgio);
fs/nfs/read.c +4 -9
@@ -30,7 +30,7 @@#define NFSDBG_FACILITY NFSDBG_PAGECACHE -static const struct nfs_pgio_completion_ops nfs_async_read_completion_ops; +const struct nfs_pgio_completion_ops nfs_async_read_completion_ops;static const struct nfs_rw_ops nfs_rw_read_ops;static struct kmem_cache *nfs_rdata_cachep;
@@ -74,7 +74,7 @@ void nfs_pageio_init_read(struct nfs_pageio_descriptor *pgio, }EXPORT_SYMBOL_GPL (nfs_pageio_init_read); -static void nfs_pageio_complete_read (struct nfs_pageio_descriptor *pgio, +void nfs_pageio_complete_read (struct nfs_pageio_descriptor *pgio,struct inode *inode) {struct nfs_pgio_mirror *pgm;
@@ -132,11 +132,6 @@ static void nfs_readpage_release(struct nfs_page *req, int error)nfs_release_request (req); } -struct nfs_readdesc { -struct nfs_pageio_descriptor pgio; -struct nfs_open_context *ctx; -}; -static void nfs_page_group_set_uptodate (struct nfs_page *req) {if (nfs_page_group_sync_on_bit (req,PG_UPTODATE ))
@@ -215,7 +210,7 @@ static void nfs_initiate_read(struct nfs_pgio_header *hdr, } } -static const struct nfs_pgio_completion_ops nfs_async_read_completion_ops = { +const struct nfs_pgio_completion_ops nfs_async_read_completion_ops = { .error_cleanup = nfs_async_read_error, .completion = nfs_read_completion, };
@@ -290,7 +285,7 @@ static void nfs_readpage_result(struct rpc_task *task,nfs_readpage_retry (task, hdr); } -static int +int readpage_async_filler (void *data,struct page *page) {struct nfs_readdesc *desc = data;
Signature · 1 line
1.8.3.1
PATCH 7/8 NFS: Convert to the netfs API and nfs_readpage to use netfs_readpage
In reply to Dave WysochanskiThis patch converts the main NFS read paths to the new netfs API, when fscache is enabled, and converts readpage while minimizing changes to the existing NFS read code paths.
The netfs API requires a few functions to be provided by the netfs:
- init_rreq: allows netfs to allocate resources prior to IO
- is_cache_enabled: allows netfs to disable fscache
- begin_cache_operation: signals the start of an fscache IO
- issue_op: called when netfs should issue read to server
- clamp_length: allows netfs to limit size of IO
- cleanup: allows netfs to cleanup after an IO is complete
The new netfs_readpage() API is called when fscache is enabled. If a read cannot be satisfied from fscache, the netfs is called back via issue_op() to obtain the data from the server. Once the read completes, the netfs must call netfs_subreq_terminated() which then may write the data to fscache. In order to call back into fscache via netfs_subreq_terminated(), we must save the netfs_read_subrequest* as a field in the nfs_pgio_header, similar to nfs_direct_req.
If the netfs has a read IO limit (for example, NFS 'rsize' mount options) the clamp_length() function is called.
--- fs/nfs/fscache.c | 158 ++++++++++++++++++++++++++++++++--------------- fs/nfs/fscache.h | 44 +++---------- fs/nfs/pagelist.c | 2 + fs/nfs/read.c | 9 ++- include/linux/nfs_page.h | 1 + include/linux/nfs_xdr.h | 1 + 6 files changed, 127 insertions(+), 88 deletions(-)
fs/nfs/fscache.c +107 -51
@@ -15,6 +15,9 @@#include <linux/seq_file.h> #include <linux/slab.h> #include <linux/iversion.h> +#include <linux/xarray.h> +#include <linux/fscache.h> +#include <linux/netfs.h> #include "internal.h" #include "iostat.h"
@@ -373,62 +376,126 @@ void __nfs_fscache_invalidate_page(struct page *page, struct inode *inode) NFSIOS_FSCACHE_PAGES_UNCACHED); } -/* -* 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) +static void nfs_issue_op (struct netfs_read_subrequest *subreq) { -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); +struct inode *inode = subreq->rreq->inode; +struct nfs_readdesc *desc = subreq->rreq->netfs_priv; +struct page *page; +pgoff_t start = (subreq->start + subreq->transferred) >>PAGE_SHIFT ; +pgoff_t last = ((subreq->start + subreq->len - + subreq->transferred -1 ) >>PAGE_SHIFT ); +XA_STATE (xas, &subreq->rreq->mapping->i_pages, start); + +dfprintk (FSCACHE ,"NFS: %s(fsc:%p s:%lu l:%lu) subreq->start: %lld " +"subreq->len: %ld subreq->transferred: %ld\n" , + __func__,nfs_i_fscache (inode), start, last, subreq->start, + subreq->len, subreq->transferred); + +nfs_add_fscache_stats (inode,NFSIOS_FSCACHE_PAGES_READ_FAIL , + last - start +1 ); +nfs_pageio_init_read (&desc->pgio, inode, false, + &nfs_async_read_completion_ops); + + desc->pgio.pg_fsc = subreq;/* used in completion */ + +rcu_read_lock (); +xas_for_each (&xas, page, last) { + subreq->error =readpage_async_filler (desc, page); +if (subreq->error <0 ) +break ; + } +rcu_read_unlock (); +nfs_pageio_complete_read (&desc->pgio, inode); +} + +static bool nfs_clamp_length (struct netfs_read_subrequest *subreq) +{ +struct inode *inode = subreq->rreq->mapping->host; +unsigned int rsize =NFS_SB (inode->i_sb)->rsize; + +if (subreq->len > rsize) { +dfprintk (FSCACHE , +"NFS: %s(fsc:%p slen:%lu rsize: %u)\n" , + __func__,nfs_i_fscache (inode), subreq->len, rsize); + subreq->len = rsize; } + +return true; +} + +static void nfs_cleanup (struct address_space *mapping,void *netfs_priv) +{ + ;/* fscache assumes if netfs_priv is given we have cleanup */ +} + +atomic_t nfs_fscache_debug_id; +static void nfs_init_rreq (struct netfs_read_request *rreq,struct file *file) +{ +struct nfs_inode *nfsi =NFS_I (rreq->inode); + +if (nfsi->fscache &&test_bit (NFS_INO_FSCACHE , &nfsi->flags)) + rreq->cookie_debug_id =atomic_inc_return (&nfs_fscache_debug_id); +} + +static bool nfs_is_cache_enabled (struct inode *inode) +{ +struct nfs_inode *nfsi =NFS_I (inode); + +return nfsi->fscache &&test_bit (NFS_INO_FSCACHE , &nfsi->flags); +} + +static int nfs_begin_cache_operation (struct netfs_read_request *rreq) +{ +struct fscache_cookie *cookie =NFS_I (rreq->inode)->fscache; + +return fscache_begin_read_operation (rreq, cookie); } +static struct netfs_read_request_ops nfs_fscache_req_ops = { + .init_rreq = nfs_init_rreq, + .is_cache_enabled = nfs_is_cache_enabled, + .begin_cache_operation = nfs_begin_cache_operation, + .issue_op = nfs_issue_op, + .clamp_length = nfs_clamp_length, + .cleanup = nfs_cleanup +}; +/* * Retrieve a page from fscache */ -int __nfs_readpage_from_fscache (struct nfs_open_context *ctx, -struct inode *inode,struct page *page) +int nfs_readpage_from_fscache (struct file *file, +struct page *page, +struct nfs_readdesc *desc) {int ret; +struct inode *inode =file_inode (file); + +if (!NFS_I (file_inode (file))->fscache) +return -ENOBUFS ;dfprintk (FSCACHE ,"NFS: readpage_from_fscache(fsc:%p/p:%p(i:%lx f:%lx)/0x%p)\n" ,nfs_i_fscache (inode), page, page->index, page->flags, inode); - ret =fscache_read_or_alloc_page (nfs_i_fscache (inode), - page, - nfs_readpage_from_fscache_complete, - ctx, -GFP_KERNEL ); + ret =netfs_readpage (file, page, &nfs_fscache_req_ops, desc);switch (ret) { -case 0 :/* read BIO submitted (page in fscache) */ -dfprintk (FSCACHE , -"NFS: readpage_from_fscache: BIO submitted\n" ); +case 0 :/* read submitted */ +dfprintk (FSCACHE ,"NFS: readpage_from_fscache: submitted\n" );nfs_inc_fscache_stats (inode,NFSIOS_FSCACHE_PAGES_READ_OK );return ret;case -ENOBUFS :/* inode not in cache */ case -ENODATA :/* page not in cache */ nfs_inc_fscache_stats (inode,NFSIOS_FSCACHE_PAGES_READ_FAIL ); -dfprintk (FSCACHE , -"NFS: readpage_from_fscache %d\n" , ret); +dfprintk (FSCACHE ,"NFS: readpage_from_fscache %d\n" , ret);return 1 ;default :dfprintk (FSCACHE ,"NFS: readpage_from_fscache %d\n" , ret);nfs_inc_fscache_stats (inode,NFSIOS_FSCACHE_PAGES_READ_FAIL ); } +return ret; }
@@ -449,7 +516,7 @@ int __nfs_readpages_from_fscache(struct nfs_open_context *ctx, ret =fscache_read_or_alloc_pages (nfs_i_fscache (inode), mapping, pages, nr_pages, - nfs_readpage_from_fscache_complete, +NULL , ctx,mapping_gfp_mask (mapping));if (*nr_pages < npages)
@@ -483,30 +550,19 @@ int __nfs_readpages_from_fscache(struct nfs_open_context *ctx, }/* -* Store a newly fetched page in fscache -* - PG_fscache must be set on the page +* Store a newly fetched data in fscache */ -void __nfs_readpage_to_fscache (struct inode *inode,struct page *page,int sync) +void nfs_read_completion_to_fscache (struct nfs_pgio_header *hdr, +unsigned long bytes) { -int ret; +struct netfs_read_subrequest *subreq = hdr->fsc; -dfprintk (FSCACHE , -"NFS: readpage_to_fscache(fsc:%p/p:%p(i:%lx f:%lx)/%d)\n" , -nfs_i_fscache (inode), page, page->index, page->flags, sync); - - ret =fscache_write_page (nfs_i_fscache (inode), page, - inode->i_size,GFP_KERNEL ); -dfprintk (FSCACHE , -"NFS: readpage_to_fscache: p:%p(i:%lu f:%lx) ret %d\n" , - page, page->index, page->flags, ret); - -if (ret !=0 ) { -fscache_uncache_page (nfs_i_fscache (inode), page); -nfs_inc_fscache_stats (inode, -NFSIOS_FSCACHE_PAGES_WRITTEN_FAIL ); -nfs_inc_fscache_stats (inode,NFSIOS_FSCACHE_PAGES_UNCACHED ); - }else { -nfs_inc_fscache_stats (inode, -NFSIOS_FSCACHE_PAGES_WRITTEN_OK ); +if (NFS_I (hdr->inode)->fscache && subreq) { +dfprintk (FSCACHE , +"NFS: read_completion_to_fscache(fsc:%p err:%d bytes:%lu subreq->len:%lu\n" , +NFS_I (hdr->inode)->fscache, hdr->error, bytes, subreq->len); +__set_bit (NETFS_SREQ_CLEAR_TAIL , &subreq->flags); +netfs_subreq_terminated (subreq, hdr->error ?: bytes); + hdr->fsc =NULL ; } }
fs/nfs/fscache.h +10 -34
77 lines not on this page · raw message
fs/nfs/pagelist.c +2 -0
@@ -68,6 +68,7 @@ void nfs_pgheader_init(struct nfs_pageio_descriptor *desc, hdr->good_bytes = mirror->pg_count; hdr->io_completion = desc->pg_io_completion; hdr->dreq = desc->pg_dreq; + hdr->fsc = desc->pg_fsc; hdr->release = release; hdr->completion_ops = desc->pg_completion_ops;if (hdr->completion_ops->init_hdr)
@@ -849,6 +850,7 @@ void nfs_pageio_init(struct nfs_pageio_descriptor *desc, desc->pg_lseg =NULL ; desc->pg_io_completion =NULL ; desc->pg_dreq =NULL ; + desc->pg_fsc =NULL ; desc->pg_bsize = bsize; desc->pg_mirror_count =1 ;
fs/nfs/read.c +6 -3
@@ -124,10 +124,11 @@ static void nfs_readpage_release(struct nfs_page *req, int error)struct address_space *mapping =page_file_mapping (page);if (PageUptodate (page)) -nfs_readpage_to_fscache (inode, page,0 ); + ;/* FIXME: review fscache page error handling */ else if (!PageError (page) && !PagePrivate (page))generic_error_remove_page (mapping, page); -unlock_page (page); +if (!nfs_i_fscache (inode)) +unlock_page (page); }nfs_release_request (req); }
@@ -181,6 +182,8 @@ static void nfs_read_completion(struct nfs_pgio_header *hdr)nfs_list_remove_request (req);nfs_readpage_release (req, error); } +/* FIXME: NFS_IOHDR_ERROR and NFS_IOHDR_EOF handled per-page */ +nfs_read_completion_to_fscache (hdr, bytes); out: hdr->release (hdr); }
@@ -359,7 +362,7 @@ int nfs_readpage(struct file *file, struct page *page) desc.ctx =get_nfs_open_context (nfs_file_open_context (file));if (!IS_SYNC (inode)) { - ret =nfs_readpage_from_fscache (desc.ctx, inode, page); + ret =nfs_readpage_from_fscache (file, page, &desc);if (ret ==0 ) goto out; }
include/linux/nfs_page.h +1 -0
@@ -101,6 +101,7 @@ struct nfs_pageio_descriptor {struct pnfs_layout_segment *pg_lseg;struct nfs_io_completion *pg_io_completion;struct nfs_direct_req *pg_dreq; +void *pg_fsc;unsigned int pg_bsize;/* default bsize for mirrors */ u32 pg_mirror_count;
include/linux/nfs_xdr.h +1 -0
@@ -1607,6 +1607,7 @@ struct nfs_pgio_header {const struct nfs_rw_ops *rw_ops;struct nfs_io_completion *io_completion;struct nfs_direct_req *dreq; +void *fsc;int pnfs_error;int error;/* merge with pnfs_error */
Signature · 1 line
1.8.3.1
PATCH 8/8 NFS: Convert readpages to readahead and use netfs_readahead for fscache
In reply to Dave WysochanskiThe new FS-Cache API does not have a readpages equivalent function, and instead of fscache_read_or_alloc_pages() it implements a readahead function, netfs_readahead(). Call netfs_readahead() if fscache is enabled, and if not, utilize readahead_page() to run through the pages needed calling readpage_async_filler(). If we get an error on any page, then exit the loop, which matches the behavior of previously called read_cache_pages() when 'filler' returns an error.
--- fs/nfs/file.c | 2 +- fs/nfs/fscache.c | 50 ++++++++++------------------------------------ fs/nfs/fscache.h | 28 ++++---------------------- fs/nfs/read.c | 36 ++++++++++++++++----------------- include/linux/nfs_fs.h | 3 +-- include/linux/nfs_iostat.h | 2 +- 6 files changed, 35 insertions(+), 86 deletions(-)
fs/nfs/file.c +1 -1
@@ -515,7 +515,7 @@ static void nfs_swap_deactivate(struct file *file)const struct address_space_operations nfs_file_aops = { .readpage = nfs_readpage, - .readpages = nfs_readpages, + .readahead = nfs_readahead, .set_page_dirty = __set_page_dirty_nobuffers, .writepage = nfs_writepage, .writepages = nfs_writepages,
fs/nfs/fscache.c +10 -40
61 lines not on this page · raw message
fs/nfs/fscache.h +4 -24
@@ -98,12 +98,10 @@ struct nfs_fscache_inode_auxdata {extern int nfs_readpage_from_fscache (struct file *file,struct page *page,struct nfs_readdesc *desc); -extern int __nfs_readpages_from_fscache (struct nfs_open_context *, -struct inode *,struct address_space *, -struct list_head *,unsigned *); +extern int nfs_readahead_from_fscache (struct nfs_readdesc *desc, +struct readahead_control *ractl);extern void nfs_read_completion_to_fscache (struct nfs_pgio_header *hdr,unsigned long bytes); -/* * wait for a page to complete writing to the cache */
@@ -126,21 +124,6 @@ static inline void nfs_fscache_invalidate_page(struct page *page, }/* -* 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 ; -} - -/* * Invalidate the contents of fscache for this inode. This will not sleep. */ static inline void nfs_fscache_invalidate (struct inode *inode)
@@ -195,11 +178,8 @@ static inline int nfs_readpage_from_fscache(struct file *file, {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) +static inline int nfs_readahead_from_fscache (struct nfs_readdesc *desc, +struct readahead_control *ractl) {return -ENOBUFS ; }
fs/nfs/read.c +18 -18
@@ -390,50 +390,50 @@ int nfs_readpage(struct file *file, struct page *page)return ret; } -int nfs_readpages (struct file *file,struct address_space *mapping, -struct list_head *pages,unsigned nr_pages) +void nfs_readahead (struct readahead_control *ractl) {struct nfs_readdesc desc; -struct inode *inode = mapping->host; +struct inode *inode = ractl->mapping->host; +struct page *page;int ret; -dprintk ("NFS: nfs_readpages (%s/%Lu %d)\n" , - inode->i_sb->s_id, - (unsigned long long )NFS_FILEID (inode), - nr_pages); +dprintk ("NFS: %s (%s/%llu %lld)\n" , __func__, + inode->i_sb->s_id, + (unsigned long long )NFS_FILEID (inode), +readahead_length (ractl));nfs_inc_stats (inode,NFSIOS_VFSREADPAGES ); - ret = -ESTALE ;if (NFS_STALE (inode)) - goto out; +return ; -if (file ==NULL ) { - ret = -EBADF ; +if (ractl->file ==NULL ) { desc.ctx =nfs_find_open_context (inode,NULL ,FMODE_READ );if (desc.ctx ==NULL ) - goto out; +return ; }else - desc.ctx =get_nfs_open_context (nfs_file_open_context (file)); + desc.ctx =get_nfs_open_context (nfs_file_open_context (ractl->file));/* 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); + ret =nfs_readahead_from_fscache (&desc, ractl);if (ret ==0 ) goto read_complete;/* all pages were read */ nfs_pageio_init_read (&desc.pgio, inode, false, &nfs_async_read_completion_ops); - ret =read_cache_pages (mapping, pages, readpage_async_filler, &desc); +while ((page =readahead_page (ractl))) { + ret =readpage_async_filler (&desc, page); +put_page (page); +if (unlikely (ret)) +break ; + }nfs_pageio_complete_read (&desc.pgio, inode); read_complete:put_nfs_open_context (desc.ctx); -out: -return ret; }int __init nfs_init_readpagecache (void )
include/linux/nfs_fs.h +1 -2
@@ -568,8 +568,7 @@ extern int nfs_access_get_cached(struct inode *inode, const struct cred *cred, s* linux/fs/nfs/read.c */ extern int nfs_readpage (struct file *,struct page *); -extern int nfs_readpages (struct file *,struct address_space *, -struct list_head *,unsigned ); +extern void nfs_readahead (struct readahead_control *rac);/* * inline functions
include/linux/nfs_iostat.h +1 -1
@@ -53,7 +53,7 @@* NFS page counters * * These count the number of pages read or written via nfs_readpage(), -* nfs_readpages(), or their write equivalents. +* nfs_readahead(), or their write equivalents. * * NB: When adding new byte counters, please include the measured * units in the name of each byte counter to help users of this
Signature · 1 line
1.8.3.1