2015-02-12 14:12:14 +11:00
|
|
|
#! /bin/bash
|
2018-06-09 11:35:45 +10:00
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
|
|
|
# Copyright (c) 2015 Red Hat, Inc. All Rights Reserved.
|
|
|
|
|
#
|
2015-02-12 14:12:14 +11:00
|
|
|
# FS QA Test No. 070
|
|
|
|
|
#
|
|
|
|
|
# As part of superblock verification, xfs_repair checks the primary sb and
|
|
|
|
|
# verifies all secondary sb's against the primary. In the event of geometry
|
|
|
|
|
# inconsistency, repair uses a heuristic that tracks the most frequently
|
|
|
|
|
# occurring settings across the set of N (agcount) superblocks.
|
|
|
|
|
#
|
|
|
|
|
# xfs_repair was subject to a bug that disregards this heuristic in the event
|
|
|
|
|
# that the last secondary superblock in the fs is corrupt. The side effect is an
|
|
|
|
|
# unnecessary and potentially time consuming brute force superblock scan.
|
|
|
|
|
#
|
|
|
|
|
# This is a regression test for the aforementioned xfs_repair bug. We
|
|
|
|
|
# intentionally corrupt the last superblock in the fs, run xfs_repair and
|
|
|
|
|
# verify it repairs the fs correctly. We explicitly detect a brute force scan
|
|
|
|
|
# and abort the repair to save time in the failure case.
|
|
|
|
|
#
|
|
|
|
|
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.*
|
2016-06-13 11:58:01 +09:00
|
|
|
$KILLALL_PROG -9 $XFS_REPAIR_PROG > /dev/null 2>&1
|
2015-02-12 14:12:14 +11:00
|
|
|
wait > /dev/null 2>&1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Start and monitor an xfs_repair of the scratch device. This test can induce a
|
|
|
|
|
# time consuming brute force superblock scan. Since a brute force scan means
|
|
|
|
|
# test failure, detect it and end the repair.
|
|
|
|
|
_xfs_repair_noscan()
|
|
|
|
|
{
|
|
|
|
|
# invoke repair directly so we can kill the process if need be
|
2020-09-14 18:43:53 -07:00
|
|
|
[ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
|
|
|
|
|
log_repair_opts="-l $SCRATCH_LOGDEV"
|
2018-01-11 20:16:19 -08:00
|
|
|
[ "$USE_EXTERNAL" = yes ] && [ -n "$SCRATCH_RTDEV" ] && \
|
|
|
|
|
rt_repair_opts="-r $SCRATCH_RTDEV"
|
2020-09-14 18:43:53 -07:00
|
|
|
$XFS_REPAIR_PROG $log_repair_opts $rt_repair_opts $SCRATCH_DEV 2>&1 |
|
2018-01-11 20:16:19 -08:00
|
|
|
tee -a $seqres.full > $tmp.repair &
|
2015-02-12 14:12:14 +11:00
|
|
|
repair_pid=$!
|
|
|
|
|
|
|
|
|
|
# monitor progress for as long as it is running
|
|
|
|
|
while [ `pgrep xfs_repair` ]; do
|
|
|
|
|
grep "couldn't verify primary superblock" $tmp.repair \
|
|
|
|
|
> /dev/null 2>&1
|
|
|
|
|
if [ $? == 0 ]; then
|
|
|
|
|
# we've started a brute force scan. kill repair and
|
|
|
|
|
# fail the test
|
|
|
|
|
kill -9 $repair_pid >> $seqres.full 2>&1
|
|
|
|
|
wait >> $seqres.full 2>&1
|
|
|
|
|
|
|
|
|
|
_fail "xfs_repair resorted to brute force scan"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
sleep 1
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
wait
|
|
|
|
|
|
|
|
|
|
cat $tmp.repair | _filter_repair
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rm -f $seqres.full
|
|
|
|
|
|
|
|
|
|
# get standard environment, filters and checks
|
|
|
|
|
. ./common/rc
|
|
|
|
|
. ./common/filter
|
|
|
|
|
. ./common/repair
|
|
|
|
|
|
|
|
|
|
# real QA test starts here
|
|
|
|
|
|
|
|
|
|
# Modify as appropriate.
|
|
|
|
|
_supported_fs xfs
|
|
|
|
|
_require_scratch_nocheck
|
2016-06-13 11:58:01 +09:00
|
|
|
_require_command "$KILLALL_PROG" killall
|
2015-02-12 14:12:14 +11:00
|
|
|
|
|
|
|
|
_scratch_mkfs | _filter_mkfs > /dev/null 2> $tmp.mkfs || _fail "mkfs failed"
|
|
|
|
|
|
|
|
|
|
. $tmp.mkfs # import agcount
|
|
|
|
|
|
|
|
|
|
# corrupt the last secondary sb in the fs
|
2016-09-29 19:23:41 -07:00
|
|
|
_scratch_xfs_db -x -c "sb $((agcount - 1))" -c "type data" \
|
|
|
|
|
-c "write fill 0xff 0 512"
|
2015-02-12 14:12:14 +11:00
|
|
|
|
|
|
|
|
# attempt to repair
|
|
|
|
|
_xfs_repair_noscan
|
|
|
|
|
|
|
|
|
|
# success, all done
|
|
|
|
|
status=0
|
|
|
|
|
exit
|