fstests: convert remaining tests to SPDX license tags
[xfstests-dev.git] / tests / generic / 155
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 155
6 #
7 # Ensure that CoW on all copies of a file reflinked N times increases block count
8 #   - Record fs block usage (0)
9 #   - Create a file and some reflink copies
10 #   - Record fs block usage (1)
11 #   - CoW some blocks of the copies
12 #   - Record fs block usage (2)
13 #   - CoW all the rest of the blocks of the copies
14 #   - Compare fs block usage to (2), (1), and (0)
15 #
16 # The main difference from 834 is that we use zero range, directio, and
17 # mmap to mix things up a bit.
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.* $testdir
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_test_reflink
42 _require_cp_reflink
43 _require_xfs_io_command "fzero"
44 _require_odirect
45
46 rm -f $seqres.full
47
48 testdir=$TEST_DIR/test-$seq
49 rm -rf $testdir
50 mkdir $testdir
51
52 echo "Create the original file blocks"
53 blksz="$(_get_block_size $testdir)"
54 blks=2000
55 margin='15%'
56 sz=$((blksz * blks))
57 free_blocks0=$(stat -f $testdir -c '%f')
58 nr=4
59 filesize=$((blksz * nr))
60 _pwrite_byte 0x61 0 $sz $testdir/file1 >> $seqres.full
61 _test_cycle_mount
62
63 echo "Create the reflink copies"
64 for i in `seq 2 $nr`; do
65         _cp_reflink $testdir/file1 $testdir/file$i
66 done
67 _test_cycle_mount
68 free_blocks1=$(stat -f $testdir -c '%f')
69
70 echo "Rewrite some of the blocks"
71 $XFS_IO_PROG -f -c "fzero 0 $sz" $testdir/file2 >> $seqres.full
72 _pwrite_byte 0x63 0 $((sz / 2)) $testdir/file3 -d >> $seqres.full
73 _mwrite_byte 0x64 $((sz / 2)) $((sz / 2)) $sz $testdir/file4 >> $seqres.full
74 _test_cycle_mount
75 free_blocks2=$(stat -f $testdir -c '%f')
76
77 echo "Rewrite all the files"
78 _pwrite_byte 0x62 0 $sz $testdir/file2 -d >> $seqres.full
79 _mwrite_byte 0x63 0 $sz $sz $testdir/file3 >> $seqres.full
80 $XFS_IO_PROG -f -c "fzero 0 $sz" $testdir/file4 >> $seqres.full
81 _test_cycle_mount
82 free_blocks3=$(stat -f $testdir -c '%f')
83
84 echo "Rewrite the original file"
85 _pwrite_byte 0x65 0 $sz $testdir/file1 >> $seqres.full
86 _test_cycle_mount
87 free_blocks4=$(stat -f $testdir -c '%f')
88 #echo $free_blocks0 $free_blocks1 $free_blocks2 $free_blocks3 $free_blocks4
89
90 _within_tolerance "free blocks after reflinking" $free_blocks1 $((free_blocks0 - blks)) $margin -v
91
92 _within_tolerance "free blocks after partially CoWing some copies" $free_blocks2 $((free_blocks1 - (2 * blks))) $margin -v
93
94 _within_tolerance "free blocks after CoWing all copies" $free_blocks3 $((free_blocks2 - blks)) $margin -v
95
96 _within_tolerance "free blocks after overwriting original" $free_blocks4 $free_blocks3 $margin -v
97
98 _within_tolerance "free blocks after all tests" $free_blocks4 $((free_blocks0 - (4 * blks))) $margin -v
99
100 # success, all done
101 status=0
102 exit