2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2000-2002 Silicon Graphics, Inc. All Rights Reserved.
8 # create a large fragmented file and check that xfs_fsr doesn't corrupt
9 # it or the other contents of the filesystem
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
19 status=1 # failure is the default!
26 trap "_cleanup ; exit \$status" 0 1 2 3 15
28 # get standard environment, filters and checks
32 # real QA test starts here
38 [ "$XFS_FSR_PROG" = "" ] && _notrun "xfs_fsr not found"
40 # Test performs several operations to produce a badly fragmented file, then
41 # create enough contiguous free space for xfs_fsr to defragment the fragmented
44 # - create fs with 3 minimum sized (16Mb) allocation groups
45 # - create 16x1MB contiguous files which will become large free space extents
47 # - put a small "space" between each of the 16 contiuguous files to ensure we
48 # have separated free space extents
49 # - fill the remaining free space with a "fill file"
50 # - mount/unmount/fill remaining free space with a pad file
51 # - punch alternate single block holes in the the "fill file" to create
52 # fragmented free space.
53 # - use fill2 to generate a very large fragmented file
54 # - delete the 16 large contiguous files created initially
55 # - run xfs_fsr on the filesystem
56 # - check checksums for remaining files
59 _do_die_on_error=message_only
61 echo -n "Make a 48 megabyte filesystem on SCRATCH_DEV and mount... "
62 _scratch_mkfs_xfs -dsize=48m,agcount=3 2>&1 >/dev/null || _fail "mkfs failed"
67 echo -n "Reserve 16 1Mb unfragmented regions... "
68 for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
70 _do "$XFS_IO_PROG -f -c \"resvsp 0 1m\" $SCRATCH_MNT/hole$i"
71 _do "$XFS_IO_PROG -f -c \"resvsp 0 4k\" $SCRATCH_MNT/space$i"
72 _do "xfs_bmap -vp $SCRATCH_MNT/hole$i"
77 echo -n "Fill filesystem with fill file... "
78 for i in `seq 0 1 31`; do
79 _do "$XFS_IO_PROG -f -c \"falloc ${i}m 1m\" $SCRATCH_MNT/fill"
81 _do "xfs_bmap -vp $SCRATCH_MNT/fill"
83 # flush the filesystem - make sure there is no space "lost" to pre-allocation
84 _do "_scratch_unmount"
85 _do "_try_scratch_mount"
86 echo -n "Use up any further available space... "
87 _do "$XFS_IO_PROG -f -c \"falloc 0 1m\" $SCRATCH_MNT/pad"
90 # create fragmented file
91 #_do "Delete every second file" "_cull_files"
92 echo -n "Punch every second 4k block... "
93 for i in `seq 0 8 32768`; do
94 # This generates excessive output that significantly slows down the
95 # test. It's not necessary for debug, so just bin it.
96 $XFS_IO_PROG -f -c "unresvsp ${i}k 4k" $SCRATCH_MNT/fill \
99 _do "xfs_bmap -vp $SCRATCH_MNT/fill"
100 _do "sum $SCRATCH_MNT/fill >$tmp.fillsum1"
103 echo -n "Create one very large file... "
104 _do "$here/src/fill2 -d nbytes=16000000,file=$SCRATCH_MNT/fragmented"
106 _do "xfs_bmap -v $SCRATCH_MNT/fragmented"
107 _do "sum $SCRATCH_MNT/fragmented >$tmp.sum1"
108 _do "Remove other files" "rm -rf $SCRATCH_MNT/{pad,hole*}"
111 _do "Run xfs_fsr on filesystem" "$XFS_FSR_PROG -v $SCRATCH_MNT/fragmented"
112 _do "xfs_bmap -v $SCRATCH_MNT/fragmented"
114 echo -n "Check fill file... "
115 _do "sum $SCRATCH_MNT/fill >$tmp.fillsum2"
116 if ! _do "diff $tmp.fillsum1 $tmp.fillsum2"; then
118 echo "Fill file is corrupt/missing after fsr. Test failed see $seqres.full"
124 echo -n "Check large file... "
125 _do "sum $SCRATCH_MNT/fragmented >$tmp.sum2"
126 if ! _do "diff $tmp.sum1 $tmp.sum2"; then
128 echo "File is corrupt/missing after fsr. Test failed see $seqres.full"
134 echo "xfs_fsr tests passed."