4 # Ensure that fallocate on reflinked files actually CoWs the shared blocks.
5 # - Record fs block usage (0)
6 # - Create a file and some reflink copies
7 # - Record fs block usage (1)
8 # - funshare half of one of the copies
9 # - Record fs block usage (2)
10 # - funshare all of the copies
11 # - Record fs block usage (3)
12 # - rewrite the original file
13 # - Record fs block usage (4)
14 # - Compare fs block usage of 0-4 to ensure that block usage behaves as
16 # - Compare the status of the inode reflink flag at each step.
18 # "funshare" refers to fallocate copy-on-writing the shared blocks
20 # This is the same test as generic/156 except that we also check the inode
23 #-----------------------------------------------------------------------
24 # Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
26 # This program is free software; you can redistribute it and/or
27 # modify it under the terms of the GNU General Public License as
28 # published by the Free Software Foundation.
30 # This program is distributed in the hope that it would be useful,
31 # but WITHOUT ANY WARRANTY; without even the implied warranty of
32 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 # GNU General Public License for more details.
35 # You should have received a copy of the GNU General Public License
36 # along with this program; if not, write the Free Software Foundation,
37 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
38 #-----------------------------------------------------------------------
41 seqres="$RESULT_DIR/$seq"
42 echo "QA output created by $seq"
46 status=1 # failure is the default!
47 trap "_cleanup; exit \$status" 0 1 2 3 15
52 rm -rf "$tmp".* "$TESTDIR"
55 # get standard environment, filters and checks
61 # real QA test starts here
66 _require_xfs_io_command "falloc"
70 TESTDIR="$TEST_DIR/test-$seq"
74 echo "Create the original file blocks"
75 BLKSZ="$(stat -f "$TESTDIR" -c '%S')"
79 FREE_BLOCKS0=$(stat -f "$TESTDIR" -c '%f')
81 _pwrite_byte 0x61 0 $SZ "$TESTDIR/file1" >> "$seqres.full"
84 echo "Create the reflink copies"
85 for i in `seq 2 $NR`; do
86 _cp_reflink "$TESTDIR/file1" "$TESTDIR/file$i"
89 FREE_BLOCKS1=$(stat -f "$TESTDIR" -c '%f')
90 lsattr -l $TESTDIR/ | _filter_test_dir
92 echo "funshare part of a file"
93 "$XFS_IO_PROG" -f -c "falloc 0 $((SZ / 2))" "$TESTDIR/file2"
95 lsattr -l $TESTDIR/ | _filter_test_dir
97 echo "funshare some of the copies"
98 "$XFS_IO_PROG" -f -c "falloc 0 $SZ" "$TESTDIR/file2"
99 "$XFS_IO_PROG" -f -c "falloc 0 $SZ" "$TESTDIR/file3"
101 FREE_BLOCKS2=$(stat -f "$TESTDIR" -c '%f')
102 lsattr -l $TESTDIR/ | _filter_test_dir
104 echo "funshare the rest of the files"
105 "$XFS_IO_PROG" -f -c "falloc 0 $SZ" "$TESTDIR/file4"
106 "$XFS_IO_PROG" -f -c "falloc 0 $SZ" "$TESTDIR/file1"
108 FREE_BLOCKS3=$(stat -f "$TESTDIR" -c '%f')
109 lsattr -l $TESTDIR/ | _filter_test_dir
111 echo "Rewrite the original file"
112 _pwrite_byte 0x65 0 $SZ "$TESTDIR/file1" >> "$seqres.full"
114 FREE_BLOCKS4=$(stat -f "$TESTDIR" -c '%f')
115 lsattr -l $TESTDIR/ | _filter_test_dir
116 #echo $FREE_BLOCKS0 $FREE_BLOCKS1 $FREE_BLOCKS2 $FREE_BLOCKS3 $FREE_BLOCKS4
118 _within_tolerance "free blocks after reflinking" $FREE_BLOCKS1 $((FREE_BLOCKS0 - BLKS)) $MARGIN -v
120 _within_tolerance "free blocks after nocow'ing some copies" $FREE_BLOCKS2 $((FREE_BLOCKS1 - (2 * BLKS))) $MARGIN -v
122 _within_tolerance "free blocks after nocow'ing all copies" $FREE_BLOCKS3 $((FREE_BLOCKS2 - BLKS)) $MARGIN -v
124 _within_tolerance "free blocks after overwriting original" $FREE_BLOCKS4 $FREE_BLOCKS3 $MARGIN -v
126 _within_tolerance "free blocks after all tests" $FREE_BLOCKS4 $((FREE_BLOCKS0 - (4 * BLKS))) $MARGIN -v