Commit cd9ae2b6 authored by Trond Myklebust's avatar Trond Myklebust Committed by Linus Torvalds

[PATCH] NFS: Deal with failure of invalidate_inode_pages2()

If invalidate_inode_pages2() fails, then it should in principle just be
because the current process was signalled.  In that case, we just want to
ensure that the inode's page cache remains marked as invalid.

Also add a helper to allow the O_DIRECT code to simply mark the page cache as
invalid once it is finished writing, instead of calling
invalidate_inode_pages2() itself.
Signed-off-by: default avatarTrond Myklebust <Trond.Myklebust@netapp.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 13bbc06a
...@@ -203,8 +203,10 @@ int nfs_readdir_filler(nfs_readdir_descriptor_t *desc, struct page *page) ...@@ -203,8 +203,10 @@ int nfs_readdir_filler(nfs_readdir_descriptor_t *desc, struct page *page)
* Note: assumes we have exclusive access to this mapping either * Note: assumes we have exclusive access to this mapping either
* through inode->i_mutex or some other mechanism. * through inode->i_mutex or some other mechanism.
*/ */
if (page->index == 0) if (page->index == 0 && invalidate_inode_pages2_range(inode->i_mapping, PAGE_CACHE_SIZE, -1) < 0) {
invalidate_inode_pages2_range(inode->i_mapping, PAGE_CACHE_SIZE, -1); /* Should never happen */
nfs_zap_mapping(inode, inode->i_mapping);
}
unlock_page(page); unlock_page(page);
return 0; return 0;
error: error:
......
...@@ -497,6 +497,7 @@ static void nfs_direct_write_complete(struct nfs_direct_req *dreq, struct inode ...@@ -497,6 +497,7 @@ static void nfs_direct_write_complete(struct nfs_direct_req *dreq, struct inode
if (dreq->commit_data != NULL) if (dreq->commit_data != NULL)
nfs_commit_free(dreq->commit_data); nfs_commit_free(dreq->commit_data);
nfs_direct_free_writedata(dreq); nfs_direct_free_writedata(dreq);
nfs_zap_mapping(inode, inode->i_mapping);
nfs_direct_complete(dreq); nfs_direct_complete(dreq);
} }
} }
...@@ -517,6 +518,7 @@ static void nfs_direct_write_complete(struct nfs_direct_req *dreq, struct inode ...@@ -517,6 +518,7 @@ static void nfs_direct_write_complete(struct nfs_direct_req *dreq, struct inode
{ {
nfs_end_data_update(inode); nfs_end_data_update(inode);
nfs_direct_free_writedata(dreq); nfs_direct_free_writedata(dreq);
nfs_zap_mapping(inode, inode->i_mapping);
nfs_direct_complete(dreq); nfs_direct_complete(dreq);
} }
#endif #endif
...@@ -830,17 +832,6 @@ ssize_t nfs_file_direct_write(struct kiocb *iocb, const struct iovec *iov, ...@@ -830,17 +832,6 @@ ssize_t nfs_file_direct_write(struct kiocb *iocb, const struct iovec *iov,
retval = nfs_direct_write(iocb, (unsigned long) buf, count, pos); retval = nfs_direct_write(iocb, (unsigned long) buf, count, pos);
/*
* XXX: nfs_end_data_update() already ensures this file's
* cached data is subsequently invalidated. Do we really
* need to call invalidate_inode_pages2() again here?
*
* For aio writes, this invalidation will almost certainly
* occur before the writes complete. Kind of racey.
*/
if (mapping->nrpages)
invalidate_inode_pages2(mapping);
if (retval > 0) if (retval > 0)
iocb->ki_pos = pos + retval; iocb->ki_pos = pos + retval;
......
...@@ -131,6 +131,15 @@ void nfs_zap_caches(struct inode *inode) ...@@ -131,6 +131,15 @@ void nfs_zap_caches(struct inode *inode)
spin_unlock(&inode->i_lock); spin_unlock(&inode->i_lock);
} }
void nfs_zap_mapping(struct inode *inode, struct address_space *mapping)
{
if (mapping->nrpages != 0) {
spin_lock(&inode->i_lock);
NFS_I(inode)->cache_validity |= NFS_INO_INVALID_DATA;
spin_unlock(&inode->i_lock);
}
}
static void nfs_zap_acl_cache(struct inode *inode) static void nfs_zap_acl_cache(struct inode *inode)
{ {
void (*clear_acl_cache)(struct inode *); void (*clear_acl_cache)(struct inode *);
...@@ -671,13 +680,20 @@ int nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping) ...@@ -671,13 +680,20 @@ int nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping)
if ((nfsi->cache_validity & NFS_INO_REVAL_PAGECACHE) if ((nfsi->cache_validity & NFS_INO_REVAL_PAGECACHE)
|| nfs_attribute_timeout(inode)) || nfs_attribute_timeout(inode))
ret = __nfs_revalidate_inode(NFS_SERVER(inode), inode); ret = __nfs_revalidate_inode(NFS_SERVER(inode), inode);
if (ret < 0)
goto out;
if (nfsi->cache_validity & NFS_INO_INVALID_DATA) { if (nfsi->cache_validity & NFS_INO_INVALID_DATA) {
nfs_inc_stats(inode, NFSIOS_DATAINVALIDATE); if (mapping->nrpages != 0) {
if (S_ISREG(inode->i_mode)) if (S_ISREG(inode->i_mode)) {
nfs_sync_mapping(mapping); ret = nfs_sync_mapping(mapping);
invalidate_inode_pages2(mapping); if (ret < 0)
goto out;
}
ret = invalidate_inode_pages2(mapping);
if (ret < 0)
goto out;
}
spin_lock(&inode->i_lock); spin_lock(&inode->i_lock);
nfsi->cache_validity &= ~NFS_INO_INVALID_DATA; nfsi->cache_validity &= ~NFS_INO_INVALID_DATA;
if (S_ISDIR(inode->i_mode)) { if (S_ISDIR(inode->i_mode)) {
...@@ -687,10 +703,12 @@ int nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping) ...@@ -687,10 +703,12 @@ int nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping)
} }
spin_unlock(&inode->i_lock); spin_unlock(&inode->i_lock);
nfs_inc_stats(inode, NFSIOS_DATAINVALIDATE);
dfprintk(PAGECACHE, "NFS: (%s/%Ld) data cache invalidated\n", dfprintk(PAGECACHE, "NFS: (%s/%Ld) data cache invalidated\n",
inode->i_sb->s_id, inode->i_sb->s_id,
(long long)NFS_FILEID(inode)); (long long)NFS_FILEID(inode));
} }
out:
return ret; return ret;
} }
......
...@@ -290,6 +290,7 @@ static inline int nfs_verify_change_attribute(struct inode *inode, unsigned long ...@@ -290,6 +290,7 @@ static inline int nfs_verify_change_attribute(struct inode *inode, unsigned long
* linux/fs/nfs/inode.c * linux/fs/nfs/inode.c
*/ */
extern int nfs_sync_mapping(struct address_space *mapping); extern int nfs_sync_mapping(struct address_space *mapping);
extern void nfs_zap_mapping(struct inode *inode, struct address_space *mapping);
extern void nfs_zap_caches(struct inode *); extern void nfs_zap_caches(struct inode *);
extern struct inode *nfs_fhget(struct super_block *, struct nfs_fh *, extern struct inode *nfs_fhget(struct super_block *, struct nfs_fh *,
struct nfs_fattr *); struct nfs_fattr *);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment