summaryrefslogtreecommitdiff
path: root/check/main.c
Commit message (Collapse)AuthorAge
* New upstream releaseDimitri John Ledkov2019-01-26
|
* btrfs-progs: check: fix typo in device_extent_record::chunk_objectidJosh Soref2018-11-26
| | | | | | | | | | | This header is exported to /usr/include/btrfs but there are no known users, so the change should be safe. Generated by https://github.com/jsoref/spelling Issue: #154 Author: Josh Soref <jsoref@users.noreply.github.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: fix typos in user-visible stringsJosh Soref2018-11-26
| | | | | | | | | | | * error messages * help strings Generated by https://github.com/jsoref/spelling Issue: #154 Author: Josh Soref <jsoref@users.noreply.github.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: fix typos in commentsJosh Soref2018-11-26
| | | | | | | | Generated by https://github.com/jsoref/spelling Issue: #154 Author: Josh Soref <jsoref@users.noreply.github.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: convert strerror to implicit %mDavid Sterba2018-10-31
| | | | | | | | | | | | | | | Similar to the changes where strerror(errno) was converted, continue with the remaining cases where the argument was stored in another variable. The savings in object size are about 4500 bytes: $ size btrfs.old btrfs.new text data bss dec hex filename 805055 24248 19748 849051 cf49b btrfs.old 804527 24248 19748 848523 cf28b btrfs.new Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: Add support for freespace tree fixingNikolay Borisov2018-10-25
| | | | | | | | | | | | | Now that all the prerequisite code for proper support of free space tree repair is in, it's time to wire it in. This is achieved by first hooking the freespace tree to the __free_extent/alloc_reserved_tree_block functions. And then introducing a wrapper function to contains the existing check_space_cache and the newly introduced repair code. Finally, it's important to note that FST repair code first clears the existing FST in case of any problem found and rebuilds it from scratch. Signed-off-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Wire up delayed refsNikolay Borisov2018-10-23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit enables the delayed refs infrastructures. This entails doing the following: 1. Replacing existing calls of btrfs_extent_post_op (which is the equivalent of delayed refs) with the proper btrfs_run_delayed_refs. As well as eliminating open-coded calls to finish_current_insert and del_pending_extents which execute the delayed ops. 2. Wiring up the addition of delayed refs when freeing extents (btrfs_free_extent) and when adding new extents (alloc_tree_block). 3. Adding calls to btrfs_run_delayed refs in the transaction commit path alongside comments why every call is needed, since it's not always obvious (those call sites were derived empirically by running and debugging existing tests) 4. Correctly flagging the transaction in which we are reinitialising the extent tree. 5. Moving btrfs_write_dirty_block_groups to btrfs_write_dirty_block_groups since blockgroups should be written to disk after the last delayed refs have been run. Signed-off-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: fix infinite loop when bad key order repair failsQu Wenruo2018-10-23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | An infinite loop can be triggered during fuzz/003: ====== RUN MAYFAIL btrfs check --repair tests/fuzz-tests/images/bko-199833-reloc-recovery-crash.raw.restored [1/7] checking root items Fixed 0 roots. [2/7] checking extents ctree.c:1650: leaf_space_used: Warning: assertion `data_len < 0` failed, value 1 bad key ordering 18 19 ctree.c:1650: leaf_space_used: Warning: assertion `data_len < 0` failed, value 1 bad key ordering 18 19 ctree.c:1650: leaf_space_used: Warning: assertion `data_len < 0` failed, value 1 bad key ordering 18 19 [CAUSE] In try_to_fix_bad_block() it's possible that btrfs_find_all_roots() finds no root referring to that tree block, thus we can't do any repair. However in that case, we still return 0 since the last caller assigning @ret is btrfs_find_all_roots(), and the ulist while loop doesn't get run at all. And since try_to_fix_bad_block() returns 0, check_block() in check/main.c will return -EAGAIN to re-check the tree block. This leads to the infinite loop. [FIX] Change the default return value from 0 to -EIO in try_to_fix_bad_block(), so if there is no tree referring to the bad tree block, it won't cause infinite loop anymore. Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: exit gracefully when root dir item repair failsQu Wenruo2018-10-23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Another BUG_ON() during fuzz/003: ====== RUN MAYFAIL btrfs check --init-csum-tree tests/fuzz-tests/images/bko-161821.raw.restored [1/7] checking root items Fixed 0 roots. [2/7] checking extents parent transid verify failed on 4198400 wanted 14 found 1114126 parent transid verify failed on 4198400 wanted 14 found 1114126 Ignoring transid failure owner ref check failed [4198400 4096] repair deleting extent record: key [4198400,169,0] adding new tree backref on start 4198400 len 4096 parent 0 root 5 Repaired extent references for 4198400 ref mismatch on [4222976 4096] extent item 1, found 0 backref 4222976 root 7 not referenced back 0x55e9cc694780 incorrect global backref count on 4222976 found 1 wanted 0 backpointer mismatch on [4222976 4096] owner ref check failed [4222976 4096] repair deleting extent record: key [4222976,169,0] Repaired extent references for 4222976 [3/7] checking free space cache [4/7] checking fs roots parent transid verify failed on 4198400 wanted 14 found 1114126 Ignoring transid failure Wrong generation of child node/leaf, wanted: 1114126, have: 14 root 5 missing its root dir, recreating parent transid verify failed on 4198400 wanted 14 found 1114126 Ignoring transid failure ERROR: child eb corrupted: parent bytenr=4222976 item=0 parent level=1 child level=2 check/main.c:2738: check_inode_recs: BUG_ON `ret` triggered, value -5 failed (ignored, ret=134): btrfs check --init-csum-tree tests/fuzz-tests/images/bko-161821.raw.restored mayfail: returned code 134 (SIGABRT), not ignored test failed for case 003-multi-check-unmounted Just abort current transaction and exit gracefully in this case, the caller handles errors. 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: check: reorder options to sectionsDavid Sterba2018-08-06
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check/original: Don't overwrite return value when we failed to ↵Qu Wenruo2018-08-06
| | | | | | | | | | | | | | repair In check_inode_recs(), for repair mode we always reset @ret to 0. It makes no sense and later we check @ret to determine if the repair is successful. Fix it by removing the offending overwrite. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Gu Jinxiang <gujx@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check/original: Avoid infinite loop when failed to repair inodeQu Wenruo2018-08-06
| | | | | | | | | | | | | | | | | Exposed by fuzz-tests/003-multi-check-unmounted/ on fuzzed image bko-161811.raw.xz. It's caused by the fact when check_fs_roots() finds tree root is modified, it re-search tree root by goto again: label. However again: label. will also reset root objectid to 0. If we failed to repair one fs root but still modified tree root, we will go into such infinite loop. Fix it by recording which root we should skip for repair mode. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Gu Jinxiang <gujx@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: Remove the ability to rebuild root overwriting existing ↵Qu Wenruo2018-08-06
| | | | | | | | | | | | | | | | | | tree blocks We have function btrfs_fsck_reinit_root() to reinit csum or extent tree. However this function allows us to let it overwrite existing tree blocks using @overwrite parameter. Such behavior is pretty dangerous while no caller is using this feature explicitly. So just remove @overwrite parameter and allow btrfs_fsck_reinit_root() to error out when it fails to allocate tree block. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Gu Jinxiang <gujx@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: enhanced progress indicatorStéphane Lesimple2018-08-06
| | | | | | | | | | | | | | | | | | | | | | | | We reuse the task_position enum and task_ctx struct of the original progress indicator, adding more values and fields for our needs. Then add hooks in all steps of the check to properly record progress. Here's how the output looks like on a 22 Tb 5-disk RAID1 FS: Opening filesystem to check... Checking filesystem on /dev/mapper/luks-ST10000VN0004-XXXXXXXX UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx [1/7] checking extents (0:20:21 elapsed, 950958 items checked) [2/7] checking root items (0:01:29 elapsed, 15121 items checked) [3/7] checking free space cache (0:00:11 elapsed, 4928 items checked) [4/7] checking fs roots (0:51:31 elapsed, 600892 items checked) [5/7] checking csums (0:14:35 elapsed, 754522 items checked) [6/7] checking root refs (0:00:00 elapsed, 232 items checked) [7/7] checking quota groups skipped (not enabled on this FS) found 5286458060800 bytes used, no error found Signed-off-by: Stéphane Lesimple <stephane_btrfs@lesimple.fr> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: orig: Don't panic when unexpected root item is referring ↵Qu Wenruo2018-08-06
| | | | | | | | | | | | | to one extent With crafted image, expected root item can refer to certain extent, and original mode uses BUG_ON() to handle such case. Fix it by gracefully return error. Link: https://bugzilla.kernel.org/show_bug.cgi?id=200403 Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: Drop trans/root arguments from free_extent_hookNikolay Borisov2018-08-06
| | | | | | | | | | They are not really needed, what free_extent_hook wants is really a pointer to fs_info so give it to it directly. This is in preparation of delayed refs code. 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: check: add experimental flag for lowmem modeDavid Disseldorp2018-08-06
| | | | | | | | | | | The experimental flag is already carried in the manpage, but was removed from the btrfs check usage message as part of refactoring via 87c1bd13c1fca430c3dbf0da62e9aa33bde609c8. Add it back. Signed-off-by: David Disseldorp <ddiss@suse.de> Reviewed-by: Nikolay Borisov <nborisov@suse.com> Reviewed-by: Su Yue <suy.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check/original: Detect and repair wrong inline ram_bytesQu Wenruo2018-08-06
| | | | | | | | | | | | | It looks like that around 2014, btrfs kernel has a regression that would cause offset-by-one ram_bytes for inline extent. Add the ability to repair it in original mode. Reported-by: Steve Leung <sjleung@shaw.ca> Tested-by: Steve Leung <sjleung@shaw.ca> 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: 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: check: factor out root parsing from check_chunks_and_extentsNikolay Borisov2018-08-06
| | | | | | | | | | | | | | | | | check_chunks_and_extents does quite a number of distinct things. The first of those is going through all root items in the root tree and classify every root depending on whether they have a dropping operation in progress or not. Lets factor out this code and move the variables specific to this in a separate function so clean up check_chunks_and_extents a bit. Accidentally, this patch fixes some reference leaks since in error conditions in the loop the code does "goto out" but at that label we don't really release the path. Having this code extracted in a separate function which always releases the path avoids this problem entirely. Signed-off-by: Nikolay Borisov <nborisov@suse.com> Reviewed-by: Su Yue <suy.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: Fix wrong root parameter of btrfs_next_leaf callNikolay Borisov2018-08-06
| | | | | | | | | | | | | | | | | | The first thing that check_chunks_and_extents does is to iterate all the root items in the root tree and link them to either the "normal_list" or "dropping_trees" list. If a leaf has to be crossed during this operation btrfs_next_leaf is called to do that. However, currently it's called with a wrong argument for its 'root' parameter. Since we are iterating the root tree the passed root should be fs_info->tree_rot, whereas right now we are passing the local variable 'root' which is assigned to the fs_tree. As it stands, this bug is actually benign since the passed root is only passed to reada_for_search, where it's used to reference the fs_info. Nevertheless the code is wrong and at the very least misleading, so fix it by passing the correct root. Signed-off-by: Nikolay Borisov <nborisov@suse.com> Reviewed-by: Su Yue <suy.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: check symlinks with append/immutable flagsSu Yue2018-06-07
| | | | | | | | | | | | | | | Define new macro I_ERR_ODD_INODE_FLAGS to represents odd inode flags. Symlinks should never have append/immutable flags. While processing inodes, if found a symlink with append/immutable flags, mark the inode record with I_ERR_ODD_INODE_FLAGS. This is for original mode. Issue: #133 Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com> Reviewed-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Change btrfs_root to btrfs_fs_info argument in ↵Nikolay Borisov2018-06-07
| | | | | | | | | | | btrfs_lookup_extent_info That function really wants an fs_info and not a root. Accidentally, this also makes the kernel/user space signatures to be coherent. Signed-off-by: Nikolay Borisov <nborisov@suse.com> Reviewed-by: Su Yue <suy.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: Remove unused root argument from btrfs_extent_post_opNikolay Borisov2018-06-07
| | | | | | | | This is no longer used by the callees of that function so remove it. Signed-off-by: Nikolay Borisov <nborisov@suse.com> Reviewed-by: Su Yue <suy.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: Remove root parameter from btrfs_fix_block_accountingNikolay Borisov2018-06-07
| | | | | | | | | | It's always set to extent_root and the function already takes a transaction handle where fs_info could be referenced and in turn the extent_tree. Signed-off-by: Nikolay Borisov <nborisov@suse.com> Reviewed-by: Su Yue <suy.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: Remove root argument from delete_extent_recordsNikolay Borisov2018-06-07
| | | | | | | | | | | | | This function is always passed the extent_root as "root" parameter. In turn it uses the root parameter to mostly access fs_info and performs only a single call to btrfs_update_block_group where it passses the passed root. This is all redundant since fs_info can be referenced from the transaction handle and in turn extent_root can be referenced from the fs_info. So do that to simplify the function's signature. Signed-off-by: Nikolay Borisov <nborisov@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: check: Make btrfs check return error for qgroup mismatchQu Wenruo2018-06-07
| | | | | | | | | | | | | | | Current btrfs-check will check qgroup consistency, but even when it finds something wrong, the return value is still 0. Fix it by allowing report_qgroups() to return int to indicate qgroup mismatch, and also add extra logic to return no error if qgroup repair is successful. Without this patch, fstests can't detect qgroup corruption by its fsck alone. Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Remove devid parameter from btrfs_rmap_blockNikolay Borisov2018-06-07
| | | | | | | | | This parameter was introduced with the original implementation of the function but has never really been used, so just remove it. 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: check: lowmem: exclude extents if init-extent-tree in lowmemSu Yue2018-06-07
| | | | | | | | | | | | | If options '--init-extent-tree' and '--mode=lowmem' are both input, all metadata blocks will be traversed twice. First one is done by pin_metadata_blocks() in reinit_extent_tree(). Second one is in check_chunks_and_extents_v2(). Excluding instead of pinning metadata blocks before reinitializing th extent tree in lowmem can save some time. Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: move pin_down_tree_blocks to mode-common.cSu Yue2018-06-07
| | | | | | | | | Move pin_down_tree_blocks from main.c to mode-common.c for further patches. And export pin_metadata_blocks to mode-common.h. Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: Distinguish csum checking output for --check-data-csumQu Wenruo2018-06-07
| | | | | | | | | | | No matter --check-data-csum is passed or not, btrfs check will always output message like "checking csum". This message could be a little confusing, change it according to --check-data-csum option. Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: Continue check even if csum error is foundQu Wenruo2018-06-07
| | | | | | | | Since data csum mismatch is not a fatal error compared to fs/extent trees, continue check. Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: Fix data csum check return valueQu Wenruo2018-06-07
| | | | | | | | | | When --check-data-csum option found csum mismatch, btrfs check still return 0. Fix it so log-replay could automatically pause when it finds csum error. Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: Check data csum for all copiesQu Wenruo2018-06-07
| | | | | | | | | | | Original --check-data-csum option will skip the extra copy if the first copy matches csum. Since offline scrub (with recoverability report) is still out-of-tree, at least enhance --check-data-csum option to handle multiple copies. Signed-off-by: Qu Wenruo <wqu@suse.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: check: Skip data csum verification for metadata dumpQu Wenruo2018-04-24
| | | | | | | | | | | | For metadata dump (fs restored by btrfs-image), no data is restored and check sum verification will definitely report error. Add such check in check_csums() and prompt for user input. Issue: #103 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: check/original: Remove unused variable first_keyQu Wenruo2018-03-30
| | | | | | | | | | | | | | This @first_key variable is introduced in f5c4c4f3b75b ("btrfsck: add code to rebuild extent records"), however it's not only unused, but also used incorrectly. It's calling btrfs_item_key_to_cpu() on an node extent buffer. Anyway, just remove it. Fixes: f5c4c4f3b75b ("btrfsck: add code to rebuild extent records") Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: original mode: Check inline extent sizeQu Wenruo2018-03-30
| | | | | | | | | | | | | | | For inline compressed file extent, kernel doesn't allow inline extent ram size larger than sector size and on-disk inline extent size should not exceed BTRFS_MAX_INLINE_DATA_SIZE(). For inline uncompressed file extent, kernel doesn't allow inline extent ram and on-disk size larger than either BTRFS_MAX_INLINE_DATA_SIZE() or sector size. Check it in original mode. Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* Btrfs-progs: check, fix false error reports for shared prealloc extentsFilipe Manana2018-03-30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Under some cases the filesystem checker reports an error when it finds checksum items for an extent that is referenced by an inode as a prealloc extent. Such cases are not an error when the extent is actually shared (was cloned/reflinked) with other inodes and was written through one of those other inodes. Example: $ mkfs.btrfs -f /dev/sdb $ mount /dev/sdb /mnt $ touch /mnt/foo $ xfs_io -c "falloc 0 256K" /mnt/foo $ sync $ xfs_io -c "pwrite -S 0xab 0 256K" /mnt/foo $ touch /mnt/bar $ xfs_io -c "reflink /mnt/foo 0 0 256K" /mnt/bar $ xfs_io -c "fsync" /mnt/bar <power fail> $ mount /dev/sdb /mnt $ umount /mnt $ btrfs check /dev/sdc Checking filesystem on /dev/sdb UUID: 52d3006e-ee3b-40eb-aa21-e56253a03d39 checking extents checking free space cache checking fs roots root 5 inode 257 errors 800, odd csum item ERROR: errors found in fs roots found 688128 bytes used, error(s) found total csum bytes: 256 total tree bytes: 163840 total fs tree bytes: 65536 total extent tree bytes: 16384 btree space waste bytes: 138819 file data blocks allocated: 10747904 referenced 10747904 $ echo $? 1 So teach check to not report such cases as errors by checking if the extent is shared with other inodes and if so, consider it an error the existence of checksum items only if all those other inodes are referencing the extent as a prealloc extent. This case can be hit often when running the generic/475 testcase from fstests. A test case will follow in a separate patch. Signed-off-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: free-space-cache: Enhance free space cache free space checkQu Wenruo2018-03-30
| | | | | | | | | | | | | | | | | | | | | | | When we found free space difference between free space cache and block group item, we just discard this free space cache. Normally such difference is caused by btrfs_reserve_extent() called by delalloc which is out of a transaction. And since all btrfs_release_extent() is called with a transaction, under heavy race free space cache can have less free space than block group item. Normally kernel will detect such difference and just discard that cache. However we must be more careful if free space cache has more free space cache, and if that happens, paried with above race one invalid free space cache can be loaded into kernel. So if we find any free space cache who has more free space then block group item, we report it as an error other than ignoring it. Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Move chunk stripe size calculation function to volumes.hQu Wenruo2018-03-06
| | | | | Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: btrfs-progs: Fix read beyond boundary bug in ↵Qu Wenruo2018-02-14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | build_roots_info_cache() This bug is exposed by fsck-test with D=asan, hit by test case 020, with the following error report: ================================================================= ==10740==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x621000061580 at pc 0x56051f0db6cd bp 0x7ffe170f3e20 sp 0x7ffe170f3e10 READ of size 1 at 0x621000061580 thread T0 #0 0x56051f0db6cc in btrfs_extent_inline_ref_type /home/adam/btrfs/btrfs-progs/ctree.h:1727 #1 0x56051f13b669 in build_roots_info_cache /home/adam/btrfs/btrfs-progs/cmds-check.c:14306 #2 0x56051f13c86a in repair_root_items /home/adam/btrfs/btrfs-progs/cmds-check.c:14450 #3 0x56051f13ea89 in cmd_check /home/adam/btrfs/btrfs-progs/cmds-check.c:14965 #4 0x56051efe75bb in main /home/adam/btrfs/btrfs-progs/btrfs.c:302 #5 0x7f04ddbb0f49 in __libc_start_main (/usr/lib/libc.so.6+0x20f49) #6 0x56051efe68c9 in _start (/home/adam/btrfs/btrfs-progs/btrfs+0x5b8c9) 0x621000061580 is located 0 bytes to the right of 4224-byte region [0x621000060500,0x621000061580) allocated by thread T0 here: #0 0x7f04ded50ce1 in __interceptor_calloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:70 #1 0x56051f04685e in __alloc_extent_buffer /home/adam/btrfs/btrfs-progs/extent_io.c:553 #2 0x56051f047563 in alloc_extent_buffer /home/adam/btrfs/btrfs-progs/extent_io.c:687 #3 0x56051efff1d1 in btrfs_find_create_tree_block /home/adam/btrfs/btrfs-progs/disk-io.c:187 #4 0x56051f000133 in read_tree_block /home/adam/btrfs/btrfs-progs/disk-io.c:327 #5 0x56051efeddb8 in read_node_slot /home/adam/btrfs/btrfs-progs/ctree.c:652 #6 0x56051effb0d9 in btrfs_next_leaf /home/adam/btrfs/btrfs-progs/ctree.c:2853 #7 0x56051f13b343 in build_roots_info_cache /home/adam/btrfs/btrfs-progs/cmds-check.c:14267 #8 0x56051f13c86a in repair_root_items /home/adam/btrfs/btrfs-progs/cmds-check.c:14450 #9 0x56051f13ea89 in cmd_check /home/adam/btrfs/btrfs-progs/cmds-check.c:14965 #10 0x56051efe75bb in main /home/adam/btrfs/btrfs-progs/btrfs.c:302 #11 0x7f04ddbb0f49 in __libc_start_main (/usr/lib/libc.so.6+0x20f49) It's completely possible that one extent/metadata item has no inline reference, while build_roots_info_cache() doesn't have such check. Fix it by checking @iref against item end to avoid such problem. Issue: #92 Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: rename files after moving codeDavid Sterba2018-02-02
| | | | | | Add prefixes to the files so it's clear they belong to the mode group. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: Cleanup all checkpatch error and warningQu Wenruo2018-02-02
| | | | | | | | | | | | | | | | | | | | | Since we're moving tons of code, it's a good idea to fix all errors and warnings from checkpatch. Note: we don't rely on checkpatch, take its warnings and errors as a hint and do not blindly fix anything that gets reported. The code follows some style that should be kept and is not in 100% with what checkpatch finds. Always apply your common sense and decide if the change makes sense or if it is really making the code better. Additional fixes from dsterba: - %Lu -> %llu - lowercase first word or messages Signed-off-by: Qu Wenruo <wqu@suse.com> [ added note ] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check/lowmem: Cleanup unnecessary _v2 suffixesQu Wenruo2018-02-02
| | | | | | | | | | | | | There used to be some functions with _v2 suffix to distinguish them from original mode that had similar functions. However now when the lowmem mode is moved to own check/lowmem.[ch], cleanup the _v2 suffixes, and for functions that really need to be distinguished from original mode (exported functions), change the _v2 suffix to _lowmem. Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: Move lowmem check code to its own check/lowmem.[ch]Qu Wenruo2018-02-02
| | | | | | | | | | | | | Since lowmem mode code is highly internally connected, it's pretty hard to move them piece by piece. In theory it's possible to move part of the functions and temporarily export them, but it will just cause extra temporarily modifications. So this patch moves the whole lowmem check part into its own check/lowmem.[ch]. Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: Move reset_cached_block_groups to check/common.cQu Wenruo2018-02-02
| | | | | | Reviewed-by: Su Yue <suy.fnst@cn.fujitsu.com> Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: Move check_child_node to check/common.cQu Wenruo2018-02-02
| | | | | | Reviewed-by: Su Yue <suy.fnst@cn.fujitsu.com> Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: move reada_walk_down to check/common.cQu Wenruo2018-02-02
| | | | | | | | Both original and lowmem modes share this function to do readahead. Reviewed-by: Su Yue <suy.fnst@cn.fujitsu.com> Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>