Commit 4d09b4e9 authored by Josef Bacik's avatar Josef Bacik Committed by David Sterba

btrfs: do not use a function to initialize btrfs_ref

btrfs_ref currently has ->owning_root, and ->ref_root is shared between
the tree ref and data ref, so in order to move that into btrfs_ref
proper I would need to add another root parameter to the initialization
function.  This function has too many arguments, and adding another root
will make it easy to make mistakes about which root goes where.

Drop the generic ref init function and statically initialize the
btrfs_ref in every usage.  This makes the code easier to read because we
can see what elements we're assigning, and will make the upcoming change
moving the ref_root into the btrfs_ref more clear and less error prone
than adding a new element to the initialization function.
Reviewed-by: default avatarFilipe Manana <fdmanana@suse.com>
Signed-off-by: default avatarJosef Bacik <josef@toxicpanda.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent d3fbb00f
...@@ -1007,16 +1007,6 @@ static void init_delayed_ref_common(struct btrfs_fs_info *fs_info, ...@@ -1007,16 +1007,6 @@ static void init_delayed_ref_common(struct btrfs_fs_info *fs_info,
INIT_LIST_HEAD(&ref->add_list); INIT_LIST_HEAD(&ref->add_list);
} }
void btrfs_init_generic_ref(struct btrfs_ref *generic_ref, int action, u64 bytenr,
u64 len, u64 parent, u64 owning_root)
{
generic_ref->action = action;
generic_ref->bytenr = bytenr;
generic_ref->len = len;
generic_ref->parent = parent;
generic_ref->owning_root = owning_root;
}
void btrfs_init_tree_ref(struct btrfs_ref *generic_ref, int level, u64 root, void btrfs_init_tree_ref(struct btrfs_ref *generic_ref, int level, u64 root,
u64 mod_root, bool skip_qgroup) u64 mod_root, bool skip_qgroup)
{ {
......
...@@ -320,8 +320,6 @@ static inline u64 btrfs_calc_delayed_ref_csum_bytes(const struct btrfs_fs_info * ...@@ -320,8 +320,6 @@ static inline u64 btrfs_calc_delayed_ref_csum_bytes(const struct btrfs_fs_info *
return btrfs_calc_metadata_size(fs_info, num_csum_items); return btrfs_calc_metadata_size(fs_info, num_csum_items);
} }
void btrfs_init_generic_ref(struct btrfs_ref *generic_ref, int action, u64 bytenr,
u64 len, u64 parent, u64 owning_root);
void btrfs_init_tree_ref(struct btrfs_ref *generic_ref, int level, u64 root, void btrfs_init_tree_ref(struct btrfs_ref *generic_ref, int level, u64 root,
u64 mod_root, bool skip_qgroup); u64 mod_root, bool skip_qgroup);
void btrfs_init_data_ref(struct btrfs_ref *generic_ref, u64 ref_root, u64 ino, void btrfs_init_data_ref(struct btrfs_ref *generic_ref, u64 ref_root, u64 ino,
......
...@@ -2492,14 +2492,11 @@ static int __btrfs_mod_ref(struct btrfs_trans_handle *trans, ...@@ -2492,14 +2492,11 @@ static int __btrfs_mod_ref(struct btrfs_trans_handle *trans,
int full_backref, int inc) int full_backref, int inc)
{ {
struct btrfs_fs_info *fs_info = root->fs_info; struct btrfs_fs_info *fs_info = root->fs_info;
u64 bytenr;
u64 num_bytes;
u64 parent; u64 parent;
u64 ref_root; u64 ref_root;
u32 nritems; u32 nritems;
struct btrfs_key key; struct btrfs_key key;
struct btrfs_file_extent_item *fi; struct btrfs_file_extent_item *fi;
struct btrfs_ref generic_ref = { 0 };
bool for_reloc = btrfs_header_flag(buf, BTRFS_HEADER_FLAG_RELOC); bool for_reloc = btrfs_header_flag(buf, BTRFS_HEADER_FLAG_RELOC);
int i; int i;
int action; int action;
...@@ -2526,6 +2523,11 @@ static int __btrfs_mod_ref(struct btrfs_trans_handle *trans, ...@@ -2526,6 +2523,11 @@ static int __btrfs_mod_ref(struct btrfs_trans_handle *trans,
action = BTRFS_DROP_DELAYED_REF; action = BTRFS_DROP_DELAYED_REF;
for (i = 0; i < nritems; i++) { for (i = 0; i < nritems; i++) {
struct btrfs_ref ref = {
.action = action,
.parent = parent,
};
if (level == 0) { if (level == 0) {
btrfs_item_key_to_cpu(buf, &key, i); btrfs_item_key_to_cpu(buf, &key, i);
if (key.type != BTRFS_EXTENT_DATA_KEY) if (key.type != BTRFS_EXTENT_DATA_KEY)
...@@ -2535,35 +2537,34 @@ static int __btrfs_mod_ref(struct btrfs_trans_handle *trans, ...@@ -2535,35 +2537,34 @@ static int __btrfs_mod_ref(struct btrfs_trans_handle *trans,
if (btrfs_file_extent_type(buf, fi) == if (btrfs_file_extent_type(buf, fi) ==
BTRFS_FILE_EXTENT_INLINE) BTRFS_FILE_EXTENT_INLINE)
continue; continue;
bytenr = btrfs_file_extent_disk_bytenr(buf, fi); ref.bytenr = btrfs_file_extent_disk_bytenr(buf, fi);
if (bytenr == 0) if (ref.bytenr == 0)
continue; continue;
num_bytes = btrfs_file_extent_disk_num_bytes(buf, fi); ref.len = btrfs_file_extent_disk_num_bytes(buf, fi);
ref.owning_root = ref_root;
key.offset -= btrfs_file_extent_offset(buf, fi); key.offset -= btrfs_file_extent_offset(buf, fi);
btrfs_init_generic_ref(&generic_ref, action, bytenr, btrfs_init_data_ref(&ref, ref_root, key.objectid,
num_bytes, parent, ref_root);
btrfs_init_data_ref(&generic_ref, ref_root, key.objectid,
key.offset, root->root_key.objectid, key.offset, root->root_key.objectid,
for_reloc); for_reloc);
if (inc) if (inc)
ret = btrfs_inc_extent_ref(trans, &generic_ref); ret = btrfs_inc_extent_ref(trans, &ref);
else else
ret = btrfs_free_extent(trans, &generic_ref); ret = btrfs_free_extent(trans, &ref);
if (ret) if (ret)
goto fail; goto fail;
} else { } else {
bytenr = btrfs_node_blockptr(buf, i); /* We don't know the owning_root, leave as 0. */
num_bytes = fs_info->nodesize; ref.bytenr = btrfs_node_blockptr(buf, i);
/* We don't know the owning_root, use 0. */ ref.len = fs_info->nodesize;
btrfs_init_generic_ref(&generic_ref, action, bytenr,
num_bytes, parent, 0); btrfs_init_tree_ref(&ref, level - 1, ref_root,
btrfs_init_tree_ref(&generic_ref, level - 1, ref_root,
root->root_key.objectid, for_reloc); root->root_key.objectid, for_reloc);
if (inc) if (inc)
ret = btrfs_inc_extent_ref(trans, &generic_ref); ret = btrfs_inc_extent_ref(trans, &ref);
else else
ret = btrfs_free_extent(trans, &generic_ref); ret = btrfs_free_extent(trans, &ref);
if (ret) if (ret)
goto fail; goto fail;
} }
...@@ -3462,7 +3463,13 @@ void btrfs_free_tree_block(struct btrfs_trans_handle *trans, ...@@ -3462,7 +3463,13 @@ void btrfs_free_tree_block(struct btrfs_trans_handle *trans,
int ret; int ret;
if (root_id != BTRFS_TREE_LOG_OBJECTID) { if (root_id != BTRFS_TREE_LOG_OBJECTID) {
struct btrfs_ref generic_ref = { 0 }; struct btrfs_ref generic_ref = {
.action = BTRFS_DROP_DELAYED_REF,
.bytenr = buf->start,
.len = buf->len,
.parent = parent,
.owning_root = btrfs_header_owner(buf),
};
/* /*
* Assert that the extent buffer is not cleared due to * Assert that the extent buffer is not cleared due to
...@@ -3472,9 +3479,6 @@ void btrfs_free_tree_block(struct btrfs_trans_handle *trans, ...@@ -3472,9 +3479,6 @@ void btrfs_free_tree_block(struct btrfs_trans_handle *trans,
*/ */
ASSERT(btrfs_header_bytenr(buf) != 0); ASSERT(btrfs_header_bytenr(buf) != 0);
btrfs_init_generic_ref(&generic_ref, BTRFS_DROP_DELAYED_REF,
buf->start, buf->len, parent,
btrfs_header_owner(buf));
btrfs_init_tree_ref(&generic_ref, btrfs_header_level(buf), btrfs_init_tree_ref(&generic_ref, btrfs_header_level(buf),
root_id, 0, false); root_id, 0, false);
btrfs_ref_tree_mod(fs_info, &generic_ref); btrfs_ref_tree_mod(fs_info, &generic_ref);
...@@ -4966,17 +4970,19 @@ int btrfs_alloc_reserved_file_extent(struct btrfs_trans_handle *trans, ...@@ -4966,17 +4970,19 @@ int btrfs_alloc_reserved_file_extent(struct btrfs_trans_handle *trans,
u64 offset, u64 ram_bytes, u64 offset, u64 ram_bytes,
struct btrfs_key *ins) struct btrfs_key *ins)
{ {
struct btrfs_ref generic_ref = { 0 }; struct btrfs_ref generic_ref = {
.action = BTRFS_ADD_DELAYED_EXTENT,
.bytenr = ins->objectid,
.len = ins->offset,
.owning_root = root->root_key.objectid,
};
u64 root_objectid = root->root_key.objectid; u64 root_objectid = root->root_key.objectid;
u64 owning_root = root_objectid;
ASSERT(root_objectid != BTRFS_TREE_LOG_OBJECTID); ASSERT(root_objectid != BTRFS_TREE_LOG_OBJECTID);
if (btrfs_is_data_reloc_root(root) && is_fstree(root->relocation_src_root)) if (btrfs_is_data_reloc_root(root) && is_fstree(root->relocation_src_root))
owning_root = root->relocation_src_root; generic_ref.owning_root = root->relocation_src_root;
btrfs_init_generic_ref(&generic_ref, BTRFS_ADD_DELAYED_EXTENT,
ins->objectid, ins->offset, 0, owning_root);
btrfs_init_data_ref(&generic_ref, root_objectid, owner, btrfs_init_data_ref(&generic_ref, root_objectid, owner,
offset, 0, false); offset, 0, false);
btrfs_ref_tree_mod(root->fs_info, &generic_ref); btrfs_ref_tree_mod(root->fs_info, &generic_ref);
...@@ -5157,7 +5163,6 @@ struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans, ...@@ -5157,7 +5163,6 @@ struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans,
struct btrfs_block_rsv *block_rsv; struct btrfs_block_rsv *block_rsv;
struct extent_buffer *buf; struct extent_buffer *buf;
struct btrfs_delayed_extent_op *extent_op; struct btrfs_delayed_extent_op *extent_op;
struct btrfs_ref generic_ref = { 0 };
u64 flags = 0; u64 flags = 0;
int ret; int ret;
u32 blocksize = fs_info->nodesize; u32 blocksize = fs_info->nodesize;
...@@ -5200,6 +5205,13 @@ struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans, ...@@ -5200,6 +5205,13 @@ struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans,
BUG_ON(parent > 0); BUG_ON(parent > 0);
if (root_objectid != BTRFS_TREE_LOG_OBJECTID) { if (root_objectid != BTRFS_TREE_LOG_OBJECTID) {
struct btrfs_ref generic_ref = {
.action = BTRFS_ADD_DELAYED_EXTENT,
.bytenr = ins.objectid,
.len = ins.offset,
.parent = parent,
.owning_root = owning_root,
};
extent_op = btrfs_alloc_delayed_extent_op(); extent_op = btrfs_alloc_delayed_extent_op();
if (!extent_op) { if (!extent_op) {
ret = -ENOMEM; ret = -ENOMEM;
...@@ -5214,8 +5226,6 @@ struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans, ...@@ -5214,8 +5226,6 @@ struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans,
extent_op->update_flags = true; extent_op->update_flags = true;
extent_op->level = level; extent_op->level = level;
btrfs_init_generic_ref(&generic_ref, BTRFS_ADD_DELAYED_EXTENT,
ins.objectid, ins.offset, parent, owning_root);
btrfs_init_tree_ref(&generic_ref, level, root_objectid, btrfs_init_tree_ref(&generic_ref, level, root_objectid,
root->root_key.objectid, false); root->root_key.objectid, false);
btrfs_ref_tree_mod(fs_info, &generic_ref); btrfs_ref_tree_mod(fs_info, &generic_ref);
...@@ -5460,11 +5470,9 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, ...@@ -5460,11 +5470,9 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans,
struct btrfs_fs_info *fs_info = root->fs_info; struct btrfs_fs_info *fs_info = root->fs_info;
u64 bytenr; u64 bytenr;
u64 generation; u64 generation;
u64 parent;
u64 owner_root = 0; u64 owner_root = 0;
struct btrfs_tree_parent_check check = { 0 }; struct btrfs_tree_parent_check check = { 0 };
struct btrfs_key key; struct btrfs_key key;
struct btrfs_ref ref = { 0 };
struct extent_buffer *next; struct extent_buffer *next;
int level = wc->level; int level = wc->level;
int reada = 0; int reada = 0;
...@@ -5581,8 +5589,14 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, ...@@ -5581,8 +5589,14 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans,
wc->refs[level - 1] = 0; wc->refs[level - 1] = 0;
wc->flags[level - 1] = 0; wc->flags[level - 1] = 0;
if (wc->stage == DROP_REFERENCE) { if (wc->stage == DROP_REFERENCE) {
struct btrfs_ref ref = {
.action = BTRFS_DROP_DELAYED_REF,
.bytenr = bytenr,
.len = fs_info->nodesize,
.owning_root = owner_root,
};
if (wc->flags[level] & BTRFS_BLOCK_FLAG_FULL_BACKREF) { if (wc->flags[level] & BTRFS_BLOCK_FLAG_FULL_BACKREF) {
parent = path->nodes[level]->start; ref.parent = path->nodes[level]->start;
} else { } else {
ASSERT(root->root_key.objectid == ASSERT(root->root_key.objectid ==
btrfs_header_owner(path->nodes[level])); btrfs_header_owner(path->nodes[level]));
...@@ -5593,7 +5607,6 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, ...@@ -5593,7 +5607,6 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans,
ret = -EIO; ret = -EIO;
goto out_unlock; goto out_unlock;
} }
parent = 0;
} }
/* /*
...@@ -5603,7 +5616,7 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, ...@@ -5603,7 +5616,7 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans,
* ->restarted flag. * ->restarted flag.
*/ */
if (wc->restarted) { if (wc->restarted) {
ret = check_ref_exists(trans, root, bytenr, parent, ret = check_ref_exists(trans, root, bytenr, ref.parent,
level - 1); level - 1);
if (ret < 0) if (ret < 0)
goto out_unlock; goto out_unlock;
...@@ -5638,8 +5651,6 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, ...@@ -5638,8 +5651,6 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans,
wc->drop_level = level; wc->drop_level = level;
find_next_key(path, level, &wc->drop_progress); find_next_key(path, level, &wc->drop_progress);
btrfs_init_generic_ref(&ref, BTRFS_DROP_DELAYED_REF, bytenr,
fs_info->nodesize, parent, owner_root);
btrfs_init_tree_ref(&ref, level - 1, root->root_key.objectid, btrfs_init_tree_ref(&ref, level - 1, root->root_key.objectid,
0, false); 0, false);
ret = btrfs_free_extent(trans, &ref); ret = btrfs_free_extent(trans, &ref);
......
...@@ -206,7 +206,6 @@ int btrfs_drop_extents(struct btrfs_trans_handle *trans, ...@@ -206,7 +206,6 @@ int btrfs_drop_extents(struct btrfs_trans_handle *trans,
struct btrfs_fs_info *fs_info = root->fs_info; struct btrfs_fs_info *fs_info = root->fs_info;
struct extent_buffer *leaf; struct extent_buffer *leaf;
struct btrfs_file_extent_item *fi; struct btrfs_file_extent_item *fi;
struct btrfs_ref ref = { 0 };
struct btrfs_key key; struct btrfs_key key;
struct btrfs_key new_key; struct btrfs_key new_key;
u64 ino = btrfs_ino(inode); u64 ino = btrfs_ino(inode);
...@@ -373,10 +372,13 @@ int btrfs_drop_extents(struct btrfs_trans_handle *trans, ...@@ -373,10 +372,13 @@ int btrfs_drop_extents(struct btrfs_trans_handle *trans,
btrfs_mark_buffer_dirty(trans, leaf); btrfs_mark_buffer_dirty(trans, leaf);
if (update_refs && disk_bytenr > 0) { if (update_refs && disk_bytenr > 0) {
btrfs_init_generic_ref(&ref, struct btrfs_ref ref = {
BTRFS_ADD_DELAYED_REF, .action = BTRFS_ADD_DELAYED_REF,
disk_bytenr, num_bytes, 0, .bytenr = disk_bytenr,
root->root_key.objectid); .len = num_bytes,
.parent = 0,
.owning_root = root->root_key.objectid,
};
btrfs_init_data_ref(&ref, btrfs_init_data_ref(&ref,
root->root_key.objectid, root->root_key.objectid,
new_key.objectid, new_key.objectid,
...@@ -464,10 +466,13 @@ int btrfs_drop_extents(struct btrfs_trans_handle *trans, ...@@ -464,10 +466,13 @@ int btrfs_drop_extents(struct btrfs_trans_handle *trans,
extent_end = ALIGN(extent_end, extent_end = ALIGN(extent_end,
fs_info->sectorsize); fs_info->sectorsize);
} else if (update_refs && disk_bytenr > 0) { } else if (update_refs && disk_bytenr > 0) {
btrfs_init_generic_ref(&ref, struct btrfs_ref ref = {
BTRFS_DROP_DELAYED_REF, .action = BTRFS_DROP_DELAYED_REF,
disk_bytenr, num_bytes, 0, .bytenr = disk_bytenr,
root->root_key.objectid); .len = num_bytes,
.parent = 0,
.owning_root = root->root_key.objectid,
};
btrfs_init_data_ref(&ref, btrfs_init_data_ref(&ref,
root->root_key.objectid, root->root_key.objectid,
key.objectid, key.objectid,
...@@ -748,8 +753,11 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, ...@@ -748,8 +753,11 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
extent_end - split); extent_end - split);
btrfs_mark_buffer_dirty(trans, leaf); btrfs_mark_buffer_dirty(trans, leaf);
btrfs_init_generic_ref(&ref, BTRFS_ADD_DELAYED_REF, bytenr, ref.action = BTRFS_ADD_DELAYED_REF;
num_bytes, 0, root->root_key.objectid); ref.bytenr = bytenr;
ref.len = num_bytes;
ref.parent = 0;
ref.owning_root = root->root_key.objectid;
btrfs_init_data_ref(&ref, root->root_key.objectid, ino, btrfs_init_data_ref(&ref, root->root_key.objectid, ino,
orig_offset, 0, false); orig_offset, 0, false);
ret = btrfs_inc_extent_ref(trans, &ref); ret = btrfs_inc_extent_ref(trans, &ref);
...@@ -774,8 +782,12 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, ...@@ -774,8 +782,12 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
other_start = end; other_start = end;
other_end = 0; other_end = 0;
btrfs_init_generic_ref(&ref, BTRFS_DROP_DELAYED_REF, bytenr,
num_bytes, 0, root->root_key.objectid); ref.action = BTRFS_DROP_DELAYED_REF;
ref.bytenr = bytenr;
ref.len = num_bytes;
ref.parent = 0;
ref.owning_root = root->root_key.objectid;
btrfs_init_data_ref(&ref, root->root_key.objectid, ino, orig_offset, btrfs_init_data_ref(&ref, root->root_key.objectid, ino, orig_offset,
0, false); 0, false);
if (extent_mergeable(leaf, path->slots[0] + 1, if (extent_mergeable(leaf, path->slots[0] + 1,
...@@ -2424,7 +2436,6 @@ static int btrfs_insert_replace_extent(struct btrfs_trans_handle *trans, ...@@ -2424,7 +2436,6 @@ static int btrfs_insert_replace_extent(struct btrfs_trans_handle *trans,
struct extent_buffer *leaf; struct extent_buffer *leaf;
struct btrfs_key key; struct btrfs_key key;
int slot; int slot;
struct btrfs_ref ref = { 0 };
int ret; int ret;
if (replace_len == 0) if (replace_len == 0)
...@@ -2480,12 +2491,14 @@ static int btrfs_insert_replace_extent(struct btrfs_trans_handle *trans, ...@@ -2480,12 +2491,14 @@ static int btrfs_insert_replace_extent(struct btrfs_trans_handle *trans,
extent_info->qgroup_reserved, extent_info->qgroup_reserved,
&key); &key);
} else { } else {
struct btrfs_ref ref = {
.action = BTRFS_ADD_DELAYED_REF,
.bytenr = extent_info->disk_offset,
.len = extent_info->disk_len,
.owning_root = root->root_key.objectid,
};
u64 ref_offset; u64 ref_offset;
btrfs_init_generic_ref(&ref, BTRFS_ADD_DELAYED_REF,
extent_info->disk_offset,
extent_info->disk_len, 0,
root->root_key.objectid);
ref_offset = extent_info->file_offset - extent_info->data_offset; ref_offset = extent_info->file_offset - extent_info->data_offset;
btrfs_init_data_ref(&ref, root->root_key.objectid, btrfs_init_data_ref(&ref, root->root_key.objectid,
btrfs_ino(inode), ref_offset, 0, false); btrfs_ino(inode), ref_offset, 0, false);
......
...@@ -670,13 +670,15 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, ...@@ -670,13 +670,15 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
} }
if (del_item && extent_start != 0 && !control->skip_ref_updates) { if (del_item && extent_start != 0 && !control->skip_ref_updates) {
struct btrfs_ref ref = { 0 }; struct btrfs_ref ref = {
.action = BTRFS_DROP_DELAYED_REF,
.bytenr = extent_start,
.len = extent_num_bytes,
.owning_root = root->root_key.objectid,
};
bytes_deleted += extent_num_bytes; bytes_deleted += extent_num_bytes;
btrfs_init_generic_ref(&ref, BTRFS_DROP_DELAYED_REF,
extent_start, extent_num_bytes, 0,
root->root_key.objectid);
btrfs_init_data_ref(&ref, btrfs_header_owner(leaf), btrfs_init_data_ref(&ref, btrfs_header_owner(leaf),
control->ino, extent_offset, control->ino, extent_offset,
root->root_key.objectid, false); root->root_key.objectid, false);
......
...@@ -1104,8 +1104,11 @@ int replace_file_extents(struct btrfs_trans_handle *trans, ...@@ -1104,8 +1104,11 @@ int replace_file_extents(struct btrfs_trans_handle *trans,
dirty = 1; dirty = 1;
key.offset -= btrfs_file_extent_offset(leaf, fi); key.offset -= btrfs_file_extent_offset(leaf, fi);
btrfs_init_generic_ref(&ref, BTRFS_ADD_DELAYED_REF, new_bytenr, ref.action = BTRFS_ADD_DELAYED_REF;
num_bytes, parent, root->root_key.objectid); ref.bytenr = new_bytenr;
ref.len = num_bytes;
ref.parent = parent;
ref.owning_root = root->root_key.objectid;
btrfs_init_data_ref(&ref, btrfs_header_owner(leaf), btrfs_init_data_ref(&ref, btrfs_header_owner(leaf),
key.objectid, key.offset, key.objectid, key.offset,
root->root_key.objectid, false); root->root_key.objectid, false);
...@@ -1115,8 +1118,11 @@ int replace_file_extents(struct btrfs_trans_handle *trans, ...@@ -1115,8 +1118,11 @@ int replace_file_extents(struct btrfs_trans_handle *trans,
break; break;
} }
btrfs_init_generic_ref(&ref, BTRFS_DROP_DELAYED_REF, bytenr, ref.action = BTRFS_DROP_DELAYED_REF;
num_bytes, parent, root->root_key.objectid); ref.bytenr = bytenr;
ref.len = num_bytes;
ref.parent = parent;
ref.owning_root = root->root_key.objectid;
btrfs_init_data_ref(&ref, btrfs_header_owner(leaf), btrfs_init_data_ref(&ref, btrfs_header_owner(leaf),
key.objectid, key.offset, key.objectid, key.offset,
root->root_key.objectid, false); root->root_key.objectid, false);
...@@ -1328,9 +1334,11 @@ int replace_path(struct btrfs_trans_handle *trans, struct reloc_control *rc, ...@@ -1328,9 +1334,11 @@ int replace_path(struct btrfs_trans_handle *trans, struct reloc_control *rc,
path->slots[level], old_ptr_gen); path->slots[level], old_ptr_gen);
btrfs_mark_buffer_dirty(trans, path->nodes[level]); btrfs_mark_buffer_dirty(trans, path->nodes[level]);
btrfs_init_generic_ref(&ref, BTRFS_ADD_DELAYED_REF, old_bytenr, ref.action = BTRFS_ADD_DELAYED_REF;
blocksize, path->nodes[level]->start, ref.bytenr = old_bytenr;
src->root_key.objectid); ref.len = blocksize;
ref.parent = path->nodes[level]->start;
ref.owning_root = src->root_key.objectid;
btrfs_init_tree_ref(&ref, level - 1, src->root_key.objectid, btrfs_init_tree_ref(&ref, level - 1, src->root_key.objectid,
0, true); 0, true);
ret = btrfs_inc_extent_ref(trans, &ref); ret = btrfs_inc_extent_ref(trans, &ref);
...@@ -1338,8 +1346,12 @@ int replace_path(struct btrfs_trans_handle *trans, struct reloc_control *rc, ...@@ -1338,8 +1346,12 @@ int replace_path(struct btrfs_trans_handle *trans, struct reloc_control *rc,
btrfs_abort_transaction(trans, ret); btrfs_abort_transaction(trans, ret);
break; break;
} }
btrfs_init_generic_ref(&ref, BTRFS_ADD_DELAYED_REF, new_bytenr,
blocksize, 0, dest->root_key.objectid); ref.action = BTRFS_ADD_DELAYED_REF;
ref.bytenr = new_bytenr;
ref.len = blocksize;
ref.parent = 0;
ref.owning_root = dest->root_key.objectid;
btrfs_init_tree_ref(&ref, level - 1, dest->root_key.objectid, 0, btrfs_init_tree_ref(&ref, level - 1, dest->root_key.objectid, 0,
true); true);
ret = btrfs_inc_extent_ref(trans, &ref); ret = btrfs_inc_extent_ref(trans, &ref);
...@@ -1349,8 +1361,11 @@ int replace_path(struct btrfs_trans_handle *trans, struct reloc_control *rc, ...@@ -1349,8 +1361,11 @@ int replace_path(struct btrfs_trans_handle *trans, struct reloc_control *rc,
} }
/* We don't know the real owning_root, use 0. */ /* We don't know the real owning_root, use 0. */
btrfs_init_generic_ref(&ref, BTRFS_DROP_DELAYED_REF, new_bytenr, ref.action = BTRFS_DROP_DELAYED_REF;
blocksize, path->nodes[level]->start, 0); ref.bytenr = new_bytenr;
ref.len = blocksize;
ref.parent = path->nodes[level]->start;
ref.owning_root = 0;
btrfs_init_tree_ref(&ref, level - 1, src->root_key.objectid, btrfs_init_tree_ref(&ref, level - 1, src->root_key.objectid,
0, true); 0, true);
ret = btrfs_free_extent(trans, &ref); ret = btrfs_free_extent(trans, &ref);
...@@ -1360,8 +1375,11 @@ int replace_path(struct btrfs_trans_handle *trans, struct reloc_control *rc, ...@@ -1360,8 +1375,11 @@ int replace_path(struct btrfs_trans_handle *trans, struct reloc_control *rc,
} }
/* We don't know the real owning_root, use 0. */ /* We don't know the real owning_root, use 0. */
btrfs_init_generic_ref(&ref, BTRFS_DROP_DELAYED_REF, old_bytenr, ref.action = BTRFS_DROP_DELAYED_REF;
blocksize, 0, 0); ref.bytenr = old_bytenr;
ref.len = blocksize;
ref.parent = 0;
ref.owning_root = 0;
btrfs_init_tree_ref(&ref, level - 1, dest->root_key.objectid, btrfs_init_tree_ref(&ref, level - 1, dest->root_key.objectid,
0, true); 0, true);
ret = btrfs_free_extent(trans, &ref); ret = btrfs_free_extent(trans, &ref);
...@@ -2374,8 +2392,6 @@ static int do_relocation(struct btrfs_trans_handle *trans, ...@@ -2374,8 +2392,6 @@ static int do_relocation(struct btrfs_trans_handle *trans,
path->lowest_level = node->level + 1; path->lowest_level = node->level + 1;
rc->backref_cache.path[node->level] = node; rc->backref_cache.path[node->level] = node;
list_for_each_entry(edge, &node->upper, list[LOWER]) { list_for_each_entry(edge, &node->upper, list[LOWER]) {
struct btrfs_ref ref = { 0 };
cond_resched(); cond_resched();
upper = edge->node[UPPER]; upper = edge->node[UPPER];
...@@ -2463,16 +2479,20 @@ static int do_relocation(struct btrfs_trans_handle *trans, ...@@ -2463,16 +2479,20 @@ static int do_relocation(struct btrfs_trans_handle *trans,
*/ */
ASSERT(node->eb == eb); ASSERT(node->eb == eb);
} else { } else {
struct btrfs_ref ref = {
.action = BTRFS_ADD_DELAYED_REF,
.bytenr = node->eb->start,
.len = blocksize,
.parent = upper->eb->start,
.owning_root = btrfs_header_owner(upper->eb),
};
btrfs_set_node_blockptr(upper->eb, slot, btrfs_set_node_blockptr(upper->eb, slot,
node->eb->start); node->eb->start);
btrfs_set_node_ptr_generation(upper->eb, slot, btrfs_set_node_ptr_generation(upper->eb, slot,
trans->transid); trans->transid);
btrfs_mark_buffer_dirty(trans, upper->eb); btrfs_mark_buffer_dirty(trans, upper->eb);
btrfs_init_generic_ref(&ref, BTRFS_ADD_DELAYED_REF,
node->eb->start, blocksize,
upper->eb->start,
btrfs_header_owner(upper->eb));
btrfs_init_tree_ref(&ref, node->level, btrfs_init_tree_ref(&ref, node->level,
btrfs_header_owner(upper->eb), btrfs_header_owner(upper->eb),
root->root_key.objectid, false); root->root_key.objectid, false);
......
...@@ -748,7 +748,6 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans, ...@@ -748,7 +748,6 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans,
goto out; goto out;
if (ins.objectid > 0) { if (ins.objectid > 0) {
struct btrfs_ref ref = { 0 };
u64 csum_start; u64 csum_start;
u64 csum_end; u64 csum_end;
LIST_HEAD(ordered_sums); LIST_HEAD(ordered_sums);
...@@ -762,10 +761,12 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans, ...@@ -762,10 +761,12 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans,
if (ret < 0) { if (ret < 0) {
goto out; goto out;
} else if (ret == 0) { } else if (ret == 0) {
btrfs_init_generic_ref(&ref, struct btrfs_ref ref = {
BTRFS_ADD_DELAYED_REF, .action = BTRFS_ADD_DELAYED_REF,
ins.objectid, ins.offset, 0, .bytenr = ins.objectid,
root->root_key.objectid); .len = ins.offset,
.owning_root = root->root_key.objectid,
};
btrfs_init_data_ref(&ref, btrfs_init_data_ref(&ref,
root->root_key.objectid, root->root_key.objectid,
key->objectid, offset, 0, false); key->objectid, offset, 0, false);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment