2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
7 # Test that if we truncate a file to a smaller size, then truncate it to its
8 # original size or a larger size, then fsyncing it and a power failure happens,
9 # the file will have the range [first_truncate_size, last_size[ with all bytes
10 # having a value of 0x00 if we read it the next time the filesystem is mounted.
12 # This test is motivated by a bug found in btrfs.
15 seqres=$RESULT_DIR/$seq
16 echo "QA output created by $seq"
18 status=1 # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
27 # get standard environment, filters and checks
32 # real QA test starts here
36 _require_dm_target flakey
38 # This test was motivated by an issue found in btrfs when the btrfs no-holes
39 # feature is enabled (introduced in kernel 3.14). So enable the feature if the
40 # fs being tested is btrfs.
41 if [ $FSTYP == "btrfs" ]; then
42 _require_btrfs_fs_feature "no_holes"
43 _require_btrfs_mkfs_feature "no-holes"
44 MKFS_OPTIONS="$MKFS_OPTIONS -O no-holes"
49 _scratch_mkfs >>$seqres.full 2>&1
50 _require_metadata_journaling $SCRATCH_DEV
54 # Create our test files and make sure everything is durably persisted.
55 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0 64K" \
56 -c "pwrite -S 0xbb 64K 61K" \
57 $SCRATCH_MNT/foo | _filter_xfs_io
58 $XFS_IO_PROG -f -c "pwrite -S 0xee 0 64K" \
59 -c "pwrite -S 0xff 64K 61K" \
60 $SCRATCH_MNT/bar | _filter_xfs_io
63 # Now truncate our file foo to a smaller size (64Kb) and then truncate it to the
64 # size it had before the shrinking truncate (125Kb). Then fsync our file. If a
65 # power failure happens after the fsync, we expect our file to have a size of
66 # 125Kb, with the first 64Kb of data having the value 0xaa and the second 61Kb
67 # of data having the value 0x00.
68 $XFS_IO_PROG -c "truncate 64K" \
73 # Do something similar to our file bar, but the first truncation sets the file
74 # size to 0 and the second truncation expands the size to the double of what it
76 $XFS_IO_PROG -c "truncate 0" \
81 _flakey_drop_and_remount
83 # We expect foo to have a size of 125Kb, the first 64Kb of data all having the
84 # value 0xaa and the remaining 61Kb to be a hole (all bytes with value 0x00).
85 echo "File foo content after log replay:"
86 od -t x1 $SCRATCH_MNT/foo
88 # We expect bar to have a size of 253Kb and no extents (any byte read from bar
89 # has the value 0x00).
90 echo "File bar content after log replay:"
91 od -t x1 $SCRATCH_MNT/bar