2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016, Oracle and/or its affiliates. All Rights Reserved.
7 # Ensure that xfs_fsr handles errors correctly while defragging files.
10 seqres="$RESULT_DIR/$seq"
11 echo "QA output created by $seq"
15 status=1 # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
24 # get standard environment, filters and checks
31 # real QA test starts here
34 _require_scratch_reflink
36 _require_command "$XFS_FSR_PROG" "xfs_fsr"
37 _require_xfs_io_error_injection "bmap_finish_one"
38 _require_xfs_scratch_rmapbt
42 echo "Format and mount"
43 _scratch_mkfs > "$seqres.full" 2>&1
44 _scratch_mount >> "$seqres.full" 2>&1
46 testdir="$SCRATCH_MNT/test-$seq"
51 echo "Create a many-block file"
52 _pwrite_byte 0x62 0 $((blksz * blks)) $testdir/file1 >> $seqres.full
53 _pwrite_byte 0x63 0 $blksz $testdir/file2 >> $seqres.full
54 _reflink_range $testdir/file2 0 $testdir/file1 $blksz $blksz >> $seqres.full
56 $XFS_IO_PROG -c 'bmap -v' $testdir/file1 >> $seqres.full
59 _scratch_inject_error "bmap_finish_one"
61 echo "Defrag the file"
62 old_nextents=$(_count_extents $testdir/file1)
63 $XFS_FSR_PROG -v -d $testdir/file1 >> $seqres.full 2>&1
65 echo "FS should be shut down, touch will fail"
66 touch $SCRATCH_MNT/badfs 2>&1 | _filter_scratch
68 echo "Remount to replay log" | tee /dev/ttyprintk
69 _scratch_inject_logprint >> $seqres.full
70 new_nextents=$(_count_extents $testdir/file1)
72 echo "Check extent count" | tee /dev/ttyprintk
73 $XFS_IO_PROG -c 'stat -v' $testdir/file1 >> $seqres.full
74 $XFS_IO_PROG -c 'stat -v' $testdir/file2 >> $seqres.full
75 echo "extents: $old_nextents -> $new_nextents" >> $seqres.full
77 echo "FS should be online, touch should succeed"
78 touch $SCRATCH_MNT/goodfs
79 $XFS_IO_PROG -c 'bmap -v' $testdir/file1 >> $seqres.full