Commit Graph

3582 Commits (05734124f2cf616d94d7f2640351bc0272b1a8d0)
 

Author SHA1 Message Date
Qu Wenruo 05734124f2 btrfs-progs: Introduce wrapper to recover raid56 data
Introduce a wrapper to recover raid56 data.

The logical is the same with kernel one, but with different interfaces,
since kernel ones cares the performance while in btrfs we don't care
that much.

And the interface is more caller friendly inside btrfs-progs.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-07-03 13:35:11 +02:00
Qu Wenruo 008bbd8842 btrfs-progs: raid56: Allow raid6 to recover data and P
Copied from kernel lib/raid6/recov.c.

Minor modifications includes:
- Rename from raid6_datap_recov_intx() to raid5_recov_datap()
- Rename parameter from faila to dest1

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-07-03 13:35:11 +02:00
Qu Wenruo 9604ce49d6 btrfs-progs: raid56: Allow raid6 to recover 2 data stripes
Copied from kernel lib/raid6/recov.c raid6_2data_recov_intx1() function.
With the following modification:
- Rename to raid6_recov_data2() for shorter name
- s/kfree/free/g modification

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-07-03 13:35:11 +02:00
Qu Wenruo 084d152407 btrfs-progs: raid56: Introduce tables for RAID6 recovery
Use kernel RAID6 galois tables for later RAID6 recovery.

Galois tables file, kernel-lib/tables.c is generated by user space
program, mktable.

Galois field tables declaration, in kernel-lib/raid56.h, is completely
copied from kernel.

The mktables.c is copied from kernel with minor header/macro
modification, to ensure the generated tables.c works well in
btrfs-progs.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-07-03 13:35:11 +02:00
Qu Wenruo 5e2a2acc9a btrfs-progs: raid56: Introduce raid56 header for later recovery usage
Introduce a new header, kernel-lib/raid56.h, for later raid56 works.

It contains 2 functions, from original btrfs-progs code:
void raid6_gen_syndrome(int disks, size_t bytes, void **ptrs);
int raid5_gen_result(int nr_devs, size_t stripe_len, int dest, void **data);

Will be expanded later and some part of it(RAID6 recover part) may keep
sync with kernel later.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
[ unify gpl header, rename header macro ]
Signed-off-by: David Sterba <dsterba@suse.com>
2017-07-03 13:35:11 +02:00
Philipp Hahn 1618d8afb9 btrfs-progs: Fix slot >= nritems
Running "btrfsck --repair /dev/sdd2" crashed as it can happen in
(corrupted) file systems, that slot > nritems:
> (gdb) bt full
> #0  0x00007ffff7020e71 in __memmove_sse2_unaligned_erms () from /lib/x86_64-linux-gnu/libc.so.6
> #1  0x0000000000438764 in btrfs_del_ptr (trans=<optimized out>, root=0x6e4fe0, path=0x1d17880, level=0, slot=7)
>     at ctree.c:2611
>         parent = 0xcd96980
>         nritems = <optimized out>
>         __func__ = "btrfs_del_ptr"
> #2  0x0000000000421b15 in repair_btree (corrupt_blocks=<optimized out>, root=<optimized out>) at cmds-check.c:3539
>         key = {objectid = 77990592512, type = 168 '\250', offset = 16384}
>         trans = 0x8f48c0
>         path = 0x1d17880
>         level = 0
> #3  check_fs_root (wc=<optimized out>, root_cache=<optimized out>, root=<optimized out>) at cmds-check.c:3703
>         corrupt = 0x1d17880
>         corrupt_blocks = {root = {rb_node = 0x6e80c60}}
>         path = {nodes = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, slots = {0, 0, 0, 0, 0, 0, 0, 0}, locks = {0, 0,
>             0, 0, 0, 0, 0, 0}, reada = 0, lowest_level = 0, search_for_split = 0, skip_check_block = 0}
>         nrefs = {bytenr = {271663104, 271646720, 560021504, 0, 0, 0, 0, 0}, refs = {1, 1, 1, 0, 0, 0, 0, 0}}
>         wret = 215575372
>         root_node = {cache = {rb_node = {__rb_parent_color = 0, rb_right = 0x0, rb_left = 0x0}, objectid = 0,
>             start = 0, size = 0}, root_cache = {root = {rb_node = 0x0}}, inode_cache = {root = {
>               rb_node = 0x781c80}}, current = 0x819530, refs = 0}
>         status = 215575372
>         rec = 0x1
> #4  check_fs_roots (root_cache=0xcd96b6d, root=<optimized out>) at cmds-check.c:3809
>         path = {nodes = {0x6eed90, 0x6a2f40, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, slots = {18, 2, 0, 0, 0, 0, 0, 0},
>           locks = {0, 0, 0, 0, 0, 0, 0, 0}, reada = 0, lowest_level = 0, search_for_split = 0,
>           skip_check_block = 0}
>         key = {objectid = 323, type = 132 '\204', offset = 18446744073709551615}
>         wc = {shared = {root = {rb_node = 0x0}}, nodes = {0x0, 0x0, 0x7fffffffe428, 0x0, 0x0, 0x0, 0x0, 0x0},
>           active_node = 2, root_level = 2}
>         leaf = 0x6e4fe0
>         tmp_root = 0x6e4fe0
> #5  0x00000000004287c3 in cmd_check (argc=215575372, argv=0x1d17880) at cmds-check.c:11521
>         root_cache = {root = {rb_node = 0x98c2940}}
>         info = 0x6927b0
>         bytenr = 6891440
>         tree_root_bytenr = 0
>         uuidbuf = "f65ff1a1-76ef-456e-beb5-c6c3841e7534"
>         num = 215575372
>         readonly = 218080104
>         qgroups_repaired = 0
> #6  0x000000000040a41f in main (argc=3, argv=0x7fffffffebe8) at btrfs.c:243
>         cmd = 0x689868
>         bname = <optimized out>
>         ret = <optimized out>

in that case the count of remaining items (nritems - slot - 1) gets
negative. That is then casted to (unsigned long len), which leads to the
observed crash.

Change the tests before the move to handle only the non-corrupted case,
were slow < nritems.

This does not fix the corruption, but allows btrfsck to finish without
crashing.

Signed-off-by: Philipp Hahn <hahn@univention.de>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-07-03 13:35:11 +02:00
Qu Wenruo 9f6dec4dd5 btrfs-progs: Refactor read_node_slot function to get rid of btrfs_root
parameter

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
2017-07-03 13:35:11 +02:00
Qu Wenruo 8690c887d1 btrfs-progs: Refactor read_tree_block to get rid of btrfs_root
The only reasom read_tree_block() needs a btrfs_root parameter is to get
its node/sector size.

And long ago, I have already introduced a compactible interface,
read_tree_block_fs_info() to pass btrfs_fs_info instead of btrfs_root.

Since we have cleaned up all root->sector/node/stripesize users, we
should be OK to refactor read_tree_block() function.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
2017-07-03 13:35:11 +02:00
Qu Wenruo 060c7b3a1a btrfs-progs: Refactor btrfs_root paramters in btrfs-corrupt-block.c
Refactor the following functions and its callers to get rid of
incorrectly passed btrfs_root parameters:

1) corrupt_keys()
2) corrupt_metadata_block()

The only reason passing btrfs_root for them is to get block sizes.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
2017-07-03 13:35:11 +02:00
Qu Wenruo fa5fd68021 btrfs-progs: Remove block size members in btrfs_root
Finally, we can get rid of per tree block size members now.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
2017-07-03 13:35:11 +02:00
Qu Wenruo 7a30f5a01c btrfs-progs: Refactor sectorsize users in cmds-inspect-dump-tree.c
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
2017-07-03 13:35:11 +02:00
Qu Wenruo ec5a427fec btrfs-progs: Refactor sectorsize users in convert/source-ext2.c
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
2017-07-03 13:35:11 +02:00
Qu Wenruo df4ad82810 btrfs-progs: Refactor sectorsize users in convert/main.c
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
2017-07-03 13:35:10 +02:00
Qu Wenruo 2b50d3b82a btrfs-progs: Refactor sectorsize in convert/source-fs.c
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
2017-07-03 13:35:10 +02:00
Qu Wenruo caf9c18f66 btrfs-progs: Refactor sectorsize users in free-space-tree.c
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
2017-07-03 13:35:10 +02:00
Qu Wenruo aca37c7915 btrfs-progs: Refactor sectorsize users in volumes.c
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
2017-07-03 13:35:10 +02:00
Qu Wenruo a124232f5d btrfs-progs: Refactor sectorsize users in file.c
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
2017-07-03 13:35:10 +02:00
Qu Wenruo 4925e1bc11 btrfs-progs: Refactor sectorsize users in free-space-cache.c
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
2017-07-03 13:35:10 +02:00
Qu Wenruo db6a1d42b0 btrfs-progs: Refactor sectorsizes users in file-item.c
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
2017-07-03 13:35:10 +02:00
Qu Wenruo b0f14e9b3d btrfs-progs: Refactor sectorsize users in mkfs/main.c
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
2017-07-03 13:35:10 +02:00
Qu Wenruo b2615be24a btrfs-progs: Refactor nodesize users in cmds-inspect-tree-stats.c
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
2017-07-03 13:35:10 +02:00
Qu Wenruo 389a2e8095 btrfs-progs: Refactor nodesize users in qgroup-verify.c
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
2017-07-03 13:35:10 +02:00
Qu Wenruo 428e689b87 btrfs-progs: Refactor nodesize user in print-tree.c
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
2017-07-03 13:35:10 +02:00
Qu Wenruo 6418b4c79f btrfs-progs: Refactor block sizes users in extent-tree.c
And in the refactoring, also refactors a open-coded round_up().

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
2017-07-03 13:35:10 +02:00
Qu Wenruo bca69ec060 btrfs-progs: Refactor nodesize users in utils.c
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
2017-07-03 13:35:10 +02:00
Qu Wenruo da79b13898 btrfs-progs: Refactor nodesize user in btrfstune.c
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
2017-07-03 13:35:10 +02:00
Qu Wenruo 7354c698eb btrfs-progs: Refactor block sizes users in cmds-check.c
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
2017-07-03 13:35:10 +02:00
Qu Wenruo 3816fd1ee1 btrfs-progs: Refactor nodesize users in image/main.c
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
2017-07-03 13:35:10 +02:00
Qu Wenruo dea4badfe6 btrfs-progs: Refactor nodesize user in extent_io.c
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
2017-07-03 13:35:10 +02:00
Qu Wenruo fa48918bf0 btrfs-progs: Refactor block sizes users in cmds-restore.c
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
2017-07-03 13:35:10 +02:00
Qu Wenruo 155f4c217f btrfs-progs: Refactor block sizes users in backref.c
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
2017-07-03 13:35:10 +02:00
Qu Wenruo f73e2a3236 btrfs-progs: Refactor block sizes users in chunk-recover.c
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
2017-07-03 13:35:10 +02:00
Qu Wenruo 20d35007f8 btrfs-progs: Refactor block sizes users in btrfs-map-logical.c
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
2017-07-03 13:35:10 +02:00
Qu Wenruo 34bd207932 btrfs-progs: Refactor block sizes users in ctree.c and ctree.h
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
2017-07-03 13:35:10 +02:00
Qu Wenruo 3d5eadd633 btrfs-progs: Refactor block sizes users in btrfs-corrupt-block.c
Convert root->sectorsize/nodesize users in btrfs-corrupt-block.

This provides the basis to further refactor incorrect btrfs_root
parameter to btrfs_fs_info parameter.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
2017-07-03 13:35:10 +02:00
Qu Wenruo d2ed05c9ae btrfs-progs: Refactor block sizes users in disk-io.c
Since we have cached block sizes in fs_info, there is no need to specify
these sizes in btrfs_setup_root() function.

And refactor all root->sector/node/stripesize users in disk-io.c.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
2017-07-03 13:35:10 +02:00
Qu Wenruo c4893f15ce btrfs-progs: Introduce sectorsize nodesize and stripesize members for
btrfs_fs_info

Just like what we do in kernel, since we will not support different
leaf/node/stripe size per tree, there is no need to store these block
sizes in btrfs_root.

This patch will introduce these block size members into btrfs_fs_info
structure, allowing us to convert such usage in later patches.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
2017-07-03 13:35:10 +02:00
Qu Wenruo 3c7a04e592 btrfs-progs: Remove deprecated leafsize usage
Leafsize is deprecated for a long time, and kernel has already updated
ctree.h to rename sb->leafsize to sb->__unused_leafsize.

This patch will remove normal users of leafsize:
1) Remove leafsize member from btrfs_root structure
   Now only root->nodesize and root->sectorisze.
   No longer root->leafsize.

2) Remove @leafsize parameter from btrfs_setup_root() function
   Since no root->leafsize, no need for @leafsize parameter.

The remaining user of leafsize will be:
1) btrfs inspect-internal dump-super
   Reformat the "leafsize" output to "leafsize (deprecated)" and
   use le32_to_cpu() to do the cast manually.

2) mkfs
   We still need to set sb->__unused_leafsize to nodesize.
   Do the manual cast too.

3) convert
   Same as mkfs, these two superblock setup should be merged later

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
2017-07-03 13:35:10 +02:00
Qu Wenruo 8f41197b92 btrfs-progs: Cleanup open-coded btrfs_chunk_item_size
In btrfs_check_chunk_valid() we calculate chunk item using open code,
use an existing helper btrfs_chunk_item_size() instead.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-07-03 13:35:10 +02:00
David Sterba cc5c10b675 btrfs-progs: docs: document conventions
Signed-off-by: David Sterba <dsterba@suse.com>
2017-07-03 13:35:10 +02:00
David Sterba 88221fc081
Btrfs progs v4.11.1
Signed-off-by: David Sterba <dsterba@suse.com>
2017-06-30 18:34:24 +02:00
David Sterba 579f4832e6 btrfs-progs: update CHANGES for v4.11.1
Signed-off-by: David Sterba <dsterba@suse.com>
2017-06-30 17:04:27 +02:00
Liu Bo 1d46d6ba2c Btrfs-progs: convert: do not clear header rev
So btrfs_set_header_flags() vs btrfs_set_header_flag, the difference is
sort of similar to "=" vs "|=", when creating and initialising a new
extent buffer, convert uses the former one which clears header_rev by
accident.

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Reviewed-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-06-30 17:01:19 +02:00
Liu Bo 188f9c889a Btrfs-progs: convert: do not clear nodatasum flag in inode item
With the current btrfs-convert, if we convert a ext4 without data checksum,
it'd not set nodatasum flag in inode item, nor create csum item, reading
file ends up with checksum errors.

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-06-30 16:31:02 +02:00
Liu Bo c58d13eeba Btrfs-progs: man: nodesize must be power of 2 now
This updates mkfs.btrfs's man page with the new limitation that nodesize must
be a power of 2 as well.

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-06-30 16:31:02 +02:00
Lu Fengqi bf95b303f4 btrfs-progs: lowmem check: Fix false alert about file extent interrupt
As Qu mentioned in this thread
(https://www.spinics.net/lists/linux-btrfs/msg64469.html), compression
can cause regular extent to co-exist with an inlined extent. This
coexistence makes things confusing. Since it is currently allowed and
can appear in a filesystem, fix btrfsck to prevent a bunch of error
reports to appear that will make user feel uneasy.

When checking a file extent, record the extent_end of the regular extent
to check if there is a gap between the regular extents. Normally there
is only one inlined extent, so the extent_end of inlined extent is
useless. However, if a regular extent can co-exist with an inlined
extent, the extent_end of the inlined extent also needs to be recorded.

Reported-by: Marc MERLIN <marc@merlins.org>
Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-06-26 17:10:06 +02:00
Qu Wenruo bb305ae832 btrfs-progs: tests: Add test case to check file hole extents with NO_HOLES flag
Add test case which we have NO_HOLES incompat flag while still have
hole file extent.

This can be created by enabling NO_HOLES feature on an existing
filesystem, which lowmem mode would cause false alert for it.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
[ minor adjustments ]
Signed-off-by: David Sterba <dsterba@suse.com>
2017-06-26 17:10:02 +02:00
Qu Wenruo 163ca0e431 btrfs-progs: check: Fix false alert about EXTENT_DATA that shouldn't be a hole
Since the incompat feature NO_HOLES still allows us to have an explicit
hole file extent, current check is too strict and will cause false
alerts like:

  root 5 EXTENT_DATA[257, 0] shouldn't be hole

Fix it by removing the strict file hole extent check.

Link: https://www.spinics.net/lists/linux-btrfs/msg66374.html
Reported-by: Henk Slager <eye1tm@gmail.com>
Tested-by: Henk Slager <eye1tm@gmail.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-06-26 17:09:58 +02:00
Lakshmipathi.G 324d4c1857 btrfs-progs: convert: Add larger device support
With larger file system (in this case its 22TB), ext2fs_open() returns
EXT2_ET_CANT_USE_LEGACY_BITMAPS error message with
ext2fs_read_block_bitmap().

To overcome this issue,
(a) we need pass EXT2_FLAG_64BITS flag with ext2fs_open.
(b) use 64-bit functions like ext2fs_get_block_bitmap_range2,
    ext2fs_inode_data_blocks2,ext2fs_read_ext_attr2
(c) use 64bit types with btrfs_convert_context fields

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=194795
Signed-off-by: Lakshmipathi.G <lakshmipathi.g@giis.co.in>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-06-26 17:09:54 +02:00
Lakshmipathi.G 8636132c6d btrfs-progs: convert: widen int types in convert context
The u32 types in the convert context might not be enough for some very
large filesytems (20TB). Use 64bit types to be safe.

Signed-off-by: Lakshmipathi.G <lakshmipathi.g@giis.co.in>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-06-26 17:09:53 +02:00