From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 1/3] btrfs-progs: dump-tree: output the sequence number for inline references
Date: Sun, 22 Oct 2023 14:10:07 +1030 [thread overview]
Message-ID: <fa881bcd58d137e9096150c0a875f2dcee38ae30.1697945679.git.wqu@suse.com> (raw)
In-Reply-To: <cover.1697945679.git.wqu@suse.com>
Commit 6cf11f3e3815 ("btrfs-progs: check: check order of inline extent
refs") fixes a problem that btrfs check never properly verify the
sequence of inline references.
It's not obvious because by default kernel handles EXTENT_DATA_REF_KEY
using its own hash, resulting some seemingly out-of-order result:
item 0 key (13631488 EXTENT_ITEM 4096) itemoff 16143 itemsize 140
refs 4 gen 7 flags DATA
extent data backref root FS_TREE objectid 258 offset 0 count 1
extent data backref root FS_TREE objectid 257 offset 0 count 1
extent data backref root FS_TREE objectid 260 offset 0 count 1
extent data backref root FS_TREE objectid 259 offset 0 count 1
By a quick glance, no one can see the above inline backref items are in
any order.
To make such sequence more obvious, let dump-tree to output a new prefix
to indicate the type and the internal sequence number:
For above case, the new output would look like this:
item 0 key (13631488 EXTENT_ITEM 4096) itemoff 16143 itemsize 140
refs 4 gen 7 flags DATA
(178 0xdfb591fbbf5f519) extent data backref root FS_TREE objectid 258 offset 0 count 1
(178 0xdfb591fa80d95ea) extent data backref root FS_TREE objectid 257 offset 0 count 1
(178 0xdfb591f9c0534ff) extent data backref root FS_TREE objectid 260 offset 0 count 1
(178 0xdfb591f49f9f8e7) extent data backref root FS_TREE objectid 259 offset 0 count 1
Although still not that obvious, it should show the inline data backrefs
has descending sequence number.
For the type part, it's anti-instinctive in ascending order, which is
not that easy to produce.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
kernel-shared/print-tree.c | 31 +++++++++++++++++++------------
1 file changed, 19 insertions(+), 12 deletions(-)
diff --git a/kernel-shared/print-tree.c b/kernel-shared/print-tree.c
index f6e7539eb191..9e3ebddb97b3 100644
--- a/kernel-shared/print-tree.c
+++ b/kernel-shared/print-tree.c
@@ -487,38 +487,45 @@ void print_extent_item(struct extent_buffer *eb, int slot, int metadata)
ptr = (unsigned long)iref;
end = (unsigned long)ei + item_size;
while (ptr < end) {
+ u64 seq;
+
iref = (struct btrfs_extent_inline_ref *)ptr;
type = btrfs_extent_inline_ref_type(eb, iref);
offset = btrfs_extent_inline_ref_offset(eb, iref);
+ seq = offset;
switch (type) {
case BTRFS_TREE_BLOCK_REF_KEY:
- printf("\t\ttree block backref root ");
+ printf("\t\t(%u 0x%llx) tree block backref root ",
+ type, seq);
print_objectid(stdout, offset, 0);
printf("\n");
break;
case BTRFS_SHARED_BLOCK_REF_KEY:
- printf("\t\tshared block backref parent %llu\n",
- (unsigned long long)offset);
+ printf("\t\t(%u 0x%llx) shared block backref parent %llu\n",
+ type, seq, offset);
break;
case BTRFS_EXTENT_DATA_REF_KEY:
dref = (struct btrfs_extent_data_ref *)(&iref->offset);
- printf("\t\textent data backref root ");
- print_objectid(stdout,
- (unsigned long long)btrfs_extent_data_ref_root(eb, dref), 0);
+ seq = hash_extent_data_ref(
+ btrfs_extent_data_ref_root(eb, dref),
+ btrfs_extent_data_ref_objectid(eb, dref),
+ btrfs_extent_data_ref_offset(eb, dref));
+ printf("\t\t(%u 0x%llx) extent data backref root ",
+ type, seq);
+ print_objectid(stdout, btrfs_extent_data_ref_root(eb, dref), 0);
printf(" objectid %llu offset %llu count %u\n",
- (unsigned long long)btrfs_extent_data_ref_objectid(eb, dref),
+ btrfs_extent_data_ref_objectid(eb, dref),
btrfs_extent_data_ref_offset(eb, dref),
btrfs_extent_data_ref_count(eb, dref));
break;
case BTRFS_SHARED_DATA_REF_KEY:
sref = (struct btrfs_shared_data_ref *)(iref + 1);
- printf("\t\tshared data backref parent %llu count %u\n",
- (unsigned long long)offset,
- btrfs_shared_data_ref_count(eb, sref));
+ printf("\t\t(%u 0x%llx) shared data backref parent %llu count %u\n",
+ type, seq, offset, btrfs_shared_data_ref_count(eb, sref));
break;
case BTRFS_EXTENT_OWNER_REF_KEY:
- printf("\t\textent owner root %llu\n",
- (unsigned long long)offset);
+ printf("\t\(%u 0x%llx) textent owner root %llu\n",
+ type, seq, offset);
break;
default:
return;
--
2.42.0
next prev parent reply other threads:[~2023-10-22 3:41 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-22 3:40 [PATCH 0/3] btrfs-progs: follow-ups for issue #622 Qu Wenruo
2023-10-22 3:40 ` Qu Wenruo [this message]
2023-10-22 3:40 ` [PATCH 2/3] btrfs-progs: check/lowmem: verify the sequence of inline backref items Qu Wenruo
2023-10-22 3:40 ` [PATCH 3/3] btrfs-progs: fsck-tests: add test image of out-of-order " Qu Wenruo
2023-10-24 5:28 ` Anand Jain
2023-10-24 5:47 ` Qu Wenruo
2023-10-24 11:15 ` David Sterba
2023-10-23 13:42 ` [PATCH 0/3] btrfs-progs: follow-ups for issue #622 David Sterba
2023-10-24 6:18 ` Anand Jain
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=fa881bcd58d137e9096150c0a875f2dcee38ae30.1697945679.git.wqu@suse.com \
--to=wqu@suse.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).