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