All of lore.kernel.org
 help / color / mirror / Atom feed
From: Josef Bacik <josef@toxicpanda.com>
To: linux-btrfs@vger.kernel.org, kernel-team@fb.com
Subject: [PATCH 15/19] btrfs: make the insert backref helpers take a btrfs_delayed_ref_node
Date: Sat, 13 Apr 2024 19:53:25 -0400	[thread overview]
Message-ID: <c849bc3ba7c0871ff672eca80e4f096eec92fe98.1713052088.git.josef@toxicpanda.com> (raw)
In-Reply-To: <cover.1713052088.git.josef@toxicpanda.com>

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.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/extent-tree.c | 46 +++++++++++++++++++-----------------------
 1 file changed, 21 insertions(+), 25 deletions(-)

diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 540dadcefb92..d85bc31f2e57 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -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,
 					   struct btrfs_path *path,
-					   u64 bytenr, u64 parent,
-					   u64 root_objectid, u64 owner,
-					   u64 offset, int refs_to_add)
+					   struct btrfs_delayed_ref_node *node,
+					   u64 bytenr)
 {
 	struct btrfs_root *root = btrfs_extent_root(trans->fs_info, bytenr);
 	struct btrfs_key key;
 	struct extent_buffer *leaf;
+	u64 owner = btrfs_delayed_ref_owner(node);
+	u64 offset = btrfs_delayed_ref_offset(node);
 	u32 size;
 	u32 num_refs;
 	int ret;
 
 	key.objectid = bytenr;
-	if (parent) {
+	if (node->parent) {
 		key.type = BTRFS_SHARED_DATA_REF_KEY;
-		key.offset = parent;
+		key.offset = node->parent;
 		size = sizeof(struct btrfs_shared_data_ref);
 	} else {
 		key.type = BTRFS_EXTENT_DATA_REF_KEY;
-		key.offset = hash_extent_data_ref(root_objectid,
-						  owner, offset);
+		key.offset = hash_extent_data_ref(node->ref_root, owner, offset);
 		size = sizeof(struct btrfs_extent_data_ref);
 	}
 
@@ -541,15 +541,15 @@ static noinline int insert_extent_data_ref(struct btrfs_trans_handle *trans,
 		goto fail;
 
 	leaf = path->nodes[0];
-	if (parent) {
+	if (node->parent) {
 		struct btrfs_shared_data_ref *ref;
 		ref = btrfs_item_ptr(leaf, path->slots[0],
 				     struct btrfs_shared_data_ref);
 		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 {
 			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);
 		}
 	} else {
@@ -557,7 +557,7 @@ static noinline int insert_extent_data_ref(struct btrfs_trans_handle *trans,
 		while (ret == -EEXIST) {
 			ref = btrfs_item_ptr(leaf, path->slots[0],
 					     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))
 				break;
 			btrfs_release_path(path);
@@ -572,14 +572,13 @@ static noinline int insert_extent_data_ref(struct btrfs_trans_handle *trans,
 		ref = btrfs_item_ptr(leaf, path->slots[0],
 				     struct btrfs_extent_data_ref);
 		if (ret == 0) {
-			btrfs_set_extent_data_ref_root(leaf, ref,
-						       root_objectid);
+			btrfs_set_extent_data_ref_root(leaf, ref, node->ref_root);
 			btrfs_set_extent_data_ref_objectid(leaf, ref, owner);
 			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 {
 			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);
 		}
 	}
@@ -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,
 					  struct btrfs_path *path,
-					  u64 bytenr, u64 parent,
-					  u64 root_objectid)
+					  struct btrfs_delayed_ref_node *node,
+					  u64 bytenr)
 {
 	struct btrfs_root *root = btrfs_extent_root(trans->fs_info, bytenr);
 	struct btrfs_key key;
 	int ret;
 
 	key.objectid = bytenr;
-	if (parent) {
+	if (node->parent) {
 		key.type = BTRFS_SHARED_BLOCK_REF_KEY;
-		key.offset = parent;
+		key.offset = node->parent;
 	} else {
 		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);
@@ -1509,12 +1508,9 @@ static int __btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
 
 	/* now insert the actual backref */
 	if (owner < BTRFS_FIRST_FREE_OBJECTID)
-		ret = insert_tree_block_ref(trans, path, bytenr, node->parent,
-					    node->ref_root);
+		ret = insert_tree_block_ref(trans, path, node, bytenr);
 	else
-		ret = insert_extent_data_ref(trans, path, bytenr, node->parent,
-					     node->ref_root, owner, offset,
-					     refs_to_add);
+		ret = insert_extent_data_ref(trans, path, node, bytenr);
 
 	if (ret)
 		btrfs_abort_transaction(trans, ret);
-- 
2.43.0


  parent reply	other threads:[~2024-04-13 23:53 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-13 23:53 [PATCH 00/19] btrfs: delayed refs cleanups Josef Bacik
2024-04-13 23:53 ` [PATCH 01/19] btrfs: add a helper to get the delayed ref node from the data/tree ref Josef Bacik
2024-04-15 12:37   ` Filipe Manana
2024-04-13 23:53 ` [PATCH 02/19] btrfs: embed data_ref and tree_ref in btrfs_delayed_ref_node Josef Bacik
2024-04-15 12:38   ` Filipe Manana
2024-04-13 23:53 ` [PATCH 03/19] btrfs: do not use a function to initialize btrfs_ref Josef Bacik
2024-04-15 12:40   ` Filipe Manana
2024-04-13 23:53 ` [PATCH 04/19] btrfs: move ref_root into btrfs_ref Josef Bacik
2024-04-15 12:40   ` Filipe Manana
2024-04-13 23:53 ` [PATCH 05/19] btrfs: pass btrfs_ref to init_delayed_ref_common Josef Bacik
2024-04-15 12:43   ` Filipe Manana
2024-04-13 23:53 ` [PATCH 06/19] btrfs: initialize btrfs_delayed_ref_head with btrfs_ref Josef Bacik
2024-04-15 12:44   ` Filipe Manana
2024-04-13 23:53 ` [PATCH 07/19] btrfs: move ref specific initialization into init_delayed_ref_common Josef Bacik
2024-04-15 12:44   ` Filipe Manana
2024-04-13 23:53 ` [PATCH 08/19] btrfs: simplify delayed ref tracepoints Josef Bacik
2024-04-15 12:45   ` Filipe Manana
2024-04-13 23:53 ` [PATCH 09/19] btrfs: unify the btrfs_add_delayed_*_ref helpers into one helper Josef Bacik
2024-04-15 12:48   ` Filipe Manana
2024-04-13 23:53 ` [PATCH 10/19] btrfs: rename ->len to ->num_bytes in btrfs_ref Josef Bacik
2024-04-15 12:49   ` Filipe Manana
2024-04-13 23:53 ` [PATCH 11/19] btrfs: move ->parent and ->ref_root into btrfs_delayed_ref_node Josef Bacik
2024-04-15 12:56   ` Filipe Manana
2024-04-13 23:53 ` [PATCH 12/19] btrfs: rename btrfs_data_ref->ino to ->objectid Josef Bacik
2024-04-15 12:57   ` Filipe Manana
2024-04-13 23:53 ` [PATCH 13/19] btrfs: make __btrfs_inc_extent_ref take a btrfs_delayed_ref_node Josef Bacik
2024-04-15 13:00   ` Filipe Manana
2024-04-13 23:53 ` [PATCH 14/19] btrfs: drop unnecessary arguments from __btrfs_free_extent Josef Bacik
2024-04-15 13:00   ` Filipe Manana
2024-04-13 23:53 ` Josef Bacik [this message]
2024-04-15 13:01   ` [PATCH 15/19] btrfs: make the insert backref helpers take a btrfs_delayed_ref_node Filipe Manana
2024-04-13 23:53 ` [PATCH 16/19] btrfs: stop referencing btrfs_delayed_data_ref directly Josef Bacik
2024-04-15 13:04   ` Filipe Manana
2024-04-13 23:53 ` [PATCH 17/19] btrfs: stop referencing btrfs_delayed_tree_ref directly Josef Bacik
2024-04-15 13:05   ` Filipe Manana
2024-04-13 23:53 ` [PATCH 18/19] btrfs: remove the btrfs_delayed_ref_node container helpers Josef Bacik
2024-04-15 13:06   ` Filipe Manana
2024-04-13 23:53 ` [PATCH 19/19] btrfs: replace btrfs_delayed_*_ref with btrfs_*_ref Josef Bacik
2024-04-15 13:11   ` Filipe Manana

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c849bc3ba7c0871ff672eca80e4f096eec92fe98.1713052088.git.josef@toxicpanda.com \
    --to=josef@toxicpanda.com \
    --cc=kernel-team@fb.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.