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
47 _require_xfs_io_command "funshare"
51 testdir=$TEST_DIR/test-$seq
55 echo "Create the original file blocks"
56 blksz="$(_get_block_size $testdir)"
60 free_blocks0=$(stat -f $testdir -c '%f')
62 filesize=$((blksz * nr))
63 _pwrite_byte 0x61 0 $sz $testdir/file1 >> $seqres.full
66 echo "Create the reflink copies"
67 for i in `seq 2 $nr`; do
68 _cp_reflink $testdir/file1 $testdir/file$i
71 free_blocks1=$(stat -f $testdir -c '%f')
73 echo "funshare part of a file"
74 $XFS_IO_PROG -f -c "funshare 0 $((sz / 2))" $testdir/file2
77 echo "funshare some of the copies"
78 $XFS_IO_PROG -f -c "funshare 0 $sz" $testdir/file2
79 $XFS_IO_PROG -f -c "funshare 0 $sz" $testdir/file3
81 free_blocks2=$(stat -f $testdir -c '%f')
83 echo "funshare the rest of the files"
84 $XFS_IO_PROG -f -c "funshare 0 $sz" $testdir/file4
85 $XFS_IO_PROG -f -c "funshare 0 $sz" $testdir/file1
87 free_blocks3=$(stat -f $testdir -c '%f')
89 echo "Rewrite the original file"
90 _pwrite_byte 0x65 0 $sz $testdir/file1 >> $seqres.full
92 free_blocks4=$(stat -f $testdir -c '%f')
93 #echo $free_blocks0 $free_blocks1 $free_blocks2 $free_blocks3 $free_blocks4
95 _within_tolerance "free blocks after reflinking" $free_blocks1 $((free_blocks0 - blks)) $margin -v
97 _within_tolerance "free blocks after nocow'ing some copies" $free_blocks2 $((free_blocks1 - (2 * blks))) $margin -v
99 _within_tolerance "free blocks after nocow'ing all copies" $free_blocks3 $((free_blocks2 - blks)) $margin -v
101 _within_tolerance "free blocks after overwriting original" $free_blocks4 $free_blocks3 $margin -v
103 _within_tolerance "free blocks after all tests" $free_blocks4 $((free_blocks0 - (4 * blks))) $margin -v