aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/file.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/btrfs/file.c')
-rw-r--r--fs/btrfs/file.c35
1 files changed, 8 insertions, 27 deletions
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 4b833972273a..571ad3c13b47 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -112,8 +112,6 @@ static noinline int dirty_and_release_pages(struct btrfs_trans_handle *trans,
112 int err = 0; 112 int err = 0;
113 int i; 113 int i;
114 struct inode *inode = fdentry(file)->d_inode; 114 struct inode *inode = fdentry(file)->d_inode;
115 struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree;
116 u64 hint_byte;
117 u64 num_bytes; 115 u64 num_bytes;
118 u64 start_pos; 116 u64 start_pos;
119 u64 end_of_last_block; 117 u64 end_of_last_block;
@@ -125,22 +123,6 @@ static noinline int dirty_and_release_pages(struct btrfs_trans_handle *trans,
125 root->sectorsize - 1) & ~((u64)root->sectorsize - 1); 123 root->sectorsize - 1) & ~((u64)root->sectorsize - 1);
126 124
127 end_of_last_block = start_pos + num_bytes - 1; 125 end_of_last_block = start_pos + num_bytes - 1;
128
129 lock_extent(io_tree, start_pos, end_of_last_block, GFP_NOFS);
130 trans = btrfs_join_transaction(root, 1);
131 if (!trans) {
132 err = -ENOMEM;
133 goto out_unlock;
134 }
135 btrfs_set_trans_block_group(trans, inode);
136 hint_byte = 0;
137
138 set_extent_uptodate(io_tree, start_pos, end_of_last_block, GFP_NOFS);
139
140 /* check for reserved extents on each page, we don't want
141 * to reset the delalloc bit on things that already have
142 * extents reserved.
143 */
144 btrfs_set_extent_delalloc(inode, start_pos, end_of_last_block); 126 btrfs_set_extent_delalloc(inode, start_pos, end_of_last_block);
145 for (i = 0; i < num_pages; i++) { 127 for (i = 0; i < num_pages; i++) {
146 struct page *p = pages[i]; 128 struct page *p = pages[i];
@@ -155,9 +137,6 @@ static noinline int dirty_and_release_pages(struct btrfs_trans_handle *trans,
155 * at this time. 137 * at this time.
156 */ 138 */
157 } 139 }
158 err = btrfs_end_transaction(trans, root);
159out_unlock:
160 unlock_extent(io_tree, start_pos, end_of_last_block, GFP_NOFS);
161 return err; 140 return err;
162} 141}
163 142
@@ -189,18 +168,18 @@ int btrfs_drop_extent_cache(struct inode *inode, u64 start, u64 end,
189 if (!split2) 168 if (!split2)
190 split2 = alloc_extent_map(GFP_NOFS); 169 split2 = alloc_extent_map(GFP_NOFS);
191 170
192 spin_lock(&em_tree->lock); 171 write_lock(&em_tree->lock);
193 em = lookup_extent_mapping(em_tree, start, len); 172 em = lookup_extent_mapping(em_tree, start, len);
194 if (!em) { 173 if (!em) {
195 spin_unlock(&em_tree->lock); 174 write_unlock(&em_tree->lock);
196 break; 175 break;
197 } 176 }
198 flags = em->flags; 177 flags = em->flags;
199 if (skip_pinned && test_bit(EXTENT_FLAG_PINNED, &em->flags)) { 178 if (skip_pinned && test_bit(EXTENT_FLAG_PINNED, &em->flags)) {
200 spin_unlock(&em_tree->lock);
201 if (em->start <= start && 179 if (em->start <= start &&
202 (!testend || em->start + em->len >= start + len)) { 180 (!testend || em->start + em->len >= start + len)) {
203 free_extent_map(em); 181 free_extent_map(em);
182 write_unlock(&em_tree->lock);
204 break; 183 break;
205 } 184 }
206 if (start < em->start) { 185 if (start < em->start) {
@@ -210,6 +189,7 @@ int btrfs_drop_extent_cache(struct inode *inode, u64 start, u64 end,
210 start = em->start + em->len; 189 start = em->start + em->len;
211 } 190 }
212 free_extent_map(em); 191 free_extent_map(em);
192 write_unlock(&em_tree->lock);
213 continue; 193 continue;
214 } 194 }
215 compressed = test_bit(EXTENT_FLAG_COMPRESSED, &em->flags); 195 compressed = test_bit(EXTENT_FLAG_COMPRESSED, &em->flags);
@@ -260,7 +240,7 @@ int btrfs_drop_extent_cache(struct inode *inode, u64 start, u64 end,
260 free_extent_map(split); 240 free_extent_map(split);
261 split = NULL; 241 split = NULL;
262 } 242 }
263 spin_unlock(&em_tree->lock); 243 write_unlock(&em_tree->lock);
264 244
265 /* once for us */ 245 /* once for us */
266 free_extent_map(em); 246 free_extent_map(em);
@@ -289,7 +269,7 @@ int btrfs_drop_extent_cache(struct inode *inode, u64 start, u64 end,
289noinline int btrfs_drop_extents(struct btrfs_trans_handle *trans, 269noinline int btrfs_drop_extents(struct btrfs_trans_handle *trans,
290 struct btrfs_root *root, struct inode *inode, 270 struct btrfs_root *root, struct inode *inode,
291 u64 start, u64 end, u64 locked_end, 271 u64 start, u64 end, u64 locked_end,
292 u64 inline_limit, u64 *hint_byte) 272 u64 inline_limit, u64 *hint_byte, int drop_cache)
293{ 273{
294 u64 extent_end = 0; 274 u64 extent_end = 0;
295 u64 search_start = start; 275 u64 search_start = start;
@@ -314,7 +294,8 @@ noinline int btrfs_drop_extents(struct btrfs_trans_handle *trans,
314 int ret; 294 int ret;
315 295
316 inline_limit = 0; 296 inline_limit = 0;
317 btrfs_drop_extent_cache(inode, start, end - 1, 0); 297 if (drop_cache)
298 btrfs_drop_extent_cache(inode, start, end - 1, 0);
318 299
319 path = btrfs_alloc_path(); 300 path = btrfs_alloc_path();
320 if (!path) 301 if (!path)