Commit Graph

219 Commits (72e2a08a5c6d5f12be273e286e3355496e4a2f08)

Author SHA1 Message Date
David Sterba 72e2a08a5c btrfs-progs: factor out repair mode
Signed-off-by: David Sterba <dsterba@suse.com>
2016-07-04 15:22:53 +02:00
Jeff Mahoney bbebe814c0 btrfs-progs: check: switch to iterating over the backref_tree
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>
2016-07-04 14:27:14 +02:00
Jeff Mahoney 31d8235410 btrfs-progs: check: supplement extent backref list with rbtree
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>
2016-07-04 14:24:40 +02:00
Jeff Mahoney 93014d2353 btrfs-progs: check: add helpers for converting between structures
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>
2016-07-04 14:22:17 +02:00
Mark Fasheh 183995781f btrfs-progs: free qgroup counts in btrfsck
Signed-off-by: Mark Fasheh <mfasheh@suse.de>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-17 17:16:44 +02:00
Nicholas D Steeves bd2cc320af btrfs-progs: typo review of strings and comments
Signed-off-by: Nicholas D Steeves <nsteeves@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-01 14:56:56 +02:00
Qu Wenruo e6de81e959 btrfs-progs: check: fix found bytes accounting error
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>
2016-05-11 15:53:06 +02:00
David Sterba 25b93eefe2 btrfs-progs: check: check stripe crossing against nodesize
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>
2016-05-11 15:50:31 +02:00
David Sterba b241a46c7c btrfs-progs: check: refactor add_extent_rec, reduce argument count
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>
2016-05-11 15:50:29 +02:00
David Sterba 5b1bbc8924 btrfs-progs: check: reduce size of extent_record
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>
2016-05-11 15:50:26 +02:00
David Sterba 427643f069 btrfs-progs: check: simplify assignments in add_extent_rec_nolookup
Signed-off-by: David Sterba <dsterba@suse.com>
2016-05-11 15:50:24 +02:00
David Sterba a087884799 btrfs-progs: check: pass a template to add_extent_rec_nolookup
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>
2016-05-11 15:50:21 +02:00
Qu Wenruo f172bd2b8d btrfs-progs: Fix return value bug of qgroups check
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>
2016-05-02 14:42:28 +02:00
David Sterba 5f8cd780b9 btrfs-progs: check: use add_extent_rec_nolookup after lookups
The lookup was duplicated, use the helper that does not do it.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-05-02 14:41:35 +02:00
David Sterba e1a5ecc206 btrfs-progs: check: refactor add_extent_rec, separate lookup
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>
2016-05-02 14:41:27 +02:00
David Sterba e83012d57e btrfs-progs: check: cleanup, move structure definitions to the beginning
Signed-off-by: David Sterba <dsterba@suse.com>
2016-05-02 14:41:07 +02:00
David Sterba 3be6e3e7c9 btrfs-progs: deprecate and stop using btrfs_level_size
Size of a b-tree node is always nodesize, regardless of the level.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-05-02 14:40:23 +02:00
David Sterba 2a796d84af btrfs-progs: replace leafsize with nodesize
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>
2016-05-02 14:40:18 +02:00
Qu Wenruo 12234d0202 btrfs-progs: fsck: Fix a false metadata extent warning
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>
2016-05-02 14:40:05 +02:00
David Sterba 378e12701a btrfs-progs: check: unify naming of long option values
We use GETOP_VAL_ .

Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-14 13:42:47 +01:00
David Sterba 28d924290e btrfs-progs: docs: update check options
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-14 13:42:47 +01:00
David Sterba d3257893d5 btrfs-progs: check: drop short option for --chunk-tree
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>
2016-03-14 13:42:47 +01:00
Lu Fengqi 05640939ea btrfs-progs: Add new option for specify chunk root bytenr
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>
2016-03-14 13:42:47 +01:00
David Sterba 358807cc33 btrfs-progs: unify argc min/max checking
We don't want to modify argc.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-14 13:42:47 +01:00
David Sterba 39e98213eb btrfs-porgs: check: rename variable to avoid shadowing
Reported by gcc -Wshadow .

Signed-off-by: David Sterba <dsterba@suse.com>
2016-01-12 15:02:56 +01:00
Omar Sandoval e4797df6a9 btrfs-progs: check the free space tree in btrfsck
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>
2016-01-12 15:02:54 +01:00
David Sterba ef45c6b9db btrfs-progs: handler memory allocation failure in add_extent_rec
Signed-off-by: David Sterba <dsterba@suse.com>
2016-01-12 15:02:51 +01:00
David Sterba 87296b5541 btrfs-progs: catch memory allocation failure from alloc_data_backref
Do the dumb BUG_ON now, the function needs more changes to handle all
errors.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-01-12 15:02:50 +01:00
David Sterba 62b4c169e4 btrfs-progs: catch memory allocation failure from alloc_tree_backref
Do the dumb BUG_ON now, the function needs more changes to handle all
errors.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-01-12 15:02:50 +01:00
David Sterba cb2b8b19c8 btrfs-progs: catch memory allocation failure in splice_shared_node
Do the dumb BUG_ON now, the function needs more changes to handle all
errors.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-01-12 15:02:50 +01:00
David Sterba b317ca97d3 btrfs-progs: handle errors in get_inode_backref and fail in the caller
Signed-off-by: David Sterba <dsterba@suse.com>
2016-01-12 15:01:09 +01:00
David Sterba f72a3f9f9f btrfs-progs: handle errors in get_root_backref and fail in the caller
Signed-off-by: David Sterba <dsterba@suse.com>
2016-01-12 15:01:08 +01:00
David Sterba 3823cc2771 btrfs-progs: return errors from get_root_rec, fail in callers
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>
2016-01-12 15:01:08 +01:00
David Sterba 6aff5d74bd btrfs-progs: handle errors in add_shared_node and fail in the caller
Signed-off-by: David Sterba <dsterba@suse.com>
2016-01-12 15:01:08 +01:00
David Sterba e0a28fa2fd btrfs-progs: return errors from clone_inode_rec, fail in callers
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>
2016-01-12 15:01:07 +01:00
David Sterba 441f88498d btrfs-progs: return errors from get_inode_rec, fail in callers
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>
2016-01-12 15:01:07 +01:00
Naohiro Aota 9709d754db btrfs-progs: check, properly reset nlink of multi-linked file
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>
2016-01-12 15:01:02 +01:00
Qu Wenruo b08a740d7b btrfs-progs: fsck: Fix a false alert where extent record has wrong metadata flag
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>
2015-11-26 15:15:38 +01:00
David Sterba e29ec82e4e btrfs-progs: don't print version info from embedded subcommands
The version is provided by 'btrfs --version'.

Signed-off-by: David Sterba <dsterba@suse.com>
2015-11-06 17:00:36 +01:00
Zhao Lei da34dbd149 btrfs-progs: Remove all btrfs_close_all_devices in sub-command
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>
2015-11-02 09:35:07 +01:00
Eryu Guan ae71f1cf53 btrfs-progs: remove identical branch in record_extent()
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>
2015-11-02 09:35:02 +01:00
Eryu Guan 529f5c5854 btrfs-progs: save and return error number correctly in check_chunks_and_extents
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>
2015-11-02 09:35:02 +01:00
David Sterba 9fe7900ef3 btrfs-progs: check: update help text
Add some missing options and add a high-level description.

Signed-off-by: David Sterba <dsterba@suse.com>
2015-10-21 14:29:26 +02:00
Silvio Fricke c47a831cd6 btrfs-progs: use calloc instead of malloc+memset
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>
2015-10-21 14:29:26 +02:00
Silvio Fricke 90b63ba242 btrfs-progs: check: add progress indicator
Signed-off-by: Silvio Fricke <silvio.fricke@gmail.com>
[minor updates]
Signed-off-by: David Sterba <dsterba@suse.com>
2015-10-21 14:29:26 +02:00
Qu Wenruo 58fbb78add btrfs-progs: fsck: Add check for extent and parent chunk type
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>
2015-10-19 11:48:24 +02:00
Silvio Fricke afe33bc29b btrfs-progs: check: fix memset range
Signed-off-by: Silvio Fricke <silvio.fricke@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-10-02 17:56:28 +02:00
David Sterba fe2657a707 btrfs-progs: cleanup, mark more functions static
Reported by sparse.

Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-14 23:45:53 +02:00
Tsutomu Itoh f32b82ba98 btrfs-progs: add newline to some error messages
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>
2015-08-31 19:25:13 +02:00
Zhao Lei ec1fc69d39 btrfs-progs: close all fs_devices before exit in some commands
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>
2015-08-31 19:25:13 +02:00