Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 128323
b: refs/heads/master
c: 5caf2a0
h: refs/heads/master
i:
  128321: f736188
  128319: f7e6059
v: v3
  • Loading branch information
Chris Mason authored and David Woodhouse committed Apr 2, 2007
1 parent 0a72af3 commit 33bc2f3
Show file tree
Hide file tree
Showing 7 changed files with 244 additions and 173 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: 2c90e5d658424bc71b111eb5a972240d5d06fe86
refs/heads/master: 5caf2a002901f0fde475371c4bf1c553b51884af
18 changes: 10 additions & 8 deletions trunk/fs/btrfs/dir-item.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
objectid, u8 type)
{
int ret = 0;
struct btrfs_path path;
struct btrfs_path *path;
struct btrfs_dir_item *dir_item;
char *name_ptr;
struct btrfs_key key;
Expand All @@ -20,24 +20,26 @@ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
btrfs_set_key_type(&key, BTRFS_DIR_ITEM_KEY);
ret = btrfs_name_hash(name, name_len, &key.offset);
BUG_ON(ret);
btrfs_init_path(&path);
path = btrfs_alloc_path();
btrfs_init_path(path);
data_size = sizeof(*dir_item) + name_len;
ret = btrfs_insert_empty_item(trans, root, &path, &key, data_size);
ret = btrfs_insert_empty_item(trans, root, path, &key, data_size);
if (ret)
goto out;

dir_item = btrfs_item_ptr(btrfs_buffer_leaf(path.nodes[0]),
path.slots[0],
dir_item = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]),
path->slots[0],
struct btrfs_dir_item);
btrfs_set_dir_objectid(dir_item, objectid);
btrfs_set_dir_type(dir_item, type);
btrfs_set_dir_flags(dir_item, 0);
btrfs_set_dir_name_len(dir_item, name_len);
name_ptr = (char *)(dir_item + 1);
btrfs_memcpy(root, path.nodes[0]->b_data, name_ptr, name, name_len);
btrfs_mark_buffer_dirty(path.nodes[0]);
btrfs_memcpy(root, path->nodes[0]->b_data, name_ptr, name, name_len);
btrfs_mark_buffer_dirty(path->nodes[0]);
out:
btrfs_release_path(root, &path);
btrfs_release_path(root, path);
btrfs_free_path(path);
return ret;
}

Expand Down
100 changes: 61 additions & 39 deletions trunk/fs/btrfs/extent-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static int del_pending_extents(struct btrfs_trans_handle *trans, struct
static int inc_block_ref(struct btrfs_trans_handle *trans, struct btrfs_root
*root, u64 blocknr, u64 num_blocks)
{
struct btrfs_path path;
struct btrfs_path *path;
int ret;
struct btrfs_key key;
struct btrfs_leaf *l;
Expand All @@ -25,23 +25,26 @@ static int inc_block_ref(struct btrfs_trans_handle *trans, struct btrfs_root

find_free_extent(trans, root->fs_info->extent_root, 0, 0, (u64)-1,
&ins);
btrfs_init_path(&path);
path = btrfs_alloc_path();
BUG_ON(!path);
btrfs_init_path(path);
key.objectid = blocknr;
key.flags = 0;
btrfs_set_key_type(&key, BTRFS_EXTENT_ITEM_KEY);
key.offset = num_blocks;
ret = btrfs_search_slot(trans, root->fs_info->extent_root, &key, &path,
ret = btrfs_search_slot(trans, root->fs_info->extent_root, &key, path,
0, 1);
if (ret != 0)
BUG();
BUG_ON(ret != 0);
l = btrfs_buffer_leaf(path.nodes[0]);
item = btrfs_item_ptr(l, path.slots[0], struct btrfs_extent_item);
l = btrfs_buffer_leaf(path->nodes[0]);
item = btrfs_item_ptr(l, path->slots[0], struct btrfs_extent_item);
refs = btrfs_extent_refs(item);
btrfs_set_extent_refs(item, refs + 1);
btrfs_mark_buffer_dirty(path.nodes[0]);
btrfs_mark_buffer_dirty(path->nodes[0]);

btrfs_release_path(root->fs_info->extent_root, &path);
btrfs_release_path(root->fs_info->extent_root, path);
btrfs_free_path(path);
finish_current_insert(trans, root->fs_info->extent_root);
del_pending_extents(trans, root->fs_info->extent_root);
return 0;
Expand All @@ -50,24 +53,27 @@ static int inc_block_ref(struct btrfs_trans_handle *trans, struct btrfs_root
static int lookup_block_ref(struct btrfs_trans_handle *trans, struct btrfs_root
*root, u64 blocknr, u64 num_blocks, u32 *refs)
{
struct btrfs_path path;
struct btrfs_path *path;
int ret;
struct btrfs_key key;
struct btrfs_leaf *l;
struct btrfs_extent_item *item;
btrfs_init_path(&path);

path = btrfs_alloc_path();
btrfs_init_path(path);
key.objectid = blocknr;
key.offset = num_blocks;
key.flags = 0;
btrfs_set_key_type(&key, BTRFS_EXTENT_ITEM_KEY);
ret = btrfs_search_slot(trans, root->fs_info->extent_root, &key, &path,
ret = btrfs_search_slot(trans, root->fs_info->extent_root, &key, path,
0, 0);
if (ret != 0)
BUG();
l = btrfs_buffer_leaf(path.nodes[0]);
item = btrfs_item_ptr(l, path.slots[0], struct btrfs_extent_item);
l = btrfs_buffer_leaf(path->nodes[0]);
item = btrfs_item_ptr(l, path->slots[0], struct btrfs_extent_item);
*refs = btrfs_extent_refs(item);
btrfs_release_path(root->fs_info->extent_root, &path);
btrfs_release_path(root->fs_info->extent_root, path);
btrfs_free_path(path);
return 0;
}

Expand Down Expand Up @@ -200,7 +206,7 @@ static int pin_down_block(struct btrfs_root *root, u64 blocknr, int pending)
static int __free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
*root, u64 blocknr, u64 num_blocks, int pin)
{
struct btrfs_path path;
struct btrfs_path *path;
struct btrfs_key key;
struct btrfs_fs_info *info = root->fs_info;
struct btrfs_root *extent_root = info->extent_root;
Expand All @@ -215,20 +221,22 @@ static int __free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
key.offset = num_blocks;

find_free_extent(trans, root, 0, 0, (u64)-1, &ins);
btrfs_init_path(&path);
ret = btrfs_search_slot(trans, extent_root, &key, &path, -1, 1);
path = btrfs_alloc_path();
BUG_ON(!path);
btrfs_init_path(path);
ret = btrfs_search_slot(trans, extent_root, &key, path, -1, 1);
if (ret) {
printk("failed to find %Lu\n", key.objectid);
btrfs_print_tree(extent_root, extent_root->node);
printk("failed to find %Lu\n", key.objectid);
BUG();
}
ei = btrfs_item_ptr(btrfs_buffer_leaf(path.nodes[0]), path.slots[0],
ei = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]), path->slots[0],
struct btrfs_extent_item);
BUG_ON(ei->refs == 0);
refs = btrfs_extent_refs(ei) - 1;
btrfs_set_extent_refs(ei, refs);
btrfs_mark_buffer_dirty(path.nodes[0]);
btrfs_mark_buffer_dirty(path->nodes[0]);
if (refs == 0) {
u64 super_blocks_used;

Expand All @@ -240,13 +248,14 @@ static int __free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
super_blocks_used = btrfs_super_blocks_used(info->disk_super);
btrfs_set_super_blocks_used(info->disk_super,
super_blocks_used - num_blocks);
ret = btrfs_del_item(trans, extent_root, &path);
ret = btrfs_del_item(trans, extent_root, path);
if (extent_root->fs_info->last_insert.objectid > blocknr)
extent_root->fs_info->last_insert.objectid = blocknr;
if (ret)
BUG();
}
btrfs_release_path(extent_root, &path);
btrfs_release_path(extent_root, path);
btrfs_free_path(path);
finish_current_insert(trans, extent_root);
return ret;
}
Expand Down Expand Up @@ -319,7 +328,7 @@ static int find_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
*orig_root, u64 num_blocks, u64 search_start, u64
search_end, struct btrfs_key *ins)
{
struct btrfs_path path;
struct btrfs_path *path;
struct btrfs_key key;
int ret;
u64 hole_size = 0;
Expand All @@ -339,24 +348,25 @@ static int find_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root

ins->flags = 0;
btrfs_set_key_type(ins, BTRFS_EXTENT_ITEM_KEY);
path = btrfs_alloc_path();

check_failed:
btrfs_init_path(&path);
btrfs_init_path(path);
ins->objectid = search_start;
ins->offset = 0;
start_found = 0;
ret = btrfs_search_slot(trans, root, ins, &path, 0, 0);
ret = btrfs_search_slot(trans, root, ins, path, 0, 0);
if (ret < 0)
goto error;

if (path.slots[0] > 0)
path.slots[0]--;
if (path->slots[0] > 0)
path->slots[0]--;

while (1) {
l = btrfs_buffer_leaf(path.nodes[0]);
slot = path.slots[0];
l = btrfs_buffer_leaf(path->nodes[0]);
slot = path->slots[0];
if (slot >= btrfs_header_nritems(&l->header)) {
ret = btrfs_next_leaf(root, &path);
ret = btrfs_next_leaf(root, path);
if (ret == 0)
continue;
if (ret < 0)
Expand Down Expand Up @@ -387,14 +397,14 @@ static int find_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
}
start_found = 1;
last_block = key.objectid + key.offset;
path.slots[0]++;
path->slots[0]++;
}
// FIXME -ENOSPC
check_pending:
/* we have to make sure we didn't find an extent that has already
* been allocated by the map tree or the original allocation
*/
btrfs_release_path(root, &path);
btrfs_release_path(root, path);
BUG_ON(ins->objectid < search_start);
for (test_block = ins->objectid;
test_block < ins->objectid + total_needed; test_block++) {
Expand All @@ -410,9 +420,11 @@ static int find_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
root->fs_info->current_insert.flags = 0;
root->fs_info->last_insert.objectid = ins->objectid;
ins->offset = num_blocks;
btrfs_free_path(path);
return 0;
error:
btrfs_release_path(root, &path);
btrfs_release_path(root, path);
btrfs_free_path(path);
return ret;
}

Expand Down Expand Up @@ -533,6 +545,8 @@ static int walk_down_tree(struct btrfs_trans_handle *trans, struct btrfs_root
int ret;
u32 refs;

WARN_ON(*level < 0);
WARN_ON(*level >= BTRFS_MAX_LEVEL);
ret = lookup_block_ref(trans, root, path->nodes[*level]->b_blocknr,
1, &refs);
BUG_ON(ret);
Expand All @@ -542,6 +556,8 @@ static int walk_down_tree(struct btrfs_trans_handle *trans, struct btrfs_root
* walk down to the last node level and free all the leaves
*/
while(*level >= 0) {
WARN_ON(*level < 0);
WARN_ON(*level >= BTRFS_MAX_LEVEL);
cur = path->nodes[*level];
if (btrfs_header_level(btrfs_buffer_header(cur)) != *level)
WARN_ON(1);
Expand All @@ -564,13 +580,16 @@ static int walk_down_tree(struct btrfs_trans_handle *trans, struct btrfs_root
continue;
}
next = read_tree_block(root, blocknr);
WARN_ON(*level <= 0);
if (path->nodes[*level-1])
btrfs_block_release(root, path->nodes[*level-1]);
path->nodes[*level-1] = next;
*level = btrfs_header_level(btrfs_buffer_header(next));
path->slots[*level] = 0;
}
out:
WARN_ON(*level < 0);
WARN_ON(*level >= BTRFS_MAX_LEVEL);
ret = btrfs_free_extent(trans, root,
path->nodes[*level]->b_blocknr, 1, 1);
btrfs_block_release(root, path->nodes[*level]);
Expand Down Expand Up @@ -622,33 +641,36 @@ int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
int ret = 0;
int wret;
int level;
struct btrfs_path path;
struct btrfs_path *path;
int i;
int orig_level;

btrfs_init_path(&path);
path = btrfs_alloc_path();
BUG_ON(!path);
btrfs_init_path(path);

level = btrfs_header_level(btrfs_buffer_header(snap));
orig_level = level;
path.nodes[level] = snap;
path.slots[level] = 0;
path->nodes[level] = snap;
path->slots[level] = 0;
while(1) {
wret = walk_down_tree(trans, root, &path, &level);
wret = walk_down_tree(trans, root, path, &level);
if (wret > 0)
break;
if (wret < 0)
ret = wret;

wret = walk_up_tree(trans, root, &path, &level);
wret = walk_up_tree(trans, root, path, &level);
if (wret > 0)
break;
if (wret < 0)
ret = wret;
}
for (i = 0; i <= orig_level; i++) {
if (path.nodes[i]) {
btrfs_block_release(root, path.nodes[i]);
if (path->nodes[i]) {
btrfs_block_release(root, path->nodes[i]);
}
}
btrfs_free_path(path);
return ret;
}
Loading

0 comments on commit 33bc2f3

Please sign in to comment.