fstests: convert remaining tests to SPDX license tags
[xfstests-dev.git] / tests / xfs / 226
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. 226
6 #
7 # Ensuring that copy on write in buffered mode works when the CoW
8 # range originally covers multiple extents, some regular, some not.
9 #   - Set cowextsize hint.
10 #   - Create two files.
11 #   - Reflink the odd blocks of the first file into the second file.
12 #   - CoW across the halfway mark, starting with the unwritten extent.
13 #   - Check that the files are now different where we say they're different.
14 #
15 seq=`basename $0`
16 seqres=$RESULT_DIR/$seq
17 echo "QA output created by $seq"
18
19 here=`pwd`
20 tmp=/tmp/$$
21 status=1    # failure is the default!
22 trap "_cleanup; exit \$status" 0 1 2 3 15
23
24 _cleanup()
25 {
26     cd /
27     rm -rf $tmp.*
28 }
29
30 # get standard environment, filters and checks
31 . ./common/rc
32 . ./common/filter
33 . ./common/reflink
34
35 # real QA test starts here
36 _supported_os Linux
37 _require_scratch_reflink
38 _require_xfs_io_command "falloc"
39 _require_xfs_io_command "cowextsize"
40
41 rm -f $seqres.full
42
43 echo "Format and mount"
44 _scratch_mkfs > $seqres.full 2>&1
45 _scratch_mount >> $seqres.full 2>&1
46
47 testdir=$SCRATCH_MNT/test-$seq
48 mkdir $testdir
49
50 echo "Create the original files"
51 blksz=65536
52 nr=64
53 filesize=$((blksz * nr))
54 real_blksz=$(_get_block_size $testdir)
55 internal_blks=$((filesize / real_blksz))
56 $XFS_IO_PROG -c "cowextsize $((blksz * 16))" $testdir >> $seqres.full
57 _weave_reflink_regular $blksz $nr $testdir/file1 $testdir/file3 >> $seqres.full
58 _scratch_cycle_mount
59
60 echo "Compare files"
61 md5sum $testdir/file1 | _filter_scratch
62 md5sum $testdir/file3 | _filter_scratch
63 md5sum $testdir/file3.chk | _filter_scratch
64
65 echo "CoW across the transition"
66 cowoff=$((filesize / 4))
67 cowsz=$((filesize / 2))
68 $XFS_IO_PROG -f -c "pwrite -S 0x63 -b $cowsz $cowoff $cowsz" $testdir/file3 >> $seqres.full
69 _pwrite_byte 0x63 $cowoff $cowsz $testdir/file3.chk >> $seqres.full
70 _scratch_cycle_mount
71
72 echo "Compare files"
73 md5sum $testdir/file1 | _filter_scratch
74 md5sum $testdir/file3 | _filter_scratch
75 md5sum $testdir/file3.chk | _filter_scratch
76
77 echo "Check extent counts"
78 old_extents=$(_count_extents $testdir/file1)
79 new_extents=$(_count_extents $testdir/file3)
80
81 echo "old extents: $old_extents" >> $seqres.full
82 echo "new extents: $new_extents" >> $seqres.full
83 echo "maximum extents: $internal_blks" >> $seqres.full
84 test $((new_extents - (nr / 2))) -lt $((internal_blks / 2)) || echo "file3 badly fragmented"
85
86 # success, all done
87 status=0
88 exit