xfs: fix old fuzz test invocations of xfs_repair
[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 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21         _cleanup_flakey
22         cd /
23         rm -f $tmp.*
24 }
25
26 # get standard environment, filters and checks
27 . ./common/rc
28 . ./common/filter
29 . ./common/reflink
30 . ./common/dmflakey
31
32 # real QA test starts here
33 _supported_fs generic
34 _require_scratch_reflink
35 _require_dm_target flakey
36
37 rm -f $seqres.full
38
39 _scratch_mkfs >>$seqres.full 2>&1
40 _require_metadata_journaling $SCRATCH_DEV
41 _init_flakey
42 _mount_flakey
43
44 # Use file sizes and offsets/lengths for the clone operation that are multiples
45 # of 64Kb, so that the test works on machine with any page size.
46 $XFS_IO_PROG -f -s -c "pwrite -S 0x18 0 2M" $SCRATCH_MNT/foo >>$seqres.full
47 $XFS_IO_PROG -f -s -c "pwrite -S 0x20 0 20M" $SCRATCH_MNT/bar >>$seqres.full
48
49 # We clone from file foo into a range of file bar that overlaps the existing
50 # extent at file bar. The clone operation must also extend the size of file bar.
51 # Note: in order to trigger the original bug on btrfs, the destination file size
52 # must be at least 16Mb and the destination file must have been fsynced before.
53 $XFS_IO_PROG -c "reflink ${SCRATCH_MNT}/foo 0 19M 2M" \
54              -c "fsync" \
55              $SCRATCH_MNT/bar >>$seqres.full
56
57 echo "File bar digest before power failure:"
58 md5sum $SCRATCH_MNT/bar | _filter_scratch
59
60 # Simulate a power failure and mount the filesystem to check that no file data
61 # was lost or corrupted.
62 _flakey_drop_and_remount
63
64 echo "File bar digest after power failure:"
65 md5sum $SCRATCH_MNT/bar | _filter_scratch
66
67 _unmount_flakey
68 _cleanup_flakey
69
70 status=0
71 exit