diff options
author | Chris Mason <chris.mason@oracle.com> | 2009-10-01 12:58:13 -0400 |
---|---|---|
committer | Chris Mason <chris.mason@oracle.com> | 2009-10-01 12:58:13 -0400 |
commit | 25472b880c69c0daa485c4f80a6550437ed1149f (patch) | |
tree | d12bc091e8991513db0d2891111ba773eb5c52e2 /fs/btrfs/file.c | |
parent | 17d857be649a21ca90008c6dc425d849fa83db5c (diff) | |
parent | ab93dbecfba72bbc04b7036343d180aaff1b61a3 (diff) |
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-unstable into for-linus
Diffstat (limited to 'fs/btrfs/file.c')
-rw-r--r-- | fs/btrfs/file.c | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index a3492a3ad96b..7351bdbca26f 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c | |||
@@ -123,7 +123,10 @@ static noinline int dirty_and_release_pages(struct btrfs_trans_handle *trans, | |||
123 | root->sectorsize - 1) & ~((u64)root->sectorsize - 1); | 123 | root->sectorsize - 1) & ~((u64)root->sectorsize - 1); |
124 | 124 | ||
125 | end_of_last_block = start_pos + num_bytes - 1; | 125 | end_of_last_block = start_pos + num_bytes - 1; |
126 | btrfs_set_extent_delalloc(inode, start_pos, end_of_last_block); | 126 | err = btrfs_set_extent_delalloc(inode, start_pos, end_of_last_block); |
127 | if (err) | ||
128 | return err; | ||
129 | |||
127 | for (i = 0; i < num_pages; i++) { | 130 | for (i = 0; i < num_pages; i++) { |
128 | struct page *p = pages[i]; | 131 | struct page *p = pages[i]; |
129 | SetPageUptodate(p); | 132 | SetPageUptodate(p); |
@@ -917,21 +920,35 @@ static ssize_t btrfs_file_write(struct file *file, const char __user *buf, | |||
917 | start_pos = pos; | 920 | start_pos = pos; |
918 | 921 | ||
919 | 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 | |||
920 | current->backing_dev_info = inode->i_mapping->backing_dev_info; | 933 | current->backing_dev_info = inode->i_mapping->backing_dev_info; |
921 | 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)); |
922 | if (err) | 935 | if (err) |
923 | goto out_nolock; | 936 | goto out; |
937 | |||
924 | if (count == 0) | 938 | if (count == 0) |
925 | goto out_nolock; | 939 | goto out; |
926 | 940 | ||
927 | err = file_remove_suid(file); | 941 | err = file_remove_suid(file); |
928 | if (err) | 942 | if (err) |
929 | goto out_nolock; | 943 | goto out; |
944 | |||
930 | file_update_time(file); | 945 | file_update_time(file); |
931 | 946 | ||
932 | pages = kmalloc(nrptrs * sizeof(struct page *), GFP_KERNEL); | 947 | pages = kmalloc(nrptrs * sizeof(struct page *), GFP_KERNEL); |
933 | 948 | ||
934 | mutex_lock(&inode->i_mutex); | 949 | /* generic_write_checks can change our pos */ |
950 | start_pos = pos; | ||
951 | |||
935 | BTRFS_I(inode)->sequence++; | 952 | BTRFS_I(inode)->sequence++; |
936 | first_index = pos >> PAGE_CACHE_SHIFT; | 953 | first_index = pos >> PAGE_CACHE_SHIFT; |
937 | last_index = (pos + count) >> PAGE_CACHE_SHIFT; | 954 | last_index = (pos + count) >> PAGE_CACHE_SHIFT; |
@@ -1028,6 +1045,7 @@ out: | |||
1028 | mutex_unlock(&inode->i_mutex); | 1045 | mutex_unlock(&inode->i_mutex); |
1029 | if (ret) | 1046 | if (ret) |
1030 | err = ret; | 1047 | err = ret; |
1048 | btrfs_unreserve_metadata_for_delalloc(root, inode, 1); | ||
1031 | 1049 | ||
1032 | out_nolock: | 1050 | out_nolock: |
1033 | kfree(pages); | 1051 | kfree(pages); |