fstests: move test group info to test files
[xfstests-dev.git] / tests / generic / 501
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2018 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. 501
6 #
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.
11 #
12 . ./common/preamble
13 _begin_fstest auto quick clone log
14
15 # Override the default cleanup function.
16 _cleanup()
17 {
18         _cleanup_flakey
19         cd /
20         rm -f $tmp.*
21 }
22
23 # Import common functions.
24 . ./common/filter
25 . ./common/reflink
26 . ./common/dmflakey
27
28 # real QA test starts here
29 _supported_fs generic
30 _require_scratch_reflink
31 _require_dm_target flakey
32
33 _scratch_mkfs >>$seqres.full 2>&1
34 _require_metadata_journaling $SCRATCH_DEV
35 _init_flakey
36 _mount_flakey
37
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
42
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" \
48              -c "fsync" \
49              $SCRATCH_MNT/bar >>$seqres.full
50
51 echo "File bar digest before power failure:"
52 md5sum $SCRATCH_MNT/bar | _filter_scratch
53
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
57
58 echo "File bar digest after power failure:"
59 md5sum $SCRATCH_MNT/bar | _filter_scratch
60
61 _unmount_flakey
62 _cleanup_flakey
63
64 status=0
65 exit