2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016 Red Hat, Inc. All Rights Reserved.
7 # Regression test for an XFS multi-block buffer logging bug.
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).
16 _begin_fstest auto quick punch
18 # Import common functions.
20 # Modify as appropriate.
23 _require_scratch_nocheck # check complains about single AG fs
24 _require_xfs_io_command "fpunch"
25 _require_command $UUIDGEN_PROG uuidgen
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.
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
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`
43 # precreate target dirs while we still have free space for inodes
44 for i in $(seq 0 3); do
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
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
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
71 for f in `ls -U $SCRATCH_MNT/$d`; do
73 unlink $SCRATCH_MNT/$d/$f
79 # remount to flush and ensure subsequent operations allocate a new log item
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
91 echo Silence is golden.