All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: selftests: dump extent io tree if extent-io-tree test failed
@ 2021-12-30  8:45 Qu Wenruo
  2022-01-03 16:07 ` Josef Bacik
  2022-01-03 18:08 ` David Sterba
  0 siblings, 2 replies; 3+ messages in thread
From: Qu Wenruo @ 2021-12-30  8:45 UTC (permalink / raw)
  To: linux-btrfs

When code modifying extent-io-tree get modified and got that selftest
failed, it can take some time to pin down the cause.

To make it easier to expose the problem, dump the extent io tree if the
selftest failed.

This can save developers debug time, especially since the selftest we
can not use the trace events, thus have to manually add debug trace
points.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 fs/btrfs/tests/extent-io-tests.c | 52 ++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/fs/btrfs/tests/extent-io-tests.c b/fs/btrfs/tests/extent-io-tests.c
index c2e72e7a8ff0e..160480f6155e8 100644
--- a/fs/btrfs/tests/extent-io-tests.c
+++ b/fs/btrfs/tests/extent-io-tests.c
@@ -56,6 +56,54 @@ static noinline int process_page_range(struct inode *inode, u64 start, u64 end,
 	return count;
 }
 
+#define STATE_FLAG_STR_LEN	256
+
+#define print_one_flag(state, dest, cur, name)				\
+({									\
+	if (state->state & EXTENT_##name)				\
+		cur += scnprintf(dest + cur, STATE_FLAG_STR_LEN - cur,	\
+				 "%s" #name, cur == 0 ? "" : "|");	\
+})
+
+static void extent_flag_to_str(struct extent_state *state, char *dest)
+{
+	int cur = 0;
+
+	dest[0] = '\0';
+	print_one_flag(state, dest, cur, DIRTY);
+	print_one_flag(state, dest, cur, UPTODATE);
+	print_one_flag(state, dest, cur, LOCKED);
+	print_one_flag(state, dest, cur, NEW);
+	print_one_flag(state, dest, cur, DELALLOC);
+	print_one_flag(state, dest, cur, DEFRAG);
+	print_one_flag(state, dest, cur, BOUNDARY);
+	print_one_flag(state, dest, cur, NODATASUM);
+	print_one_flag(state, dest, cur, CLEAR_META_RESV);
+	print_one_flag(state, dest, cur, NEED_WAIT);
+	print_one_flag(state, dest, cur, DAMAGED);
+	print_one_flag(state, dest, cur, NORESERVE);
+	print_one_flag(state, dest, cur, QGROUP_RESERVED);
+	print_one_flag(state, dest, cur, CLEAR_DATA_RESV);
+}
+
+static void dump_extent_io_tree(struct extent_io_tree *tree)
+{
+	struct rb_node *node;
+	char flags_str[STATE_FLAG_STR_LEN];
+
+	node = rb_first(&tree->state);
+	test_msg("io tree content:");
+	while (node) {
+		struct extent_state *state;
+
+		state = rb_entry(node, struct extent_state, rb_node);
+		extent_flag_to_str(state, flags_str);
+		test_msg("  start=%llu len=%llu flags=%s", state->start,
+			 state->end + 1 - state->start, flags_str);
+		node = rb_next(node);
+	}
+}
+
 static int test_find_delalloc(u32 sectorsize)
 {
 	struct inode *inode;
@@ -258,6 +306,8 @@ static int test_find_delalloc(u32 sectorsize)
 	}
 	ret = 0;
 out_bits:
+	if (ret)
+		dump_extent_io_tree(tmp);
 	clear_extent_bits(tmp, 0, total_dirty - 1, (unsigned)-1);
 out:
 	if (locked_page)
@@ -534,6 +584,8 @@ static int test_find_first_clear_extent_bit(void)
 
 	ret = 0;
 out:
+	if (ret)
+		dump_extent_io_tree(&tree);
 	clear_extent_bits(&tree, 0, (u64)-1, CHUNK_TRIMMED | CHUNK_ALLOCATED);
 
 	return ret;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] btrfs: selftests: dump extent io tree if extent-io-tree test failed
  2021-12-30  8:45 [PATCH] btrfs: selftests: dump extent io tree if extent-io-tree test failed Qu Wenruo
@ 2022-01-03 16:07 ` Josef Bacik
  2022-01-03 18:08 ` David Sterba
  1 sibling, 0 replies; 3+ messages in thread
From: Josef Bacik @ 2022-01-03 16:07 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: linux-btrfs

On Thu, Dec 30, 2021 at 04:45:13PM +0800, Qu Wenruo wrote:
> When code modifying extent-io-tree get modified and got that selftest
> failed, it can take some time to pin down the cause.
> 
> To make it easier to expose the problem, dump the extent io tree if the
> selftest failed.
> 
> This can save developers debug time, especially since the selftest we
> can not use the trace events, thus have to manually add debug trace
> points.
> 
> Signed-off-by: Qu Wenruo <wqu@suse.com>

Love it,

Reviewed-by: Josef Bacik <josef@toxicpanda.com>

Thanks,

Josef

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] btrfs: selftests: dump extent io tree if extent-io-tree test failed
  2021-12-30  8:45 [PATCH] btrfs: selftests: dump extent io tree if extent-io-tree test failed Qu Wenruo
  2022-01-03 16:07 ` Josef Bacik
@ 2022-01-03 18:08 ` David Sterba
  1 sibling, 0 replies; 3+ messages in thread
From: David Sterba @ 2022-01-03 18:08 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: linux-btrfs

On Thu, Dec 30, 2021 at 04:45:13PM +0800, Qu Wenruo wrote:
> When code modifying extent-io-tree get modified and got that selftest
> failed, it can take some time to pin down the cause.
> 
> To make it easier to expose the problem, dump the extent io tree if the
> selftest failed.
> 
> This can save developers debug time, especially since the selftest we
> can not use the trace events, thus have to manually add debug trace
> points.
> 
> Signed-off-by: Qu Wenruo <wqu@suse.com>

Added to misc-next, thanks.

> ---
>  fs/btrfs/tests/extent-io-tests.c | 52 ++++++++++++++++++++++++++++++++
>  1 file changed, 52 insertions(+)
> 
> diff --git a/fs/btrfs/tests/extent-io-tests.c b/fs/btrfs/tests/extent-io-tests.c
> index c2e72e7a8ff0e..160480f6155e8 100644
> --- a/fs/btrfs/tests/extent-io-tests.c
> +++ b/fs/btrfs/tests/extent-io-tests.c
> @@ -56,6 +56,54 @@ static noinline int process_page_range(struct inode *inode, u64 start, u64 end,
>  	return count;
>  }
>  
> +#define STATE_FLAG_STR_LEN	256
> +
> +#define print_one_flag(state, dest, cur, name)				\

Please use uppercase name for magic macros.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-01-03 18:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-30  8:45 [PATCH] btrfs: selftests: dump extent io tree if extent-io-tree test failed Qu Wenruo
2022-01-03 16:07 ` Josef Bacik
2022-01-03 18:08 ` David Sterba

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.