diff options
author | Miklos Szeredi <miklos@szeredi.hu> | 2007-01-04 01:14:06 +0100 |
---|---|---|
committer | Adrian Bunk <bunk@stusta.de> | 2007-01-04 01:14:06 +0100 |
commit | 571525bb8f82493d0332aa8e31776a9fdc607b3b (patch) | |
tree | c23faa99bbd088ee1576745239b63ff51359a015 /fs/fuse/file.c | |
parent | e79366b5564af42aa2449042c75630c16edbdb4d (diff) |
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.
Adrian Bunk:
Backported to 2.6.16.
Signed-off-by: Miklos Szeredi <miklos@szeredi.hu>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
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 ce93cf9fd0f0..caebdd6d67a2 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -469,8 +469,10 @@ static int fuse_commit_write(struct file *file, struct page *page, err = -EIO; if (!err) { pos += count; - if (pos > i_size_read(inode)) + spin_lock(&fuse_lock); + if (pos > inode->i_size) i_size_write(inode, pos); + spin_unlock(&fuse_lock); if (offset == 0 && to == PAGE_CACHE_SIZE) { clear_page_dirty(page); @@ -570,8 +572,12 @@ static ssize_t fuse_direct_io(struct file *file, const char __user *buf, } fuse_put_request(fc, req); if (res > 0) { - if (write && pos > i_size_read(inode)) - i_size_write(inode, pos); + if (write) { + spin_lock(&fuse_lock); + if (pos > inode->i_size) + i_size_write(inode, pos); + spin_unlock(&fuse_lock); + } *ppos = pos; } fuse_invalidate_attr(inode); |