diff mbox

[1/2] btrfs-progs: Allow btrfs_leaf_free_space to accept NULL root

Message ID 1446712380-7654-1-git-send-email-quwenruo@cn.fujitsu.com (mailing list archive)
State Accepted
Headers show

Commit Message

Qu Wenruo Nov. 5, 2015, 8:32 a.m. UTC
Btrfs_leaf_free_space() function is used to determine the leaf/node
size.
It's OK to use root->nodesize to determine nodesize, but in fact,
extent_buffer->len can also be used to determine the nodesize if caller
can ensure it's a tree block.

So this patch will add support for NULL root for btrfs_leaf_free_space()
function, to allow btrfs_print_leaf() functions to be called in gdb or
to debug temporary btrfs in make_btrfs() without a valid root.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 ctree.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Comments

David Sterba Nov. 5, 2015, 12:40 p.m. UTC | #1
On Thu, Nov 05, 2015 at 04:32:59PM +0800, Qu Wenruo wrote:
> Btrfs_leaf_free_space() function is used to determine the leaf/node
> size.
> It's OK to use root->nodesize to determine nodesize, but in fact,
> extent_buffer->len can also be used to determine the nodesize if caller
> can ensure it's a tree block.
> 
> So this patch will add support for NULL root for btrfs_leaf_free_space()
> function, to allow btrfs_print_leaf() functions to be called in gdb or
> to debug temporary btrfs in make_btrfs() without a valid root.
> 
> Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>

Applied, thanks.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/ctree.c b/ctree.c
index 1434007..46153e3 100644
--- a/ctree.c
+++ b/ctree.c
@@ -1619,13 +1619,14 @@  static int leaf_space_used(struct extent_buffer *l, int start, int nr)
  */
 int btrfs_leaf_free_space(struct btrfs_root *root, struct extent_buffer *leaf)
 {
+	u32 nodesize = (root ? BTRFS_LEAF_DATA_SIZE(root) : leaf->len);
 	int nritems = btrfs_header_nritems(leaf);
 	int ret;
-	ret = BTRFS_LEAF_DATA_SIZE(root) - leaf_space_used(leaf, 0, nritems);
+	ret = nodesize - leaf_space_used(leaf, 0, nritems);
 	if (ret < 0) {
-		printk("leaf free space ret %d, leaf data size %lu, used %d nritems %d\n",
-		       ret, (unsigned long) BTRFS_LEAF_DATA_SIZE(root),
-		       leaf_space_used(leaf, 0, nritems), nritems);
+		printk("leaf free space ret %d, leaf data size %u, used %d nritems %d\n",
+		       ret, nodesize, leaf_space_used(leaf, 0, nritems),
+		       nritems);
 	}
 	return ret;
 }