xfs: force file creation to the data device for certain layout tests
[xfstests-dev.git] / tests / xfs / 306
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016 Red Hat, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 306
6 #
7 # Regression test for an XFS multi-block buffer logging bug.
8 #
9 # The XFS bug results in a panic when a non-contiguous multi-block buffer is
10 # mapped and logged in a particular manner, such that only regions beyond the
11 # first fsb-sized mapping are logged. The crash occurs asynchronous to
12 # transaction submission, when the associated buffer log item is pushed from the
13 # CIL (i.e., when the log is subsequently flushed).
14 #
15 seq=`basename $0`
16 seqres=$RESULT_DIR/$seq
17 echo "QA output created by $seq"
18
19 here=`pwd`
20 tmp=/tmp/$$
21 status=1        # failure is the default!
22 trap "_cleanup; exit \$status" 0 1 2 3 15
23
24 _cleanup()
25 {
26         cd /
27         rm -f $tmp.*
28 }
29
30 # get standard environment, filters and checks
31 . ./common/rc
32
33 # Modify as appropriate.
34 _supported_fs xfs
35
36 _require_scratch_nocheck        # check complains about single AG fs
37 _require_xfs_io_command "fpunch"
38 _require_command $UUIDGEN_PROG uuidgen
39
40 rm -f $seqres.full
41
42 # Disable the scratch rt device to avoid test failures relating to the rt
43 # bitmap consuming all the free space in our small data device.
44 unset SCRATCH_RTDEV
45
46 # Create a small fs with a large directory block size. We want to fill up the fs
47 # quickly and then create multi-fsb dirblocks over fragmented free space.
48 _scratch_mkfs_xfs -d size=20m -n size=64k >> $seqres.full 2>&1
49 _scratch_mount
50
51 # Fill a source directory with many largish-named files. 1k uuid-named entries
52 # sufficiently populates a 64k directory block.
53 mkdir $SCRATCH_MNT/src
54 for i in $(seq 0 1023); do
55         touch $SCRATCH_MNT/src/`$UUIDGEN_PROG`
56 done
57
58 # precreate target dirs while we still have free space for inodes
59 for i in $(seq 0 3); do
60         mkdir $SCRATCH_MNT/$i
61 done
62
63 # consume and fragment free space
64 $XFS_IO_PROG -xc "resblks 16" $SCRATCH_MNT >> $seqres.full 2>&1
65 dd if=/dev/zero of=$SCRATCH_MNT/file bs=4k >> $seqres.full 2>&1
66 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/file >> $seqres.full 2>&1
67 size=`_get_filesize $SCRATCH_MNT/file`
68 for i in $(seq 0 8192 $size); do
69         $XFS_IO_PROG -c "fpunch $i 4k" $SCRATCH_MNT/file >> $seqres.full 2>&1
70 done
71
72 # Replicate the src dir several times into fragmented free space. After one or
73 # two dirs, we should have nothing but non-contiguous directory blocks.
74 for d in $(seq 0 3); do
75         for f in `ls -1 $SCRATCH_MNT/src`; do
76                 ln $SCRATCH_MNT/src/$f $SCRATCH_MNT/$d/$f
77         done
78 done
79
80 # Fragment the target dirs a bit. Remove a handful of entries from each to
81 # populate the best free space regions in the directory block headers. We want
82 # to populate these now so the subsequent unlinks have no reason to log the
83 # first block of the directory.
84 for d in $(seq 0 3); do
85         i=0
86         for f in `ls -U $SCRATCH_MNT/$d`; do
87                 if [ $i == 0 ]; then
88                         unlink $SCRATCH_MNT/$d/$f
89                 fi
90                 i=$(((i + 1) % 128))
91         done
92 done
93
94 # remount to flush and ensure subsequent operations allocate a new log item
95 _scratch_cycle_mount
96
97 # Unlink an entry towards the end of each dir and fsync. The unlink should only
98 # need to log the latter mappings of the 64k directory block. If the logging bug
99 # is present, this will crash!
100 for d in $(seq 0 3); do
101         f=`ls -U $SCRATCH_MNT/$d | tail -10 | head -n 1`
102         unlink $SCRATCH_MNT/$d/$f
103         $XFS_IO_PROG -c fsync $SCRATCH_MNT/$d
104 done
105
106 echo Silence is golden.
107
108 # success, all done
109 status=0
110 exit