diff options
-rw-r--r-- | fs/btrfs/extent_io.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 355a973719a..3c17c9eb0d9 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c | |||
@@ -1171,7 +1171,8 @@ out: | |||
1171 | * 1 is returned if we find something, 0 if nothing was in the tree | 1171 | * 1 is returned if we find something, 0 if nothing was in the tree |
1172 | */ | 1172 | */ |
1173 | static noinline u64 find_delalloc_range(struct extent_io_tree *tree, | 1173 | static noinline u64 find_delalloc_range(struct extent_io_tree *tree, |
1174 | u64 *start, u64 *end, u64 max_bytes) | 1174 | u64 *start, u64 *end, u64 max_bytes, |
1175 | struct extent_state **cached_state) | ||
1175 | { | 1176 | { |
1176 | struct rb_node *node; | 1177 | struct rb_node *node; |
1177 | struct extent_state *state; | 1178 | struct extent_state *state; |
@@ -1203,8 +1204,11 @@ static noinline u64 find_delalloc_range(struct extent_io_tree *tree, | |||
1203 | *end = state->end; | 1204 | *end = state->end; |
1204 | goto out; | 1205 | goto out; |
1205 | } | 1206 | } |
1206 | if (!found) | 1207 | if (!found) { |
1207 | *start = state->start; | 1208 | *start = state->start; |
1209 | *cached_state = state; | ||
1210 | atomic_inc(&state->refs); | ||
1211 | } | ||
1208 | found++; | 1212 | found++; |
1209 | *end = state->end; | 1213 | *end = state->end; |
1210 | cur_start = state->end + 1; | 1214 | cur_start = state->end + 1; |
@@ -1336,10 +1340,11 @@ again: | |||
1336 | delalloc_start = *start; | 1340 | delalloc_start = *start; |
1337 | delalloc_end = 0; | 1341 | delalloc_end = 0; |
1338 | found = find_delalloc_range(tree, &delalloc_start, &delalloc_end, | 1342 | found = find_delalloc_range(tree, &delalloc_start, &delalloc_end, |
1339 | max_bytes); | 1343 | max_bytes, &cached_state); |
1340 | if (!found || delalloc_end <= *start) { | 1344 | if (!found || delalloc_end <= *start) { |
1341 | *start = delalloc_start; | 1345 | *start = delalloc_start; |
1342 | *end = delalloc_end; | 1346 | *end = delalloc_end; |
1347 | free_extent_state(cached_state); | ||
1343 | return found; | 1348 | return found; |
1344 | } | 1349 | } |
1345 | 1350 | ||