Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 128290
b: refs/heads/master
c: 9f5fae2
h: refs/heads/master
v: v3
  • Loading branch information
Chris Mason authored and David Woodhouse committed Mar 20, 2007
1 parent 0b69c40 commit 2abb400
Show file tree
Hide file tree
Showing 12 changed files with 543 additions and 174 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 631d7d950a2f2706f5c86858402c1ec50b9801f1
refs/heads/master: 9f5fae2fe6dc35b46bf56183f11398451851cb3f
3 changes: 2 additions & 1 deletion trunk/fs/btrfs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ CFLAGS = -g -Wall -Werror
headers = radix-tree.h ctree.h disk-io.h kerncompat.h print-tree.h list.h \
transaction.h
objects = ctree.o disk-io.o radix-tree.o mkfs.o extent-tree.o print-tree.o \
root-tree.o dir-item.o hash.o file-item.o inode-item.o
root-tree.o dir-item.o hash.o file-item.o inode-item.o \
inode-map.o \

# if you don't have sparse installed, use ls instead
CHECKFLAGS=-D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise \
Expand Down
129 changes: 115 additions & 14 deletions trunk/fs/btrfs/ctree.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ struct btrfs_trans_handle;

#define BTRFS_ROOT_TREE_OBJECTID 1
#define BTRFS_EXTENT_TREE_OBJECTID 2
#define BTRFS_FS_TREE_OBJECTID 3
#define BTRFS_INODE_MAP_OBJECTID 3
#define BTRFS_FS_TREE_OBJECTID 4

/*
* the key defines the order in the tree, and so it also defines (optimal)
Expand Down Expand Up @@ -178,31 +179,65 @@ struct btrfs_root_item {
__le64 block_limit;
__le64 blocks_used;
__le32 refs;
};
} __attribute__ ((__packed__));

/*
* 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 btrfs_root {
struct btrfs_buffer *node;
struct btrfs_buffer *commit_root;
struct btrfs_file_extent_item {
/*
* disk space consumed by the extent, checksum blocks are included
* in these numbers
*/
__le64 disk_blocknr;
__le64 disk_num_blocks;
/*
* the logical offset in file bytes (no csums)
* this extent record is for. This allows a file extent to point
* into the middle of an existing extent on disk, sharing it
* between two snapshots (useful if some bytes in the middle of the
* extent have changed
*/
__le64 offset;
/*
* the logical number of file blocks (no csums included)
*/
__le64 num_blocks;
} __attribute__ ((__packed__));

struct btrfs_inode_map_item {
struct btrfs_disk_key key;
} __attribute__ ((__packed__));

struct btrfs_fs_info {
struct btrfs_root *fs_root;
struct btrfs_root *extent_root;
struct btrfs_root *tree_root;
struct btrfs_root *inode_root;
struct btrfs_key current_insert;
struct btrfs_key last_insert;
int fp;
struct radix_tree_root cache_radix;
struct radix_tree_root pinned_radix;
struct list_head trans;
struct list_head cache;
u64 last_inode_alloc;
u64 last_inode_alloc_dirid;
int cache_size;
int ref_cows;
int fp;
struct btrfs_trans_handle *running_transaction;
};

/*
* 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 btrfs_root {
struct btrfs_buffer *node;
struct btrfs_buffer *commit_root;
struct btrfs_root_item root_item;
struct btrfs_key root_key;
struct btrfs_fs_info *fs_info;
u32 blocksize;
struct btrfs_trans_handle *running_transaction;
int ref_cows;
u32 type;
};

/* the lower bits in the key flags defines the item type */
Expand Down Expand Up @@ -240,11 +275,17 @@ struct btrfs_root {
* are used, and how many references there are to each block
*/
#define BTRFS_EXTENT_ITEM_KEY 6

/*
* the inode map records which inode numbers are in use and where
* they actually live on disk
*/
#define BTRFS_INODE_MAP_ITEM_KEY 7
/*
* string items are for debugging. They just store a short string of
* data in the FS
*/
#define BTRFS_STRING_ITEM_KEY 7
#define BTRFS_STRING_ITEM_KEY 8

static inline u64 btrfs_inode_generation(struct btrfs_inode_item *i)
{
Expand Down Expand Up @@ -654,6 +695,57 @@ static inline u8 *btrfs_leaf_data(struct btrfs_leaf *l)
{
return (u8 *)l->items;
}

static inline u64 btrfs_file_extent_disk_blocknr(struct btrfs_file_extent_item
*e)
{
return le64_to_cpu(e->disk_blocknr);
}

static inline void btrfs_set_file_extent_disk_blocknr(struct
btrfs_file_extent_item
*e, u64 val)
{
e->disk_blocknr = cpu_to_le64(val);
}

static inline u64 btrfs_file_extent_disk_num_blocks(struct
btrfs_file_extent_item *e)
{
return le64_to_cpu(e->disk_num_blocks);
}

static inline void btrfs_set_file_extent_disk_num_blocks(struct
btrfs_file_extent_item
*e, u64 val)
{
e->disk_num_blocks = cpu_to_le64(val);
}

static inline u64 btrfs_file_extent_offset(struct btrfs_file_extent_item *e)
{
return le64_to_cpu(e->offset);
}

static inline void btrfs_set_file_extent_offset(struct btrfs_file_extent_item
*e, u64 val)
{
e->offset = cpu_to_le64(val);
}

static inline u64 btrfs_file_extent_num_blocks(struct btrfs_file_extent_item
*e)
{
return le64_to_cpu(e->num_blocks);
}

static inline void btrfs_set_file_extent_num_blocks(struct
btrfs_file_extent_item *e,
u64 val)
{
e->num_blocks = cpu_to_le64(val);
}

/* helper function to cast into the data area of the leaf. */
#define btrfs_item_ptr(leaf, slot, type) \
((type *)(btrfs_leaf_data(leaf) + \
Expand Down Expand Up @@ -701,4 +793,13 @@ int btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
int name_len, int mod);
int btrfs_match_dir_item_name(struct btrfs_root *root, struct btrfs_path *path,
char *name, int name_len);
int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
struct btrfs_root *fs_root,
u64 dirid, u64 *objectid);
int btrfs_insert_inode_map(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
u64 objectid, struct btrfs_key *location);
int btrfs_lookup_inode_map(struct btrfs_trans_handle *trans,
struct btrfs_root *root, struct btrfs_path *path,
u64 objectid, int mod);
#endif
9 changes: 7 additions & 2 deletions trunk/fs/btrfs/debug-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ int main(int ac, char **av) {
printf("fs tree\n");
btrfs_print_tree(root, root->node);
printf("map tree\n");
btrfs_print_tree(root->extent_root, root->extent_root->node);
btrfs_print_tree(root->fs_info->extent_root,
root->fs_info->extent_root->node);
printf("inode tree\n");
btrfs_print_tree(root->fs_info->inode_root,
root->fs_info->inode_root->node);
printf("root tree\n");
btrfs_print_tree(root->tree_root, root->tree_root->node);
btrfs_print_tree(root->fs_info->tree_root,
root->fs_info->tree_root->node);
return 0;
}
91 changes: 75 additions & 16 deletions trunk/fs/btrfs/dir-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,26 @@ static int ins_one(struct btrfs_trans_handle *trans, struct btrfs_root *root,
int ret;
char buf[128];
unsigned long oid;
u64 objectid;
struct btrfs_path path;
struct btrfs_key inode_map;

find_num(radix, &oid, 0);
sprintf(buf, "str-%lu", oid);

ret = btrfs_find_free_objectid(trans, root, dir_oid + 1, &objectid);
if (ret)
goto error;

inode_map.objectid = objectid;
inode_map.flags = 0;
inode_map.offset = 0;

ret = btrfs_insert_inode_map(trans, root, objectid, &inode_map);
if (ret)
goto error;
ret = btrfs_insert_dir_item(trans, root, buf, strlen(buf), dir_oid,
file_oid, 1);
objectid, 1);
if (ret)
goto error;

Expand Down Expand Up @@ -120,14 +133,60 @@ static int insert_dup(struct btrfs_trans_handle *trans, struct btrfs_root
return 0;
}

static int del_dir_item(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
struct radix_tree_root *radix,
unsigned long radix_index,
struct btrfs_path *path)
{
int ret;
unsigned long *ptr;
u64 file_objectid;
struct btrfs_dir_item *di;
struct btrfs_path map_path;

/* find the inode number of the file */
di = btrfs_item_ptr(&path->nodes[0]->leaf, path->slots[0],
struct btrfs_dir_item);
file_objectid = btrfs_dir_objectid(di);

/* delete the directory item */
ret = btrfs_del_item(trans, root, path);
if (ret)
goto out;

/* delete the inode mapping */
btrfs_init_path(&map_path);
ret = btrfs_lookup_inode_map(trans, root, &map_path, file_objectid, -1);
if (ret)
goto out_release;
ret = btrfs_del_item(trans, root->fs_info->inode_root, &map_path);
if (ret)
goto out_release;

if (root->fs_info->last_inode_alloc > file_objectid)
root->fs_info->last_inode_alloc = file_objectid;
btrfs_release_path(root, &map_path);
ptr = radix_tree_delete(radix, radix_index);
if (!ptr) {
ret = -5555;
goto out;
}
return 0;
out_release:
btrfs_release_path(root, &map_path);
out:
printf("failed to delete %lu %d\n", radix_index, ret);
return -1;
}

static int del_one(struct btrfs_trans_handle *trans, struct btrfs_root *root,
struct radix_tree_root *radix)
{
int ret;
char buf[128];
unsigned long oid;
struct btrfs_path path;
unsigned long *ptr;

ret = find_num(radix, &oid, 1);
if (ret < 0)
Expand All @@ -138,19 +197,14 @@ static int del_one(struct btrfs_trans_handle *trans, struct btrfs_root *root,
strlen(buf), -1);
if (ret)
goto out_release;
ret = btrfs_del_item(trans, root, &path);

ret = del_dir_item(trans, root, radix, oid, &path);
if (ret)
goto out_release;
btrfs_release_path(root, &path);
ptr = radix_tree_delete(radix, oid);
if (!ptr) {
ret = -5555;
goto out;
}
return 0;
return ret;
out_release:
btrfs_release_path(root, &path);
out:
printf("failed to delete %lu %d\n", oid, ret);
return -1;
}
Expand All @@ -162,6 +216,8 @@ static int lookup_item(struct btrfs_trans_handle *trans, struct btrfs_root
char buf[128];
int ret;
unsigned long oid;
u64 objectid;
struct btrfs_dir_item *di;

ret = find_num(radix, &oid, 1);
if (ret < 0)
Expand All @@ -170,6 +226,14 @@ static int lookup_item(struct btrfs_trans_handle *trans, struct btrfs_root
btrfs_init_path(&path);
ret = btrfs_lookup_dir_item(trans, root, &path, dir_oid, buf,
strlen(buf), 0);
if (!ret) {
di = btrfs_item_ptr(&path.nodes[0]->leaf, path.slots[0],
struct btrfs_dir_item);
objectid = btrfs_dir_objectid(di);
btrfs_release_path(root, &path);
btrfs_init_path(&path);
ret = btrfs_lookup_inode_map(trans, root, &path, objectid, 0);
}
btrfs_release_path(root, &path);
if (ret) {
printf("unable to find key %lu\n", oid);
Expand Down Expand Up @@ -210,7 +274,6 @@ static int empty_tree(struct btrfs_trans_handle *trans, struct btrfs_root
u32 found_len;
int ret;
int slot;
int *ptr;
int count = 0;
char buf[128];
struct btrfs_dir_item *di;
Expand Down Expand Up @@ -241,7 +304,7 @@ static int empty_tree(struct btrfs_trans_handle *trans, struct btrfs_root
BUG_ON(found_len > 128);
buf[found_len] = '\0';
found = atoi(buf + 4);
ret = btrfs_del_item(trans, root, &path);
ret = del_dir_item(trans, root, radix, found, &path);
count++;
if (ret) {
fprintf(stderr,
Expand All @@ -250,14 +313,10 @@ static int empty_tree(struct btrfs_trans_handle *trans, struct btrfs_root
return -1;
}
btrfs_release_path(root, &path);
ptr = radix_tree_delete(radix, found);
if (!ptr)
goto error;
if (!keep_running)
break;
}
return 0;
error:
fprintf(stderr, "failed to delete from the radix %lu\n", found);
return -1;
}
Expand Down
Loading

0 comments on commit 2abb400

Please sign in to comment.