xfs: convert tests to SPDX license tags
[xfstests-dev.git] / tests / xfs / 228
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 228
6 #
7 # Ensuring that copy on write in direct-io mode works when the CoW
8 # range originally covers multiple extents, some unwritten, some not.
9 #   - Set cowextsize hint.
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 #   - directio CoW 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_os Linux
41 _require_scratch_reflink
42 _require_xfs_io_command "falloc"
43 _require_xfs_io_command "cowextsize"
44 _require_xfs_io_command "fpunch"
45 _require_cp_reflink
46 _require_odirect
47
48 rm -f $seqres.full
49
50 echo "Format and mount"
51 _scratch_mkfs > $seqres.full 2>&1
52 _scratch_mount >> $seqres.full 2>&1
53
54 testdir=$SCRATCH_MNT/test-$seq
55 mkdir $testdir
56
57 echo "Create the original files"
58 blksz=65536
59 nr=64
60 filesize=$((blksz * nr))
61 real_blksz=$(_get_block_size $testdir)
62 internal_blks=$((filesize / real_blksz))
63 $XFS_IO_PROG -c "cowextsize $((blksz * 16))" $testdir >> $seqres.full
64 _weave_reflink_rainbow $blksz $nr $testdir/file1 $testdir/file3 >> $seqres.full
65 _scratch_cycle_mount
66
67 echo "Compare files"
68 md5sum $testdir/file1 | _filter_scratch
69 md5sum $testdir/file3 | _filter_scratch
70 md5sum $testdir/file3.chk | _filter_scratch
71
72 echo "directio CoW across the transition"
73 cowoff=$((filesize / 4))
74 cowsz=$((filesize / 2))
75 _weave_reflink_rainbow_delalloc $blksz $nr $testdir/file3 >> $seqres.full
76 # now cow
77 $XFS_IO_PROG -d -f -c "pwrite -S 0x63 -b $cowsz $cowoff $cowsz" $testdir/file3 >> $seqres.full
78 _pwrite_byte 0x63 $cowoff $cowsz $testdir/file3.chk >> $seqres.full
79 _scratch_cycle_mount
80
81 echo "Compare files"
82 md5sum $testdir/file1 | _filter_scratch
83 md5sum $testdir/file3 | _filter_scratch
84 md5sum $testdir/file3.chk | _filter_scratch
85
86 echo "Check extent counts"
87 old_extents=$(_count_extents $testdir/file1)
88 new_extents=$(_count_extents $testdir/file3)
89
90 echo "old extents: $old_extents" >> $seqres.full
91 echo "new extents: $new_extents" >> $seqres.full
92 echo "maximum extents: $internal_blks" >> $seqres.full
93 test $((new_extents - (nr * 4 / 10))) -lt $((internal_blks / 2)) || echo "file3 badly fragmented"
94
95 # success, all done
96 status=0
97 exit