aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfs/inode.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/nfs/inode.c')
-rw-r--r--fs/nfs/inode.c90
1 files changed, 13 insertions, 77 deletions
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index 7f9ecc46f3fb..657201acda84 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -97,18 +97,6 @@ u64 nfs_compat_user_ino64(u64 fileid)
97 return ino; 97 return ino;
98} 98}
99 99
100int nfs_write_inode(struct inode *inode, struct writeback_control *wbc)
101{
102 int ret;
103
104 ret = nfs_commit_inode(inode,
105 wbc->sync_mode == WB_SYNC_ALL ? FLUSH_SYNC : 0);
106 if (ret >= 0)
107 return 0;
108 __mark_inode_dirty(inode, I_DIRTY_DATASYNC);
109 return ret;
110}
111
112void nfs_clear_inode(struct inode *inode) 100void nfs_clear_inode(struct inode *inode)
113{ 101{
114 /* 102 /*
@@ -126,16 +114,12 @@ void nfs_clear_inode(struct inode *inode)
126 */ 114 */
127int nfs_sync_mapping(struct address_space *mapping) 115int nfs_sync_mapping(struct address_space *mapping)
128{ 116{
129 int ret; 117 int ret = 0;
130 118
131 if (mapping->nrpages == 0) 119 if (mapping->nrpages != 0) {
132 return 0; 120 unmap_mapping_range(mapping, 0, 0, 0);
133 unmap_mapping_range(mapping, 0, 0, 0); 121 ret = nfs_wb_all(mapping->host);
134 ret = filemap_write_and_wait(mapping); 122 }
135 if (ret != 0)
136 goto out;
137 ret = nfs_wb_all(mapping->host);
138out:
139 return ret; 123 return ret;
140} 124}
141 125
@@ -507,17 +491,11 @@ int nfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
507 int need_atime = NFS_I(inode)->cache_validity & NFS_INO_INVALID_ATIME; 491 int need_atime = NFS_I(inode)->cache_validity & NFS_INO_INVALID_ATIME;
508 int err; 492 int err;
509 493
510 /* 494 /* Flush out writes to the server in order to update c/mtime. */
511 * Flush out writes to the server in order to update c/mtime.
512 *
513 * Hold the i_mutex to suspend application writes temporarily;
514 * this prevents long-running writing applications from blocking
515 * nfs_wb_nocommit.
516 */
517 if (S_ISREG(inode->i_mode)) { 495 if (S_ISREG(inode->i_mode)) {
518 mutex_lock(&inode->i_mutex); 496 err = filemap_write_and_wait(inode->i_mapping);
519 nfs_wb_nocommit(inode); 497 if (err)
520 mutex_unlock(&inode->i_mutex); 498 goto out;
521 } 499 }
522 500
523 /* 501 /*
@@ -541,6 +519,7 @@ int nfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
541 generic_fillattr(inode, stat); 519 generic_fillattr(inode, stat);
542 stat->ino = nfs_compat_user_ino64(NFS_FILEID(inode)); 520 stat->ino = nfs_compat_user_ino64(NFS_FILEID(inode));
543 } 521 }
522out:
544 return err; 523 return err;
545} 524}
546 525
@@ -616,11 +595,6 @@ void put_nfs_open_context(struct nfs_open_context *ctx)
616 __put_nfs_open_context(ctx, 0); 595 __put_nfs_open_context(ctx, 0);
617} 596}
618 597
619static void put_nfs_open_context_sync(struct nfs_open_context *ctx)
620{
621 __put_nfs_open_context(ctx, 1);
622}
623
624/* 598/*
625 * Ensure that mmap has a recent RPC credential for use when writing out 599 * Ensure that mmap has a recent RPC credential for use when writing out
626 * shared pages 600 * shared pages
@@ -667,7 +641,7 @@ static void nfs_file_clear_open_context(struct file *filp)
667 spin_lock(&inode->i_lock); 641 spin_lock(&inode->i_lock);
668 list_move_tail(&ctx->list, &NFS_I(inode)->open_files); 642 list_move_tail(&ctx->list, &NFS_I(inode)->open_files);
669 spin_unlock(&inode->i_lock); 643 spin_unlock(&inode->i_lock);
670 put_nfs_open_context_sync(ctx); 644 __put_nfs_open_context(ctx, filp->f_flags & O_DIRECT ? 0 : 1);
671 } 645 }
672} 646}
673 647
@@ -775,7 +749,7 @@ int nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
775 return __nfs_revalidate_inode(server, inode); 749 return __nfs_revalidate_inode(server, inode);
776} 750}
777 751
778static int nfs_invalidate_mapping_nolock(struct inode *inode, struct address_space *mapping) 752static int nfs_invalidate_mapping(struct inode *inode, struct address_space *mapping)
779{ 753{
780 struct nfs_inode *nfsi = NFS_I(inode); 754 struct nfs_inode *nfsi = NFS_I(inode);
781 755
@@ -796,49 +770,10 @@ static int nfs_invalidate_mapping_nolock(struct inode *inode, struct address_spa
796 return 0; 770 return 0;
797} 771}
798 772
799static int nfs_invalidate_mapping(struct inode *inode, struct address_space *mapping)
800{
801 int ret = 0;
802
803 mutex_lock(&inode->i_mutex);
804 if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_DATA) {
805 ret = nfs_sync_mapping(mapping);
806 if (ret == 0)
807 ret = nfs_invalidate_mapping_nolock(inode, mapping);
808 }
809 mutex_unlock(&inode->i_mutex);
810 return ret;
811}
812
813/**
814 * nfs_revalidate_mapping_nolock - Revalidate the pagecache
815 * @inode - pointer to host inode
816 * @mapping - pointer to mapping
817 */
818int nfs_revalidate_mapping_nolock(struct inode *inode, struct address_space *mapping)
819{
820 struct nfs_inode *nfsi = NFS_I(inode);
821 int ret = 0;
822
823 if ((nfsi->cache_validity & NFS_INO_REVAL_PAGECACHE)
824 || nfs_attribute_timeout(inode) || NFS_STALE(inode)) {
825 ret = __nfs_revalidate_inode(NFS_SERVER(inode), inode);
826 if (ret < 0)
827 goto out;
828 }
829 if (nfsi->cache_validity & NFS_INO_INVALID_DATA)
830 ret = nfs_invalidate_mapping_nolock(inode, mapping);
831out:
832 return ret;
833}
834
835/** 773/**
836 * nfs_revalidate_mapping - Revalidate the pagecache 774 * nfs_revalidate_mapping - Revalidate the pagecache
837 * @inode - pointer to host inode 775 * @inode - pointer to host inode
838 * @mapping - pointer to mapping 776 * @mapping - pointer to mapping
839 *
840 * This version of the function will take the inode->i_mutex and attempt to
841 * flush out all dirty data if it needs to invalidate the page cache.
842 */ 777 */
843int nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping) 778int nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping)
844{ 779{
@@ -1416,6 +1351,7 @@ static void init_once(void *foo)
1416 INIT_LIST_HEAD(&nfsi->access_cache_inode_lru); 1351 INIT_LIST_HEAD(&nfsi->access_cache_inode_lru);
1417 INIT_RADIX_TREE(&nfsi->nfs_page_tree, GFP_ATOMIC); 1352 INIT_RADIX_TREE(&nfsi->nfs_page_tree, GFP_ATOMIC);
1418 nfsi->npages = 0; 1353 nfsi->npages = 0;
1354 nfsi->ncommit = 0;
1419 atomic_set(&nfsi->silly_count, 1); 1355 atomic_set(&nfsi->silly_count, 1);
1420 INIT_HLIST_HEAD(&nfsi->silly_list); 1356 INIT_HLIST_HEAD(&nfsi->silly_list);
1421 init_waitqueue_head(&nfsi->waitqueue); 1357 init_waitqueue_head(&nfsi->waitqueue);