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 _begin_fstest auto quick clone log
15 # Override the default cleanup function.
23 # Import common functions.
28 # real QA test starts here
30 _require_scratch_reflink
31 _require_dm_target flakey
33 _scratch_mkfs >>$seqres.full 2>&1
34 _require_metadata_journaling $SCRATCH_DEV
38 # Use file sizes and offsets/lengths for the clone operation that are multiples
39 # of 64Kb, so that the test works on machine with any page size.
40 $XFS_IO_PROG -f -s -c "pwrite -S 0x18 0 2M" $SCRATCH_MNT/foo >>$seqres.full
41 $XFS_IO_PROG -f -s -c "pwrite -S 0x20 0 20M" $SCRATCH_MNT/bar >>$seqres.full
43 # We clone from file foo into a range of file bar that overlaps the existing
44 # extent at file bar. The clone operation must also extend the size of file bar.
45 # Note: in order to trigger the original bug on btrfs, the destination file size
46 # must be at least 16Mb and the destination file must have been fsynced before.
47 $XFS_IO_PROG -c "reflink ${SCRATCH_MNT}/foo 0 19M 2M" \
49 $SCRATCH_MNT/bar >>$seqres.full
51 echo "File bar digest before power failure:"
52 md5sum $SCRATCH_MNT/bar | _filter_scratch
54 # Simulate a power failure and mount the filesystem to check that no file data
55 # was lost or corrupted.
56 _flakey_drop_and_remount
58 echo "File bar digest after power failure:"
59 md5sum $SCRATCH_MNT/bar | _filter_scratch