generic: test for non-zero used blocks while writing into a file
[xfstests-dev.git] / tests / generic / 542
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0+
3 # Copyright (c) 2019, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 542
6 #
7 # Ensuring that reflinking works when the destination range covers multiple
8 # extents, some unwritten, some not:
9 #
10 #   - Create a file with the following repeating sequence of blocks:
11 #     1. reflinked
12 #     2. unwritten
13 #     3. hole
14 #     4. regular block
15 #     5. delalloc
16 #   - reflink across the halfway mark, starting with the unwritten extent.
17 #   - Check that the files are now different where we say they're different.
18 #
19 seq=`basename $0`
20 seqres=$RESULT_DIR/$seq
21 echo "QA output created by $seq"
22
23 here=`pwd`
24 tmp=/tmp/$$
25 status=1    # failure is the default!
26 trap "_cleanup; exit \$status" 0 1 2 3 15
27
28 _cleanup()
29 {
30         cd /
31         rm -rf $tmp.*
32 }
33
34 # get standard environment, filters and checks
35 . ./common/rc
36 . ./common/filter
37 . ./common/reflink
38
39 # real QA test starts here
40 _supported_fs generic
41 _require_scratch_reflink
42 _require_xfs_io_command "falloc"
43
44 rm -f $seqres.full
45
46 echo "Format and mount"
47 _scratch_mkfs > $seqres.full 2>&1
48 _scratch_mount >> $seqres.full 2>&1
49
50 testdir=$SCRATCH_MNT/test-$seq
51 mkdir $testdir
52
53 echo "Create the original files"
54 blksz=65536
55 nr=64
56 filesize=$((blksz * nr))
57 _pwrite_byte 0x64 0 $((blksz * nr)) $testdir/file2 >> $seqres.full
58 _weave_reflink_rainbow $blksz $nr $testdir/file1 $testdir/file3 >> $seqres.full
59 _scratch_cycle_mount
60
61 echo "Compare files"
62 md5sum $testdir/file1 | _filter_scratch
63 md5sum $testdir/file2 | _filter_scratch
64 md5sum $testdir/file3 | _filter_scratch
65 md5sum $testdir/file3.chk | _filter_scratch
66
67 echo "reflink across the transition"
68 soff=$((filesize / 4))
69 doff=$((filesize / 2))
70 rsz=$((filesize / 2))
71 _weave_reflink_rainbow_delalloc $blksz $nr $testdir/file3 >> $seqres.full
72
73 # now reflink into the rainbow
74 echo "before reflink" >> $seqres.full
75 $FILEFRAG_PROG -v $testdir/file2 >> $seqres.full 2>&1
76 $FILEFRAG_PROG -v $testdir/file3 >> $seqres.full 2>&1
77 $XFS_IO_PROG -f -c "reflink $testdir/file2 $soff $doff $rsz" $testdir/file3 >> $seqres.full
78 _pwrite_byte 0x64 $doff $rsz $testdir/file3.chk >> $seqres.full
79 _scratch_cycle_mount
80
81 echo "Compare files"
82 echo "after reflink" >> $seqres.full
83 $FILEFRAG_PROG -v $testdir/file2 >> $seqres.full 2>&1
84 $FILEFRAG_PROG -v $testdir/file3 >> $seqres.full 2>&1
85 md5sum $testdir/file1 | _filter_scratch
86 md5sum $testdir/file2 | _filter_scratch
87 md5sum $testdir/file3 | _filter_scratch
88 md5sum $testdir/file3.chk | _filter_scratch
89
90 # success, all done
91 status=0
92 exit