summaryrefslogtreecommitdiff
path: root/cmds-check.c
Commit message (Collapse)AuthorAge
* btrfs-progs: Fix return value bug of qgroups checkQu Wenruo2016-05-02
| | | | | | | | | | | Before this patch, although btrfsck will check qgroups if quota is enabled, it always return 0 even qgroup numbers are corrupted. Fix it by allowing return value from report_qgroups function (formally defined as print_qgroup_difference). Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: use add_extent_rec_nolookup after lookupsDavid Sterba2016-05-02
| | | | | | The lookup was duplicated, use the helper that does not do it. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: refactor add_extent_rec, separate lookupDavid Sterba2016-05-02
| | | | | | | Separate the part of add_extent_rec that comes after the lookup does not succeed, there are callers interested in just this. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: cleanup, move structure definitions to the beginningDavid Sterba2016-05-02
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: deprecate and stop using btrfs_level_sizeDavid Sterba2016-05-02
| | | | | | Size of a b-tree node is always nodesize, regardless of the level. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: replace leafsize with nodesizeDavid Sterba2016-05-02
| | | | | | | | Nodesize is used in kernel, the values are always equal. We have to keep leafsize in headers, similarly the tree setting functions still take and set leafsize, but it's effectively a no-op. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: fsck: Fix a false metadata extent warningQu Wenruo2016-05-02
| | | | | | | | | | | | | | | | | | At least 2 user from mail list reported btrfsck reported false alert of "bad metadata [XXXX,YYYY) crossing stripe boundary". While the reported number are all inside the same 64K boundary. After some check, all the false alert have the same bytenr feature, which can be divided by stripe size (64K). The result seems to be initial 'max_size' can be 0, causing 'start' + 'max_size' - 1, to cross the stripe boundary. Fix it by always update extent_record->cross_stripe when the extent_record is updated, to avoid temporary false alert to be reported. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: unify naming of long option valuesDavid Sterba2016-03-14
| | | | | | We use GETOP_VAL_ . Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: docs: update check optionsDavid Sterba2016-03-14
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: drop short option for --chunk-treeDavid Sterba2016-03-14
| | | | | | | The need to specify the chunk root is not that common, we will reserve the short option -c for later use. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Add new option for specify chunk root bytenrLu Fengqi2016-03-14
| | | | | | | | | | Add new btrfsck option, '--chunk-root', to specify chunk root bytenr. And allow open_ctree_fs_info() function accept chunk_root_bytenr to override the bytenr in superblock. This will be mainly used when chunk tree corruption. Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: unify argc min/max checkingDavid Sterba2016-03-14
| | | | | | We don't want to modify argc. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-porgs: check: rename variable to avoid shadowingDavid Sterba2016-01-12
| | | | | | Reported by gcc -Wshadow . Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check the free space tree in btrfsckOmar Sandoval2016-01-12
| | | | | | | | | | This reuses the existing code for checking the free space cache, we just need to load the free space tree. While we do that, we check a couple of invariants on the free space tree itself. This requires pulling in some code from the kernel to exclude the super stripes. Signed-off-by: Omar Sandoval <osandov@fb.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: handler memory allocation failure in add_extent_recDavid Sterba2016-01-12
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: catch memory allocation failure from alloc_data_backrefDavid Sterba2016-01-12
| | | | | | | Do the dumb BUG_ON now, the function needs more changes to handle all errors. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: catch memory allocation failure from alloc_tree_backrefDavid Sterba2016-01-12
| | | | | | | Do the dumb BUG_ON now, the function needs more changes to handle all errors. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: catch memory allocation failure in splice_shared_nodeDavid Sterba2016-01-12
| | | | | | | Do the dumb BUG_ON now, the function needs more changes to handle all errors. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: handle errors in get_inode_backref and fail in the callerDavid Sterba2016-01-12
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: handle errors in get_root_backref and fail in the callerDavid Sterba2016-01-12
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: return errors from get_root_rec, fail in callersDavid Sterba2016-01-12
| | | | | | | get_root_rec return value is enahanced, callers will just BUG_ON now and will be fixed one by one. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: handle errors in add_shared_node and fail in the callerDavid Sterba2016-01-12
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: return errors from clone_inode_rec, fail in callersDavid Sterba2016-01-12
| | | | | | | clone_inode_rec return value is enahanced, callers will just BUG_ON now and will be fixed one by one. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: return errors from get_inode_rec, fail in callersDavid Sterba2016-01-12
| | | | | | | get_inode_rec return value is enahanced, callers will just BUG_ON now and will be fixed one by one. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check, properly reset nlink of multi-linked fileNaohiro Aota2016-01-12
| | | | | | | | | | | | | | | | | | | | If a file is linked from more than one directory and only one of the links is corrupted, btrfs check dose not reset the nlink properly. Actually it can go into infinite loop to link the broken file into lost+found. This patch fix two part of the code. The first one delay the freeing valid (no error, found inode ref, directory index, and directory item) backrefs. Freeing valid backrefs earier prevent reset_nlink() to add back all valid links. The second fix is obvious: passing `ref_type' to btrfs_add_link() is just wrong. It should be `filetype' instead. The current code can break all valid file links. Signed-off-by: Naohiro Aota <naota@elisp.net> Reviewed-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: fsck: Fix a false alert where extent record has wrong metadata flagQu Wenruo2015-11-26
| | | | | | | | | | | | | | In process_extent_item(), it gives 'metadata' initial value 0, but for non-skinny-metadata case, metadata extent can't be judged just from key type and it forgot that case. This causes a lot of false alert in non-skinny-metadata filesystem. Fix it by set correct metadata value before calling add_extent_rec(). Reported-by: Christoph Anton Mitterer <calestyo@scientia.net> Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: don't print version info from embedded subcommandsDavid Sterba2015-11-06
| | | | | | The version is provided by 'btrfs --version'. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Remove all btrfs_close_all_devices in sub-commandZhao Lei2015-11-02
| | | | | | | | | Since we have btrfs_close_all_devices() in btrfs's main entrance, it is not necessary to call btrfs_close_all_devices() separately in each sub-command. Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: remove identical branch in record_extent()Eryu Guan2015-11-02
| | | | | | | | | The same code is executed when the condition "ret" is true or false, because the code in the if-then branch and after the if statement is identical. Signed-off-by: Eryu Guan <guaneryu@gmail.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: save and return error number correctly in check_chunks_and_extentsEryu Guan2015-11-02
| | | | | | | | The variable "err" is assigned to "ret" then "ret" gets overwritten by check_extent_refs() before "ret" can be used. Reported by Coverity. Signed-off-by: Eryu Guan <guaneryu@gmail.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: update help textDavid Sterba2015-10-21
| | | | | | Add some missing options and add a high-level description. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: use calloc instead of malloc+memsetSilvio Fricke2015-10-21
| | | | | | | | | | | | | | | | | | | | | | This patch is generated from a coccinelle semantic patch: identifier t; expression e; statement s; @@ -t = malloc(e); +t = calloc(1, e); ( if (!t) s | if (t == NULL) s | ) -memset(t, 0, e); Signed-off-by: Silvio Fricke <silvio.fricke@gmail.com> [squashed patches into one] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: add progress indicatorSilvio Fricke2015-10-21
| | | | | | Signed-off-by: Silvio Fricke <silvio.fricke@gmail.com> [minor updates] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: fsck: Add check for extent and parent chunk typeQu Wenruo2015-10-19
| | | | | | | | | | | | | | There is a bug in btrfs-convert in 4.1.2, even we don't allow mixed block group for converted image, btrfs-convert will still create image with data and metadata inside one chunk. And further more, the chunk type is still DATA or METADATA, not DATA|METADATA (not mixed). So add btrfsck check for it right now. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: fix memset rangeSilvio Fricke2015-10-02
| | | | | Signed-off-by: Silvio Fricke <silvio.fricke@gmail.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: cleanup, mark more functions staticDavid Sterba2015-09-14
| | | | | | Reported by sparse. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: add newline to some error messagesTsutomu Itoh2015-08-31
| | | | | | | | | Added a missing newline to some error messages. Also printf() was changed to fprintf(stderr) for error messages. Signed-off-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com> Reviewed-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: close all fs_devices before exit in some commandsZhao Lei2015-08-31
| | | | | | | | | | | | | | | | | | mkfs creates more than one fs_devices in fs_uuids. 1: one is for file system being created 2: others are created in test_dev_for_mkfs in order to check mount point test_dev_for_mkfs()-> ... -> btrfs_scan_one_device() Current code only closes 1, and this patch also closes in case 2. Similar problem exist in other tools, eg.:: cmd-check.c: the function is: cmd_check()->check_mounted()-> ... -> btrfs_scan_one_device() ... Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Add initialztion of rec->crossing_stripesZhao Lei2015-08-31
| | | | | | | | rec->crossing_stripes is not initialized in allocate place, and have possibility causing wrong report for normal tree block. Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: cleanup: remove unnecessary check before btrfs_free_path is calledTsutomu Itoh2015-08-31
| | | | | | | | We need not check path before btrfs_free_path() is called because path is checked in btrfs_free_path(). Signed-off-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: fsck: fix a infinite loop on discount file extent repairQu Wenruo2015-08-31
| | | | | | | | | | | | | | | For a special case, discount file extent repair function will cause infinite loop. The case is, if the file loses all its extents, we won't have a hole to fill, causing repair function doing nothing. Since the I_ERR_DISCOUNT doesn't disappear, fsck will do an infinite loop. For such case, just puch hole to fill the whole range to fix it. Reported-by: Robert Munteanu <robert.munteanu@gmail.com> Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: fsck: print correct file holeQu Wenruo2015-08-31
| | | | | | | | | If a file lost all its extents, fsck will unable to print out the hole. Add an extra check to print out the hole range. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: fsck: Check if a metadata tree block crossing stripe boundaryQu Wenruo2015-08-31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Kernel btrfs_map_block() function has a limitation that it can only map BTRFS_STRIPE_LEN size. That will cause scrub fails to scrub tree block which crosses strip boundary, causing BUG_ON(). Normally, it's OK as metadata is always in metadata chunk and BTRFS_STRIPE_LEN can always be divided by node/leaf size. So without mixed block group, tree block won't cross stripe boundary. But for mixed block group, especially for btrfs converted from ext4, it's almost sure one or more tree blocks are not aligned with node size and cross stripe boundary. Causing bug with kernel scrub. This patch will report the problem, although we don't have a good idea how to fix it in user space until we add the ability to relocate tree block in user space. Also, kernel code should also be checked for such tree block alloc problems. Reported-by: Chris Murphy <lists@colorremedies.com> Reported-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: fsck: Add repair function for I_ERR_FILE_WRONG_NBYTESQu Wenruo2015-07-03
| | | | | | | | | | | | | | | Some unknown kernel bug makes inode nbytes modification out of sync with file extent update. But it's quite easy to fix in btrfs-progs anyway. So just fix it by adding a new function repair_inode_nbytes by using the found_size in inode_record. Reported-by: Christian <cdysthe@gmail.com> Reported-by: Chris Murphy <lists@colorremedies.com> Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: export read_extent_data functionQu Wenruo2015-06-17
| | | | | | | Export it for later btrfs-map-logical cleanup. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: fsck: Fix a shallow copy which will leads to segfault.Qu Wenruo2015-05-14
| | | | | | | | | | | | | | | In copy_inode_rec(), a shallow copy happens on rec->holes rb_root. So for shared inode case, new rec->holes still points to old rb_root, and when the old inode record is freed, the new inode_rec->holes will points to garbage and cause segfault when we try to free new inode_rec->holes. Fix it by calling copy_file_extent_holes() to do deep copy. Reported-by: Eric Sandeen <sandeen@redhat.com> Reported-by: Filipe David Manana <fdmanana@gmail.com> Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: check: fix compile warnings in del_file_extent_holeDavid Sterba2015-04-24
| | | | | | | | | | | | make[1]: Nothing to be done for `all'. cmds-check.c: In function ‘del_file_extent_hole’: cmds-check.c:289:26: warning: ‘prev.start’ may be used uninitialized in this function cmds-check.c:289:26: warning: ‘prev.len’ may be used uninitialized in this function cmds-check.c:290:26: warning: ‘next.start’ may be used uninitialized in this function cmds-check.c:290:26: warning: ‘next.len’ may be used uninitialized in this function Reported-by: Anand Jain <Anand.Jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: getopt, use symbolic name for argument requirementsDavid Sterba2015-04-08
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: cleanup option index argument from getopt_longDavid Sterba2015-04-08
| | | | | | | We're not using it anywhere. The best practice is to add enums with values > 255 for the long options, option index counting is error prone. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Make csum tree rebuild works with extent tree rebuild.Qu Wenruo2015-02-27
| | | | | | | | | | | | | | | | Before this patch, csum tree rebuild will not work with extent tree rebuild, since extent tree rebuild will only build up basic block groups, but csum tree rebuild needs data extents to rebuild. So if one use btrfsck with --init-csum-tree and --init-extent-tree, csum tree will be empty and tons of "missing csum" error will be outputted. This patch allows csum tree rebuild get its data from fs/subvol trees using regular file extents (which is also the only one using csum tree currently). Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> [renamed to fill_csum_tree_from_one_fs_root] Signed-off-by: David Sterba <dsterba@suse.cz>