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 _begin_fstest fsr ioctl auto
16 # Override the default cleanup function.
23 # Import common functions.
26 # real QA test starts here
28 _require_xfs_io_command "falloc"
32 [ "$XFS_FSR_PROG" = "" ] && _notrun "xfs_fsr not found"
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
38 # - create fs with 3 minimum sized (16Mb) allocation groups
39 # - create 16x1MB contiguous files which will become large free space extents
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
52 _do_die_on_error=message_only
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"
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
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"
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"
74 _do "xfs_bmap -vp $SCRATCH_MNT/fill"
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"
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 \
92 _do "xfs_bmap -vp $SCRATCH_MNT/fill"
93 _do "sum $SCRATCH_MNT/fill >$tmp.fillsum1"
96 echo -n "Create one very large file... "
97 _do "$here/src/fill2 -d nbytes=16000000,file=$SCRATCH_MNT/fragmented"
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*}"
104 _do "Run xfs_fsr on filesystem" "$XFS_FSR_PROG -v $SCRATCH_MNT/fragmented"
105 _do "xfs_bmap -v $SCRATCH_MNT/fragmented"
107 echo -n "Check fill file... "
108 _do "sum $SCRATCH_MNT/fill >$tmp.fillsum2"
109 if ! _do "diff $tmp.fillsum1 $tmp.fillsum2"; then
111 echo "Fill file is corrupt/missing after fsr. Test failed see $seqres.full"
117 echo -n "Check large file... "
118 _do "sum $SCRATCH_MNT/fragmented >$tmp.sum2"
119 if ! _do "diff $tmp.sum1 $tmp.sum2"; then
121 echo "File is corrupt/missing after fsr. Test failed see $seqres.full"
127 echo "xfs_fsr tests passed."