aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/btrfs/extent_io.c52
-rw-r--r--fs/btrfs/extent_io.h18
-rw-r--r--fs/btrfs/inode.c26
3 files changed, 34 insertions, 62 deletions
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 5bbdb243bb6f..789d0b23048f 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -254,14 +254,14 @@ static void merge_cb(struct extent_io_tree *tree, struct extent_state *new,
254 * 254 *
255 * This should be called with the tree lock held. 255 * This should be called with the tree lock held.
256 */ 256 */
257static int merge_state(struct extent_io_tree *tree, 257static void merge_state(struct extent_io_tree *tree,
258 struct extent_state *state) 258 struct extent_state *state)
259{ 259{
260 struct extent_state *other; 260 struct extent_state *other;
261 struct rb_node *other_node; 261 struct rb_node *other_node;
262 262
263 if (state->state & (EXTENT_IOBITS | EXTENT_BOUNDARY)) 263 if (state->state & (EXTENT_IOBITS | EXTENT_BOUNDARY))
264 return 0; 264 return;
265 265
266 other_node = rb_prev(&state->rb_node); 266 other_node = rb_prev(&state->rb_node);
267 if (other_node) { 267 if (other_node) {
@@ -287,19 +287,13 @@ static int merge_state(struct extent_io_tree *tree,
287 free_extent_state(other); 287 free_extent_state(other);
288 } 288 }
289 } 289 }
290
291 return 0;
292} 290}
293 291
294static int set_state_cb(struct extent_io_tree *tree, 292static void set_state_cb(struct extent_io_tree *tree,
295 struct extent_state *state, int *bits) 293 struct extent_state *state, int *bits)
296{ 294{
297 if (tree->ops && tree->ops->set_bit_hook) { 295 if (tree->ops && tree->ops->set_bit_hook)
298 return tree->ops->set_bit_hook(tree->mapping->host, 296 tree->ops->set_bit_hook(tree->mapping->host, state, bits);
299 state, bits);
300 }
301
302 return 0;
303} 297}
304 298
305static void clear_state_cb(struct extent_io_tree *tree, 299static void clear_state_cb(struct extent_io_tree *tree,
@@ -325,7 +319,6 @@ static int insert_state(struct extent_io_tree *tree,
325{ 319{
326 struct rb_node *node; 320 struct rb_node *node;
327 int bits_to_set = *bits & ~EXTENT_CTLBITS; 321 int bits_to_set = *bits & ~EXTENT_CTLBITS;
328 int ret;
329 322
330 if (end < start) { 323 if (end < start) {
331 printk(KERN_ERR "btrfs end < start %llu %llu\n", 324 printk(KERN_ERR "btrfs end < start %llu %llu\n",
@@ -335,9 +328,7 @@ static int insert_state(struct extent_io_tree *tree,
335 } 328 }
336 state->start = start; 329 state->start = start;
337 state->end = end; 330 state->end = end;
338 ret = set_state_cb(tree, state, bits); 331 set_state_cb(tree, state, bits);
339 if (ret)
340 return ret;
341 332
342 if (bits_to_set & EXTENT_DIRTY) 333 if (bits_to_set & EXTENT_DIRTY)
343 tree->dirty_bytes += end - start + 1; 334 tree->dirty_bytes += end - start + 1;
@@ -357,13 +348,11 @@ static int insert_state(struct extent_io_tree *tree,
357 return 0; 348 return 0;
358} 349}
359 350
360static int split_cb(struct extent_io_tree *tree, struct extent_state *orig, 351static void split_cb(struct extent_io_tree *tree, struct extent_state *orig,
361 u64 split) 352 u64 split)
362{ 353{
363 if (tree->ops && tree->ops->split_extent_hook) 354 if (tree->ops && tree->ops->split_extent_hook)
364 return tree->ops->split_extent_hook(tree->mapping->host, 355 tree->ops->split_extent_hook(tree->mapping->host, orig, split);
365 orig, split);
366 return 0;
367} 356}
368 357
369/* 358/*
@@ -670,23 +659,18 @@ out:
670 return 0; 659 return 0;
671} 660}
672 661
673static int set_state_bits(struct extent_io_tree *tree, 662static void set_state_bits(struct extent_io_tree *tree,
674 struct extent_state *state, 663 struct extent_state *state,
675 int *bits) 664 int *bits)
676{ 665{
677 int ret;
678 int bits_to_set = *bits & ~EXTENT_CTLBITS; 666 int bits_to_set = *bits & ~EXTENT_CTLBITS;
679 667
680 ret = set_state_cb(tree, state, bits); 668 set_state_cb(tree, state, bits);
681 if (ret)
682 return ret;
683 if ((bits_to_set & EXTENT_DIRTY) && !(state->state & EXTENT_DIRTY)) { 669 if ((bits_to_set & EXTENT_DIRTY) && !(state->state & EXTENT_DIRTY)) {
684 u64 range = state->end - state->start + 1; 670 u64 range = state->end - state->start + 1;
685 tree->dirty_bytes += range; 671 tree->dirty_bytes += range;
686 } 672 }
687 state->state |= bits_to_set; 673 state->state |= bits_to_set;
688
689 return 0;
690} 674}
691 675
692static void cache_state(struct extent_state *state, 676static void cache_state(struct extent_state *state,
@@ -779,9 +763,7 @@ hit_next:
779 goto out; 763 goto out;
780 } 764 }
781 765
782 err = set_state_bits(tree, state, &bits); 766 set_state_bits(tree, state, &bits);
783 if (err)
784 goto out;
785 767
786 cache_state(state, cached_state); 768 cache_state(state, cached_state);
787 merge_state(tree, state); 769 merge_state(tree, state);
@@ -830,9 +812,7 @@ hit_next:
830 if (err) 812 if (err)
831 goto out; 813 goto out;
832 if (state->end <= end) { 814 if (state->end <= end) {
833 err = set_state_bits(tree, state, &bits); 815 set_state_bits(tree, state, &bits);
834 if (err)
835 goto out;
836 cache_state(state, cached_state); 816 cache_state(state, cached_state);
837 merge_state(tree, state); 817 merge_state(tree, state);
838 if (last_end == (u64)-1) 818 if (last_end == (u64)-1)
@@ -893,11 +873,7 @@ hit_next:
893 err = split_state(tree, state, prealloc, end + 1); 873 err = split_state(tree, state, prealloc, end + 1);
894 BUG_ON(err == -EEXIST); 874 BUG_ON(err == -EEXIST);
895 875
896 err = set_state_bits(tree, prealloc, &bits); 876 set_state_bits(tree, prealloc, &bits);
897 if (err) {
898 prealloc = NULL;
899 goto out;
900 }
901 cache_state(prealloc, cached_state); 877 cache_state(prealloc, cached_state);
902 merge_state(tree, prealloc); 878 merge_state(tree, prealloc);
903 prealloc = NULL; 879 prealloc = NULL;
diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h
index 21a7ca9e7282..d6871dc7524f 100644
--- a/fs/btrfs/extent_io.h
+++ b/fs/btrfs/extent_io.h
@@ -76,15 +76,15 @@ struct extent_io_ops {
76 struct extent_state *state); 76 struct extent_state *state);
77 int (*writepage_end_io_hook)(struct page *page, u64 start, u64 end, 77 int (*writepage_end_io_hook)(struct page *page, u64 start, u64 end,
78 struct extent_state *state, int uptodate); 78 struct extent_state *state, int uptodate);
79 int (*set_bit_hook)(struct inode *inode, struct extent_state *state, 79 void (*set_bit_hook)(struct inode *inode, struct extent_state *state,
80 int *bits); 80 int *bits);
81 int (*clear_bit_hook)(struct inode *inode, struct extent_state *state, 81 void (*clear_bit_hook)(struct inode *inode, struct extent_state *state,
82 int *bits); 82 int *bits);
83 int (*merge_extent_hook)(struct inode *inode, 83 void (*merge_extent_hook)(struct inode *inode,
84 struct extent_state *new, 84 struct extent_state *new,
85 struct extent_state *other); 85 struct extent_state *other);
86 int (*split_extent_hook)(struct inode *inode, 86 void (*split_extent_hook)(struct inode *inode,
87 struct extent_state *orig, u64 split); 87 struct extent_state *orig, u64 split);
88 int (*write_cache_pages_lock_hook)(struct page *page); 88 int (*write_cache_pages_lock_hook)(struct page *page);
89}; 89};
90 90
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 69e448eddf09..34195f9fc6bb 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -1283,17 +1283,16 @@ static int run_delalloc_range(struct inode *inode, struct page *locked_page,
1283 return ret; 1283 return ret;
1284} 1284}
1285 1285
1286static int btrfs_split_extent_hook(struct inode *inode, 1286static void btrfs_split_extent_hook(struct inode *inode,
1287 struct extent_state *orig, u64 split) 1287 struct extent_state *orig, u64 split)
1288{ 1288{
1289 /* not delalloc, ignore it */ 1289 /* not delalloc, ignore it */
1290 if (!(orig->state & EXTENT_DELALLOC)) 1290 if (!(orig->state & EXTENT_DELALLOC))
1291 return 0; 1291 return;
1292 1292
1293 spin_lock(&BTRFS_I(inode)->lock); 1293 spin_lock(&BTRFS_I(inode)->lock);
1294 BTRFS_I(inode)->outstanding_extents++; 1294 BTRFS_I(inode)->outstanding_extents++;
1295 spin_unlock(&BTRFS_I(inode)->lock); 1295 spin_unlock(&BTRFS_I(inode)->lock);
1296 return 0;
1297} 1296}
1298 1297
1299/* 1298/*
@@ -1302,18 +1301,17 @@ static int btrfs_split_extent_hook(struct inode *inode,
1302 * extents, such as when we are doing sequential writes, so we can properly 1301 * extents, such as when we are doing sequential writes, so we can properly
1303 * account for the metadata space we'll need. 1302 * account for the metadata space we'll need.
1304 */ 1303 */
1305static int btrfs_merge_extent_hook(struct inode *inode, 1304static void btrfs_merge_extent_hook(struct inode *inode,
1306 struct extent_state *new, 1305 struct extent_state *new,
1307 struct extent_state *other) 1306 struct extent_state *other)
1308{ 1307{
1309 /* not delalloc, ignore it */ 1308 /* not delalloc, ignore it */
1310 if (!(other->state & EXTENT_DELALLOC)) 1309 if (!(other->state & EXTENT_DELALLOC))
1311 return 0; 1310 return;
1312 1311
1313 spin_lock(&BTRFS_I(inode)->lock); 1312 spin_lock(&BTRFS_I(inode)->lock);
1314 BTRFS_I(inode)->outstanding_extents--; 1313 BTRFS_I(inode)->outstanding_extents--;
1315 spin_unlock(&BTRFS_I(inode)->lock); 1314 spin_unlock(&BTRFS_I(inode)->lock);
1316 return 0;
1317} 1315}
1318 1316
1319/* 1317/*
@@ -1321,8 +1319,8 @@ static int btrfs_merge_extent_hook(struct inode *inode,
1321 * bytes in this file, and to maintain the list of inodes that 1319 * bytes in this file, and to maintain the list of inodes that
1322 * have pending delalloc work to be done. 1320 * have pending delalloc work to be done.
1323 */ 1321 */
1324static int btrfs_set_bit_hook(struct inode *inode, 1322static void btrfs_set_bit_hook(struct inode *inode,
1325 struct extent_state *state, int *bits) 1323 struct extent_state *state, int *bits)
1326{ 1324{
1327 1325
1328 /* 1326 /*
@@ -1352,14 +1350,13 @@ static int btrfs_set_bit_hook(struct inode *inode,
1352 } 1350 }
1353 spin_unlock(&root->fs_info->delalloc_lock); 1351 spin_unlock(&root->fs_info->delalloc_lock);
1354 } 1352 }
1355 return 0;
1356} 1353}
1357 1354
1358/* 1355/*
1359 * extent_io.c clear_bit_hook, see set_bit_hook for why 1356 * extent_io.c clear_bit_hook, see set_bit_hook for why
1360 */ 1357 */
1361static int btrfs_clear_bit_hook(struct inode *inode, 1358static void btrfs_clear_bit_hook(struct inode *inode,
1362 struct extent_state *state, int *bits) 1359 struct extent_state *state, int *bits)
1363{ 1360{
1364 /* 1361 /*
1365 * set_bit and clear bit hooks normally require _irqsave/restore 1362 * set_bit and clear bit hooks normally require _irqsave/restore
@@ -1396,7 +1393,6 @@ static int btrfs_clear_bit_hook(struct inode *inode,
1396 } 1393 }
1397 spin_unlock(&root->fs_info->delalloc_lock); 1394 spin_unlock(&root->fs_info->delalloc_lock);
1398 } 1395 }
1399 return 0;
1400} 1396}
1401 1397
1402/* 1398/*