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.c117
1 files changed, 26 insertions, 91 deletions
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index faa091865ad0..50a56edca0b5 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -36,6 +36,7 @@
36#include <linux/vfs.h> 36#include <linux/vfs.h>
37#include <linux/inet.h> 37#include <linux/inet.h>
38#include <linux/nfs_xdr.h> 38#include <linux/nfs_xdr.h>
39#include <linux/slab.h>
39 40
40#include <asm/system.h> 41#include <asm/system.h>
41#include <asm/uaccess.h> 42#include <asm/uaccess.h>
@@ -97,22 +98,6 @@ u64 nfs_compat_user_ino64(u64 fileid)
97 return ino; 98 return ino;
98} 99}
99 100
100int nfs_write_inode(struct inode *inode, int sync)
101{
102 int ret;
103
104 if (sync) {
105 ret = filemap_fdatawait(inode->i_mapping);
106 if (ret == 0)
107 ret = nfs_commit_inode(inode, FLUSH_SYNC);
108 } else
109 ret = nfs_commit_inode(inode, 0);
110 if (ret >= 0)
111 return 0;
112 __mark_inode_dirty(inode, I_DIRTY_DATASYNC);
113 return ret;
114}
115
116void nfs_clear_inode(struct inode *inode) 101void nfs_clear_inode(struct inode *inode)
117{ 102{
118 /* 103 /*
@@ -130,16 +115,12 @@ void nfs_clear_inode(struct inode *inode)
130 */ 115 */
131int nfs_sync_mapping(struct address_space *mapping) 116int nfs_sync_mapping(struct address_space *mapping)
132{ 117{
133 int ret; 118 int ret = 0;
134 119
135 if (mapping->nrpages == 0) 120 if (mapping->nrpages != 0) {
136 return 0; 121 unmap_mapping_range(mapping, 0, 0, 0);
137 unmap_mapping_range(mapping, 0, 0, 0); 122 ret = nfs_wb_all(mapping->host);
138 ret = filemap_write_and_wait(mapping); 123 }
139 if (ret != 0)
140 goto out;
141 ret = nfs_wb_all(mapping->host);
142out:
143 return ret; 124 return ret;
144} 125}
145 126
@@ -511,17 +492,11 @@ int nfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
511 int need_atime = NFS_I(inode)->cache_validity & NFS_INO_INVALID_ATIME; 492 int need_atime = NFS_I(inode)->cache_validity & NFS_INO_INVALID_ATIME;
512 int err; 493 int err;
513 494
514 /* 495 /* Flush out writes to the server in order to update c/mtime. */
515 * Flush out writes to the server in order to update c/mtime.
516 *
517 * Hold the i_mutex to suspend application writes temporarily;
518 * this prevents long-running writing applications from blocking
519 * nfs_wb_nocommit.
520 */
521 if (S_ISREG(inode->i_mode)) { 496 if (S_ISREG(inode->i_mode)) {
522 mutex_lock(&inode->i_mutex); 497 err = filemap_write_and_wait(inode->i_mapping);
523 nfs_wb_nocommit(inode); 498 if (err)
524 mutex_unlock(&inode->i_mutex); 499 goto out;
525 } 500 }
526 501
527 /* 502 /*
@@ -545,6 +520,7 @@ int nfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
545 generic_fillattr(inode, stat); 520 generic_fillattr(inode, stat);
546 stat->ino = nfs_compat_user_ino64(NFS_FILEID(inode)); 521 stat->ino = nfs_compat_user_ino64(NFS_FILEID(inode));
547 } 522 }
523out:
548 return err; 524 return err;
549} 525}
550 526
@@ -574,14 +550,14 @@ void nfs_close_context(struct nfs_open_context *ctx, int is_sync)
574 nfs_revalidate_inode(server, inode); 550 nfs_revalidate_inode(server, inode);
575} 551}
576 552
577static struct nfs_open_context *alloc_nfs_open_context(struct vfsmount *mnt, struct dentry *dentry, struct rpc_cred *cred) 553static struct nfs_open_context *alloc_nfs_open_context(struct path *path, struct rpc_cred *cred)
578{ 554{
579 struct nfs_open_context *ctx; 555 struct nfs_open_context *ctx;
580 556
581 ctx = kmalloc(sizeof(*ctx), GFP_KERNEL); 557 ctx = kmalloc(sizeof(*ctx), GFP_KERNEL);
582 if (ctx != NULL) { 558 if (ctx != NULL) {
583 ctx->path.dentry = dget(dentry); 559 ctx->path = *path;
584 ctx->path.mnt = mntget(mnt); 560 path_get(&ctx->path);
585 ctx->cred = get_rpccred(cred); 561 ctx->cred = get_rpccred(cred);
586 ctx->state = NULL; 562 ctx->state = NULL;
587 ctx->lockowner = current->files; 563 ctx->lockowner = current->files;
@@ -620,11 +596,6 @@ void put_nfs_open_context(struct nfs_open_context *ctx)
620 __put_nfs_open_context(ctx, 0); 596 __put_nfs_open_context(ctx, 0);
621} 597}
622 598
623static void put_nfs_open_context_sync(struct nfs_open_context *ctx)
624{
625 __put_nfs_open_context(ctx, 1);
626}
627
628/* 599/*
629 * Ensure that mmap has a recent RPC credential for use when writing out 600 * Ensure that mmap has a recent RPC credential for use when writing out
630 * shared pages 601 * shared pages
@@ -652,10 +623,10 @@ struct nfs_open_context *nfs_find_open_context(struct inode *inode, struct rpc_c
652 list_for_each_entry(pos, &nfsi->open_files, list) { 623 list_for_each_entry(pos, &nfsi->open_files, list) {
653 if (cred != NULL && pos->cred != cred) 624 if (cred != NULL && pos->cred != cred)
654 continue; 625 continue;
655 if ((pos->mode & mode) == mode) { 626 if ((pos->mode & (FMODE_READ|FMODE_WRITE)) != mode)
656 ctx = get_nfs_open_context(pos); 627 continue;
657 break; 628 ctx = get_nfs_open_context(pos);
658 } 629 break;
659 } 630 }
660 spin_unlock(&inode->i_lock); 631 spin_unlock(&inode->i_lock);
661 return ctx; 632 return ctx;
@@ -671,7 +642,7 @@ static void nfs_file_clear_open_context(struct file *filp)
671 spin_lock(&inode->i_lock); 642 spin_lock(&inode->i_lock);
672 list_move_tail(&ctx->list, &NFS_I(inode)->open_files); 643 list_move_tail(&ctx->list, &NFS_I(inode)->open_files);
673 spin_unlock(&inode->i_lock); 644 spin_unlock(&inode->i_lock);
674 put_nfs_open_context_sync(ctx); 645 __put_nfs_open_context(ctx, filp->f_flags & O_DIRECT ? 0 : 1);
675 } 646 }
676} 647}
677 648
@@ -686,7 +657,7 @@ int nfs_open(struct inode *inode, struct file *filp)
686 cred = rpc_lookup_cred(); 657 cred = rpc_lookup_cred();
687 if (IS_ERR(cred)) 658 if (IS_ERR(cred))
688 return PTR_ERR(cred); 659 return PTR_ERR(cred);
689 ctx = alloc_nfs_open_context(filp->f_path.mnt, filp->f_path.dentry, cred); 660 ctx = alloc_nfs_open_context(&filp->f_path, cred);
690 put_rpccred(cred); 661 put_rpccred(cred);
691 if (ctx == NULL) 662 if (ctx == NULL)
692 return -ENOMEM; 663 return -ENOMEM;
@@ -759,7 +730,7 @@ int nfs_attribute_timeout(struct inode *inode)
759{ 730{
760 struct nfs_inode *nfsi = NFS_I(inode); 731 struct nfs_inode *nfsi = NFS_I(inode);
761 732
762 if (nfs_have_delegation(inode, FMODE_READ)) 733 if (nfs_have_delegated_attributes(inode))
763 return 0; 734 return 0;
764 return !time_in_range_open(jiffies, nfsi->read_cache_jiffies, nfsi->read_cache_jiffies + nfsi->attrtimeo); 735 return !time_in_range_open(jiffies, nfsi->read_cache_jiffies, nfsi->read_cache_jiffies + nfsi->attrtimeo);
765} 736}
@@ -779,7 +750,7 @@ int nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
779 return __nfs_revalidate_inode(server, inode); 750 return __nfs_revalidate_inode(server, inode);
780} 751}
781 752
782static int nfs_invalidate_mapping_nolock(struct inode *inode, struct address_space *mapping) 753static int nfs_invalidate_mapping(struct inode *inode, struct address_space *mapping)
783{ 754{
784 struct nfs_inode *nfsi = NFS_I(inode); 755 struct nfs_inode *nfsi = NFS_I(inode);
785 756
@@ -800,49 +771,10 @@ static int nfs_invalidate_mapping_nolock(struct inode *inode, struct address_spa
800 return 0; 771 return 0;
801} 772}
802 773
803static int nfs_invalidate_mapping(struct inode *inode, struct address_space *mapping)
804{
805 int ret = 0;
806
807 mutex_lock(&inode->i_mutex);
808 if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_DATA) {
809 ret = nfs_sync_mapping(mapping);
810 if (ret == 0)
811 ret = nfs_invalidate_mapping_nolock(inode, mapping);
812 }
813 mutex_unlock(&inode->i_mutex);
814 return ret;
815}
816
817/**
818 * nfs_revalidate_mapping_nolock - Revalidate the pagecache
819 * @inode - pointer to host inode
820 * @mapping - pointer to mapping
821 */
822int nfs_revalidate_mapping_nolock(struct inode *inode, struct address_space *mapping)
823{
824 struct nfs_inode *nfsi = NFS_I(inode);
825 int ret = 0;
826
827 if ((nfsi->cache_validity & NFS_INO_REVAL_PAGECACHE)
828 || nfs_attribute_timeout(inode) || NFS_STALE(inode)) {
829 ret = __nfs_revalidate_inode(NFS_SERVER(inode), inode);
830 if (ret < 0)
831 goto out;
832 }
833 if (nfsi->cache_validity & NFS_INO_INVALID_DATA)
834 ret = nfs_invalidate_mapping_nolock(inode, mapping);
835out:
836 return ret;
837}
838
839/** 774/**
840 * nfs_revalidate_mapping - Revalidate the pagecache 775 * nfs_revalidate_mapping - Revalidate the pagecache
841 * @inode - pointer to host inode 776 * @inode - pointer to host inode
842 * @mapping - pointer to mapping 777 * @mapping - pointer to mapping
843 *
844 * This version of the function will take the inode->i_mutex and attempt to
845 * flush out all dirty data if it needs to invalidate the page cache.
846 */ 778 */
847int nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping) 779int nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping)
848{ 780{
@@ -1261,8 +1193,10 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1261 1193
1262 if (fattr->valid & NFS_ATTR_FATTR_MODE) { 1194 if (fattr->valid & NFS_ATTR_FATTR_MODE) {
1263 if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO)) { 1195 if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO)) {
1196 umode_t newmode = inode->i_mode & S_IFMT;
1197 newmode |= fattr->mode & S_IALLUGO;
1198 inode->i_mode = newmode;
1264 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL; 1199 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
1265 inode->i_mode = fattr->mode;
1266 } 1200 }
1267 } else if (server->caps & NFS_CAP_MODE) 1201 } else if (server->caps & NFS_CAP_MODE)
1268 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR 1202 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
@@ -1418,6 +1352,7 @@ static void init_once(void *foo)
1418 INIT_LIST_HEAD(&nfsi->access_cache_inode_lru); 1352 INIT_LIST_HEAD(&nfsi->access_cache_inode_lru);
1419 INIT_RADIX_TREE(&nfsi->nfs_page_tree, GFP_ATOMIC); 1353 INIT_RADIX_TREE(&nfsi->nfs_page_tree, GFP_ATOMIC);
1420 nfsi->npages = 0; 1354 nfsi->npages = 0;
1355 nfsi->ncommit = 0;
1421 atomic_set(&nfsi->silly_count, 1); 1356 atomic_set(&nfsi->silly_count, 1);
1422 INIT_HLIST_HEAD(&nfsi->silly_list); 1357 INIT_HLIST_HEAD(&nfsi->silly_list);
1423 init_waitqueue_head(&nfsi->waitqueue); 1358 init_waitqueue_head(&nfsi->waitqueue);