2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2018 SUSE Linux Products GmbH. All Rights Reserved.
7 # Test that if we do a buffered write to a file, fsync it, clone a range from
8 # another file into our file that overlaps the previously written range, fsync
9 # the file again and then power fail, after we mount again the filesystem, no
10 # file data was lost or corrupted.
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
16 status=1 # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
26 # get standard environment, filters and checks
32 # real QA test starts here
35 _require_scratch_reflink
36 _require_dm_target flakey
40 _scratch_mkfs >>$seqres.full 2>&1
41 _require_metadata_journaling $SCRATCH_DEV
45 # Use file sizes and offsets/lengths for the clone operation that are multiples
46 # of 64Kb, so that the test works on machine with any page size.
47 $XFS_IO_PROG -f -s -c "pwrite -S 0x18 0 2M" $SCRATCH_MNT/foo >>$seqres.full
48 $XFS_IO_PROG -f -s -c "pwrite -S 0x20 0 20M" $SCRATCH_MNT/bar >>$seqres.full
50 # We clone from file foo into a range of file bar that overlaps the existing
51 # extent at file bar. The clone operation must also extend the size of file bar.
52 # Note: in order to trigger the original bug on btrfs, the destination file size
53 # must be at least 16Mb and the destination file must have been fsynced before.
54 $XFS_IO_PROG -c "reflink ${SCRATCH_MNT}/foo 0 19M 2M" \
56 $SCRATCH_MNT/bar >>$seqres.full
58 echo "File bar digest before power failure:"
59 md5sum $SCRATCH_MNT/bar | _filter_scratch
61 # Simulate a power failure and mount the filesystem to check that no file data
62 # was lost or corrupted.
63 _flakey_drop_and_remount
65 echo "File bar digest after power failure:"
66 md5sum $SCRATCH_MNT/bar | _filter_scratch