aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorTrond Myklebust <Trond.Myklebust@netapp.com>2006-03-20 13:44:04 -0500
committerTrond Myklebust <Trond.Myklebust@netapp.com>2006-03-20 13:44:04 -0500
commitcd52ed35535ef443f08bf5cd3331d350272885b8 (patch)
tree135c3a80b21ce478816229dc82586b12754eb49f /fs
parentb92dccf65bab3b6b7deb79ff3321dc256eb0f53b (diff)
NFS: Avoid races between writebacks and truncation
Currently, there is no serialisation between NFS asynchronous writebacks and truncation at the page level due to the fact that nfs_sync_inode() cannot lock the pages that it is about to write out. This means that it is possible to be flushing out data (and calling something like set_page_writeback()) while the page cache is busy evicting the page. Oops... Use the hooks provided in try_to_release_page() to ensure that dirty pages are always written back to storage before we evict them. Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/nfs/file.c13
-rw-r--r--fs/nfs/pagelist.c10
2 files changed, 21 insertions, 2 deletions
diff --git a/fs/nfs/file.c b/fs/nfs/file.c
index 7a79fbe9f539..387809f2d188 100644
--- a/fs/nfs/file.c
+++ b/fs/nfs/file.c
@@ -316,6 +316,17 @@ static int nfs_commit_write(struct file *file, struct page *page, unsigned offse
316 return status; 316 return status;
317} 317}
318 318
319static int nfs_invalidate_page(struct page *page, unsigned long offset)
320{
321 /* FIXME: we really should cancel any unstarted writes on this page */
322 return 1;
323}
324
325static int nfs_release_page(struct page *page, gfp_t gfp)
326{
327 return !nfs_wb_page(page->mapping->host, page);
328}
329
319struct address_space_operations nfs_file_aops = { 330struct address_space_operations nfs_file_aops = {
320 .readpage = nfs_readpage, 331 .readpage = nfs_readpage,
321 .readpages = nfs_readpages, 332 .readpages = nfs_readpages,
@@ -324,6 +335,8 @@ struct address_space_operations nfs_file_aops = {
324 .writepages = nfs_writepages, 335 .writepages = nfs_writepages,
325 .prepare_write = nfs_prepare_write, 336 .prepare_write = nfs_prepare_write,
326 .commit_write = nfs_commit_write, 337 .commit_write = nfs_commit_write,
338 .invalidatepage = nfs_invalidate_page,
339 .releasepage = nfs_release_page,
327#ifdef CONFIG_NFS_DIRECTIO 340#ifdef CONFIG_NFS_DIRECTIO
328 .direct_IO = nfs_direct_IO, 341 .direct_IO = nfs_direct_IO,
329#endif 342#endif
diff --git a/fs/nfs/pagelist.c b/fs/nfs/pagelist.c
index d53857b148e2..d6e076c9dbe1 100644
--- a/fs/nfs/pagelist.c
+++ b/fs/nfs/pagelist.c
@@ -85,6 +85,10 @@ nfs_create_request(struct nfs_open_context *ctx, struct inode *inode,
85 atomic_set(&req->wb_complete, 0); 85 atomic_set(&req->wb_complete, 0);
86 req->wb_index = page->index; 86 req->wb_index = page->index;
87 page_cache_get(page); 87 page_cache_get(page);
88 BUG_ON(PagePrivate(page));
89 BUG_ON(!PageLocked(page));
90 BUG_ON(page->mapping->host != inode);
91 SetPagePrivate(page);
88 req->wb_offset = offset; 92 req->wb_offset = offset;
89 req->wb_pgbase = offset; 93 req->wb_pgbase = offset;
90 req->wb_bytes = count; 94 req->wb_bytes = count;
@@ -147,8 +151,10 @@ void nfs_clear_page_writeback(struct nfs_page *req)
147 */ 151 */
148void nfs_clear_request(struct nfs_page *req) 152void nfs_clear_request(struct nfs_page *req)
149{ 153{
150 if (req->wb_page) { 154 struct page *page = req->wb_page;
151 page_cache_release(req->wb_page); 155 if (page != NULL) {
156 ClearPagePrivate(page);
157 page_cache_release(page);
152 req->wb_page = NULL; 158 req->wb_page = NULL;
153 } 159 }
154} 160}