generic: test for file loss after mix of rename, fsync and inode eviction
[xfstests-dev.git] / tests / generic / 524
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017-2019 Red Hat, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 524
6 #
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.
15
16 . ./common/preamble
17 _begin_fstest auto quick
18
19 # Import common functions.
20
21 # real QA test starts here
22
23 # Modify as appropriate.
24 _supported_fs generic
25 _require_scratch
26 _require_test_program "feature"
27 _require_xfs_io_command "sync_range"
28
29 _scratch_mkfs >> $seqres.full 2>&1 || _fail "mkfs failed"
30 _scratch_mount
31
32 file=$SCRATCH_MNT/file
33 filesize=$((1024 * 1024 * 32))
34 pagesize=`$here/src/feature -s`
35 truncsize=$((filesize - pagesize))
36
37 for i in $(seq 0 15); do
38         # Truncate the file and fsync to persist the final size on-disk. This is
39         # required so the subsequent truncate will not wait on writeback.
40         $XFS_IO_PROG -fc "truncate 0" $file
41         $XFS_IO_PROG -c "truncate $filesize" -c fsync $file
42
43         # create a small enough delalloc extent to likely be contiguous
44         $XFS_IO_PROG -c "pwrite 0 $filesize" $file >> $seqres.full 2>&1
45
46         # Start writeback and a racing truncate and rewrite of the final page.
47         $XFS_IO_PROG -c "sync_range -w 0 0" $file &
48         sync_pid=$!
49         $XFS_IO_PROG -c "truncate $truncsize" \
50                      -c "pwrite $truncsize $pagesize" $file >> $seqres.full 2>&1
51
52         # If the test fails, the most likely outcome is an sb_fdblocks mismatch
53         # and/or an associated delalloc assert failure on inode reclaim. Cycle
54         # the mount to trigger detection.
55         wait $sync_pid
56         _scratch_cycle_mount
57 done
58
59 echo Silence is golden
60
61 # success, all done
62 status=0
63 exit