NFS: Convert fscache invalidation and update aux_data and i_size
Subsystems (2)
PATCH 9/13 NFS: Convert fscache invalidation and update aux_data and i_size
Convert 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.
Since the current NFS fscache implementation is only enabled when a file is open for read, handle writes with invalidation. If a write extends the size of the file and fscache is enabled, we must invalidate the object with the new size.
We must also invalidate fscache when doing a direct write to avoid issues seen specifically with NFSv4.x when direct writes are followed by non-direct (buffered) reads. Note that we cannot call fscache_invalidate() while holding inode->i_lock.
--- fs/nfs/direct.c | 2 ++ fs/nfs/file.c | 20 ++++++++++------ fs/nfs/fscache.c | 20 ---------------- fs/nfs/fscache.h | 69 +++++++++++++++++++------------------------------------ fs/nfs/inode.c | 4 ++-- fs/nfs/nfs4proc.c | 2 +- fs/nfs/write.c | 3 ++- 7 files changed, 44 insertions(+), 76 deletions(-)
fs/nfs/direct.c +2 -0
@@ -59,6 +59,7 @@#include "internal.h" #include "iostat.h" #include "pnfs.h" +#include "fscache.h" #define NFSDBG_FACILITY NFSDBG_VFS
@@ -962,6 +963,7 @@ ssize_t nfs_file_direct_write(struct kiocb *iocb, struct iov_iter *iter) }else { result = requested; } +nfs_fscache_invalidate (inode,FSCACHE_INVAL_DIO_WRITE ); out_release:nfs_direct_req_release (dreq); out:
fs/nfs/file.c +13 -7
@@ -415,8 +415,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,0 ); }/*
@@ -431,8 +431,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,
@@ -475,12 +480,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); }
@@ -555,7 +559,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 -20
@@ -234,19 +234,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 +280,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 +24 -45
110 lines not on this page · raw message
fs/nfs/inode.c +2 -2
@@ -213,7 +213,7 @@ static void nfs_set_cache_invalid(struct inode *inode, unsigned long flags) flags &= ~(NFS_INO_INVALID_DATA |NFS_INO_DATA_INVAL_DEFER ); nfsi->cache_validity |= flags;if (flags &NFS_INO_INVALID_DATA ) -nfs_fscache_invalidate (inode); +nfs_fscache_invalidate (inode,0 ); }/*
@@ -1240,6 +1240,7 @@ static int nfs_invalidate_mapping(struct inode *inode, struct address_space *mapstruct nfs_inode *nfsi =NFS_I (inode);int ret; +nfs_fscache_invalidate (inode,0 );if (mapping->nrpages !=0 ) {if (S_ISREG (inode->i_mode)) { ret =nfs_sync_mapping (mapping);
@@ -1256,7 +1257,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/nfs4proc.c +1 -1
@@ -1217,7 +1217,7 @@ int nfs4_call_sync(struct rpc_clnt *clnt, nfsi->cache_validity &= ~NFS_INO_INVALID_CHANGE ;if (nfsi->cache_validity &NFS_INO_INVALID_DATA ) -nfs_fscache_invalidate (inode); +nfs_fscache_invalidate (inode,0 ); }void
fs/nfs/write.c +2 -1
@@ -293,6 +293,7 @@ static void nfs_grow_file(struct page *page, unsigned int offset, unsigned int cnfs_inc_stats (inode,NFSIOS_EXTENDWRITE ); out:spin_unlock (&inode->i_lock); +nfs_fscache_invalidate (inode,0 ); }/* A writeback failed: mark the page as bad, and invalidate the page cache */
@@ -2112,7 +2113,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