summaryrefslogtreecommitdiff
path: root/check
Commit message (Collapse)AuthorAge
* 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/lowmem: Repair wrong inline ram_bytes for uncompressed extentQu Wenruo2018-08-06
| | | | | | | | Similar to the original mode repair. Reported-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/lowmem: Prepare check_file_extent() to handle repairQu Wenruo2018-08-06
| | | | | | | | | | | | | Current check_file_extent() doesn't support later repair work, since it doesn't accept btrfs_path structure as parameter, thus it can't modify btrfs trees, or later check will still use the old and wrong path. Use btrfs_path to replace btrfs_key, extent_buffer and slot parameters, so we can modify @path directly for repair, and reduce the number of parameters for check_file_extent(). Signed-off-by: Qu Wenruo <wqu@suse.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: Initialize all filed of btrfs_inode_item in ↵Misono Tomohiro2018-06-07
| | | | | | | | | | insert_inode_item() Initialize all filed of btrfs_inode_item to zero in order to prevent having some garbage, especially for flags field. Signed-off-by: Misono Tomohiro <misono.tomohiro@jp.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: lowmem: check symlinks with append/immutable flagsSu Yue2018-06-07
| | | | | | | | | | | | | | | | Define new error bit INODE_FLAGS_ERROR to represents invalid inode flags error. Symlinks should never have append/immutable flags set. While checking inodes, if found a symlink with append/immutable flags, report and record the inode flags error. This is for lowmem 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: 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: Remove ext_ref local variable from check_fs_roots_lowmemNikolay Borisov2018-06-07
| | | | | | | | | All real consumers of that variable have inlined the checks since they are simple enough. So just 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: Drop ext_ref arument from check_fs_rootNikolay Borisov2018-06-07
| | | | | | | | It's no longer used so just 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: Drop ext_ref param from check_fs_first_inodeNikolay Borisov2018-06-07
| | | | | | | | It's no longer used in that function so can be dropped altogether. 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 ext_ref param from walk_down_treeNikolay Borisov2018-06-07
| | | | | | | | It's no longer used so just 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 ext_ref param from check_fs_first_inodeNikolay Borisov2018-06-07
| | | | | | | | It's no longer use and can be dropped. 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: Drop unused ext_ref parameter from process_one_leafNikolay Borisov2018-06-07
| | | | | | | | It's no longer used in the function so just 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: Drop ext_ref argument from check_inode_itemNikolay Borisov2018-06-07
| | | | | | | | | We can derive this argument from root->fs_info and also make it local to the sole switch case it's used. 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: Drop ext_ref param from check_dir_itemNikolay Borisov2018-06-07
| | | | | | | | This parameter is no longer used in this function, so drop 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: Drop ext_ref parameter from find_inode_refNikolay Borisov2018-06-07
| | | | | | | | | | This is a boolean parameter which signals whether the fs has the EXTENDED_IREF feature flag toggled or not. Since a reference to fs_info can be obtained there is no need to pollute the interface. 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 DIR_ITEM checking in lowmemNikolay Borisov2018-06-07
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When checking the validity of a DIR_ITEM item the index variable is explicitly set to -1 so that the index check in find_inode_ref() is ignored. This is necessary due to possible name collisions in DIR_ITEMS (i.e. multiple files with the same crc32c for their names, resulting in the identical key->offset). Currently the code is broken due to index being set to -1 at the beginning of check_dir_item and subsequently reset to the index found in find_inode_ref. On subsequent iterations of the while loop in check_dir_items we are going to erroneously perform index checking, since index is not -1 but whatever the index value of the last handled INODE_REF ITEM. Without this patch check in lowmem mode produces the following false warnings positivess: ERROR: root 5 INODE REF[1991456, 256] name 5ab4e28b~~~~~~~~QBXUT2GBJDRT5CB6ZWAJVDHK filetype 1 missing But the items for this name are in fact correct: ------------------SNIP------------------------ item 13 key (256 DIR_ITEM 4227063046) itemoff 2945 itemsize 140 location key (220890 INODE_ITEM 0) type FILE transid 2278 data_len 0 name_len 40 name: 5ab4e1bb~~~~~~~~65KNTAWVJ5VD4SV2R3BKFCXL location key (1991456 INODE_ITEM 0) type FILE transid 2285 data_len 0 name_len 40 name: 5ab4e28b~~~~~~~~QBXUT2GBJDRT5CB6ZWAJVDHK item 21 key (1991456 INODE_REF 256) itemoff 2104 itemsize 50 index 1934146 namelen 40 name: 5ab4e28b~~~~~~~~QBXUT2GBJDRT5CB6ZWAJVDHK -------------------SNIP------------------------- Fix this by moving the code setting index at the beginning of the while loop. This ensure that for each item in DIR_ITEM we have index set correctly. Fixes: 564901eac7a4 ("btrfs-progs: check: introduce print_dir_item_err()") Signed-off-by: Nikolay Borisov <nborisov@suse.com> Reviewed-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: end of removing parameters @trans in lowmemSu Yue2018-06-07
| | | | | | | | | Remove @trans in check_chunks_and_extents_lowmem(). After this patch, lowmem repair works again. Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: lowmem: introduce repair_block_accountingSu Yue2018-06-07
| | | | | | | | | | | | | | Introduce repair_block_accounting() which calls btrfs_fix_block_accounting() to repair block group accouting. Replace btrfs_fix_block_accounting() with the new function. Note: This patch and next patches cause error in lowmem repair like: "Error: Commit_root already set when starting transaction". Such error will disappear after removing @trans finished. Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: lowmem: remove parameter @trans of check_btrfs_rootSu Yue2018-06-07
| | | | | | | | | | | Remove parameters @trans of delete_extent_item() and walk_down_tree_v2(). Note: This patch and next patches cause error in lowmem repair like: "Error: Commit_root already set when starting transaction". Such error will disappear after removing @trans finished. Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: lowmem: remove parameter @trans of repair_tree_back_refSu Yue2018-06-07
| | | | | | | | | | | | | This patch removes parameter @trans of repair_tree_back_ref(). It calls try_avoid_extents_overwrite() and starts a transaction by itself. Note: This patch and next patches cause error in lowmem repair like: "Error: Commit_root already set when starting transaction". Such error will disappear after removing @trans finished. Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: lowmem: remove parameter @trans of check_leaf_itemsSu Yue2018-06-07
| | | | | | | | | | | This patch removes parameter @trans of check_leaf_items(). Note: This patch and next patches cause error in lowmem repair like: "Error: Commit_root already set when starting transaction". Such error will disappear after removing @trans finished. Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: lowmem: remove parameter @trans of repair_extent_itemSu Yue2018-06-07
| | | | | | | | | | | | | This patch removes parameter @trans of repair_extent_item(). It calls try_avoid_extents_overwrite() and starts a transaction by itself. Note: This patch and next patches cause error in lowmem repair like: "Error: Commit_root already set when starting transaction". Such error will disappear after removing @trans finished. Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: lowmem: remove parameter @trans of repair_chunk_itemSu Yue2018-06-07
| | | | | | | | | | | | | This patch removes parameter @trans of repair_chunk_item(). It calls try_avoid_extents_overwrite() and starts a transaction by itself. Note: This patch and next patches cause error in lowmem repair like: "Error: Commit_root already set when starting transaction". Such error will disappear after removing @trans finished. Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: lowmem: remove parameter @trans of delete_extent_itemSu Yue2018-06-07
| | | | | | | | | | | | | This patch removes the parameter @trans of delete_extent_item(). It calls try_avoid_extents_overwrite() and starts a transaction by itself. Note: This patch and next patches cause error in lowmem repair like: "Error: Commit_root already set when starting transaction". Such error will disappear after removing @trans finished. Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: lowmem: start to remove parameters @trans in lowmemSu Yue2018-06-07
| | | | | | | | | | | | | | | | Since extents can be avoided to be overwrittten by excluding or chunk allocation. It's not necessary to do all repairs in one transaction. This patch removes parameter @trans of repair_extent_data_item(). repair_extent_data_item() calls try_avoid_extents_overwrite() and starts a transaction by itself. Note: This patch and next patches cause error in lowmem repair like: "Error: Commit_root already set when starting transaction". Such error will disappear after removing @trans finished. Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.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: lowmem: introduce avoid_extents_overwriteSu Yue2018-06-07
| | | | | | | | | | | | | | Declare a global u64 variable last_allocated_chunk records start of the last chunk allocated by lowmem repair. Although global variable is not nice, it simplifies the code a lot. avoid_extents_overwrite() prefers to allocate a new chunk first. If it failed because of no space or wrong used bytes (like in fsck-tests/004), then it tries to exclude metadata blocks which costs a lot of time in large filesystems. Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: lowmem: introduce try_force_cow_in_new_chunkSu Yue2018-06-07
| | | | | | | | | | | | | | | | | | | | | Introduce create_chunk_and_block_block_group() to allocate a new chunk and corresponding block group. The new function force_cow_in_new_chunk() firstly allocates new chunk and records its start. Then it modifies all metadata block groups cached and full. Finally it marks the new block group uncached and unfree. In the next COW, extents states will be updated automatically by cache_block_group(). New function try_to_force_cow_in_new_chunk() will try to mark block groups full, allocate a new chunk and records the start. If the last allocated chunk is almost full, a new chunk will be allocated. Suggested-by: Qu Wenruo <wqu@suse.com> Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: lowmem: introduce mark/clear_block_groups_fullSu Yue2018-06-07
| | | | | | | | | | | | | | | | Excluding or pining all metadata blocks is time-inefficient for large filesystems. Here is another way to mark all metadata block groups full and allocate new chunks for COW. Then new reserved extents never overwrite extents. Introduce modify_block_groups_cache() to modify all blocks groups cache state and set all extents in block groups unfree in free space cache. mark/clear_block_groups_full() are wrappers of above function. Suggested-by: Qu Wenruo <wqu@suse.com> Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: lowmem: exclude extents of metadata blocksSu Yue2018-06-07
| | | | | | | | | | | | | | | | | | | | Commit d17d6663c99c ("btrfs-progs: lowmem check: Fix regression which screws up extent allocator") removes pin_metadata_blocks() from lowmem repair. So we have to find another way to exclude extents which should be occupied by existing tree blocks. Modify pin_down_tree_blocks() and rename it to traverse_tree_blocks for sharing code with new function exclude_metadata_blocks(). * exclude_metadata_blocks() traverses and marks extents of all tree blocks dirty in fs_info->excluded_extents. * cleanup_excluded_extents() is responsible for cleanup. Export them to mode-common.h since they will be used both in original and lowmem modes. 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: check: lowmem: assign parent early in repair_extent_data_itemSu Yue2018-06-07
| | | | | | | | | | | The variable @eb is assigned to leaf in fs_tree before insertion of backref. It will cause wrong parent of new inserted backref. Set @parent at beginning to fix the problem. Reviewed-by: Qu Wenruo <wqu@suse.com> Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: lowmem: record returned errors after walk_down_tree_v2Su Yue2018-06-07
| | | | | | | | | | | | | | | | | In lowmem mode with '--repair', check_chunks_and_extents_v2 will fix accounting in block groups and clear the error bit BG_ACCOUNTING_ERROR. However, return value of check_btrfs_root() doesn't contain error bits. If extent tree is on error, lowmem repair always prints error and returns nonzero value even the filesystem is fine after repair. Introduce FATAL_ERROR for lowmem mode to represent negative return values since negative and positive can't be mixed in the bit operations. Then let check_btrfs_root() return error bits. Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>