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
This diff is collapsed.
#ifndef __CTREE__
#define __CTREE__
#ifndef __BTRFS__
#define __BTRFS__
#include "list.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)
......@@ -46,21 +46,21 @@ struct btrfs_header {
/* generation flags to be added */
} __attribute__ ((__packed__));
#define MAX_LEVEL 8
#define NODEPTRS_PER_BLOCK ((CTREE_BLOCKSIZE - sizeof(struct btrfs_header)) / \
#define BTRFS_MAX_LEVEL 8
#define NODEPTRS_PER_BLOCK ((BTRFS_BLOCKSIZE - sizeof(struct btrfs_header)) / \
(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
* and for the extent tree extent_root root. current_insert is used
* only for the extent tree.
*/
struct ctree_root {
struct tree_buffer *node;
struct tree_buffer *commit_root;
struct ctree_root *extent_root;
struct btrfs_root {
struct btrfs_buffer *node;
struct btrfs_buffer *commit_root;
struct btrfs_root *extent_root;
struct btrfs_key current_insert;
struct btrfs_key last_insert;
int fp;
......@@ -74,7 +74,7 @@ struct ctree_root {
/*
* describes a tree on disk
*/
struct ctree_root_info {
struct btrfs_root_info {
u64 fsid[2]; /* FS specific uuid */
u64 blocknr; /* blocknr of this block */
u64 objectid; /* inode number of this root */
......@@ -88,9 +88,9 @@ struct ctree_root_info {
* the super block basically lists the main trees of the FS
* it currently lacks any block count etc etc
*/
struct ctree_super_block {
struct ctree_root_info root_info;
struct ctree_root_info extent_info;
struct btrfs_super_block {
struct btrfs_root_info root_info;
struct btrfs_root_info extent_info;
} __attribute__ ((__packed__));
/*
......@@ -111,13 +111,13 @@ struct btrfs_item {
* The data is separate from the items to get the keys closer together
* during searches.
*/
#define LEAF_DATA_SIZE (CTREE_BLOCKSIZE - sizeof(struct btrfs_header))
struct leaf {
#define LEAF_DATA_SIZE (BTRFS_BLOCKSIZE - sizeof(struct btrfs_header))
struct btrfs_leaf {
struct btrfs_header header;
union {
struct btrfs_item items[LEAF_DATA_SIZE/
sizeof(struct btrfs_item)];
u8 data[CTREE_BLOCKSIZE-sizeof(struct btrfs_header)];
u8 data[BTRFS_BLOCKSIZE - sizeof(struct btrfs_header)];
};
} __attribute__ ((__packed__));
......@@ -125,7 +125,7 @@ struct leaf {
* all non-leaf blocks are nodes, they hold only keys and pointers to
* other blocks
*/
struct node {
struct btrfs_node {
struct btrfs_header header;
struct btrfs_disk_key keys[NODEPTRS_PER_BLOCK];
__le64 blockptrs[NODEPTRS_PER_BLOCK];
......@@ -135,50 +135,51 @@ struct node {
* items in the extent btree are used to record the objectid of the
* owner of the block and the number of references
*/
struct extent_item {
struct btrfs_extent_item {
__le32 refs;
__le64 owner;
} __attribute__ ((__packed__));
/*
* ctree_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
* btrfs_paths remember the path taken from the root down to the leaf.
* level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point
* to any other levels that are present.
*
* The slots array records the index of the item or block pointer
* used while walking the tree.
*/
struct ctree_path {
struct tree_buffer *nodes[MAX_LEVEL];
int slots[MAX_LEVEL];
struct btrfs_path {
struct btrfs_buffer *nodes[BTRFS_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);
}
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);
}
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);
}
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);
}
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]);
}
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);
}
......@@ -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)
{
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)
{
u16 flags;
BUG_ON(level > MAX_LEVEL);
flags = btrfs_header_flags(h) & ~(MAX_LEVEL - 1);
BUG_ON(level > BTRFS_MAX_LEVEL);
flags = btrfs_header_flags(h) & ~(BTRFS_MAX_LEVEL - 1);
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);
}
struct tree_buffer *alloc_free_block(struct ctree_root *root);
int btrfs_inc_ref(struct ctree_root *root, struct tree_buffer *buf);
int free_extent(struct ctree_root *root, u64 blocknr, u64 num_blocks);
int search_slot(struct ctree_root *root, struct btrfs_key *key,
struct ctree_path *p, int ins_len, int cow);
void release_path(struct ctree_root *root, struct ctree_path *p);
void init_path(struct ctree_path *p);
int del_item(struct ctree_root *root, struct ctree_path *path);
int insert_item(struct ctree_root *root, struct btrfs_key *key,
struct btrfs_buffer *btrfs_alloc_free_block(struct btrfs_root *root);
int btrfs_inc_ref(struct btrfs_root *root, struct btrfs_buffer *buf);
int btrfs_free_extent(struct btrfs_root *root, u64 blocknr, u64 num_blocks);
int btrfs_search_slot(struct btrfs_root *root, struct btrfs_key *key,
struct btrfs_path *p, int ins_len, int cow);
void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
void btrfs_init_path(struct btrfs_path *p);
int btrfs_del_item(struct btrfs_root *root, struct btrfs_path *path);
int btrfs_insert_item(struct btrfs_root *root, struct btrfs_key *key,
void *data, int data_size);
int next_leaf(struct ctree_root *root, struct ctree_path *path);
int leaf_free_space(struct leaf *leaf);
int btrfs_drop_snapshot(struct ctree_root *root, struct tree_buffer *snap);
int btrfs_finish_extent_commit(struct ctree_root *root);
int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
int btrfs_leaf_free_space(struct btrfs_leaf *leaf);
int btrfs_drop_snapshot(struct btrfs_root *root, struct btrfs_buffer *snap);
int btrfs_finish_extent_commit(struct btrfs_root *root);
#endif
......@@ -7,13 +7,13 @@
#include "print-tree.h"
int main(int ac, char **av) {
struct ctree_super_block super;
struct ctree_root *root;
struct btrfs_super_block super;
struct btrfs_root *root;
radix_tree_init();
root = open_ctree("dbfile", &super);
printf("root tree\n");
print_tree(root, root->node);
btrfs_print_tree(root, root->node);
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;
}
......@@ -13,7 +13,7 @@
static int allocated_blocks = 0;
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))
BUG();
......@@ -23,18 +23,18 @@ static int check_tree_block(struct ctree_root *root, struct tree_buffer *buf)
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 tree_buffer *b;
struct btrfs_buffer *b;
if (root->cache_size < cache_max)
return 0;
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) {
BUG_ON(!list_empty(&b->dirty));
list_del_init(&b->cache);
tree_block_release(root, b);
btrfs_block_release(root, b);
if (root->cache_size < cache_max)
break;
}
......@@ -42,11 +42,11 @@ static int free_some_buffers(struct ctree_root *root)
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;
buf = malloc(sizeof(struct tree_buffer));
buf = malloc(sizeof(struct btrfs_buffer));
if (!buf)
return buf;
allocated_blocks++;
......@@ -66,9 +66,9 @@ struct tree_buffer *alloc_tree_block(struct ctree_root *root, u64 blocknr)
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);
if (buf) {
buf->count++;
......@@ -82,10 +82,10 @@ struct tree_buffer *find_tree_block(struct ctree_root *root, u64 blocknr)
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;
struct tree_buffer *buf;
loff_t offset = blocknr * BTRFS_BLOCKSIZE;
struct btrfs_buffer *buf;
int ret;
buf = radix_tree_lookup(&root->cache_radix, blocknr);
......@@ -95,8 +95,8 @@ struct tree_buffer *read_tree_block(struct ctree_root *root, u64 blocknr)
buf = alloc_tree_block(root, blocknr);
if (!buf)
return NULL;
ret = pread(root->fp, &buf->node, CTREE_BLOCKSIZE, offset);
if (ret != CTREE_BLOCKSIZE) {
ret = pread(root->fp, &buf->node, BTRFS_BLOCKSIZE, offset);
if (ret != BTRFS_BLOCKSIZE) {
free(buf);
return NULL;
}
......@@ -106,7 +106,7 @@ struct tree_buffer *read_tree_block(struct ctree_root *root, u64 blocknr)
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))
return 0;
......@@ -115,46 +115,47 @@ int dirty_tree_block(struct ctree_root *root, struct tree_buffer *buf)
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)) {
list_del_init(&buf->dirty);
tree_block_release(root, buf);
btrfs_block_release(root, buf);
}
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;
loff_t offset = blocknr * CTREE_BLOCKSIZE;
loff_t offset = blocknr * BTRFS_BLOCKSIZE;
int ret;
if (buf->blocknr != btrfs_header_blocknr(&buf->node.header))
BUG();
ret = pwrite(root->fp, &buf->node, CTREE_BLOCKSIZE, offset);
if (ret != CTREE_BLOCKSIZE)
ret = pwrite(root->fp, &buf->node, BTRFS_BLOCKSIZE, offset);
if (ret != BTRFS_BLOCKSIZE)
return ret;
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 wret;
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);
wret = write_tree_block(root, b);
if (wret)
ret = wret;
tree_block_release(root, b);
btrfs_block_release(root, b);
}
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;
......@@ -163,20 +164,20 @@ int commit_transaction(struct ctree_root *root, struct ctree_super_block *s)
ret = __commit_transaction(root->extent_root);
BUG_ON(ret);
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->node->count++;
ret = btrfs_drop_snapshot(root, snap);
BUG_ON(ret);
// tree_block_release(root, snap);
// btrfs_block_release(root, snap);
}
write_ctree_super(root, s);
btrfs_finish_extent_commit(root);
return ret;
}
static int __setup_root(struct ctree_root *root, struct ctree_root *extent_root,
struct ctree_root_info *info, int fp)
static int __setup_root(struct btrfs_root *root, struct btrfs_root *extent_root,
struct btrfs_root_info *info, int fp)
{
INIT_LIST_HEAD(&root->trans);
INIT_LIST_HEAD(&root->cache);
......@@ -191,10 +192,10 @@ static int __setup_root(struct ctree_root *root, struct ctree_root *extent_root,
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 ctree_root *extent_root = malloc(sizeof(struct ctree_root));
struct btrfs_root *root = malloc(sizeof(struct btrfs_root));
struct btrfs_root *extent_root = malloc(sizeof(struct btrfs_root));
int fp;
int ret;
......@@ -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(&extent_root->pinned_radix, GFP_KERNEL);
INIT_RADIX_TREE(&extent_root->cache_radix, GFP_KERNEL);
ret = pread(fp, super, sizeof(struct ctree_super_block),
CTREE_SUPER_INFO_OFFSET(CTREE_BLOCKSIZE));
ret = pread(fp, super, sizeof(struct btrfs_super_block),
BTRFS_SUPER_INFO_OFFSET(BTRFS_BLOCKSIZE));
if (ret == 0 || super->root_info.tree_root == 0) {
printf("making new FS!\n");
ret = mkfs(fp);
if (ret)
return NULL;
ret = pread(fp, super, sizeof(struct ctree_super_block),
CTREE_SUPER_INFO_OFFSET(CTREE_BLOCKSIZE));
if (ret != sizeof(struct ctree_super_block))
ret = pread(fp, super, sizeof(struct btrfs_super_block),
BTRFS_SUPER_INFO_OFFSET(BTRFS_BLOCKSIZE));
if (ret != sizeof(struct btrfs_super_block))
return NULL;
}
BUG_ON(ret < 0);
......@@ -227,18 +228,19 @@ struct ctree_root *open_ctree(char *filename, struct ctree_super_block *super)
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;
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;
__update_root(root, &s->root_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)) {
fprintf(stderr, "failed to write new super block err %d\n", ret);
return ret;
......@@ -246,19 +248,19 @@ int write_ctree_super(struct ctree_root *root, struct ctree_super_block *s)
return 0;
}
static int drop_cache(struct ctree_root *root)
static int drop_cache(struct btrfs_root *root)
{
while(!list_empty(&root->cache)) {
struct tree_buffer *b = list_entry(root->cache.next,
struct tree_buffer, cache);
struct btrfs_buffer *b = list_entry(root->cache.next,
struct btrfs_buffer, cache);
list_del_init(&b->cache);
tree_block_release(root, b);
btrfs_block_release(root, b);
}
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);
write_ctree_super(root, s);
drop_cache(root->extent_root);
......@@ -268,16 +270,16 @@ int close_ctree(struct ctree_root *root, struct ctree_super_block *s)
close(root->fp);
if (root->node)
tree_block_release(root, root->node);
btrfs_block_release(root, root->node);
if (root->extent_root->node)
tree_block_release(root->extent_root, root->extent_root->node);
tree_block_release(root, root->commit_root);
btrfs_block_release(root->extent_root, root->extent_root->node);
btrfs_block_release(root, root->commit_root);
free(root);
printf("on close %d blocks are allocated\n", allocated_blocks);
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--;
if (buf->count < 0)
......
......@@ -2,29 +2,30 @@
#define __DISKIO__
#include "list.h"
struct tree_buffer {
struct btrfs_buffer {
u64 blocknr;
int count;
union {
struct node node;
struct leaf leaf;
struct btrfs_node node;
struct btrfs_leaf leaf;
};
struct list_head dirty;
struct list_head cache;
};
struct tree_buffer *read_tree_block(struct ctree_root *root, u64 blocknr);
struct tree_buffer *find_tree_block(struct ctree_root *root, u64 blocknr);
int write_tree_block(struct ctree_root *root, struct tree_buffer *buf);
int dirty_tree_block(struct ctree_root *root, struct tree_buffer *buf);
int clean_tree_block(struct ctree_root *root, struct tree_buffer *buf);
int commit_transaction(struct ctree_root *root, struct ctree_super_block *s);
struct ctree_root *open_ctree(char *filename, struct ctree_super_block *s);
int close_ctree(struct ctree_root *root, struct ctree_super_block *s);
void tree_block_release(struct ctree_root *root, struct tree_buffer *buf);
int write_ctree_super(struct ctree_root *root, struct ctree_super_block *s);
struct btrfs_buffer *read_tree_block(struct btrfs_root *root, u64 blocknr);
struct btrfs_buffer *find_tree_block(struct btrfs_root *root, u64 blocknr);
int write_tree_block(struct btrfs_root *root, struct btrfs_buffer *buf);
int dirty_tree_block(struct btrfs_root *root, struct btrfs_buffer *buf);
int clean_tree_block(struct btrfs_root *root, struct btrfs_buffer *buf);
int btrfs_commit_transaction(struct btrfs_root *root,
struct btrfs_super_block *s);
struct btrfs_root *open_ctree(char *filename, struct btrfs_super_block *s);
int close_ctree(struct btrfs_root *root, struct btrfs_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);
#define CTREE_SUPER_INFO_OFFSET(bs) (16 * (bs))
#define BTRFS_SUPER_INFO_OFFSET(bs) (16 * (bs))
#endif
This diff is collapsed.
......@@ -12,10 +12,10 @@
int mkfs(int fd)
{
struct ctree_root_info info[2];
struct leaf empty_leaf;
struct btrfs_root_info info[2];
struct btrfs_leaf empty_leaf;
struct btrfs_item item;
struct extent_item extent_item;
struct btrfs_extent_item extent_item;
int ret;
/* setup the super block area */
......@@ -28,7 +28,7 @@ int mkfs(int fd)
info[1].objectid = 2;
info[1].tree_root = 18;
ret = pwrite(fd, info, sizeof(info),
CTREE_SUPER_INFO_OFFSET(CTREE_BLOCKSIZE));
BTRFS_SUPER_INFO_OFFSET(BTRFS_BLOCKSIZE));
if (ret != sizeof(info))
return -1;
......@@ -36,7 +36,7 @@ int mkfs(int fd)
memset(&empty_leaf, 0, sizeof(empty_leaf));
btrfs_set_header_parentid(&empty_leaf.header, 1);
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))
return -1;
......@@ -48,9 +48,9 @@ int mkfs(int fd)
btrfs_set_key_objectid(&item.key, 0);
btrfs_set_key_offset(&item.key, 17);
btrfs_set_key_flags(&item.key, 0);
btrfs_set_item_offset(&item,
LEAF_DATA_SIZE - sizeof(struct extent_item));
btrfs_set_item_size(&item, sizeof(struct extent_item));
btrfs_set_item_offset(&item, LEAF_DATA_SIZE -
sizeof(struct btrfs_extent_item));
btrfs_set_item_size(&item, sizeof(struct btrfs_extent_item));
btrfs_set_extent_refs(&extent_item, 1);
btrfs_set_extent_owner(&extent_item, 0);
memcpy(empty_leaf.items, &item, sizeof(item));
......@@ -60,8 +60,8 @@ int mkfs(int fd)
/* item2, give block 17 to the root */
btrfs_set_key_objectid(&item.key, 17);
btrfs_set_key_offset(&item.key, 1);
btrfs_set_item_offset(&item,
LEAF_DATA_SIZE - sizeof(struct extent_item) * 2);
btrfs_set_item_offset(&item, LEAF_DATA_SIZE -
sizeof(struct btrfs_extent_item) * 2);
btrfs_set_extent_owner(&extent_item, 1);
memcpy(empty_leaf.items + 1, &item, sizeof(item));
memcpy(empty_leaf.data + btrfs_item_offset(&item), &extent_item,
......@@ -70,13 +70,13 @@ int mkfs(int fd)
/* item3, give block 18 for the extent root */
btrfs_set_key_objectid(&item.key, 18);
btrfs_set_key_offset(&item.key, 1);
btrfs_set_item_offset(&item,
LEAF_DATA_SIZE - sizeof(struct extent_item) * 3);
btrfs_set_item_offset(&item, LEAF_DATA_SIZE -
sizeof(struct btrfs_extent_item) * 3);
btrfs_set_extent_owner(&extent_item, 2);
memcpy(empty_leaf.items + 2, &item, sizeof(item));
memcpy(empty_leaf.data + btrfs_item_offset(&item), &extent_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))
return -1;
return 0;
......
......@@ -5,14 +5,14 @@
#include "ctree.h"
#include "disk-io.h"
void print_leaf(struct leaf *l)
void btrfs_print_leaf(struct btrfs_leaf *l)
{
int i;
u32 nr = btrfs_header_nritems(&l->header);
struct btrfs_item *item;
struct extent_item *ei;
struct btrfs_extent_item *ei;
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);
for (i = 0 ; i < nr ; i++) {
item = l->items + i;
......@@ -26,24 +26,25 @@ void print_leaf(struct leaf *l)
fflush(stdout);
printf("\t\titem data %.*s\n", btrfs_item_size(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,
ei->owner);
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;
u32 nr;
struct node *c;
struct btrfs_node *c;
if (!t)
return;
c = &t->node;
nr = btrfs_header_nritems(&c->header);
if (btrfs_is_leaf(c)) {
print_leaf((struct leaf *)c);
btrfs_print_leaf((struct btrfs_leaf *)c);
return;
}
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)
fflush(stdout);
}
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));
struct node *next = &next_buf->node;
struct btrfs_node *next = &next_buf->node;
if (btrfs_is_leaf(next) &&
btrfs_header_level(&c->header) != 1)
BUG();
if (btrfs_header_level(&next->header) !=
btrfs_header_level(&c->header) - 1)
BUG();
print_tree(root, next_buf);
tree_block_release(root, next_buf);
btrfs_print_tree(root, next_buf);
btrfs_block_release(root, next_buf);
}
}
......
void print_leaf(struct leaf *l);
void print_tree(struct ctree_root *root, struct tree_buffer *t);
void btrfs_print_leaf(struct btrfs_leaf *l);
void btrfs_print_tree(struct btrfs_root *root, struct btrfs_buffer *t);
......@@ -22,9 +22,9 @@ int main(int ac, char **av) {
int run_size = 100000;
int max_key = 100000000;
int tree_size = 0;
struct ctree_path path;
struct ctree_super_block super;
struct ctree_root *root;
struct btrfs_path path;
struct btrfs_super_block super;
struct btrfs_root *root;
radix_tree_init();
......@@ -40,12 +40,12 @@ int main(int ac, char **av) {
ins.objectid = num;
ins.offset = 0;
ins.flags = 0;
ret = insert_item(root, &ins, buf, strlen(buf));
ret = btrfs_insert_item(root, &ins, buf, strlen(buf));
if (!ret)
tree_size++;
free(buf);
if (i == run_size - 5) {
commit_transaction(root, &super);
btrfs_commit_transaction(root, &super);
}
}
......@@ -57,16 +57,16 @@ int main(int ac, char **av) {
for (i = 0; i < run_size; i++) {
num = next_key(i, max_key);
ins.objectid = num;
init_path(&path);
btrfs_init_path(&path);
if (i % 10000 == 0)
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) {
print_tree(root, root->node);
btrfs_print_tree(root, root->node);
printf("unable to find %d\n", num);
exit(1);
}
release_path(root, &path);
btrfs_release_path(root, &path);
}
close_ctree(root, &super);
root = open_ctree("dbfile", &super);
......@@ -81,17 +81,17 @@ int main(int ac, char **av) {
for (i = 0 ; i < run_size/4; i++) {
num = next_key(i, max_key);
ins.objectid = num;
init_path(&path);
ret = search_slot(root, &ins, &path, -1, 1);
btrfs_init_path(&path);
ret = btrfs_search_slot(root, &ins, &path, -1, 1);
if (!ret) {
if (i % 10000 == 0)
fprintf(stderr, "del %d:%d\n", num, i);
ret = del_item(root, &path);
ret = btrfs_del_item(root, &path);
if (ret != 0)
BUG();
tree_size--;
}
release_path(root, &path);
btrfs_release_path(root, &path);
}
close_ctree(root, &super);
root = open_ctree("dbfile", &super);
......@@ -103,7 +103,7 @@ int main(int ac, char **av) {
ins.objectid = num;
if (i % 10000 == 0)
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)
tree_size++;
free(buf);
......@@ -115,25 +115,25 @@ int main(int ac, char **av) {
for (i = 0; i < run_size; i++) {
num = next_key(i, max_key);
ins.objectid = num;
init_path(&path);
btrfs_init_path(&path);
if (i % 10000 == 0)
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) {
print_tree(root, root->node);
btrfs_print_tree(root, root->node);
printf("unable to find %d\n", num);
exit(1);
}
release_path(root, &path);
btrfs_release_path(root, &path);
}
printf("starting big long delete run\n");
while(root->node &&
btrfs_header_nritems(&root->node->node.header) > 0) {
struct leaf *leaf;
struct btrfs_leaf *leaf;
int slot;
ins.objectid = (u64)-1;
init_path(&path);
ret = search_slot(root, &ins, &path, -1, 1);
btrfs_init_path(&path);
ret = btrfs_search_slot(root, &ins, &path, -1, 1);
if (ret == 0)
BUG();
......@@ -149,26 +149,26 @@ int main(int ac, char **av) {
btrfs_disk_key_to_cpu(&last, &leaf->items[slot].key);
if (tree_size % 10000 == 0)
printf("big del %d:%d\n", tree_size, i);
ret = del_item(root, &path);
ret = btrfs_del_item(root, &path);
if (ret != 0) {
printf("del_item returned %d\n", ret);
BUG();
}
tree_size--;
}
release_path(root, &path);
btrfs_release_path(root, &path);
}
/*
printf("previous tree:\n");
print_tree(root, root->commit_root);
btrfs_print_tree(root, root->commit_root);
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("root %p commit root %p\n", root->node, root->commit_root);
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);
return 0;
}
......@@ -8,7 +8,7 @@
#include "print-tree.h"
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,
int exists)
......@@ -36,17 +36,17 @@ static int setup_key(struct radix_tree_root *root, struct btrfs_key *key,
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;
int ret;
char buf[128];
unsigned long oid;
init_path(&path);
btrfs_init_path(&path);
ret = setup_key(radix, &key, 0);
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)
goto error;
oid = (unsigned long)key.objectid;
......@@ -61,18 +61,18 @@ static int ins_one(struct ctree_root *root, struct radix_tree_root *radix)
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;
int ret;
char buf[128];
init_path(&path);
btrfs_init_path(&path);
ret = setup_key(radix, &key, 1);
if (ret < 0)
return 0;
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) {
printf("insert on %Lu gave us %d\n", key.objectid, ret);
return 1;
......@@ -80,21 +80,21 @@ static int insert_dup(struct ctree_root *root, struct radix_tree_root *radix)
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;
int ret;
unsigned long *ptr;
init_path(&path);
btrfs_init_path(&path);
ret = setup_key(radix, &key, 1);
if (ret < 0)
return 0;
ret = search_slot(root, &key, &path, -1, 1);
ret = btrfs_search_slot(root, &key, &path, -1, 1);
if (ret)
goto error;
ret = del_item(root, &path);
release_path(root, &path);
ret = btrfs_del_item(root, &path);
btrfs_release_path(root, &path);
if (ret != 0)
goto error;
ptr = radix_tree_delete(radix, key.objectid);
......@@ -106,17 +106,17 @@ static int del_one(struct ctree_root *root, struct radix_tree_root *radix)
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;
int ret;
init_path(&path);
btrfs_init_path(&path);
ret = setup_key(radix, &key, 1);
if (ret < 0)
return 0;
ret = search_slot(root, &key, &path, 0, 1);
release_path(root, &path);
ret = btrfs_search_slot(root, &key, &path, 0, 1);
btrfs_release_path(root, &path);
if (ret)
goto error;
return 0;
......@@ -125,17 +125,17 @@ static int lookup_item(struct ctree_root *root, struct radix_tree_root *radix)
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;
int ret;
init_path(&path);
btrfs_init_path(&path);
ret = setup_key(radix, &key, 0);
if (ret < 0)
return ret;
ret = search_slot(root, &key, &path, 0, 0);
release_path(root, &path);
ret = btrfs_search_slot(root, &key, &path, 0, 0);
btrfs_release_path(root, &path);
if (ret <= 0)
goto error;
return 0;
......@@ -144,10 +144,10 @@ static int lookup_enoent(struct ctree_root *root, struct radix_tree_root *radix)
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)
{
struct ctree_path path;
struct btrfs_path path;
struct btrfs_key key;
unsigned long found = 0;
int ret;
......@@ -159,22 +159,22 @@ static int empty_tree(struct ctree_root *root, struct radix_tree_root *radix,
key.flags = 0;
key.objectid = (unsigned long)-1;
while(nr-- >= 0) {
init_path(&path);
ret = search_slot(root, &key, &path, -1, 1);
btrfs_init_path(&path);
ret = btrfs_search_slot(root, &key, &path, -1, 1);
if (ret < 0) {
release_path(root, &path);
btrfs_release_path(root, &path);
return ret;
}
if (ret != 0) {
if (path.slots[0] == 0) {
release_path(root, &path);
btrfs_release_path(root, &path);
break;
}
path.slots[0] -= 1;
}
slot = path.slots[0];
found=btrfs_key_objectid(&path.nodes[0]->leaf.items[slot].key);
ret = del_item(root, &path);
ret = btrfs_del_item(root, &path);
count++;
if (ret) {
fprintf(stderr,
......@@ -182,7 +182,7 @@ static int empty_tree(struct ctree_root *root, struct radix_tree_root *radix,
found);
return -1;
}
release_path(root, &path);
btrfs_release_path(root, &path);
ptr = radix_tree_delete(radix, found);
if (!ptr)
goto error;
......@@ -195,7 +195,7 @@ static int empty_tree(struct ctree_root *root, struct radix_tree_root *radix,
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 i;
......@@ -207,7 +207,7 @@ static int fill_tree(struct ctree_root *root, struct radix_tree_root *radix,
goto out;
}
if (i % 1000 == 0) {
ret = commit_transaction(root, &super);
ret = btrfs_commit_transaction(root, &super);
if (ret) {
fprintf(stderr, "fill commit failed\n");
return ret;
......@@ -223,7 +223,7 @@ static int fill_tree(struct ctree_root *root, struct radix_tree_root *radix,
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 nr = rand() % 5000;
......@@ -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,
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;
unsigned long found;
int ret;
......@@ -259,16 +259,16 @@ static int fill_radix(struct ctree_root *root, struct radix_tree_root *radix)
key.flags = 0;
key.objectid = (unsigned long)-1;
while(1) {
init_path(&path);
ret = search_slot(root, &key, &path, 0, 0);
btrfs_init_path(&path);
ret = btrfs_search_slot(root, &key, &path, 0, 0);
if (ret < 0) {
release_path(root, &path);
btrfs_release_path(root, &path);
return ret;
}
slot = path.slots[0];
if (ret != 0) {
if (slot == 0) {
release_path(root, &path);
btrfs_release_path(root, &path);
break;
}
slot -= 1;
......@@ -287,7 +287,7 @@ static int fill_radix(struct ctree_root *root, struct radix_tree_root *radix)
radix_tree_preload_end();
}
release_path(root, &path);
btrfs_release_path(root, &path);
key.objectid = found - 1;
if (key.objectid > found)
break;
......@@ -312,7 +312,7 @@ int print_usage(void)
int main(int ac, char **av)
{
RADIX_TREE(radix, GFP_KERNEL);
struct ctree_root *root;
struct btrfs_root *root;
int i;
int ret;
int count;
......@@ -370,7 +370,7 @@ int main(int ac, char **av)
if (ret) {
fprintf(stderr, "op %d failed %d:%d\n",
op, i, iterations);
print_tree(root, root->node);
btrfs_print_tree(root, root->node);
fprintf(stderr, "op %d failed %d:%d\n",
op, i, iterations);
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