2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
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)
16 # The main difference from 834 is that we use zero range, directio, and
17 # mmap to mix things up a bit.
20 _begin_fstest auto quick clone zero
22 # Override the default cleanup function.
26 rm -rf $tmp.* $testdir
29 # Import common functions.
33 # real QA test starts here
36 _require_xfs_io_command "fzero"
39 testdir=$TEST_DIR/test-$seq
43 echo "Create the original file blocks"
44 blksz="$(_get_block_size $testdir)"
48 free_blocks0=$(stat -f $testdir -c '%f')
50 filesize=$((blksz * nr))
51 _pwrite_byte 0x61 0 $sz $testdir/file1 >> $seqres.full
54 echo "Create the reflink copies"
55 for i in `seq 2 $nr`; do
56 _cp_reflink $testdir/file1 $testdir/file$i
59 free_blocks1=$(stat -f $testdir -c '%f')
61 echo "Rewrite some of the blocks"
62 $XFS_IO_PROG -f -c "fzero 0 $sz" $testdir/file2 >> $seqres.full
63 _pwrite_byte 0x63 0 $((sz / 2)) $testdir/file3 -d >> $seqres.full
64 _mwrite_byte 0x64 $((sz / 2)) $((sz / 2)) $sz $testdir/file4 >> $seqres.full
66 free_blocks2=$(stat -f $testdir -c '%f')
68 echo "Rewrite all the files"
69 _pwrite_byte 0x62 0 $sz $testdir/file2 -d >> $seqres.full
70 _mwrite_byte 0x63 0 $sz $sz $testdir/file3 >> $seqres.full
71 $XFS_IO_PROG -f -c "fzero 0 $sz" $testdir/file4 >> $seqres.full
73 free_blocks3=$(stat -f $testdir -c '%f')
75 echo "Rewrite the original file"
76 _pwrite_byte 0x65 0 $sz $testdir/file1 >> $seqres.full
78 free_blocks4=$(stat -f $testdir -c '%f')
79 #echo $free_blocks0 $free_blocks1 $free_blocks2 $free_blocks3 $free_blocks4
81 _within_tolerance "free blocks after reflinking" $free_blocks1 $((free_blocks0 - blks)) $margin -v
83 _within_tolerance "free blocks after partially CoWing some copies" $free_blocks2 $((free_blocks1 - (2 * blks))) $margin -v
85 _within_tolerance "free blocks after CoWing all copies" $free_blocks3 $((free_blocks2 - blks)) $margin -v
87 _within_tolerance "free blocks after overwriting original" $free_blocks4 $free_blocks3 $margin -v
89 _within_tolerance "free blocks after all tests" $free_blocks4 $((free_blocks0 - (4 * blks))) $margin -v