generic: test for creating duplicate filenames in encrypted 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 _require_scratch
42 _require_test_program "feature"
43 _require_xfs_io_command "sync_range"
44
45 _scratch_mkfs >> $seqres.full 2>&1 || _fail "mkfs failed"
46 _scratch_mount
47
48 file=$SCRATCH_MNT/file
49 filesize=$((1024 * 1024 * 32))
50 pagesize=`$here/src/feature -s`
51 truncsize=$((filesize - pagesize))
52
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
58
59         # create a small enough delalloc extent to likely be contiguous
60         $XFS_IO_PROG -c "pwrite 0 $filesize" $file >> $seqres.full 2>&1
61
62         # Start writeback and a racing truncate and rewrite of the final page.
63         $XFS_IO_PROG -c "sync_range -w 0 0" $file &
64         sync_pid=$!
65         $XFS_IO_PROG -c "truncate $truncsize" \
66                      -c "pwrite $truncsize $pagesize" $file >> $seqres.full 2>&1
67
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.
71         wait $sync_pid
72         _scratch_cycle_mount
73 done
74
75 echo Silence is golden
76
77 # success, all done
78 status=0
79 exit