common/rc: add _scratch_{u}mount_idmapped() helpers
[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 _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 # Create our test file with two 256Kb extents, one at file offset 0 and the
45 # other at file offset 256Kb.
46 $XFS_IO_PROG -f -c "pwrite -S 0xa3 0 256K" \
47              -c "fsync" \
48              -c "pwrite -S 0xc7 256K 256K" \
49              $SCRATCH_MNT/foobar | _filter_xfs_io
50
51 # Now clone the second 64Kb of data from the second extent into file offset 0.
52 # After this we get that extent partially shared. Also fsync the file.
53 $XFS_IO_PROG -c "reflink $SCRATCH_MNT/foobar 320K 0K 64K" \
54              -c "fsync" \
55              $SCRATCH_MNT/foobar | _filter_xfs_io
56
57 # Now COW the first 64Kb of data for that second extent. After this we no longer
58 # have the extent fully referenced - its second 64Kb of data are referenced at
59 # file offset 0 and its last 192Kb of data are referenced at file offset 320Kb.
60 # Fsync the file to make sure everything is durably persisted.
61 $XFS_IO_PROG -c "pwrite -S 0xe5 256K 64K" \
62              -c "fsync" \
63              $SCRATCH_MNT/foobar | _filter_xfs_io
64
65 echo "File digest before power failure:"
66 _md5_checksum $SCRATCH_MNT/foobar
67
68 # Simulate a power failure and then check no data loss or corruption happened.
69 _flakey_drop_and_remount
70
71 echo "File digest after mount:"
72 _md5_checksum $SCRATCH_MNT/foobar
73
74 _unmount_flakey
75 status=0
76 exit