xfs: skip tests that rely on allocation behaviors of the data device
[xfstests-dev.git] / tests / xfs / 306
index 5af5aced27370a6cdb0006e76998efad9858245f..d2a0dd7f7e7fd8bbcd014c38f29898e2d394b70b 100755 (executable)
@@ -1,29 +1,17 @@
-#!/bin/bash
-# FS QA Test No. xfs/306
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2016 Red Hat, Inc.  All Rights Reserved.
 #
-# Basic log recovery stress test - do lots of stuff, shut down in the middle of
-# it and check that recovery runs to completion and everything can be
-# successfully removed afterwards..
+# FS QA Test No. 306
 #
-#-----------------------------------------------------------------------
-# Copyright (c) 2013 Red Hat, Inc.  All Rights Reserved.
+# Regression test for an XFS multi-block buffer logging bug.
 #
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation.
+# The XFS bug results in a panic when a non-contiguous multi-block buffer is
+# mapped and logged in a particular manner, such that only regions beyond the
+# first fsb-sized mapping are logged. The crash occurs asynchronous to
+# transaction submission, when the associated buffer log item is pushed from the
+# CIL (i.e., when the log is subsequently flushed).
 #
-# This program is distributed in the hope that it would be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write the Free Software Foundation,
-# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-#
-#-----------------------------------------------------------------------
-#
-
 seq=`basename $0`
 seqres=$RESULT_DIR/$seq
 echo "QA output created by $seq"
@@ -31,75 +19,90 @@ echo "QA output created by $seq"
 here=`pwd`
 tmp=/tmp/$$
 status=1       # failure is the default!
-
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
+trap "_cleanup; exit \$status" 0 1 2 3 15
 
 _cleanup()
 {
        cd /
-       umount $SCRATCH_MNT 2>/dev/null
        rm -f $tmp.*
 }
-trap "_cleanup; exit \$status" 0 1 2 3 15
 
-# real QA test starts here
+# get standard environment, filters and checks
+. ./common/rc
+
+# Modify as appropriate.
 _supported_fs xfs
 _supported_os Linux
 
-_require_scratch
-_require_scratch_shutdown
+_require_scratch_nocheck       # check complains about single AG fs
+_require_no_rtinherit
+_require_xfs_io_command "fpunch"
+_require_command $UUIDGEN_PROG uuidgen
 
 rm -f $seqres.full
 
-_scratch_mkfs > $seqres.full 2>&1
+# Create a small fs with a large directory block size. We want to fill up the fs
+# quickly and then create multi-fsb dirblocks over fragmented free space.
+_scratch_mkfs_xfs -d size=20m -n size=64k >> $seqres.full 2>&1
 _scratch_mount
 
-SLEEP_TIME=$((30 * $TIME_FACTOR))
-PROCS=$((2 * LOAD_FACTOR))
+# Fill a source directory with many largish-named files. 1k uuid-named entries
+# sufficiently populates a 64k directory block.
+mkdir $SCRATCH_MNT/src
+for i in $(seq 0 1023); do
+       touch $SCRATCH_MNT/src/`$UUIDGEN_PROG`
+done
 
-load_dir=$SCRATCH_MNT/test
+# precreate target dirs while we still have free space for inodes
+for i in $(seq 0 3); do
+       mkdir $SCRATCH_MNT/$i
+done
 
-# let this run for a while
-$FSSTRESS_PROG -n10000000 -p $PROCS -d $load_dir >> $seqres.full 2>&1 &
-sleep $SLEEP_TIME
-killall -q $FSSTRESS_PROG
-wait
-sync
-umount $SCRATCH_MNT
+# consume and fragment free space
+$XFS_IO_PROG -xc "resblks 16" $SCRATCH_MNT >> $seqres.full 2>&1
+dd if=/dev/zero of=$SCRATCH_MNT/file bs=4k >> $seqres.full 2>&1
+$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/file >> $seqres.full 2>&1
+size=`_get_filesize $SCRATCH_MNT/file`
+for i in $(seq 0 8192 $size); do
+       $XFS_IO_PROG -c "fpunch $i 4k" $SCRATCH_MNT/file >> $seqres.full 2>&1
+done
 
-# now mount again, run the load again, this time with a shutdown.
-_scratch_mount
-$XFS_FSR_PROG -v $load_dir >> $seqres.full 2>&1
-$FSSTRESS_PROG -n10000000 -p $PROCS -d $load_dir >> $seqres.full 2>&1 &
-sleep $SLEEP_TIME
-sync
-
-# now shutdown and unmount
-sleep 5
-$here/src/godown $load_dir
-killall -q $FSSTRESS_PROG
-wait
-
-# for some reason fsstress processes manage to live on beyond the wait?
-sleep 5
-umount $SCRATCH_MNT
-
-# now recover, check the filesystem for consistency
-_scratch_mount
-umount $SCRATCH_MNT
-_check_scratch_fs
+# Replicate the src dir several times into fragmented free space. After one or
+# two dirs, we should have nothing but non-contiguous directory blocks.
+for d in $(seq 0 3); do
+       for f in `ls -1 $SCRATCH_MNT/src`; do
+               ln $SCRATCH_MNT/src/$f $SCRATCH_MNT/$d/$f
+       done
+done
 
-# now clean up.
-_scratch_mount
-for d in $load_dir/*; do
-        rm -rf $d > /dev/null 2>&1 &
+# Fragment the target dirs a bit. Remove a handful of entries from each to
+# populate the best free space regions in the directory block headers. We want
+# to populate these now so the subsequent unlinks have no reason to log the
+# first block of the directory.
+for d in $(seq 0 3); do
+       i=0
+       for f in `ls -U $SCRATCH_MNT/$d`; do
+               if [ $i == 0 ]; then
+                       unlink $SCRATCH_MNT/$d/$f
+               fi
+               i=$(((i + 1) % 128))
+       done
+done
+
+# remount to flush and ensure subsequent operations allocate a new log item
+_scratch_cycle_mount
+
+# Unlink an entry towards the end of each dir and fsync. The unlink should only
+# need to log the latter mappings of the 64k directory block. If the logging bug
+# is present, this will crash!
+for d in $(seq 0 3); do
+       f=`ls -U $SCRATCH_MNT/$d | tail -10 | head -n 1`
+       unlink $SCRATCH_MNT/$d/$f
+       $XFS_IO_PROG -c fsync $SCRATCH_MNT/$d
 done
-wait
-umount $SCRATCH_MNT
 
-echo "No output is good. Failures are loud."
+echo Silence is golden.
 
+# success, all done
 status=0
 exit