aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2009-10-01 12:29:10 -0400
committerChris Mason <chris.mason@oracle.com>2009-10-01 12:29:10 -0400
commitab93dbecfba72bbc04b7036343d180aaff1b61a3 (patch)
tree6bb523dcf9be0885b6fa9cb6cc9ac694ee089028 /fs/btrfs
parent35d62a942db5ae03104929fe7397835b572c4bc4 (diff)
Btrfs: take i_mutex before generic_write_checks
btrfs_file_write was incorrectly calling generic_write_checks without taking i_mutex. This lead to problems with racing around i_size when doing O_APPEND writes. The fix here is to move i_mutex higher. Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs')
-rw-r--r--fs/btrfs/file.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 1be96ba6f6bb..f155179877a6 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -920,26 +920,35 @@ static ssize_t btrfs_file_write(struct file *file, const char __user *buf,
920 start_pos = pos; 920 start_pos = pos;
921 921
922 vfs_check_frozen(inode->i_sb, SB_FREEZE_WRITE); 922 vfs_check_frozen(inode->i_sb, SB_FREEZE_WRITE);
923
924 /* do the reserve before the mutex lock in case we have to do some
925 * flushing. We wouldn't deadlock, but this is more polite.
926 */
927 err = btrfs_reserve_metadata_for_delalloc(root, inode, 1);
928 if (err)
929 goto out_nolock;
930
931 mutex_lock(&inode->i_mutex);
932
923 current->backing_dev_info = inode->i_mapping->backing_dev_info; 933 current->backing_dev_info = inode->i_mapping->backing_dev_info;
924 err = generic_write_checks(file, &pos, &count, S_ISBLK(inode->i_mode)); 934 err = generic_write_checks(file, &pos, &count, S_ISBLK(inode->i_mode));
925 if (err) 935 if (err)
926 goto out_nolock; 936 goto out;
937
927 if (count == 0) 938 if (count == 0)
928 goto out_nolock; 939 goto out;
929 940
930 err = file_remove_suid(file); 941 err = file_remove_suid(file);
931 if (err) 942 if (err)
932 goto out_nolock; 943 goto out;
933
934 err = btrfs_reserve_metadata_for_delalloc(root, inode, 1);
935 if (err)
936 goto out_nolock;
937 944
938 file_update_time(file); 945 file_update_time(file);
939 946
940 pages = kmalloc(nrptrs * sizeof(struct page *), GFP_KERNEL); 947 pages = kmalloc(nrptrs * sizeof(struct page *), GFP_KERNEL);
941 948
942 mutex_lock(&inode->i_mutex); 949 /* generic_write_checks can change our pos */
950 start_pos = pos;
951
943 BTRFS_I(inode)->sequence++; 952 BTRFS_I(inode)->sequence++;
944 first_index = pos >> PAGE_CACHE_SHIFT; 953 first_index = pos >> PAGE_CACHE_SHIFT;
945 last_index = (pos + count) >> PAGE_CACHE_SHIFT; 954 last_index = (pos + count) >> PAGE_CACHE_SHIFT;