Files
apfstests/common/repair
T
Zhihao Cheng b7cecbea22 fstests: Add path $here before src/<file>
Calling src/<file> without path '$here' may cause the problem that
the file cannot be found.

For example, Running generic/192 with overlayfs(Let ubifs as base
fs) yields the following output:

  generic/192 - output mismatch
     QA output created by 192
     sleep for 5 seconds
     test
    +./common/rc: line 316: src/t_dir_type: No such file or directory
     delta1 is in range
     delta2 is in range
    ...

When the use case fails, the call stack in generic/192 is:

  local unknowns=$(src/t_dir_type $dir u | wc -l)	common/rc
  _supports_filetype					common/rc
  _overlay_mount					common/overlay
  _overlay_test_mount					common/overlay
  _test_mount						common/rc
  _test_cycle_mount					generic/192

Before _test_cycle_mount() being invoked, generic/192 executed 'cd
/' to change work dir from 'xfstests-dev' to '/', so src/t_dir_type
was not found.

[Eryu: some tests run src/<file> as regular user, don't add $here
prefix in such case, as a regular user may have no search permission
on $here]

Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Reviewed-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
2019-10-23 23:12:42 +08:00

132 lines
4.1 KiB
Plaintext

##/bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2000-2002 Silicon Graphics, Inc. All Rights Reserved.
#
# Functions useful for xfs_repair tests
_zero_position()
{
value=$1
struct="$2"
# set values for off/len variables provided by db
eval `xfs_db -r -c "$struct" -c stack $SCRATCH_DEV | perl -ne '
if (/byte offset (\d+), length (\d+)/) {
print "offset=$1\nlength=$2\n"; exit
}'`
if [ -z "$offset" -o -z "$length" ]; then
echo "cannot calculate offset ($offset) or length ($length)"
exit
fi
length=`expr $length / 512`
$here/src/devzero -v $value -b 1 -n $length -o $offset $SCRATCH_DEV \
| perl -npe 's/\d\.\d\dKb/X.XXKb/g'
}
_filter_repair()
{
perl -ne '
# for sb
/- agno = / && next; # remove each AG line (variable number)
s/(pointer to) (\d+)/\1 INO/;
s/(sb root inode value) (\d+)( \(NULLFSINO\))?/\1 INO/;
s/(realtime bitmap inode) (\d+)( \(NULLFSINO\))?/\1 INO/;
s/(realtime summary inode) (\d+)( \(NULLFSINO\))?/\1 INO/;
s/(inconsistent with calculated value) (\d+)/\1 INO/;
s/\.+(found)/\1/g; # remove "searching" output
# for agf + agi
s/(bad length -{0,1}\d+ for ag. 0, should be) (\d+)/\1 LENGTH/;
s/(bad length # -{0,1}\d+ for ag. 0, should be) (\d+)/\1 LENGTH/;
s/(bad agbno) (\d+)/\1 AGBNO/g;
s/(max =) (\d+)/\1 MAX/g;
# for root inos
s/(on inode) (\d+)/\1 INO/g;
s/(imap claims a free inode) (\d+)/\1 INO/;
s/(imap claims in-use inode) (\d+)/\1 INO/;
s/(cleared root inode) (\d+)/\1 INO/;
s/(resetting inode) (\d+)/\1 INO/;
s/(disconnected dir inode) (\d+)/\1 INO/;
# for log
s/internal log/<TYPEOF> log/g;
s/external log on \S+/<TYPEOF> log/g;
# realtime subvol - remove this whole line if it appears
s/ - generate realtime summary info and bitmap...\n//g;
#
# new xfs repair output filters
#
s/\s+- creating \d+ worker thread\(s\)\n//g;
s/\s+- reporting progress in intervals of \d+ minutes\n//g;
s/\s+- \d+:\d\d:\d\d:.*\n//g;
# 3.1.0 extra accounting output
/^agf_/ && next; # remove agf counts
/^agi_/ && next; # remove agi counts
/^sb_/ && next; # remove sb counts
/^agi unlinked/ && next; # remove agi unlinked bucket warning
# crc enabled filesystem output
/XFS_CORRUPTION_ERROR/ && next;
/^bad uuid/ && next;
/^Metadata corruption detected/ && next;
/^Metadata CRC error detected/ && next;
/^agfl has bad CRC/ && next;
/^bad CRC for inode/ && next;
# finobt enabled filesystem output
s/(inode chunk) (\d+)\/(\d+)/AGNO\/INO/;
# sunit/swidth reset messages
s/^(Note - .*) were copied.*/\1 fields have been reset./;
s/^(Please) reset (with .*) if necessary/\1 set \2/;
# And make them generic so we dont depend on geometry
s/(stripe unit) \(.*\) (and width) \(.*\)/\1 (SU) \2 (SW)/;
# corrupt sb messages
s/(superblock) (\d+)/\1 AGNO/;
s/(AG \#)(\d+)/\1AGNO/;
s/(reset bad sb for ag) (\d+)/\1 AGNO/;
s/(unknown block state, ag )(\d+)(, block )(\d+)/\1AGNO\3AGBNO/;
/^Note - quota info will be regenerated on next quota mount.$/ && next;
print;'
}
# Filter out unknown block state messages that appear when rmap is enabled
# and we erase a btree root pointer (such that repair never finds the
# tree and fails to reconcile the metadata reverse mappings against the
# metadata).
_filter_repair_lostblocks() {
_filter_repair | sed -e '/unknown block state, ag AGNO, block AGBNO/d'
}
_filter_dd()
{
fgrep -v records # lose records in/out lines
}
# do some controlled corrupting & ensure repair recovers us
#
_check_repair()
{
value=$1
structure="$2"
#ensure the filesystem has been dirtied since last repair
_scratch_mount
POSIXLY_CORRECT=yes \
dd if=/bin/bash of=$SCRATCH_MNT/sh 2>&1 |_filter_dd
sync
rm -f $SCRATCH_MNT/sh
_scratch_unmount
_zero_position $value "$structure"
_scratch_xfs_repair 2>&1 | _filter_repair
# some basic sanity checks...
_check_scratch_fs
_scratch_mount #mount
POSIXLY_CORRECT=yes \
dd if=/bin/bash of=$SCRATCH_MNT/sh 2>&1 |_filter_dd #open,write
POSIXLY_CORRECT=yes \
dd if=$SCRATCH_MNT/sh of=/dev/null 2>&1 |_filter_dd #read
rm -f $SCRATCH_MNT/sh #unlink
_scratch_unmount #umount
}
# make sure this script returns success
/bin/true