summaryrefslogtreecommitdiff
path: root/fs/btrfs/extent-tree.c
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2007-08-10 14:06:19 -0400
committerDavid Woodhouse <dwmw2@hera.kernel.org>2007-08-10 14:06:19 -0400
commite9d0b13b5bbb58c9b840e407a8d181442f799966 (patch)
treed51a7e111a824e883c347c83745109400231de1c /fs/btrfs/extent-tree.c
parent409eb95d7f6632d5af32b795244ce68a29e49319 (diff)
downloadlwn-e9d0b13b5bbb58c9b840e407a8d181442f799966.tar.gz
lwn-e9d0b13b5bbb58c9b840e407a8d181442f799966.zip
Btrfs: Btree defrag on the extent-mapping tree as well
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/extent-tree.c')
-rw-r--r--fs/btrfs/extent-tree.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 120c448f58f8..3418bb62b996 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -396,6 +396,14 @@ int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
return 0;
}
+int btrfs_extent_post_op(struct btrfs_trans_handle *trans,
+ struct btrfs_root *root)
+{
+ finish_current_insert(trans, root->fs_info->extent_root);
+ del_pending_extents(trans, root->fs_info->extent_root);
+ return 0;
+}
+
static int lookup_extent_ref(struct btrfs_trans_handle *trans,
struct btrfs_root *root, u64 blocknr,
u64 num_blocks, u32 *refs)
@@ -1374,7 +1382,25 @@ static int walk_down_tree(struct btrfs_trans_handle *trans, struct btrfs_root
BUG_ON(ret);
continue;
}
- next = read_tree_block(root, blocknr);
+ next = btrfs_find_tree_block(root, blocknr);
+ if (!next || !buffer_uptodate(next)) {
+ brelse(next);
+ mutex_unlock(&root->fs_info->fs_mutex);
+ next = read_tree_block(root, blocknr);
+ mutex_lock(&root->fs_info->fs_mutex);
+
+ /* we dropped the lock, check one more time */
+ ret = lookup_extent_ref(trans, root, blocknr, 1, &refs);
+ BUG_ON(ret);
+ if (refs != 1) {
+ path->slots[*level]++;
+ brelse(next);
+ ret = btrfs_free_extent(trans, root,
+ blocknr, 1, 1);
+ BUG_ON(ret);
+ continue;
+ }
+ }
WARN_ON(*level <= 0);
if (path->nodes[*level-1])
btrfs_block_release(root, path->nodes[*level-1]);