aboutsummaryrefslogtreecommitdiffstats
path: root/fs/fuse
diff options
context:
space:
mode:
authorMiklos Szeredi <miklos@szeredi.hu>2006-10-17 03:10:06 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2006-10-17 11:18:45 -0400
commit9ffbb9162312fd8113037cb3d94f787f06bbfa9a (patch)
treea8194bb542dcda56271b44d7de23f2a72ecac900 /fs/fuse
parent48d1a7ea6373337985f27dc1c707649469df5827 (diff)
[PATCH] fuse: fix hang on SMP
Fuse didn't always call i_size_write() with i_mutex held which caused rare hangs on SMP/32bit. This bug has been present since fuse-2.2, well before being merged into mainline. The simplest solution is to protect i_size_write() with the per-connection spinlock. Using i_mutex for this purpose would require some restructuring of the code and I'm not even sure it's always safe to acquire i_mutex in all places i_size needs to be set. Since most of vmtruncate is already duplicated for other reasons, duplicate the remaining part as well, making all i_size_write() calls internal to fuse. Using i_size_write() was unnecessary in fuse_init_inode(), since this function is only called on a newly created locked inode. Reported by a few people over the years, but special thanks to Dana Henriksen who was persistent enough in helping me debug it. Signed-off-by: Miklos Szeredi <miklos@szeredi.hu> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'fs/fuse')
-rw-r--r--fs/fuse/dir.c30
-rw-r--r--fs/fuse/file.c12
-rw-r--r--fs/fuse/inode.c5
3 files changed, 34 insertions, 13 deletions
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index 8605155db171..a8f65c11aa2c 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -935,14 +935,30 @@ static void iattr_to_fattr(struct iattr *iattr, struct fuse_setattr_in *arg)
935 } 935 }
936} 936}
937 937
938static void fuse_vmtruncate(struct inode *inode, loff_t offset)
939{
940 struct fuse_conn *fc = get_fuse_conn(inode);
941 int need_trunc;
942
943 spin_lock(&fc->lock);
944 need_trunc = inode->i_size > offset;
945 i_size_write(inode, offset);
946 spin_unlock(&fc->lock);
947
948 if (need_trunc) {
949 struct address_space *mapping = inode->i_mapping;
950 unmap_mapping_range(mapping, offset + PAGE_SIZE - 1, 0, 1);
951 truncate_inode_pages(mapping, offset);
952 }
953}
954
938/* 955/*
939 * Set attributes, and at the same time refresh them. 956 * Set attributes, and at the same time refresh them.
940 * 957 *
941 * Truncation is slightly complicated, because the 'truncate' request 958 * Truncation is slightly complicated, because the 'truncate' request
942 * may fail, in which case we don't want to touch the mapping. 959 * may fail, in which case we don't want to touch the mapping.
943 * vmtruncate() doesn't allow for this case. So do the rlimit 960 * vmtruncate() doesn't allow for this case, so do the rlimit checking
944 * checking by hand and call vmtruncate() only after the file has 961 * and the actual truncation by hand.
945 * actually been truncated.
946 */ 962 */
947static int fuse_setattr(struct dentry *entry, struct iattr *attr) 963static int fuse_setattr(struct dentry *entry, struct iattr *attr)
948{ 964{
@@ -993,12 +1009,8 @@ static int fuse_setattr(struct dentry *entry, struct iattr *attr)
993 make_bad_inode(inode); 1009 make_bad_inode(inode);
994 err = -EIO; 1010 err = -EIO;
995 } else { 1011 } else {
996 if (is_truncate) { 1012 if (is_truncate)
997 loff_t origsize = i_size_read(inode); 1013 fuse_vmtruncate(inode, outarg.attr.size);
998 i_size_write(inode, outarg.attr.size);
999 if (origsize > outarg.attr.size)
1000 vmtruncate(inode, outarg.attr.size);
1001 }
1002 fuse_change_attributes(inode, &outarg.attr); 1014 fuse_change_attributes(inode, &outarg.attr);
1003 fi->i_time = time_to_jiffies(outarg.attr_valid, 1015 fi->i_time = time_to_jiffies(outarg.attr_valid,
1004 outarg.attr_valid_nsec); 1016 outarg.attr_valid_nsec);
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 183626868eea..2bb5ace3882d 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -481,8 +481,10 @@ static int fuse_commit_write(struct file *file, struct page *page,
481 err = -EIO; 481 err = -EIO;
482 if (!err) { 482 if (!err) {
483 pos += count; 483 pos += count;
484 if (pos > i_size_read(inode)) 484 spin_lock(&fc->lock);
485 if (pos > inode->i_size)
485 i_size_write(inode, pos); 486 i_size_write(inode, pos);
487 spin_unlock(&fc->lock);
486 488
487 if (offset == 0 && to == PAGE_CACHE_SIZE) { 489 if (offset == 0 && to == PAGE_CACHE_SIZE) {
488 clear_page_dirty(page); 490 clear_page_dirty(page);
@@ -586,8 +588,12 @@ static ssize_t fuse_direct_io(struct file *file, const char __user *buf,
586 } 588 }
587 fuse_put_request(fc, req); 589 fuse_put_request(fc, req);
588 if (res > 0) { 590 if (res > 0) {
589 if (write && pos > i_size_read(inode)) 591 if (write) {
590 i_size_write(inode, pos); 592 spin_lock(&fc->lock);
593 if (pos > inode->i_size)
594 i_size_write(inode, pos);
595 spin_unlock(&fc->lock);
596 }
591 *ppos = pos; 597 *ppos = pos;
592 } 598 }
593 fuse_invalidate_attr(inode); 599 fuse_invalidate_attr(inode);
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 7d0a9aee01f2..8e106163aaed 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -109,6 +109,7 @@ static int fuse_remount_fs(struct super_block *sb, int *flags, char *data)
109 109
110void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr) 110void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr)
111{ 111{
112 struct fuse_conn *fc = get_fuse_conn(inode);
112 if (S_ISREG(inode->i_mode) && i_size_read(inode) != attr->size) 113 if (S_ISREG(inode->i_mode) && i_size_read(inode) != attr->size)
113 invalidate_inode_pages(inode->i_mapping); 114 invalidate_inode_pages(inode->i_mapping);
114 115
@@ -117,7 +118,9 @@ void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr)
117 inode->i_nlink = attr->nlink; 118 inode->i_nlink = attr->nlink;
118 inode->i_uid = attr->uid; 119 inode->i_uid = attr->uid;
119 inode->i_gid = attr->gid; 120 inode->i_gid = attr->gid;
121 spin_lock(&fc->lock);
120 i_size_write(inode, attr->size); 122 i_size_write(inode, attr->size);
123 spin_unlock(&fc->lock);
121 inode->i_blocks = attr->blocks; 124 inode->i_blocks = attr->blocks;
122 inode->i_atime.tv_sec = attr->atime; 125 inode->i_atime.tv_sec = attr->atime;
123 inode->i_atime.tv_nsec = attr->atimensec; 126 inode->i_atime.tv_nsec = attr->atimensec;
@@ -130,7 +133,7 @@ void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr)
130static void fuse_init_inode(struct inode *inode, struct fuse_attr *attr) 133static void fuse_init_inode(struct inode *inode, struct fuse_attr *attr)
131{ 134{
132 inode->i_mode = attr->mode & S_IFMT; 135 inode->i_mode = attr->mode & S_IFMT;
133 i_size_write(inode, attr->size); 136 inode->i_size = attr->size;
134 if (S_ISREG(inode->i_mode)) { 137 if (S_ISREG(inode->i_mode)) {
135 fuse_init_common(inode); 138 fuse_init_common(inode);
136 fuse_init_file_inode(inode); 139 fuse_init_file_inode(inode);