When I run sparse checking it gives the following error:
$ make C=1 V=1
gcc -MM -MG -MF cmds-fi-usage.o.d -MT cmds-fi-usage.o -MT \
cmds-fi-usage.static.o -MT cmds-fi-usage.o.d -g -O1 -Wall \
-D_FORTIFY_SOURCE=2 -include config.h -DBTRFS_FLAT_INCLUDES \
-D_XOPEN_SOURCE=700 -fno-strict-aliasing -fPIC cmds-fi-usage.c
[SP] ctree.c
sparse -g -O1 -Wall -D_FORTIFY_SOURCE=2 -include config.h \
-DBTRFS_FLAT_INCLUDES -D_XOPEN_SOURCE=700 -fno-strict-aliasing -fPIC \
-include -D__CHECKER__ -D__CHECK_ENDIAN__ -Wbitwise -Wuninitialized \
-Wshadow -Wundef -U_FORTIFY_SOURCE ctree.c
builtin:1:15: error: unable to open '-D__CHECKER__'
Makefile:177: recipe for target 'ctree.o' failed
make: *** [ctree.o] Error 1
It means '$(check_defs)' is passed to sparse as NULL and looks
'$(check_defs)'should be assigned before assigning '$(CHECKER_FLAGS)'.
BTW, I'm not familiar with make tool so there could be some my
misunderstanding and better solution.
Signed-off-by: Byongho Lee <bhlee.kernel@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Enhance chunk validation:
1) Num_stripes
We already have such check but it's only in super block sys chunk
array.
Now check all on-disk chunks.
2) Chunk logical
It should be aligned to sector size.
This behavior should be *DOUBLE CHECKED* for 64K sector size like
PPC64 or AArch64.
Maybe we can found some hidden bugs.
3) Chunk length
Same as chunk logical, should be aligned to sector size.
4) Stripe length
It should be power of 2.
5) Chunk type
Any bit out of TYPE_MAS | PROFILE_MASK is invalid.
With all these much restrict rules, several fuzzed image reported in
mail list should no longer cause btrfsck error.
Reported-by: Vegard Nossum <vegard.nossum@oracle.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
ftw_add_entry_size() assumes 4k as the block size of the underlying
filesystem and hence the file sizes computed is incorrect for non-4k
sectorsized filesystems. Fix this by rounding up file sizes to
sectorsize.
Signed-off-by: Chandan Rajendra <chandan@linux.vnet.ibm.com>
Signed-off-by: David Sterba <dsterba@suse.com>
We can do more with the balance usage filter. Enhance it so we can
specify also the minimum usage of the block groups to process. The
'usage' filter now accepts a range (a..b, can be partial) and needs
kernel support.
The 'usage=value' filter is equivalent to 'limit=..value' but works on
older kernels as well.
The min/max values are 32bit, unlike the single-value limit which is
64bit.
Signed-off-by: David Sterba <dsterba@suse.com>
Add the overlapping usage and [usage_min, usage_max] members to the
balance args. The min/max values are interpreted iff the corresponding
flag BTRFS_BALANCE_ARGS_USAGE_RANGE is set.
The minimum boundary is inclusive, maximum is exclusive:
* usage_min <= chunk_usage < usage_max
Signed-off-by: David Sterba <dsterba@suse.com>
Add new balance filter 'stripes=<range>' to process only chunks that are
spread accross given number of chunks.
The range minimum and maximum are inclusive.
Signed-off-by: Gabríel Arthúr Pétursson <gabriel@system.is>
[ reworked a bit to use the range helpers, dropped the single value
for stripes ]
Signed-off-by: David Sterba <dsterba@suse.com>
We can do more with the balance filter. Enhance it so we can specify
also the minimum number of block groups to process. The 'limit' filter
now accepts a range (a..b, can be partial) and needs kernel support.
The 'limit=value' filter is equivalent to 'limit=..value' but works on
older kernels as well.
The min/max values are 32bit, unlike the single-value limit which is
64bit.
Signed-off-by: David Sterba <dsterba@suse.com>
Add the overlapping limit and [limit_min, limit_max] members to the
balance args. The min/max values are interpreted iff the corresponding
flag BTRFS_BALANCE_ARGS_LIMIT_RANGE is set.
The minimum and maximum are inclusive.
Note that the values are only 32bit, but this should be enough for the
foreseeable future.
Signed-off-by: David Sterba <dsterba@suse.com>
This commit extends the leaf corruption test to try to repair a file
linked from multiple directory. It stresses a case that some links to a
file is broken but others kept valid.
Signed-off-by: Naohiro Aota <naota@elisp.net>
Signed-off-by: David Sterba <dsterba@suse.com>
Introduce 3 new members for btrfs_convert_context:
1) struct cache_tree used
Records accurate byte ranges which are used by old filesystem.
This will be used to create old filesystem image.
2) struct cache_tree data_chunks
Records batched ranges which must be covered by data chunks.
The bytenr range is optimized to meet all the chunk requirement.
3) u64 total_bytenr
Records how large the filesystem is in bytenr.
Yes, we can calculate it easy, but that's for old blocks based
filesystem.
This will make it more friendly for extent based filesystem.
And later cctx->block_counts and may be removed
And 2 for mkfs_config:
1) char *chunk_uuid.
Used as temporary chunk_uuid (unparsed) string for later
make_convert_btrfs()
2) u64 super_bytenr
Records the new temporary super bytenr after make_btrfs().
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This add_merge_cache_extent() function will try to merge adjusted
cache_extent.
This is used for later btrfs-convert ext2 free space cache.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
There are quite a lot search/lookup functions with different behavior,
add comments for them, as it will take extra time to view source to
understand the behavior difference.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
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-show-super has own implementation to read the sys array and it
lacks all the sanity checks.
Copy and adapt the improved implementation from btrfs_read_sys_array.
This will fix crashes on a fuzzed/corrupted images. It's duplicating
code but at the moment looks easier than refactoring and restructuring
btrfs_read_sys_array that now almost matches the kernel code, which we
want in the long term.
Signed-off-by: David Sterba <dsterba@suse.com>
We can handle the special case of num_stripes == 0 directly inside
btrfs_read_sys_array. The BUG_ON in btrfs_chunk_item_size is there to
catch other unhandled cases where we fail to validate external data,
like in btrfs-show-super.
Signed-off-by: David Sterba <dsterba@suse.com>
Port of kernel commit e3540eab29e1b2260bc4b9b3979a49a00e3e3af8
Verify that the sys_array has enough bytes to read the next item.
Signed-off-by: David Sterba <dsterba@suse.com>
Port of kernel commit 1ffb22cf8c322bbfea6b35fe23d025841b49fede
There's a pointer to buffer, integer offset and offset passed as
pointer, try to find matching names for them.
Signed-off-by: David Sterba <dsterba@suse.com>
There are some sanity checks missing on both sides, kernel/userspace.
Preparation to port the missing changes.
Sync code with parent of kernel commit
1ffb22cf8c322bbfea6b35fe23d025841b49fede ("btrfs: cleanup, rename a few
variables in btrfs_read_sys_array")
This effectively reverts progs commit
be96777126 ("btrfs-progs: Cleanup unneeded
extra variant in btrfs_read_sys_array") so we can apply more of the
kernel patches.
Signed-off-by: David Sterba <dsterba@suse.com>
The conversion to autotools changed the default prefix to /usr. There's
no reason to diverge. Distributions builds set prefix the /usr path and
local builds are supposed to go to /usr/local .
Reference: https://bugzilla.kernel.org/show_bug.cgi?id=108571
Reported-by: Karl Richter <krichter722@aol.de>
Signed-off-by: David Sterba <dsterba@suse.com>
Push out common convert operations into function pointers that we can
ultimately allow other file systems to use to provide their own
conversions.
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Catch a buggy condition fixed by "btrfs-progs: fsck: Fix a false alert
where extent record has wrong metadata flag"
Signed-off-by: David Sterba <dsterba@suse.com>
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>
* split copies to copies and parity and add a common header for all the
raid options
* add missing RAID1
* n/a were dropped
Based on feedback from Duncan <1i5t5.duncan@cox.net>.
Signed-off-by: David Sterba <dsterba@suse.com>
If sectorsize is not BTRFS_SUPER_INFO_SIZE (4k), the superblock checksum
is wrong and mkfs fails. This has been reported on ppc64 where we pick
sectorisize from page size (64k). This has been broken since ages
(2008) and discovered by the recently added superblock checks.
Reported-by: Dinar Valeev <dvaleev@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Create filesystem on a partitioned loop device, test for "btrfs-progs:
Fix partitioned loop devices resolving".
Signed-off-by: David Sterba <dsterba@suse.com>
The loop_info64::lo_file_name might not be null terminated. Avoid strlen
and trim the length to whatever size of the loop_info buffer.
Signed-off-by: David Sterba <dsterba@suse.com>
When using partitions on a loop device, the device's name can be
e.g. /dev/loop0p1 or similar, and no relevant entry exists in the /sys
filesystem, so the current resolve_loop_device function fails.
Instead of using string functions to extract the device name and reading
this file, this patch uses the loop device API through ioctl to get the
correct backing file.
Signed-off-by: Florian Margaine <florian@platform.sh>
[ changed checks of error values from open and ioctl ]
Signed-off-by: David Sterba <dsterba@suse.com>
Add support to search chunk root, as we only need to search tree roots
in system chunk, which should be very easy to add, just iterate in
system chunks.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
[ renamed to btrfs_next_bg_* ]
Signed-off-by: David Sterba <dsterba@suse.com>
1: Remove more_than_one variable, use iterators value instead
2: Remove "out" label, we use break instead.
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
[ changelog update ]
Signed-off-by: David Sterba <dsterba@suse.com>
Switch to common warning()/error() for cmds-device.c.
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
[ minor tweaks ]
Signed-off-by: David Sterba <dsterba@suse.com>
periodic.timer_fd's value is 0 on inititlize-failed case,
if no value-checking before read(), the code will run as
read(STDIN).
This patch fixed above case.
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
A test for "btrfs-progs: mkfs: increase buffer size in is_ssd". Create a
device with a long name through loop device wrapped to a device mapper
linear device, switch it to the "ssd" mode status.
Signed-off-by: David Sterba <dsterba@suse.com>
In current versions of util-linux the buffer passed to blkid_devno_to_wholedisk
has to be sufficiently large to not only hold the device name but the complete
target of the /sys/dev/block/<maj:min> symlink. This was changed only recently
in 4419ffb9eff5801fdbd385a4a6199b3877f802ad.
The small buffer size currently can lead to failure of is_ssd due to truncated
device names:
readlink("/sys/dev/block/254:7", "../../devices/virtual/block/dm-", 31) = 31
open("/sys/block/dm-/queue/rotational", O_RDONLY) = -1 ENOENT (No such file or directory)
Signed-off-by: Michael Lass <bevan@bi-co.net>
Signed-off-by: David Sterba <dsterba@suse.com>
Device deletion procedures ensures the device is a block device.
This patch introduces 'missing' as keyword again, correctly
passing it on to the kernel instead of complaining about
'missing' not being a block device.
Signed-off-by: Alexander Fougner <fougner89@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>