ee0e4b400c71a3affaf74b565e2476db1542ac87
[xfstests-dev.git] / tests / generic / 042
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. 042
6 #
7 # Test stale data exposure via writeback using various file allocation
8 # modification commands. The presumption is that such commands result in partial
9 # writeback and can convert a delayed allocation extent, that might be larger
10 # than the ranged affected by fallocate, to a normal extent. If the fs happens
11 # to crash sometime between when the extent modification is logged and writeback
12 # occurs for dirty pages within the extent but outside of the fallocated range,
13 # stale data exposure can occur.
14 #
15 seq=`basename $0`
16 seqres=$RESULT_DIR/$seq
17 echo "QA output created by $seq"
18
19 here=`pwd`
20 tmp=/tmp/$$
21 status=1        # failure is the default!
22 trap "_cleanup; exit \$status" 0 1 2 3 15
23
24 _cleanup()
25 {
26         cd /
27         rm -f $tmp.*
28 }
29
30 # get standard environment, filters and checks
31 . ./common/rc
32 . ./common/filter
33 . ./common/punch
34
35 # real QA test starts here
36 rm -f $seqres.full
37
38 _crashtest()
39 {
40         cmd=$1
41         img=$SCRATCH_MNT/$seq.img
42         mnt=$SCRATCH_MNT/$seq.mnt
43         file=$mnt/file
44         size=25M
45
46         # 25M is too small for f2fs.
47         if [ $FSTYP == "f2fs" ]; then
48                 size=38M
49         fi
50
51         # Create an fs on a small, initialized image. The pattern is written to
52         # the image to detect stale data exposure.
53         $XFS_IO_PROG -f -c "truncate 0" -c "pwrite -S 0xCD 0 $size" $img \
54                 >> $seqres.full 2>&1
55         _mkfs_dev $img >> $seqres.full 2>&1
56
57         mkdir -p $mnt
58         _mount $img $mnt
59
60         echo $cmd
61
62         # write, run the test command and shutdown the fs
63         $XFS_IO_PROG -f -c "pwrite -S 1 0 64k" -c "$cmd 60k 4k" $file | \
64                 _filter_xfs_io
65         $here/src/godown -f $mnt
66
67         $UMOUNT_PROG $mnt
68         _mount $img $mnt
69
70         # We should /never/ see 0xCD in the file, because we wrote that pattern
71         # to the filesystem image to expose stale data.
72         if hexdump -v -e '/1 "%02X "' $file | grep -q "CD"; then
73                 echo "Saw stale data!!!"
74                 hexdump $file
75         fi
76
77         $UMOUNT_PROG $mnt
78 }
79
80 # Modify as appropriate.
81 _supported_fs generic
82 _require_scratch
83 _require_scratch_shutdown
84 _require_xfs_io_command "falloc"
85 _require_xfs_io_command "fpunch"
86 _require_xfs_io_command "fzero"
87
88 _scratch_mkfs >/dev/null 2>&1
89 _require_local_device $SCRATCH_DEV
90 _require_metadata_journaling $SCRATCH_DEV
91 _scratch_mount
92
93 _crashtest "falloc -k"
94 _crashtest "fpunch"
95 _crashtest "fzero -k"
96
97 status=0
98 exit