2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017-2019 Red Hat, Inc. All Rights Reserved.
7 # Test XFS page writeback code for races with the cached file mapping. XFS
8 # caches the file -> block mapping for a full extent once it is initially looked
9 # up. The cached mapping is used for all subsequent pages in the same writeback
10 # cycle that cover the associated extent. Under certain conditions, it is
11 # possible for concurrent operations on the file to invalidate the cached
12 # mapping without the knowledge of writeback. Writeback ends up sending I/O to a
13 # partly stale mapping and potentially leaving delalloc blocks in the current
14 # mapping unconverted.
17 seqres=$RESULT_DIR/$seq
18 echo "QA output created by $seq"
22 status=1 # failure is the default!
23 trap "_cleanup; exit \$status" 0 1 2 3 15
31 # get standard environment, filters and checks
34 # remove previous $seqres.full before test
37 # real QA test starts here
39 # Modify as appropriate.
42 _require_test_program "feature"
43 _require_xfs_io_command "sync_range"
45 _scratch_mkfs >> $seqres.full 2>&1 || _fail "mkfs failed"
48 file=$SCRATCH_MNT/file
49 filesize=$((1024 * 1024 * 32))
50 pagesize=`$here/src/feature -s`
51 truncsize=$((filesize - pagesize))
53 for i in $(seq 0 15); do
54 # Truncate the file and fsync to persist the final size on-disk. This is
55 # required so the subsequent truncate will not wait on writeback.
56 $XFS_IO_PROG -fc "truncate 0" $file
57 $XFS_IO_PROG -c "truncate $filesize" -c fsync $file
59 # create a small enough delalloc extent to likely be contiguous
60 $XFS_IO_PROG -c "pwrite 0 $filesize" $file >> $seqres.full 2>&1
62 # Start writeback and a racing truncate and rewrite of the final page.
63 $XFS_IO_PROG -c "sync_range -w 0 0" $file &
65 $XFS_IO_PROG -c "truncate $truncsize" \
66 -c "pwrite $truncsize $pagesize" $file >> $seqres.full 2>&1
68 # If the test fails, the most likely outcome is an sb_fdblocks mismatch
69 # and/or an associated delalloc assert failure on inode reclaim. Cycle
70 # the mount to trigger detection.
75 echo Silence is golden