Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 297857
b: refs/heads/master
c: 8c34293
h: refs/heads/master
i:
  297855: 8d5c187
v: v3
  • Loading branch information
Jeff Mahoney authored and David Sterba committed Mar 22, 2012
1 parent 39c9572 commit 60b2788
Show file tree
Hide file tree
Showing 14 changed files with 1,022 additions and 2,016 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: b5d67f64f9bc656970dacba245410f0faedad18e
refs/heads/master: 8c3429300181be44b30f9f017d53dc717da56caa
134 changes: 37 additions & 97 deletions trunk/fs/btrfs/ctree.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,23 +156,10 @@ struct extent_buffer *btrfs_root_node(struct btrfs_root *root)
{
struct extent_buffer *eb;

while (1) {
rcu_read_lock();
eb = rcu_dereference(root->node);

/*
* RCU really hurts here, we could free up the root node because
* it was cow'ed but we may not get the new root node yet so do
* the inc_not_zero dance and if it doesn't work then
* synchronize_rcu and try again.
*/
if (atomic_inc_not_zero(&eb->refs)) {
rcu_read_unlock();
break;
}
rcu_read_unlock();
synchronize_rcu();
}
rcu_read_lock();
eb = rcu_dereference(root->node);
extent_buffer_get(eb);
rcu_read_unlock();
return eb;
}

Expand Down Expand Up @@ -517,7 +504,7 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
}
if (unlock_orig)
btrfs_tree_unlock(buf);
free_extent_buffer_stale(buf);
free_extent_buffer(buf);
btrfs_mark_buffer_dirty(cow);
*cow_ret = cow;
return 0;
Expand Down Expand Up @@ -972,7 +959,7 @@ static noinline int balance_level(struct btrfs_trans_handle *trans,
root_sub_used(root, mid->len);
btrfs_free_tree_block(trans, root, mid, 0, 1, 0);
/* once for the root ptr */
free_extent_buffer_stale(mid);
free_extent_buffer(mid);
return 0;
}
if (btrfs_header_nritems(mid) >
Expand Down Expand Up @@ -1029,7 +1016,7 @@ static noinline int balance_level(struct btrfs_trans_handle *trans,
ret = wret;
root_sub_used(root, right->len);
btrfs_free_tree_block(trans, root, right, 0, 1, 0);
free_extent_buffer_stale(right);
free_extent_buffer(right);
right = NULL;
} else {
struct btrfs_disk_key right_key;
Expand Down Expand Up @@ -1069,7 +1056,7 @@ static noinline int balance_level(struct btrfs_trans_handle *trans,
ret = wret;
root_sub_used(root, mid->len);
btrfs_free_tree_block(trans, root, mid, 0, 1, 0);
free_extent_buffer_stale(mid);
free_extent_buffer(mid);
mid = NULL;
} else {
/* update the parent key to reflect our changes */
Expand Down Expand Up @@ -1395,8 +1382,7 @@ static noinline int reada_for_balance(struct btrfs_root *root,
* if lowest_unlock is 1, level 0 won't be unlocked
*/
static noinline void unlock_up(struct btrfs_path *path, int level,
int lowest_unlock, int min_write_lock_level,
int *write_lock_level)
int lowest_unlock)
{
int i;
int skip_level = level;
Expand Down Expand Up @@ -1428,11 +1414,6 @@ static noinline void unlock_up(struct btrfs_path *path, int level,
if (i >= lowest_unlock && i > skip_level && path->locks[i]) {
btrfs_tree_unlock_rw(t, path->locks[i]);
path->locks[i] = 0;
if (write_lock_level &&
i > min_write_lock_level &&
i <= *write_lock_level) {
*write_lock_level = i - 1;
}
}
}
}
Expand Down Expand Up @@ -1656,7 +1637,6 @@ int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
/* everything at write_lock_level or lower must be write locked */
int write_lock_level = 0;
u8 lowest_level = 0;
int min_write_lock_level;

lowest_level = p->lowest_level;
WARN_ON(lowest_level && ins_len > 0);
Expand Down Expand Up @@ -1684,8 +1664,6 @@ int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
if (cow && (p->keep_locks || p->lowest_level))
write_lock_level = BTRFS_MAX_LEVEL;

min_write_lock_level = write_lock_level;

again:
/*
* we try very hard to do read locks on the root
Expand Down Expand Up @@ -1817,8 +1795,7 @@ int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
goto again;
}

unlock_up(p, level, lowest_unlock,
min_write_lock_level, &write_lock_level);
unlock_up(p, level, lowest_unlock);

if (level == lowest_level) {
if (dec)
Expand Down Expand Up @@ -1880,8 +1857,7 @@ int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
}
}
if (!p->search_for_split)
unlock_up(p, level, lowest_unlock,
min_write_lock_level, &write_lock_level);
unlock_up(p, level, lowest_unlock);
goto done;
}
}
Expand Down Expand Up @@ -2344,7 +2320,6 @@ static noinline int __push_leaf_right(struct btrfs_trans_handle *trans,
{
struct extent_buffer *left = path->nodes[0];
struct extent_buffer *upper = path->nodes[1];
struct btrfs_map_token token;
struct btrfs_disk_key disk_key;
int slot;
u32 i;
Expand All @@ -2356,8 +2331,6 @@ static noinline int __push_leaf_right(struct btrfs_trans_handle *trans,
u32 data_end;
u32 this_item_size;

btrfs_init_map_token(&token);

if (empty)
nr = 0;
else
Expand Down Expand Up @@ -2435,8 +2408,8 @@ static noinline int __push_leaf_right(struct btrfs_trans_handle *trans,
push_space = BTRFS_LEAF_DATA_SIZE(root);
for (i = 0; i < right_nritems; i++) {
item = btrfs_item_nr(right, i);
push_space -= btrfs_token_item_size(right, item, &token);
btrfs_set_token_item_offset(right, item, push_space, &token);
push_space -= btrfs_item_size(right, item);
btrfs_set_item_offset(right, item, push_space);
}

left_nritems -= push_items;
Expand Down Expand Up @@ -2567,9 +2540,6 @@ static noinline int __push_leaf_left(struct btrfs_trans_handle *trans,
int wret;
u32 this_item_size;
u32 old_left_item_size;
struct btrfs_map_token token;

btrfs_init_map_token(&token);

if (empty)
nr = min(right_nritems, max_slot);
Expand Down Expand Up @@ -2630,10 +2600,9 @@ static noinline int __push_leaf_left(struct btrfs_trans_handle *trans,

item = btrfs_item_nr(left, i);

ioff = btrfs_token_item_offset(left, item, &token);
btrfs_set_token_item_offset(left, item,
ioff - (BTRFS_LEAF_DATA_SIZE(root) - old_left_item_size),
&token);
ioff = btrfs_item_offset(left, item);
btrfs_set_item_offset(left, item,
ioff - (BTRFS_LEAF_DATA_SIZE(root) - old_left_item_size));
}
btrfs_set_header_nritems(left, old_left_nritems + push_items);

Expand Down Expand Up @@ -2663,9 +2632,8 @@ static noinline int __push_leaf_left(struct btrfs_trans_handle *trans,
for (i = 0; i < right_nritems; i++) {
item = btrfs_item_nr(right, i);

push_space = push_space - btrfs_token_item_size(right,
item, &token);
btrfs_set_token_item_offset(right, item, push_space, &token);
push_space = push_space - btrfs_item_size(right, item);
btrfs_set_item_offset(right, item, push_space);
}

btrfs_mark_buffer_dirty(left);
Expand Down Expand Up @@ -2786,9 +2754,6 @@ static noinline int copy_for_split(struct btrfs_trans_handle *trans,
int ret = 0;
int wret;
struct btrfs_disk_key disk_key;
struct btrfs_map_token token;

btrfs_init_map_token(&token);

nritems = nritems - mid;
btrfs_set_header_nritems(right, nritems);
Expand All @@ -2810,9 +2775,8 @@ static noinline int copy_for_split(struct btrfs_trans_handle *trans,
struct btrfs_item *item = btrfs_item_nr(right, i);
u32 ioff;

ioff = btrfs_token_item_offset(right, item, &token);
btrfs_set_token_item_offset(right, item,
ioff + rt_data_off, &token);
ioff = btrfs_item_offset(right, item);
btrfs_set_item_offset(right, item, ioff + rt_data_off);
}

btrfs_set_header_nritems(l, mid);
Expand Down Expand Up @@ -3307,9 +3271,6 @@ int btrfs_truncate_item(struct btrfs_trans_handle *trans,
unsigned int old_size;
unsigned int size_diff;
int i;
struct btrfs_map_token token;

btrfs_init_map_token(&token);

leaf = path->nodes[0];
slot = path->slots[0];
Expand All @@ -3336,9 +3297,8 @@ int btrfs_truncate_item(struct btrfs_trans_handle *trans,
u32 ioff;
item = btrfs_item_nr(leaf, i);

ioff = btrfs_token_item_offset(leaf, item, &token);
btrfs_set_token_item_offset(leaf, item,
ioff + size_diff, &token);
ioff = btrfs_item_offset(leaf, item);
btrfs_set_item_offset(leaf, item, ioff + size_diff);
}

/* shift the data */
Expand Down Expand Up @@ -3408,9 +3368,6 @@ int btrfs_extend_item(struct btrfs_trans_handle *trans,
unsigned int old_data;
unsigned int old_size;
int i;
struct btrfs_map_token token;

btrfs_init_map_token(&token);

leaf = path->nodes[0];

Expand Down Expand Up @@ -3440,9 +3397,8 @@ int btrfs_extend_item(struct btrfs_trans_handle *trans,
u32 ioff;
item = btrfs_item_nr(leaf, i);

ioff = btrfs_token_item_offset(leaf, item, &token);
btrfs_set_token_item_offset(leaf, item,
ioff - data_size, &token);
ioff = btrfs_item_offset(leaf, item);
btrfs_set_item_offset(leaf, item, ioff - data_size);
}

/* shift the data */
Expand Down Expand Up @@ -3485,9 +3441,6 @@ int btrfs_insert_some_items(struct btrfs_trans_handle *trans,
unsigned int data_end;
struct btrfs_disk_key disk_key;
struct btrfs_key found_key;
struct btrfs_map_token token;

btrfs_init_map_token(&token);

for (i = 0; i < nr; i++) {
if (total_size + data_size[i] + sizeof(struct btrfs_item) >
Expand Down Expand Up @@ -3553,9 +3506,8 @@ int btrfs_insert_some_items(struct btrfs_trans_handle *trans,
u32 ioff;

item = btrfs_item_nr(leaf, i);
ioff = btrfs_token_item_offset(leaf, item, &token);
btrfs_set_token_item_offset(leaf, item,
ioff - total_data, &token);
ioff = btrfs_item_offset(leaf, item);
btrfs_set_item_offset(leaf, item, ioff - total_data);
}
/* shift the items */
memmove_extent_buffer(leaf, btrfs_item_nr_offset(slot + nr),
Expand All @@ -3582,10 +3534,9 @@ int btrfs_insert_some_items(struct btrfs_trans_handle *trans,
btrfs_cpu_key_to_disk(&disk_key, cpu_key + i);
btrfs_set_item_key(leaf, &disk_key, slot + i);
item = btrfs_item_nr(leaf, slot + i);
btrfs_set_token_item_offset(leaf, item,
data_end - data_size[i], &token);
btrfs_set_item_offset(leaf, item, data_end - data_size[i]);
data_end -= data_size[i];
btrfs_set_token_item_size(leaf, item, data_size[i], &token);
btrfs_set_item_size(leaf, item, data_size[i]);
}
btrfs_set_header_nritems(leaf, nritems + nr);
btrfs_mark_buffer_dirty(leaf);
Expand Down Expand Up @@ -3624,9 +3575,6 @@ int setup_items_for_insert(struct btrfs_trans_handle *trans,
int ret;
struct extent_buffer *leaf;
int slot;
struct btrfs_map_token token;

btrfs_init_map_token(&token);

leaf = path->nodes[0];
slot = path->slots[0];
Expand Down Expand Up @@ -3658,9 +3606,8 @@ int setup_items_for_insert(struct btrfs_trans_handle *trans,
u32 ioff;

item = btrfs_item_nr(leaf, i);
ioff = btrfs_token_item_offset(leaf, item, &token);
btrfs_set_token_item_offset(leaf, item,
ioff - total_data, &token);
ioff = btrfs_item_offset(leaf, item);
btrfs_set_item_offset(leaf, item, ioff - total_data);
}
/* shift the items */
memmove_extent_buffer(leaf, btrfs_item_nr_offset(slot + nr),
Expand All @@ -3679,10 +3626,9 @@ int setup_items_for_insert(struct btrfs_trans_handle *trans,
btrfs_cpu_key_to_disk(&disk_key, cpu_key + i);
btrfs_set_item_key(leaf, &disk_key, slot + i);
item = btrfs_item_nr(leaf, slot + i);
btrfs_set_token_item_offset(leaf, item,
data_end - data_size[i], &token);
btrfs_set_item_offset(leaf, item, data_end - data_size[i]);
data_end -= data_size[i];
btrfs_set_token_item_size(leaf, item, data_size[i], &token);
btrfs_set_item_size(leaf, item, data_size[i]);
}

btrfs_set_header_nritems(leaf, nritems + nr);
Expand Down Expand Up @@ -3835,9 +3781,7 @@ static noinline int btrfs_del_leaf(struct btrfs_trans_handle *trans,

root_sub_used(root, leaf->len);

extent_buffer_get(leaf);
btrfs_free_tree_block(trans, root, leaf, 0, 1, 0);
free_extent_buffer_stale(leaf);
return 0;
}
/*
Expand All @@ -3855,9 +3799,6 @@ int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,
int wret;
int i;
u32 nritems;
struct btrfs_map_token token;

btrfs_init_map_token(&token);

leaf = path->nodes[0];
last_off = btrfs_item_offset_nr(leaf, slot + nr - 1);
Expand All @@ -3879,9 +3820,8 @@ int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,
u32 ioff;

item = btrfs_item_nr(leaf, i);
ioff = btrfs_token_item_offset(leaf, item, &token);
btrfs_set_token_item_offset(leaf, item,
ioff + dsize, &token);
ioff = btrfs_item_offset(leaf, item);
btrfs_set_item_offset(leaf, item, ioff + dsize);
}

memmove_extent_buffer(leaf, btrfs_item_nr_offset(slot),
Expand Down Expand Up @@ -4119,7 +4059,7 @@ int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key,
path->slots[level] = slot;
if (level == path->lowest_level) {
ret = 0;
unlock_up(path, level, 1, 0, NULL);
unlock_up(path, level, 1);
goto out;
}
btrfs_set_path_blocking(path);
Expand All @@ -4130,7 +4070,7 @@ int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key,

path->locks[level - 1] = BTRFS_READ_LOCK;
path->nodes[level - 1] = cur;
unlock_up(path, level, 1, 0, NULL);
unlock_up(path, level, 1);
btrfs_clear_path_blocking(path, NULL, 0);
}
out:
Expand Down Expand Up @@ -4366,7 +4306,7 @@ int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path)
}
ret = 0;
done:
unlock_up(path, 0, 1, 0, NULL);
unlock_up(path, 0, 1);
path->leave_spinning = old_spinning;
if (!old_spinning)
btrfs_set_path_blocking(path);
Expand Down
Loading

0 comments on commit 60b2788

Please sign in to comment.