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 _begin_fstest auto quick log clone
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 # Create our test file with two 256Kb extents, one at file offset 0 and the
39 # other at file offset 256Kb.
40 $XFS_IO_PROG -f -c "pwrite -S 0xa3 0 256K" \
42 -c "pwrite -S 0xc7 256K 256K" \
43 $SCRATCH_MNT/foobar | _filter_xfs_io
45 # Now clone the second 64Kb of data from the second extent into file offset 0.
46 # After this we get that extent partially shared. Also fsync the file.
47 $XFS_IO_PROG -c "reflink $SCRATCH_MNT/foobar 320K 0K 64K" \
49 $SCRATCH_MNT/foobar | _filter_xfs_io
51 # Now COW the first 64Kb of data for that second extent. After this we no longer
52 # have the extent fully referenced - its second 64Kb of data are referenced at
53 # file offset 0 and its last 192Kb of data are referenced at file offset 320Kb.
54 # Fsync the file to make sure everything is durably persisted.
55 $XFS_IO_PROG -c "pwrite -S 0xe5 256K 64K" \
57 $SCRATCH_MNT/foobar | _filter_xfs_io
59 echo "File digest before power failure:"
60 _md5_checksum $SCRATCH_MNT/foobar
62 # Simulate a power failure and then check no data loss or corruption happened.
63 _flakey_drop_and_remount
65 echo "File digest after mount:"
66 _md5_checksum $SCRATCH_MNT/foobar