2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
7 # Ensure that fallocate on reflinked files actually CoWs the shared blocks.
8 # - Record fs block usage (0)
9 # - Create a file and some reflink copies
10 # - Record fs block usage (1)
11 # - funshare half of one of the copies
12 # - Record fs block usage (2)
13 # - funshare all of the copies
14 # - Record fs block usage (3)
15 # - rewrite the original file
16 # - Record fs block usage (4)
17 # - Compare fs block usage of 0-4 to ensure that block usage behaves as
20 # "funshare" refers to fallocate copy-on-writing the shared blocks
23 seqres=$RESULT_DIR/$seq
24 echo "QA output created by $seq"
28 status=1 # failure is the default!
29 trap "_cleanup; exit \$status" 0 1 2 3 15
34 rm -rf $tmp.* $testdir
37 # get standard environment, filters and checks
43 # real QA test starts here
46 _require_xfs_io_command "funshare"
50 testdir=$TEST_DIR/test-$seq
54 echo "Create the original file blocks"
55 blksz="$(_get_block_size $testdir)"
59 free_blocks0=$(stat -f $testdir -c '%f')
61 filesize=$((blksz * nr))
62 _pwrite_byte 0x61 0 $sz $testdir/file1 >> $seqres.full
65 echo "Create the reflink copies"
66 for i in `seq 2 $nr`; do
67 _cp_reflink $testdir/file1 $testdir/file$i
70 free_blocks1=$(stat -f $testdir -c '%f')
72 echo "funshare part of a file"
73 $XFS_IO_PROG -f -c "funshare 0 $((sz / 2))" $testdir/file2
76 echo "funshare some of the copies"
77 $XFS_IO_PROG -f -c "funshare 0 $sz" $testdir/file2
78 $XFS_IO_PROG -f -c "funshare 0 $sz" $testdir/file3
80 free_blocks2=$(stat -f $testdir -c '%f')
82 echo "funshare the rest of the files"
83 $XFS_IO_PROG -f -c "funshare 0 $sz" $testdir/file4
84 $XFS_IO_PROG -f -c "funshare 0 $sz" $testdir/file1
86 free_blocks3=$(stat -f $testdir -c '%f')
88 echo "Rewrite the original file"
89 _pwrite_byte 0x65 0 $sz $testdir/file1 >> $seqres.full
91 free_blocks4=$(stat -f $testdir -c '%f')
92 #echo $free_blocks0 $free_blocks1 $free_blocks2 $free_blocks3 $free_blocks4
94 _within_tolerance "free blocks after reflinking" $free_blocks1 $((free_blocks0 - blks)) $margin -v
96 _within_tolerance "free blocks after nocow'ing some copies" $free_blocks2 $((free_blocks1 - (2 * blks))) $margin -v
98 _within_tolerance "free blocks after nocow'ing all copies" $free_blocks3 $((free_blocks2 - blks)) $margin -v
100 _within_tolerance "free blocks after overwriting original" $free_blocks4 $free_blocks3 $margin -v
102 _within_tolerance "free blocks after all tests" $free_blocks4 $((free_blocks0 - (4 * blks))) $margin -v