fstests: use _require_symlinks on all necessary tests
[xfstests-dev.git] / tests / generic / 588
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2019 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FSQA Test No. 588
6 #
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.
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 _supported_os Linux
35 _require_scratch_reflink
36 _require_dm_target flakey
37
38 rm -f $seqres.full
39
40 _scratch_mkfs >>$seqres.full 2>&1
41 _require_metadata_journaling $SCRATCH_DEV
42 _init_flakey
43 _mount_flakey
44
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" \
48              -c "fsync" \
49              -c "pwrite -S 0xc7 256K 256K" \
50              $SCRATCH_MNT/foobar | _filter_xfs_io
51
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" \
55              -c "fsync" \
56              $SCRATCH_MNT/foobar | _filter_xfs_io
57
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" \
63              -c "fsync" \
64              $SCRATCH_MNT/foobar | _filter_xfs_io
65
66 echo "File digest before power failure:"
67 _md5_checksum $SCRATCH_MNT/foobar
68
69 # Simulate a power failure and then check no data loss or corruption happened.
70 _flakey_drop_and_remount
71
72 echo "File digest after mount:"
73 _md5_checksum $SCRATCH_MNT/foobar
74
75 _unmount_flakey
76 status=0
77 exit