diff options
Diffstat (limited to 'fs/btrfs/extent_io.c')
| -rw-r--r-- | fs/btrfs/extent_io.c | 189 |
1 files changed, 99 insertions, 90 deletions
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 96577e8bf9fd..d74e6af9b53a 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c | |||
| @@ -2,7 +2,6 @@ | |||
| 2 | #include <linux/slab.h> | 2 | #include <linux/slab.h> |
| 3 | #include <linux/bio.h> | 3 | #include <linux/bio.h> |
| 4 | #include <linux/mm.h> | 4 | #include <linux/mm.h> |
| 5 | #include <linux/gfp.h> | ||
| 6 | #include <linux/pagemap.h> | 5 | #include <linux/pagemap.h> |
| 7 | #include <linux/page-flags.h> | 6 | #include <linux/page-flags.h> |
| 8 | #include <linux/module.h> | 7 | #include <linux/module.h> |
| @@ -104,8 +103,8 @@ void extent_io_exit(void) | |||
| 104 | void extent_io_tree_init(struct extent_io_tree *tree, | 103 | void extent_io_tree_init(struct extent_io_tree *tree, |
| 105 | struct address_space *mapping, gfp_t mask) | 104 | struct address_space *mapping, gfp_t mask) |
| 106 | { | 105 | { |
| 107 | tree->state.rb_node = NULL; | 106 | tree->state = RB_ROOT; |
| 108 | tree->buffer.rb_node = NULL; | 107 | tree->buffer = RB_ROOT; |
| 109 | tree->ops = NULL; | 108 | tree->ops = NULL; |
| 110 | tree->dirty_bytes = 0; | 109 | tree->dirty_bytes = 0; |
| 111 | spin_lock_init(&tree->lock); | 110 | spin_lock_init(&tree->lock); |
| @@ -136,7 +135,7 @@ static struct extent_state *alloc_extent_state(gfp_t mask) | |||
| 136 | return state; | 135 | return state; |
| 137 | } | 136 | } |
| 138 | 137 | ||
| 139 | static void free_extent_state(struct extent_state *state) | 138 | void free_extent_state(struct extent_state *state) |
| 140 | { | 139 | { |
| 141 | if (!state) | 140 | if (!state) |
| 142 | return; | 141 | return; |
| @@ -336,21 +335,18 @@ static int merge_state(struct extent_io_tree *tree, | |||
| 336 | } | 335 | } |
| 337 | 336 | ||
| 338 | static int set_state_cb(struct extent_io_tree *tree, | 337 | static int set_state_cb(struct extent_io_tree *tree, |
| 339 | struct extent_state *state, | 338 | struct extent_state *state, int *bits) |
| 340 | unsigned long bits) | ||
| 341 | { | 339 | { |
| 342 | if (tree->ops && tree->ops->set_bit_hook) { | 340 | if (tree->ops && tree->ops->set_bit_hook) { |
| 343 | return tree->ops->set_bit_hook(tree->mapping->host, | 341 | return tree->ops->set_bit_hook(tree->mapping->host, |
| 344 | state->start, state->end, | 342 | state, bits); |
| 345 | state->state, bits); | ||
| 346 | } | 343 | } |
| 347 | 344 | ||
| 348 | return 0; | 345 | return 0; |
| 349 | } | 346 | } |
| 350 | 347 | ||
| 351 | static void clear_state_cb(struct extent_io_tree *tree, | 348 | static void clear_state_cb(struct extent_io_tree *tree, |
| 352 | struct extent_state *state, | 349 | struct extent_state *state, int *bits) |
| 353 | unsigned long bits) | ||
| 354 | { | 350 | { |
| 355 | if (tree->ops && tree->ops->clear_bit_hook) | 351 | if (tree->ops && tree->ops->clear_bit_hook) |
| 356 | tree->ops->clear_bit_hook(tree->mapping->host, state, bits); | 352 | tree->ops->clear_bit_hook(tree->mapping->host, state, bits); |
| @@ -368,9 +364,10 @@ static void clear_state_cb(struct extent_io_tree *tree, | |||
| 368 | */ | 364 | */ |
| 369 | static int insert_state(struct extent_io_tree *tree, | 365 | static int insert_state(struct extent_io_tree *tree, |
| 370 | struct extent_state *state, u64 start, u64 end, | 366 | struct extent_state *state, u64 start, u64 end, |
| 371 | int bits) | 367 | int *bits) |
| 372 | { | 368 | { |
| 373 | struct rb_node *node; | 369 | struct rb_node *node; |
| 370 | int bits_to_set = *bits & ~EXTENT_CTLBITS; | ||
| 374 | int ret; | 371 | int ret; |
| 375 | 372 | ||
| 376 | if (end < start) { | 373 | if (end < start) { |
| @@ -385,9 +382,9 @@ static int insert_state(struct extent_io_tree *tree, | |||
| 385 | if (ret) | 382 | if (ret) |
| 386 | return ret; | 383 | return ret; |
| 387 | 384 | ||
| 388 | if (bits & EXTENT_DIRTY) | 385 | if (bits_to_set & EXTENT_DIRTY) |
| 389 | tree->dirty_bytes += end - start + 1; | 386 | tree->dirty_bytes += end - start + 1; |
| 390 | state->state |= bits; | 387 | state->state |= bits_to_set; |
| 391 | node = tree_insert(&tree->state, end, &state->rb_node); | 388 | node = tree_insert(&tree->state, end, &state->rb_node); |
| 392 | if (node) { | 389 | if (node) { |
| 393 | struct extent_state *found; | 390 | struct extent_state *found; |
| @@ -457,13 +454,13 @@ static int split_state(struct extent_io_tree *tree, struct extent_state *orig, | |||
| 457 | * struct is freed and removed from the tree | 454 | * struct is freed and removed from the tree |
| 458 | */ | 455 | */ |
| 459 | static int clear_state_bit(struct extent_io_tree *tree, | 456 | static int clear_state_bit(struct extent_io_tree *tree, |
| 460 | struct extent_state *state, int bits, int wake, | 457 | struct extent_state *state, |
| 461 | int delete) | 458 | int *bits, int wake) |
| 462 | { | 459 | { |
| 463 | int bits_to_clear = bits & ~EXTENT_DO_ACCOUNTING; | 460 | int bits_to_clear = *bits & ~EXTENT_CTLBITS; |
| 464 | int ret = state->state & bits_to_clear; | 461 | int ret = state->state & bits_to_clear; |
| 465 | 462 | ||
| 466 | if ((bits & EXTENT_DIRTY) && (state->state & EXTENT_DIRTY)) { | 463 | if ((bits_to_clear & EXTENT_DIRTY) && (state->state & EXTENT_DIRTY)) { |
| 467 | u64 range = state->end - state->start + 1; | 464 | u64 range = state->end - state->start + 1; |
| 468 | WARN_ON(range > tree->dirty_bytes); | 465 | WARN_ON(range > tree->dirty_bytes); |
| 469 | tree->dirty_bytes -= range; | 466 | tree->dirty_bytes -= range; |
| @@ -472,9 +469,8 @@ static int clear_state_bit(struct extent_io_tree *tree, | |||
| 472 | state->state &= ~bits_to_clear; | 469 | state->state &= ~bits_to_clear; |
| 473 | if (wake) | 470 | if (wake) |
| 474 | wake_up(&state->wq); | 471 | wake_up(&state->wq); |
| 475 | if (delete || state->state == 0) { | 472 | if (state->state == 0) { |
| 476 | if (state->tree) { | 473 | if (state->tree) { |
| 477 | clear_state_cb(tree, state, state->state); | ||
| 478 | rb_erase(&state->rb_node, &tree->state); | 474 | rb_erase(&state->rb_node, &tree->state); |
| 479 | state->tree = NULL; | 475 | state->tree = NULL; |
| 480 | free_extent_state(state); | 476 | free_extent_state(state); |
| @@ -513,7 +509,14 @@ int clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, | |||
| 513 | u64 last_end; | 509 | u64 last_end; |
| 514 | int err; | 510 | int err; |
| 515 | int set = 0; | 511 | int set = 0; |
| 512 | int clear = 0; | ||
| 513 | |||
| 514 | if (delete) | ||
| 515 | bits |= ~EXTENT_CTLBITS; | ||
| 516 | bits |= EXTENT_FIRST_DELALLOC; | ||
| 516 | 517 | ||
| 518 | if (bits & (EXTENT_IOBITS | EXTENT_BOUNDARY)) | ||
| 519 | clear = 1; | ||
| 517 | again: | 520 | again: |
| 518 | if (!prealloc && (mask & __GFP_WAIT)) { | 521 | if (!prealloc && (mask & __GFP_WAIT)) { |
| 519 | prealloc = alloc_extent_state(mask); | 522 | prealloc = alloc_extent_state(mask); |
| @@ -524,14 +527,20 @@ again: | |||
| 524 | spin_lock(&tree->lock); | 527 | spin_lock(&tree->lock); |
| 525 | if (cached_state) { | 528 | if (cached_state) { |
| 526 | cached = *cached_state; | 529 | cached = *cached_state; |
| 527 | *cached_state = NULL; | 530 | |
| 528 | cached_state = NULL; | 531 | if (clear) { |
| 532 | *cached_state = NULL; | ||
| 533 | cached_state = NULL; | ||
| 534 | } | ||
| 535 | |||
| 529 | if (cached && cached->tree && cached->start == start) { | 536 | if (cached && cached->tree && cached->start == start) { |
| 530 | atomic_dec(&cached->refs); | 537 | if (clear) |
| 538 | atomic_dec(&cached->refs); | ||
| 531 | state = cached; | 539 | state = cached; |
| 532 | goto hit_next; | 540 | goto hit_next; |
| 533 | } | 541 | } |
| 534 | free_extent_state(cached); | 542 | if (clear) |
| 543 | free_extent_state(cached); | ||
| 535 | } | 544 | } |
| 536 | /* | 545 | /* |
| 537 | * this search will find the extents that end after | 546 | * this search will find the extents that end after |
| @@ -572,8 +581,7 @@ hit_next: | |||
| 572 | if (err) | 581 | if (err) |
| 573 | goto out; | 582 | goto out; |
| 574 | if (state->end <= end) { | 583 | if (state->end <= end) { |
| 575 | set |= clear_state_bit(tree, state, bits, wake, | 584 | set |= clear_state_bit(tree, state, &bits, wake); |
| 576 | delete); | ||
| 577 | if (last_end == (u64)-1) | 585 | if (last_end == (u64)-1) |
| 578 | goto out; | 586 | goto out; |
| 579 | start = last_end + 1; | 587 | start = last_end + 1; |
| @@ -594,7 +602,7 @@ hit_next: | |||
| 594 | if (wake) | 602 | if (wake) |
| 595 | wake_up(&state->wq); | 603 | wake_up(&state->wq); |
| 596 | 604 | ||
| 597 | set |= clear_state_bit(tree, prealloc, bits, wake, delete); | 605 | set |= clear_state_bit(tree, prealloc, &bits, wake); |
| 598 | 606 | ||
| 599 | prealloc = NULL; | 607 | prealloc = NULL; |
| 600 | goto out; | 608 | goto out; |
| @@ -605,7 +613,7 @@ hit_next: | |||
| 605 | else | 613 | else |
| 606 | next_node = NULL; | 614 | next_node = NULL; |
| 607 | 615 | ||
| 608 | set |= clear_state_bit(tree, state, bits, wake, delete); | 616 | set |= clear_state_bit(tree, state, &bits, wake); |
| 609 | if (last_end == (u64)-1) | 617 | if (last_end == (u64)-1) |
| 610 | goto out; | 618 | goto out; |
| 611 | start = last_end + 1; | 619 | start = last_end + 1; |
| @@ -698,19 +706,19 @@ out: | |||
| 698 | 706 | ||
| 699 | static int set_state_bits(struct extent_io_tree *tree, | 707 | static int set_state_bits(struct extent_io_tree *tree, |
| 700 | struct extent_state *state, | 708 | struct extent_state *state, |
| 701 | int bits) | 709 | int *bits) |
| 702 | { | 710 | { |
| 703 | int ret; | 711 | int ret; |
| 712 | int bits_to_set = *bits & ~EXTENT_CTLBITS; | ||
| 704 | 713 | ||
| 705 | ret = set_state_cb(tree, state, bits); | 714 | ret = set_state_cb(tree, state, bits); |
| 706 | if (ret) | 715 | if (ret) |
| 707 | return ret; | 716 | return ret; |
| 708 | 717 | if ((bits_to_set & EXTENT_DIRTY) && !(state->state & EXTENT_DIRTY)) { | |
| 709 | if ((bits & EXTENT_DIRTY) && !(state->state & EXTENT_DIRTY)) { | ||
| 710 | u64 range = state->end - state->start + 1; | 718 | u64 range = state->end - state->start + 1; |
| 711 | tree->dirty_bytes += range; | 719 | tree->dirty_bytes += range; |
| 712 | } | 720 | } |
| 713 | state->state |= bits; | 721 | state->state |= bits_to_set; |
| 714 | 722 | ||
| 715 | return 0; | 723 | return 0; |
| 716 | } | 724 | } |
| @@ -737,10 +745,9 @@ static void cache_state(struct extent_state *state, | |||
| 737 | * [start, end] is inclusive This takes the tree lock. | 745 | * [start, end] is inclusive This takes the tree lock. |
| 738 | */ | 746 | */ |
| 739 | 747 | ||
| 740 | static int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, | 748 | int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, |
| 741 | int bits, int exclusive_bits, u64 *failed_start, | 749 | int bits, int exclusive_bits, u64 *failed_start, |
| 742 | struct extent_state **cached_state, | 750 | struct extent_state **cached_state, gfp_t mask) |
| 743 | gfp_t mask) | ||
| 744 | { | 751 | { |
| 745 | struct extent_state *state; | 752 | struct extent_state *state; |
| 746 | struct extent_state *prealloc = NULL; | 753 | struct extent_state *prealloc = NULL; |
| @@ -749,6 +756,7 @@ static int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, | |||
| 749 | u64 last_start; | 756 | u64 last_start; |
| 750 | u64 last_end; | 757 | u64 last_end; |
| 751 | 758 | ||
| 759 | bits |= EXTENT_FIRST_DELALLOC; | ||
| 752 | again: | 760 | again: |
| 753 | if (!prealloc && (mask & __GFP_WAIT)) { | 761 | if (!prealloc && (mask & __GFP_WAIT)) { |
| 754 | prealloc = alloc_extent_state(mask); | 762 | prealloc = alloc_extent_state(mask); |
| @@ -770,7 +778,7 @@ again: | |||
| 770 | */ | 778 | */ |
| 771 | node = tree_search(tree, start); | 779 | node = tree_search(tree, start); |
| 772 | if (!node) { | 780 | if (!node) { |
| 773 | err = insert_state(tree, prealloc, start, end, bits); | 781 | err = insert_state(tree, prealloc, start, end, &bits); |
| 774 | prealloc = NULL; | 782 | prealloc = NULL; |
| 775 | BUG_ON(err == -EEXIST); | 783 | BUG_ON(err == -EEXIST); |
| 776 | goto out; | 784 | goto out; |
| @@ -794,7 +802,7 @@ hit_next: | |||
| 794 | goto out; | 802 | goto out; |
| 795 | } | 803 | } |
| 796 | 804 | ||
| 797 | err = set_state_bits(tree, state, bits); | 805 | err = set_state_bits(tree, state, &bits); |
| 798 | if (err) | 806 | if (err) |
| 799 | goto out; | 807 | goto out; |
| 800 | 808 | ||
| @@ -844,7 +852,7 @@ hit_next: | |||
| 844 | if (err) | 852 | if (err) |
| 845 | goto out; | 853 | goto out; |
| 846 | if (state->end <= end) { | 854 | if (state->end <= end) { |
| 847 | err = set_state_bits(tree, state, bits); | 855 | err = set_state_bits(tree, state, &bits); |
| 848 | if (err) | 856 | if (err) |
| 849 | goto out; | 857 | goto out; |
| 850 | cache_state(state, cached_state); | 858 | cache_state(state, cached_state); |
| @@ -869,7 +877,7 @@ hit_next: | |||
| 869 | else | 877 | else |
| 870 | this_end = last_start - 1; | 878 | this_end = last_start - 1; |
| 871 | err = insert_state(tree, prealloc, start, this_end, | 879 | err = insert_state(tree, prealloc, start, this_end, |
| 872 | bits); | 880 | &bits); |
| 873 | BUG_ON(err == -EEXIST); | 881 | BUG_ON(err == -EEXIST); |
| 874 | if (err) { | 882 | if (err) { |
| 875 | prealloc = NULL; | 883 | prealloc = NULL; |
| @@ -895,7 +903,7 @@ hit_next: | |||
| 895 | err = split_state(tree, state, prealloc, end + 1); | 903 | err = split_state(tree, state, prealloc, end + 1); |
| 896 | BUG_ON(err == -EEXIST); | 904 | BUG_ON(err == -EEXIST); |
| 897 | 905 | ||
| 898 | err = set_state_bits(tree, prealloc, bits); | 906 | err = set_state_bits(tree, prealloc, &bits); |
| 899 | if (err) { | 907 | if (err) { |
| 900 | prealloc = NULL; | 908 | prealloc = NULL; |
| 901 | goto out; | 909 | goto out; |
| @@ -946,11 +954,11 @@ int clear_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, | |||
| 946 | } | 954 | } |
| 947 | 955 | ||
| 948 | int set_extent_delalloc(struct extent_io_tree *tree, u64 start, u64 end, | 956 | int set_extent_delalloc(struct extent_io_tree *tree, u64 start, u64 end, |
| 949 | gfp_t mask) | 957 | struct extent_state **cached_state, gfp_t mask) |
| 950 | { | 958 | { |
| 951 | return set_extent_bit(tree, start, end, | 959 | return set_extent_bit(tree, start, end, |
| 952 | EXTENT_DELALLOC | EXTENT_DIRTY | EXTENT_UPTODATE, | 960 | EXTENT_DELALLOC | EXTENT_DIRTY | EXTENT_UPTODATE, |
| 953 | 0, NULL, NULL, mask); | 961 | 0, NULL, cached_state, mask); |
| 954 | } | 962 | } |
| 955 | 963 | ||
| 956 | int clear_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end, | 964 | int clear_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end, |
| @@ -958,8 +966,7 @@ int clear_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end, | |||
| 958 | { | 966 | { |
| 959 | return clear_extent_bit(tree, start, end, | 967 | return clear_extent_bit(tree, start, end, |
| 960 | EXTENT_DIRTY | EXTENT_DELALLOC | | 968 | EXTENT_DIRTY | EXTENT_DELALLOC | |
| 961 | EXTENT_DO_ACCOUNTING, 0, 0, | 969 | EXTENT_DO_ACCOUNTING, 0, 0, NULL, mask); |
| 962 | NULL, mask); | ||
| 963 | } | 970 | } |
| 964 | 971 | ||
| 965 | int set_extent_new(struct extent_io_tree *tree, u64 start, u64 end, | 972 | int set_extent_new(struct extent_io_tree *tree, u64 start, u64 end, |
| @@ -984,10 +991,11 @@ int set_extent_uptodate(struct extent_io_tree *tree, u64 start, u64 end, | |||
| 984 | } | 991 | } |
| 985 | 992 | ||
| 986 | static int clear_extent_uptodate(struct extent_io_tree *tree, u64 start, | 993 | static int clear_extent_uptodate(struct extent_io_tree *tree, u64 start, |
| 987 | u64 end, gfp_t mask) | 994 | u64 end, struct extent_state **cached_state, |
| 995 | gfp_t mask) | ||
| 988 | { | 996 | { |
| 989 | return clear_extent_bit(tree, start, end, EXTENT_UPTODATE, 0, 0, | 997 | return clear_extent_bit(tree, start, end, EXTENT_UPTODATE, 0, 0, |
| 990 | NULL, mask); | 998 | cached_state, mask); |
| 991 | } | 999 | } |
| 992 | 1000 | ||
| 993 | int wait_on_extent_writeback(struct extent_io_tree *tree, u64 start, u64 end) | 1001 | int wait_on_extent_writeback(struct extent_io_tree *tree, u64 start, u64 end) |
| @@ -1171,7 +1179,8 @@ out: | |||
| 1171 | * 1 is returned if we find something, 0 if nothing was in the tree | 1179 | * 1 is returned if we find something, 0 if nothing was in the tree |
| 1172 | */ | 1180 | */ |
| 1173 | static noinline u64 find_delalloc_range(struct extent_io_tree *tree, | 1181 | static noinline u64 find_delalloc_range(struct extent_io_tree *tree, |
| 1174 | u64 *start, u64 *end, u64 max_bytes) | 1182 | u64 *start, u64 *end, u64 max_bytes, |
| 1183 | struct extent_state **cached_state) | ||
| 1175 | { | 1184 | { |
| 1176 | struct rb_node *node; | 1185 | struct rb_node *node; |
| 1177 | struct extent_state *state; | 1186 | struct extent_state *state; |
| @@ -1203,8 +1212,11 @@ static noinline u64 find_delalloc_range(struct extent_io_tree *tree, | |||
| 1203 | *end = state->end; | 1212 | *end = state->end; |
| 1204 | goto out; | 1213 | goto out; |
| 1205 | } | 1214 | } |
| 1206 | if (!found) | 1215 | if (!found) { |
| 1207 | *start = state->start; | 1216 | *start = state->start; |
| 1217 | *cached_state = state; | ||
| 1218 | atomic_inc(&state->refs); | ||
| 1219 | } | ||
| 1208 | found++; | 1220 | found++; |
| 1209 | *end = state->end; | 1221 | *end = state->end; |
| 1210 | cur_start = state->end + 1; | 1222 | cur_start = state->end + 1; |
| @@ -1336,10 +1348,11 @@ again: | |||
| 1336 | delalloc_start = *start; | 1348 | delalloc_start = *start; |
| 1337 | delalloc_end = 0; | 1349 | delalloc_end = 0; |
| 1338 | found = find_delalloc_range(tree, &delalloc_start, &delalloc_end, | 1350 | found = find_delalloc_range(tree, &delalloc_start, &delalloc_end, |
| 1339 | max_bytes); | 1351 | max_bytes, &cached_state); |
| 1340 | if (!found || delalloc_end <= *start) { | 1352 | if (!found || delalloc_end <= *start) { |
| 1341 | *start = delalloc_start; | 1353 | *start = delalloc_start; |
| 1342 | *end = delalloc_end; | 1354 | *end = delalloc_end; |
| 1355 | free_extent_state(cached_state); | ||
| 1343 | return found; | 1356 | return found; |
| 1344 | } | 1357 | } |
| 1345 | 1358 | ||
| @@ -1421,9 +1434,6 @@ int extent_clear_unlock_delalloc(struct inode *inode, | |||
| 1421 | if (op & EXTENT_CLEAR_DELALLOC) | 1434 | if (op & EXTENT_CLEAR_DELALLOC) |
| 1422 | clear_bits |= EXTENT_DELALLOC; | 1435 | clear_bits |= EXTENT_DELALLOC; |
| 1423 | 1436 | ||
| 1424 | if (op & EXTENT_CLEAR_ACCOUNTING) | ||
| 1425 | clear_bits |= EXTENT_DO_ACCOUNTING; | ||
| 1426 | |||
| 1427 | clear_extent_bit(tree, start, end, clear_bits, 1, 0, NULL, GFP_NOFS); | 1437 | clear_extent_bit(tree, start, end, clear_bits, 1, 0, NULL, GFP_NOFS); |
| 1428 | if (!(op & (EXTENT_CLEAR_UNLOCK_PAGE | EXTENT_CLEAR_DIRTY | | 1438 | if (!(op & (EXTENT_CLEAR_UNLOCK_PAGE | EXTENT_CLEAR_DIRTY | |
| 1429 | EXTENT_SET_WRITEBACK | EXTENT_END_WRITEBACK | | 1439 | EXTENT_SET_WRITEBACK | EXTENT_END_WRITEBACK | |
| @@ -1722,7 +1732,7 @@ static void end_bio_extent_writepage(struct bio *bio, int err) | |||
| 1722 | } | 1732 | } |
| 1723 | 1733 | ||
| 1724 | if (!uptodate) { | 1734 | if (!uptodate) { |
| 1725 | clear_extent_uptodate(tree, start, end, GFP_NOFS); | 1735 | clear_extent_uptodate(tree, start, end, NULL, GFP_NOFS); |
| 1726 | ClearPageUptodate(page); | 1736 | ClearPageUptodate(page); |
| 1727 | SetPageError(page); | 1737 | SetPageError(page); |
| 1728 | } | 1738 | } |
| @@ -1750,7 +1760,8 @@ static void end_bio_extent_writepage(struct bio *bio, int err) | |||
| 1750 | static void end_bio_extent_readpage(struct bio *bio, int err) | 1760 | static void end_bio_extent_readpage(struct bio *bio, int err) |
| 1751 | { | 1761 | { |
| 1752 | int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); | 1762 | int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); |
| 1753 | struct bio_vec *bvec = bio->bi_io_vec + bio->bi_vcnt - 1; | 1763 | struct bio_vec *bvec_end = bio->bi_io_vec + bio->bi_vcnt - 1; |
| 1764 | struct bio_vec *bvec = bio->bi_io_vec; | ||
| 1754 | struct extent_io_tree *tree; | 1765 | struct extent_io_tree *tree; |
| 1755 | u64 start; | 1766 | u64 start; |
| 1756 | u64 end; | 1767 | u64 end; |
| @@ -1773,7 +1784,7 @@ static void end_bio_extent_readpage(struct bio *bio, int err) | |||
| 1773 | else | 1784 | else |
| 1774 | whole_page = 0; | 1785 | whole_page = 0; |
| 1775 | 1786 | ||
| 1776 | if (--bvec >= bio->bi_io_vec) | 1787 | if (++bvec <= bvec_end) |
| 1777 | prefetchw(&bvec->bv_page->flags); | 1788 | prefetchw(&bvec->bv_page->flags); |
| 1778 | 1789 | ||
| 1779 | if (uptodate && tree->ops && tree->ops->readpage_end_io_hook) { | 1790 | if (uptodate && tree->ops && tree->ops->readpage_end_io_hook) { |
| @@ -1818,7 +1829,7 @@ static void end_bio_extent_readpage(struct bio *bio, int err) | |||
| 1818 | } | 1829 | } |
| 1819 | check_page_locked(tree, page); | 1830 | check_page_locked(tree, page); |
| 1820 | } | 1831 | } |
| 1821 | } while (bvec >= bio->bi_io_vec); | 1832 | } while (bvec <= bvec_end); |
| 1822 | 1833 | ||
| 1823 | bio_put(bio); | 1834 | bio_put(bio); |
| 1824 | } | 1835 | } |
| @@ -1901,7 +1912,7 @@ static int submit_one_bio(int rw, struct bio *bio, int mirror_num, | |||
| 1901 | 1912 | ||
| 1902 | if (tree->ops && tree->ops->submit_bio_hook) | 1913 | if (tree->ops && tree->ops->submit_bio_hook) |
| 1903 | tree->ops->submit_bio_hook(page->mapping->host, rw, bio, | 1914 | tree->ops->submit_bio_hook(page->mapping->host, rw, bio, |
| 1904 | mirror_num, bio_flags); | 1915 | mirror_num, bio_flags, start); |
| 1905 | else | 1916 | else |
| 1906 | submit_bio(rw, bio); | 1917 | submit_bio(rw, bio); |
| 1907 | if (bio_flagged(bio, BIO_EOPNOTSUPP)) | 1918 | if (bio_flagged(bio, BIO_EOPNOTSUPP)) |
| @@ -2005,6 +2016,7 @@ static int __extent_read_full_page(struct extent_io_tree *tree, | |||
| 2005 | sector_t sector; | 2016 | sector_t sector; |
| 2006 | struct extent_map *em; | 2017 | struct extent_map *em; |
| 2007 | struct block_device *bdev; | 2018 | struct block_device *bdev; |
| 2019 | struct btrfs_ordered_extent *ordered; | ||
| 2008 | int ret; | 2020 | int ret; |
| 2009 | int nr = 0; | 2021 | int nr = 0; |
| 2010 | size_t page_offset = 0; | 2022 | size_t page_offset = 0; |
| @@ -2016,7 +2028,15 @@ static int __extent_read_full_page(struct extent_io_tree *tree, | |||
| 2016 | set_page_extent_mapped(page); | 2028 | set_page_extent_mapped(page); |
| 2017 | 2029 | ||
| 2018 | end = page_end; | 2030 | end = page_end; |
| 2019 | lock_extent(tree, start, end, GFP_NOFS); | 2031 | while (1) { |
| 2032 | lock_extent(tree, start, end, GFP_NOFS); | ||
| 2033 | ordered = btrfs_lookup_ordered_extent(inode, start); | ||
| 2034 | if (!ordered) | ||
| 2035 | break; | ||
| 2036 | unlock_extent(tree, start, end, GFP_NOFS); | ||
| 2037 | btrfs_start_ordered_extent(inode, ordered, 1); | ||
| 2038 | btrfs_put_ordered_extent(ordered); | ||
| 2039 | } | ||
| 2020 | 2040 | ||
| 2021 | if (page->index == last_byte >> PAGE_CACHE_SHIFT) { | 2041 | if (page->index == last_byte >> PAGE_CACHE_SHIFT) { |
| 2022 | char *userpage; | 2042 | char *userpage; |
| @@ -2574,7 +2594,6 @@ int extent_write_full_page(struct extent_io_tree *tree, struct page *page, | |||
| 2574 | .sync_io = wbc->sync_mode == WB_SYNC_ALL, | 2594 | .sync_io = wbc->sync_mode == WB_SYNC_ALL, |
| 2575 | }; | 2595 | }; |
| 2576 | struct writeback_control wbc_writepages = { | 2596 | struct writeback_control wbc_writepages = { |
| 2577 | .bdi = wbc->bdi, | ||
| 2578 | .sync_mode = wbc->sync_mode, | 2597 | .sync_mode = wbc->sync_mode, |
| 2579 | .older_than_this = NULL, | 2598 | .older_than_this = NULL, |
| 2580 | .nr_to_write = 64, | 2599 | .nr_to_write = 64, |
| @@ -2608,7 +2627,6 @@ int extent_write_locked_range(struct extent_io_tree *tree, struct inode *inode, | |||
| 2608 | .sync_io = mode == WB_SYNC_ALL, | 2627 | .sync_io = mode == WB_SYNC_ALL, |
| 2609 | }; | 2628 | }; |
| 2610 | struct writeback_control wbc_writepages = { | 2629 | struct writeback_control wbc_writepages = { |
| 2611 | .bdi = inode->i_mapping->backing_dev_info, | ||
| 2612 | .sync_mode = mode, | 2630 | .sync_mode = mode, |
| 2613 | .older_than_this = NULL, | 2631 | .older_than_this = NULL, |
| 2614 | .nr_to_write = nr_pages * 2, | 2632 | .nr_to_write = nr_pages * 2, |
| @@ -2663,33 +2681,20 @@ int extent_readpages(struct extent_io_tree *tree, | |||
| 2663 | { | 2681 | { |
| 2664 | struct bio *bio = NULL; | 2682 | struct bio *bio = NULL; |
| 2665 | unsigned page_idx; | 2683 | unsigned page_idx; |
| 2666 | struct pagevec pvec; | ||
| 2667 | unsigned long bio_flags = 0; | 2684 | unsigned long bio_flags = 0; |
| 2668 | 2685 | ||
| 2669 | pagevec_init(&pvec, 0); | ||
| 2670 | for (page_idx = 0; page_idx < nr_pages; page_idx++) { | 2686 | for (page_idx = 0; page_idx < nr_pages; page_idx++) { |
| 2671 | struct page *page = list_entry(pages->prev, struct page, lru); | 2687 | struct page *page = list_entry(pages->prev, struct page, lru); |
| 2672 | 2688 | ||
| 2673 | prefetchw(&page->flags); | 2689 | prefetchw(&page->flags); |
| 2674 | list_del(&page->lru); | 2690 | list_del(&page->lru); |
| 2675 | /* | 2691 | if (!add_to_page_cache_lru(page, mapping, |
| 2676 | * what we want to do here is call add_to_page_cache_lru, | ||
| 2677 | * but that isn't exported, so we reproduce it here | ||
| 2678 | */ | ||
| 2679 | if (!add_to_page_cache(page, mapping, | ||
| 2680 | page->index, GFP_KERNEL)) { | 2692 | page->index, GFP_KERNEL)) { |
| 2681 | |||
| 2682 | /* open coding of lru_cache_add, also not exported */ | ||
| 2683 | page_cache_get(page); | ||
| 2684 | if (!pagevec_add(&pvec, page)) | ||
| 2685 | __pagevec_lru_add_file(&pvec); | ||
| 2686 | __extent_read_full_page(tree, page, get_extent, | 2693 | __extent_read_full_page(tree, page, get_extent, |
| 2687 | &bio, 0, &bio_flags); | 2694 | &bio, 0, &bio_flags); |
| 2688 | } | 2695 | } |
| 2689 | page_cache_release(page); | 2696 | page_cache_release(page); |
| 2690 | } | 2697 | } |
| 2691 | if (pagevec_count(&pvec)) | ||
| 2692 | __pagevec_lru_add_file(&pvec); | ||
| 2693 | BUG_ON(!list_empty(pages)); | 2698 | BUG_ON(!list_empty(pages)); |
| 2694 | if (bio) | 2699 | if (bio) |
| 2695 | submit_one_bio(READ, bio, 0, bio_flags); | 2700 | submit_one_bio(READ, bio, 0, bio_flags); |
| @@ -2704,6 +2709,7 @@ int extent_readpages(struct extent_io_tree *tree, | |||
| 2704 | int extent_invalidatepage(struct extent_io_tree *tree, | 2709 | int extent_invalidatepage(struct extent_io_tree *tree, |
| 2705 | struct page *page, unsigned long offset) | 2710 | struct page *page, unsigned long offset) |
| 2706 | { | 2711 | { |
| 2712 | struct extent_state *cached_state = NULL; | ||
| 2707 | u64 start = ((u64)page->index << PAGE_CACHE_SHIFT); | 2713 | u64 start = ((u64)page->index << PAGE_CACHE_SHIFT); |
| 2708 | u64 end = start + PAGE_CACHE_SIZE - 1; | 2714 | u64 end = start + PAGE_CACHE_SIZE - 1; |
| 2709 | size_t blocksize = page->mapping->host->i_sb->s_blocksize; | 2715 | size_t blocksize = page->mapping->host->i_sb->s_blocksize; |
| @@ -2712,12 +2718,12 @@ int extent_invalidatepage(struct extent_io_tree *tree, | |||
| 2712 | if (start > end) | 2718 | if (start > end) |
| 2713 | return 0; | 2719 | return 0; |
| 2714 | 2720 | ||
| 2715 | lock_extent(tree, start, end, GFP_NOFS); | 2721 | lock_extent_bits(tree, start, end, 0, &cached_state, GFP_NOFS); |
| 2716 | wait_on_page_writeback(page); | 2722 | wait_on_page_writeback(page); |
| 2717 | clear_extent_bit(tree, start, end, | 2723 | clear_extent_bit(tree, start, end, |
| 2718 | EXTENT_LOCKED | EXTENT_DIRTY | EXTENT_DELALLOC | | 2724 | EXTENT_LOCKED | EXTENT_DIRTY | EXTENT_DELALLOC | |
| 2719 | EXTENT_DO_ACCOUNTING, | 2725 | EXTENT_DO_ACCOUNTING, |
| 2720 | 1, 1, NULL, GFP_NOFS); | 2726 | 1, 1, &cached_state, GFP_NOFS); |
| 2721 | return 0; | 2727 | return 0; |
| 2722 | } | 2728 | } |
| 2723 | 2729 | ||
| @@ -2920,16 +2926,17 @@ sector_t extent_bmap(struct address_space *mapping, sector_t iblock, | |||
| 2920 | get_extent_t *get_extent) | 2926 | get_extent_t *get_extent) |
| 2921 | { | 2927 | { |
| 2922 | struct inode *inode = mapping->host; | 2928 | struct inode *inode = mapping->host; |
| 2929 | struct extent_state *cached_state = NULL; | ||
| 2923 | u64 start = iblock << inode->i_blkbits; | 2930 | u64 start = iblock << inode->i_blkbits; |
| 2924 | sector_t sector = 0; | 2931 | sector_t sector = 0; |
| 2925 | size_t blksize = (1 << inode->i_blkbits); | 2932 | size_t blksize = (1 << inode->i_blkbits); |
| 2926 | struct extent_map *em; | 2933 | struct extent_map *em; |
| 2927 | 2934 | ||
| 2928 | lock_extent(&BTRFS_I(inode)->io_tree, start, start + blksize - 1, | 2935 | lock_extent_bits(&BTRFS_I(inode)->io_tree, start, start + blksize - 1, |
| 2929 | GFP_NOFS); | 2936 | 0, &cached_state, GFP_NOFS); |
| 2930 | em = get_extent(inode, NULL, 0, start, blksize, 0); | 2937 | em = get_extent(inode, NULL, 0, start, blksize, 0); |
| 2931 | unlock_extent(&BTRFS_I(inode)->io_tree, start, start + blksize - 1, | 2938 | unlock_extent_cached(&BTRFS_I(inode)->io_tree, start, |
| 2932 | GFP_NOFS); | 2939 | start + blksize - 1, &cached_state, GFP_NOFS); |
| 2933 | if (!em || IS_ERR(em)) | 2940 | if (!em || IS_ERR(em)) |
| 2934 | return 0; | 2941 | return 0; |
| 2935 | 2942 | ||
| @@ -2951,6 +2958,7 @@ int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, | |||
| 2951 | u32 flags = 0; | 2958 | u32 flags = 0; |
| 2952 | u64 disko = 0; | 2959 | u64 disko = 0; |
| 2953 | struct extent_map *em = NULL; | 2960 | struct extent_map *em = NULL; |
| 2961 | struct extent_state *cached_state = NULL; | ||
| 2954 | int end = 0; | 2962 | int end = 0; |
| 2955 | u64 em_start = 0, em_len = 0; | 2963 | u64 em_start = 0, em_len = 0; |
| 2956 | unsigned long emflags; | 2964 | unsigned long emflags; |
| @@ -2959,8 +2967,8 @@ int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, | |||
| 2959 | if (len == 0) | 2967 | if (len == 0) |
| 2960 | return -EINVAL; | 2968 | return -EINVAL; |
| 2961 | 2969 | ||
| 2962 | lock_extent(&BTRFS_I(inode)->io_tree, start, start + len, | 2970 | lock_extent_bits(&BTRFS_I(inode)->io_tree, start, start + len, 0, |
| 2963 | GFP_NOFS); | 2971 | &cached_state, GFP_NOFS); |
| 2964 | em = get_extent(inode, NULL, 0, off, max - off, 0); | 2972 | em = get_extent(inode, NULL, 0, off, max - off, 0); |
| 2965 | if (!em) | 2973 | if (!em) |
| 2966 | goto out; | 2974 | goto out; |
| @@ -3023,8 +3031,8 @@ int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, | |||
| 3023 | out_free: | 3031 | out_free: |
| 3024 | free_extent_map(em); | 3032 | free_extent_map(em); |
| 3025 | out: | 3033 | out: |
| 3026 | unlock_extent(&BTRFS_I(inode)->io_tree, start, start + len, | 3034 | unlock_extent_cached(&BTRFS_I(inode)->io_tree, start, start + len, |
| 3027 | GFP_NOFS); | 3035 | &cached_state, GFP_NOFS); |
| 3028 | return ret; | 3036 | return ret; |
| 3029 | } | 3037 | } |
| 3030 | 3038 | ||
| @@ -3165,10 +3173,9 @@ struct extent_buffer *alloc_extent_buffer(struct extent_io_tree *tree, | |||
| 3165 | spin_unlock(&tree->buffer_lock); | 3173 | spin_unlock(&tree->buffer_lock); |
| 3166 | goto free_eb; | 3174 | goto free_eb; |
| 3167 | } | 3175 | } |
| 3168 | spin_unlock(&tree->buffer_lock); | ||
| 3169 | |||
| 3170 | /* add one reference for the tree */ | 3176 | /* add one reference for the tree */ |
| 3171 | atomic_inc(&eb->refs); | 3177 | atomic_inc(&eb->refs); |
| 3178 | spin_unlock(&tree->buffer_lock); | ||
| 3172 | return eb; | 3179 | return eb; |
| 3173 | 3180 | ||
| 3174 | free_eb: | 3181 | free_eb: |
| @@ -3265,7 +3272,8 @@ int set_extent_buffer_dirty(struct extent_io_tree *tree, | |||
| 3265 | } | 3272 | } |
| 3266 | 3273 | ||
| 3267 | int clear_extent_buffer_uptodate(struct extent_io_tree *tree, | 3274 | int clear_extent_buffer_uptodate(struct extent_io_tree *tree, |
| 3268 | struct extent_buffer *eb) | 3275 | struct extent_buffer *eb, |
| 3276 | struct extent_state **cached_state) | ||
| 3269 | { | 3277 | { |
| 3270 | unsigned long i; | 3278 | unsigned long i; |
| 3271 | struct page *page; | 3279 | struct page *page; |
| @@ -3275,7 +3283,7 @@ int clear_extent_buffer_uptodate(struct extent_io_tree *tree, | |||
| 3275 | clear_bit(EXTENT_BUFFER_UPTODATE, &eb->bflags); | 3283 | clear_bit(EXTENT_BUFFER_UPTODATE, &eb->bflags); |
| 3276 | 3284 | ||
| 3277 | clear_extent_uptodate(tree, eb->start, eb->start + eb->len - 1, | 3285 | clear_extent_uptodate(tree, eb->start, eb->start + eb->len - 1, |
| 3278 | GFP_NOFS); | 3286 | cached_state, GFP_NOFS); |
| 3279 | for (i = 0; i < num_pages; i++) { | 3287 | for (i = 0; i < num_pages; i++) { |
| 3280 | page = extent_buffer_page(eb, i); | 3288 | page = extent_buffer_page(eb, i); |
| 3281 | if (page) | 3289 | if (page) |
| @@ -3335,7 +3343,8 @@ int extent_range_uptodate(struct extent_io_tree *tree, | |||
| 3335 | } | 3343 | } |
| 3336 | 3344 | ||
| 3337 | int extent_buffer_uptodate(struct extent_io_tree *tree, | 3345 | int extent_buffer_uptodate(struct extent_io_tree *tree, |
| 3338 | struct extent_buffer *eb) | 3346 | struct extent_buffer *eb, |
| 3347 | struct extent_state *cached_state) | ||
| 3339 | { | 3348 | { |
| 3340 | int ret = 0; | 3349 | int ret = 0; |
| 3341 | unsigned long num_pages; | 3350 | unsigned long num_pages; |
| @@ -3347,7 +3356,7 @@ int extent_buffer_uptodate(struct extent_io_tree *tree, | |||
| 3347 | return 1; | 3356 | return 1; |
| 3348 | 3357 | ||
| 3349 | ret = test_range_bit(tree, eb->start, eb->start + eb->len - 1, | 3358 | ret = test_range_bit(tree, eb->start, eb->start + eb->len - 1, |
| 3350 | EXTENT_UPTODATE, 1, NULL); | 3359 | EXTENT_UPTODATE, 1, cached_state); |
| 3351 | if (ret) | 3360 | if (ret) |
| 3352 | return ret; | 3361 | return ret; |
| 3353 | 3362 | ||
