Commit 234b63a0 authored by Chris Mason's avatar Chris Mason Committed by David Woodhouse

rename funcs and structs to btrfs

Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
parent cf27e1ee
...@@ -6,47 +6,47 @@ ...@@ -6,47 +6,47 @@
#include "disk-io.h" #include "disk-io.h"
#include "print-tree.h" #include "print-tree.h"
static int split_node(struct ctree_root *root, struct ctree_path *path, static int split_node(struct btrfs_root *root, struct btrfs_path *path,
int level); int level);
static int split_leaf(struct ctree_root *root, struct ctree_path *path, static int split_leaf(struct btrfs_root *root, struct btrfs_path *path,
int data_size); int data_size);
static int push_node_left(struct ctree_root *root, struct tree_buffer *dst, static int push_node_left(struct btrfs_root *root, struct btrfs_buffer *dst,
struct tree_buffer *src); struct btrfs_buffer *src);
static int balance_node_right(struct ctree_root *root, static int balance_node_right(struct btrfs_root *root,
struct tree_buffer *dst_buf, struct btrfs_buffer *dst_buf,
struct tree_buffer *src_buf); struct btrfs_buffer *src_buf);
static int del_ptr(struct ctree_root *root, struct ctree_path *path, int level, static int del_ptr(struct btrfs_root *root, struct btrfs_path *path, int level,
int slot); int slot);
inline void init_path(struct ctree_path *p) inline void btrfs_init_path(struct btrfs_path *p)
{ {
memset(p, 0, sizeof(*p)); memset(p, 0, sizeof(*p));
} }
void release_path(struct ctree_root *root, struct ctree_path *p) void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p)
{ {
int i; int i;
for (i = 0; i < MAX_LEVEL; i++) { for (i = 0; i < BTRFS_MAX_LEVEL; i++) {
if (!p->nodes[i]) if (!p->nodes[i])
break; break;
tree_block_release(root, p->nodes[i]); btrfs_block_release(root, p->nodes[i]);
} }
memset(p, 0, sizeof(*p)); memset(p, 0, sizeof(*p));
} }
int btrfs_cow_block(struct ctree_root *root, int btrfs_cow_block(struct btrfs_root *root,
struct tree_buffer *buf, struct btrfs_buffer *buf,
struct tree_buffer *parent, struct btrfs_buffer *parent,
int parent_slot, int parent_slot,
struct tree_buffer **cow_ret) struct btrfs_buffer **cow_ret)
{ {
struct tree_buffer *cow; struct btrfs_buffer *cow;
if (!list_empty(&buf->dirty)) { if (!list_empty(&buf->dirty)) {
*cow_ret = buf; *cow_ret = buf;
return 0; return 0;
} }
cow = alloc_free_block(root); cow = btrfs_alloc_free_block(root);
memcpy(&cow->node, &buf->node, sizeof(buf->node)); memcpy(&cow->node, &buf->node, sizeof(buf->node));
btrfs_set_header_blocknr(&cow->node.header, cow->blocknr); btrfs_set_header_blocknr(&cow->node.header, cow->blocknr);
*cow_ret = cow; *cow_ret = cow;
...@@ -55,15 +55,15 @@ int btrfs_cow_block(struct ctree_root *root, ...@@ -55,15 +55,15 @@ int btrfs_cow_block(struct ctree_root *root,
root->node = cow; root->node = cow;
cow->count++; cow->count++;
if (buf != root->commit_root) if (buf != root->commit_root)
free_extent(root, buf->blocknr, 1); btrfs_free_extent(root, buf->blocknr, 1);
tree_block_release(root, buf); btrfs_block_release(root, buf);
} else { } else {
btrfs_set_node_blockptr(&parent->node, parent_slot, btrfs_set_node_blockptr(&parent->node, parent_slot,
cow->blocknr); cow->blocknr);
BUG_ON(list_empty(&parent->dirty)); BUG_ON(list_empty(&parent->dirty));
free_extent(root, buf->blocknr, 1); btrfs_free_extent(root, buf->blocknr, 1);
} }
tree_block_release(root, buf); btrfs_block_release(root, buf);
return 0; return 0;
} }
...@@ -72,7 +72,7 @@ int btrfs_cow_block(struct ctree_root *root, ...@@ -72,7 +72,7 @@ int btrfs_cow_block(struct ctree_root *root,
* this returns the address of the start of the last item, * this returns the address of the start of the last item,
* which is the stop of the leaf data stack * which is the stop of the leaf data stack
*/ */
static inline unsigned int leaf_data_end(struct leaf *leaf) static inline unsigned int leaf_data_end(struct btrfs_leaf *leaf)
{ {
u32 nr = btrfs_header_nritems(&leaf->header); u32 nr = btrfs_header_nritems(&leaf->header);
if (nr == 0) if (nr == 0)
...@@ -85,7 +85,7 @@ static inline unsigned int leaf_data_end(struct leaf *leaf) ...@@ -85,7 +85,7 @@ static inline unsigned int leaf_data_end(struct leaf *leaf)
* the start of the leaf data. IOW, how much room * the start of the leaf data. IOW, how much room
* the leaf has left for both items and data * the leaf has left for both items and data
*/ */
int leaf_free_space(struct leaf *leaf) int btrfs_leaf_free_space(struct btrfs_leaf *leaf)
{ {
int data_end = leaf_data_end(leaf); int data_end = leaf_data_end(leaf);
int nritems = btrfs_header_nritems(&leaf->header); int nritems = btrfs_header_nritems(&leaf->header);
...@@ -117,11 +117,11 @@ int comp_keys(struct btrfs_disk_key *disk, struct btrfs_key *k2) ...@@ -117,11 +117,11 @@ int comp_keys(struct btrfs_disk_key *disk, struct btrfs_key *k2)
return 0; return 0;
} }
int check_node(struct ctree_path *path, int level) int check_node(struct btrfs_path *path, int level)
{ {
int i; int i;
struct node *parent = NULL; struct btrfs_node *parent = NULL;
struct node *node = &path->nodes[level]->node; struct btrfs_node *node = &path->nodes[level]->node;
int parent_slot; int parent_slot;
u32 nritems = btrfs_header_nritems(&node->header); u32 nritems = btrfs_header_nritems(&node->header);
...@@ -146,18 +146,18 @@ int check_node(struct ctree_path *path, int level) ...@@ -146,18 +146,18 @@ int check_node(struct ctree_path *path, int level)
return 0; return 0;
} }
int check_leaf(struct ctree_path *path, int level) int check_leaf(struct btrfs_path *path, int level)
{ {
int i; int i;
struct leaf *leaf = &path->nodes[level]->leaf; struct btrfs_leaf *leaf = &path->nodes[level]->leaf;
struct node *parent = NULL; struct btrfs_node *parent = NULL;
int parent_slot; int parent_slot;
u32 nritems = btrfs_header_nritems(&leaf->header); u32 nritems = btrfs_header_nritems(&leaf->header);
if (path->nodes[level + 1]) if (path->nodes[level + 1])
parent = &path->nodes[level + 1]->node; parent = &path->nodes[level + 1]->node;
parent_slot = path->slots[level + 1]; parent_slot = path->slots[level + 1];
BUG_ON(leaf_free_space(leaf) < 0); BUG_ON(btrfs_leaf_free_space(leaf) < 0);
if (nritems == 0) if (nritems == 0)
return 0; return 0;
...@@ -186,7 +186,7 @@ int check_leaf(struct ctree_path *path, int level) ...@@ -186,7 +186,7 @@ int check_leaf(struct ctree_path *path, int level)
return 0; return 0;
} }
int check_block(struct ctree_path *path, int level) int check_block(struct btrfs_path *path, int level)
{ {
if (level == 0) if (level == 0)
return check_leaf(path, level); return check_leaf(path, level);
...@@ -233,10 +233,10 @@ int generic_bin_search(char *p, int item_size, struct btrfs_key *key, ...@@ -233,10 +233,10 @@ int generic_bin_search(char *p, int item_size, struct btrfs_key *key,
* simple bin_search frontend that does the right thing for * simple bin_search frontend that does the right thing for
* leaves vs nodes * leaves vs nodes
*/ */
int bin_search(struct node *c, struct btrfs_key *key, int *slot) int bin_search(struct btrfs_node *c, struct btrfs_key *key, int *slot)
{ {
if (btrfs_is_leaf(c)) { if (btrfs_is_leaf(c)) {
struct leaf *l = (struct leaf *)c; struct btrfs_leaf *l = (struct btrfs_leaf *)c;
return generic_bin_search((void *)l->items, return generic_bin_search((void *)l->items,
sizeof(struct btrfs_item), sizeof(struct btrfs_item),
key, btrfs_header_nritems(&c->header), key, btrfs_header_nritems(&c->header),
...@@ -250,11 +250,11 @@ int bin_search(struct node *c, struct btrfs_key *key, int *slot) ...@@ -250,11 +250,11 @@ int bin_search(struct node *c, struct btrfs_key *key, int *slot)
return -1; return -1;
} }
struct tree_buffer *read_node_slot(struct ctree_root *root, struct btrfs_buffer *read_node_slot(struct btrfs_root *root,
struct tree_buffer *parent_buf, struct btrfs_buffer *parent_buf,
int slot) int slot)
{ {
struct node *node = &parent_buf->node; struct btrfs_node *node = &parent_buf->node;
if (slot < 0) if (slot < 0)
return NULL; return NULL;
if (slot >= btrfs_header_nritems(&node->header)) if (slot >= btrfs_header_nritems(&node->header))
...@@ -262,17 +262,17 @@ struct tree_buffer *read_node_slot(struct ctree_root *root, ...@@ -262,17 +262,17 @@ struct tree_buffer *read_node_slot(struct ctree_root *root,
return read_tree_block(root, btrfs_node_blockptr(node, slot)); return read_tree_block(root, btrfs_node_blockptr(node, slot));
} }
static int balance_level(struct ctree_root *root, struct ctree_path *path, static int balance_level(struct btrfs_root *root, struct btrfs_path *path,
int level) int level)
{ {
struct tree_buffer *right_buf; struct btrfs_buffer *right_buf;
struct tree_buffer *mid_buf; struct btrfs_buffer *mid_buf;
struct tree_buffer *left_buf; struct btrfs_buffer *left_buf;
struct tree_buffer *parent_buf = NULL; struct btrfs_buffer *parent_buf = NULL;
struct node *right = NULL; struct btrfs_node *right = NULL;
struct node *mid; struct btrfs_node *mid;
struct node *left = NULL; struct btrfs_node *left = NULL;
struct node *parent = NULL; struct btrfs_node *parent = NULL;
int ret = 0; int ret = 0;
int wret; int wret;
int pslot; int pslot;
...@@ -286,12 +286,12 @@ static int balance_level(struct ctree_root *root, struct ctree_path *path, ...@@ -286,12 +286,12 @@ static int balance_level(struct ctree_root *root, struct ctree_path *path,
mid = &mid_buf->node; mid = &mid_buf->node;
orig_ptr = btrfs_node_blockptr(mid, orig_slot); orig_ptr = btrfs_node_blockptr(mid, orig_slot);
if (level < MAX_LEVEL - 1) if (level < BTRFS_MAX_LEVEL - 1)
parent_buf = path->nodes[level + 1]; parent_buf = path->nodes[level + 1];
pslot = path->slots[level + 1]; pslot = path->slots[level + 1];
if (!parent_buf) { if (!parent_buf) {
struct tree_buffer *child; struct btrfs_buffer *child;
u64 blocknr = mid_buf->blocknr; u64 blocknr = mid_buf->blocknr;
if (btrfs_header_nritems(&mid->header) != 1) if (btrfs_header_nritems(&mid->header) != 1)
...@@ -303,11 +303,11 @@ static int balance_level(struct ctree_root *root, struct ctree_path *path, ...@@ -303,11 +303,11 @@ static int balance_level(struct ctree_root *root, struct ctree_path *path,
root->node = child; root->node = child;
path->nodes[level] = NULL; path->nodes[level] = NULL;
/* once for the path */ /* once for the path */
tree_block_release(root, mid_buf); btrfs_block_release(root, mid_buf);
/* once for the root ptr */ /* once for the root ptr */
tree_block_release(root, mid_buf); btrfs_block_release(root, mid_buf);
clean_tree_block(root, mid_buf); clean_tree_block(root, mid_buf);
return free_extent(root, blocknr, 1); return btrfs_free_extent(root, blocknr, 1);
} }
parent = &parent_buf->node; parent = &parent_buf->node;
...@@ -340,14 +340,14 @@ static int balance_level(struct ctree_root *root, struct ctree_path *path, ...@@ -340,14 +340,14 @@ static int balance_level(struct ctree_root *root, struct ctree_path *path,
ret = wret; ret = wret;
if (btrfs_header_nritems(&right->header) == 0) { if (btrfs_header_nritems(&right->header) == 0) {
u64 blocknr = right_buf->blocknr; u64 blocknr = right_buf->blocknr;
tree_block_release(root, right_buf); btrfs_block_release(root, right_buf);
clean_tree_block(root, right_buf); clean_tree_block(root, right_buf);
right_buf = NULL; right_buf = NULL;
right = NULL; right = NULL;
wret = del_ptr(root, path, level + 1, pslot + 1); wret = del_ptr(root, path, level + 1, pslot + 1);
if (wret) if (wret)
ret = wret; ret = wret;
wret = free_extent(root, blocknr, 1); wret = btrfs_free_extent(root, blocknr, 1);
if (wret) if (wret)
ret = wret; ret = wret;
} else { } else {
...@@ -375,14 +375,14 @@ static int balance_level(struct ctree_root *root, struct ctree_path *path, ...@@ -375,14 +375,14 @@ static int balance_level(struct ctree_root *root, struct ctree_path *path,
if (btrfs_header_nritems(&mid->header) == 0) { if (btrfs_header_nritems(&mid->header) == 0) {
/* we've managed to empty the middle node, drop it */ /* we've managed to empty the middle node, drop it */
u64 blocknr = mid_buf->blocknr; u64 blocknr = mid_buf->blocknr;
tree_block_release(root, mid_buf); btrfs_block_release(root, mid_buf);
clean_tree_block(root, mid_buf); clean_tree_block(root, mid_buf);
mid_buf = NULL; mid_buf = NULL;
mid = NULL; mid = NULL;
wret = del_ptr(root, path, level + 1, pslot); wret = del_ptr(root, path, level + 1, pslot);
if (wret) if (wret)
ret = wret; ret = wret;
wret = free_extent(root, blocknr, 1); wret = btrfs_free_extent(root, blocknr, 1);
if (wret) if (wret)
ret = wret; ret = wret;
} else { } else {
...@@ -400,7 +400,7 @@ static int balance_level(struct ctree_root *root, struct ctree_path *path, ...@@ -400,7 +400,7 @@ static int balance_level(struct ctree_root *root, struct ctree_path *path,
path->slots[level + 1] -= 1; path->slots[level + 1] -= 1;
path->slots[level] = orig_slot; path->slots[level] = orig_slot;
if (mid_buf) if (mid_buf)
tree_block_release(root, mid_buf); btrfs_block_release(root, mid_buf);
} else { } else {
orig_slot -= btrfs_header_nritems(&left->header); orig_slot -= btrfs_header_nritems(&left->header);
path->slots[level] = orig_slot; path->slots[level] = orig_slot;
...@@ -413,9 +413,9 @@ static int balance_level(struct ctree_root *root, struct ctree_path *path, ...@@ -413,9 +413,9 @@ static int balance_level(struct ctree_root *root, struct ctree_path *path,
BUG(); BUG();
if (right_buf) if (right_buf)
tree_block_release(root, right_buf); btrfs_block_release(root, right_buf);
if (left_buf) if (left_buf)
tree_block_release(root, left_buf); btrfs_block_release(root, left_buf);
return ret; return ret;
} }
...@@ -432,12 +432,12 @@ static int balance_level(struct ctree_root *root, struct ctree_path *path, ...@@ -432,12 +432,12 @@ static int balance_level(struct ctree_root *root, struct ctree_path *path,
* tree. if ins_len < 0, nodes will be merged as we walk down the tree (if * tree. if ins_len < 0, nodes will be merged as we walk down the tree (if
* possible) * possible)
*/ */
int search_slot(struct ctree_root *root, struct btrfs_key *key, int btrfs_search_slot(struct btrfs_root *root, struct btrfs_key *key,
struct ctree_path *p, int ins_len, int cow) struct btrfs_path *p, int ins_len, int cow)
{ {
struct tree_buffer *b; struct btrfs_buffer *b;
struct tree_buffer *cow_buf; struct btrfs_buffer *cow_buf;
struct node *c; struct btrfs_node *c;
int slot; int slot;
int ret; int ret;
int level; int level;
...@@ -486,9 +486,9 @@ int search_slot(struct ctree_root *root, struct btrfs_key *key, ...@@ -486,9 +486,9 @@ int search_slot(struct ctree_root *root, struct btrfs_key *key,
} }
b = read_tree_block(root, btrfs_node_blockptr(c, slot)); b = read_tree_block(root, btrfs_node_blockptr(c, slot));
} else { } else {
struct leaf *l = (struct leaf *)c; struct btrfs_leaf *l = (struct btrfs_leaf *)c;
p->slots[level] = slot; p->slots[level] = slot;
if (ins_len > 0 && leaf_free_space(l) < if (ins_len > 0 && btrfs_leaf_free_space(l) <
sizeof(struct btrfs_item) + ins_len) { sizeof(struct btrfs_item) + ins_len) {
int sret = split_leaf(root, p, ins_len); int sret = split_leaf(root, p, ins_len);
BUG_ON(sret > 0); BUG_ON(sret > 0);
...@@ -513,14 +513,14 @@ int search_slot(struct ctree_root *root, struct btrfs_key *key, ...@@ -513,14 +513,14 @@ int search_slot(struct ctree_root *root, struct btrfs_key *key,
* If this fails to write a tree block, it returns -1, but continues * If this fails to write a tree block, it returns -1, but continues
* fixing up the blocks in ram so the tree is consistent. * fixing up the blocks in ram so the tree is consistent.
*/ */
static int fixup_low_keys(struct ctree_root *root, static int fixup_low_keys(struct btrfs_root *root,
struct ctree_path *path, struct btrfs_disk_key *key, struct btrfs_path *path, struct btrfs_disk_key *key,
int level) int level)
{ {
int i; int i;
int ret = 0; int ret = 0;
for (i = level; i < MAX_LEVEL; i++) { for (i = level; i < BTRFS_MAX_LEVEL; i++) {
struct node *t; struct btrfs_node *t;
int tslot = path->slots[i]; int tslot = path->slots[i];
if (!path->nodes[i]) if (!path->nodes[i])
break; break;
...@@ -540,11 +540,11 @@ static int fixup_low_keys(struct ctree_root *root, ...@@ -540,11 +540,11 @@ static int fixup_low_keys(struct ctree_root *root,
* returns 0 if some ptrs were pushed left, < 0 if there was some horrible * returns 0 if some ptrs were pushed left, < 0 if there was some horrible
* error, and > 0 if there was no room in the left hand block. * error, and > 0 if there was no room in the left hand block.
*/ */
static int push_node_left(struct ctree_root *root, struct tree_buffer *dst_buf, static int push_node_left(struct btrfs_root *root, struct btrfs_buffer *dst_buf,
struct tree_buffer *src_buf) struct btrfs_buffer *src_buf)
{ {
struct node *src = &src_buf->node; struct btrfs_node *src = &src_buf->node;
struct node *dst = &dst_buf->node; struct btrfs_node *dst = &dst_buf->node;
int push_items = 0; int push_items = 0;
int src_nritems; int src_nritems;
int dst_nritems; int dst_nritems;
...@@ -587,12 +587,12 @@ static int push_node_left(struct ctree_root *root, struct tree_buffer *dst_buf, ...@@ -587,12 +587,12 @@ static int push_node_left(struct ctree_root *root, struct tree_buffer *dst_buf,
* *
* this will only push up to 1/2 the contents of the left node over * this will only push up to 1/2 the contents of the left node over
*/ */
static int balance_node_right(struct ctree_root *root, static int balance_node_right(struct btrfs_root *root,
struct tree_buffer *dst_buf, struct btrfs_buffer *dst_buf,
struct tree_buffer *src_buf) struct btrfs_buffer *src_buf)
{ {
struct node *src = &src_buf->node; struct btrfs_node *src = &src_buf->node;
struct node *dst = &dst_buf->node; struct btrfs_node *dst = &dst_buf->node;
int push_items = 0; int push_items = 0;
int max_push; int max_push;
int src_nritems; int src_nritems;
...@@ -637,18 +637,18 @@ static int balance_node_right(struct ctree_root *root, ...@@ -637,18 +637,18 @@ static int balance_node_right(struct ctree_root *root,
* *
* returns zero on success or < 0 on failure. * returns zero on success or < 0 on failure.
*/ */
static int insert_new_root(struct ctree_root *root, static int insert_new_root(struct btrfs_root *root,
struct ctree_path *path, int level) struct btrfs_path *path, int level)
{ {
struct tree_buffer *t; struct btrfs_buffer *t;
struct node *lower; struct btrfs_node *lower;
struct node *c; struct btrfs_node *c;
struct btrfs_disk_key *lower_key; struct btrfs_disk_key *lower_key;
BUG_ON(path->nodes[level]); BUG_ON(path->nodes[level]);
BUG_ON(path->nodes[level-1] != root->node); BUG_ON(path->nodes[level-1] != root->node);
t = alloc_free_block(root); t = btrfs_alloc_free_block(root);
c = &t->node; c = &t->node;
memset(c, 0, sizeof(c)); memset(c, 0, sizeof(c));
btrfs_set_header_nritems(&c->header, 1); btrfs_set_header_nritems(&c->header, 1);
...@@ -658,13 +658,13 @@ static int insert_new_root(struct ctree_root *root, ...@@ -658,13 +658,13 @@ static int insert_new_root(struct ctree_root *root,
btrfs_header_parentid(&root->node->node.header)); btrfs_header_parentid(&root->node->node.header));
lower = &path->nodes[level-1]->node; lower = &path->nodes[level-1]->node;
if (btrfs_is_leaf(lower)) if (btrfs_is_leaf(lower))
lower_key = &((struct leaf *)lower)->items[0].key; lower_key = &((struct btrfs_leaf *)lower)->items[0].key;
else else
lower_key = lower->keys; lower_key = lower->keys;
memcpy(c->keys, lower_key, sizeof(struct btrfs_disk_key)); memcpy(c->keys, lower_key, sizeof(struct btrfs_disk_key));
btrfs_set_node_blockptr(c, 0, path->nodes[level - 1]->blocknr); btrfs_set_node_blockptr(c, 0, path->nodes[level - 1]->blocknr);
/* the super has an extra ref to root->node */ /* the super has an extra ref to root->node */
tree_block_release(root, root->node); btrfs_block_release(root, root->node);
root->node = t; root->node = t;
t->count++; t->count++;
path->nodes[level] = t; path->nodes[level] = t;
...@@ -681,11 +681,11 @@ static int insert_new_root(struct ctree_root *root, ...@@ -681,11 +681,11 @@ static int insert_new_root(struct ctree_root *root,
* *
* returns zero on success and < 0 on any error * returns zero on success and < 0 on any error
*/ */
static int insert_ptr(struct ctree_root *root, static int insert_ptr(struct btrfs_root *root,
struct ctree_path *path, struct btrfs_disk_key *key, struct btrfs_path *path, struct btrfs_disk_key *key,
u64 blocknr, int slot, int level) u64 blocknr, int slot, int level)
{ {
struct node *lower; struct btrfs_node *lower;
int nritems; int nritems;
BUG_ON(!path->nodes[level]); BUG_ON(!path->nodes[level]);
...@@ -719,13 +719,13 @@ static int insert_ptr(struct ctree_root *root, ...@@ -719,13 +719,13 @@ static int insert_ptr(struct ctree_root *root,
* *
* returns 0 on success and < 0 on failure * returns 0 on success and < 0 on failure
*/ */
static int split_node(struct ctree_root *root, struct ctree_path *path, static int split_node(struct btrfs_root *root, struct btrfs_path *path,
int level) int level)
{ {
struct tree_buffer *t; struct btrfs_buffer *t;
struct node *c; struct btrfs_node *c;
struct tree_buffer *split_buffer; struct btrfs_buffer *split_buffer;
struct node *split; struct btrfs_node *split;
int mid; int mid;
int ret; int ret;
int wret; int wret;
...@@ -740,7 +740,7 @@ static int split_node(struct ctree_root *root, struct ctree_path *path, ...@@ -740,7 +740,7 @@ static int split_node(struct ctree_root *root, struct ctree_path *path,
return ret; return ret;
} }
c_nritems = btrfs_header_nritems(&c->header); c_nritems = btrfs_header_nritems(&c->header);
split_buffer = alloc_free_block(root); split_buffer = btrfs_alloc_free_block(root);
split = &split_buffer->node; split = &split_buffer->node;
btrfs_set_header_flags(&split->header, btrfs_header_flags(&c->header)); btrfs_set_header_flags(&split->header, btrfs_header_flags(&c->header));
btrfs_set_header_blocknr(&split->header, split_buffer->blocknr); btrfs_set_header_blocknr(&split->header, split_buffer->blocknr);
...@@ -763,11 +763,11 @@ static int split_node(struct ctree_root *root, struct ctree_path *path, ...@@ -763,11 +763,11 @@ static int split_node(struct ctree_root *root, struct ctree_path *path,
if (path->slots[level] >= mid) { if (path->slots[level] >= mid) {
path->slots[level] -= mid; path->slots[level] -= mid;
tree_block_release(root, t); btrfs_block_release(root, t);
path->nodes[level] = split_buffer; path->nodes[level] = split_buffer;
path->slots[level + 1] += 1; path->slots[level + 1] += 1;
} else { } else {
tree_block_release(root, split_buffer); btrfs_block_release(root, split_buffer);
} }
return ret; return ret;
} }
...@@ -777,7 +777,7 @@ static int split_node(struct ctree_root *root, struct ctree_path *path, ...@@ -777,7 +777,7 @@ static int split_node(struct ctree_root *root, struct ctree_path *path,
* and nr indicate which items in the leaf to check. This totals up the * and nr indicate which items in the leaf to check. This totals up the
* space used both by the item structs and the item data * space used both by the item structs and the item data
*/ */
static int leaf_space_used(struct leaf *l, int start, int nr) static int leaf_space_used(struct btrfs_leaf *l, int start, int nr)
{ {
int data_len; int data_len;
int end = start + nr - 1; int end = start + nr - 1;
...@@ -797,14 +797,14 @@ static int leaf_space_used(struct leaf *l, int start, int nr) ...@@ -797,14 +797,14 @@ static int leaf_space_used(struct leaf *l, int start, int nr)
* returns 1 if the push failed because the other node didn't have enough * returns 1 if the push failed because the other node didn't have enough
* room, 0 if everything worked out and < 0 if there were major errors. * room, 0 if everything worked out and < 0 if there were major errors.
*/ */
static int push_leaf_right(struct ctree_root *root, struct ctree_path *path, static int push_leaf_right(struct btrfs_root *root, struct btrfs_path *path,
int data_size) int data_size)
{ {
struct tree_buffer *left_buf = path->nodes[0]; struct btrfs_buffer *left_buf = path->nodes[0];
struct leaf *left = &left_buf->leaf; struct btrfs_leaf *left = &left_buf->leaf;
struct leaf *right; struct btrfs_leaf *right;
struct tree_buffer *right_buf; struct btrfs_buffer *right_buf;
struct tree_buffer *upper; struct btrfs_buffer *upper;
int slot; int slot;
int i; int i;
int free_space; int free_space;
...@@ -825,17 +825,17 @@ static int push_leaf_right(struct ctree_root *root, struct ctree_path *path, ...@@ -825,17 +825,17 @@ static int push_leaf_right(struct ctree_root *root, struct ctree_path *path,
right_buf = read_tree_block(root, btrfs_node_blockptr(&upper->node, right_buf = read_tree_block(root, btrfs_node_blockptr(&upper->node,
slot + 1)); slot + 1));
right = &right_buf->leaf; right = &right_buf->leaf;
free_space = leaf_free_space(right); free_space = btrfs_leaf_free_space(right);
if (free_space < data_size + sizeof(struct btrfs_item)) { if (free_space < data_size + sizeof(struct btrfs_item)) {
tree_block_release(root, right_buf); btrfs_block_release(root, right_buf);
return 1; return 1;
} }
/* cow and double check */ /* cow and double check */
btrfs_cow_block(root, right_buf, upper, slot + 1, &right_buf); btrfs_cow_block(root, right_buf, upper, slot + 1, &right_buf);
right = &right_buf->leaf; right = &right_buf->leaf;
free_space = leaf_free_space(right); free_space = btrfs_leaf_free_space(right);
if (free_space < data_size + sizeof(struct btrfs_item)) { if (free_space < data_size + sizeof(struct btrfs_item)) {
tree_block_release(root, right_buf); btrfs_block_release(root, right_buf);
return 1; return 1;
} }
...@@ -851,7 +851,7 @@ static int push_leaf_right(struct ctree_root *root, struct ctree_path *path, ...@@ -851,7 +851,7 @@ static int push_leaf_right(struct ctree_root *root, struct ctree_path *path,
push_space += btrfs_item_size(item) + sizeof(*item); push_space += btrfs_item_size(item) + sizeof(*item);
} }
if (push_items == 0) { if (push_items == 0) {
tree_block_release(root, right_buf); btrfs_block_release(root, right_buf);
return 1; return 1;
} }
right_nritems = btrfs_header_nritems(&right->header); right_nritems = btrfs_header_nritems(&right->header);
...@@ -893,11 +893,11 @@ static int push_leaf_right(struct ctree_root *root, struct ctree_path *path, ...@@ -893,11 +893,11 @@ static int push_leaf_right(struct ctree_root *root, struct ctree_path *path,
/* then fixup the leaf pointer in the path */ /* then fixup the leaf pointer in the path */
if (path->slots[0] >= left_nritems) { if (path->slots[0] >= left_nritems) {
path->slots[0] -= left_nritems; path->slots[0] -= left_nritems;
tree_block_release(root, path->nodes[0]); btrfs_block_release(root, path->nodes[0]);
path->nodes[0] = right_buf; path->nodes[0] = right_buf;
path->slots[1] += 1; path->slots[1] += 1;
} else { } else {
tree_block_release(root, right_buf); btrfs_block_release(root, right_buf);
} }
return 0; return 0;
} }
...@@ -905,13 +905,13 @@ static int push_leaf_right(struct ctree_root *root, struct ctree_path *path, ...@@ -905,13 +905,13 @@ static int push_leaf_right(struct ctree_root *root, struct ctree_path *path,
* push some data in the path leaf to the left, trying to free up at * push some data in the path leaf to the left, trying to free up at
* least data_size bytes. returns zero if the push worked, nonzero otherwise * least data_size bytes. returns zero if the push worked, nonzero otherwise
*/ */
static int push_leaf_left(struct ctree_root *root, struct ctree_path *path, static int push_leaf_left(struct btrfs_root *root, struct btrfs_path *path,
int data_size) int data_size)
{ {
struct tree_buffer *right_buf = path->nodes[0]; struct btrfs_buffer *right_buf = path->nodes[0];
struct leaf *right = &right_buf->leaf; struct btrfs_leaf *right = &right_buf->leaf;
struct tree_buffer *t; struct btrfs_buffer *t;
struct leaf *left; struct btrfs_leaf *left;
int slot; int slot;
int i; int i;
int free_space; int free_space;
...@@ -932,18 +932,18 @@ static int push_leaf_left(struct ctree_root *root, struct ctree_path *path, ...@@ -932,18 +932,18 @@ static int push_leaf_left(struct ctree_root *root, struct ctree_path *path,
t = read_tree_block(root, btrfs_node_blockptr(&path->nodes[1]->node, t = read_tree_block(root, btrfs_node_blockptr(&path->nodes[1]->node,
slot - 1)); slot - 1));
left = &t->leaf; left = &t->leaf;
free_space = leaf_free_space(left); free_space = btrfs_leaf_free_space(left);
if (free_space < data_size + sizeof(struct btrfs_item)) { if (free_space < data_size + sizeof(struct btrfs_item)) {
tree_block_release(root, t); btrfs_block_release(root, t);
return 1; return 1;
} }
/* cow and double check */ /* cow and double check */
btrfs_cow_block(root, t, path->nodes[1], slot - 1, &t); btrfs_cow_block(root, t, path->nodes[1], slot - 1, &t);
left = &t->leaf; left = &t->leaf;
free_space = leaf_free_space(left); free_space = btrfs_leaf_free_space(left);
if (free_space < data_size + sizeof(struct btrfs_item)) { if (free_space < data_size + sizeof(struct btrfs_item)) {
tree_block_release(root, t); btrfs_block_release(root, t);
return 1; return 1;
} }
...@@ -958,7 +958,7 @@ static int push_leaf_left(struct ctree_root *root, struct ctree_path *path, ...@@ -958,7 +958,7 @@ static int push_leaf_left(struct ctree_root *root, struct ctree_path *path,
push_space += btrfs_item_size(item) + sizeof(*item); push_space += btrfs_item_size(item) + sizeof(*item);
} }
if (push_items == 0) { if (push_items == 0) {
tree_block_release(root, t); btrfs_block_release(root, t);
return 1; return 1;
} }
/* push data from right to left */ /* push data from right to left */
...@@ -1009,11 +1009,11 @@ static int push_leaf_left(struct ctree_root *root, struct ctree_path *path, ...@@ -1009,11 +1009,11 @@ static int push_leaf_left(struct ctree_root *root, struct ctree_path *path,
/* then fixup the leaf pointer in the path */ /* then fixup the leaf pointer in the path */
if (path->slots[0] < push_items) { if (path->slots[0] < push_items) {
path->slots[0] += old_left_nritems; path->slots[0] += old_left_nritems;
tree_block_release(root, path->nodes[0]); btrfs_block_release(root, path->nodes[0]);
path->nodes[0] = t; path->nodes[0] = t;
path->slots[1] -= 1; path->slots[1] -= 1;
} else { } else {
tree_block_release(root, t); btrfs_block_release(root, t);
path->slots[0] -= push_items; path->slots[0] -= push_items;
} }
BUG_ON(path->slots[0] < 0); BUG_ON(path->slots[0] < 0);
...@@ -1026,16 +1026,16 @@ static int push_leaf_left(struct ctree_root *root, struct ctree_path *path, ...@@ -1026,16 +1026,16 @@ static int push_leaf_left(struct ctree_root *root, struct ctree_path *path,
* *
* returns 0 if all went well and < 0 on failure. * returns 0 if all went well and < 0 on failure.
*/ */
static int split_leaf(struct ctree_root *root, struct ctree_path *path, static int split_leaf(struct btrfs_root *root, struct btrfs_path *path,
int data_size) int data_size)
{ {
struct tree_buffer *l_buf; struct btrfs_buffer *l_buf;
struct leaf *l; struct btrfs_leaf *l;
u32 nritems; u32 nritems;
int mid; int mid;
int slot; int slot;
struct leaf *right; struct btrfs_leaf *right;
struct tree_buffer *right_buffer; struct btrfs_buffer *right_buffer;
int space_needed = data_size + sizeof(struct btrfs_item); int space_needed = data_size + sizeof(struct btrfs_item);
int data_copy_size; int data_copy_size;
int rt_data_off; int rt_data_off;
...@@ -1047,7 +1047,7 @@ static int split_leaf(struct ctree_root *root, struct ctree_path *path, ...@@ -1047,7 +1047,7 @@ static int split_leaf(struct ctree_root *root, struct ctree_path *path,
l = &l_buf->leaf; l = &l_buf->leaf;
/* did the pushes work? */ /* did the pushes work? */
if (leaf_free_space(l) >= sizeof(struct btrfs_item) + data_size) if (btrfs_leaf_free_space(l) >= sizeof(struct btrfs_item) + data_size)
return 0; return 0;
if (!path->nodes[1]) { if (!path->nodes[1]) {
...@@ -1058,7 +1058,7 @@ static int split_leaf(struct ctree_root *root, struct ctree_path *path, ...@@ -1058,7 +1058,7 @@ static int split_leaf(struct ctree_root *root, struct ctree_path *path,
slot = path->slots[0]; slot = path->slots[0];
nritems = btrfs_header_nritems(&l->header); nritems = btrfs_header_nritems(&l->header);
mid = (nritems + 1)/ 2; mid = (nritems + 1)/ 2;
right_buffer = alloc_free_block(root); right_buffer = btrfs_alloc_free_block(root);
BUG_ON(!right_buffer); BUG_ON(!right_buffer);
BUG_ON(mid == nritems); BUG_ON(mid == nritems);
right = &right_buffer->leaf; right = &right_buffer->leaf;
...@@ -1101,12 +1101,12 @@ static int split_leaf(struct ctree_root *root, struct ctree_path *path, ...@@ -1101,12 +1101,12 @@ static int split_leaf(struct ctree_root *root, struct ctree_path *path,
BUG_ON(list_empty(&l_buf->dirty)); BUG_ON(list_empty(&l_buf->dirty));
BUG_ON(path->slots[0] != slot); BUG_ON(path->slots[0] != slot);
if (mid <= slot) { if (mid <= slot) {
tree_block_release(root, path->nodes[0]); btrfs_block_release(root, path->nodes[0]);
path->nodes[0] = right_buffer; path->nodes[0] = right_buffer;
path->slots[0] -= mid; path->slots[0] -= mid;
path->slots[1] += 1; path->slots[1] += 1;
} else } else
tree_block_release(root, right_buffer); btrfs_block_release(root, right_buffer);
BUG_ON(path->slots[0] < 0); BUG_ON(path->slots[0] < 0);
return ret; return ret;
} }
...@@ -1115,17 +1115,17 @@ static int split_leaf(struct ctree_root *root, struct ctree_path *path, ...@@ -1115,17 +1115,17 @@ static int split_leaf(struct ctree_root *root, struct ctree_path *path,
* Given a key and some data, insert an item into the tree. * Given a key and some data, insert an item into the tree.
* This does all the path init required, making room in the tree if needed. * This does all the path init required, making room in the tree if needed.
*/ */
int insert_item(struct ctree_root *root, struct btrfs_key *cpu_key, int btrfs_insert_item(struct btrfs_root *root, struct btrfs_key *cpu_key,
void *data, int data_size) void *data, int data_size)
{ {
int ret = 0; int ret = 0;
int slot; int slot;
int slot_orig; int slot_orig;
struct leaf *leaf; struct btrfs_leaf *leaf;
struct tree_buffer *leaf_buf; struct btrfs_buffer *leaf_buf;
u32 nritems; u32 nritems;
unsigned int data_end; unsigned int data_end;
struct ctree_path path; struct btrfs_path path;
struct btrfs_disk_key disk_key; struct btrfs_disk_key disk_key;
btrfs_cpu_key_to_disk(&disk_key, cpu_key); btrfs_cpu_key_to_disk(&disk_key, cpu_key);
...@@ -1133,10 +1133,10 @@ int insert_item(struct ctree_root *root, struct btrfs_key *cpu_key, ...@@ -1133,10 +1133,10 @@ int insert_item(struct ctree_root *root, struct btrfs_key *cpu_key,
/* create a root if there isn't one */ /* create a root if there isn't one */
if (!root->node) if (!root->node)
BUG(); BUG();
init_path(&path); btrfs_init_path(&path);
ret = search_slot(root, cpu_key, &path, data_size, 1); ret = btrfs_search_slot(root, cpu_key, &path, data_size, 1);
if (ret == 0) { if (ret == 0) {
release_path(root, &path); btrfs_release_path(root, &path);
return -EEXIST; return -EEXIST;
} }
if (ret < 0) if (ret < 0)
...@@ -1149,7 +1149,8 @@ int insert_item(struct ctree_root *root, struct btrfs_key *cpu_key, ...@@ -1149,7 +1149,8 @@ int insert_item(struct ctree_root *root, struct btrfs_key *cpu_key,
nritems = btrfs_header_nritems(&leaf->header); nritems = btrfs_header_nritems(&leaf->header);
data_end = leaf_data_end(leaf); data_end = leaf_data_end(leaf);
if (leaf_free_space(leaf) < sizeof(struct btrfs_item) + data_size) if (btrfs_leaf_free_space(leaf) <
sizeof(struct btrfs_item) + data_size)
BUG(); BUG();
slot = path.slots[0]; slot = path.slots[0];
...@@ -1190,11 +1191,11 @@ int insert_item(struct ctree_root *root, struct btrfs_key *cpu_key, ...@@ -1190,11 +1191,11 @@ int insert_item(struct ctree_root *root, struct btrfs_key *cpu_key,
ret = fixup_low_keys(root, &path, &disk_key, 1); ret = fixup_low_keys(root, &path, &disk_key, 1);
BUG_ON(list_empty(&leaf_buf->dirty)); BUG_ON(list_empty(&leaf_buf->dirty));
if (leaf_free_space(leaf) < 0) if (btrfs_leaf_free_space(leaf) < 0)
BUG(); BUG();
check_leaf(&path, 0); check_leaf(&path, 0);
out: out:
release_path(root, &path); btrfs_release_path(root, &path);
return ret; return ret;
} }
...@@ -1205,11 +1206,11 @@ int insert_item(struct ctree_root *root, struct btrfs_key *cpu_key, ...@@ -1205,11 +1206,11 @@ int insert_item(struct ctree_root *root, struct btrfs_key *cpu_key,
* continuing all the way the root if required. The root is converted into * continuing all the way the root if required. The root is converted into
* a leaf if all the nodes are emptied. * a leaf if all the nodes are emptied.
*/ */
static int del_ptr(struct ctree_root *root, struct ctree_path *path, int level, static int del_ptr(struct btrfs_root *root, struct btrfs_path *path, int level,
int slot) int slot)
{ {
struct node *node; struct btrfs_node *node;
struct tree_buffer *parent = path->nodes[level]; struct btrfs_buffer *parent = path->nodes[level];
u32 nritems; u32 nritems;
int ret = 0; int ret = 0;
int wret; int wret;
...@@ -1242,11 +1243,11 @@ static int del_ptr(struct ctree_root *root, struct ctree_path *path, int level, ...@@ -1242,11 +1243,11 @@ static int del_ptr(struct ctree_root *root, struct ctree_path *path, int level,
* delete the item at the leaf level in path. If that empties * delete the item at the leaf level in path. If that empties
* the leaf, remove it from the tree * the leaf, remove it from the tree
*/ */
int del_item(struct ctree_root *root, struct ctree_path *path) int btrfs_del_item(struct btrfs_root *root, struct btrfs_path *path)
{ {
int slot; int slot;
struct leaf *leaf; struct btrfs_leaf *leaf;
struct tree_buffer *leaf_buf; struct btrfs_buffer *leaf_buf;
int doff; int doff;
int dsize; int dsize;
int ret = 0; int ret = 0;
...@@ -1286,7 +1287,7 @@ int del_item(struct ctree_root *root, struct ctree_path *path) ...@@ -1286,7 +1287,7 @@ int del_item(struct ctree_root *root, struct ctree_path *path)
wret = del_ptr(root, path, 1, path->slots[1]); wret = del_ptr(root, path, 1, path->slots[1]);
if (wret) if (wret)
ret = wret; ret = wret;
wret = free_extent(root, leaf_buf->blocknr, 1); wret = btrfs_free_extent(root, leaf_buf->blocknr, 1);
if (wret) if (wret)
ret = wret; ret = wret;
} }
...@@ -1323,12 +1324,12 @@ int del_item(struct ctree_root *root, struct ctree_path *path) ...@@ -1323,12 +1324,12 @@ int del_item(struct ctree_root *root, struct ctree_path *path)
wret = del_ptr(root, path, 1, slot); wret = del_ptr(root, path, 1, slot);
if (wret) if (wret)
ret = wret; ret = wret;
tree_block_release(root, leaf_buf); btrfs_block_release(root, leaf_buf);
wret = free_extent(root, blocknr, 1); wret = btrfs_free_extent(root, blocknr, 1);
if (wret) if (wret)
ret = wret; ret = wret;
} else { } else {
tree_block_release(root, leaf_buf); btrfs_block_release(root, leaf_buf);
} }
} }
} }
...@@ -1340,15 +1341,15 @@ int del_item(struct ctree_root *root, struct ctree_path *path) ...@@ -1340,15 +1341,15 @@ int del_item(struct ctree_root *root, struct ctree_path *path)
* returns 0 if it found something or 1 if there are no greater leaves. * returns 0 if it found something or 1 if there are no greater leaves.
* returns < 0 on io errors. * returns < 0 on io errors.
*/ */
int next_leaf(struct ctree_root *root, struct ctree_path *path) int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path)
{ {
int slot; int slot;
int level = 1; int level = 1;
u64 blocknr; u64 blocknr;
struct tree_buffer *c; struct btrfs_buffer *c;
struct tree_buffer *next = NULL; struct btrfs_buffer *next = NULL;
while(level < MAX_LEVEL) { while(level < BTRFS_MAX_LEVEL) {
if (!path->nodes[level]) if (!path->nodes[level])
return 1; return 1;
slot = path->slots[level] + 1; slot = path->slots[level] + 1;
...@@ -1359,7 +1360,7 @@ int next_leaf(struct ctree_root *root, struct ctree_path *path) ...@@ -1359,7 +1360,7 @@ int next_leaf(struct ctree_root *root, struct ctree_path *path)
} }
blocknr = btrfs_node_blockptr(&c->node, slot); blocknr = btrfs_node_blockptr(&c->node, slot);
if (next) if (next)
tree_block_release(root, next); btrfs_block_release(root, next);
next = read_tree_block(root, blocknr); next = read_tree_block(root, blocknr);
break; break;
} }
...@@ -1367,7 +1368,7 @@ int next_leaf(struct ctree_root *root, struct ctree_path *path) ...@@ -1367,7 +1368,7 @@ int next_leaf(struct ctree_root *root, struct ctree_path *path)
while(1) { while(1) {
level--; level--;
c = path->nodes[level]; c = path->nodes[level];
tree_block_release(root, c); btrfs_block_release(root, c);
path->nodes[level] = next; path->nodes[level] = next;
path->slots[level] = 0; path->slots[level] = 0;
if (!level) if (!level)
......
#ifndef __CTREE__ #ifndef __BTRFS__
#define __CTREE__ #define __BTRFS__
#include "list.h" #include "list.h"
#include "kerncompat.h" #include "kerncompat.h"
#define CTREE_BLOCKSIZE 1024 #define BTRFS_BLOCKSIZE 1024
/* /*
* the key defines the order in the tree, and so it also defines (optimal) * the key defines the order in the tree, and so it also defines (optimal)
...@@ -46,21 +46,21 @@ struct btrfs_header { ...@@ -46,21 +46,21 @@ struct btrfs_header {
/* generation flags to be added */ /* generation flags to be added */
} __attribute__ ((__packed__)); } __attribute__ ((__packed__));
#define MAX_LEVEL 8 #define BTRFS_MAX_LEVEL 8
#define NODEPTRS_PER_BLOCK ((CTREE_BLOCKSIZE - sizeof(struct btrfs_header)) / \ #define NODEPTRS_PER_BLOCK ((BTRFS_BLOCKSIZE - sizeof(struct btrfs_header)) / \
(sizeof(struct btrfs_disk_key) + sizeof(u64))) (sizeof(struct btrfs_disk_key) + sizeof(u64)))
struct tree_buffer; struct btrfs_buffer;
/* /*
* in ram representation of the tree. extent_root is used for all allocations * in ram representation of the tree. extent_root is used for all allocations
* and for the extent tree extent_root root. current_insert is used * and for the extent tree extent_root root. current_insert is used
* only for the extent tree. * only for the extent tree.
*/ */
struct ctree_root { struct btrfs_root {
struct tree_buffer *node; struct btrfs_buffer *node;
struct tree_buffer *commit_root; struct btrfs_buffer *commit_root;
struct ctree_root *extent_root; struct btrfs_root *extent_root;
struct btrfs_key current_insert; struct btrfs_key current_insert;
struct btrfs_key last_insert; struct btrfs_key last_insert;
int fp; int fp;
...@@ -74,7 +74,7 @@ struct ctree_root { ...@@ -74,7 +74,7 @@ struct ctree_root {
/* /*
* describes a tree on disk * describes a tree on disk
*/ */
struct ctree_root_info { struct btrfs_root_info {
u64 fsid[2]; /* FS specific uuid */ u64 fsid[2]; /* FS specific uuid */
u64 blocknr; /* blocknr of this block */ u64 blocknr; /* blocknr of this block */
u64 objectid; /* inode number of this root */ u64 objectid; /* inode number of this root */
...@@ -88,9 +88,9 @@ struct ctree_root_info { ...@@ -88,9 +88,9 @@ struct ctree_root_info {
* the super block basically lists the main trees of the FS * the super block basically lists the main trees of the FS
* it currently lacks any block count etc etc * it currently lacks any block count etc etc
*/ */
struct ctree_super_block { struct btrfs_super_block {
struct ctree_root_info root_info; struct btrfs_root_info root_info;
struct ctree_root_info extent_info; struct btrfs_root_info extent_info;
} __attribute__ ((__packed__)); } __attribute__ ((__packed__));
/* /*
...@@ -111,13 +111,13 @@ struct btrfs_item { ...@@ -111,13 +111,13 @@ struct btrfs_item {
* The data is separate from the items to get the keys closer together * The data is separate from the items to get the keys closer together
* during searches. * during searches.
*/ */
#define LEAF_DATA_SIZE (CTREE_BLOCKSIZE - sizeof(struct btrfs_header)) #define LEAF_DATA_SIZE (BTRFS_BLOCKSIZE - sizeof(struct btrfs_header))
struct leaf { struct btrfs_leaf {
struct btrfs_header header; struct btrfs_header header;
union { union {
struct btrfs_item items[LEAF_DATA_SIZE/ struct btrfs_item items[LEAF_DATA_SIZE/
sizeof(struct btrfs_item)]; sizeof(struct btrfs_item)];
u8 data[CTREE_BLOCKSIZE-sizeof(struct btrfs_header)]; u8 data[BTRFS_BLOCKSIZE - sizeof(struct btrfs_header)];
}; };
} __attribute__ ((__packed__)); } __attribute__ ((__packed__));
...@@ -125,7 +125,7 @@ struct leaf { ...@@ -125,7 +125,7 @@ struct leaf {
* all non-leaf blocks are nodes, they hold only keys and pointers to * all non-leaf blocks are nodes, they hold only keys and pointers to
* other blocks * other blocks
*/ */
struct node { struct btrfs_node {
struct btrfs_header header; struct btrfs_header header;
struct btrfs_disk_key keys[NODEPTRS_PER_BLOCK]; struct btrfs_disk_key keys[NODEPTRS_PER_BLOCK];
__le64 blockptrs[NODEPTRS_PER_BLOCK]; __le64 blockptrs[NODEPTRS_PER_BLOCK];
...@@ -135,50 +135,51 @@ struct node { ...@@ -135,50 +135,51 @@ struct node {
* items in the extent btree are used to record the objectid of the * items in the extent btree are used to record the objectid of the
* owner of the block and the number of references * owner of the block and the number of references
*/ */
struct extent_item { struct btrfs_extent_item {
__le32 refs; __le32 refs;
__le64 owner; __le64 owner;
} __attribute__ ((__packed__)); } __attribute__ ((__packed__));
/* /*
* ctree_paths remember the path taken from the root down to the leaf. * btrfs_paths remember the path taken from the root down to the leaf.
* level 0 is always the leaf, and nodes[1...MAX_LEVEL] will point * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point
* to any other levels that are present. * to any other levels that are present.
* *
* The slots array records the index of the item or block pointer * The slots array records the index of the item or block pointer
* used while walking the tree. * used while walking the tree.
*/ */
struct ctree_path { struct btrfs_path {
struct tree_buffer *nodes[MAX_LEVEL]; struct btrfs_buffer *nodes[BTRFS_MAX_LEVEL];
int slots[MAX_LEVEL]; int slots[BTRFS_MAX_LEVEL];
}; };
static inline u64 btrfs_extent_owner(struct extent_item *ei) static inline u64 btrfs_extent_owner(struct btrfs_extent_item *ei)
{ {
return le64_to_cpu(ei->owner); return le64_to_cpu(ei->owner);
} }
static inline void btrfs_set_extent_owner(struct extent_item *ei, u64 val) static inline void btrfs_set_extent_owner(struct btrfs_extent_item *ei, u64 val)
{ {
ei->owner = cpu_to_le64(val); ei->owner = cpu_to_le64(val);
} }
static inline u32 btrfs_extent_refs(struct extent_item *ei) static inline u32 btrfs_extent_refs(struct btrfs_extent_item *ei)
{ {
return le32_to_cpu(ei->refs); return le32_to_cpu(ei->refs);
} }
static inline void btrfs_set_extent_refs(struct extent_item *ei, u32 val) static inline void btrfs_set_extent_refs(struct btrfs_extent_item *ei, u32 val)
{ {
ei->refs = cpu_to_le32(val); ei->refs = cpu_to_le32(val);
} }
static inline u64 btrfs_node_blockptr(struct node *n, int nr) static inline u64 btrfs_node_blockptr(struct btrfs_node *n, int nr)
{ {
return le64_to_cpu(n->blockptrs[nr]); return le64_to_cpu(n->blockptrs[nr]);
} }
static inline void btrfs_set_node_blockptr(struct node *n, int nr, u64 val) static inline void btrfs_set_node_blockptr(struct btrfs_node *n, int nr,
u64 val)
{ {
n->blockptrs[nr] = cpu_to_le64(val); n->blockptrs[nr] = cpu_to_le64(val);
} }
...@@ -300,34 +301,34 @@ static inline void btrfs_set_header_flags(struct btrfs_header *h, u16 val) ...@@ -300,34 +301,34 @@ static inline void btrfs_set_header_flags(struct btrfs_header *h, u16 val)
static inline int btrfs_header_level(struct btrfs_header *h) static inline int btrfs_header_level(struct btrfs_header *h)
{ {
return btrfs_header_flags(h) & (MAX_LEVEL - 1); return btrfs_header_flags(h) & (BTRFS_MAX_LEVEL - 1);
} }
static inline void btrfs_set_header_level(struct btrfs_header *h, int level) static inline void btrfs_set_header_level(struct btrfs_header *h, int level)
{ {
u16 flags; u16 flags;
BUG_ON(level > MAX_LEVEL); BUG_ON(level > BTRFS_MAX_LEVEL);
flags = btrfs_header_flags(h) & ~(MAX_LEVEL - 1); flags = btrfs_header_flags(h) & ~(BTRFS_MAX_LEVEL - 1);
btrfs_set_header_flags(h, flags | level); btrfs_set_header_flags(h, flags | level);
} }
static inline int btrfs_is_leaf(struct node *n) static inline int btrfs_is_leaf(struct btrfs_node *n)
{ {
return (btrfs_header_level(&n->header) == 0); return (btrfs_header_level(&n->header) == 0);
} }
struct tree_buffer *alloc_free_block(struct ctree_root *root); struct btrfs_buffer *btrfs_alloc_free_block(struct btrfs_root *root);
int btrfs_inc_ref(struct ctree_root *root, struct tree_buffer *buf); int btrfs_inc_ref(struct btrfs_root *root, struct btrfs_buffer *buf);
int free_extent(struct ctree_root *root, u64 blocknr, u64 num_blocks); int btrfs_free_extent(struct btrfs_root *root, u64 blocknr, u64 num_blocks);
int search_slot(struct ctree_root *root, struct btrfs_key *key, int btrfs_search_slot(struct btrfs_root *root, struct btrfs_key *key,
struct ctree_path *p, int ins_len, int cow); struct btrfs_path *p, int ins_len, int cow);
void release_path(struct ctree_root *root, struct ctree_path *p); void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
void init_path(struct ctree_path *p); void btrfs_init_path(struct btrfs_path *p);
int del_item(struct ctree_root *root, struct ctree_path *path); int btrfs_del_item(struct btrfs_root *root, struct btrfs_path *path);
int insert_item(struct ctree_root *root, struct btrfs_key *key, int btrfs_insert_item(struct btrfs_root *root, struct btrfs_key *key,
void *data, int data_size); void *data, int data_size);
int next_leaf(struct ctree_root *root, struct ctree_path *path); int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
int leaf_free_space(struct leaf *leaf); int btrfs_leaf_free_space(struct btrfs_leaf *leaf);
int btrfs_drop_snapshot(struct ctree_root *root, struct tree_buffer *snap); int btrfs_drop_snapshot(struct btrfs_root *root, struct btrfs_buffer *snap);
int btrfs_finish_extent_commit(struct ctree_root *root); int btrfs_finish_extent_commit(struct btrfs_root *root);
#endif #endif
...@@ -7,13 +7,13 @@ ...@@ -7,13 +7,13 @@
#include "print-tree.h" #include "print-tree.h"
int main(int ac, char **av) { int main(int ac, char **av) {
struct ctree_super_block super; struct btrfs_super_block super;
struct ctree_root *root; struct btrfs_root *root;
radix_tree_init(); radix_tree_init();
root = open_ctree("dbfile", &super); root = open_ctree("dbfile", &super);
printf("root tree\n"); printf("root tree\n");
print_tree(root, root->node); btrfs_print_tree(root, root->node);
printf("map tree\n"); printf("map tree\n");
print_tree(root->extent_root, root->extent_root->node); btrfs_print_tree(root->extent_root, root->extent_root->node);
return 0; return 0;
} }
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
static int allocated_blocks = 0; static int allocated_blocks = 0;
int cache_max = 10000; int cache_max = 10000;
static int check_tree_block(struct ctree_root *root, struct tree_buffer *buf) static int check_tree_block(struct btrfs_root *root, struct btrfs_buffer *buf)
{ {
if (buf->blocknr != btrfs_header_blocknr(&buf->node.header)) if (buf->blocknr != btrfs_header_blocknr(&buf->node.header))
BUG(); BUG();
...@@ -23,18 +23,18 @@ static int check_tree_block(struct ctree_root *root, struct tree_buffer *buf) ...@@ -23,18 +23,18 @@ static int check_tree_block(struct ctree_root *root, struct tree_buffer *buf)
return 0; return 0;
} }
static int free_some_buffers(struct ctree_root *root) static int free_some_buffers(struct btrfs_root *root)
{ {
struct list_head *node, *next; struct list_head *node, *next;
struct tree_buffer *b; struct btrfs_buffer *b;
if (root->cache_size < cache_max) if (root->cache_size < cache_max)
return 0; return 0;
list_for_each_safe(node, next, &root->cache) { list_for_each_safe(node, next, &root->cache) {
b = list_entry(node, struct tree_buffer, cache); b = list_entry(node, struct btrfs_buffer, cache);
if (b->count == 1) { if (b->count == 1) {
BUG_ON(!list_empty(&b->dirty)); BUG_ON(!list_empty(&b->dirty));
list_del_init(&b->cache); list_del_init(&b->cache);
tree_block_release(root, b); btrfs_block_release(root, b);
if (root->cache_size < cache_max) if (root->cache_size < cache_max)
break; break;
} }
...@@ -42,11 +42,11 @@ static int free_some_buffers(struct ctree_root *root) ...@@ -42,11 +42,11 @@ static int free_some_buffers(struct ctree_root *root)
return 0; return 0;
} }
struct tree_buffer *alloc_tree_block(struct ctree_root *root, u64 blocknr) struct btrfs_buffer *alloc_tree_block(struct btrfs_root *root, u64 blocknr)
{ {
struct tree_buffer *buf; struct btrfs_buffer *buf;
int ret; int ret;
buf = malloc(sizeof(struct tree_buffer)); buf = malloc(sizeof(struct btrfs_buffer));
if (!buf) if (!buf)
return buf; return buf;
allocated_blocks++; allocated_blocks++;
...@@ -66,9 +66,9 @@ struct tree_buffer *alloc_tree_block(struct ctree_root *root, u64 blocknr) ...@@ -66,9 +66,9 @@ struct tree_buffer *alloc_tree_block(struct ctree_root *root, u64 blocknr)
return buf; return buf;
} }
struct tree_buffer *find_tree_block(struct ctree_root *root, u64 blocknr) struct btrfs_buffer *find_tree_block(struct btrfs_root *root, u64 blocknr)
{ {
struct tree_buffer *buf; struct btrfs_buffer *buf;
buf = radix_tree_lookup(&root->cache_radix, blocknr); buf = radix_tree_lookup(&root->cache_radix, blocknr);
if (buf) { if (buf) {
buf->count++; buf->count++;
...@@ -82,10 +82,10 @@ struct tree_buffer *find_tree_block(struct ctree_root *root, u64 blocknr) ...@@ -82,10 +82,10 @@ struct tree_buffer *find_tree_block(struct ctree_root *root, u64 blocknr)
return buf; return buf;
} }
struct tree_buffer *read_tree_block(struct ctree_root *root, u64 blocknr) struct btrfs_buffer *read_tree_block(struct btrfs_root *root, u64 blocknr)
{ {
loff_t offset = blocknr * CTREE_BLOCKSIZE; loff_t offset = blocknr * BTRFS_BLOCKSIZE;
struct tree_buffer *buf; struct btrfs_buffer *buf;
int ret; int ret;
buf = radix_tree_lookup(&root->cache_radix, blocknr); buf = radix_tree_lookup(&root->cache_radix, blocknr);
...@@ -95,8 +95,8 @@ struct tree_buffer *read_tree_block(struct ctree_root *root, u64 blocknr) ...@@ -95,8 +95,8 @@ struct tree_buffer *read_tree_block(struct ctree_root *root, u64 blocknr)
buf = alloc_tree_block(root, blocknr); buf = alloc_tree_block(root, blocknr);
if (!buf) if (!buf)
return NULL; return NULL;
ret = pread(root->fp, &buf->node, CTREE_BLOCKSIZE, offset); ret = pread(root->fp, &buf->node, BTRFS_BLOCKSIZE, offset);
if (ret != CTREE_BLOCKSIZE) { if (ret != BTRFS_BLOCKSIZE) {
free(buf); free(buf);
return NULL; return NULL;
} }
...@@ -106,7 +106,7 @@ struct tree_buffer *read_tree_block(struct ctree_root *root, u64 blocknr) ...@@ -106,7 +106,7 @@ struct tree_buffer *read_tree_block(struct ctree_root *root, u64 blocknr)
return buf; return buf;
} }
int dirty_tree_block(struct ctree_root *root, struct tree_buffer *buf) int dirty_tree_block(struct btrfs_root *root, struct btrfs_buffer *buf)
{ {
if (!list_empty(&buf->dirty)) if (!list_empty(&buf->dirty))
return 0; return 0;
...@@ -115,46 +115,47 @@ int dirty_tree_block(struct ctree_root *root, struct tree_buffer *buf) ...@@ -115,46 +115,47 @@ int dirty_tree_block(struct ctree_root *root, struct tree_buffer *buf)
return 0; return 0;
} }
int clean_tree_block(struct ctree_root *root, struct tree_buffer *buf) int clean_tree_block(struct btrfs_root *root, struct btrfs_buffer *buf)
{ {
if (!list_empty(&buf->dirty)) { if (!list_empty(&buf->dirty)) {
list_del_init(&buf->dirty); list_del_init(&buf->dirty);
tree_block_release(root, buf); btrfs_block_release(root, buf);
} }
return 0; return 0;
} }
int write_tree_block(struct ctree_root *root, struct tree_buffer *buf) int write_tree_block(struct btrfs_root *root, struct btrfs_buffer *buf)
{ {
u64 blocknr = buf->blocknr; u64 blocknr = buf->blocknr;
loff_t offset = blocknr * CTREE_BLOCKSIZE; loff_t offset = blocknr * BTRFS_BLOCKSIZE;
int ret; int ret;
if (buf->blocknr != btrfs_header_blocknr(&buf->node.header)) if (buf->blocknr != btrfs_header_blocknr(&buf->node.header))
BUG(); BUG();
ret = pwrite(root->fp, &buf->node, CTREE_BLOCKSIZE, offset); ret = pwrite(root->fp, &buf->node, BTRFS_BLOCKSIZE, offset);
if (ret != CTREE_BLOCKSIZE) if (ret != BTRFS_BLOCKSIZE)
return ret; return ret;
return 0; return 0;
} }
static int __commit_transaction(struct ctree_root *root) static int __commit_transaction(struct btrfs_root *root)
{ {
struct tree_buffer *b; struct btrfs_buffer *b;
int ret = 0; int ret = 0;
int wret; int wret;
while(!list_empty(&root->trans)) { while(!list_empty(&root->trans)) {
b = list_entry(root->trans.next, struct tree_buffer, dirty); b = list_entry(root->trans.next, struct btrfs_buffer, dirty);
list_del_init(&b->dirty); list_del_init(&b->dirty);
wret = write_tree_block(root, b); wret = write_tree_block(root, b);
if (wret) if (wret)
ret = wret; ret = wret;
tree_block_release(root, b); btrfs_block_release(root, b);
} }
return ret; return ret;
} }
int commit_transaction(struct ctree_root *root, struct ctree_super_block *s) int btrfs_commit_transaction(struct btrfs_root *root,
struct btrfs_super_block *s)
{ {
int ret = 0; int ret = 0;
...@@ -163,20 +164,20 @@ int commit_transaction(struct ctree_root *root, struct ctree_super_block *s) ...@@ -163,20 +164,20 @@ int commit_transaction(struct ctree_root *root, struct ctree_super_block *s)
ret = __commit_transaction(root->extent_root); ret = __commit_transaction(root->extent_root);
BUG_ON(ret); BUG_ON(ret);
if (root->commit_root != root->node) { if (root->commit_root != root->node) {
struct tree_buffer *snap = root->commit_root; struct btrfs_buffer *snap = root->commit_root;
root->commit_root = root->node; root->commit_root = root->node;
root->node->count++; root->node->count++;
ret = btrfs_drop_snapshot(root, snap); ret = btrfs_drop_snapshot(root, snap);
BUG_ON(ret); BUG_ON(ret);
// tree_block_release(root, snap); // btrfs_block_release(root, snap);
} }
write_ctree_super(root, s); write_ctree_super(root, s);
btrfs_finish_extent_commit(root); btrfs_finish_extent_commit(root);
return ret; return ret;
} }
static int __setup_root(struct ctree_root *root, struct ctree_root *extent_root, static int __setup_root(struct btrfs_root *root, struct btrfs_root *extent_root,
struct ctree_root_info *info, int fp) struct btrfs_root_info *info, int fp)
{ {
INIT_LIST_HEAD(&root->trans); INIT_LIST_HEAD(&root->trans);
INIT_LIST_HEAD(&root->cache); INIT_LIST_HEAD(&root->cache);
...@@ -191,10 +192,10 @@ static int __setup_root(struct ctree_root *root, struct ctree_root *extent_root, ...@@ -191,10 +192,10 @@ static int __setup_root(struct ctree_root *root, struct ctree_root *extent_root,
return 0; return 0;
} }
struct ctree_root *open_ctree(char *filename, struct ctree_super_block *super) struct btrfs_root *open_ctree(char *filename, struct btrfs_super_block *super)
{ {
struct ctree_root *root = malloc(sizeof(struct ctree_root)); struct btrfs_root *root = malloc(sizeof(struct btrfs_root));
struct ctree_root *extent_root = malloc(sizeof(struct ctree_root)); struct btrfs_root *extent_root = malloc(sizeof(struct btrfs_root));
int fp; int fp;
int ret; int ret;
...@@ -207,16 +208,16 @@ struct ctree_root *open_ctree(char *filename, struct ctree_super_block *super) ...@@ -207,16 +208,16 @@ struct ctree_root *open_ctree(char *filename, struct ctree_super_block *super)
INIT_RADIX_TREE(&root->pinned_radix, GFP_KERNEL); INIT_RADIX_TREE(&root->pinned_radix, GFP_KERNEL);
INIT_RADIX_TREE(&extent_root->pinned_radix, GFP_KERNEL); INIT_RADIX_TREE(&extent_root->pinned_radix, GFP_KERNEL);
INIT_RADIX_TREE(&extent_root->cache_radix, GFP_KERNEL); INIT_RADIX_TREE(&extent_root->cache_radix, GFP_KERNEL);
ret = pread(fp, super, sizeof(struct ctree_super_block), ret = pread(fp, super, sizeof(struct btrfs_super_block),
CTREE_SUPER_INFO_OFFSET(CTREE_BLOCKSIZE)); BTRFS_SUPER_INFO_OFFSET(BTRFS_BLOCKSIZE));
if (ret == 0 || super->root_info.tree_root == 0) { if (ret == 0 || super->root_info.tree_root == 0) {
printf("making new FS!\n"); printf("making new FS!\n");
ret = mkfs(fp); ret = mkfs(fp);
if (ret) if (ret)
return NULL; return NULL;
ret = pread(fp, super, sizeof(struct ctree_super_block), ret = pread(fp, super, sizeof(struct btrfs_super_block),
CTREE_SUPER_INFO_OFFSET(CTREE_BLOCKSIZE)); BTRFS_SUPER_INFO_OFFSET(BTRFS_BLOCKSIZE));
if (ret != sizeof(struct ctree_super_block)) if (ret != sizeof(struct btrfs_super_block))
return NULL; return NULL;
} }
BUG_ON(ret < 0); BUG_ON(ret < 0);
...@@ -227,18 +228,19 @@ struct ctree_root *open_ctree(char *filename, struct ctree_super_block *super) ...@@ -227,18 +228,19 @@ struct ctree_root *open_ctree(char *filename, struct ctree_super_block *super)
return root; return root;
} }
static int __update_root(struct ctree_root *root, struct ctree_root_info *info) static int __update_root(struct btrfs_root *root, struct btrfs_root_info *info)
{ {
info->tree_root = root->node->blocknr; info->tree_root = root->node->blocknr;
return 0; return 0;
} }
int write_ctree_super(struct ctree_root *root, struct ctree_super_block *s) int write_ctree_super(struct btrfs_root *root, struct btrfs_super_block *s)
{ {
int ret; int ret;
__update_root(root, &s->root_info); __update_root(root, &s->root_info);
__update_root(root->extent_root, &s->extent_info); __update_root(root->extent_root, &s->extent_info);
ret = pwrite(root->fp, s, sizeof(*s), CTREE_SUPER_INFO_OFFSET(CTREE_BLOCKSIZE)); ret = pwrite(root->fp, s, sizeof(*s),
BTRFS_SUPER_INFO_OFFSET(BTRFS_BLOCKSIZE));
if (ret != sizeof(*s)) { if (ret != sizeof(*s)) {
fprintf(stderr, "failed to write new super block err %d\n", ret); fprintf(stderr, "failed to write new super block err %d\n", ret);
return ret; return ret;
...@@ -246,19 +248,19 @@ int write_ctree_super(struct ctree_root *root, struct ctree_super_block *s) ...@@ -246,19 +248,19 @@ int write_ctree_super(struct ctree_root *root, struct ctree_super_block *s)
return 0; return 0;
} }
static int drop_cache(struct ctree_root *root) static int drop_cache(struct btrfs_root *root)
{ {
while(!list_empty(&root->cache)) { while(!list_empty(&root->cache)) {
struct tree_buffer *b = list_entry(root->cache.next, struct btrfs_buffer *b = list_entry(root->cache.next,
struct tree_buffer, cache); struct btrfs_buffer, cache);
list_del_init(&b->cache); list_del_init(&b->cache);
tree_block_release(root, b); btrfs_block_release(root, b);
} }
return 0; return 0;
} }
int close_ctree(struct ctree_root *root, struct ctree_super_block *s) int close_ctree(struct btrfs_root *root, struct btrfs_super_block *s)
{ {
commit_transaction(root, s); btrfs_commit_transaction(root, s);
__commit_transaction(root->extent_root); __commit_transaction(root->extent_root);
write_ctree_super(root, s); write_ctree_super(root, s);
drop_cache(root->extent_root); drop_cache(root->extent_root);
...@@ -268,16 +270,16 @@ int close_ctree(struct ctree_root *root, struct ctree_super_block *s) ...@@ -268,16 +270,16 @@ int close_ctree(struct ctree_root *root, struct ctree_super_block *s)
close(root->fp); close(root->fp);
if (root->node) if (root->node)
tree_block_release(root, root->node); btrfs_block_release(root, root->node);
if (root->extent_root->node) if (root->extent_root->node)
tree_block_release(root->extent_root, root->extent_root->node); btrfs_block_release(root->extent_root, root->extent_root->node);
tree_block_release(root, root->commit_root); btrfs_block_release(root, root->commit_root);
free(root); free(root);
printf("on close %d blocks are allocated\n", allocated_blocks); printf("on close %d blocks are allocated\n", allocated_blocks);
return 0; return 0;
} }
void tree_block_release(struct ctree_root *root, struct tree_buffer *buf) void btrfs_block_release(struct btrfs_root *root, struct btrfs_buffer *buf)
{ {
buf->count--; buf->count--;
if (buf->count < 0) if (buf->count < 0)
......
...@@ -2,29 +2,30 @@ ...@@ -2,29 +2,30 @@
#define __DISKIO__ #define __DISKIO__
#include "list.h" #include "list.h"
struct tree_buffer { struct btrfs_buffer {
u64 blocknr; u64 blocknr;
int count; int count;
union { union {
struct node node; struct btrfs_node node;
struct leaf leaf; struct btrfs_leaf leaf;
}; };
struct list_head dirty; struct list_head dirty;
struct list_head cache; struct list_head cache;
}; };
struct tree_buffer *read_tree_block(struct ctree_root *root, u64 blocknr); struct btrfs_buffer *read_tree_block(struct btrfs_root *root, u64 blocknr);
struct tree_buffer *find_tree_block(struct ctree_root *root, u64 blocknr); struct btrfs_buffer *find_tree_block(struct btrfs_root *root, u64 blocknr);
int write_tree_block(struct ctree_root *root, struct tree_buffer *buf); int write_tree_block(struct btrfs_root *root, struct btrfs_buffer *buf);
int dirty_tree_block(struct ctree_root *root, struct tree_buffer *buf); int dirty_tree_block(struct btrfs_root *root, struct btrfs_buffer *buf);
int clean_tree_block(struct ctree_root *root, struct tree_buffer *buf); int clean_tree_block(struct btrfs_root *root, struct btrfs_buffer *buf);
int commit_transaction(struct ctree_root *root, struct ctree_super_block *s); int btrfs_commit_transaction(struct btrfs_root *root,
struct ctree_root *open_ctree(char *filename, struct ctree_super_block *s); struct btrfs_super_block *s);
int close_ctree(struct ctree_root *root, struct ctree_super_block *s); struct btrfs_root *open_ctree(char *filename, struct btrfs_super_block *s);
void tree_block_release(struct ctree_root *root, struct tree_buffer *buf); int close_ctree(struct btrfs_root *root, struct btrfs_super_block *s);
int write_ctree_super(struct ctree_root *root, struct ctree_super_block *s); void btrfs_block_release(struct btrfs_root *root, struct btrfs_buffer *buf);
int write_ctree_super(struct btrfs_root *root, struct btrfs_super_block *s);
int mkfs(int fd); int mkfs(int fd);
#define CTREE_SUPER_INFO_OFFSET(bs) (16 * (bs)) #define BTRFS_SUPER_INFO_OFFSET(bs) (16 * (bs))
#endif #endif
...@@ -6,11 +6,11 @@ ...@@ -6,11 +6,11 @@
#include "disk-io.h" #include "disk-io.h"
#include "print-tree.h" #include "print-tree.h"
static int find_free_extent(struct ctree_root *orig_root, u64 num_blocks, static int find_free_extent(struct btrfs_root *orig_root, u64 num_blocks,
u64 search_start, u64 search_end, u64 search_start, u64 search_end,
struct btrfs_key *ins); struct btrfs_key *ins);
static int finish_current_insert(struct ctree_root *extent_root); static int finish_current_insert(struct btrfs_root *extent_root);
static int run_pending(struct ctree_root *extent_root); static int run_pending(struct btrfs_root *extent_root);
/* /*
* pending extents are blocks that we're trying to allocate in the extent * pending extents are blocks that we're trying to allocate in the extent
...@@ -21,62 +21,63 @@ static int run_pending(struct ctree_root *extent_root); ...@@ -21,62 +21,63 @@ static int run_pending(struct ctree_root *extent_root);
*/ */
#define CTREE_EXTENT_PENDING_DEL 0 #define CTREE_EXTENT_PENDING_DEL 0
static int inc_block_ref(struct ctree_root *root, u64 blocknr) static int inc_block_ref(struct btrfs_root *root, u64 blocknr)
{ {
struct ctree_path path; struct btrfs_path path;
int ret; int ret;
struct btrfs_key key; struct btrfs_key key;
struct leaf *l; struct btrfs_leaf *l;
struct extent_item *item; struct btrfs_extent_item *item;
struct btrfs_key ins; struct btrfs_key ins;
u32 refs; u32 refs;
find_free_extent(root->extent_root, 0, 0, (u64)-1, &ins); find_free_extent(root->extent_root, 0, 0, (u64)-1, &ins);
init_path(&path); btrfs_init_path(&path);
key.objectid = blocknr; key.objectid = blocknr;
key.flags = 0; key.flags = 0;
key.offset = 1; key.offset = 1;
ret = search_slot(root->extent_root, &key, &path, 0, 1); ret = btrfs_search_slot(root->extent_root, &key, &path, 0, 1);
if (ret != 0) if (ret != 0)
BUG(); BUG();
BUG_ON(ret != 0); BUG_ON(ret != 0);
l = &path.nodes[0]->leaf; l = &path.nodes[0]->leaf;
item = (struct extent_item *)(l->data + btrfs_item_offset(l->items + item = (struct btrfs_extent_item *)(l->data +
path.slots[0])); btrfs_item_offset(l->items +
path.slots[0]));
refs = btrfs_extent_refs(item); refs = btrfs_extent_refs(item);
btrfs_set_extent_refs(item, refs + 1); btrfs_set_extent_refs(item, refs + 1);
BUG_ON(list_empty(&path.nodes[0]->dirty)); BUG_ON(list_empty(&path.nodes[0]->dirty));
release_path(root->extent_root, &path); btrfs_release_path(root->extent_root, &path);
finish_current_insert(root->extent_root); finish_current_insert(root->extent_root);
run_pending(root->extent_root); run_pending(root->extent_root);
return 0; return 0;
} }
static int lookup_block_ref(struct ctree_root *root, u64 blocknr, u32 *refs) static int lookup_block_ref(struct btrfs_root *root, u64 blocknr, u32 *refs)
{ {
struct ctree_path path; struct btrfs_path path;
int ret; int ret;
struct btrfs_key key; struct btrfs_key key;
struct leaf *l; struct btrfs_leaf *l;
struct extent_item *item; struct btrfs_extent_item *item;
init_path(&path); btrfs_init_path(&path);
key.objectid = blocknr; key.objectid = blocknr;
key.flags = 0; key.flags = 0;
key.offset = 1; key.offset = 1;
ret = search_slot(root->extent_root, &key, &path, 0, 0); ret = btrfs_search_slot(root->extent_root, &key, &path, 0, 0);
if (ret != 0) if (ret != 0)
BUG(); BUG();
l = &path.nodes[0]->leaf; l = &path.nodes[0]->leaf;
item = (struct extent_item *)(l->data + item = (struct btrfs_extent_item *)(l->data +
btrfs_item_offset(l->items + btrfs_item_offset(l->items +
path.slots[0])); path.slots[0]));
*refs = btrfs_extent_refs(item); *refs = btrfs_extent_refs(item);
release_path(root->extent_root, &path); btrfs_release_path(root->extent_root, &path);
return 0; return 0;
} }
int btrfs_inc_ref(struct ctree_root *root, struct tree_buffer *buf) int btrfs_inc_ref(struct btrfs_root *root, struct btrfs_buffer *buf)
{ {
u64 blocknr; u64 blocknr;
int i; int i;
...@@ -93,9 +94,9 @@ int btrfs_inc_ref(struct ctree_root *root, struct tree_buffer *buf) ...@@ -93,9 +94,9 @@ int btrfs_inc_ref(struct ctree_root *root, struct tree_buffer *buf)
return 0; return 0;
} }
int btrfs_finish_extent_commit(struct ctree_root *root) int btrfs_finish_extent_commit(struct btrfs_root *root)
{ {
struct ctree_root *extent_root = root->extent_root; struct btrfs_root *extent_root = root->extent_root;
unsigned long gang[8]; unsigned long gang[8];
int ret; int ret;
int i; int i;
...@@ -115,10 +116,10 @@ int btrfs_finish_extent_commit(struct ctree_root *root) ...@@ -115,10 +116,10 @@ int btrfs_finish_extent_commit(struct ctree_root *root)
return 0; return 0;
} }
static int finish_current_insert(struct ctree_root *extent_root) static int finish_current_insert(struct btrfs_root *extent_root)
{ {
struct btrfs_key ins; struct btrfs_key ins;
struct extent_item extent_item; struct btrfs_extent_item extent_item;
int i; int i;
int ret; int ret;
...@@ -130,7 +131,7 @@ static int finish_current_insert(struct ctree_root *extent_root) ...@@ -130,7 +131,7 @@ static int finish_current_insert(struct ctree_root *extent_root)
for (i = 0; i < extent_root->current_insert.flags; i++) { for (i = 0; i < extent_root->current_insert.flags; i++) {
ins.objectid = extent_root->current_insert.objectid + i; ins.objectid = extent_root->current_insert.objectid + i;
ret = insert_item(extent_root, &ins, &extent_item, ret = btrfs_insert_item(extent_root, &ins, &extent_item,
sizeof(extent_item)); sizeof(extent_item));
BUG_ON(ret); BUG_ON(ret);
} }
...@@ -141,14 +142,14 @@ static int finish_current_insert(struct ctree_root *extent_root) ...@@ -141,14 +142,14 @@ static int finish_current_insert(struct ctree_root *extent_root)
/* /*
* remove an extent from the root, returns 0 on success * remove an extent from the root, returns 0 on success
*/ */
int __free_extent(struct ctree_root *root, u64 blocknr, u64 num_blocks) static int __free_extent(struct btrfs_root *root, u64 blocknr, u64 num_blocks)
{ {
struct ctree_path path; struct btrfs_path path;
struct btrfs_key key; struct btrfs_key key;
struct ctree_root *extent_root = root->extent_root; struct btrfs_root *extent_root = root->extent_root;
int ret; int ret;
struct btrfs_item *item; struct btrfs_item *item;
struct extent_item *ei; struct btrfs_extent_item *ei;
struct btrfs_key ins; struct btrfs_key ins;
u32 refs; u32 refs;
...@@ -157,16 +158,16 @@ int __free_extent(struct ctree_root *root, u64 blocknr, u64 num_blocks) ...@@ -157,16 +158,16 @@ int __free_extent(struct ctree_root *root, u64 blocknr, u64 num_blocks)
key.offset = num_blocks; key.offset = num_blocks;
find_free_extent(root, 0, 0, (u64)-1, &ins); find_free_extent(root, 0, 0, (u64)-1, &ins);
init_path(&path); btrfs_init_path(&path);
ret = search_slot(extent_root, &key, &path, -1, 1); ret = btrfs_search_slot(extent_root, &key, &path, -1, 1);
if (ret) { if (ret) {
printf("failed to find %Lu\n", key.objectid); printf("failed to find %Lu\n", key.objectid);
print_tree(extent_root, extent_root->node); btrfs_print_tree(extent_root, extent_root->node);
printf("failed to find %Lu\n", key.objectid); printf("failed to find %Lu\n", key.objectid);
BUG(); BUG();
} }
item = path.nodes[0]->leaf.items + path.slots[0]; item = path.nodes[0]->leaf.items + path.slots[0];
ei = (struct extent_item *)(path.nodes[0]->leaf.data + ei = (struct btrfs_extent_item *)(path.nodes[0]->leaf.data +
btrfs_item_offset(item)); btrfs_item_offset(item));
BUG_ON(ei->refs == 0); BUG_ON(ei->refs == 0);
refs = btrfs_extent_refs(ei) - 1; refs = btrfs_extent_refs(ei) - 1;
...@@ -180,14 +181,14 @@ int __free_extent(struct ctree_root *root, u64 blocknr, u64 num_blocks) ...@@ -180,14 +181,14 @@ int __free_extent(struct ctree_root *root, u64 blocknr, u64 num_blocks)
BUG_ON(err); BUG_ON(err);
radix_tree_preload_end(); radix_tree_preload_end();
} }
ret = del_item(extent_root, &path); ret = btrfs_del_item(extent_root, &path);
if (root != extent_root && if (root != extent_root &&
extent_root->last_insert.objectid < blocknr) extent_root->last_insert.objectid < blocknr)
extent_root->last_insert.objectid = blocknr; extent_root->last_insert.objectid = blocknr;
if (ret) if (ret)
BUG(); BUG();
} }
release_path(extent_root, &path); btrfs_release_path(extent_root, &path);
finish_current_insert(extent_root); finish_current_insert(extent_root);
return ret; return ret;
} }
...@@ -196,10 +197,10 @@ int __free_extent(struct ctree_root *root, u64 blocknr, u64 num_blocks) ...@@ -196,10 +197,10 @@ int __free_extent(struct ctree_root *root, u64 blocknr, u64 num_blocks)
* find all the blocks marked as pending in the radix tree and remove * find all the blocks marked as pending in the radix tree and remove
* them from the extent map * them from the extent map
*/ */
static int del_pending_extents(struct ctree_root *extent_root) static int del_pending_extents(struct btrfs_root *extent_root)
{ {
int ret; int ret;
struct tree_buffer *gang[4]; struct btrfs_buffer *gang[4];
int i; int i;
while(1) { while(1) {
...@@ -214,13 +215,13 @@ static int del_pending_extents(struct ctree_root *extent_root) ...@@ -214,13 +215,13 @@ static int del_pending_extents(struct ctree_root *extent_root)
radix_tree_tag_clear(&extent_root->cache_radix, radix_tree_tag_clear(&extent_root->cache_radix,
gang[i]->blocknr, gang[i]->blocknr,
CTREE_EXTENT_PENDING_DEL); CTREE_EXTENT_PENDING_DEL);
tree_block_release(extent_root, gang[i]); btrfs_block_release(extent_root, gang[i]);
} }
} }
return 0; return 0;
} }
static int run_pending(struct ctree_root *extent_root) static int run_pending(struct btrfs_root *extent_root)
{ {
while(radix_tree_tagged(&extent_root->cache_radix, while(radix_tree_tagged(&extent_root->cache_radix,
CTREE_EXTENT_PENDING_DEL)) CTREE_EXTENT_PENDING_DEL))
...@@ -232,11 +233,11 @@ static int run_pending(struct ctree_root *extent_root) ...@@ -232,11 +233,11 @@ static int run_pending(struct ctree_root *extent_root)
/* /*
* remove an extent from the root, returns 0 on success * remove an extent from the root, returns 0 on success
*/ */
int free_extent(struct ctree_root *root, u64 blocknr, u64 num_blocks) int btrfs_free_extent(struct btrfs_root *root, u64 blocknr, u64 num_blocks)
{ {
struct btrfs_key key; struct btrfs_key key;
struct ctree_root *extent_root = root->extent_root; struct btrfs_root *extent_root = root->extent_root;
struct tree_buffer *t; struct btrfs_buffer *t;
int pending_ret; int pending_ret;
int ret; int ret;
...@@ -262,11 +263,11 @@ int free_extent(struct ctree_root *root, u64 blocknr, u64 num_blocks) ...@@ -262,11 +263,11 @@ int free_extent(struct ctree_root *root, u64 blocknr, u64 num_blocks)
* ins->offset == number of blocks * ins->offset == number of blocks
* Any available blocks before search_start are skipped. * Any available blocks before search_start are skipped.
*/ */
static int find_free_extent(struct ctree_root *orig_root, u64 num_blocks, static int find_free_extent(struct btrfs_root *orig_root, u64 num_blocks,
u64 search_start, u64 search_end, u64 search_start, u64 search_end,
struct btrfs_key *ins) struct btrfs_key *ins)
{ {
struct ctree_path path; struct btrfs_path path;
struct btrfs_key key; struct btrfs_key key;
int ret; int ret;
u64 hole_size = 0; u64 hole_size = 0;
...@@ -274,20 +275,20 @@ static int find_free_extent(struct ctree_root *orig_root, u64 num_blocks, ...@@ -274,20 +275,20 @@ static int find_free_extent(struct ctree_root *orig_root, u64 num_blocks,
u64 last_block; u64 last_block;
u64 test_block; u64 test_block;
int start_found; int start_found;
struct leaf *l; struct btrfs_leaf *l;
struct ctree_root * root = orig_root->extent_root; struct btrfs_root * root = orig_root->extent_root;
int total_needed = num_blocks; int total_needed = num_blocks;
total_needed += (btrfs_header_level(&root->node->node.header) + 1) * 3; total_needed += (btrfs_header_level(&root->node->node.header) + 1) * 3;
if (root->last_insert.objectid > search_start) if (root->last_insert.objectid > search_start)
search_start = root->last_insert.objectid; search_start = root->last_insert.objectid;
check_failed: check_failed:
init_path(&path); btrfs_init_path(&path);
ins->objectid = search_start; ins->objectid = search_start;
ins->offset = 0; ins->offset = 0;
ins->flags = 0; ins->flags = 0;
start_found = 0; start_found = 0;
ret = search_slot(root, ins, &path, 0, 0); ret = btrfs_search_slot(root, ins, &path, 0, 0);
if (ret < 0) if (ret < 0)
goto error; goto error;
...@@ -298,7 +299,7 @@ static int find_free_extent(struct ctree_root *orig_root, u64 num_blocks, ...@@ -298,7 +299,7 @@ static int find_free_extent(struct ctree_root *orig_root, u64 num_blocks,
l = &path.nodes[0]->leaf; l = &path.nodes[0]->leaf;
slot = path.slots[0]; slot = path.slots[0];
if (slot >= btrfs_header_nritems(&l->header)) { if (slot >= btrfs_header_nritems(&l->header)) {
ret = next_leaf(root, &path); ret = btrfs_next_leaf(root, &path);
if (ret == 0) if (ret == 0)
continue; continue;
if (ret < 0) if (ret < 0)
...@@ -336,7 +337,7 @@ static int find_free_extent(struct ctree_root *orig_root, u64 num_blocks, ...@@ -336,7 +337,7 @@ static int find_free_extent(struct ctree_root *orig_root, u64 num_blocks,
/* we have to make sure we didn't find an extent that has already /* we have to make sure we didn't find an extent that has already
* been allocated by the map tree or the original allocation * been allocated by the map tree or the original allocation
*/ */
release_path(root, &path); btrfs_release_path(root, &path);
BUG_ON(ins->objectid < search_start); BUG_ON(ins->objectid < search_start);
for (test_block = ins->objectid; for (test_block = ins->objectid;
test_block < ins->objectid + total_needed; test_block++) { test_block < ins->objectid + total_needed; test_block++) {
...@@ -353,7 +354,7 @@ static int find_free_extent(struct ctree_root *orig_root, u64 num_blocks, ...@@ -353,7 +354,7 @@ static int find_free_extent(struct ctree_root *orig_root, u64 num_blocks,
ins->offset = num_blocks; ins->offset = num_blocks;
return 0; return 0;
error: error:
release_path(root, &path); btrfs_release_path(root, &path);
return ret; return ret;
} }
...@@ -364,13 +365,13 @@ static int find_free_extent(struct ctree_root *orig_root, u64 num_blocks, ...@@ -364,13 +365,13 @@ static int find_free_extent(struct ctree_root *orig_root, u64 num_blocks,
* *
* returns 0 if everything worked, non-zero otherwise. * returns 0 if everything worked, non-zero otherwise.
*/ */
int alloc_extent(struct ctree_root *root, u64 num_blocks, u64 search_start, int alloc_extent(struct btrfs_root *root, u64 num_blocks, u64 search_start,
u64 search_end, u64 owner, struct btrfs_key *ins) u64 search_end, u64 owner, struct btrfs_key *ins)
{ {
int ret; int ret;
int pending_ret; int pending_ret;
struct ctree_root *extent_root = root->extent_root; struct btrfs_root *extent_root = root->extent_root;
struct extent_item extent_item; struct btrfs_extent_item extent_item;
btrfs_set_extent_refs(&extent_item, 1); btrfs_set_extent_refs(&extent_item, 1);
btrfs_set_extent_owner(&extent_item, owner); btrfs_set_extent_owner(&extent_item, owner);
...@@ -390,7 +391,7 @@ int alloc_extent(struct ctree_root *root, u64 num_blocks, u64 search_start, ...@@ -390,7 +391,7 @@ int alloc_extent(struct ctree_root *root, u64 num_blocks, u64 search_start,
if (ret) if (ret)
return ret; return ret;
ret = insert_item(extent_root, ins, &extent_item, ret = btrfs_insert_item(extent_root, ins, &extent_item,
sizeof(extent_item)); sizeof(extent_item));
finish_current_insert(extent_root); finish_current_insert(extent_root);
...@@ -406,11 +407,11 @@ int alloc_extent(struct ctree_root *root, u64 num_blocks, u64 search_start, ...@@ -406,11 +407,11 @@ int alloc_extent(struct ctree_root *root, u64 num_blocks, u64 search_start,
* helper function to allocate a block for a given tree * helper function to allocate a block for a given tree
* returns the tree buffer or NULL. * returns the tree buffer or NULL.
*/ */
struct tree_buffer *alloc_free_block(struct ctree_root *root) struct btrfs_buffer *btrfs_alloc_free_block(struct btrfs_root *root)
{ {
struct btrfs_key ins; struct btrfs_key ins;
int ret; int ret;
struct tree_buffer *buf; struct btrfs_buffer *buf;
ret = alloc_extent(root, 1, 0, (unsigned long)-1, ret = alloc_extent(root, 1, 0, (unsigned long)-1,
btrfs_header_parentid(&root->node->node.header), btrfs_header_parentid(&root->node->node.header),
...@@ -424,10 +425,10 @@ struct tree_buffer *alloc_free_block(struct ctree_root *root) ...@@ -424,10 +425,10 @@ struct tree_buffer *alloc_free_block(struct ctree_root *root)
return buf; return buf;
} }
int walk_down_tree(struct ctree_root *root, struct ctree_path *path, int *level) int walk_down_tree(struct btrfs_root *root, struct btrfs_path *path, int *level)
{ {
struct tree_buffer *next; struct btrfs_buffer *next;
struct tree_buffer *cur; struct btrfs_buffer *cur;
u64 blocknr; u64 blocknr;
int ret; int ret;
u32 refs; u32 refs;
...@@ -445,33 +446,33 @@ int walk_down_tree(struct ctree_root *root, struct ctree_path *path, int *level) ...@@ -445,33 +446,33 @@ int walk_down_tree(struct ctree_root *root, struct ctree_path *path, int *level)
ret = lookup_block_ref(root, blocknr, &refs); ret = lookup_block_ref(root, blocknr, &refs);
if (refs != 1 || *level == 1) { if (refs != 1 || *level == 1) {
path->slots[*level]++; path->slots[*level]++;
ret = free_extent(root, blocknr, 1); ret = btrfs_free_extent(root, blocknr, 1);
BUG_ON(ret); BUG_ON(ret);
continue; continue;
} }
BUG_ON(ret); BUG_ON(ret);
next = read_tree_block(root, blocknr); next = read_tree_block(root, blocknr);
if (path->nodes[*level-1]) if (path->nodes[*level-1])
tree_block_release(root, path->nodes[*level-1]); btrfs_block_release(root, path->nodes[*level-1]);
path->nodes[*level-1] = next; path->nodes[*level-1] = next;
*level = btrfs_header_level(&next->node.header); *level = btrfs_header_level(&next->node.header);
path->slots[*level] = 0; path->slots[*level] = 0;
} }
out: out:
ret = free_extent(root, path->nodes[*level]->blocknr, 1); ret = btrfs_free_extent(root, path->nodes[*level]->blocknr, 1);
tree_block_release(root, path->nodes[*level]); btrfs_block_release(root, path->nodes[*level]);
path->nodes[*level] = NULL; path->nodes[*level] = NULL;
*level += 1; *level += 1;
BUG_ON(ret); BUG_ON(ret);
return 0; return 0;
} }
int walk_up_tree(struct ctree_root *root, struct ctree_path *path, int *level) int walk_up_tree(struct btrfs_root *root, struct btrfs_path *path, int *level)
{ {
int i; int i;
int slot; int slot;
int ret; int ret;
for(i = *level; i < MAX_LEVEL - 1 && path->nodes[i]; i++) { for(i = *level; i < BTRFS_MAX_LEVEL - 1 && path->nodes[i]; i++) {
slot = path->slots[i]; slot = path->slots[i];
if (slot < if (slot <
btrfs_header_nritems(&path->nodes[i]->node.header)- 1) { btrfs_header_nritems(&path->nodes[i]->node.header)- 1) {
...@@ -479,9 +480,9 @@ int walk_up_tree(struct ctree_root *root, struct ctree_path *path, int *level) ...@@ -479,9 +480,9 @@ int walk_up_tree(struct ctree_root *root, struct ctree_path *path, int *level)
*level = i; *level = i;
return 0; return 0;
} else { } else {
ret = free_extent(root, ret = btrfs_free_extent(root,
path->nodes[*level]->blocknr, 1); path->nodes[*level]->blocknr, 1);
tree_block_release(root, path->nodes[*level]); btrfs_block_release(root, path->nodes[*level]);
path->nodes[*level] = NULL; path->nodes[*level] = NULL;
*level = i + 1; *level = i + 1;
BUG_ON(ret); BUG_ON(ret);
...@@ -490,15 +491,15 @@ int walk_up_tree(struct ctree_root *root, struct ctree_path *path, int *level) ...@@ -490,15 +491,15 @@ int walk_up_tree(struct ctree_root *root, struct ctree_path *path, int *level)
return 1; return 1;
} }
int btrfs_drop_snapshot(struct ctree_root *root, struct tree_buffer *snap) int btrfs_drop_snapshot(struct btrfs_root *root, struct btrfs_buffer *snap)
{ {
int ret; int ret;
int level; int level;
struct ctree_path path; struct btrfs_path path;
int i; int i;
int orig_level; int orig_level;
init_path(&path); btrfs_init_path(&path);
level = btrfs_header_level(&snap->node.header); level = btrfs_header_level(&snap->node.header);
orig_level = level; orig_level = level;
...@@ -514,7 +515,7 @@ int btrfs_drop_snapshot(struct ctree_root *root, struct tree_buffer *snap) ...@@ -514,7 +515,7 @@ int btrfs_drop_snapshot(struct ctree_root *root, struct tree_buffer *snap)
} }
for (i = 0; i <= orig_level; i++) { for (i = 0; i <= orig_level; i++) {
if (path.nodes[i]) { if (path.nodes[i]) {
tree_block_release(root, path.nodes[i]); btrfs_block_release(root, path.nodes[i]);
} }
} }
......
...@@ -12,10 +12,10 @@ ...@@ -12,10 +12,10 @@
int mkfs(int fd) int mkfs(int fd)
{ {
struct ctree_root_info info[2]; struct btrfs_root_info info[2];
struct leaf empty_leaf; struct btrfs_leaf empty_leaf;
struct btrfs_item item; struct btrfs_item item;
struct extent_item extent_item; struct btrfs_extent_item extent_item;
int ret; int ret;
/* setup the super block area */ /* setup the super block area */
...@@ -28,7 +28,7 @@ int mkfs(int fd) ...@@ -28,7 +28,7 @@ int mkfs(int fd)
info[1].objectid = 2; info[1].objectid = 2;
info[1].tree_root = 18; info[1].tree_root = 18;
ret = pwrite(fd, info, sizeof(info), ret = pwrite(fd, info, sizeof(info),
CTREE_SUPER_INFO_OFFSET(CTREE_BLOCKSIZE)); BTRFS_SUPER_INFO_OFFSET(BTRFS_BLOCKSIZE));
if (ret != sizeof(info)) if (ret != sizeof(info))
return -1; return -1;
...@@ -36,7 +36,7 @@ int mkfs(int fd) ...@@ -36,7 +36,7 @@ int mkfs(int fd)
memset(&empty_leaf, 0, sizeof(empty_leaf)); memset(&empty_leaf, 0, sizeof(empty_leaf));
btrfs_set_header_parentid(&empty_leaf.header, 1); btrfs_set_header_parentid(&empty_leaf.header, 1);
btrfs_set_header_blocknr(&empty_leaf.header, 17); btrfs_set_header_blocknr(&empty_leaf.header, 17);
ret = pwrite(fd, &empty_leaf, sizeof(empty_leaf), 17 * CTREE_BLOCKSIZE); ret = pwrite(fd, &empty_leaf, sizeof(empty_leaf), 17 * BTRFS_BLOCKSIZE);
if (ret != sizeof(empty_leaf)) if (ret != sizeof(empty_leaf))
return -1; return -1;
...@@ -48,9 +48,9 @@ int mkfs(int fd) ...@@ -48,9 +48,9 @@ int mkfs(int fd)
btrfs_set_key_objectid(&item.key, 0); btrfs_set_key_objectid(&item.key, 0);
btrfs_set_key_offset(&item.key, 17); btrfs_set_key_offset(&item.key, 17);
btrfs_set_key_flags(&item.key, 0); btrfs_set_key_flags(&item.key, 0);
btrfs_set_item_offset(&item, btrfs_set_item_offset(&item, LEAF_DATA_SIZE -
LEAF_DATA_SIZE - sizeof(struct extent_item)); sizeof(struct btrfs_extent_item));
btrfs_set_item_size(&item, sizeof(struct extent_item)); btrfs_set_item_size(&item, sizeof(struct btrfs_extent_item));
btrfs_set_extent_refs(&extent_item, 1); btrfs_set_extent_refs(&extent_item, 1);
btrfs_set_extent_owner(&extent_item, 0); btrfs_set_extent_owner(&extent_item, 0);
memcpy(empty_leaf.items, &item, sizeof(item)); memcpy(empty_leaf.items, &item, sizeof(item));
...@@ -60,8 +60,8 @@ int mkfs(int fd) ...@@ -60,8 +60,8 @@ int mkfs(int fd)
/* item2, give block 17 to the root */ /* item2, give block 17 to the root */
btrfs_set_key_objectid(&item.key, 17); btrfs_set_key_objectid(&item.key, 17);
btrfs_set_key_offset(&item.key, 1); btrfs_set_key_offset(&item.key, 1);
btrfs_set_item_offset(&item, btrfs_set_item_offset(&item, LEAF_DATA_SIZE -
LEAF_DATA_SIZE - sizeof(struct extent_item) * 2); sizeof(struct btrfs_extent_item) * 2);
btrfs_set_extent_owner(&extent_item, 1); btrfs_set_extent_owner(&extent_item, 1);
memcpy(empty_leaf.items + 1, &item, sizeof(item)); memcpy(empty_leaf.items + 1, &item, sizeof(item));
memcpy(empty_leaf.data + btrfs_item_offset(&item), &extent_item, memcpy(empty_leaf.data + btrfs_item_offset(&item), &extent_item,
...@@ -70,13 +70,13 @@ int mkfs(int fd) ...@@ -70,13 +70,13 @@ int mkfs(int fd)
/* item3, give block 18 for the extent root */ /* item3, give block 18 for the extent root */
btrfs_set_key_objectid(&item.key, 18); btrfs_set_key_objectid(&item.key, 18);
btrfs_set_key_offset(&item.key, 1); btrfs_set_key_offset(&item.key, 1);
btrfs_set_item_offset(&item, btrfs_set_item_offset(&item, LEAF_DATA_SIZE -
LEAF_DATA_SIZE - sizeof(struct extent_item) * 3); sizeof(struct btrfs_extent_item) * 3);
btrfs_set_extent_owner(&extent_item, 2); btrfs_set_extent_owner(&extent_item, 2);
memcpy(empty_leaf.items + 2, &item, sizeof(item)); memcpy(empty_leaf.items + 2, &item, sizeof(item));
memcpy(empty_leaf.data + btrfs_item_offset(&item), &extent_item, memcpy(empty_leaf.data + btrfs_item_offset(&item), &extent_item,
btrfs_item_size(&item)); btrfs_item_size(&item));
ret = pwrite(fd, &empty_leaf, sizeof(empty_leaf), 18 * CTREE_BLOCKSIZE); ret = pwrite(fd, &empty_leaf, sizeof(empty_leaf), 18 * BTRFS_BLOCKSIZE);
if (ret != sizeof(empty_leaf)) if (ret != sizeof(empty_leaf))
return -1; return -1;
return 0; return 0;
......
...@@ -5,14 +5,14 @@ ...@@ -5,14 +5,14 @@
#include "ctree.h" #include "ctree.h"
#include "disk-io.h" #include "disk-io.h"
void print_leaf(struct leaf *l) void btrfs_print_leaf(struct btrfs_leaf *l)
{ {
int i; int i;
u32 nr = btrfs_header_nritems(&l->header); u32 nr = btrfs_header_nritems(&l->header);
struct btrfs_item *item; struct btrfs_item *item;
struct extent_item *ei; struct btrfs_extent_item *ei;
printf("leaf %Lu total ptrs %d free space %d\n", printf("leaf %Lu total ptrs %d free space %d\n",
btrfs_header_blocknr(&l->header), nr, leaf_free_space(l)); btrfs_header_blocknr(&l->header), nr, btrfs_leaf_free_space(l));
fflush(stdout); fflush(stdout);
for (i = 0 ; i < nr ; i++) { for (i = 0 ; i < nr ; i++) {
item = l->items + i; item = l->items + i;
...@@ -26,24 +26,25 @@ void print_leaf(struct leaf *l) ...@@ -26,24 +26,25 @@ void print_leaf(struct leaf *l)
fflush(stdout); fflush(stdout);
printf("\t\titem data %.*s\n", btrfs_item_size(item), printf("\t\titem data %.*s\n", btrfs_item_size(item),
l->data + btrfs_item_offset(item)); l->data + btrfs_item_offset(item));
ei = (struct extent_item *)(l->data + btrfs_item_offset(item)); ei = (struct btrfs_extent_item *)(l->data +
btrfs_item_offset(item));
printf("\t\textent data refs %u owner %Lu\n", ei->refs, printf("\t\textent data refs %u owner %Lu\n", ei->refs,
ei->owner); ei->owner);
fflush(stdout); fflush(stdout);
} }
} }
void print_tree(struct ctree_root *root, struct tree_buffer *t) void btrfs_print_tree(struct btrfs_root *root, struct btrfs_buffer *t)
{ {
int i; int i;
u32 nr; u32 nr;
struct node *c; struct btrfs_node *c;
if (!t) if (!t)
return; return;
c = &t->node; c = &t->node;
nr = btrfs_header_nritems(&c->header); nr = btrfs_header_nritems(&c->header);
if (btrfs_is_leaf(c)) { if (btrfs_is_leaf(c)) {
print_leaf((struct leaf *)c); btrfs_print_leaf((struct btrfs_leaf *)c);
return; return;
} }
printf("node %Lu level %d total ptrs %d free spc %u\n", t->blocknr, printf("node %Lu level %d total ptrs %d free spc %u\n", t->blocknr,
...@@ -58,17 +59,17 @@ void print_tree(struct ctree_root *root, struct tree_buffer *t) ...@@ -58,17 +59,17 @@ void print_tree(struct ctree_root *root, struct tree_buffer *t)
fflush(stdout); fflush(stdout);
} }
for (i = 0; i < nr; i++) { for (i = 0; i < nr; i++) {
struct tree_buffer *next_buf = read_tree_block(root, struct btrfs_buffer *next_buf = read_tree_block(root,
btrfs_node_blockptr(c, i)); btrfs_node_blockptr(c, i));
struct node *next = &next_buf->node; struct btrfs_node *next = &next_buf->node;
if (btrfs_is_leaf(next) && if (btrfs_is_leaf(next) &&
btrfs_header_level(&c->header) != 1) btrfs_header_level(&c->header) != 1)
BUG(); BUG();
if (btrfs_header_level(&next->header) != if (btrfs_header_level(&next->header) !=
btrfs_header_level(&c->header) - 1) btrfs_header_level(&c->header) - 1)
BUG(); BUG();
print_tree(root, next_buf); btrfs_print_tree(root, next_buf);
tree_block_release(root, next_buf); btrfs_block_release(root, next_buf);
} }
} }
......
void print_leaf(struct leaf *l); void btrfs_print_leaf(struct btrfs_leaf *l);
void print_tree(struct ctree_root *root, struct tree_buffer *t); void btrfs_print_tree(struct btrfs_root *root, struct btrfs_buffer *t);
...@@ -22,9 +22,9 @@ int main(int ac, char **av) { ...@@ -22,9 +22,9 @@ int main(int ac, char **av) {
int run_size = 100000; int run_size = 100000;
int max_key = 100000000; int max_key = 100000000;
int tree_size = 0; int tree_size = 0;
struct ctree_path path; struct btrfs_path path;
struct ctree_super_block super; struct btrfs_super_block super;
struct ctree_root *root; struct btrfs_root *root;
radix_tree_init(); radix_tree_init();
...@@ -40,12 +40,12 @@ int main(int ac, char **av) { ...@@ -40,12 +40,12 @@ int main(int ac, char **av) {
ins.objectid = num; ins.objectid = num;
ins.offset = 0; ins.offset = 0;
ins.flags = 0; ins.flags = 0;
ret = insert_item(root, &ins, buf, strlen(buf)); ret = btrfs_insert_item(root, &ins, buf, strlen(buf));
if (!ret) if (!ret)
tree_size++; tree_size++;
free(buf); free(buf);
if (i == run_size - 5) { if (i == run_size - 5) {
commit_transaction(root, &super); btrfs_commit_transaction(root, &super);
} }
} }
...@@ -57,16 +57,16 @@ int main(int ac, char **av) { ...@@ -57,16 +57,16 @@ int main(int ac, char **av) {
for (i = 0; i < run_size; i++) { for (i = 0; i < run_size; i++) {
num = next_key(i, max_key); num = next_key(i, max_key);
ins.objectid = num; ins.objectid = num;
init_path(&path); btrfs_init_path(&path);
if (i % 10000 == 0) if (i % 10000 == 0)
fprintf(stderr, "search %d:%d\n", num, i); fprintf(stderr, "search %d:%d\n", num, i);
ret = search_slot(root, &ins, &path, 0, 0); ret = btrfs_search_slot(root, &ins, &path, 0, 0);
if (ret) { if (ret) {
print_tree(root, root->node); btrfs_print_tree(root, root->node);
printf("unable to find %d\n", num); printf("unable to find %d\n", num);
exit(1); exit(1);
} }
release_path(root, &path); btrfs_release_path(root, &path);
} }
close_ctree(root, &super); close_ctree(root, &super);
root = open_ctree("dbfile", &super); root = open_ctree("dbfile", &super);
...@@ -81,17 +81,17 @@ int main(int ac, char **av) { ...@@ -81,17 +81,17 @@ int main(int ac, char **av) {
for (i = 0 ; i < run_size/4; i++) { for (i = 0 ; i < run_size/4; i++) {
num = next_key(i, max_key); num = next_key(i, max_key);
ins.objectid = num; ins.objectid = num;
init_path(&path); btrfs_init_path(&path);
ret = search_slot(root, &ins, &path, -1, 1); ret = btrfs_search_slot(root, &ins, &path, -1, 1);
if (!ret) { if (!ret) {
if (i % 10000 == 0) if (i % 10000 == 0)
fprintf(stderr, "del %d:%d\n", num, i); fprintf(stderr, "del %d:%d\n", num, i);
ret = del_item(root, &path); ret = btrfs_del_item(root, &path);
if (ret != 0) if (ret != 0)
BUG(); BUG();
tree_size--; tree_size--;
} }
release_path(root, &path); btrfs_release_path(root, &path);
} }
close_ctree(root, &super); close_ctree(root, &super);
root = open_ctree("dbfile", &super); root = open_ctree("dbfile", &super);
...@@ -103,7 +103,7 @@ int main(int ac, char **av) { ...@@ -103,7 +103,7 @@ int main(int ac, char **av) {
ins.objectid = num; ins.objectid = num;
if (i % 10000 == 0) if (i % 10000 == 0)
fprintf(stderr, "insert %d:%d\n", num, i); fprintf(stderr, "insert %d:%d\n", num, i);
ret = insert_item(root, &ins, buf, strlen(buf)); ret = btrfs_insert_item(root, &ins, buf, strlen(buf));
if (!ret) if (!ret)
tree_size++; tree_size++;
free(buf); free(buf);
...@@ -115,25 +115,25 @@ int main(int ac, char **av) { ...@@ -115,25 +115,25 @@ int main(int ac, char **av) {
for (i = 0; i < run_size; i++) { for (i = 0; i < run_size; i++) {
num = next_key(i, max_key); num = next_key(i, max_key);
ins.objectid = num; ins.objectid = num;
init_path(&path); btrfs_init_path(&path);
if (i % 10000 == 0) if (i % 10000 == 0)
fprintf(stderr, "search %d:%d\n", num, i); fprintf(stderr, "search %d:%d\n", num, i);
ret = search_slot(root, &ins, &path, 0, 0); ret = btrfs_search_slot(root, &ins, &path, 0, 0);
if (ret) { if (ret) {
print_tree(root, root->node); btrfs_print_tree(root, root->node);
printf("unable to find %d\n", num); printf("unable to find %d\n", num);
exit(1); exit(1);
} }
release_path(root, &path); btrfs_release_path(root, &path);
} }
printf("starting big long delete run\n"); printf("starting big long delete run\n");
while(root->node && while(root->node &&
btrfs_header_nritems(&root->node->node.header) > 0) { btrfs_header_nritems(&root->node->node.header) > 0) {
struct leaf *leaf; struct btrfs_leaf *leaf;
int slot; int slot;
ins.objectid = (u64)-1; ins.objectid = (u64)-1;
init_path(&path); btrfs_init_path(&path);
ret = search_slot(root, &ins, &path, -1, 1); ret = btrfs_search_slot(root, &ins, &path, -1, 1);
if (ret == 0) if (ret == 0)
BUG(); BUG();
...@@ -149,26 +149,26 @@ int main(int ac, char **av) { ...@@ -149,26 +149,26 @@ int main(int ac, char **av) {
btrfs_disk_key_to_cpu(&last, &leaf->items[slot].key); btrfs_disk_key_to_cpu(&last, &leaf->items[slot].key);
if (tree_size % 10000 == 0) if (tree_size % 10000 == 0)
printf("big del %d:%d\n", tree_size, i); printf("big del %d:%d\n", tree_size, i);
ret = del_item(root, &path); ret = btrfs_del_item(root, &path);
if (ret != 0) { if (ret != 0) {
printf("del_item returned %d\n", ret); printf("del_item returned %d\n", ret);
BUG(); BUG();
} }
tree_size--; tree_size--;
} }
release_path(root, &path); btrfs_release_path(root, &path);
} }
/* /*
printf("previous tree:\n"); printf("previous tree:\n");
print_tree(root, root->commit_root); btrfs_print_tree(root, root->commit_root);
printf("map before commit\n"); printf("map before commit\n");
print_tree(root->extent_root, root->extent_root->node); btrfs_print_tree(root->extent_root, root->extent_root->node);
*/ */
commit_transaction(root, &super); btrfs_commit_transaction(root, &super);
printf("tree size is now %d\n", tree_size); printf("tree size is now %d\n", tree_size);
printf("root %p commit root %p\n", root->node, root->commit_root); printf("root %p commit root %p\n", root->node, root->commit_root);
printf("map tree\n"); printf("map tree\n");
print_tree(root->extent_root, root->extent_root->node); btrfs_print_tree(root->extent_root, root->extent_root->node);
close_ctree(root, &super); close_ctree(root, &super);
return 0; return 0;
} }
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include "print-tree.h" #include "print-tree.h"
int keep_running = 1; int keep_running = 1;
struct ctree_super_block super; struct btrfs_super_block super;
static int setup_key(struct radix_tree_root *root, struct btrfs_key *key, static int setup_key(struct radix_tree_root *root, struct btrfs_key *key,
int exists) int exists)
...@@ -36,17 +36,17 @@ static int setup_key(struct radix_tree_root *root, struct btrfs_key *key, ...@@ -36,17 +36,17 @@ static int setup_key(struct radix_tree_root *root, struct btrfs_key *key,
return 0; return 0;
} }
static int ins_one(struct ctree_root *root, struct radix_tree_root *radix) static int ins_one(struct btrfs_root *root, struct radix_tree_root *radix)
{ {
struct ctree_path path; struct btrfs_path path;
struct btrfs_key key; struct btrfs_key key;
int ret; int ret;
char buf[128]; char buf[128];
unsigned long oid; unsigned long oid;
init_path(&path); btrfs_init_path(&path);
ret = setup_key(radix, &key, 0); ret = setup_key(radix, &key, 0);
sprintf(buf, "str-%Lu\n", key.objectid); sprintf(buf, "str-%Lu\n", key.objectid);
ret = insert_item(root, &key, buf, strlen(buf)); ret = btrfs_insert_item(root, &key, buf, strlen(buf));
if (ret) if (ret)
goto error; goto error;
oid = (unsigned long)key.objectid; oid = (unsigned long)key.objectid;
...@@ -61,18 +61,18 @@ static int ins_one(struct ctree_root *root, struct radix_tree_root *radix) ...@@ -61,18 +61,18 @@ static int ins_one(struct ctree_root *root, struct radix_tree_root *radix)
return -1; return -1;
} }
static int insert_dup(struct ctree_root *root, struct radix_tree_root *radix) static int insert_dup(struct btrfs_root *root, struct radix_tree_root *radix)
{ {
struct ctree_path path; struct btrfs_path path;
struct btrfs_key key; struct btrfs_key key;
int ret; int ret;
char buf[128]; char buf[128];
init_path(&path); btrfs_init_path(&path);
ret = setup_key(radix, &key, 1); ret = setup_key(radix, &key, 1);
if (ret < 0) if (ret < 0)
return 0; return 0;
sprintf(buf, "str-%Lu\n", key.objectid); sprintf(buf, "str-%Lu\n", key.objectid);
ret = insert_item(root, &key, buf, strlen(buf)); ret = btrfs_insert_item(root, &key, buf, strlen(buf));
if (ret != -EEXIST) { if (ret != -EEXIST) {
printf("insert on %Lu gave us %d\n", key.objectid, ret); printf("insert on %Lu gave us %d\n", key.objectid, ret);
return 1; return 1;
...@@ -80,21 +80,21 @@ static int insert_dup(struct ctree_root *root, struct radix_tree_root *radix) ...@@ -80,21 +80,21 @@ static int insert_dup(struct ctree_root *root, struct radix_tree_root *radix)
return 0; return 0;
} }
static int del_one(struct ctree_root *root, struct radix_tree_root *radix) static int del_one(struct btrfs_root *root, struct radix_tree_root *radix)
{ {
struct ctree_path path; struct btrfs_path path;
struct btrfs_key key; struct btrfs_key key;
int ret; int ret;
unsigned long *ptr; unsigned long *ptr;
init_path(&path); btrfs_init_path(&path);
ret = setup_key(radix, &key, 1); ret = setup_key(radix, &key, 1);
if (ret < 0) if (ret < 0)
return 0; return 0;
ret = search_slot(root, &key, &path, -1, 1); ret = btrfs_search_slot(root, &key, &path, -1, 1);
if (ret) if (ret)
goto error; goto error;
ret = del_item(root, &path); ret = btrfs_del_item(root, &path);
release_path(root, &path); btrfs_release_path(root, &path);
if (ret != 0) if (ret != 0)
goto error; goto error;
ptr = radix_tree_delete(radix, key.objectid); ptr = radix_tree_delete(radix, key.objectid);
...@@ -106,17 +106,17 @@ static int del_one(struct ctree_root *root, struct radix_tree_root *radix) ...@@ -106,17 +106,17 @@ static int del_one(struct ctree_root *root, struct radix_tree_root *radix)
return -1; return -1;
} }
static int lookup_item(struct ctree_root *root, struct radix_tree_root *radix) static int lookup_item(struct btrfs_root *root, struct radix_tree_root *radix)
{ {
struct ctree_path path; struct btrfs_path path;
struct btrfs_key key; struct btrfs_key key;
int ret; int ret;
init_path(&path); btrfs_init_path(&path);
ret = setup_key(radix, &key, 1); ret = setup_key(radix, &key, 1);
if (ret < 0) if (ret < 0)
return 0; return 0;
ret = search_slot(root, &key, &path, 0, 1); ret = btrfs_search_slot(root, &key, &path, 0, 1);
release_path(root, &path); btrfs_release_path(root, &path);
if (ret) if (ret)
goto error; goto error;
return 0; return 0;
...@@ -125,17 +125,17 @@ static int lookup_item(struct ctree_root *root, struct radix_tree_root *radix) ...@@ -125,17 +125,17 @@ static int lookup_item(struct ctree_root *root, struct radix_tree_root *radix)
return -1; return -1;
} }
static int lookup_enoent(struct ctree_root *root, struct radix_tree_root *radix) static int lookup_enoent(struct btrfs_root *root, struct radix_tree_root *radix)
{ {
struct ctree_path path; struct btrfs_path path;
struct btrfs_key key; struct btrfs_key key;
int ret; int ret;
init_path(&path); btrfs_init_path(&path);
ret = setup_key(radix, &key, 0); ret = setup_key(radix, &key, 0);
if (ret < 0) if (ret < 0)
return ret; return ret;
ret = search_slot(root, &key, &path, 0, 0); ret = btrfs_search_slot(root, &key, &path, 0, 0);
release_path(root, &path); btrfs_release_path(root, &path);
if (ret <= 0) if (ret <= 0)
goto error; goto error;
return 0; return 0;
...@@ -144,10 +144,10 @@ static int lookup_enoent(struct ctree_root *root, struct radix_tree_root *radix) ...@@ -144,10 +144,10 @@ static int lookup_enoent(struct ctree_root *root, struct radix_tree_root *radix)
return -1; return -1;
} }
static int empty_tree(struct ctree_root *root, struct radix_tree_root *radix, static int empty_tree(struct btrfs_root *root, struct radix_tree_root *radix,
int nr) int nr)
{ {
struct ctree_path path; struct btrfs_path path;
struct btrfs_key key; struct btrfs_key key;
unsigned long found = 0; unsigned long found = 0;
int ret; int ret;
...@@ -159,22 +159,22 @@ static int empty_tree(struct ctree_root *root, struct radix_tree_root *radix, ...@@ -159,22 +159,22 @@ static int empty_tree(struct ctree_root *root, struct radix_tree_root *radix,
key.flags = 0; key.flags = 0;
key.objectid = (unsigned long)-1; key.objectid = (unsigned long)-1;
while(nr-- >= 0) { while(nr-- >= 0) {
init_path(&path); btrfs_init_path(&path);
ret = search_slot(root, &key, &path, -1, 1); ret = btrfs_search_slot(root, &key, &path, -1, 1);
if (ret < 0) { if (ret < 0) {
release_path(root, &path); btrfs_release_path(root, &path);
return ret; return ret;
} }
if (ret != 0) { if (ret != 0) {
if (path.slots[0] == 0) { if (path.slots[0] == 0) {
release_path(root, &path); btrfs_release_path(root, &path);
break; break;
} }
path.slots[0] -= 1; path.slots[0] -= 1;
} }
slot = path.slots[0]; slot = path.slots[0];
found=btrfs_key_objectid(&path.nodes[0]->leaf.items[slot].key); found=btrfs_key_objectid(&path.nodes[0]->leaf.items[slot].key);
ret = del_item(root, &path); ret = btrfs_del_item(root, &path);
count++; count++;
if (ret) { if (ret) {
fprintf(stderr, fprintf(stderr,
...@@ -182,7 +182,7 @@ static int empty_tree(struct ctree_root *root, struct radix_tree_root *radix, ...@@ -182,7 +182,7 @@ static int empty_tree(struct ctree_root *root, struct radix_tree_root *radix,
found); found);
return -1; return -1;
} }
release_path(root, &path); btrfs_release_path(root, &path);
ptr = radix_tree_delete(radix, found); ptr = radix_tree_delete(radix, found);
if (!ptr) if (!ptr)
goto error; goto error;
...@@ -195,7 +195,7 @@ static int empty_tree(struct ctree_root *root, struct radix_tree_root *radix, ...@@ -195,7 +195,7 @@ static int empty_tree(struct ctree_root *root, struct radix_tree_root *radix,
return -1; return -1;
} }
static int fill_tree(struct ctree_root *root, struct radix_tree_root *radix, static int fill_tree(struct btrfs_root *root, struct radix_tree_root *radix,
int count) int count)
{ {
int i; int i;
...@@ -207,7 +207,7 @@ static int fill_tree(struct ctree_root *root, struct radix_tree_root *radix, ...@@ -207,7 +207,7 @@ static int fill_tree(struct ctree_root *root, struct radix_tree_root *radix,
goto out; goto out;
} }
if (i % 1000 == 0) { if (i % 1000 == 0) {
ret = commit_transaction(root, &super); ret = btrfs_commit_transaction(root, &super);
if (ret) { if (ret) {
fprintf(stderr, "fill commit failed\n"); fprintf(stderr, "fill commit failed\n");
return ret; return ret;
...@@ -223,7 +223,7 @@ static int fill_tree(struct ctree_root *root, struct radix_tree_root *radix, ...@@ -223,7 +223,7 @@ static int fill_tree(struct ctree_root *root, struct radix_tree_root *radix,
return ret; return ret;
} }
static int bulk_op(struct ctree_root *root, struct radix_tree_root *radix) static int bulk_op(struct btrfs_root *root, struct radix_tree_root *radix)
{ {
int ret; int ret;
int nr = rand() % 5000; int nr = rand() % 5000;
...@@ -242,13 +242,13 @@ static int bulk_op(struct ctree_root *root, struct radix_tree_root *radix) ...@@ -242,13 +242,13 @@ static int bulk_op(struct ctree_root *root, struct radix_tree_root *radix)
} }
int (*ops[])(struct ctree_root *root, struct radix_tree_root *radix) = int (*ops[])(struct btrfs_root *root, struct radix_tree_root *radix) =
{ ins_one, insert_dup, del_one, lookup_item, { ins_one, insert_dup, del_one, lookup_item,
lookup_enoent, bulk_op }; lookup_enoent, bulk_op };
static int fill_radix(struct ctree_root *root, struct radix_tree_root *radix) static int fill_radix(struct btrfs_root *root, struct radix_tree_root *radix)
{ {
struct ctree_path path; struct btrfs_path path;
struct btrfs_key key; struct btrfs_key key;
unsigned long found; unsigned long found;
int ret; int ret;
...@@ -259,16 +259,16 @@ static int fill_radix(struct ctree_root *root, struct radix_tree_root *radix) ...@@ -259,16 +259,16 @@ static int fill_radix(struct ctree_root *root, struct radix_tree_root *radix)
key.flags = 0; key.flags = 0;
key.objectid = (unsigned long)-1; key.objectid = (unsigned long)-1;
while(1) { while(1) {
init_path(&path); btrfs_init_path(&path);
ret = search_slot(root, &key, &path, 0, 0); ret = btrfs_search_slot(root, &key, &path, 0, 0);
if (ret < 0) { if (ret < 0) {
release_path(root, &path); btrfs_release_path(root, &path);
return ret; return ret;
} }
slot = path.slots[0]; slot = path.slots[0];
if (ret != 0) { if (ret != 0) {
if (slot == 0) { if (slot == 0) {
release_path(root, &path); btrfs_release_path(root, &path);
break; break;
} }
slot -= 1; slot -= 1;
...@@ -287,7 +287,7 @@ static int fill_radix(struct ctree_root *root, struct radix_tree_root *radix) ...@@ -287,7 +287,7 @@ static int fill_radix(struct ctree_root *root, struct radix_tree_root *radix)
radix_tree_preload_end(); radix_tree_preload_end();
} }
release_path(root, &path); btrfs_release_path(root, &path);
key.objectid = found - 1; key.objectid = found - 1;
if (key.objectid > found) if (key.objectid > found)
break; break;
...@@ -312,7 +312,7 @@ int print_usage(void) ...@@ -312,7 +312,7 @@ int print_usage(void)
int main(int ac, char **av) int main(int ac, char **av)
{ {
RADIX_TREE(radix, GFP_KERNEL); RADIX_TREE(radix, GFP_KERNEL);
struct ctree_root *root; struct btrfs_root *root;
int i; int i;
int ret; int ret;
int count; int count;
...@@ -370,7 +370,7 @@ int main(int ac, char **av) ...@@ -370,7 +370,7 @@ int main(int ac, char **av)
if (ret) { if (ret) {
fprintf(stderr, "op %d failed %d:%d\n", fprintf(stderr, "op %d failed %d:%d\n",
op, i, iterations); op, i, iterations);
print_tree(root, root->node); btrfs_print_tree(root, root->node);
fprintf(stderr, "op %d failed %d:%d\n", fprintf(stderr, "op %d failed %d:%d\n",
op, i, iterations); op, i, iterations);
err = ret; err = ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment