fstests: support check for uuidgen utility
[xfstests-dev.git] / tests / xfs / 306
1 #! /bin/bash
2 # FS QA Test No. 306
3 #
4 # Regression test for an XFS multi-block buffer logging bug.
5 #
6 # The XFS bug results in a panic when a non-contiguous multi-block buffer is
7 # mapped and logged in a particular manner, such that only regions beyond the
8 # first fsb-sized mapping are logged. The crash occurs asynchronous to
9 # transaction submission, when the associated buffer log item is pushed from the
10 # CIL (i.e., when the log is subsequently flushed).
11 #
12 #-----------------------------------------------------------------------
13 # Copyright (c) 2016 Red Hat, Inc.  All Rights Reserved.
14 #
15 # This program is free software; you can redistribute it and/or
16 # modify it under the terms of the GNU General Public License as
17 # published by the Free Software Foundation.
18 #
19 # This program is distributed in the hope that it would be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 # GNU General Public License for more details.
23 #
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write the Free Software Foundation,
26 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
27 #-----------------------------------------------------------------------
28 #
29
30 seq=`basename $0`
31 seqres=$RESULT_DIR/$seq
32 echo "QA output created by $seq"
33
34 here=`pwd`
35 tmp=/tmp/$$
36 status=1        # failure is the default!
37 trap "_cleanup; exit \$status" 0 1 2 3 15
38
39 _cleanup()
40 {
41         cd /
42         rm -f $tmp.*
43 }
44
45 # get standard environment, filters and checks
46 . ./common/rc
47
48 # Modify as appropriate.
49 _supported_fs xfs
50 _supported_os Linux
51
52 _require_scratch_nocheck        # check complains about single AG fs
53 _require_xfs_io_command "fpunch"
54 _require_command $UUIDGEN_PROG uuidgen
55
56 rm -f $seqres.full
57
58 # Create a small fs with a large directory block size. We want to fill up the fs
59 # quickly and then create multi-fsb dirblocks over fragmented free space.
60 _scratch_mkfs_xfs -d size=20m -n size=64k >> $seqres.full 2>&1
61 _scratch_mount
62
63 # Fill a source directory with many largish-named files. 1k uuid-named entries
64 # sufficiently populates a 64k directory block.
65 mkdir $SCRATCH_MNT/src
66 for i in $(seq 0 1023); do
67         touch $SCRATCH_MNT/src/`$UUIDGEN_PROG`
68 done
69
70 # precreate target dirs while we still have free space for inodes
71 for i in $(seq 0 3); do
72         mkdir $SCRATCH_MNT/$i
73 done
74
75 # consume and fragment free space
76 $XFS_IO_PROG -xc "resblks 16" $SCRATCH_MNT >> $seqres.full 2>&1
77 dd if=/dev/zero of=$SCRATCH_MNT/file bs=4k >> $seqres.full 2>&1
78 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/file >> $seqres.full 2>&1
79 size=`stat -c %s $SCRATCH_MNT/file`
80 for i in $(seq 0 8192 $size); do
81         $XFS_IO_PROG -c "fpunch $i 4k" $SCRATCH_MNT/file >> $seqres.full 2>&1
82 done
83
84 # Replicate the src dir several times into fragmented free space. After one or
85 # two dirs, we should have nothing but non-contiguous directory blocks.
86 for d in $(seq 0 3); do
87         for f in `ls -1 $SCRATCH_MNT/src`; do
88                 ln $SCRATCH_MNT/src/$f $SCRATCH_MNT/$d/$f
89         done
90 done
91
92 # Fragment the target dirs a bit. Remove a handful of entries from each to
93 # populate the best free space regions in the directory block headers. We want
94 # to populate these now so the subsequent unlinks have no reason to log the
95 # first block of the directory.
96 for d in $(seq 0 3); do
97         i=0
98         for f in `ls -U $SCRATCH_MNT/$d`; do
99                 if [ $i == 0 ]; then
100                         unlink $SCRATCH_MNT/$d/$f
101                 fi
102                 i=$(((i + 1) % 128))
103         done
104 done
105
106 # remount to flush and ensure subsequent operations allocate a new log item
107 _scratch_cycle_mount
108
109 # Unlink an entry towards the end of each dir and fsync. The unlink should only
110 # need to log the latter mappings of the 64k directory block. If the logging bug
111 # is present, this will crash!
112 for d in $(seq 0 3); do
113         f=`ls -U $SCRATCH_MNT/$d | tail -10 | head -n 1`
114         unlink $SCRATCH_MNT/$d/$f
115         $XFS_IO_PROG -c fsync $SCRATCH_MNT/$d
116 done
117
118 echo Silence is golden.
119
120 # success, all done
121 status=0
122 exit