aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/btrfs/extent_io.c16
-rw-r--r--fs/btrfs/transaction.c3
2 files changed, 15 insertions, 4 deletions
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 420fe26d32d5..0d931b143c00 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -796,17 +796,25 @@ static void set_state_bits(struct extent_io_tree *tree,
796 state->state |= bits_to_set; 796 state->state |= bits_to_set;
797} 797}
798 798
799static void cache_state(struct extent_state *state, 799static void cache_state_if_flags(struct extent_state *state,
800 struct extent_state **cached_ptr) 800 struct extent_state **cached_ptr,
801 const u64 flags)
801{ 802{
802 if (cached_ptr && !(*cached_ptr)) { 803 if (cached_ptr && !(*cached_ptr)) {
803 if (state->state & (EXTENT_IOBITS | EXTENT_BOUNDARY)) { 804 if (!flags || (state->state & flags)) {
804 *cached_ptr = state; 805 *cached_ptr = state;
805 atomic_inc(&state->refs); 806 atomic_inc(&state->refs);
806 } 807 }
807 } 808 }
808} 809}
809 810
811static void cache_state(struct extent_state *state,
812 struct extent_state **cached_ptr)
813{
814 return cache_state_if_flags(state, cached_ptr,
815 EXTENT_IOBITS | EXTENT_BOUNDARY);
816}
817
810/* 818/*
811 * set some bits on a range in the tree. This may require allocations or 819 * set some bits on a range in the tree. This may require allocations or
812 * sleeping, so the gfp mask is used to indicate what is allowed. 820 * sleeping, so the gfp mask is used to indicate what is allowed.
@@ -1482,7 +1490,7 @@ int find_first_extent_bit(struct extent_io_tree *tree, u64 start,
1482 state = find_first_extent_bit_state(tree, start, bits); 1490 state = find_first_extent_bit_state(tree, start, bits);
1483got_it: 1491got_it:
1484 if (state) { 1492 if (state) {
1485 cache_state(state, cached_state); 1493 cache_state_if_flags(state, cached_state, 0);
1486 *start_ret = state->start; 1494 *start_ret = state->start;
1487 *end_ret = state->end; 1495 *end_ret = state->end;
1488 ret = 0; 1496 ret = 0;
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 04dbc800c209..16c704b68704 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -883,6 +883,7 @@ int btrfs_write_marked_extents(struct btrfs_root *root,
883 werr = err; 883 werr = err;
884 else if (wait_writeback) 884 else if (wait_writeback)
885 werr = filemap_fdatawait_range(mapping, start, end); 885 werr = filemap_fdatawait_range(mapping, start, end);
886 free_extent_state(cached_state);
886 cached_state = NULL; 887 cached_state = NULL;
887 cond_resched(); 888 cond_resched();
888 start = end + 1; 889 start = end + 1;
@@ -927,6 +928,8 @@ int btrfs_wait_marked_extents(struct btrfs_root *root,
927 err = filemap_fdatawait_range(mapping, start, end); 928 err = filemap_fdatawait_range(mapping, start, end);
928 if (err) 929 if (err)
929 werr = err; 930 werr = err;
931 free_extent_state(cached_state);
932 cached_state = NULL;
930 cond_resched(); 933 cond_resched();
931 start = end + 1; 934 start = end + 1;
932 } 935 }