提交 5581a51a 编写于 作者: J Jan Schmidt

Btrfs: don't set for_cow parameter for tree block functions

Three callers of btrfs_free_tree_block or btrfs_alloc_tree_block passed
parameter for_cow = 1. In fact, these two functions should never mark
their tree modification operations as for_cow, because they can change
the number of blocks referenced by a tree.

Hence, we remove the extra for_cow parameter from these functions and
make them pass a zero down.
Signed-off-by: NJan Schmidt <list.btrfs@jan-o-sch.net>
上级 976b1908
...@@ -255,7 +255,7 @@ int btrfs_copy_root(struct btrfs_trans_handle *trans, ...@@ -255,7 +255,7 @@ int btrfs_copy_root(struct btrfs_trans_handle *trans,
cow = btrfs_alloc_free_block(trans, root, buf->len, 0, cow = btrfs_alloc_free_block(trans, root, buf->len, 0,
new_root_objectid, &disk_key, level, new_root_objectid, &disk_key, level,
buf->start, 0, 1); buf->start, 0);
if (IS_ERR(cow)) if (IS_ERR(cow))
return PTR_ERR(cow); return PTR_ERR(cow);
...@@ -467,7 +467,7 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans, ...@@ -467,7 +467,7 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
cow = btrfs_alloc_free_block(trans, root, buf->len, parent_start, cow = btrfs_alloc_free_block(trans, root, buf->len, parent_start,
root->root_key.objectid, &disk_key, root->root_key.objectid, &disk_key,
level, search_start, empty_size, 1); level, search_start, empty_size);
if (IS_ERR(cow)) if (IS_ERR(cow))
return PTR_ERR(cow); return PTR_ERR(cow);
...@@ -509,7 +509,7 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans, ...@@ -509,7 +509,7 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
rcu_assign_pointer(root->node, cow); rcu_assign_pointer(root->node, cow);
btrfs_free_tree_block(trans, root, buf, parent_start, btrfs_free_tree_block(trans, root, buf, parent_start,
last_ref, 1); last_ref);
free_extent_buffer(buf); free_extent_buffer(buf);
add_root_to_dirty_list(root); add_root_to_dirty_list(root);
} else { } else {
...@@ -525,7 +525,7 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans, ...@@ -525,7 +525,7 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
trans->transid); trans->transid);
btrfs_mark_buffer_dirty(parent); btrfs_mark_buffer_dirty(parent);
btrfs_free_tree_block(trans, root, buf, parent_start, btrfs_free_tree_block(trans, root, buf, parent_start,
last_ref, 1); last_ref);
} }
if (unlock_orig) if (unlock_orig)
btrfs_tree_unlock(buf); btrfs_tree_unlock(buf);
...@@ -987,7 +987,7 @@ static noinline int balance_level(struct btrfs_trans_handle *trans, ...@@ -987,7 +987,7 @@ static noinline int balance_level(struct btrfs_trans_handle *trans,
free_extent_buffer(mid); free_extent_buffer(mid);
root_sub_used(root, mid->len); root_sub_used(root, mid->len);
btrfs_free_tree_block(trans, root, mid, 0, 1, 0); btrfs_free_tree_block(trans, root, mid, 0, 1);
/* once for the root ptr */ /* once for the root ptr */
free_extent_buffer_stale(mid); free_extent_buffer_stale(mid);
return 0; return 0;
...@@ -1042,7 +1042,7 @@ static noinline int balance_level(struct btrfs_trans_handle *trans, ...@@ -1042,7 +1042,7 @@ static noinline int balance_level(struct btrfs_trans_handle *trans,
btrfs_tree_unlock(right); btrfs_tree_unlock(right);
del_ptr(trans, root, path, level + 1, pslot + 1); del_ptr(trans, root, path, level + 1, pslot + 1);
root_sub_used(root, right->len); root_sub_used(root, right->len);
btrfs_free_tree_block(trans, root, right, 0, 1, 0); btrfs_free_tree_block(trans, root, right, 0, 1);
free_extent_buffer_stale(right); free_extent_buffer_stale(right);
right = NULL; right = NULL;
} else { } else {
...@@ -1084,7 +1084,7 @@ static noinline int balance_level(struct btrfs_trans_handle *trans, ...@@ -1084,7 +1084,7 @@ static noinline int balance_level(struct btrfs_trans_handle *trans,
btrfs_tree_unlock(mid); btrfs_tree_unlock(mid);
del_ptr(trans, root, path, level + 1, pslot); del_ptr(trans, root, path, level + 1, pslot);
root_sub_used(root, mid->len); root_sub_used(root, mid->len);
btrfs_free_tree_block(trans, root, mid, 0, 1, 0); btrfs_free_tree_block(trans, root, mid, 0, 1);
free_extent_buffer_stale(mid); free_extent_buffer_stale(mid);
mid = NULL; mid = NULL;
} else { } else {
...@@ -2129,7 +2129,7 @@ static noinline int insert_new_root(struct btrfs_trans_handle *trans, ...@@ -2129,7 +2129,7 @@ static noinline int insert_new_root(struct btrfs_trans_handle *trans,
c = btrfs_alloc_free_block(trans, root, root->nodesize, 0, c = btrfs_alloc_free_block(trans, root, root->nodesize, 0,
root->root_key.objectid, &lower_key, root->root_key.objectid, &lower_key,
level, root->node->start, 0, 0); level, root->node->start, 0);
if (IS_ERR(c)) if (IS_ERR(c))
return PTR_ERR(c); return PTR_ERR(c);
...@@ -2252,7 +2252,7 @@ static noinline int split_node(struct btrfs_trans_handle *trans, ...@@ -2252,7 +2252,7 @@ static noinline int split_node(struct btrfs_trans_handle *trans,
split = btrfs_alloc_free_block(trans, root, root->nodesize, 0, split = btrfs_alloc_free_block(trans, root, root->nodesize, 0,
root->root_key.objectid, root->root_key.objectid,
&disk_key, level, c->start, 0, 0); &disk_key, level, c->start, 0);
if (IS_ERR(split)) if (IS_ERR(split))
return PTR_ERR(split); return PTR_ERR(split);
...@@ -3004,7 +3004,7 @@ static noinline int split_leaf(struct btrfs_trans_handle *trans, ...@@ -3004,7 +3004,7 @@ static noinline int split_leaf(struct btrfs_trans_handle *trans,
right = btrfs_alloc_free_block(trans, root, root->leafsize, 0, right = btrfs_alloc_free_block(trans, root, root->leafsize, 0,
root->root_key.objectid, root->root_key.objectid,
&disk_key, 0, l->start, 0, 0); &disk_key, 0, l->start, 0);
if (IS_ERR(right)) if (IS_ERR(right))
return PTR_ERR(right); return PTR_ERR(right);
...@@ -3804,7 +3804,7 @@ static noinline void btrfs_del_leaf(struct btrfs_trans_handle *trans, ...@@ -3804,7 +3804,7 @@ static noinline void btrfs_del_leaf(struct btrfs_trans_handle *trans,
root_sub_used(root, leaf->len); root_sub_used(root, leaf->len);
extent_buffer_get(leaf); extent_buffer_get(leaf);
btrfs_free_tree_block(trans, root, leaf, 0, 1, 0); btrfs_free_tree_block(trans, root, leaf, 0, 1);
free_extent_buffer_stale(leaf); free_extent_buffer_stale(leaf);
} }
/* /*
......
...@@ -2496,11 +2496,11 @@ struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans, ...@@ -2496,11 +2496,11 @@ struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
struct btrfs_root *root, u32 blocksize, struct btrfs_root *root, u32 blocksize,
u64 parent, u64 root_objectid, u64 parent, u64 root_objectid,
struct btrfs_disk_key *key, int level, struct btrfs_disk_key *key, int level,
u64 hint, u64 empty_size, int for_cow); u64 hint, u64 empty_size);
void btrfs_free_tree_block(struct btrfs_trans_handle *trans, void btrfs_free_tree_block(struct btrfs_trans_handle *trans,
struct btrfs_root *root, struct btrfs_root *root,
struct extent_buffer *buf, struct extent_buffer *buf,
u64 parent, int last_ref, int for_cow); u64 parent, int last_ref);
struct extent_buffer *btrfs_init_new_buffer(struct btrfs_trans_handle *trans, struct extent_buffer *btrfs_init_new_buffer(struct btrfs_trans_handle *trans,
struct btrfs_root *root, struct btrfs_root *root,
u64 bytenr, u32 blocksize, u64 bytenr, u32 blocksize,
......
...@@ -1252,7 +1252,7 @@ static struct btrfs_root *alloc_log_tree(struct btrfs_trans_handle *trans, ...@@ -1252,7 +1252,7 @@ static struct btrfs_root *alloc_log_tree(struct btrfs_trans_handle *trans,
leaf = btrfs_alloc_free_block(trans, root, root->leafsize, 0, leaf = btrfs_alloc_free_block(trans, root, root->leafsize, 0,
BTRFS_TREE_LOG_OBJECTID, NULL, BTRFS_TREE_LOG_OBJECTID, NULL,
0, 0, 0, 0); 0, 0, 0);
if (IS_ERR(leaf)) { if (IS_ERR(leaf)) {
kfree(root); kfree(root);
return ERR_CAST(leaf); return ERR_CAST(leaf);
......
...@@ -5217,7 +5217,7 @@ static noinline int check_ref_cleanup(struct btrfs_trans_handle *trans, ...@@ -5217,7 +5217,7 @@ static noinline int check_ref_cleanup(struct btrfs_trans_handle *trans,
void btrfs_free_tree_block(struct btrfs_trans_handle *trans, void btrfs_free_tree_block(struct btrfs_trans_handle *trans,
struct btrfs_root *root, struct btrfs_root *root,
struct extent_buffer *buf, struct extent_buffer *buf,
u64 parent, int last_ref, int for_cow) u64 parent, int last_ref)
{ {
struct btrfs_block_group_cache *cache = NULL; struct btrfs_block_group_cache *cache = NULL;
int ret; int ret;
...@@ -5227,7 +5227,7 @@ void btrfs_free_tree_block(struct btrfs_trans_handle *trans, ...@@ -5227,7 +5227,7 @@ void btrfs_free_tree_block(struct btrfs_trans_handle *trans,
buf->start, buf->len, buf->start, buf->len,
parent, root->root_key.objectid, parent, root->root_key.objectid,
btrfs_header_level(buf), btrfs_header_level(buf),
BTRFS_DROP_DELAYED_REF, NULL, for_cow); BTRFS_DROP_DELAYED_REF, NULL, 0);
BUG_ON(ret); /* -ENOMEM */ BUG_ON(ret); /* -ENOMEM */
} }
...@@ -6249,7 +6249,7 @@ struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans, ...@@ -6249,7 +6249,7 @@ struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
struct btrfs_root *root, u32 blocksize, struct btrfs_root *root, u32 blocksize,
u64 parent, u64 root_objectid, u64 parent, u64 root_objectid,
struct btrfs_disk_key *key, int level, struct btrfs_disk_key *key, int level,
u64 hint, u64 empty_size, int for_cow) u64 hint, u64 empty_size)
{ {
struct btrfs_key ins; struct btrfs_key ins;
struct btrfs_block_rsv *block_rsv; struct btrfs_block_rsv *block_rsv;
...@@ -6297,7 +6297,7 @@ struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans, ...@@ -6297,7 +6297,7 @@ struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
ins.objectid, ins.objectid,
ins.offset, parent, root_objectid, ins.offset, parent, root_objectid,
level, BTRFS_ADD_DELAYED_EXTENT, level, BTRFS_ADD_DELAYED_EXTENT,
extent_op, for_cow); extent_op, 0);
BUG_ON(ret); /* -ENOMEM */ BUG_ON(ret); /* -ENOMEM */
} }
return buf; return buf;
...@@ -6715,7 +6715,7 @@ static noinline int walk_up_proc(struct btrfs_trans_handle *trans, ...@@ -6715,7 +6715,7 @@ static noinline int walk_up_proc(struct btrfs_trans_handle *trans,
btrfs_header_owner(path->nodes[level + 1])); btrfs_header_owner(path->nodes[level + 1]));
} }
btrfs_free_tree_block(trans, root, eb, parent, wc->refs[level] == 1, 0); btrfs_free_tree_block(trans, root, eb, parent, wc->refs[level] == 1);
out: out:
wc->refs[level] = 0; wc->refs[level] = 0;
wc->flags[level] = 0; wc->flags[level] = 0;
......
...@@ -367,7 +367,7 @@ static noinline int create_subvol(struct btrfs_root *root, ...@@ -367,7 +367,7 @@ static noinline int create_subvol(struct btrfs_root *root,
return PTR_ERR(trans); return PTR_ERR(trans);
leaf = btrfs_alloc_free_block(trans, root, root->leafsize, leaf = btrfs_alloc_free_block(trans, root, root->leafsize,
0, objectid, NULL, 0, 0, 0, 0); 0, objectid, NULL, 0, 0, 0);
if (IS_ERR(leaf)) { if (IS_ERR(leaf)) {
ret = PTR_ERR(leaf); ret = PTR_ERR(leaf);
goto fail; goto fail;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册