Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Btrfs: fix unfinished readahead thread for raid5/6 degraded mounting

Steps to reproduce:

# mkfs.btrfs -f /dev/sd[b-f] -m raid5 -d raid5
# mkfs.ext4 /dev/sdc --->corrupt one of btrfs device
# mount /dev/sdb /mnt -o degraded
# btrfs scrub start -BRd /mnt

This is because readahead would skip missing device, this is not true
for RAID5/6, because REQ_GET_READ_MIRRORS return 1 for RAID5/6 block
mapping. If expected data locates in missing device, readahead thread
would not call __readahead_hook() which makes event @rc->elems=0
wait forever.

Fix this problem by checking return value of btrfs_map_block(),we
can only skip missing device safely if there are several mirrors.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: Chris Mason <clm@fb.com>

authored by

Wang Shilong and committed by
Chris Mason
5fbc7c59 cc68a8a5

+7 -2
+7 -2
fs/btrfs/reada.c
··· 428 428 continue; 429 429 } 430 430 if (!dev->bdev) { 431 - /* cannot read ahead on missing device */ 432 - continue; 431 + /* 432 + * cannot read ahead on missing device, but for RAID5/6, 433 + * REQ_GET_READ_MIRRORS return 1. So don't skip missing 434 + * device for such case. 435 + */ 436 + if (nzones > 1) 437 + continue; 433 438 } 434 439 if (dev_replace_is_ongoing && 435 440 dev == fs_info->dev_replace.tgtdev) {