Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 128262
b: refs/heads/master
c: a28ec19
h: refs/heads/master
v: v3
  • Loading branch information
Chris Mason authored and David Woodhouse committed Mar 7, 2007
1 parent d701bb3 commit bbce64a
Show file tree
Hide file tree
Showing 10 changed files with 268 additions and 128 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: 02217ed299c6340a35696e0610047eb96826de2d
refs/heads/master: a28ec19775d62d673b034082128aca95780d3737
2 changes: 1 addition & 1 deletion trunk/fs/btrfs/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

CC=gcc
CFLAGS = -g -Wall
headers = radix-tree.h ctree.h disk-io.h kerncompat.h print-tree.h
headers = radix-tree.h ctree.h disk-io.h kerncompat.h print-tree.h list.h
objects = ctree.o disk-io.o radix-tree.o mkfs.o extent-tree.o print-tree.o

# if you don't have sparse installed, use ls instead
Expand Down
9 changes: 4 additions & 5 deletions trunk/fs/btrfs/ctree.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,17 @@ int btrfs_cow_block(struct ctree_root *root,
memcpy(&cow->node, &buf->node, sizeof(buf->node));
cow->node.header.blocknr = cow->blocknr;
*cow_ret = cow;
btrfs_inc_ref(root, buf);
if (buf == root->node) {
root->node = cow;
cow->count++;
if (buf != root->commit_root)
free_extent(root, buf->blocknr, 1);
tree_block_release(root, buf);
} else {
parent->node.blockptrs[parent_slot] = cow->blocknr;
BUG_ON(list_empty(&parent->dirty));
}
if (0 && root != root->extent_root && !is_leaf(cow->node.header.flags)) {
btrfs_inc_ref(root, cow);
free_extent(root, buf->blocknr, 1);
}
tree_block_release(root, buf);
return 0;
Expand Down Expand Up @@ -1018,7 +1019,6 @@ static int split_leaf(struct ctree_root *root, struct ctree_path *path,
slot = path->slots[0];
nritems = l->header.nritems;
mid = (nritems + 1)/ 2;

right_buffer = alloc_free_block(root);
BUG_ON(!right_buffer);
BUG_ON(mid == nritems);
Expand Down Expand Up @@ -1170,7 +1170,6 @@ static int del_ptr(struct ctree_root *root, struct ctree_path *path, int level,

node = &parent->node;
nritems = node->header.nritems;

if (slot != nritems -1) {
memmove(node->keys + slot, node->keys + slot + 1,
sizeof(struct key) * (nritems - slot - 1));
Expand Down
4 changes: 4 additions & 0 deletions trunk/fs/btrfs/ctree.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ struct tree_buffer;
*/
struct ctree_root {
struct tree_buffer *node;
struct tree_buffer *commit_root;
struct ctree_root *extent_root;
struct key current_insert;
int fp;
struct radix_tree_root cache_radix;
struct radix_tree_root pinned_radix;
struct list_head trans;
struct list_head cache;
int cache_size;
Expand Down Expand Up @@ -151,4 +153,6 @@ 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);
int btrfs_drop_snapshot(struct ctree_root *root, struct tree_buffer *snap);
int btrfs_finish_extent_commit(struct ctree_root *root);
#endif
31 changes: 26 additions & 5 deletions trunk/fs/btrfs/disk-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,24 @@ static int __commit_transaction(struct ctree_root *root)
return ret;
}

int commit_transaction(struct ctree_root *root)
int commit_transaction(struct ctree_root *root, struct ctree_super_block *s)
{
int ret;
int ret = 0;

ret = __commit_transaction(root);
if (!ret && root != root->extent_root)
ret = __commit_transaction(root->extent_root);
BUG_ON(ret);
if (root->commit_root != root->node) {
struct tree_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);
}
write_ctree_super(root, s);
btrfs_finish_extent_commit(root);
return ret;
}

Expand All @@ -168,10 +179,13 @@ static int __setup_root(struct ctree_root *root, struct ctree_root *extent_root,
{
INIT_LIST_HEAD(&root->trans);
INIT_LIST_HEAD(&root->cache);
root->cache_size = 0;
root->fp = fp;
root->node = NULL;
root->node = read_tree_block(root, info->tree_root);
root->extent_root = extent_root;
root->commit_root = NULL;
root->node = read_tree_block(root, info->tree_root);
memset(&root->current_insert, 0, sizeof(root->current_insert));
return 0;
}

Expand All @@ -188,6 +202,8 @@ struct ctree_root *open_ctree(char *filename, struct ctree_super_block *super)
return NULL;
}
INIT_RADIX_TREE(&root->cache_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->cache_radix, GFP_KERNEL);
ret = pread(fp, super, sizeof(struct ctree_super_block),
CTREE_SUPER_INFO_OFFSET(CTREE_BLOCKSIZE));
Expand All @@ -204,6 +220,8 @@ struct ctree_root *open_ctree(char *filename, struct ctree_super_block *super)
BUG_ON(ret < 0);
__setup_root(root, extent_root, &super->root_info, fp);
__setup_root(extent_root, extent_root, &super->extent_info, fp);
root->commit_root = root->node;
root->node->count++;
return root;
}

Expand Down Expand Up @@ -236,9 +254,11 @@ static int drop_cache(struct ctree_root *root)
}
return 0;
}
int close_ctree(struct ctree_root *root)
int close_ctree(struct ctree_root *root, struct ctree_super_block *s)
{
commit_transaction(root);
commit_transaction(root, s);
__commit_transaction(root->extent_root);
write_ctree_super(root, s);
drop_cache(root->extent_root);
drop_cache(root);
BUG_ON(!list_empty(&root->trans));
Expand All @@ -249,6 +269,7 @@ int close_ctree(struct ctree_root *root)
tree_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);
free(root);
printf("on close %d blocks are allocated\n", allocated_blocks);
return 0;
Expand Down
4 changes: 2 additions & 2 deletions trunk/fs/btrfs/disk-io.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ 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);
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);
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);
int mkfs(int fd);
Expand Down
Loading

0 comments on commit bbce64a

Please sign in to comment.