2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Liu Bo. All Rights Reserved.
4 # Copyright (c) 2022 Christoph Hellwig.
8 # Test that btrfs buffered read repair on a raid1c3 profile can repair
9 # interleaving errors on all mirrors.
13 _begin_fstest auto quick read_repair
15 # Import common functions.
18 # real QA test starts here
21 _require_scratch_dev_pool 3
24 # Overwriting data is forbidden on a zoned block device
25 _require_non_zoned_device "${SCRATCH_DEV}"
27 _scratch_dev_pool_get 3
28 # step 1, create a raid1 btrfs which contains one 128k file.
29 echo "step 1......mkfs.btrfs"
31 mkfs_opts="-d raid1c3 -b 1G"
32 _scratch_pool_mkfs $mkfs_opts >>$seqres.full 2>&1
36 $XFS_IO_PROG -f -d -c "pwrite -S 0xaa -b 256K 0 256K" \
37 "$SCRATCH_MNT/foobar" | \
40 # step 2, corrupt 64k in each copy
41 echo "step 2......corrupt file extent"
43 # ensure btrfs-map-logical sees the tree updates
46 logical=$(_btrfs_get_first_logical $SCRATCH_MNT/foobar)
48 physical1=$(_btrfs_get_physical ${logical} 1)
49 devpath1=$(_btrfs_get_device_path ${logical} 1)
51 physical2=$(_btrfs_get_physical ${logical} 2)
52 devpath2=$(_btrfs_get_device_path ${logical} 2)
54 physical3=$(_btrfs_get_physical ${logical} 3)
55 devpath3=$(_btrfs_get_device_path ${logical} 3)
59 $XFS_IO_PROG -d -c "pwrite -S 0xbd -b 64K $physical3 64K" \
62 $XFS_IO_PROG -d -c "pwrite -S 0xba -b 64K $physical1 128K" \
65 $XFS_IO_PROG -d -c "pwrite -S 0xbb -b 64K $((physical2 + 65536)) 128K" \
68 $XFS_IO_PROG -d -c "pwrite -S 0xbc -b 64K $((physical3 + (2 * 65536))) 128K" \
73 # step 3, 128k dio read (this read can repair bad copy)
74 echo "step 3......repair the bad copy"
76 _btrfs_direct_read_on_mirror 0 3 "$SCRATCH_MNT/foobar" 0 256K
77 _btrfs_direct_read_on_mirror 1 3 "$SCRATCH_MNT/foobar" 0 256K
78 _btrfs_direct_read_on_mirror 2 3 "$SCRATCH_MNT/foobar" 0 256K
82 echo "step 4......check if the repair worked"
83 $XFS_IO_PROG -d -c "pread -v -b 512 $physical1 512" $devpath1 |\
85 $XFS_IO_PROG -d -c "pread -v -b 512 $physical2 512" $devpath2 |\
87 $XFS_IO_PROG -d -c "pread -v -b 512 $physical3 512" $devpath3 |\