generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / generic / 483
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2018 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FSQA Test No. 483
6 #
7 # Test that fsync operations preserve extents allocated with fallocate(2) that
8 # are placed beyond a file's size.
9 #
10 . ./common/preamble
11 _begin_fstest auto quick log metadata
12
13 # Override the default cleanup function.
14 _cleanup()
15 {
16         _cleanup_flakey
17         cd /
18         rm -f $tmp.*
19 }
20
21 # Import common functions.
22 . ./common/filter
23 . ./common/dmflakey
24 . ./common/punch
25
26 # real QA test starts here
27 _supported_fs generic
28 _require_scratch
29 _require_dm_target flakey
30 _require_xfs_io_command "falloc" "-k"
31 _require_xfs_io_command "fiemap"
32
33 _scratch_mkfs >>$seqres.full 2>&1
34 _require_metadata_journaling $SCRATCH_DEV
35 _init_flakey
36 _mount_flakey
37
38 # Create our test files.
39 $XFS_IO_PROG -f -c "pwrite -S 0xea 0 256K" $SCRATCH_MNT/foo >/dev/null
40
41 # Create a file with many extents. We later want to shrink truncate it and
42 # add a prealloc extent beyond its new size.
43 for ((i = 1; i <= 500; i++)); do
44         offset=$(((i - 1) * 4 * 1024))
45         $XFS_IO_PROG -f -s -c "pwrite -S 0xcf $offset 4K" \
46                 $SCRATCH_MNT/bar >/dev/null
47 done
48
49 # A file which already has a prealloc extent beyond its size.
50 # The fsync done on it is motivated by differences in the btrfs implementation
51 # of fsync (first fsync has different logic from subsequent fsyncs).
52 $XFS_IO_PROG -f -c "pwrite -S 0xf1 0 256K" \
53              -c "falloc -k 256K 768K" \
54              -c "fsync" \
55              $SCRATCH_MNT/baz >/dev/null
56
57 # Make sure everything done so far is durably persisted.
58 sync
59
60 # Allocate an extent beyond the size of the first test file and fsync it.
61 $XFS_IO_PROG -c "falloc -k 256K 1M"\
62              -c "fsync" \
63              $SCRATCH_MNT/foo
64
65 # Do a shrinking truncate of our test file, add a prealloc extent to it after
66 # its new size and fsync it.
67 $XFS_IO_PROG -c "truncate 256K" \
68              -c "falloc -k 256K 1M"\
69              -c "fsync" \
70              $SCRATCH_MNT/bar
71
72 # Allocate another extent beyond the size of file baz.
73 $XFS_IO_PROG -c "falloc -k 1M 2M"\
74              -c "fsync" \
75              $SCRATCH_MNT/baz
76
77 # Simulate a power failure and mount the filesystem to check that the extents
78 # previously allocated were not lost and the file sizes are correct.
79 _flakey_drop_and_remount
80
81 echo "File foo fiemap:"
82 $XFS_IO_PROG -c "fiemap -v" $SCRATCH_MNT/foo | _filter_hole_fiemap
83 echo "File foo size:"
84 stat --format %s $SCRATCH_MNT/foo
85
86 echo "File bar fiemap:"
87 $XFS_IO_PROG -c "fiemap -v" $SCRATCH_MNT/bar | _filter_hole_fiemap
88 echo "File bar size:"
89 stat --format %s $SCRATCH_MNT/bar
90
91 echo "File baz fiemap:"
92 $XFS_IO_PROG -c "fiemap -v" $SCRATCH_MNT/baz | _filter_hole_fiemap
93 echo "File baz size:"
94 stat --format %s $SCRATCH_MNT/baz
95
96 _unmount_flakey
97 _cleanup_flakey
98
99 status=0
100 exit