diff options
Diffstat (limited to 'fs/btrfs/file.c')
-rw-r--r-- | fs/btrfs/file.c | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index c800d58f3013..7084140d5940 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c | |||
@@ -186,6 +186,7 @@ int btrfs_drop_extent_cache(struct inode *inode, u64 start, u64 end, | |||
186 | split = alloc_extent_map(GFP_NOFS); | 186 | split = alloc_extent_map(GFP_NOFS); |
187 | if (!split2) | 187 | if (!split2) |
188 | split2 = alloc_extent_map(GFP_NOFS); | 188 | split2 = alloc_extent_map(GFP_NOFS); |
189 | BUG_ON(!split || !split2); | ||
189 | 190 | ||
190 | write_lock(&em_tree->lock); | 191 | write_lock(&em_tree->lock); |
191 | em = lookup_extent_mapping(em_tree, start, len); | 192 | em = lookup_extent_mapping(em_tree, start, len); |
@@ -793,8 +794,12 @@ again: | |||
793 | for (i = 0; i < num_pages; i++) { | 794 | for (i = 0; i < num_pages; i++) { |
794 | pages[i] = grab_cache_page(inode->i_mapping, index + i); | 795 | pages[i] = grab_cache_page(inode->i_mapping, index + i); |
795 | if (!pages[i]) { | 796 | if (!pages[i]) { |
796 | err = -ENOMEM; | 797 | int c; |
797 | BUG_ON(1); | 798 | for (c = i - 1; c >= 0; c--) { |
799 | unlock_page(pages[c]); | ||
800 | page_cache_release(pages[c]); | ||
801 | } | ||
802 | return -ENOMEM; | ||
798 | } | 803 | } |
799 | wait_on_page_writeback(pages[i]); | 804 | wait_on_page_writeback(pages[i]); |
800 | } | 805 | } |
@@ -946,6 +951,10 @@ static ssize_t btrfs_file_aio_write(struct kiocb *iocb, | |||
946 | PAGE_CACHE_SIZE, PAGE_CACHE_SIZE / | 951 | PAGE_CACHE_SIZE, PAGE_CACHE_SIZE / |
947 | (sizeof(struct page *))); | 952 | (sizeof(struct page *))); |
948 | pages = kmalloc(nrptrs * sizeof(struct page *), GFP_KERNEL); | 953 | pages = kmalloc(nrptrs * sizeof(struct page *), GFP_KERNEL); |
954 | if (!pages) { | ||
955 | ret = -ENOMEM; | ||
956 | goto out; | ||
957 | } | ||
949 | 958 | ||
950 | /* generic_write_checks can change our pos */ | 959 | /* generic_write_checks can change our pos */ |
951 | start_pos = pos; | 960 | start_pos = pos; |
@@ -984,8 +993,8 @@ static ssize_t btrfs_file_aio_write(struct kiocb *iocb, | |||
984 | size_t write_bytes = min(iov_iter_count(&i), | 993 | size_t write_bytes = min(iov_iter_count(&i), |
985 | nrptrs * (size_t)PAGE_CACHE_SIZE - | 994 | nrptrs * (size_t)PAGE_CACHE_SIZE - |
986 | offset); | 995 | offset); |
987 | size_t num_pages = (write_bytes + PAGE_CACHE_SIZE - 1) >> | 996 | size_t num_pages = (write_bytes + offset + |
988 | PAGE_CACHE_SHIFT; | 997 | PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; |
989 | 998 | ||
990 | WARN_ON(num_pages > nrptrs); | 999 | WARN_ON(num_pages > nrptrs); |
991 | memset(pages, 0, sizeof(struct page *) * nrptrs); | 1000 | memset(pages, 0, sizeof(struct page *) * nrptrs); |
@@ -1015,8 +1024,8 @@ static ssize_t btrfs_file_aio_write(struct kiocb *iocb, | |||
1015 | 1024 | ||
1016 | copied = btrfs_copy_from_user(pos, num_pages, | 1025 | copied = btrfs_copy_from_user(pos, num_pages, |
1017 | write_bytes, pages, &i); | 1026 | write_bytes, pages, &i); |
1018 | dirty_pages = (copied + PAGE_CACHE_SIZE - 1) >> | 1027 | dirty_pages = (copied + offset + PAGE_CACHE_SIZE - 1) >> |
1019 | PAGE_CACHE_SHIFT; | 1028 | PAGE_CACHE_SHIFT; |
1020 | 1029 | ||
1021 | if (num_pages > dirty_pages) { | 1030 | if (num_pages > dirty_pages) { |
1022 | if (copied > 0) | 1031 | if (copied > 0) |