2 # SPDX-License-Identifier: GPL-2.0-or-later
3 # Copyright (c) 2021 Oracle. All Rights Reserved.
7 # Make sure that the kernel won't mount a filesystem if repair forcibly sets
8 # NEEDSREPAIR while fixing metadata. Corrupt a directory in such a way as
9 # to force repair to write an invalid dirent value as a sentinel to trigger a
10 # repair activity in a later phase. Use a debug knob in xfs_repair to abort
11 # the repair immediately after forcing the flag on.
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
19 status=1 # failure is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
28 # get standard environment, filters and checks
32 # real QA test starts here
34 _require_scratch_nocheck
35 _require_scratch_xfs_crc # needsrepair only exists for v5
36 _require_libxfs_debug_flag LIBXFS_DEBUG_WRITE_CRASH
40 # Set up a real filesystem for our actual test
41 _scratch_mkfs >> $seqres.full
43 # Create a directory large enough to have a dir data block. 2k worth of
44 # dirent names ought to do it.
46 mkdir -p $SCRATCH_MNT/fubar
47 for i in $(seq 0 256 2048); do
48 fname=$(printf "%0255d" $i)
49 ln -s -f urk $SCRATCH_MNT/fubar/$fname
51 inum=$(stat -c '%i' $SCRATCH_MNT/fubar)
55 _scratch_xfs_db -x -c "inode $inum" -c "dblock 0" \
56 -c "fuzz -d bu[2].inumber add" >> $seqres.full
58 # Try to repair the directory, force it to crash after setting needsrepair
59 LIBXFS_DEBUG_WRITE_CRASH=ddev=2 _scratch_xfs_repair 2>> $seqres.full
60 test $? -eq 137 || echo "repair should have been killed??"
62 # We can't mount, right?
63 _check_scratch_xfs_features NEEDSREPAIR
64 _try_scratch_mount &> $tmp.mount
66 _filter_scratch < $tmp.mount
67 if [ $res -eq 0 ]; then
68 echo "Should not be able to mount after needsrepair crash"
72 # Repair properly this time and retry the mount
73 _scratch_xfs_repair 2>> $seqres.full
74 _check_scratch_xfs_features NEEDSREPAIR