fstests: move test group info to test files
[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 . ./common/preamble
16 _begin_fstest auto quick punch
17
18 # Import common functions.
19
20 # Modify as appropriate.
21 _supported_fs xfs
22
23 _require_scratch_nocheck        # check complains about single AG fs
24 _require_xfs_io_command "fpunch"
25 _require_command $UUIDGEN_PROG uuidgen
26
27 # Disable the scratch rt device to avoid test failures relating to the rt
28 # bitmap consuming all the free space in our small data device.
29 unset SCRATCH_RTDEV
30
31 # Create a small fs with a large directory block size. We want to fill up the fs
32 # quickly and then create multi-fsb dirblocks over fragmented free space.
33 _scratch_mkfs_xfs -d size=20m -n size=64k >> $seqres.full 2>&1
34 _scratch_mount
35
36 # Fill a source directory with many largish-named files. 1k uuid-named entries
37 # sufficiently populates a 64k directory block.
38 mkdir $SCRATCH_MNT/src
39 for i in $(seq 0 1023); do
40         touch $SCRATCH_MNT/src/`$UUIDGEN_PROG`
41 done
42
43 # precreate target dirs while we still have free space for inodes
44 for i in $(seq 0 3); do
45         mkdir $SCRATCH_MNT/$i
46 done
47
48 # consume and fragment free space
49 $XFS_IO_PROG -xc "resblks 16" $SCRATCH_MNT >> $seqres.full 2>&1
50 dd if=/dev/zero of=$SCRATCH_MNT/file bs=4k >> $seqres.full 2>&1
51 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/file >> $seqres.full 2>&1
52 size=`_get_filesize $SCRATCH_MNT/file`
53 for i in $(seq 0 8192 $size); do
54         $XFS_IO_PROG -c "fpunch $i 4k" $SCRATCH_MNT/file >> $seqres.full 2>&1
55 done
56
57 # Replicate the src dir several times into fragmented free space. After one or
58 # two dirs, we should have nothing but non-contiguous directory blocks.
59 for d in $(seq 0 3); do
60         for f in `ls -1 $SCRATCH_MNT/src`; do
61                 ln $SCRATCH_MNT/src/$f $SCRATCH_MNT/$d/$f
62         done
63 done
64
65 # Fragment the target dirs a bit. Remove a handful of entries from each to
66 # populate the best free space regions in the directory block headers. We want
67 # to populate these now so the subsequent unlinks have no reason to log the
68 # first block of the directory.
69 for d in $(seq 0 3); do
70         i=0
71         for f in `ls -U $SCRATCH_MNT/$d`; do
72                 if [ $i == 0 ]; then
73                         unlink $SCRATCH_MNT/$d/$f
74                 fi
75                 i=$(((i + 1) % 128))
76         done
77 done
78
79 # remount to flush and ensure subsequent operations allocate a new log item
80 _scratch_cycle_mount
81
82 # Unlink an entry towards the end of each dir and fsync. The unlink should only
83 # need to log the latter mappings of the 64k directory block. If the logging bug
84 # is present, this will crash!
85 for d in $(seq 0 3); do
86         f=`ls -U $SCRATCH_MNT/$d | tail -10 | head -n 1`
87         unlink $SCRATCH_MNT/$d/$f
88         $XFS_IO_PROG -c fsync $SCRATCH_MNT/$d
89 done
90
91 echo Silence is golden.
92
93 # success, all done
94 status=0
95 exit