summaryrefslogtreecommitdiff
path: root/cmds-check.c
Commit message (Collapse)AuthorAge
* btrfs-progs: check: write corrected qgroup info to diskMark Fasheh2016-07-13
| | | | | | | | | | | | | | | | Now that we can verify all qgroups, we can write the corrected qgroups out to disk when '--repair' is specified. The qgroup status item is also updated to clear any out-of-date state. The repair_ functions were modeled after the inode repair code in cmds-check.c. I also renamed the 'scan' member of qgroup_status_item to 'rescan' in order to keep consistency with the kernel. Testing this was easy, I just reproduced qgroup inconsistencies via the usual routes and had btrfsck fix them. Signed-off-by: Mark Fasheh <mfasheh@suse.de> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: factor out repair modeDavid Sterba2016-07-04
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: switch to iterating over the backref_treeJeff Mahoney2016-07-04
| | | | | | | | | | We now have two data structures that can be used to iterate the same data set, and there may be quite a few of them in memory. Eliminating the list_head member will reduce memory consumption while iterating over the extent backrefs. Signed-off-by: Jeff Mahoney <jeffm@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: supplement extent backref list with rbtreeJeff Mahoney2016-07-04
| | | | | | | | | | | | | | For the pathlogical case, like xfstests generic/297 that creates a large file consisting of one, repeating reflinked extent, fsck can take hours. The root cause is that calling find_data_backref while iterating the extent records is an O(n^2) algorithm. For my example test run, n was 2*2^20 and fsck was at 8 hours and counting. This patch supplements the list with an rbtree and drops the runtime of that testcase to about 20 seconds. Signed-off-by: Jeff Mahoney <jeffm@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: add helpers for converting between structuresJeff Mahoney2016-07-04
| | | | | | | | | We either open code list_entry calls or outright cast between types. The compiler will do the right thing if we use static inlines to do typesafe conversions. Signed-off-by: Jeff Mahoney <jeffm@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: free qgroup counts in btrfsckMark Fasheh2016-06-17
| | | | | Signed-off-by: Mark Fasheh <mfasheh@suse.de> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: typo review of strings and commentsNicholas D Steeves2016-06-01
| | | | | Signed-off-by: Nicholas D Steeves <nsteeves@gmail.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: fix found bytes accounting errorQu Wenruo2016-05-11
| | | | | | | | | | | | In the new add_extent_rec_nolookup() function, we add bytes_used to update found bytes accounting. However there is a typo that we used tmpl->nr, which should be rec->nr. This will make us to add 1 for data backref, instead the correct size. Reported-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com> Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: check stripe crossing against nodesizeDavid Sterba2016-05-11
| | | | | | | | The extent record's max_size might be 0 and the stripe crossing check will report a false positive, should use the filesyste nodesize. There's a global fs_info available. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: refactor add_extent_rec, reduce argument countDavid Sterba2016-05-11
| | | | | | | | Similar to add_extent_rec_nolookup, pass the arguments via a temporary structure. In case the extent is found, some of the values are not assigned directly so the semantics is preserved. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: reduce size of extent_recordDavid Sterba2016-05-11
| | | | | | | There are just 3 values of flag_block_full_backref, we can utilize a bitfield and save 8 bytes (192 now). Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: simplify assignments in add_extent_rec_nolookupDavid Sterba2016-05-11
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: pass a template to add_extent_rec_nolookupDavid Sterba2016-05-11
| | | | | | | | Reduce number of parameters that just fill the extent_record from a temporary template that's supposed to be zeroed and filled by the callers. Signed-off-by: David Sterba <dsterba@suse.com>
* 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>