generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / xfs / 042
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 042
6 #
7 # xfs_fsr QA tests
8 # create a large fragmented file and check that xfs_fsr doesn't corrupt
9 # it or the other contents of the filesystem
10 #
11 set +x
12
13 . ./common/preamble
14 _begin_fstest fsr ioctl auto
15
16 # Override the default cleanup function.
17 _cleanup()
18 {
19     _scratch_unmount
20     rm -f $tmp.*
21 }
22
23 # Import common functions.
24 . ./common/filter
25
26 # real QA test starts here
27 _supported_fs xfs
28 _require_xfs_io_command "falloc"
29
30 _require_scratch
31
32 [ "$XFS_FSR_PROG" = "" ] && _notrun "xfs_fsr not found"
33
34 # Test performs several operations to produce a badly fragmented file, then
35 # create enough contiguous free space for xfs_fsr to defragment the fragmented
36 # file:
37 #
38 # - create fs with 3 minimum sized (16Mb) allocation groups
39 # - create 16x1MB contiguous files which will become large free space extents
40 #   when deleted
41 # - put a small "space" between each of the 16 contiuguous files to ensure we
42 #   have separated free space extents
43 # - fill the remaining free space with a "fill file"
44 # - mount/unmount/fill remaining free space with a pad file
45 # - punch alternate single block holes in the the "fill file" to create
46 #   fragmented free space.
47 # - use fill2 to generate a very large fragmented file
48 # - delete the 16 large contiguous files created initially
49 # - run xfs_fsr on the filesystem
50 # - check checksums for remaining files
51
52 _do_die_on_error=message_only
53
54 echo -n "Make a 48 megabyte filesystem on SCRATCH_DEV and mount... "
55 _scratch_mkfs_xfs -dsize=48m,agcount=3 2>&1 >/dev/null || _fail "mkfs failed"
56 _scratch_mount
57
58 echo "done"
59
60 echo -n "Reserve 16 1Mb unfragmented regions... "
61 for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
62 do
63         _do "$XFS_IO_PROG -f -c \"resvsp 0 1m\" $SCRATCH_MNT/hole$i"
64         _do "$XFS_IO_PROG -f -c \"resvsp 0 4k\" $SCRATCH_MNT/space$i"
65         _do "xfs_bmap -vp $SCRATCH_MNT/hole$i"
66 done
67 echo "done" 
68
69 # set up filesystem
70 echo -n "Fill filesystem with fill file... "
71 for i in `seq 0 1 31`; do
72         _do "$XFS_IO_PROG -f -c \"falloc ${i}m 1m\" $SCRATCH_MNT/fill"
73 done
74 _do "xfs_bmap -vp $SCRATCH_MNT/fill"
75 echo "done"
76 # flush the filesystem - make sure there is no space "lost" to pre-allocation
77 _do "_scratch_unmount"
78 _do "_try_scratch_mount"
79 echo -n "Use up any further available space... "
80 _do "$XFS_IO_PROG -f -c \"falloc 0 1m\" $SCRATCH_MNT/pad"
81 echo "done"
82
83 # create fragmented file
84 #_do "Delete every second file" "_cull_files"
85 echo -n "Punch every second 4k block... "
86 for i in `seq 0 8 32768`; do
87         # This generates excessive output that significantly slows down the
88         # test. It's not necessary for debug, so just bin it.
89         $XFS_IO_PROG -f -c "unresvsp ${i}k 4k" $SCRATCH_MNT/fill \
90                                                                 > /dev/null 2>&1
91 done
92 _do "xfs_bmap -vp $SCRATCH_MNT/fill"
93 _do "sum $SCRATCH_MNT/fill >$tmp.fillsum1"
94 echo "done"
95
96 echo -n "Create one very large file... "
97 _do "$here/src/fill2 -d nbytes=16000000,file=$SCRATCH_MNT/fragmented"
98 echo "done"
99 _do "xfs_bmap -v $SCRATCH_MNT/fragmented"
100 _do "sum $SCRATCH_MNT/fragmented >$tmp.sum1"
101 _do "Remove other files" "rm -rf $SCRATCH_MNT/{pad,hole*}"
102
103 # defragment
104 _do "Run xfs_fsr on filesystem" "$XFS_FSR_PROG -v $SCRATCH_MNT/fragmented"
105 _do "xfs_bmap -v $SCRATCH_MNT/fragmented"
106
107 echo -n "Check fill file... "
108 _do "sum $SCRATCH_MNT/fill >$tmp.fillsum2"
109 if ! _do "diff $tmp.fillsum1 $tmp.fillsum2"; then
110     echo "fail"
111     echo "Fill file is corrupt/missing after fsr. Test failed see $seqres.full"
112     status=1; exit
113 fi
114 echo "done"
115
116 # check
117 echo -n "Check large file... "
118 _do "sum $SCRATCH_MNT/fragmented >$tmp.sum2"
119 if ! _do "diff $tmp.sum1 $tmp.sum2"; then
120     echo "fail"
121     echo "File is corrupt/missing after fsr. Test failed see $seqres.full"
122     status=1; exit
123 fi
124 echo "done"
125
126 # success, all done
127 echo "xfs_fsr tests passed."
128 status=0 ; exit