Commit Graph

175 Commits

Author SHA1 Message Date
Zhang Yu e96921bcaa Btrfs-progs: print-tree: check num_stripes in print_chunk
[TEST/fuzz] case: 004-simple-dump-tree

Since the wrong key(DATA_RELOC_TREE CHUNK_ITEM 0) in root tree,
error calling print_chunk(), resulting in num_stripes == 0.

ERROR:
     [TEST/fuzz]   004-simple-dump-tree
ctree.h:317: btrfs_chunk_item_size: BUG_ON `num_stripes == 0`
        triggered, value 1

failed (ignored, ret=134): /myproject/btrfs-progs/btrfs
inspect-internal dump-tree
/myproject/btrfs-progs/tests/fuzz-tests/images/
bko-155201-wrong-chunk-item-in-root-tree.raw.restored

test failed for case 004-simple-dump-tree
Makefile:288: recipe for target 'test-fuzz' failed
make: *** [test-fuzz] Error 1

So, check on num_stripes in print_chunk

Signed-off-by: Zhang Yu <zhangyu-fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-08 16:15:05 +02:00
David Sterba 36db1080c3 btrfs-progs: print-tree: factor out extent_csum dump
Factor out code to own helper and tweak the format so it matches the
rest.

Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-08 16:15:05 +02:00
Josef Bacik 5fbc00cc73 btrfs-progs: print the csum length in debug-tree
While looking at a log of a corrupted fs I needed to verify we were
missing csums for a given range.  Make this easier by printing out the
range of bytes a csum item covers.

Signed-off-by: Josef Bacik <jbacik@fb.com>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-08 16:15:05 +02:00
David Sterba 8609c8bad6 btrfs-progs: print-tree: factor out temporary_item dump
Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-08 16:15:05 +02:00
David Sterba a4b65f00d5 btrfs-progs: print-tree: factor out persistent_item dump
Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-08 16:15:05 +02:00
David Sterba 61a578751d btrfs-progs: print-tree: factor out qgroup_limit dump
Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-08 16:15:05 +02:00
David Sterba 90631b721e btrfs-progs: print-tree: factor out qgroup_info dump
Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-08 16:15:05 +02:00
David Sterba 346d2e16dd btrfs-progs: print-tree: factor out qgroup_status dump
Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-08 16:15:05 +02:00
David Sterba 59714a77c3 btrfs-progs: print-tree: factor out dev_extent dump
Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-08 16:15:05 +02:00
David Sterba c3b767a208 btrfs-progs: print-tree: factor out free_space_info dump
Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-08 16:15:05 +02:00
David Sterba b3122697f6 btrfs-progs: print-tree: factor out shared_data_ref dump
Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-08 16:15:05 +02:00
David Sterba c23c1271d3 btrfs-progs: print-tree: factor out extent_data_ref dump
Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-08 16:15:05 +02:00
David Sterba e853a1abcd btrfs-progs: print-tree: factor out block_group_item dump
Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-08 16:15:05 +02:00
David Sterba 077a7024cd btrfs-progs: print-tree: don't print the item type for all items
In some cases it's clear from the context which item is being printed,
so we can remove them. If the item has no data, some description is
still desired (eg. orphan or various backrefs).

Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-08 16:15:05 +02:00
David Sterba 1224f7343e btrfs-progs: print-tree: rename item callbacks to match the key name
Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-08 16:15:05 +02:00
David Sterba 98909c21d7 btrfs-progs: drop blocksize from read_tree_block
Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-08 16:15:05 +02:00
David Sterba 1fa9653dc8 btrfs-progs: drop local blocksize variables if they're nodesize
Prep work so we can drop the blocksize argument from several functions.

Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-08 16:15:05 +02:00
Adam Buchbinder 3987fb6f07 btrfs-progs: Tighten integer types in print-tree
There are likely more places where the wrong size types are used, but
these tripped Clang's warnings because they eventually get passed to
printf.

Signed-off-by: Adam Buchbinder <abuchbinder@google.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-07-20 17:43:43 +02:00
Qu Wenruo 8690c887d1 btrfs-progs: Refactor read_tree_block to get rid of btrfs_root
The only reasom read_tree_block() needs a btrfs_root parameter is to get
its node/sector size.

And long ago, I have already introduced a compactible interface,
read_tree_block_fs_info() to pass btrfs_fs_info instead of btrfs_root.

Since we have cleaned up all root->sector/node/stripesize users, we
should be OK to refactor read_tree_block() function.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
2017-07-03 13:35:11 +02:00
Qu Wenruo 428e689b87 btrfs-progs: Refactor nodesize user in print-tree.c
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
2017-07-03 13:35:10 +02:00
Qu Wenruo f8c82394c4 btrfs-progs: print-tree: Add leaf flags and backref revision output
Btrfs header has a u64 member flags, whose lowest 56 bits are for header
flags like WRITTEN and RELOC.
And its highest 8 bits are for backref revision.

Manually checking btrfs_header_flags() will be a pain, so add such leaf
flags and backref revision output for print-tree.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-05-15 16:13:17 +02:00
Lu Fengqi da76d52947 btrfs-progs: print-tree: add validation to print_chunk
In print_chunk, validate the value of uuid_offset when read the dev_uuid of
stripe.

Was triggered by misc-test/015-dump-super-garbage running indefinetelly.

Issue: #37
Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-04-20 13:35:39 +02:00
David Sterba f8278f94ff btrfs-progs: print-tree: fix format string on 32bit
We're passing a size_t, use the right format specifier.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-24 13:06:36 +01:00
David Sterba 5103e80b21 btrfs-progs: dump-tree: use new names for obsoleted keys
The DEV_STATS and BALANCE_ITEM have been deprecated in favor of more
general items, print the new names in the dump.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-09 13:47:31 +01:00
David Sterba b9ff0190cf btrfs-progs: dump-tree: convert dir-item-to-string to table
Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-09 13:47:30 +01:00
David Sterba e6410f631d btrfs-progs: dump-tree: convert key-to-string to table
Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-09 13:47:30 +01:00
David Sterba 69f879eac9 btrfs-progs: dump-tree: cleanup types for item number iteration
Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-09 13:47:30 +01:00
David Sterba 56917b41fb btrfs-progs: dump-tree: move remaining item variables to the scope of use
Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-09 13:47:30 +01:00
David Sterba e58cc23823 btrfs-progs: dump-tree: move variable declarations closer to their use
Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-09 13:47:30 +01:00
David Sterba 6b138f5367 btrfs-progs: dump-tree: rename extent buffer variable in btrfs_print_leaf
Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-09 13:47:30 +01:00
David Sterba 7541b53b34 btrfs-progs: dump-tree: add untyped item ptr helper and use it
There's lots of code that passes btrfs_item_ptr. Add a helper to extract
the ptr at the beginning, ignoring the type. The print functions take
the correct type, but we ignore it in the conversion macros as it does
not provide the type checking anyway.

If the typed variable is used more than once, it's kept in place.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-09 13:47:30 +01:00
David Sterba 17a9d9013d btrfs-progs: dump-tree: constify char argument in print_root_ref
Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-09 13:47:30 +01:00
David Sterba a15294f0c4 btrfs-progs: dump-tree: simplify and fix check for empty uuid
Counting non-zero bytes is wasteful, besides that it would not recognize
uuids containing a 00 value.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-09 13:47:30 +01:00
David Sterba 5082ec84a8 btrfs-progs: dump-tree: return void from print_* functions
Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-09 13:47:30 +01:00
David Sterba e9c1121495 btrfs-progs: dump-tree: pass item size instead of item
Several functions take item but use just the size, we can factor the
item size and use that.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-09 13:47:30 +01:00
David Sterba ae00d4a251 btrfs-progs: remove unused parameter from print_inode_item
Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-09 13:47:30 +01:00
David Sterba 15db981600 btrfs-progs: dump-tree: consolidate data key names
Rename to the structure members, add underscore so it's a single word.
Compression is also printed as raw value.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-09 13:47:30 +01:00
David Sterba cf5c55fba8 btrfs-progs: dump-tree: print dev stats
Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-09 13:47:30 +01:00
David Sterba b74dbb86c0 btrfs-progs: dump-tree: print balance status item
Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-09 13:47:30 +01:00
David Sterba 8a50dc9600 btrfs-progs: teach print_leaf about temporary item subtypes
[ kernel patch 9f07e1d76eaeeddedcf9651395b4a8f870df31f0 ]
Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-09 13:47:30 +01:00
David Sterba 9da5b472d5 btrfs-progs: teach print_leaf about permanent item subtypes
[ kernel patch 585a3d0d238dfe42909cb58b0d05f644365fed14 ]
Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-09 13:47:30 +01:00
David Sterba e905d055f6 btrfs-progs: print-tree: extract offset from the item key
Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-09 13:47:30 +01:00
David Sterba 5d43dfd344 btrfs-progs: dump-tree: print missing data for file extent item
Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-09 13:47:30 +01:00
David Sterba 069b0b6d14 btrfs-progs: dump-tree: print more root_item data
Print a few more missing items of root_item (there are still some
remaining). Drop key is printend unconditionally.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-09 13:47:29 +01:00
David Sterba 58bef5b4a7 btrfs-progs: dump-tree: print missing dir_item data
Add items from dir_item that are not printed, plus other adjustments.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-09 13:47:29 +01:00
David Sterba 6c849c616e btrfs-progs: dump-tree: print missing inode_item data
Add items from inode_item that are not printed.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-09 13:47:29 +01:00
David Sterba f1d4606a6d btrfs-progs: dump-tree: add helper to print timespec
Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-09 13:47:29 +01:00
David Sterba 58fe71f3f7 btrfs-progs: dump-tree: factor inode_item dump to function
Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-09 13:47:29 +01:00
David Sterba cae265e816 btrfs-progs: dump-tree: print missing dev_extent data
Add items from chunk that are not printed, unify names according to
the member names and reorder a bit.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-09 13:47:29 +01:00
David Sterba c6cd8ff6ec btrfs-progs: dump-tree: print missing chunk data
Add items from chunk that are not printed, unify names according to
the member names and reorder a bit.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-09 13:47:29 +01:00