summaryrefslogtreecommitdiff
path: root/print-tree.c
Commit message (Collapse)AuthorAge
* btrfs-progs: print-tree: Use bool for @followQu Wenruo2018-10-31
| | | | | | | Just a minor cleanup to make the parameter easier to read. Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: print-tree: Introduce --bfs and --dfs optionsQu Wenruo2018-10-31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Originally print-tree uses depth first search to print trees. This works fine until we reach 3 level trees (root node level is 2). For tall trees whose root level is 2 or higher, DFS will mix nodes and leaves like the following example: Level 2 A / \ Level 1 B C / | | \ Level 0 D E F G DFS will cause the following output sequence: A B D E C F G Which in term of node/leave is: N N L L N L L Such mixed node/leave result is sometimes hard for human to read. This patch will introduce 2 new options, --bfs and --dfs. --dfs: keeps the original output sequence, and to keep things compatible it's the default behavior. --bfs: uses breadth-first search, and will cause better output sequence like: A B C D E F G Which in term of node/leave is: N N N L L L L Much better sorted and may become default in the future. Reviewed-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: print-tree: Introduce breadth-first searchQu Wenruo2018-10-31
| | | | | | | | | Introduce a new function, bfs_print_children(), to do breadth-first search to print a node. Reviewed-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: print-tree: skip deprecated blockptr / nodesize outputQu Wenruo2018-10-23
| | | | | | | | | | | | | | | | | | | | | When printing tree nodes, we output slots like: key (EXTENT_TREE ROOT_ITEM 0) block 73625600 (17975) gen 16 The number in the parentheses is blockptr / nodesize. However this number doesn't really do anything useful. And in fact for unaligned metadata block group (block group start bytenr is not aligned to 16K), the number doesn't even make sense as it's rounded down. In fact kernel doesn't ever output such divided result in its print-tree.c Remove it so later reader won't wonder what the number means. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Get rid of the confusing btrfs_file_extent_inline_len()Qu Wenruo2018-08-06
| | | | | | | | | | | | | | | | | | | | | | | | [BUG] If one uncompressed inline extent has incorrect ram_bytes, neither btrfs check nor dump-tree could detect such corruption. [CAUSE] Every caller tries to read inline extent ram_bytes is using btrfs_file_extent_inline_len(), other than directly calling btrfs_file_extent_ram_bytes(). For compressed extent, it's just calling btrfs_file_extent_ram_bytes(). However for uncompressed extent, it falls back to btrfs_file_extent_inline_item_len(), makes us unable to detect anything wrong in ram_bytes. [FIX] Just get rid of such confusing btrfs_file_extent_inline_len() function. Reported-by: Steve Leung <sjleung@shaw.ca> Tested-by: Steve Leung <sjleung@shaw.ca> Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: print-tree: remove dead code from btrfs_print_treeLu Fengqi2018-06-07
| | | | | | | | | Since the out label has been deleted, this free_extent_buffer will never be executed. Fixes: f37ae8d275c2 ("btrfs-progs: print-tree: Enhance warning on tree block level mismatch and error handling") Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: ins: dump-tree: Print tree name for extent data/tree block backrefMisono Tomohiro2018-06-07
| | | | | | | | | | | | | | | | | | | Print tree name instead of number to make output more readable. Example: [before] extent data backref root 5 objectid 257 offset 16384 count 1 tree block backref root 18446744073709551607 [after] extent data backref root FS_TREE objectid 257 offset 16384 count 1 tree block backref root DATA_RELOC_TREE Signed-off-by: Misono Tomohiro <misono.tomohiro@jp.fujitsu.com> Reviewed-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: ins: dump-tree: Use %lld for extent data backref offsetMisono Tomohiro2018-06-07
| | | | | | | | Offset of extent data backref in extent item can be negative. So, let's use %lld insteand of %llu to output readable value. Signed-off-by: Misono Tomohiro <misono.tomohiro@jp.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: print-tree: Enhance btrfs_print_tree() check to avoid ↵Qu Wenruo2018-06-07
| | | | | | | | | | | | out-of-boundary memory access For btrfs_print_tree(), if nr_items is corrupted, it can easily go beyond extent buffer boundary. Add extra nr_item check, and only print as many valid slots as possible. Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Allow tree to be printed without an fs_infoQu Wenruo2018-06-07
| | | | | | | | | | | | | | | | | | | | | | | | For btrfs_print_tree() and btrfs_print_leaf(), the usage of fs_info is mainly for nodesize and sectorsize. However for nodesize, we can get it from @eb->len without the need for fs_info at all. For nodesize, introduce new helper BTRFS_NODEPTR_PER_EXTENT_BUFFER() to get nodesize from @eb directly. And with the help of previous modified btrfs_leaf_free_space(), btrfs_print_tree() can live without fs_info at all. For btrfs_print_leaf(), we modify print_extent_csum() to accept NULL fs_info by skipping csum length calculation. With all these modification, btrfs_print_tree/leaf() can be called without accessing @fs_info at all, and make it more flexible to handle binary tree block dump, or inside gdb. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Su Yue <suy.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Remove fs_info parameter from btrfs_leaf_free_space()Qu Wenruo2018-06-07
| | | | | | | | | | | | | | | | | For btrfs_leaf_free_space(), to get leaf data size, we have two way to get it: 1) leaf->fs_info->nodesize 2) leaf->len Anyway, we could get rid of @fs_info parameter for btrfs_leaf_free_space(). And here we choose method 2), as it provides extra benefit to get leaf free space without initializing a real fs_info. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Su Yue <suy.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: print-tree: Avoid segfault for heavily corrupted item pointersQu Wenruo2018-06-07
| | | | | | | | | | | | | | | | | | | | | Normally corrupted leaf should be caught by csum check, but sometimes corrupted item pointers (out of leaf range) can still pass csum check. In fact, our fsck/005 test case image has such corrupted item pointer and btrfs check can surprisingly fix it. Anyway, make print-tree to skip such item and remaining slots to avoid segfault. Please note that, in btrfs-progs we can't put such check into check_tree_block() nor do kernel level comprehensive check as under certain case, btrfs-progs can handle or even repair it. A strict check_tree_block() or backporting kernel btrfs_check_leaf() could break such test cases and reduce the utility of btrfs-progs. Issue: #128 Reported-by: Hubert Kario <hubert@kario.pl> Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: print-tree: Remove btrfs_root parameterQu Wenruo2018-04-24
| | | | | | | | | | | | Just like kernel cleanup made by David, btrfs_print_leaf() and btrfs_print_tree() doesn't need btrfs_root parameter at all. With previous patches as preparation, now we can remove the btrfs_root parameter. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Unify btrfs_leaf_free_space() parameter with kernelQu Wenruo2018-04-24
| | | | | | | | | | Instead of struct btrfs_root, use struct btrfs_fs_info, since nodesize is now a per-fs setting, and with the need to pass a @root, caller don't need to wonder which root should be passed. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Beautify owner when printing leaf/nodesNikolay Borisov2018-03-30
| | | | | | | | | | | | | | | Currently we print the raw values of the owner field of leaf/nodes. This can result in output like the following: leaf 30490624 items 2 free space 16061 generation 4 owner 18446744073709551607 With the patch applied the same leaf looks like: leaf 30490624 items 2 free space 16061 generation 4 owner DATA_RELOC_TREE Signed-off-by: Nikolay Borisov <nborisov@suse.com> Reviewed-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: print-tree: Enhance warning on tree block level mismatch and ↵Qu Wenruo2018-03-30
| | | | | | | | | | | | | | | | | | | | | | error handling This patch enhances the tree block level mismatch by the following methods: 1) Merge same warning branches into one We had two branches showing the same message, and their condition is also the same. Merge them 2) Only skip bad slot The old code skipped all the remaining slots, here we just skip one slot to output as many correct tree blocks as possible. 3) Enhance warning message Output the parent bytenr and expected and wrong level, so we don't need to refer to stdout to get which tree block is corrupted. Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: print-tree: Do correct offset output for ROOT_ITEMQu Wenruo2018-03-30
| | | | | | | | | | | | | | | | | Commit Fixes: 8c36786c8198 ("btrfs-progs: print-tree: Print offset as tree objectid for ROOT_ITEM") changes how we translate offset of ROOT_ITEM. However the fact is, even for ROOT_ITEM, we have different meaning of offset. For tree reloc tree, it's indeed subvolume id. But for other trees, it's the transid of when it's created. Reported-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: print-tree: fix INODE_ITEM sequence and flagsAnand Jain2018-02-13
| | | | | | | | dump-tree prints wrong sequence number and the flags numbers, as we misplaced the printf args. This patch fixes it. Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Use fs_info instead of root for BTRFS_NODEPTRS_PER_BLOCKGu Jinxiang2018-02-02
| | | | | | | | | | | | Do a cleanup. Also make it consistent with kernel. Use fs_info instead of root for BTRFS_NODEPTRS_PER_BLOCK, since maybe in some situation we do not know root, but just know fs_info. To be consistent with kernel, change macro to inline function. Signed-off-by: Gu Jinxiang <gujx@cn.fujitsu.com> Reviewed-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: dump-tree: print c/o/s/r time of ROOT_ITEMMisono, Tomohiro2018-01-03
| | | | | | | | | | Currently ctime/otime/stime/rtime of ROOT_ITEM are not printed in print_root_item(). Fix this and print them if the values are not zero. The function print_timespec() is moved forward to reuse. Signed-off-by: Tomohiro Misono <misono.tomohiro@jp.fujitsu.com> Reviewed-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: print-tree: Print offset as tree objectid for ROOT_ITEMQu Wenruo2017-11-14
| | | | | | | | | | | | | | | | | | | | | For cases like reloc trees and subvolume trees, their key offset is the tree id. The key will be printed as: (TREE_RELOC ROOT_ITEM 18446744073709551607) The negative number is long and even guys with real engineer brains can't easily get the meaning. This patch will change the output format to: (TREE_RELOC ROOT_ITEM DATA_RELOC_TREE) While for special offset value like 0 or (u64)-1, it's still shown as is. Signed-off-by: Qu Wenruo <wqu@suse.com> [ reword comment ] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: print-tree: use proper helper for reading offsetDavid Sterba2017-09-25
| | | | | | | | | | | | | Sparse warns print-tree.c:1261:49: warning: incorrect type in argument 4 (different base types) print-tree.c:1261:49: expected unsigned long long [unsigned] [usertype] start print-tree.c:1261:49: got restricted __le64 [addressable] [usertype] offset which means we have to use the helper instead of directly accessing the offset member. This could print bogus number on bigendian arch. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Add zstd supportNick Terrell2017-09-25
| | | | | | | | | | | | | | | | Adds zstd support to the btrfs program. An optional dependency on libzstd >= 1.0.0 is added. Autoconf accepts `--enable-zstd' or `--disable-zstd' and defaults to detecting if libzstd is present using `pkg-config'. The patch is also available in my fork of btrfs-progs [1], which passes Travis-CI with the new tests. The prebuilt binary is available there. I haven't updated Android.mk. [1] https://github.com/terrelln/btrfs-progs/tree/devel Signed-off-by: Nick Terrell <terrelln@fb.com> Signed-off-by: David Sterba <dsterba@suse.com>
* Btrfs-progs: print-tree: check num_stripes in print_chunkZhang Yu2017-09-08
| | | | | | | | | | | | | | | | | | | | | | | | | | [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>
* btrfs-progs: print-tree: factor out extent_csum dumpDavid Sterba2017-09-08
| | | | | | | Factor out code to own helper and tweak the format so it matches the rest. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: print the csum length in debug-treeJosef Bacik2017-09-08
| | | | | | | | | | 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>
* btrfs-progs: print-tree: factor out temporary_item dumpDavid Sterba2017-09-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: print-tree: factor out persistent_item dumpDavid Sterba2017-09-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: print-tree: factor out qgroup_limit dumpDavid Sterba2017-09-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: print-tree: factor out qgroup_info dumpDavid Sterba2017-09-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: print-tree: factor out qgroup_status dumpDavid Sterba2017-09-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: print-tree: factor out dev_extent dumpDavid Sterba2017-09-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: print-tree: factor out free_space_info dumpDavid Sterba2017-09-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: print-tree: factor out shared_data_ref dumpDavid Sterba2017-09-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: print-tree: factor out extent_data_ref dumpDavid Sterba2017-09-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: print-tree: factor out block_group_item dumpDavid Sterba2017-09-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: print-tree: don't print the item type for all itemsDavid Sterba2017-09-08
| | | | | | | | 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>
* btrfs-progs: print-tree: rename item callbacks to match the key nameDavid Sterba2017-09-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: drop blocksize from read_tree_blockDavid Sterba2017-09-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: drop local blocksize variables if they're nodesizeDavid Sterba2017-09-08
| | | | | | Prep work so we can drop the blocksize argument from several functions. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Tighten integer types in print-treeAdam Buchbinder2017-07-20
| | | | | | | | | 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>
* btrfs-progs: Refactor read_tree_block to get rid of btrfs_rootQu Wenruo2017-07-03
| | | | | | | | | | | | | 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>
* btrfs-progs: Refactor nodesize user in print-tree.cQu Wenruo2017-07-03
| | | | Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
* btrfs-progs: print-tree: Add leaf flags and backref revision outputQu Wenruo2017-05-15
| | | | | | | | | | | | 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>
* btrfs-progs: print-tree: add validation to print_chunkLu Fengqi2017-04-20
| | | | | | | | | | | 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>
* btrfs-progs: print-tree: fix format string on 32bitDavid Sterba2016-11-24
| | | | | | We're passing a size_t, use the right format specifier. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: dump-tree: use new names for obsoleted keysDavid Sterba2016-11-09
| | | | | | | 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>
* btrfs-progs: dump-tree: convert dir-item-to-string to tableDavid Sterba2016-11-09
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: dump-tree: convert key-to-string to tableDavid Sterba2016-11-09
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: dump-tree: cleanup types for item number iterationDavid Sterba2016-11-09
| | | | Signed-off-by: David Sterba <dsterba@suse.com>