generic: test for file loss after mix of rename, fsync and inode eviction
[xfstests-dev.git] / tests / generic / 029
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2014 Red Hat, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. generic/029
6 #
7 # Test mapped writes against truncate down/up to ensure we get the data
8 # correctly written. This can expose data corruption bugs on filesystems where
9 # the block size is smaller than the page size.
10 #
11 . ./common/preamble
12 _begin_fstest auto quick rw
13
14 # Import common functions.
15 . ./common/filter
16
17 # real QA test starts here
18
19 # Modify as appropriate.
20 _supported_fs generic
21 _require_scratch
22
23 testfile=$SCRATCH_MNT/testfile
24
25 _scratch_mkfs > /dev/null 2>&1
26 _scratch_mount
27
28 # first case is just truncate down/truncate up to check that the mapped
29 # write after the truncate up is correctly handled.
30 $XFS_IO_PROG -t -f \
31 -c "truncate 5120"              `# truncate     |                        |` \
32 -c "pwrite -S 0x58 0 5120"      `# write        |XXXXXXXXXXXXXXXXXXXXXXXX|` \
33 -c "mmap -rw 0 5120"            `# mmap         |                        |` \
34 -c "mwrite -S 0x5a 2048 3072"   `# mwrite       |          ZZZZZZZZZZZZZZ|` \
35 -c "truncate 2048"              `# truncate dn  |         |` \
36 -c "truncate 5120"              `# truncate up  |                        |` \
37 -c "mwrite -S 0x59 2048 3072"   `# mwrite       |          YYYYYYYYYYYYYY|` \
38 -c "close"      \
39 $testfile | _filter_xfs_io
40
41 echo "==== Pre-Remount ==="
42 hexdump -C $testfile
43 _scratch_cycle_mount
44 echo "==== Post-Remount =="
45 hexdump -C $testfile
46
47 rm -f $testfile
48 sync
49
50 # second case is to do a mwrite between the truncate to a block on the
51 # same page we are truncating within the EOF. This checks that a mapped
52 # write between truncate down and truncate up a further mapped
53 # write to the same page into the new space doesn't result in data being lost.
54 $XFS_IO_PROG -t -f \
55 -c "truncate 5120"              `# truncate     |                        |` \
56 -c "pwrite -S 0x58 0 5120"      `# write        |XXXXXXXXXXXXXXXXXXXXXXXX|` \
57 -c "mmap -rw 0 5120"            `# mmap         |                        |` \
58 -c "mwrite -S 0x5a 2048 3072"   `# mwrite       |          ZZZZZZZZZZZZZZ|` \
59 -c "truncate 2048"              `# truncate dn  |         |` \
60 -c "mwrite -S 0x57 1024 1024"   `# mwrite       |     WWWWW              |` \
61 -c "truncate 5120"              `# truncate up  |                        |` \
62 -c "mwrite -S 0x59 2048 3072"   `# mwrite       |          YYYYYYYYYYYYYY|` \
63 -c "close"      \
64 $testfile | _filter_xfs_io
65  
66 echo "==== Pre-Remount ==="
67 hexdump -C $testfile
68 _scratch_cycle_mount
69 echo "==== Post-Remount =="
70 hexdump -C $testfile
71
72 # third case is the same as second case, just with non-1k aligned offsets and
73 # sizes.
74 $XFS_IO_PROG -t -f \
75 -c "truncate 5121"              `# truncate     |                        |` \
76 -c "pwrite -S 0x58 0 5121"      `# write        |XXXXXXXXXXXXXXXXXXXXXXXX|` \
77 -c "mmap -rw 0 5121"            `# mmap         |                        |` \
78 -c "mwrite -S 0x5a 2047 3071"   `# mwrite       |          ZZZZZZZZZZZZZZ|` \
79 -c "truncate 2047"              `# truncate dn  |         |` \
80 -c "mwrite -S 0x57 513 1025"    `# mwrite       |  WWWWW                 |` \
81 -c "truncate 5121"              `# truncate up  |                        |` \
82 -c "mwrite -S 0x59 2047 3071"   `# mwrite       |          YYYYYYYYYYYYYY|` \
83 -c "close"      \
84 $testfile | _filter_xfs_io
85  
86 echo "==== Pre-Remount ==="
87 hexdump -C $testfile
88 _scratch_cycle_mount
89 echo "==== Post-Remount =="
90 hexdump -C $testfile
91
92 status=0
93 exit
94