NFS: Fix a regression in the read() syscall
Subsystems (2)
PATCH 1/2 NFS: Fix a regression in the read() syscall
When invalidating the page cache for a regular file, we want to first sync all dirty data to disk and then call invalidate_inode_pages2(). The latter relies on nfs_launder_page() and nfs_release_page() to deal respectively with dirty pages, and unstable written pages.
When commit 9590544694bec ("NFS: avoid deadlocks with loop-back mounted NFS filesystems.") changed the behaviour of nfs_release_page(), then it made it possible for invalidate_inode_pages2() to fail with an EBUSY. Unfortunately, that error is then propagated back to read().
Let's therefore work around the problem for now by protecting the call to sync the data and invalidate_inode_pages2() so that they are atomic w.r.t. the addition of new writes.
Later on, we can revisit whether or not we still need nfs_launder_page() and nfs_release_page().
--- fs/nfs/file.c | 4 ++-- fs/nfs/inode.c | 37 ++++++++++++++++++++++++++++++++++--- include/linux/nfs_fs.h | 1 + 3 files changed, 37 insertions(+), 5 deletions(-)
fs/nfs/file.c +2 -2
@@ -178,7 +178,7 @@ nfs_file_read(struct kiocb *iocb, struct iov_iter *to) iocb->ki_filp, iov_iter_count(to), (unsigned long) iocb->ki_pos); - result =nfs_revalidate_mapping (inode, iocb->ki_filp->f_mapping); + result =nfs_revalidate_mapping_protected (inode, iocb->ki_filp->f_mapping);if (!result) { result =generic_file_read_iter (iocb, to);if (result >0 )
@@ -199,7 +199,7 @@ nfs_file_splice_read(struct file *filp, loff_t *ppos,dprintk ("NFS: splice_read(%pD2, %lu@%Lu)\n" , filp, (unsigned long ) count, (unsigned long long ) *ppos); - res =nfs_revalidate_mapping (inode, filp->f_mapping); + res =nfs_revalidate_mapping_protected (inode, filp->f_mapping);if (!res) { res =generic_file_splice_read (filp, ppos, pipe, count, flags);if (res >0 )
fs/nfs/inode.c +34 -3
@@ -1067,11 +1067,14 @@ static bool nfs_mapping_need_revalidate_inode(struct inode *inode) }/** -* nfs_revalidate_mapping - Revalidate the pagecache +* __nfs_revalidate_mapping - Revalidate the pagecache * @inode - pointer to host inode * @mapping - pointer to mapping +* @may_lock - take inode->i_mutex? */ -int nfs_revalidate_mapping (struct inode *inode,struct address_space *mapping) +static int __nfs_revalidate_mapping (struct inode *inode, +struct address_space *mapping, +bool may_lock) {struct nfs_inode *nfsi =NFS_I (inode);unsigned long *bitlock = &nfsi->flags;
@@ -1120,7 +1123,12 @@ int nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping) nfsi->cache_validity &= ~NFS_INO_INVALID_DATA ;spin_unlock (&inode->i_lock);trace_nfs_invalidate_mapping_enter (inode); - ret =nfs_invalidate_mapping (inode, mapping); +if (may_lock) { +mutex_lock (&inode->i_mutex); + ret =nfs_invalidate_mapping (inode, mapping); +mutex_unlock (&inode->i_mutex); + }else + ret =nfs_invalidate_mapping (inode, mapping);trace_nfs_invalidate_mapping_exit (inode, ret);clear_bit_unlock (NFS_INO_INVALIDATING , bitlock);
@@ -1130,6 +1138,29 @@ out:return ret; } +/** +* nfs_revalidate_mapping - Revalidate the pagecache +* @inode - pointer to host inode +* @mapping - pointer to mapping +*/ +int nfs_revalidate_mapping (struct inode *inode,struct address_space *mapping) +{ +return __nfs_revalidate_mapping (inode, mapping, false); +} + +/** +* nfs_revalidate_mapping_protected - Revalidate the pagecache +* @inode - pointer to host inode +* @mapping - pointer to mapping +* +* Differs from nfs_revalidate_mapping() in that it grabs the inode->i_mutex +* while invalidating the mapping. +*/ +int nfs_revalidate_mapping_protected (struct inode *inode,struct address_space *mapping) +{ +return __nfs_revalidate_mapping (inode, mapping, true); +} +static unsigned long nfs_wcc_update_inode (struct inode *inode,struct nfs_fattr *fattr) {struct nfs_inode *nfsi =NFS_I (inode);
include/linux/nfs_fs.h +1 -0
@@ -356,6 +356,7 @@ extern int nfs_revalidate_inode(struct nfs_server *server, struct inode *inode);extern int nfs_revalidate_inode_rcu (struct nfs_server *server,struct inode *inode);extern int __nfs_revalidate_inode (struct nfs_server *,struct inode *);extern int nfs_revalidate_mapping (struct inode *inode,struct address_space *mapping); +extern int nfs_revalidate_mapping_protected (struct inode *inode,struct address_space *mapping);extern int nfs_setattr (struct dentry *,struct iattr *);extern void nfs_setattr_update_inode (struct inode *inode,struct iattr *attr,struct nfs_fattr *); extern void nfs_setsecurity(struct inode *inode, struct nfs_fattr *fattr,
Signature · 1 line
2.1.0
PATCH 2/2 NFS: Don't write enable new pages while an invalidation is proceeding
nfs_vm_page_mkwrite() should wait until the page cache invalidation is finished. This is the second patch in a 2 patch series to deprecate the NFS client's reliance on nfs_release_page() in the context of nfs_invalidate_mapping().
--- fs/nfs/file.c | 3 +++ fs/nfs/inode.c | 1 + 2 files changed, 4 insertions(+)
fs/nfs/file.c +3 -0
@@ -623,6 +623,9 @@ static int nfs_vm_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)/* make sure the cache has finished storing the page */ nfs_fscache_wait_on_page_write (NFS_I (inode), page); +wait_on_bit_action (&NFS_I (inode)->flags,NFS_INO_INVALIDATING , + nfs_wait_bit_killable,TASK_KILLABLE ); +lock_page (page); mapping =page_file_mapping (page);if (mapping != inode->i_mapping)
fs/nfs/inode.c +1 -0
@@ -1035,6 +1035,7 @@ static int nfs_invalidate_mapping(struct inode *inode, struct address_space *mapif (mapping->nrpages !=0 ) {if (S_ISREG (inode->i_mode)) { +unmap_mapping_range (mapping,0 ,0 ,0 ); ret =nfs_sync_mapping (mapping);if (ret <0 )return ret;
Signature · 1 line
2.1.0