diff options
author | Miklos Szeredi <miklos@szeredi.hu> | 2006-10-17 03:10:06 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-10-17 11:18:45 -0400 |
commit | 9ffbb9162312fd8113037cb3d94f787f06bbfa9a (patch) | |
tree | a8194bb542dcda56271b44d7de23f2a72ecac900 /fs/fuse/file.c | |
parent | 48d1a7ea6373337985f27dc1c707649469df5827 (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/file.c')
-rw-r--r-- | fs/fuse/file.c | 12 |
1 files changed, 9 insertions, 3 deletions
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); |