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
35 _require_scratch_reflink
36 _require_dm_target flakey
40 _scratch_mkfs >>$seqres.full 2>&1
41 _require_metadata_journaling $SCRATCH_DEV
45 # Create our test file with two 256Kb extents, one at file offset 0 and the
46 # other at file offset 256Kb.
47 $XFS_IO_PROG -f -c "pwrite -S 0xa3 0 256K" \
49 -c "pwrite -S 0xc7 256K 256K" \
50 $SCRATCH_MNT/foobar | _filter_xfs_io
52 # Now clone the second 64Kb of data from the second extent into file offset 0.
53 # After this we get that extent partially shared. Also fsync the file.
54 $XFS_IO_PROG -c "reflink $SCRATCH_MNT/foobar 320K 0K 64K" \
56 $SCRATCH_MNT/foobar | _filter_xfs_io
58 # Now COW the first 64Kb of data for that second extent. After this we no longer
59 # have the extent fully referenced - its second 64Kb of data are referenced at
60 # file offset 0 and its last 192Kb of data are referenced at file offset 320Kb.
61 # Fsync the file to make sure everything is durably persisted.
62 $XFS_IO_PROG -c "pwrite -S 0xe5 256K 64K" \
64 $SCRATCH_MNT/foobar | _filter_xfs_io
66 echo "File digest before power failure:"
67 _md5_checksum $SCRATCH_MNT/foobar
69 # Simulate a power failure and then check no data loss or corruption happened.
70 _flakey_drop_and_remount
72 echo "File digest after mount:"
73 _md5_checksum $SCRATCH_MNT/foobar