Commit 5de08d7d authored by Chris Mason's avatar Chris Mason Committed by David Woodhouse

Btrfs: Break up ctree.c a little

Extent fixes
Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
parent 9a8dd150
CFLAGS= -g -Wall
CFLAGS = -g -Wall
headers = radix-tree.h ctree.h disk-io.h kerncompat.h print-tree.h
objects = ctree.o disk-io.o radix-tree.o mkfs.o extent-tree.o print-tree.o
.c.o:
$(CC) $(CFLAGS) -c $<
#.c.o:
# $(CC) $(CFLAGS) -c $<
ctree: ctree.o disk-io.h ctree.h disk-io.o radix-tree.o radix-tree.h mkfs.o
gcc $(CFLAGS) -o ctree ctree.o disk-io.o radix-tree.o mkfs.o
ctree : $(objects)
gcc $(CFLAGS) -o ctree $(objects)
clean:
$(objects) : $(headers)
clean :
rm ctree *.o
This diff is collapsed.
#ifndef __CTREE__
#define __CTREE__
#define CTREE_BLOCKSIZE 256
#define CTREE_BLOCKSIZE 4096
struct key {
u64 objectid;
......@@ -81,4 +81,14 @@ struct ctree_path {
struct tree_buffer *nodes[MAX_LEVEL];
int slots[MAX_LEVEL];
};
struct tree_buffer *alloc_free_block(struct ctree_root *root);
int free_extent(struct ctree_root *root, u64 blocknr, u64 num_blocks);
int search_slot(struct ctree_root *root, struct key *key, struct ctree_path *p, int ins_len);
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 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);
#endif
......@@ -172,7 +172,6 @@ int close_ctree(struct ctree_root *root)
void tree_block_release(struct ctree_root *root, struct tree_buffer *buf)
{
buf->count--;
write_tree_block(root, buf);
if (buf->count < 0)
BUG();
if (buf->count == 0) {
......
#include <stdio.h>
#include <stdlib.h>
#include "kerncompat.h"
#include "radix-tree.h"
#include "ctree.h"
#include "disk-io.h"
void print_leaf(struct leaf *l)
{
int i;
int nr = l->header.nritems;
struct item *item;
struct extent_item *ei;
printf("leaf %lu total ptrs %d free space %d\n", l->header.blocknr, nr,
leaf_free_space(l));
fflush(stdout);
for (i = 0 ; i < nr ; i++) {
item = l->items + i;
printf("\titem %d key (%lu %u %lu) itemoff %d itemsize %d\n",
i,
item->key.objectid, item->key.flags, item->key.offset,
item->offset, item->size);
fflush(stdout);
printf("\t\titem data %.*s\n", item->size, l->data+item->offset);
ei = (struct extent_item *)(l->data + item->offset);
printf("\t\textent data %u %lu\n", ei->refs, ei->owner);
fflush(stdout);
}
}
void print_tree(struct ctree_root *root, struct tree_buffer *t)
{
int i;
int nr;
struct node *c;
if (!t)
return;
c = &t->node;
nr = c->header.nritems;
if (c->header.blocknr != t->blocknr)
BUG();
if (is_leaf(c->header.flags)) {
print_leaf((struct leaf *)c);
return;
}
printf("node %lu level %d total ptrs %d free spc %lu\n", t->blocknr,
node_level(c->header.flags), c->header.nritems,
NODEPTRS_PER_BLOCK - c->header.nritems);
fflush(stdout);
for (i = 0; i < nr; i++) {
printf("\tkey %d (%lu %u %lu) block %lu\n",
i,
c->keys[i].objectid, c->keys[i].flags, c->keys[i].offset,
c->blockptrs[i]);
fflush(stdout);
}
for (i = 0; i < nr; i++) {
struct tree_buffer *next_buf = read_tree_block(root,
c->blockptrs[i]);
struct node *next = &next_buf->node;
if (is_leaf(next->header.flags) &&
node_level(c->header.flags) != 1)
BUG();
if (node_level(next->header.flags) !=
node_level(c->header.flags) - 1)
BUG();
print_tree(root, next_buf);
tree_block_release(root, next_buf);
}
}
void print_leaf(struct leaf *l);
void print_tree(struct ctree_root *root, struct tree_buffer *t);
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