提交 234b63a0 编写于 作者: C Chris Mason 提交者: David Woodhouse

rename funcs and structs to btrfs

Signed-off-by: NChris Mason <chris.mason@oracle.com>
上级 cf27e1ee
此差异已折叠。
#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% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册