btrfs-progs: super-recover: fix the broken sb detection
authorNikolay Borisov <nborisov@suse.com>
Tue, 5 Dec 2017 08:39:49 +0000 (10:39 +0200)
committerDavid Sterba <dsterba@suse.com>
Wed, 31 Jan 2018 14:14:01 +0000 (15:14 +0100)
commit4487aa64e73ab0f029290b67f3d619858ad516bb
tree5a3c5b61831406ed4fcbb7abe14bc74d98a7c824
parent90a16b10b328d63ea90b3f4a04fd52a0bc0b689f
btrfs-progs: super-recover: fix the broken sb detection

Commit 3296d058b7ce ("btrfs-progs: super-recover: Reuse
 btrfs_read_dev_super function") changed the logic when a superblock
is added to the bad block list to depend on -EIO. However currently
btrfs_read_dev_super doesn't return -EIO when the fist super block
is broken. Instead it returns -1. This causes the super-recovery
logic to miss the fact that the first super block is completely broken.

Fix this by considering any error code from btrfs_read_dev_super other
than -ENOENT to mean that the super block is corrupted. -ENOENT
means that the superblock copy is not part of the fs i.e. it's smaller
than the offset of the block. This can only occur for the 2nd copy at
256gb mark.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
super-recover.c