2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2019 SUSE Linux Products GmbH. All Rights Reserved.
7 # Test that if we clone part of an extent from a file to itself at different
8 # offset, fsync it, rewrite (COW) part of the extent from the former offset,
9 # fsync it again, power fail and then mount the filesystem, we are able to
10 # read the whole file and it has the correct data.
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
34 _require_scratch_reflink
35 _require_dm_target flakey
39 _scratch_mkfs >>$seqres.full 2>&1
40 _require_metadata_journaling $SCRATCH_DEV
44 # Create our test file with two 256Kb extents, one at file offset 0 and the
45 # other at file offset 256Kb.
46 $XFS_IO_PROG -f -c "pwrite -S 0xa3 0 256K" \
48 -c "pwrite -S 0xc7 256K 256K" \
49 $SCRATCH_MNT/foobar | _filter_xfs_io
51 # Now clone the second 64Kb of data from the second extent into file offset 0.
52 # After this we get that extent partially shared. Also fsync the file.
53 $XFS_IO_PROG -c "reflink $SCRATCH_MNT/foobar 320K 0K 64K" \
55 $SCRATCH_MNT/foobar | _filter_xfs_io
57 # Now COW the first 64Kb of data for that second extent. After this we no longer
58 # have the extent fully referenced - its second 64Kb of data are referenced at
59 # file offset 0 and its last 192Kb of data are referenced at file offset 320Kb.
60 # Fsync the file to make sure everything is durably persisted.
61 $XFS_IO_PROG -c "pwrite -S 0xe5 256K 64K" \
63 $SCRATCH_MNT/foobar | _filter_xfs_io
65 echo "File digest before power failure:"
66 _md5_checksum $SCRATCH_MNT/foobar
68 # Simulate a power failure and then check no data loss or corruption happened.
69 _flakey_drop_and_remount
71 echo "File digest after mount:"
72 _md5_checksum $SCRATCH_MNT/foobar