Convert NFS client to new fscache-iter API
Subsystems (2)
cover Convert NFS client to new fscache-iter API
These patches update the nfs client to use the new FS-Cache API and are at:
https://github.com/DaveWysochanskiRH/kernel/commit/a426b431873ea755c94ccd403aeaba0c4e635016
They are based on David Howells fscache-iter tree at ff12b5a05bd6984ad83e762f702cb655222bad74
https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/commit/?h=fscache-iter&id=ff12b5a05bd6984ad83e762f702cb655222bad74
The following patches may be of specific interest to review
as they are related to the conversion:
NFS: Convert fscache_acquire_cookie and fscache_relinquish_cookie
NFS: Convert nfs_readpage() and readpages() to new fscache API
NFS: Only use and unuse an fscache cookie a single time based on NFS_INO_FSCACHE
NFS: Convert fscache invalidation and update aux_data and i_size
Note that this is only a "first pass" v1 / RFC set I wanted to get out there for the maintainers to see and know this is being worked on. It is far from perfect and has some problems still need worked out. A short summary of this set:
1. Takes a "least invasive to existing code" approach
* most fscache bits stay fs/nfs/fscache.[ch]
* fscache enable/disable switched inside NFS code on nfs_inode.fscache
* only enable fscache for reads
* may not be the best approach (see future patcheset items below)
2. Basically works and passes a series of tests
* should not affect NFS when fscache is disabled (no "fsc" option)
* a couple small NFS + fscache basic verification tests
* connectathon (all NFS versions, with/without 'fsc' option)
* various iozone tests (all NFS versions, with/without 'fsc' option)
3. Still has a few known problems that are being tracked down
* Data integrity issue when write with O_DIRECT and read
back without O_DIRECT (we get 0's back from the cache)
* iozone tests run through ok but at the end superblock
cookies are left (each NFS version has a different superblock
cookie); this leads to "duplicate cookie" messages
upon subsequent mounts / runs
* A couple oopses in fscache reported to dhowells, may
be related to NFS's enable/disable of fscache on read/write
* Kernel build fails about halfway through with a strange
dubious error at the same place, linking this file:
ld: net/sunrpc/auth_gss/trace.o: attempt to load strings from a non-string section (number 41)
In addition to fixing various code issues and above issues, a future patchset may:
1. The readpage/readpages conversion patch call read_helpers directly rather than isolation into fs/nfs/fscache.c
* Similar to the AFS conversion, with calls directly to the read_helpers, but not sure about non-fsc code path
2. Add write-through support
* Would probably eliminate some problematic code paths where fscache is turned on / off depending on whether a file switches from read to write and vice-versa
* This would rework open as well
* Have to work out whether this is possible or not and with what caveats as far as NFS version support (is this an NFSv4.x only thing?)
3. Rework dfprintks and/or add ftrace points
* fscache/cachefiles has 'debug' logging similar to rpcdebug so not sure if we keep rpcdebug here or go full ftrace
Dave Wysochanski (13):
NFS: Clean up nfs_readpage() and nfs_readpages()
NFS: In nfs_readpage() only increment NFSIOS_READPAGES when read
succeeds
NFS: Refactor nfs_readpage() and nfs_readpage_async() to use
nfs_readdesc
NFS: Call readpage_async_filler() from nfs_readpage_async()
NFS: Add nfs_pageio_complete_read() and remove nfs_readpage_async()
NFS: Rename readpage_async_filler() to nfs_pageio_add_page_read()
NFS: Convert fscache_acquire_cookie and fscache_relinquish_cookie
NFS: Allow nfs_async_read_completion_ops to be used by other NFS code
NFS: Convert nfs_readpage() and readpages() to new fscache API
NFS: Allow NFS use of new fscache API in build
NFS: Only use and unuse an fscache cookie a single time based on
NFS_INO_FSCACHE
NFS: Convert fscache invalidation and update aux_data and i_size
NFS: Call nfs_fscache_invalidate() when write extends the size of the
file
fs/nfs/Kconfig | 2 +- fs/nfs/file.c | 20 +-- fs/nfs/fscache-index.c | 94 -------------- fs/nfs/fscache.c | 315 ++++++++++++++++++++++++----------------------- fs/nfs/fscache.h | 92 +++++--------- fs/nfs/inode.c | 1 - fs/nfs/internal.h | 4 + fs/nfs/pagelist.c | 1 + fs/nfs/read.c | 221 ++++++++++++++++----------------- fs/nfs/write.c | 9 +- include/linux/nfs_fs.h | 3 +- include/linux/nfs_page.h | 1 + include/linux/nfs_xdr.h | 1 + 13 files changed, 322 insertions(+), 442 deletions(-)
Signature · 1 line
1.8.3.1
RFC PATCH 1/13 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
@@ -310,11 +310,11 @@ static void nfs_readpage_result(struct rpc_task *task,* - The error flag is set for this page. This happens only when a * previous async read operation failed. */ -int nfs_readpage (struct file *file,struct page *page) +int nfs_readpage (struct file *filp,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,43 +328,43 @@ 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 ; +if (filp ==NULL ) { + ret = -EBADF ; ctx =nfs_find_open_context (inode,NULL ,FMODE_READ );if (ctx ==NULL ) goto out_unlock; }else - ctx =get_nfs_open_context (nfs_file_open_context (file)); + ctx =get_nfs_open_context (nfs_file_open_context (filp));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 {
@@ -409,12 +409,10 @@ int nfs_readpages(struct file *filp, struct address_space *mapping, {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,13 +420,15 @@ 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 ) { + 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));
@@ -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
RFC PATCH 2/13 NFS: In nfs_readpage() only increment NFSIOS_READPAGES when read succeeds
In reply to Dave WysochanskiThere 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 *filp, 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 *filp, 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
RFC PATCH 3/13 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 | 50 ++++++++++++++++++++++++++------------------------ include/linux/nfs_fs.h | 3 +-- 2 files changed, 27 insertions(+), 26 deletions(-)
fs/nfs/read.c +26 -24
@@ -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 = (struct nfs_readdesc *)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,8 @@ static void nfs_readpage_result(struct rpc_task *task,*/ int nfs_readpage (struct file *filp,struct page *page) { -struct nfs_open_context *ctx; +struct nfs_pageio_descriptor pgio; +struct nfs_readdesc desc;struct inode *inode =page_file_mapping (page)->host;int ret;
@@ -339,39 +345,35 @@ int nfs_readpage(struct file *filp, struct page *page)if (filp ==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 (filp)); + desc.ctx =get_nfs_open_context (nfs_file_open_context (filp));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); + desc.pgio = &pgio; +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) {
include/linux/nfs_fs.h +1 -2
@@ -553,8 +553,7 @@ extern int nfs_instantiate(struct dentry *dentry, struct nfs_fh *fh,extern 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
RFC PATCH 4/13 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 = (struct nfs_readdesc *)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
RFC PATCH 5/13 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/read.c | 137 ++++++++++++++++++++++++++-------------------------------- 1 file changed, 61 insertions(+), 76 deletions(-)
fs/nfs/read.c +61 -76
@@ -74,6 +74,24 @@ 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, +struct inode *inode) +{ +struct nfs_pgio_mirror *pgm; +unsigned long npages; + +nfs_pageio_complete (pgio); + +/* It doesn't make sense to do mirrored reads! */ +WARN_ON_ONCE (pgio->pg_mirror_count !=1 ); + + pgm = &pgio->pg_mirrors[0 ]; +NFS_I (inode)->read_io += pgm->pg_bytes_written; + npages = (pgm->pg_bytes_written +PAGE_SIZE -1 ) >>PAGE_SHIFT ; +nfs_add_stats (inode,NFSIOS_READPAGES , npages); +} + +void nfs_pageio_reset_read_mds (struct nfs_pageio_descriptor *pgio) {struct nfs_pgio_mirror *mirror;
@@ -119,36 +137,6 @@ 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 = (struct nfs_readdesc *)data; -struct nfs_pgio_mirror *pgm; -int error; - -nfs_pageio_init_read (desc->pgio, inode, false, - &nfs_async_read_completion_ops); - - error =readpage_async_filler (desc, page); -if (error) - goto out; - -nfs_pageio_complete (desc->pgio); - -/* It doesn't make sense to do mirrored reads! */ -WARN_ON_ONCE (desc->pgio->pg_mirror_count !=1 ); - - pgm = &desc->pgio->pg_mirrors[0 ]; -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) {if (nfs_page_group_sync_on_bit (req,PG_UPTODATE ))
@@ -170,8 +158,7 @@ static void nfs_read_completion(struct nfs_pgio_header *hdr)if (test_bit (NFS_IOHDR_EOF , &hdr->flags)) {/* note: regions of the page not covered by a -* request are zeroed in nfs_readpage_async / -* readpage_async_filler */ +* request are zeroed in readpage_async_filler */ if (bytes > hdr->good_bytes) {/* nothing in this request was good, so zero * the full extent of the request */
@@ -303,6 +290,38 @@ static void nfs_readpage_result(struct rpc_task *task,nfs_readpage_retry (task, hdr); } +static int +readpage_async_filler (void *data,struct page *page) +{ +struct nfs_readdesc *desc = (struct nfs_readdesc *)data; +struct nfs_page *new; +unsigned int len; +int error; + + 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)) + goto out_error; + +if (len <PAGE_SIZE ) +zero_user_segment (page, len,PAGE_SIZE ); +if (!nfs_pageio_add_request (desc->pgio, new)) { +nfs_list_remove_request (new); + error = desc->pgio->pg_error; +nfs_readpage_release (new, error); + goto out; + } +return 0 ; +out_error: + error =PTR_ERR (new); +unlock_page (page); +out: +return error; +} +/* * Read a page over NFS. * We read the page synchronously in the following case:
@@ -353,13 +372,20 @@ int nfs_readpage(struct file *filp, struct page *page) desc.pgio = &pgio;xchg (&desc.ctx->error,0 ); - ret =nfs_readpage_async (&desc, inode, page); +nfs_pageio_init_read (desc.pgio, inode, false, + &nfs_async_read_completion_ops); + + ret =readpage_async_filler (desc.pgio, page); + +if (!ret) +nfs_pageio_complete_read (desc.pgio, inode); + + ret = desc.pgio->pg_error <0 ? desc.pgio->pg_error :0 ;if (!ret) { ret =wait_on_page_locked_killable (page);if (!PageUptodate (page) && !ret) ret =xchg (&desc.ctx->error,0 ); } -nfs_add_stats (inode,NFSIOS_READPAGES ,1 ); out:put_nfs_open_context (desc.ctx);return ret;
@@ -368,46 +394,12 @@ int nfs_readpage(struct file *filp, struct page *page)return ret; } -static int -readpage_async_filler (void *data,struct page *page) -{ -struct nfs_readdesc *desc = (struct nfs_readdesc *)data; -struct nfs_page *new; -unsigned int len; -int error; - - 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)) - goto out_error; - -if (len <PAGE_SIZE ) -zero_user_segment (page, len,PAGE_SIZE ); -if (!nfs_pageio_add_request (desc->pgio, new)) { -nfs_list_remove_request (new); - error = desc->pgio->pg_error; -nfs_readpage_release (new, error); - goto out; - } -return 0 ; -out_error: - error =PTR_ERR (new); -unlock_page (page); -out: -return error; -} -int nfs_readpages (struct file *filp,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; -unsigned long npages;int ret; dprintk("NFS: nfs_readpages (%s/%Lu %d)\n",
@@ -441,16 +433,9 @@ int nfs_readpages(struct file *filp, struct address_space *mapping, &nfs_async_read_completion_ops); ret =read_cache_pages (mapping, pages, readpage_async_filler, &desc); -nfs_pageio_complete (&pgio); -/* It doesn't make sense to do mirrored reads! */ -WARN_ON_ONCE (pgio.pg_mirror_count !=1 ); +nfs_pageio_complete_read (desc.pgio, inode); - pgm = &pgio.pg_mirrors[0 ]; -NFS_I (inode)->read_io += pgm->pg_bytes_written; - npages = (pgm->pg_bytes_written +PAGE_SIZE -1 ) >> -PAGE_SHIFT ; -nfs_add_stats (inode,NFSIOS_READPAGES , npages); read_complete:put_nfs_open_context (desc.ctx); out:
Signature · 1 line
1.8.3.1
RFC PATCH 6/13 NFS: Rename readpage_async_filler() to nfs_pageio_add_page_read()
In reply to Dave WysochanskiRename the function that handles adding a page to an existing nfs_pageio_descriptor and export for future use.
--- fs/nfs/internal.h | 3 +++ fs/nfs/read.c | 13 ++++++------- 2 files changed, 9 insertions(+), 7 deletions(-)
fs/nfs/internal.h +3 -0
@@ -446,6 +446,9 @@ extern char *nfs_path(char **p, struct dentry *dentry,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); +extern int nfs_pageio_add_page_read (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 +6 -7
@@ -74,8 +74,8 @@ 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, -struct inode *inode) +void nfs_pageio_complete_read (struct nfs_pageio_descriptor *pgio, +struct inode *inode) {struct nfs_pgio_mirror *pgm;unsigned long npages;
@@ -158,7 +158,7 @@ static void nfs_read_completion(struct nfs_pgio_header *hdr)if (test_bit (NFS_IOHDR_EOF , &hdr->flags)) {/* note: regions of the page not covered by a -* request are zeroed in readpage_async_filler */ +* request are zeroed in nfs_pageio_add_page_read */ if (bytes > hdr->good_bytes) {/* nothing in this request was good, so zero * the full extent of the request */
@@ -290,8 +290,7 @@ static void nfs_readpage_result(struct rpc_task *task,nfs_readpage_retry (task, hdr); } -static int -readpage_async_filler (void *data,struct page *page) +int nfs_pageio_add_page_read (void *data,struct page *page) {struct nfs_readdesc *desc = (struct nfs_readdesc *)data;struct nfs_page *new;
@@ -375,7 +374,7 @@ int nfs_readpage(struct file *filp, struct page *page)nfs_pageio_init_read (desc.pgio, inode, false, &nfs_async_read_completion_ops); - ret =readpage_async_filler (desc.pgio, page); + ret =nfs_pageio_add_page_read (desc.pgio, page);if (!ret)nfs_pageio_complete_read (desc.pgio, inode);
@@ -432,7 +431,7 @@ int nfs_readpages(struct file *filp, struct address_space *mapping,nfs_pageio_init_read (&pgio, inode, false, &nfs_async_read_completion_ops); - ret =read_cache_pages (mapping, pages, readpage_async_filler, &desc); + ret =read_cache_pages (mapping, pages, nfs_pageio_add_page_read, &desc);nfs_pageio_complete_read (desc.pgio, inode);
Signature · 1 line
1.8.3.1
RFC PATCH 7/13 NFS: Convert fscache_acquire_cookie and fscache_relinquish_cookie
In reply to Dave WysochanskiThe new FS-Cache netfs API changes the cookie API slightly.
The changes to fscache_acquire_cookie are:
* remove struct fscache_cookie_def
* add 'type' of cookie (was member of fscache_cookie_def)
* add 'name' of cookie (was member of fscache_cookie_def)
* add 'advice' flags (tells cache how to handle object); set to 0
* add 'preferred_cache' tag (if NULL, derive from parent)
* remove 'netfs_data'
* remove 'enable' (See fscache_use_cookie())
The changes to fscache_relinquish_cookie are:
* remove 'aux_data'
--- fs/nfs/fscache-index.c | 94 -------------------------------------------------- fs/nfs/fscache.c | 56 +++++++++++++++++------------- fs/nfs/fscache.h | 3 -- 3 files changed, 32 insertions(+), 121 deletions(-)
fs/nfs/fscache-index.c +0 -94
@@ -44,97 +44,3 @@ void nfs_fscache_unregister(void) {fscache_unregister_netfs (&nfs_fscache_netfs); } - -/* -* Define the server object for FS-Cache. This is used to describe a server -* object to fscache_acquire_cookie(). It is keyed by the NFS protocol and -* server address parameters. -*/ -const struct fscache_cookie_def nfs_fscache_server_index_def = { - .name ="NFS.server" , - .type =FSCACHE_COOKIE_TYPE_INDEX , -}; - -/* -* Define the superblock object for FS-Cache. This is used to describe a -* superblock object to fscache_acquire_cookie(). It is keyed by all the NFS -* parameters that might cause a separate superblock. -*/ -const struct fscache_cookie_def nfs_fscache_super_index_def = { - .name ="NFS.super" , - .type =FSCACHE_COOKIE_TYPE_INDEX , -}; - -/* -* Consult the netfs about the state of an object -* - This function can be absent if the index carries no state data -* - The netfs data from the cookie being used as the target is -* presented, as is the auxiliary data -*/ -static -enum fscache_checkaux nfs_fscache_inode_check_aux (void *cookie_netfs_data, -const void *data, -uint16_t datalen, -loff_t object_size) -{ -struct nfs_fscache_inode_auxdata auxdata; -struct nfs_inode *nfsi = cookie_netfs_data; - -if (datalen !=sizeof (auxdata)) -return FSCACHE_CHECKAUX_OBSOLETE ; - -memset (&auxdata,0 ,sizeof (auxdata)); - auxdata.mtime_sec = nfsi->vfs_inode.i_mtime.tv_sec; - auxdata.mtime_nsec = nfsi->vfs_inode.i_mtime.tv_nsec; - auxdata.ctime_sec = nfsi->vfs_inode.i_ctime.tv_sec; - auxdata.ctime_nsec = nfsi->vfs_inode.i_ctime.tv_nsec; - -if (NFS_SERVER (&nfsi->vfs_inode)->nfs_client->rpc_ops->version ==4 ) - auxdata.change_attr =inode_peek_iversion_raw (&nfsi->vfs_inode); - -if (memcmp (data, &auxdata, datalen) !=0 ) -return FSCACHE_CHECKAUX_OBSOLETE ; - -return FSCACHE_CHECKAUX_OKAY ; -} - -/* -* Get an extra reference on a read context. -* - This function can be absent if the completion function doesn't require a -* context. -* - The read context is passed back to NFS in the event that a data read on the -* cache fails with EIO - in which case the server must be contacted to -* retrieve the data, which requires the read context for security. -*/ -static void nfs_fh_get_context (void *context) -{ -get_nfs_open_context (context); -} - -/* -* Release an extra reference on a read context. -* - This function can be absent if the completion function doesn't require a -* context. -*/ -static void nfs_fh_put_context (void *context) -{ -if (context) -put_nfs_open_context (context); -} - -/* -* Define the inode object for FS-Cache. This is used to describe an inode -* object to fscache_acquire_cookie(). It is keyed by the NFS file handle for -* an inode. -* -* Coherency is managed by comparing the copies of i_size, i_mtime and i_ctime -* held in the cache auxiliary data for the data storage object with those in -* the inode struct in memory. -*/ -const struct fscache_cookie_def nfs_fscache_inode_object_def = { - .name ="NFS.fh" , - .type =FSCACHE_COOKIE_TYPE_DATAFILE , - .check_aux = nfs_fscache_inode_check_aux, - .get_context = nfs_fh_get_context, - .put_context = nfs_fh_put_context, -};
fs/nfs/fscache.c +32 -24
111 lines not on this page · raw message
fs/nfs/fscache.h +0 -3
@@ -73,9 +73,6 @@ struct nfs_fscache_inode_auxdata {* fscache-index.c */ extern struct fscache_netfs nfs_fscache_netfs; -extern const struct fscache_cookie_def nfs_fscache_server_index_def; -extern const struct fscache_cookie_def nfs_fscache_super_index_def; -extern const struct fscache_cookie_def nfs_fscache_inode_object_def;extern int nfs_fscache_register (void );extern void nfs_fscache_unregister (void );
Signature · 1 line
1.8.3.1
RFC PATCH 8/13 NFS: Allow nfs_async_read_completion_ops to be used by other NFS code
In reply to Dave WysochanskiThe standard read nfs_pgio_completion_ops will be needed when fscache read path is converted to the new API, so export just to other NFS code.
--- fs/nfs/internal.h | 1 + fs/nfs/read.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-)
fs/nfs/internal.h +1 -0
@@ -443,6 +443,7 @@ 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);
fs/nfs/read.c +2 -2
@@ -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;
@@ -215,7 +215,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, };
Signature · 1 line
1.8.3.1
RFC PATCH 9/13 NFS: Convert nfs_readpage() and readpages() to new fscache API
In reply to Dave WysochanskiThis patch converts the NFS read paths to the new fscache API, minimizing changes to the existing code.
The new fscache IO path API uses a different mechanism to read through the cache. There are two main read_helper calls:
- readpage: fscache_read_helper_locked_page()
- replaces old API fscache_read_or_alloc_page()
- readpages: fscache_read_helper_page_list()
- replaces old API fscache_read_or_alloc_pages()
Once submitted to the read_helper, if pages are inside the cache fscache will call the done() function of fscache_io_request_ops(). If the pages are not inside the cache, fscache will call issue_op() so NFS can go through its normal read code paths, such as nfs_pageio_init_read(), nfs_pageio_add_page_read() and nfs_pageio_complete_read().
In the read completion code path, from nfs_read_completion() we must call into fscache via a cache.io_done() function. In order to call back into fscache via this function, we must save the nfs_fscache_req * as a field in the nfs_pgio_header, similar to nfs_direct_req. Note also that when fscache is enabled, the read_helper will lock and unlock the pages so in the completion path we skip the unlock_page() with fscache.
--- fs/nfs/fscache.c | 225 ++++++++++++++++++++++++----------------------- fs/nfs/fscache.h | 25 +++--- fs/nfs/pagelist.c | 1 + fs/nfs/read.c | 14 +-- include/linux/nfs_page.h | 1 + include/linux/nfs_xdr.h | 1 + 6 files changed, 139 insertions(+), 128 deletions(-)
fs/nfs/fscache.c +116 -109
@@ -336,73 +336,96 @@ void nfs_fscache_open_file(struct inode *inode, struct file *filp) }EXPORT_SYMBOL_GPL (nfs_fscache_open_file); -/* -* Release the caching state associated with a page, if the page isn't busy -* interacting with the cache. -* - Returns true (can release page) or false (page busy). -*/ -int nfs_fscache_release_page (struct page *page,gfp_t gfp) +/* HACK - remove / duplicate */ +struct nfs_readdesc { +struct nfs_pageio_descriptor *pgio; +struct nfs_open_context *ctx; +}; + +struct nfs_fscache_req { +struct fscache_io_request cache; +struct nfs_readdesc desc; +struct nfs_pageio_descriptor pgio;/* HACK remove */ +refcount_t usage; +}; + +static void nfs_done_io_request (struct fscache_io_request *fsreq) { -if (PageFsCache (page)) { -struct fscache_cookie *cookie =nfs_i_fscache (page->mapping->host); - -BUG_ON (!cookie); -dfprintk (FSCACHE ,"NFS: fscache releasepage (0x%p/0x%p/0x%p)\n" , - cookie, page,NFS_I (page->mapping->host)); + struct nfs_fscache_req *req = container_of(fsreq, struct nfs_fscache_req, cache); +struct inode *inode =d_inode (req->desc.ctx->dentry); -if (!fscache_maybe_release_page (cookie, page, gfp)) -return 0 ; - -nfs_inc_fscache_stats (page->mapping->host, -NFSIOS_FSCACHE_PAGES_UNCACHED ); - } - -return 1 ; +nfs_add_fscache_stats (inode,NFSIOS_FSCACHE_PAGES_READ_OK , + fsreq->transferred >>PAGE_SHIFT ); } -/* -* Release the caching state associated with a page if undergoing complete page -* invalidation. -*/ -void __nfs_fscache_invalidate_page (struct page *page,struct inode *inode) +static void nfs_get_io_request (struct fscache_io_request *fsreq) { -struct fscache_cookie *cookie =nfs_i_fscache (inode); + struct nfs_fscache_req *req = container_of(fsreq, struct nfs_fscache_req, cache); -BUG_ON (!cookie); +refcount_inc (&req->usage); +} -dfprintk (FSCACHE ,"NFS: fscache invalidatepage (0x%p/0x%p/0x%p)\n" , - cookie, page,NFS_I (inode)); +static void nfs_put_io_request (struct fscache_io_request *fsreq) +{ + struct nfs_fscache_req *req = container_of(fsreq, struct nfs_fscache_req, cache); -fscache_wait_on_page_write (cookie, page); +if (refcount_dec_and_test (&req->usage)) { +put_nfs_open_context (req->desc.ctx); +fscache_free_io_request (fsreq); +kfree (req); + } +} -BUG_ON (!PageLocked (page)); -fscache_uncache_page (cookie, page); -nfs_inc_fscache_stats (page->mapping->host, -NFSIOS_FSCACHE_PAGES_UNCACHED ); +static void nfs_issue_op (struct fscache_io_request *fsreq) +{ + struct nfs_fscache_req *req = container_of(fsreq, struct nfs_fscache_req, cache); +struct inode *inode = req->cache.mapping->host; +struct page *page; +pgoff_t index = req->cache.pos >>PAGE_SHIFT ; +pgoff_t last = index + req->cache.nr_pages -1 ; + +nfs_add_fscache_stats (inode,NFSIOS_FSCACHE_PAGES_READ_FAIL , + req->cache.nr_pages); +nfs_get_io_request (fsreq); +nfs_pageio_init_read (&req->pgio, inode, false, + &nfs_async_read_completion_ops); + +for (; index <= last; index++) { + page =find_get_page (req->cache.mapping, index); +BUG_ON (!page); + req->cache.error =nfs_pageio_add_page_read (&req->desc, page); +if (req->cache.error <0 ) +break ; + } +nfs_pageio_complete_read (&req->pgio, inode); } -/* -* 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 struct fscache_io_request_ops nfs_fscache_req_ops = { + .issue_op = nfs_issue_op, + .done = nfs_done_io_request, + .get = nfs_get_io_request, + .put = nfs_put_io_request, +}; + +struct nfs_fscache_req *nfs_alloc_io_request (struct nfs_open_context *ctx, +struct address_space *mapping) { -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); +struct nfs_fscache_req *req; +struct inode *inode = mapping->host; + + req =kzalloc (sizeof (*req),GFP_KERNEL ); +if (req) { +refcount_set (&req->usage,1 ); + req->cache.mapping = mapping; + req->desc.pgio = &req->pgio;/* HACK - remove */ + req->desc.ctx =get_nfs_open_context (ctx); + +fscache_init_io_request (&req->cache,nfs_i_fscache (inode), + &nfs_fscache_req_ops); + req->desc.pgio->pg_fsc_req = req; } + +return req; }/*
@@ -411,36 +434,38 @@ static void nfs_readpage_from_fscache_complete(struct page *page,int __nfs_readpage_from_fscache (struct nfs_open_context *ctx,struct inode *inode,struct page *page) { +struct nfs_fscache_req *req;int ret;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 ); + req =nfs_alloc_io_request (ctx,page_file_mapping (page)); +if (IS_ERR (req)) +return PTR_ERR (req); + + ret =fscache_read_helper_locked_page (&req->cache, page,ULONG_MAX ); + +nfs_put_io_request (&req->cache);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; }
@@ -450,75 +475,57 @@ int __nfs_readpage_from_fscache(struct nfs_open_context *ctx,int __nfs_readpages_from_fscache (struct nfs_open_context *ctx,struct inode *inode,struct address_space *mapping, -struct list_head *pages, -unsigned *nr_pages) +struct list_head *pages) { -unsigned npages = *nr_pages; +struct nfs_fscache_req *req;int ret; -dfprintk (FSCACHE ,"NFS: nfs_getpages_from_fscache (0x%p/%u/0x%p)\n" , -nfs_i_fscache (inode), npages, inode); - - ret =fscache_read_or_alloc_pages (nfs_i_fscache (inode), - 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); +dfprintk (FSCACHE ,"NFS: nfs_readpages_from_fscache (0x%p/0x%p)\n" , +nfs_i_fscache (inode), inode); + +while (!list_empty (pages)) { + req =nfs_alloc_io_request (ctx, mapping); +if (IS_ERR (req)) +return PTR_ERR (req); + + ret =fscache_read_helper_page_list (&req->cache, pages, +ULONG_MAX ); +nfs_put_io_request (&req->cache); +if (ret <0 ) +break ; + }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" ); +"NFS: nfs_readpages_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); +"NFS: nfs_readpages_from_fscache: no page: %d\n" , ret);return 1 ;default :dfprintk (FSCACHE , -"NFS: nfs_getpages_from_fscache: ret %d\n" , ret); +"NFS: nfs_readpages_from_fscache: ret %d\n" , ret); } -return ret; }/* -* 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 nfs_fscache_req *fsc_req = hdr->fsc_req; -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 (fsc_req && fsc_req->cache.io_done) { + fsc_req->cache.transferred =min ((long long )bytes, fsc_req->cache.len); +set_bit (FSCACHE_IO_DATA_FROM_SERVER , &fsc_req->cache.flags); + fsc_req->cache.io_done (&fsc_req->cache); +nfs_put_io_request (&fsc_req->cache); } }
fs/nfs/fscache.h +11 -14
@@ -97,8 +97,9 @@ 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 *); -extern void __nfs_readpage_to_fscache (struct inode *,struct page *,int ); +struct list_head *); +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
@@ -139,25 +140,22 @@ static inline int nfs_readpage_from_fscache(struct nfs_open_context *ctx,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) +struct list_head *pages) {if (NFS_I (inode)->fscache) -return __nfs_readpages_from_fscache (ctx, inode, mapping, pages, - nr_pages); +return __nfs_readpages_from_fscache (ctx, inode, mapping, pages);return -ENOBUFS ; }/* -* Store a page newly fetched from the server in an inode data storage object +* Store pages newly fetched from the server in an inode data storage object * in the cache. */ -static inline void nfs_readpage_to_fscache (struct inode *inode, -struct page *page, -int sync) +static inline void nfs_read_completion_to_fscache (struct nfs_pgio_header *hdr, +unsigned long bytes) { -if (PageFsCache (page)) -__nfs_readpage_to_fscache (inode, page, sync); +if (NFS_I (hdr->inode)->fscache) +__nfs_read_completion_to_fscache (hdr, bytes); }/*
@@ -218,8 +216,7 @@ static inline int nfs_readpage_from_fscache(struct nfs_open_context *ctx,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) +struct list_head *pages) {return -ENOBUFS ; }
fs/nfs/pagelist.c +1 -0
@@ -52,6 +52,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_req = desc->pg_fsc_req; hdr->release = release; hdr->completion_ops = desc->pg_completion_ops;if (hdr->completion_ops->init_hdr)
fs/nfs/read.c +9 -5
@@ -124,10 +124,13 @@ 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)) +put_page (page);/* See nfs_issue_op() */ +else +unlock_page (page); }nfs_release_request (req); }
@@ -186,6 +189,8 @@ static void nfs_read_completion(struct nfs_pgio_header *hdr)nfs_list_remove_request (req);nfs_readpage_release (req, error); } +/* FIXME: Review error handling before writing to fscache */ +nfs_read_completion_to_fscache (hdr, bytes); out: hdr->release (hdr); }
@@ -374,7 +379,7 @@ int nfs_readpage(struct file *filp, struct page *page)nfs_pageio_init_read (desc.pgio, inode, false, &nfs_async_read_completion_ops); - ret =nfs_pageio_add_page_read (desc.pgio, page); + ret =nfs_pageio_add_page_read (&desc, page);if (!ret)nfs_pageio_complete_read (desc.pgio, inode);
@@ -422,8 +427,7 @@ int nfs_readpages(struct file *filp, struct address_space *mapping,/* 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_readpages_from_fscache (desc.ctx, inode, mapping, pages);if (ret ==0 ) goto read_complete;/* all pages were read */
include/linux/nfs_page.h +1 -0
@@ -97,6 +97,7 @@ struct nfs_pageio_descriptor {struct pnfs_layout_segment *pg_lseg;struct nfs_io_completion *pg_io_completion;struct nfs_direct_req *pg_dreq; +struct nfs_fscache_req *pg_fsc_req;/* fscache req - may be NULL */ unsigned int pg_bsize;/* default bsize for mirrors */ u32 pg_mirror_count;
include/linux/nfs_xdr.h +1 -0
@@ -1535,6 +1535,7 @@ struct nfs_pgio_header {const struct nfs_rw_ops *rw_ops;struct nfs_io_completion *io_completion;struct nfs_direct_req *dreq; +struct nfs_fscache_req *fsc_req;/* fscache req - may be NULL */ int pnfs_error;int error;/* merge with pnfs_error */
Signature · 1 line
1.8.3.1
RFC PATCH 10/13 NFS: Allow NFS use of new fscache API in build
In reply to Dave WysochanskiAdd the ability for NFS to build FS-Cache against the new API.
--- fs/nfs/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/Kconfig +1 -1
@@ -170,7 +170,7 @@ config ROOT_NFS config NFS_FSCACHE bool "Provide NFS client caching support" - depends on NFS_FS=m && FSCACHE_OLD || NFS_FS=y && FSCACHE_OLD=y + depends on NFS_FS=m && FSCACHE || NFS_FS=y && FSCACHE=y help Say Y here if you want NFS data to be cached locally on disc through the general filesystem cache manager
Signature · 1 line
1.8.3.1
RFC PATCH 11/13 NFS: Only use and unuse an fscache cookie a single time based on NFS_INO_FSCACHE
In reply to Dave WysochanskiFor NFS, we only want to make a decision whether to "use" a inode based fscache cookie one time, not multiple times, and based on whether the inode is open for write by any process. Achieve this by gating the call to fscache_use_cookie / fscache_unuse_cookie by the NFS_INO_FSCACHE flag on the nfs_inode.
--- fs/nfs/fscache.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
fs/nfs/fscache.c +14 -7
@@ -285,8 +285,10 @@ void nfs_fscache_clear_inode(struct inode *inode)dfprintk (FSCACHE ,"NFS: clear cookie (0x%p/0x%p)\n" , nfsi, cookie); -nfs_fscache_update_auxdata (&auxdata, nfsi); -fscache_unuse_cookie (cookie, &auxdata,NULL ); +if (test_and_clear_bit (NFS_INO_FSCACHE , &NFS_I (inode)->flags)) { +nfs_fscache_update_auxdata (&auxdata, nfsi); +fscache_unuse_cookie (cookie, &auxdata,NULL ); + }fscache_relinquish_cookie (cookie, false); nfsi->fscache =NULL ; }
@@ -321,18 +323,23 @@ void nfs_fscache_open_file(struct inode *inode, struct file *filp) {struct nfs_inode *nfsi =NFS_I (inode);struct fscache_cookie *cookie =nfs_i_fscache (inode); +struct nfs_fscache_inode_auxdata auxdata;if (!fscache_cookie_valid (cookie))return ;if (inode_is_open_for_write (inode)) { -dfprintk (FSCACHE ,"NFS: nfsi 0x%p disabling cache\n" , nfsi); -clear_bit (NFS_INO_FSCACHE , &nfsi->flags); +if (test_and_clear_bit (NFS_INO_FSCACHE , &nfsi->flags)) { +dfprintk (FSCACHE ,"NFS: nfsi 0x%p disabling cache\n" , nfsi); +nfs_fscache_update_auxdata (&auxdata, nfsi); +fscache_unuse_cookie (cookie, &auxdata,NULL ); + } }else { -dfprintk (FSCACHE ,"NFS: nfsi 0x%p enabling cache\n" , nfsi); -set_bit (NFS_INO_FSCACHE , &NFS_I (inode)->flags); +if (!test_and_set_bit (NFS_INO_FSCACHE , &nfsi->flags)) { +dfprintk (FSCACHE ,"NFS: nfsi 0x%p enabling cache\n" , nfsi); +fscache_use_cookie (cookie, false); + } } -fscache_use_cookie (cookie, false); }EXPORT_SYMBOL_GPL (nfs_fscache_open_file);
Signature · 1 line
1.8.3.1
RFC PATCH 12/13 NFS: Convert fscache invalidation and update aux_data and i_size
In reply to Dave WysochanskiConvert nfs_fscache_invalidate to the new FS-Cache API. Also, now when invalidating an fscache cookie, be sure to pass the latest i_size as well as aux_data to fscache.
A few APIs no longer exist so remove them. We can call directly to wait_on_page_fscache() because it checks whether a page is an fscache page before waiting on it.
--- fs/nfs/file.c | 20 +++++++++++------- fs/nfs/fscache.c | 21 ------------------- fs/nfs/fscache.h | 64 +++++++++++++++++++------------------------------------- fs/nfs/inode.c | 1 - fs/nfs/write.c | 2 +- 5 files changed, 35 insertions(+), 73 deletions(-)
fs/nfs/file.c +13 -7
@@ -413,8 +413,8 @@ static void nfs_invalidate_page(struct page *page, unsigned int offset,return ;/* Cancel any unstarted writes on this page */ nfs_wb_page_cancel (page_file_mapping (page)->host, page); - -nfs_fscache_invalidate_page (page, page->mapping->host); +wait_on_page_fscache (page); +nfs_fscache_invalidate (page_file_mapping (page)->host); }/*
@@ -429,8 +429,13 @@ static int nfs_release_page(struct page *page, gfp_t gfp)/* If PagePrivate() is set, then the page is not freeable */ if (PagePrivate (page)) -return 0 ; -return nfs_fscache_release_page (page, gfp); +return false; +if (PageFsCache (page)) { +if (!(gfp & __GFP_DIRECT_RECLAIM) || !(gfp & __GFP_FS)) +return false; +wait_on_page_fscache (page); + } +return true; } static void nfs_check_dirty_writeback(struct page *page,
@@ -473,12 +478,11 @@ static void nfs_check_dirty_writeback(struct page *page,static int nfs_launder_page (struct page *page) {struct inode *inode =page_file_mapping (page)->host; -struct nfs_inode *nfsi =NFS_I (inode);dfprintk (PAGECACHE ,"NFS: launder_page(%ld, %llu)\n" , inode->i_ino, (long long )page_offset (page)); -nfs_fscache_wait_on_page_write (nfsi, page); +wait_on_page_fscache (page);return nfs_wb_page (inode, page); }
@@ -553,7 +557,9 @@ static vm_fault_t nfs_vm_page_mkwrite(struct vm_fault *vmf)sb_start_pagefault (inode->i_sb);/* make sure the cache has finished storing the page */ -nfs_fscache_wait_on_page_write (NFS_I (inode), page); +if (PageFsCache (vmf->page) && +wait_on_page_bit_killable (vmf->page, PG_fscache) <0 ) +return VM_FAULT_RETRY ;wait_on_bit_action (&NFS_I (inode)->flags,NFS_INO_INVALIDATING , nfs_wait_bit_killable,TASK_KILLABLE );
fs/nfs/fscache.c +0 -21
@@ -14,7 +14,6 @@#include <linux/in6.h> #include <linux/seq_file.h> #include <linux/slab.h> -#include <linux/iversion.h> #include "internal.h" #include "iostat.h"
@@ -234,19 +233,6 @@ void nfs_fscache_release_super_cookie(struct super_block *sb) } } -static void nfs_fscache_update_auxdata (struct nfs_fscache_inode_auxdata *auxdata, -struct nfs_inode *nfsi) -{ -memset (auxdata,0 ,sizeof (*auxdata)); - auxdata->mtime_sec = nfsi->vfs_inode.i_mtime.tv_sec; - auxdata->mtime_nsec = nfsi->vfs_inode.i_mtime.tv_nsec; - auxdata->ctime_sec = nfsi->vfs_inode.i_ctime.tv_sec; - auxdata->ctime_nsec = nfsi->vfs_inode.i_ctime.tv_nsec; - -if (NFS_SERVER (&nfsi->vfs_inode)->nfs_client->rpc_ops->version ==4 ) - auxdata->change_attr =inode_peek_iversion_raw (&nfsi->vfs_inode); -} -/* * Initialise the per-inode cache cookie pointer for an NFS inode. */
@@ -293,13 +279,6 @@ void nfs_fscache_clear_inode(struct inode *inode) nfsi->fscache =NULL ; } -static bool nfs_fscache_can_enable (void *data) -{ -struct inode *inode = data; - -return !inode_is_open_for_write (inode); -} -/* * Enable or disable caching for a file that is being opened as appropriate. * The cookie is allocated when the inode is initialised, but is not enabled at
fs/nfs/fscache.h +21 -43
106 lines not on this page · raw message
fs/nfs/inode.c +0 -1
@@ -1248,7 +1248,6 @@ static int nfs_invalidate_mapping(struct inode *inode, struct address_space *mapspin_unlock (&inode->i_lock); }nfs_inc_stats (inode,NFSIOS_DATAINVALIDATE ); -nfs_fscache_wait_on_invalidate (inode); dfprintk(PAGECACHE, "NFS: (%s/%Lu) data cache invalidated\n", inode->i_sb->s_id,
fs/nfs/write.c +1 -1
@@ -2112,7 +2112,7 @@ int nfs_migrate_page(struct address_space *mapping, struct page *newpage,if (PagePrivate (page))return -EBUSY ; -if (!nfs_fscache_release_page (page,GFP_KERNEL )) +if (PageFsCache (page))return -EBUSY ;return migrate_page (mapping, newpage, page, mode);
Signature · 1 line
1.8.3.1
RFC PATCH 13/13 NFS: Call nfs_fscache_invalidate() when write extends the size of the file
In reply to Dave WysochanskiIf a write extends the size of the file and fscache is enabled, we need to invalidate the object with the new size. Otherwise, the next read from the cache may fail inside cachefiles_shape_extent() due to cookie->zero_point being smaller than the size of the file.
--- fs/nfs/write.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
fs/nfs/write.c +6 -1
@@ -277,6 +277,7 @@ static struct nfs_page *nfs_find_and_lock_page_request(struct page *page)static void nfs_grow_file (struct page *page,unsigned int offset,unsigned int count) {struct inode *inode =page_file_mapping (page)->host; +struct nfs_inode *nfsi =NFS_I (inode);loff_t end, i_size;pgoff_t end_index;
@@ -289,10 +290,14 @@ static void nfs_grow_file(struct page *page, unsigned int offset, unsigned int cif (i_size >= end) goto out;i_size_write (inode, end); -NFS_I (inode)->cache_validity &= ~NFS_INO_INVALID_SIZE ; + nfsi->cache_validity &= ~NFS_INO_INVALID_SIZE ; +if (nfsi->fscache) +nfs_fscache_invalidate (inode);nfs_inc_stats (inode,NFSIOS_EXTENDWRITE ); out:spin_unlock (&inode->i_lock); +dprintk ("NFS: nfs_grow_file (0x%p/0x%p) i_size=%lld\n" , + nfsi, nfsi->fscache, end); }/* A writeback failed: mark the page as bad, and invalidate the page cache */
Signature · 1 line
1.8.3.1
Quoted 2 lines · Dave Wysochanski
These patches update the nfs client to use the new FS-Cache API and are at:
https://github.com/DaveWysochanskiRH/kernel/commit/a426b431873ea755c94ccd403aeaba0c4e635016
Say I had a hypothetical, err, friend, who hadn't been following that FS-Cache work--could you summarize the advantages it bring us?
--b.
Quoted 100 lines
They are based on David Howells fscache-iter tree at
ff12b5a05bd6984ad83e762f702cb655222bad74
https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/commit/?h=fscache-iter&id=ff12b5a05bd6984ad83e762f702cb655222bad74The following patches may be of specific interest to review
as they are related to the conversion:
NFS: Convertfscache_acquire_cookieandfscache_relinquish_cookie
NFS: Convertnfs_readpage()andreadpages()to new fscache API
NFS: Only use and unuse an fscache cookie a single time based onNFS_INO_FSCACHE
NFS: Convert fscache invalidation and updateaux_dataandi_sizeNote that this is only a "first pass" v1 / RFC set I wanted to get out there for the maintainers to see and know this is being worked on. It is far from perfect and has some problems still need worked out. A short summary of this set:
1. Takes a "least invasive to existing code" approach
* most fscache bits stay fs/nfs/fscache.[ch]
* fscache enable/disable switched inside NFS code on nfs_inode.fscache
* only enable fscache for reads
* may not be the best approach (see future patcheset items below)2. Basically works and passes a series of tests
* should not affect NFS when fscache is disabled (no "fsc" option)
* a couple small NFS + fscache basic verification tests
* connectathon (all NFS versions, with/without 'fsc' option)
* various iozone tests (all NFS versions, with/without 'fsc' option)3. Still has a few known problems that are being tracked down
* Data integrity issue when write withO_DIRECTand read
back withoutO_DIRECT(we get 0's back from the cache)
* iozone tests run through ok but at the end superblock
cookies are left (each NFS version has a different superblock
cookie); this leads to "duplicate cookie" messages
upon subsequent mounts / runs
* A couple oopses in fscache reported to dhowells, may
be related to NFS's enable/disable of fscache on read/write
* Kernel build fails about halfway through with a strange
dubious error at the same place, linking this file:
ld:net/sunrpc/auth_gss/trace.o: attempt to load strings from a non-string section (number 41)In addition to fixing various code issues and above issues, a future patchset may:
1. The readpage/readpages conversion patch call
read_helpersdirectly rather than isolation intofs/nfs/fscache.c
* Similar to the AFS conversion, with calls directly to theread_helpers, but not sure about non-fsc code path2. Add write-through support
* Would probably eliminate some problematic code paths where fscache is turned on / off depending on whether a file switches from read to write and vice-versa
* This would rework open as well
* Have to work out whether this is possible or not and with what caveats as far as NFS version support (is this an NFSv4.x only thing?)3. Rework dfprintks and/or add ftrace points
* fscache/cachefiles has 'debug' logging similar to rpcdebug so not sure if we keep rpcdebug here or go full ftraceDave Wysochanski (13):
NFS: Clean upnfs_readpage()andnfs_readpages()
NFS: Innfs_readpage()only incrementNFSIOS_READPAGESwhen read
succeeds
NFS: Refactornfs_readpage()andnfs_readpage_async()to use
nfs_readdesc
NFS: Callreadpage_async_filler()fromnfs_readpage_async()
NFS: Addnfs_pageio_complete_read()and removenfs_readpage_async()
NFS: Renamereadpage_async_filler()tonfs_pageio_add_page_read()
NFS: Convertfscache_acquire_cookieandfscache_relinquish_cookie
NFS: Allownfs_async_read_completion_opsto be used by other NFS code
NFS: Convertnfs_readpage()andreadpages()to new fscache API
NFS: Allow NFS use of new fscache API in build
NFS: Only use and unuse an fscache cookie a single time based on
NFS_INO_FSCACHE
NFS: Convert fscache invalidation and updateaux_dataandi_size
NFS: Callnfs_fscache_invalidate()when write extends the size of the
filefs/nfs/Kconfig | 2 +- fs/nfs/file.c | 20 +-- fs/nfs/fscache-index.c | 94 -------------- fs/nfs/fscache.c | 315 ++++++++++++++++++++++++----------------------- fs/nfs/fscache.h | 92 +++++--------- fs/nfs/inode.c | 1 - fs/nfs/internal.h | 4 + fs/nfs/pagelist.c | 1 + fs/nfs/read.c | 221 ++++++++++++++++----------------- fs/nfs/write.c | 9 +- include/linux/nfs_fs.h | 3 +- include/linux/nfs_page.h | 1 + include/linux/nfs_xdr.h | 1 + 13 files changed, 322 insertions(+), 442 deletions(-)Signature · 1 line
1.8.3.1
Quoted 2 lines · J. Bruce Fields
Say I had a hypothetical, err, friend, who hadn't been following that FS-Cache work--could you summarize the advantages it bring us?
- Makes the caching code a lot simpler (~2400 LoC removed, ~1000 LoDoc[*] removed at the moment from fscache, cachefiles and afs).
- Stops using bmap to work out what data is cached. This isn't reliable with modern extend-based filesystems. A bitmap of cached granules is saved in an xattr instead.
- Uses async DIO (kiocbs) to do I/O to/from the cache rather than using buffered writes (kernel_write) and pagecache snooping for read (don't ask).
- A lot faster and less CPU intensive as there's no page-to-page copying.
- A lot less VM pressure as it doesn't have duplicate pages in the backing fs that aren't really accounted right.
- Uses tmpfiles+link to better handle invalidation. It will at some point hopefully employ linkat(AT_LINK_REPLACE) to effect cut-over on disk rather than unlink,link.
David
[*] The upstream docs got ReSTified, so the doc patches I have are now useless
and need reworking:-(.
Quoted 17 lines · David Howells
Quoted 2 lines · J. Bruce Fields
Say I had a hypothetical, err, friend, who hadn't been following that FS-Cache work--could you summarize the advantages it bring us?
- Makes the caching code a lot simpler (~2400 LoC removed, ~1000 LoDoc[*] removed at the moment from fscache, cachefiles and afs).
- Stops using bmap to work out what data is cached. This isn't reliable with modern extend-based filesystems. A bitmap of cached granules is saved in an xattr instead.
- Uses async DIO (kiocbs) to do I/O to/from the cache rather than using buffered writes (
kernel_write) and pagecache snooping for read (don't ask).
Quoted 8 lines
- A lot faster and less CPU intensive as there's no page-to-page copying.
- A lot less VM pressure as it doesn't have duplicate pages in the backing fs that aren't really accounted right.
- Uses tmpfiles+link to better handle invalidation. It will at some point hopefully employ
linkat(AT_LINK_REPLACE)to effect cut-over on disk rather than unlink,link.
Thanks!--b.
Quoted 4 lines
David
[*] The upstream docs got ReSTified, so the doc patches I have are now useless
and need reworking:-(.