btrfs-progs: dump-tree: output the sequence number for inline references

Commit 6cf11f3e38 ("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>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Qu Wenruo 2023-10-22 14:10:07 +10:30 committed by David Sterba
parent a45c360b64
commit ad8a831a74
1 changed files with 17 additions and 12 deletions

View File

@ -487,38 +487,43 @@ 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;