diff options
author | Jeff Mahoney <jeffm@suse.com> | 2014-05-21 13:28:07 -0400 |
---|---|---|
committer | Jan Kara <jack@suse.cz> | 2014-05-21 16:36:56 -0400 |
commit | 22e7478ddbcb670e33fab72d0bbe7c394c3a2c84 (patch) | |
tree | 89c8bdbe58995dc2c0ae3d7a11b9050db2c2de54 | |
parent | 770901cc1352b46f0e2de08260ec40c0364d7723 (diff) |
reiserfs: call truncate_setsize under tailpack mutex
Prior to commit 0e4f6a791b1e (Fix reiserfs_file_release()), reiserfs
truncates serialized on i_mutex. They mostly still do, with the exception
of reiserfs_file_release. That blocks out other writers via the tailpack
mutex and the inode openers counter adjusted in reiserfs_file_open.
However, NFS will call reiserfs_setattr without having called ->open, so
we end up with a race when nfs is calling ->setattr while another
process is releasing the file. Ultimately, it triggers the
BUG_ON(inode->i_size != new_file_size) check in maybe_indirect_to_direct.
The solution is to pull the lock into reiserfs_setattr to encompass the
truncate_setsize call as well.
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Jan Kara <jack@suse.cz>
-rw-r--r-- | fs/reiserfs/inode.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/fs/reiserfs/inode.c b/fs/reiserfs/inode.c index 874c8b329cfe..e3ca04894919 100644 --- a/fs/reiserfs/inode.c +++ b/fs/reiserfs/inode.c | |||
@@ -3422,8 +3422,14 @@ int reiserfs_setattr(struct dentry *dentry, struct iattr *attr) | |||
3422 | attr->ia_size != i_size_read(inode)) { | 3422 | attr->ia_size != i_size_read(inode)) { |
3423 | error = inode_newsize_ok(inode, attr->ia_size); | 3423 | error = inode_newsize_ok(inode, attr->ia_size); |
3424 | if (!error) { | 3424 | if (!error) { |
3425 | /* | ||
3426 | * Could race against reiserfs_file_release | ||
3427 | * if called from NFS, so take tailpack mutex. | ||
3428 | */ | ||
3429 | mutex_lock(&REISERFS_I(inode)->tailpack); | ||
3425 | truncate_setsize(inode, attr->ia_size); | 3430 | truncate_setsize(inode, attr->ia_size); |
3426 | reiserfs_vfs_truncate_file(inode); | 3431 | reiserfs_truncate_file(inode, 1); |
3432 | mutex_unlock(&REISERFS_I(inode)->tailpack); | ||
3427 | } | 3433 | } |
3428 | } | 3434 | } |
3429 | 3435 | ||