Commit b4b5934a authored by Josef Bacik's avatar Josef Bacik Committed by David Sterba

btrfs: make the insert backref helpers take a btrfs_delayed_ref_node

We don't need to pass in all the elements for the backrefs as function
arguments, simply pass through the btrfs_delayed_ref_node and then
extract the values we need from that.
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 85bb9f54
...@@ -513,26 +513,26 @@ static noinline int lookup_extent_data_ref(struct btrfs_trans_handle *trans, ...@@ -513,26 +513,26 @@ static noinline int lookup_extent_data_ref(struct btrfs_trans_handle *trans,
static noinline int insert_extent_data_ref(struct btrfs_trans_handle *trans, static noinline int insert_extent_data_ref(struct btrfs_trans_handle *trans,
struct btrfs_path *path, struct btrfs_path *path,
u64 bytenr, u64 parent, struct btrfs_delayed_ref_node *node,
u64 root_objectid, u64 owner, u64 bytenr)
u64 offset, int refs_to_add)
{ {
struct btrfs_root *root = btrfs_extent_root(trans->fs_info, bytenr); struct btrfs_root *root = btrfs_extent_root(trans->fs_info, bytenr);
struct btrfs_key key; struct btrfs_key key;
struct extent_buffer *leaf; struct extent_buffer *leaf;
u64 owner = btrfs_delayed_ref_owner(node);
u64 offset = btrfs_delayed_ref_offset(node);
u32 size; u32 size;
u32 num_refs; u32 num_refs;
int ret; int ret;
key.objectid = bytenr; key.objectid = bytenr;
if (parent) { if (node->parent) {
key.type = BTRFS_SHARED_DATA_REF_KEY; key.type = BTRFS_SHARED_DATA_REF_KEY;
key.offset = parent; key.offset = node->parent;
size = sizeof(struct btrfs_shared_data_ref); size = sizeof(struct btrfs_shared_data_ref);
} else { } else {
key.type = BTRFS_EXTENT_DATA_REF_KEY; key.type = BTRFS_EXTENT_DATA_REF_KEY;
key.offset = hash_extent_data_ref(root_objectid, key.offset = hash_extent_data_ref(node->ref_root, owner, offset);
owner, offset);
size = sizeof(struct btrfs_extent_data_ref); size = sizeof(struct btrfs_extent_data_ref);
} }
...@@ -541,15 +541,15 @@ static noinline int insert_extent_data_ref(struct btrfs_trans_handle *trans, ...@@ -541,15 +541,15 @@ static noinline int insert_extent_data_ref(struct btrfs_trans_handle *trans,
goto fail; goto fail;
leaf = path->nodes[0]; leaf = path->nodes[0];
if (parent) { if (node->parent) {
struct btrfs_shared_data_ref *ref; struct btrfs_shared_data_ref *ref;
ref = btrfs_item_ptr(leaf, path->slots[0], ref = btrfs_item_ptr(leaf, path->slots[0],
struct btrfs_shared_data_ref); struct btrfs_shared_data_ref);
if (ret == 0) { if (ret == 0) {
btrfs_set_shared_data_ref_count(leaf, ref, refs_to_add); btrfs_set_shared_data_ref_count(leaf, ref, node->ref_mod);
} else { } else {
num_refs = btrfs_shared_data_ref_count(leaf, ref); num_refs = btrfs_shared_data_ref_count(leaf, ref);
num_refs += refs_to_add; num_refs += node->ref_mod;
btrfs_set_shared_data_ref_count(leaf, ref, num_refs); btrfs_set_shared_data_ref_count(leaf, ref, num_refs);
} }
} else { } else {
...@@ -557,7 +557,7 @@ static noinline int insert_extent_data_ref(struct btrfs_trans_handle *trans, ...@@ -557,7 +557,7 @@ static noinline int insert_extent_data_ref(struct btrfs_trans_handle *trans,
while (ret == -EEXIST) { while (ret == -EEXIST) {
ref = btrfs_item_ptr(leaf, path->slots[0], ref = btrfs_item_ptr(leaf, path->slots[0],
struct btrfs_extent_data_ref); struct btrfs_extent_data_ref);
if (match_extent_data_ref(leaf, ref, root_objectid, if (match_extent_data_ref(leaf, ref, node->ref_root,
owner, offset)) owner, offset))
break; break;
btrfs_release_path(path); btrfs_release_path(path);
...@@ -572,14 +572,13 @@ static noinline int insert_extent_data_ref(struct btrfs_trans_handle *trans, ...@@ -572,14 +572,13 @@ static noinline int insert_extent_data_ref(struct btrfs_trans_handle *trans,
ref = btrfs_item_ptr(leaf, path->slots[0], ref = btrfs_item_ptr(leaf, path->slots[0],
struct btrfs_extent_data_ref); struct btrfs_extent_data_ref);
if (ret == 0) { if (ret == 0) {
btrfs_set_extent_data_ref_root(leaf, ref, btrfs_set_extent_data_ref_root(leaf, ref, node->ref_root);
root_objectid);
btrfs_set_extent_data_ref_objectid(leaf, ref, owner); btrfs_set_extent_data_ref_objectid(leaf, ref, owner);
btrfs_set_extent_data_ref_offset(leaf, ref, offset); btrfs_set_extent_data_ref_offset(leaf, ref, offset);
btrfs_set_extent_data_ref_count(leaf, ref, refs_to_add); btrfs_set_extent_data_ref_count(leaf, ref, node->ref_mod);
} else { } else {
num_refs = btrfs_extent_data_ref_count(leaf, ref); num_refs = btrfs_extent_data_ref_count(leaf, ref);
num_refs += refs_to_add; num_refs += node->ref_mod;
btrfs_set_extent_data_ref_count(leaf, ref, num_refs); btrfs_set_extent_data_ref_count(leaf, ref, num_refs);
} }
} }
...@@ -703,20 +702,20 @@ static noinline int lookup_tree_block_ref(struct btrfs_trans_handle *trans, ...@@ -703,20 +702,20 @@ static noinline int lookup_tree_block_ref(struct btrfs_trans_handle *trans,
static noinline int insert_tree_block_ref(struct btrfs_trans_handle *trans, static noinline int insert_tree_block_ref(struct btrfs_trans_handle *trans,
struct btrfs_path *path, struct btrfs_path *path,
u64 bytenr, u64 parent, struct btrfs_delayed_ref_node *node,
u64 root_objectid) u64 bytenr)
{ {
struct btrfs_root *root = btrfs_extent_root(trans->fs_info, bytenr); struct btrfs_root *root = btrfs_extent_root(trans->fs_info, bytenr);
struct btrfs_key key; struct btrfs_key key;
int ret; int ret;
key.objectid = bytenr; key.objectid = bytenr;
if (parent) { if (node->parent) {
key.type = BTRFS_SHARED_BLOCK_REF_KEY; key.type = BTRFS_SHARED_BLOCK_REF_KEY;
key.offset = parent; key.offset = node->parent;
} else { } else {
key.type = BTRFS_TREE_BLOCK_REF_KEY; key.type = BTRFS_TREE_BLOCK_REF_KEY;
key.offset = root_objectid; key.offset = node->ref_root;
} }
ret = btrfs_insert_empty_item(trans, root, path, &key, 0); ret = btrfs_insert_empty_item(trans, root, path, &key, 0);
...@@ -1509,12 +1508,9 @@ static int __btrfs_inc_extent_ref(struct btrfs_trans_handle *trans, ...@@ -1509,12 +1508,9 @@ static int __btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
/* now insert the actual backref */ /* now insert the actual backref */
if (owner < BTRFS_FIRST_FREE_OBJECTID) if (owner < BTRFS_FIRST_FREE_OBJECTID)
ret = insert_tree_block_ref(trans, path, bytenr, node->parent, ret = insert_tree_block_ref(trans, path, node, bytenr);
node->ref_root);
else else
ret = insert_extent_data_ref(trans, path, bytenr, node->parent, ret = insert_extent_data_ref(trans, path, node, bytenr);
node->ref_root, owner, offset,
refs_to_add);
if (ret) if (ret)
btrfs_abort_transaction(trans, ret); btrfs_abort_transaction(trans, ret);
......
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