summaryrefslogtreecommitdiff
path: root/check
Commit message (Collapse)AuthorAge
* 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/lowmem mode: Check inline extent sizeQu Wenruo2018-03-30
| | | | | 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: check: lowmem: Fix false alert about orphan inodeQu Wenruo2018-03-30
| | | | | | | | | | | | | | | | | | | | Btrfs can delay inode deletion and in that case btrfs will unlink the victim inode from its parent dir, and insert a marker to info btrfs to delete it later. In that case, such victim inode will have nlinks == 0, but is still completely valid. Original mode won't report such problem, but lowmem mode doesn't check the ORPHAN_ITEM key for such inode, and can report false alert like: ------ ERROR: root 257 INODE[28891726] is orphan item ------ Fix such false alert by checking orphan item for inode whose nlink is 0. 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/lowmem: Fix false alert of data extent backref lost for ↵Lu Fengqi2018-03-30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | snapshot Btrfs lowmem check reports the following false alert: ------ ERROR: file extent[267 2162688] root 256 owner 5 backref lost ------ The file extent is in the leaf which is shared by file tree 256 and fs tree. ------ leaf 30605312 items 46 free space 4353 generation 7 owner 5 ...... item 45 key (267 EXTENT_DATA 2162688) itemoff 5503 itemsize 53 generation 7 type 2 (prealloc) prealloc data disk byte 13631488 nr 65536 prealloc data offset 32768 nr 32768 ------ And there is the corresponding extent_data_ref item in the extent tree. ------ item 1 key (13631488 EXTENT_DATA_REF 1007496934287921081) itemoff 15274 itemsize 28 extent data backref root 5 objectid 267 offset 2129920 count 1 ------ The offset of EXTENT_DATA_REF which is the hash of the owner root objectid, the inode number and the calculated offset (file offset - extent offset). What caused the false alert is the code mix up the owner root objectid and the file tree objectid. Fixes: b0d360b541f0 ("btrfs-progs: check: introduce function to check data backref in extent tree") Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com> Reviewed-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check/lowmem: Fix the incorrect error message of ↵Lu Fengqi2018-03-30
| | | | | | | | | | | | | check_extent_data_item Instead of the disk_bytenr and disk_num_bytes of the extent_item which the file extent references, we should output the objectid and offset of the file extent. And the leaf may be shared by the file trees, we should print the objectid of the root and the owner of the leaf. Fixes: b0d360b541f0 ("btrfs-progs: check: introduce function to check data backref in extent tree") Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.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>
* btrfs-progs: check: Move check_dev_size_alignment 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 link_inode_to_lostfound function to 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 __create_inode_item function to check/common.cQu Wenruo2018-02-02
| | | | | | | | | Move __create_inode_item() function to check/common.c and rename it to insert_inode_item(), with comment added. 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 count_csum_range function to check/common.cQu Wenruo2018-02-02
| | | | | | | | | | | | Despite of moving it to check/common.c, also: 1) Add extra comment of the function 2) Change @root parameter to @fs_info Since @root is never used, csum_root is picked from fs_info anyway. 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 fs_root_objectid function to check/common.hQu Wenruo2018-02-02
| | | | | | | | Just another small wrapper shared between original and lowmem mode. 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 imode_to_type function to check/common.hQu Wenruo2018-02-02
| | | | | | | | | This function is shared between original and lowmem mode, and it's small enough, so move it to check/common.h. 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: Export check global variables to check/common.hQu Wenruo2018-02-02
| | | | | | | | | | | | | | | | There are a dozen of variables which are used as "check global" variables, like @total_csum_bytes or @no_holes. These variables are used freely across the check code, however since we're splitting check code, they need to be exported so they can be used in other files. This patch just export them and add declarations for them in check/common.h. 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 node_refs structure to check/common.hQu 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 definitions of lowmem mode to check/lowmem.hQu Wenruo2018-02-02
| | | | | | | | | Unlike original mode, lowmem mode mostly uses normal tree operations, so no structure definitions, only a lot of random error bits. 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 original mode definitions to check/original.hQu 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: Move cmds-check.c to check/main.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>