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 $XFS_IO_PROG -f -c "pwrite -S 0x18 9000K 6908K" $SCRATCH_MNT/foo >>$seqres.full
46 $XFS_IO_PROG -f -c "pwrite -S 0x20 2572K 156K" $SCRATCH_MNT/bar >>$seqres.full
48 # We clone from file foo into a range of file bar that overlaps the existing
49 # extent at file bar. The destination offset of the reflink operation matches
50 # the eof position of file bar minus 4Kb.
51 $XFS_IO_PROG -c "fsync" \
52 -c "reflink ${SCRATCH_MNT}/foo 0 2724K 15908K" \
54 $SCRATCH_MNT/bar >>$seqres.full
56 echo "File bar digest before power failure:"
57 md5sum $SCRATCH_MNT/bar | _filter_scratch
59 # Simulate a power failure and mount the filesystem to check that no file data
60 # was lost or corrupted.
61 _flakey_drop_and_remount
63 echo "File bar digest after power failure:"
64 md5sum $SCRATCH_MNT/bar | _filter_scratch