2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2018 SUSE Linux Products GmbH. All Rights Reserved.
7 # Test that fsync operations preserve extents allocated with fallocate(2) that
8 # are placed beyond a file's size.
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
14 status=1 # failure is the default!
15 trap "_cleanup; exit \$status" 0 1 2 3 15
24 # get standard environment, filters and checks
30 # real QA test starts here
33 _require_dm_target flakey
34 _require_xfs_io_command "falloc" "-k"
35 _require_xfs_io_command "fiemap"
39 _scratch_mkfs >>$seqres.full 2>&1
40 _require_metadata_journaling $SCRATCH_DEV
44 # Create our test files.
45 $XFS_IO_PROG -f -c "pwrite -S 0xea 0 256K" $SCRATCH_MNT/foo >/dev/null
47 # Create a file with many extents. We later want to shrink truncate it and
48 # add a prealloc extent beyond its new size.
49 for ((i = 1; i <= 500; i++)); do
50 offset=$(((i - 1) * 4 * 1024))
51 $XFS_IO_PROG -f -s -c "pwrite -S 0xcf $offset 4K" \
52 $SCRATCH_MNT/bar >/dev/null
55 # A file which already has a prealloc extent beyond its size.
56 # The fsync done on it is motivated by differences in the btrfs implementation
57 # of fsync (first fsync has different logic from subsequent fsyncs).
58 $XFS_IO_PROG -f -c "pwrite -S 0xf1 0 256K" \
59 -c "falloc -k 256K 768K" \
61 $SCRATCH_MNT/baz >/dev/null
63 # Make sure everything done so far is durably persisted.
66 # Allocate an extent beyond the size of the first test file and fsync it.
67 $XFS_IO_PROG -c "falloc -k 256K 1M"\
71 # Do a shrinking truncate of our test file, add a prealloc extent to it after
72 # its new size and fsync it.
73 $XFS_IO_PROG -c "truncate 256K" \
74 -c "falloc -k 256K 1M"\
78 # Allocate another extent beyond the size of file baz.
79 $XFS_IO_PROG -c "falloc -k 1M 2M"\
83 # Simulate a power failure and mount the filesystem to check that the extents
84 # previously allocated were not lost and the file sizes are correct.
85 _flakey_drop_and_remount
87 echo "File foo fiemap:"
88 $XFS_IO_PROG -c "fiemap -v" $SCRATCH_MNT/foo | _filter_hole_fiemap
90 stat --format %s $SCRATCH_MNT/foo
92 echo "File bar fiemap:"
93 $XFS_IO_PROG -c "fiemap -v" $SCRATCH_MNT/bar | _filter_hole_fiemap
95 stat --format %s $SCRATCH_MNT/bar
97 echo "File baz fiemap:"
98 $XFS_IO_PROG -c "fiemap -v" $SCRATCH_MNT/baz | _filter_hole_fiemap
100 stat --format %s $SCRATCH_MNT/baz