mirror of
https://github.com/linux-apfs/apfstests.git
synced 2026-05-01 15:01:44 -07:00
1ff4192932
Fully scripted conversion, see script in initial SPDX license commit message. Signed-off-by: Dave Chinner <dchinner@redhat.com>
107 lines
2.9 KiB
Bash
Executable File
107 lines
2.9 KiB
Bash
Executable File
#! /bin/bash
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
# Copyright (c) 2017 Oracle. All Rights Reserved.
|
|
#
|
|
# FS QA Test 157
|
|
#
|
|
# The test case is to reproduce a bug in raid6 reconstruction process that
|
|
# would end up with read failure if there is data corruption on two disks in
|
|
# the same horizontal stripe, e.g. due to bitrot.
|
|
#
|
|
# The bug happens when
|
|
# a) all disks are good to read,
|
|
# b) there is corrupted data on two disks in the same horizontal stripe due to
|
|
# something like bitrot,
|
|
# c) when rebuilding data after crc fails, btrfs is not able to tell whether
|
|
# other copies are good or corrupted because btrfs doesn't have crc for
|
|
# unallocated blocks.
|
|
#
|
|
# The kernel fixes are
|
|
# Btrfs: do not merge rbios if their fail stripe index are not identical
|
|
# Btrfs: make raid6 rebuild retry more
|
|
#
|
|
seq=`basename $0`
|
|
seqres=$RESULT_DIR/$seq
|
|
echo "QA output created by $seq"
|
|
|
|
here=`pwd`
|
|
tmp=/tmp/$$
|
|
status=1 # failure is the default!
|
|
trap "_cleanup; exit \$status" 0 1 2 3 15
|
|
|
|
_cleanup()
|
|
{
|
|
cd /
|
|
rm -f $tmp.*
|
|
}
|
|
|
|
# get standard environment, filters and checks
|
|
. ./common/rc
|
|
. ./common/filter
|
|
|
|
# remove previous $seqres.full before test
|
|
rm -f $seqres.full
|
|
|
|
# real QA test starts here
|
|
|
|
# Modify as appropriate.
|
|
_supported_fs btrfs
|
|
_supported_os Linux
|
|
_require_scratch_dev_pool 4
|
|
_require_btrfs_command inspect-internal dump-tree
|
|
|
|
get_physical_stripe0()
|
|
{
|
|
$BTRFS_UTIL_PROG inspect-internal dump-tree -t 3 $SCRATCH_DEV | \
|
|
grep " DATA\|RAID6" -A 10 | \
|
|
$AWK_PROG '($1 ~ /stripe/ && $3 ~ /devid/ && $2 ~ /0/) { print $6 }'
|
|
}
|
|
|
|
get_physical_stripe1()
|
|
{
|
|
$BTRFS_UTIL_PROG inspect-internal dump-tree -t 3 $SCRATCH_DEV | \
|
|
grep " DATA\|RAID6" -A 10 | \
|
|
$AWK_PROG '($1 ~ /stripe/ && $3 ~ /devid/ && $2 ~ /1/) { print $6 }'
|
|
}
|
|
|
|
_scratch_dev_pool_get 4
|
|
# step 1: create a raid6 btrfs and create a 4K file
|
|
echo "step 1......mkfs.btrfs" >>$seqres.full
|
|
|
|
mkfs_opts="-d raid6 -b 1G"
|
|
_scratch_pool_mkfs $mkfs_opts >>$seqres.full 2>&1
|
|
|
|
# -o nospace_cache makes sure data is written to the start position of the data
|
|
# chunk
|
|
_scratch_mount -o nospace_cache
|
|
|
|
# [0,64K) is written to stripe 0 and [64K, 128K) is written to stripe 1
|
|
$XFS_IO_PROG -f -d -c "pwrite -S 0xaa 0 128K" -c "fsync" \
|
|
"$SCRATCH_MNT/foobar" | _filter_xfs_io
|
|
|
|
_scratch_unmount
|
|
|
|
stripe_0=`get_physical_stripe0`
|
|
stripe_1=`get_physical_stripe1`
|
|
dev4=`echo $SCRATCH_DEV_POOL | awk '{print $4}'`
|
|
dev3=`echo $SCRATCH_DEV_POOL | awk '{print $3}'`
|
|
|
|
# step 2: corrupt the 1st and 2nd stripe (stripe 0 and 1)
|
|
echo "step 2......simulate bitrot at offset $stripe_0 of device_4($dev4) and offset $stripe_1 of device_3($dev3)" >>$seqres.full
|
|
|
|
$XFS_IO_PROG -f -d -c "pwrite -S 0xbb $stripe_0 64K" $dev4 | _filter_xfs_io
|
|
$XFS_IO_PROG -f -d -c "pwrite -S 0xbb $stripe_1 64K" $dev3 | _filter_xfs_io
|
|
|
|
# step 3: read foobar to repair the bitrot
|
|
echo "step 3......repair the bitrot" >> $seqres.full
|
|
_scratch_mount -o nospace_cache
|
|
|
|
# read the 2nd stripe, i.e. [64K, 128K), to trigger repair
|
|
od -x -j 64K $SCRATCH_MNT/foobar
|
|
|
|
_scratch_dev_pool_put
|
|
|
|
# success, all done
|
|
status=0
|
|
exit
|