xfs: fix old fuzz test invocations of xfs_repair
[xfstests-dev.git] / tests / ext4 / 308
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3
4 #
5 # FSQA Test No. 308
6 #
7 # Check data integrity and layout stability during defrag compacting
8 # EXT4_IOC_MOVE_EXT simply swap extents between target and donor inode.
9 # So if ioctl was performed twice then inode's layout should not change.
10 #
11 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
14
15 PIDS=""
16 tmp=/tmp/$$
17 status=1        # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
19
20 _cleanup()
21 {
22         rm -f $tmp.*
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28 . ./common/defrag
29
30 # real QA test starts here
31 _require_scratch
32 _require_defrag
33 _require_xfs_io_command "falloc"
34
35 rm -f $seqres.full
36
37 _workout()
38 {
39         nr=$1
40         echo "Create file with $nr * 2 fragments"
41         # Create sparse file
42         for ((i=0;i<nr;i++))
43         do
44                 $XFS_IO_PROG -f -c "falloc $((409600*i)) 4k"  \
45                         $SCRATCH_MNT/test.$nr >> $seqres.full 2>&1
46         done
47         # Fill holes for half of range , as result file will contain nr*1.5 fragments
48         $XFS_IO_PROG -c "falloc 0 $((204800*nr))"  \
49             $SCRATCH_MNT/test.$nr | _filter_xfs_io
50         # Data write will convert extents to initialized ones
51         for ((i=0;i<nr;i++))
52         do
53                 patt=`printf "0x%x" $i`
54                 $XFS_IO_PROG -c "pwrite -S $patt $((i*123400)) 1234" \
55                         $SCRATCH_MNT/test.$nr | _filter_xfs_io
56         done
57         md5sum $SCRATCH_MNT/test.* | _filter_scratch
58         $XFS_IO_PROG -c "fiemap" -f $SCRATCH_MNT/test.* > $tmp.fiemap.before
59
60         echo "Perform compacting"
61         $XFS_IO_PROG -c "falloc 0 246M" -f $SCRATCH_MNT/donor | _filter_xfs_io
62         ls $SCRATCH_MNT/test.* | run_check $here/src/e4compact \
63                  -v -i -f $SCRATCH_MNT/donor  >> $seqres.full 2>&1
64         md5sum $SCRATCH_MNT/test.* | _filter_scratch
65         $XFS_IO_PROG -c "fiemap" -f $SCRATCH_MNT/test.* > $tmp.fiemap.pass1
66         diff $tmp.fiemap.before $tmp.fiemap.pass1 > /dev/null && \
67             _fail "Pass1: Extent's layout not changed"
68
69         echo "Perform compacting, second pass"
70         # Second pass should restore original layout
71         ls $SCRATCH_MNT/test.* | run_check $here/src/e4compact \
72                  -v -f $SCRATCH_MNT/donor  >> $seqres.full 2>&1
73         md5sum $SCRATCH_MNT/test.* | _filter_scratch
74         $XFS_IO_PROG -c "fiemap" -f $SCRATCH_MNT/test.* > $tmp.fiemap.pass2
75         diff -up $tmp.fiemap.before $tmp.fiemap.pass2 || \
76             _fail "Pass2: Extent's layout changed."
77         unlink $SCRATCH_MNT/donor
78 }
79
80 # Actual testing starting from here
81 _scratch_mkfs  >> $seqres.full 2>&1
82 _scratch_mount
83 _workout 10
84 _workout 20
85 _workout 40
86 _workout 80
87 _workout 160
88 status=0