diff options
author | Josef Bacik <jbacik@redhat.com> | 2008-09-30 14:40:06 -0400 |
---|---|---|
committer | Chris Mason <chris.mason@oracle.com> | 2008-09-30 14:40:06 -0400 |
commit | 45b8c9a8b1e15bf79c2c17ec217adf96785f8011 (patch) | |
tree | 591260c2db70755b6913c379631e81df929abb02 /fs/btrfs/extent-tree.c | |
parent | d352ac68148b69937d39ca5d48bcc4478e118dbf (diff) |
Btrfs: fix seekiness due to finding the wrong block group
This patch fixes a problem where we end up seeking too much when *last_ptr is
valid. This happens because btrfs_lookup_first_block_group only returns a
block group that starts on or after the given search start, so if the
search_start is in the middle of a block group it will return the block group
after the given search_start, which is suboptimal.
This patch fixes that by doing a btrfs_lookup_block_group, which will return
the block group that contains the given search start. If we fail to find a
block group, we fall back on btrfs_lookup_first_block_group so we can find the
next block group, not sure if this is absolutely needed, but better safe than
sorry.
Also if we can't find the block group that we need, or it happens to not be of
the right type, we need to add empty_cluster since *last_ptr could point to a
mismatched block group, which means we need to start over with empty_cluster
added to total needed. Thank you,
Signed-off-by: Josef Bacik <jbacik@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/extent-tree.c')
-rw-r--r-- | fs/btrfs/extent-tree.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 8043b9d584a9..64e14ddf6232 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c | |||
@@ -2238,7 +2238,10 @@ static int noinline find_free_extent(struct btrfs_trans_handle *trans, | |||
2238 | total_needed += empty_size; | 2238 | total_needed += empty_size; |
2239 | 2239 | ||
2240 | new_group: | 2240 | new_group: |
2241 | block_group = btrfs_lookup_first_block_group(info, search_start); | 2241 | block_group = btrfs_lookup_block_group(info, search_start); |
2242 | if (!block_group) | ||
2243 | block_group = btrfs_lookup_first_block_group(info, | ||
2244 | search_start); | ||
2242 | 2245 | ||
2243 | /* | 2246 | /* |
2244 | * Ok this looks a little tricky, buts its really simple. First if we | 2247 | * Ok this looks a little tricky, buts its really simple. First if we |
@@ -2255,8 +2258,10 @@ new_group: | |||
2255 | if (!block_group || (!block_group_bits(block_group, data) && | 2258 | if (!block_group || (!block_group_bits(block_group, data) && |
2256 | last_ptr && *last_ptr)) { | 2259 | last_ptr && *last_ptr)) { |
2257 | if (search_start != orig_search_start) { | 2260 | if (search_start != orig_search_start) { |
2258 | if (last_ptr && *last_ptr) | 2261 | if (last_ptr && *last_ptr) { |
2262 | total_needed += empty_cluster; | ||
2259 | *last_ptr = 0; | 2263 | *last_ptr = 0; |
2264 | } | ||
2260 | search_start = orig_search_start; | 2265 | search_start = orig_search_start; |
2261 | goto new_group; | 2266 | goto new_group; |
2262 | } else if (!chunk_alloc_done && allowed_chunk_alloc) { | 2267 | } else if (!chunk_alloc_done && allowed_chunk_alloc) { |