generic/520: Remove sync in clean_dir
[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 seq=`basename $0`
17 seqres=$RESULT_DIR/$seq
18 echo "QA output created by $seq"
19
20 here=`pwd`
21 tmp=/tmp/$$
22 status=1        # failure is the default!
23 trap "_cleanup; exit \$status" 0 1 2 3 15
24
25 _cleanup()
26 {
27         cd /
28         rm -f $tmp.*
29 }
30
31 # get standard environment, filters and checks
32 . ./common/rc
33
34 # remove previous $seqres.full before test
35 rm -f $seqres.full
36
37 # real QA test starts here
38
39 # Modify as appropriate.
40 _supported_fs generic
41 _supported_os Linux
42 _require_scratch
43 _require_test_program "feature"
44 _require_xfs_io_command "sync_range"
45
46 _scratch_mkfs >> $seqres.full 2>&1 || _fail "mkfs failed"
47 _scratch_mount
48
49 file=$SCRATCH_MNT/file
50 filesize=$((1024 * 1024 * 32))
51 pagesize=`$here/src/feature -s`
52 truncsize=$((filesize - pagesize))
53
54 for i in $(seq 0 15); do
55         # Truncate the file and fsync to persist the final size on-disk. This is
56         # required so the subsequent truncate will not wait on writeback.
57         $XFS_IO_PROG -fc "truncate 0" $file
58         $XFS_IO_PROG -c "truncate $filesize" -c fsync $file
59
60         # create a small enough delalloc extent to likely be contiguous
61         $XFS_IO_PROG -c "pwrite 0 $filesize" $file >> $seqres.full 2>&1
62
63         # Start writeback and a racing truncate and rewrite of the final page.
64         $XFS_IO_PROG -c "sync_range -w 0 0" $file &
65         sync_pid=$!
66         $XFS_IO_PROG -c "truncate $truncsize" \
67                      -c "pwrite $truncsize $pagesize" $file >> $seqres.full 2>&1
68
69         # If the test fails, the most likely outcome is an sb_fdblocks mismatch
70         # and/or an associated delalloc assert failure on inode reclaim. Cycle
71         # the mount to trigger detection.
72         wait $sync_pid
73         _scratch_cycle_mount
74 done
75
76 echo Silence is golden
77
78 # success, all done
79 status=0
80 exit