diff options
author | Yan, Zheng <zheng.yan@oracle.com> | 2010-05-16 10:48:47 -0400 |
---|---|---|
committer | Chris Mason <chris.mason@oracle.com> | 2010-05-25 10:34:51 -0400 |
commit | 0ca1f7ceb1991099ed5273885ebcf4323948c72e (patch) | |
tree | 10758d6a55c529aced177da3f6bf45cf26361913 /fs/btrfs/file.c | |
parent | a22285a6a32390195235171b89d157ed1a1fe932 (diff) |
Btrfs: Update metadata reservation for delayed allocation
Introduce metadata reservation context for delayed allocation
and update various related functions.
This patch also introduces EXTENT_FIRST_DELALLOC control bit for
set/clear_extent_bit. It tells set/clear_bit_hook whether they
are processing the first extent_state with EXTENT_DELALLOC bit
set. This change is important if set/clear_extent_bit involves
multiple extent_state.
Signed-off-by: Yan Zheng <zheng.yan@oracle.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/file.c')
-rw-r--r-- | fs/btrfs/file.c | 27 |
1 files changed, 6 insertions, 21 deletions
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 41e09e24e295..6d8f817eadb5 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c | |||
@@ -852,13 +852,6 @@ static ssize_t btrfs_file_write(struct file *file, const char __user *buf, | |||
852 | 852 | ||
853 | vfs_check_frozen(inode->i_sb, SB_FREEZE_WRITE); | 853 | vfs_check_frozen(inode->i_sb, SB_FREEZE_WRITE); |
854 | 854 | ||
855 | /* do the reserve before the mutex lock in case we have to do some | ||
856 | * flushing. We wouldn't deadlock, but this is more polite. | ||
857 | */ | ||
858 | err = btrfs_reserve_metadata_for_delalloc(root, inode, 1); | ||
859 | if (err) | ||
860 | goto out_nolock; | ||
861 | |||
862 | mutex_lock(&inode->i_mutex); | 855 | mutex_lock(&inode->i_mutex); |
863 | 856 | ||
864 | current->backing_dev_info = inode->i_mapping->backing_dev_info; | 857 | current->backing_dev_info = inode->i_mapping->backing_dev_info; |
@@ -921,7 +914,7 @@ static ssize_t btrfs_file_write(struct file *file, const char __user *buf, | |||
921 | WARN_ON(num_pages > nrptrs); | 914 | WARN_ON(num_pages > nrptrs); |
922 | memset(pages, 0, sizeof(struct page *) * nrptrs); | 915 | memset(pages, 0, sizeof(struct page *) * nrptrs); |
923 | 916 | ||
924 | ret = btrfs_check_data_free_space(root, inode, write_bytes); | 917 | ret = btrfs_delalloc_reserve_space(inode, write_bytes); |
925 | if (ret) | 918 | if (ret) |
926 | goto out; | 919 | goto out; |
927 | 920 | ||
@@ -929,26 +922,20 @@ static ssize_t btrfs_file_write(struct file *file, const char __user *buf, | |||
929 | pos, first_index, last_index, | 922 | pos, first_index, last_index, |
930 | write_bytes); | 923 | write_bytes); |
931 | if (ret) { | 924 | if (ret) { |
932 | btrfs_free_reserved_data_space(root, inode, | 925 | btrfs_delalloc_release_space(inode, write_bytes); |
933 | write_bytes); | ||
934 | goto out; | 926 | goto out; |
935 | } | 927 | } |
936 | 928 | ||
937 | ret = btrfs_copy_from_user(pos, num_pages, | 929 | ret = btrfs_copy_from_user(pos, num_pages, |
938 | write_bytes, pages, buf); | 930 | write_bytes, pages, buf); |
939 | if (ret) { | 931 | if (ret == 0) { |
940 | btrfs_free_reserved_data_space(root, inode, | 932 | dirty_and_release_pages(NULL, root, file, pages, |
941 | write_bytes); | 933 | num_pages, pos, write_bytes); |
942 | btrfs_drop_pages(pages, num_pages); | ||
943 | goto out; | ||
944 | } | 934 | } |
945 | 935 | ||
946 | ret = dirty_and_release_pages(NULL, root, file, pages, | ||
947 | num_pages, pos, write_bytes); | ||
948 | btrfs_drop_pages(pages, num_pages); | 936 | btrfs_drop_pages(pages, num_pages); |
949 | if (ret) { | 937 | if (ret) { |
950 | btrfs_free_reserved_data_space(root, inode, | 938 | btrfs_delalloc_release_space(inode, write_bytes); |
951 | write_bytes); | ||
952 | goto out; | 939 | goto out; |
953 | } | 940 | } |
954 | 941 | ||
@@ -975,9 +962,7 @@ out: | |||
975 | mutex_unlock(&inode->i_mutex); | 962 | mutex_unlock(&inode->i_mutex); |
976 | if (ret) | 963 | if (ret) |
977 | err = ret; | 964 | err = ret; |
978 | btrfs_unreserve_metadata_for_delalloc(root, inode, 1); | ||
979 | 965 | ||
980 | out_nolock: | ||
981 | kfree(pages); | 966 | kfree(pages); |
982 | if (pinned[0]) | 967 | if (pinned[0]) |
983 | page_cache_release(pinned[0]); | 968 | page_cache_release(pinned[0]); |