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 _begin_fstest auto quick clone fsr
12 # Import common functions.
18 # real QA test starts here
20 _require_scratch_reflink
22 _require_command "$XFS_FSR_PROG" "xfs_fsr"
23 _require_xfs_io_error_injection "bmap_finish_one"
24 _require_xfs_scratch_rmapbt
28 echo "Format and mount"
29 _scratch_mkfs > "$seqres.full" 2>&1
30 _scratch_mount >> "$seqres.full" 2>&1
32 testdir="$SCRATCH_MNT/test-$seq"
37 echo "Create a many-block file"
38 _pwrite_byte 0x62 0 $((blksz * blks)) $testdir/file1 >> $seqres.full
39 _pwrite_byte 0x63 0 $blksz $testdir/file2 >> $seqres.full
40 _reflink_range $testdir/file2 0 $testdir/file1 $blksz $blksz >> $seqres.full
42 $XFS_IO_PROG -c 'bmap -v' $testdir/file1 >> $seqres.full
45 _scratch_inject_error "bmap_finish_one"
47 echo "Defrag the file"
48 old_nextents=$(_count_extents $testdir/file1)
49 $XFS_FSR_PROG -v -d $testdir/file1 >> $seqres.full 2>&1
51 echo "FS should be shut down, touch will fail"
52 touch $SCRATCH_MNT/badfs 2>&1 | _filter_scratch
54 echo "Remount to replay log" | tee /dev/ttyprintk
55 _scratch_inject_logprint >> $seqres.full
56 new_nextents=$(_count_extents $testdir/file1)
58 echo "Check extent count" | tee /dev/ttyprintk
59 $XFS_IO_PROG -c 'stat -v' $testdir/file1 >> $seqres.full
60 $XFS_IO_PROG -c 'stat -v' $testdir/file2 >> $seqres.full
61 echo "extents: $old_nextents -> $new_nextents" >> $seqres.full
63 echo "FS should be online, touch should succeed"
64 touch $SCRATCH_MNT/goodfs
65 $XFS_IO_PROG -c 'bmap -v' $testdir/file1 >> $seqres.full