btrfs-progs: dump-tree: print complete root_item

The output of root_item in the 'inspect dump-tree' command lacks some
items and some of them are printed conditionally. As the dump utility
is for debugging, it's better to print all the items, with names
matching the structure members and order.

Some values will inevitably be all zeros like uuids or various
timestamps, but that's a minor issue and affecting only a few trees.

Example:

  item 0 key (EXTENT_TREE ROOT_ITEM 0) itemoff 15844 itemsize 439
	  generation 5 root_dirid 0 bytenr 30523392 byte_limit 0 bytes_used 16384
	  last_snapshot 0 flags 0x0(none) refs 1
	  drop_progress key (0 UNKNOWN.0 0) drop_level 0
	  level 0 generation_v2 5
	  uuid 00000000-0000-0000-0000-000000000000
	  parent_uuid 00000000-0000-0000-0000-000000000000
	  received_uuid 00000000-0000-0000-0000-000000000000
	  ctransid 0 otransid 0 stransid 0 rtransid 0
	  ctime 0.0 (1970-01-01 01:00:00)
	  otime 0.0 (1970-01-01 01:00:00)
	  stime 0.0 (1970-01-01 01:00:00)
	  rtime 0.0 (1970-01-01 01:00:00)

  item 3 key (FS_TREE ROOT_ITEM 0) itemoff 14949 itemsize 439
	  generation 4 root_dirid 256 bytenr 30408704 byte_limit 0 bytes_used 16384
	  last_snapshot 0 flags 0x0(none) refs 1
	  drop_progress key (0 UNKNOWN.0 0) drop_level 0
	  level 0 generation_v2 4
	  uuid ec4669b6-6d21-46ab-857e-d60cafde45b3
	  parent_uuid 00000000-0000-0000-0000-000000000000
	  received_uuid 00000000-0000-0000-0000-000000000000
	  ctransid 0 otransid 0 stransid 0 rtransid 0
	  ctime 1633021823.0 (2021-09-30 19:10:23)
	  otime 1633021823.0 (2021-09-30 19:10:23)
	  stime 0.0 (1970-01-01 01:00:00)
	  rtime 0.0 (1970-01-01 01:00:00)

Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2021-10-01 15:29:24 +02:00
parent ad4d5b163b
commit 27207d651a
2 changed files with 24 additions and 43 deletions

View File

@ -534,16 +534,6 @@ static void print_root_ref(struct extent_buffer *leaf, int slot, const char *tag
namelen, namebuf);
}
static int empty_uuid(const u8 *uuid)
{
int i;
for (i = 0; i < BTRFS_UUID_SIZE; i++)
if (uuid[i])
return 0;
return 1;
}
/*
* Caller must ensure sizeof(*ret) >= 7 "RDONLY"
*/
@ -591,55 +581,46 @@ static void print_root_item(struct extent_buffer *leaf, int slot)
read_extent_buffer(leaf, &root_item, (unsigned long)ri, len);
root_flags_to_str(btrfs_root_flags(&root_item), flags_str);
printf("\t\tgeneration %llu root_dirid %llu bytenr %llu level %hhu refs %u\n",
printf("\t\tgeneration %llu root_dirid %llu bytenr %llu byte_limit %llu bytes_used %llu\n",
(unsigned long long)btrfs_root_generation(&root_item),
(unsigned long long)btrfs_root_dirid(&root_item),
(unsigned long long)btrfs_root_bytenr(&root_item),
btrfs_root_level(&root_item),
btrfs_root_refs(&root_item));
printf("\t\tlastsnap %llu byte_limit %llu bytes_used %llu flags 0x%llx(%s)\n",
(unsigned long long)btrfs_root_last_snapshot(&root_item),
(unsigned long long)btrfs_root_limit(&root_item),
(unsigned long long)btrfs_root_used(&root_item),
(unsigned long long)btrfs_root_used(&root_item));
printf("\t\tlast_snapshot %llu flags 0x%llx(%s) refs %u\n",
(unsigned long long)btrfs_root_last_snapshot(&root_item),
(unsigned long long)btrfs_root_flags(&root_item),
flags_str);
flags_str,
btrfs_root_refs(&root_item));
btrfs_disk_key_to_cpu(&drop_key, &root_item.drop_progress);
printf("\t\tdrop_progress ");
btrfs_print_key(&root_item.drop_progress);
printf(" drop_level %hhu\n", root_item.drop_level);
printf("\t\tlevel %hhu generation_v2 %llu\n",
btrfs_root_level(&root_item), root_item.generation_v2);
if (root_item.generation == root_item.generation_v2) {
uuid_unparse(root_item.uuid, uuid_str);
printf("\t\tuuid %s\n", uuid_str);
if (!empty_uuid(root_item.parent_uuid)) {
uuid_unparse(root_item.parent_uuid, uuid_str);
printf("\t\tparent_uuid %s\n", uuid_str);
}
if (!empty_uuid(root_item.received_uuid)) {
uuid_unparse(root_item.received_uuid, uuid_str);
printf("\t\treceived_uuid %s\n", uuid_str);
}
if (root_item.ctransid) {
printf("\t\tctransid %llu otransid %llu stransid %llu rtransid %llu\n",
uuid_unparse(root_item.parent_uuid, uuid_str);
printf("\t\tparent_uuid %s\n", uuid_str);
uuid_unparse(root_item.received_uuid, uuid_str);
printf("\t\treceived_uuid %s\n", uuid_str);
printf("\t\tctransid %llu otransid %llu stransid %llu rtransid %llu\n",
btrfs_root_ctransid(&root_item),
btrfs_root_otransid(&root_item),
btrfs_root_stransid(&root_item),
btrfs_root_rtransid(&root_item));
}
if (btrfs_timespec_sec(leaf, btrfs_root_ctime(ri)))
print_timespec(leaf, btrfs_root_ctime(ri),
print_timespec(leaf, btrfs_root_ctime(ri),
"\t\tctime ", "\n");
if (btrfs_timespec_sec(leaf, btrfs_root_otime(ri)))
print_timespec(leaf, btrfs_root_otime(ri),
print_timespec(leaf, btrfs_root_otime(ri),
"\t\totime ", "\n");
if (btrfs_timespec_sec(leaf, btrfs_root_stime(ri)))
print_timespec(leaf, btrfs_root_stime(ri),
print_timespec(leaf, btrfs_root_stime(ri),
"\t\tstime ", "\n");
if (btrfs_timespec_sec(leaf, btrfs_root_rtime(ri)))
print_timespec(leaf, btrfs_root_rtime(ri),
print_timespec(leaf, btrfs_root_rtime(ri),
"\t\trtime ", "\n");
}
btrfs_disk_key_to_cpu(&drop_key, &root_item.drop_progress);
printf("\t\tdrop ");
btrfs_print_key(&root_item.drop_progress);
printf(" level %hhu\n", root_item.drop_level);
}
static void print_free_space_header(struct extent_buffer *leaf, int slot)

View File

@ -20,7 +20,7 @@ prepare_test_dev
run_check_mkfs_test_dev
# match not-all-zeros in the first part
uuid=$(run_check_stdout $SUDO_HELPER "$TOP/btrfs" inspect-internal dump-tree -t root "$TEST_DEV" | \
grep -A 3 "FS_TREE ROOT_ITEM 0" | grep 'uuid ')
grep -A 5 "FS_TREE ROOT_ITEM 0" | grep 'uuid ')
if [ $? != 0 ]; then
_fail "uuid for FS_TREE not found"
@ -31,5 +31,5 @@ if [ "$uuid" = '00000000-0000-0000-0000-000000000000' ]; then
fi
run_check_stdout $SUDO_HELPER "$TOP/btrfs" inspect-internal dump-tree -t root "$TEST_DEV" | \
grep -A 5 "FS_TREE ROOT_ITEM 0" | grep -q 'otime ' || \
grep -A 10 "FS_TREE ROOT_ITEM 0" | grep -q 'otime ' || \
_fail "otime for FS_TREE not found"