summaryrefslogtreecommitdiff
path: root/extent-tree.c
diff options
context:
space:
mode:
authorYan <yanzheng@21cn.com>2007-12-05 10:41:38 -0500
committerDavid Woodhouse <dwmw2@hera.kernel.org>2007-12-05 10:41:38 -0500
commit07a4f1b81df6cd9b9e09773f680fc098faed310c (patch)
tree3543dcbdbe4fd1c153f468d2976bcebc34b72ae7 /extent-tree.c
parent1c2b38fe25fe6496d51d41aee7a5a1eb2e2694d8 (diff)
downloadbtrfs-progs-07a4f1b81df6cd9b9e09773f680fc098faed310c.tar.gz
Update btrfs-progs to better match the kernel
Diffstat (limited to 'extent-tree.c')
-rw-r--r--extent-tree.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/extent-tree.c b/extent-tree.c
index 8615a43..621f3f6 100644
--- a/extent-tree.c
+++ b/extent-tree.c
@@ -88,21 +88,34 @@ int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
struct btrfs_buffer *buf)
{
u64 bytenr;
+ u32 blocksize;
int i;
+ int level;
if (!root->ref_cows)
return 0;
+ level = btrfs_header_level(&buf->node.header) - 1;
+ blocksize = btrfs_level_size(root, level);
+
if (btrfs_is_leaf(&buf->node))
return 0;
for (i = 0; i < btrfs_header_nritems(&buf->node.header); i++) {
bytenr = btrfs_node_blockptr(&buf->node, i);
- inc_block_ref(trans, root, bytenr, root->nodesize);
+ inc_block_ref(trans, root, bytenr, blocksize);
}
+
return 0;
}
+int btrfs_inc_root_ref(struct btrfs_trans_handle *trans,
+ struct btrfs_root *root)
+{
+ return inc_block_ref(trans, root, root->node->bytenr,
+ root->node->size);
+}
+
static int write_one_cache_group(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
struct btrfs_path *path,
@@ -525,9 +538,8 @@ static int alloc_extent(struct btrfs_trans_handle *trans,
ret = insert_cache_extent(&root->fs_info->pending_tree,
ins->objectid, ins->offset);
BUG_ON(ret);
- return 0;
+ goto update_block;
}
-
ret = btrfs_insert_item(trans, extent_root, ins, &extent_item,
sizeof(extent_item));
@@ -537,9 +549,11 @@ static int alloc_extent(struct btrfs_trans_handle *trans,
return ret;
if (pending_ret)
return pending_ret;
+update_block:
+ ret = update_block_group(trans, root, ins->objectid, ins->offset, 1);
+ BUG_ON(ret);
return 0;
}
-
/*
* helper function to allocate a block for a given tree
* returns the tree buffer or NULL.
@@ -551,14 +565,12 @@ struct btrfs_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
struct btrfs_key ins;
int ret;
struct btrfs_buffer *buf;
-
ret = alloc_extent(trans, root, root->root_key.objectid,
- blocksize, 0, (unsigned long)-1, &ins);
+ blocksize, 0, (u64)-1, &ins);
if (ret) {
BUG();
return NULL;
}
- ret = update_block_group(trans, root, ins.objectid, ins.offset, 1);
buf = find_tree_block(root, ins.objectid, blocksize);
btrfs_set_header_generation(&buf->node.header,
root->root_key.offset + 1);