overlay: run unionmount testsuite test cases
[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 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
14
15 here=`pwd`
16 tmp=/tmp/$$
17 status=1        # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
19
20 _cleanup()
21 {
22     cd /
23     rm -f $tmp.*
24 }
25
26 # get standard environment, filters and checks
27 . ./common/rc
28 . ./common/filter
29
30 # real QA test starts here
31
32 # Modify as appropriate.
33 _supported_fs generic
34 _supported_os Linux
35 _require_scratch
36
37 testfile=$SCRATCH_MNT/testfile
38
39 _scratch_mkfs > /dev/null 2>&1
40 _scratch_mount
41
42 # first case is just truncate down/truncate up to check that the mapped
43 # write after the truncate up is correctly handled.
44 $XFS_IO_PROG -t -f \
45 -c "truncate 5120"              `# truncate     |                        |` \
46 -c "pwrite -S 0x58 0 5120"      `# write        |XXXXXXXXXXXXXXXXXXXXXXXX|` \
47 -c "mmap -rw 0 5120"            `# mmap         |                        |` \
48 -c "mwrite -S 0x5a 2048 3072"   `# mwrite       |          ZZZZZZZZZZZZZZ|` \
49 -c "truncate 2048"              `# truncate dn  |         |` \
50 -c "truncate 5120"              `# truncate up  |                        |` \
51 -c "mwrite -S 0x59 2048 3072"   `# mwrite       |          YYYYYYYYYYYYYY|` \
52 -c "close"      \
53 $testfile | _filter_xfs_io
54
55 echo "==== Pre-Remount ==="
56 hexdump -C $testfile
57 _scratch_cycle_mount
58 echo "==== Post-Remount =="
59 hexdump -C $testfile
60
61 rm -f $testfile
62 sync
63
64 # second case is to do a mwrite between the truncate to a block on the
65 # same page we are truncating within the EOF. This checks that a mapped
66 # write between truncate down and truncate up a further mapped
67 # write to the same page into the new space doesn't result in data being lost.
68 $XFS_IO_PROG -t -f \
69 -c "truncate 5120"              `# truncate     |                        |` \
70 -c "pwrite -S 0x58 0 5120"      `# write        |XXXXXXXXXXXXXXXXXXXXXXXX|` \
71 -c "mmap -rw 0 5120"            `# mmap         |                        |` \
72 -c "mwrite -S 0x5a 2048 3072"   `# mwrite       |          ZZZZZZZZZZZZZZ|` \
73 -c "truncate 2048"              `# truncate dn  |         |` \
74 -c "mwrite -S 0x57 1024 1024"   `# mwrite       |     WWWWW              |` \
75 -c "truncate 5120"              `# truncate up  |                        |` \
76 -c "mwrite -S 0x59 2048 3072"   `# mwrite       |          YYYYYYYYYYYYYY|` \
77 -c "close"      \
78 $testfile | _filter_xfs_io
79  
80 echo "==== Pre-Remount ==="
81 hexdump -C $testfile
82 _scratch_cycle_mount
83 echo "==== Post-Remount =="
84 hexdump -C $testfile
85
86 # third case is the same as second case, just with non-1k aligned offsets and
87 # sizes.
88 $XFS_IO_PROG -t -f \
89 -c "truncate 5121"              `# truncate     |                        |` \
90 -c "pwrite -S 0x58 0 5121"      `# write        |XXXXXXXXXXXXXXXXXXXXXXXX|` \
91 -c "mmap -rw 0 5121"            `# mmap         |                        |` \
92 -c "mwrite -S 0x5a 2047 3071"   `# mwrite       |          ZZZZZZZZZZZZZZ|` \
93 -c "truncate 2047"              `# truncate dn  |         |` \
94 -c "mwrite -S 0x57 513 1025"    `# mwrite       |  WWWWW                 |` \
95 -c "truncate 5121"              `# truncate up  |                        |` \
96 -c "mwrite -S 0x59 2047 3071"   `# mwrite       |          YYYYYYYYYYYYYY|` \
97 -c "close"      \
98 $testfile | _filter_xfs_io
99  
100 echo "==== Pre-Remount ==="
101 hexdump -C $testfile
102 _scratch_cycle_mount
103 echo "==== Post-Remount =="
104 hexdump -C $testfile
105
106 status=0
107 exit
108