linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Gu Jinxiang <gujx@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
Subject: [PATCH 2/6] btrfs-progs: Use fs_info instead of root for BTRFS_NODEPTRS_PER_BLOCK
Date: Fri, 26 Jan 2018 11:22:02 +0800	[thread overview]
Message-ID: <1516936926-18707-2-git-send-email-gujx@cn.fujitsu.com> (raw)
In-Reply-To: <1516936926-18707-1-git-send-email-gujx@cn.fujitsu.com>

Do a cleanup. Also make it consistent with kernel.
Use fs_info instead of root for BTRFS_NODEPTRS_PER_BLOCK, since
maybe in some situation we do not know root, but just know fs_info.

Signed-off-by: Gu Jinxiang <gujx@cn.fujitsu.com>
---
 cmds-check.c |  4 ++--
 ctree.c      | 18 +++++++++---------
 ctree.h      |  3 +--
 print-tree.c |  2 +-
 quick-test.c |  2 +-
 5 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/cmds-check.c b/cmds-check.c
index b118ea71..b94fab4f 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -2529,7 +2529,7 @@ static void account_bytes(struct btrfs_root *root, struct btrfs_path *path,
 	if (level == 0) {
 		btree_space_waste += btrfs_leaf_free_space(root, eb);
 	} else {
-		free_nrs = (BTRFS_NODEPTRS_PER_BLOCK(root) -
+		free_nrs = (BTRFS_NODEPTRS_PER_BLOCK(root->fs_info) -
 			    btrfs_header_nritems(eb));
 		btree_space_waste += free_nrs * sizeof(struct btrfs_key_ptr);
 	}
@@ -9504,7 +9504,7 @@ static int run_next_block(struct btrfs_root *root,
 				add_pending(pending, seen, ptr, size);
 			}
 		}
-		btree_space_waste += (BTRFS_NODEPTRS_PER_BLOCK(root) -
+		btree_space_waste += (BTRFS_NODEPTRS_PER_BLOCK(fs_info) -
 				      nritems) * sizeof(struct btrfs_key_ptr);
 	}
 	total_btree_bytes += buf->len;
diff --git a/ctree.c b/ctree.c
index cb16c42c..11d207e7 100644
--- a/ctree.c
+++ b/ctree.c
@@ -429,7 +429,7 @@ btrfs_check_node(struct btrfs_root *root, struct btrfs_disk_key *parent_key,
 	u32 nritems = btrfs_header_nritems(buf);
 	enum btrfs_tree_block_status ret = BTRFS_TREE_BLOCK_INVALID_NRITEMS;
 
-	if (nritems == 0 || nritems > BTRFS_NODEPTRS_PER_BLOCK(root))
+	if (nritems == 0 || nritems > BTRFS_NODEPTRS_PER_BLOCK(root->fs_info))
 		goto fail;
 
 	ret = BTRFS_TREE_BLOCK_INVALID_PARENT_KEY;
@@ -716,7 +716,7 @@ static int balance_level(struct btrfs_trans_handle *trans,
 		return ret;
 	}
 	if (btrfs_header_nritems(mid) >
-	    BTRFS_NODEPTRS_PER_BLOCK(root) / 4)
+	    BTRFS_NODEPTRS_PER_BLOCK(fs_info) / 4)
 		return 0;
 
 	left = read_node_slot(fs_info, parent, pslot - 1);
@@ -884,7 +884,7 @@ static int noinline push_nodes_for_insert(struct btrfs_trans_handle *trans,
 	if (extent_buffer_uptodate(left)) {
 		u32 left_nr;
 		left_nr = btrfs_header_nritems(left);
-		if (left_nr >= BTRFS_NODEPTRS_PER_BLOCK(root) - 1) {
+		if (left_nr >= BTRFS_NODEPTRS_PER_BLOCK(fs_info) - 1) {
 			wret = 1;
 		} else {
 			ret = btrfs_cow_block(trans, root, left, parent,
@@ -927,7 +927,7 @@ static int noinline push_nodes_for_insert(struct btrfs_trans_handle *trans,
 	if (extent_buffer_uptodate(right)) {
 		u32 right_nr;
 		right_nr = btrfs_header_nritems(right);
-		if (right_nr >= BTRFS_NODEPTRS_PER_BLOCK(root) - 1) {
+		if (right_nr >= BTRFS_NODEPTRS_PER_BLOCK(root->fs_info) - 1) {
 			wret = 1;
 		} else {
 			ret = btrfs_cow_block(trans, root, right,
@@ -1146,7 +1146,7 @@ again:
 			p->slots[level] = slot;
 			if ((p->search_for_split || ins_len > 0) &&
 			    btrfs_header_nritems(b) >=
-			    BTRFS_NODEPTRS_PER_BLOCK(root) - 3) {
+			    BTRFS_NODEPTRS_PER_BLOCK(fs_info) - 3) {
 				int sret = split_node(trans, root, p, level);
 				BUG_ON(sret > 0);
 				if (sret)
@@ -1292,7 +1292,7 @@ static int push_node_left(struct btrfs_trans_handle *trans,
 
 	src_nritems = btrfs_header_nritems(src);
 	dst_nritems = btrfs_header_nritems(dst);
-	push_items = BTRFS_NODEPTRS_PER_BLOCK(root) - dst_nritems;
+	push_items = BTRFS_NODEPTRS_PER_BLOCK(root->fs_info) - dst_nritems;
 	WARN_ON(btrfs_header_generation(src) != trans->transid);
 	WARN_ON(btrfs_header_generation(dst) != trans->transid);
 
@@ -1362,7 +1362,7 @@ static int balance_node_right(struct btrfs_trans_handle *trans,
 
 	src_nritems = btrfs_header_nritems(src);
 	dst_nritems = btrfs_header_nritems(dst);
-	push_items = BTRFS_NODEPTRS_PER_BLOCK(root) - dst_nritems;
+	push_items = BTRFS_NODEPTRS_PER_BLOCK(root->fs_info) - dst_nritems;
 	if (push_items <= 0) {
 		return 1;
 	}
@@ -1490,7 +1490,7 @@ static int insert_ptr(struct btrfs_trans_handle *trans, struct btrfs_root
 	nritems = btrfs_header_nritems(lower);
 	if (slot > nritems)
 		BUG();
-	if (nritems == BTRFS_NODEPTRS_PER_BLOCK(root))
+	if (nritems == BTRFS_NODEPTRS_PER_BLOCK(root->fs_info))
 		BUG();
 	if (slot < nritems) {
 		/* shift the items */
@@ -1539,7 +1539,7 @@ static int split_node(struct btrfs_trans_handle *trans, struct btrfs_root
 		ret = push_nodes_for_insert(trans, root, path, level);
 		c = path->nodes[level];
 		if (!ret && btrfs_header_nritems(c) <
-		    BTRFS_NODEPTRS_PER_BLOCK(root) - 3)
+		    BTRFS_NODEPTRS_PER_BLOCK(root->fs_info) - 3)
 			return 0;
 		if (ret < 0)
 			return ret;
diff --git a/ctree.h b/ctree.h
index 11913efa..9e9d3d22 100644
--- a/ctree.h
+++ b/ctree.h
@@ -356,8 +356,7 @@ struct btrfs_header {
 	u8 level;
 } __attribute__ ((__packed__));
 
-#define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->fs_info->nodesize - \
-			        sizeof(struct btrfs_header)) / \
+#define BTRFS_NODEPTRS_PER_BLOCK(fs_info) (BTRFS_LEAF_DATA_SIZE(fs_info) / \
 			        sizeof(struct btrfs_key_ptr))
 #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
 #define BTRFS_LEAF_DATA_SIZE(fs_info) \
diff --git a/print-tree.c b/print-tree.c
index d3fa8621..5f37ef3e 100644
--- a/print-tree.c
+++ b/print-tree.c
@@ -1359,7 +1359,7 @@ void btrfs_print_tree(struct btrfs_root *root, struct extent_buffer *eb, int fol
 	printf("node %llu level %d items %d free %u generation %llu owner %llu\n",
 	       (unsigned long long)eb->start,
 	        btrfs_header_level(eb), nr,
-		(u32)BTRFS_NODEPTRS_PER_BLOCK(root) - nr,
+		(u32)BTRFS_NODEPTRS_PER_BLOCK(root->fs_info) - nr,
 		(unsigned long long)btrfs_header_generation(eb),
 		(unsigned long long)btrfs_header_owner(eb));
 	print_uuids(eb);
diff --git a/quick-test.c b/quick-test.c
index b1e7999d..5da47c32 100644
--- a/quick-test.c
+++ b/quick-test.c
@@ -110,7 +110,7 @@ int main(int ac, char **av) {
 	printf("node %p level %d total ptrs %d free spc %lu\n", root->node,
 	        btrfs_header_level(root->node),
 		btrfs_header_nritems(root->node),
-		(unsigned long)BTRFS_NODEPTRS_PER_BLOCK(root) -
+		(unsigned long)BTRFS_NODEPTRS_PER_BLOCK(root->fs_info) -
 		btrfs_header_nritems(root->node));
 	printf("all searches good, deleting some items\n");
 	i = 0;
-- 
2.14.3




  reply	other threads:[~2018-01-26  3:22 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-26  3:22 [PATCH 1/6] btrfs-progs: Use fs_info instead of root for BTRFS_LEAF_DATA_SIZE Gu Jinxiang
2018-01-26  3:22 ` Gu Jinxiang [this message]
2018-01-26  5:16   ` [PATCH 2/6] btrfs-progs: Use fs_info instead of root for BTRFS_NODEPTRS_PER_BLOCK Qu Wenruo
2018-01-26  5:34     ` Gu, Jinxiang
2018-01-26  3:22 ` [PATCH 3/6] btrfs-progs: Use fs_info instead of root for BTRFS_MAX_INLINE_DATA_SIZE Gu Jinxiang
2018-01-26  5:29   ` Qu Wenruo
2018-01-26  3:22 ` [PATCH 4/6] btrfs-progs: Use fs_info instead of root for BTRFS_MAX_XATTR_SIZE Gu Jinxiang
2018-01-26  5:31   ` Qu Wenruo
2018-01-26  3:22 ` [PATCH 5/6] btrfs-progs: do clean up for redundancy value assignment Gu Jinxiang
2018-01-26  5:34   ` Qu Wenruo
2018-01-26  3:22 ` [PATCH 6/6] btrfs-progs: remove no longer be used btrfs_alloc_extent Gu Jinxiang
2018-01-26  5:32   ` Qu Wenruo
2018-01-26  3:37 ` [PATCH 1/6] btrfs-progs: Use fs_info instead of root for BTRFS_LEAF_DATA_SIZE Qu Wenruo
2018-01-26  5:12   ` Gu, Jinxiang
2018-01-26  5:21     ` Qu Wenruo

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=1516936926-18707-2-git-send-email-gujx@cn.fujitsu.com \
    --to=gujx@cn.fujitsu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).