generic: test MADV_POPULATE_READ with IO errors
[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 . ./common/preamble
16 _begin_fstest shutdown rw punch zero
17
18 # Import common functions.
19 . ./common/filter
20 . ./common/punch
21
22 # real QA test starts here
23
24 _crashtest()
25 {
26         cmd=$1
27         img=$SCRATCH_MNT/$seq.img
28         mnt=$SCRATCH_MNT/$seq.mnt
29         file=$mnt/file
30         size=25M
31
32         # f2fs-utils 1.9.0 needs at least 38 MB space for f2fs image. However,
33         # f2fs-utils 1.14.0 needs at least 52 MB. Not sure if it will change
34         # again. So just set it 128M.
35         if [ $FSTYP == "f2fs" ]; then
36                 size=128M
37         fi
38
39         # Create an fs on a small, initialized image. The pattern is written to
40         # the image to detect stale data exposure.
41         $XFS_IO_PROG -f -c "truncate 0" -c "pwrite -S 0xCD 0 $size" $img \
42                 >> $seqres.full 2>&1
43         _mkfs_dev $img >> $seqres.full 2>&1
44
45         mkdir -p $mnt
46         _mount $img $mnt
47
48         echo $cmd
49
50         # write, run the test command and shutdown the fs
51         $XFS_IO_PROG -f -c "pwrite -S 1 0 64k" -c "$cmd 60k 4k" $file | \
52                 _filter_xfs_io
53         $here/src/godown -f $mnt
54
55         $UMOUNT_PROG $mnt
56         _mount $img $mnt
57
58         # We should /never/ see 0xCD in the file, because we wrote that pattern
59         # to the filesystem image to expose stale data.
60         if od -An -tx1 $file | grep -q "CD"; then
61                 echo "Saw stale data!!!"
62                 _hexdump $file
63         fi
64
65         $UMOUNT_PROG $mnt
66 }
67
68 # Modify as appropriate.
69 _supported_fs generic
70 _require_scratch
71 _require_scratch_shutdown
72 _require_xfs_io_command "falloc"
73 _require_xfs_io_command "fpunch"
74 _require_xfs_io_command "fzero"
75
76 _scratch_mkfs >/dev/null 2>&1
77 _require_local_device $SCRATCH_DEV
78 _require_metadata_journaling $SCRATCH_DEV
79 _scratch_mount
80
81 _crashtest "falloc -k"
82 _crashtest "fpunch"
83 _crashtest "fzero -k"
84
85 status=0
86 exit