reflink: ensure that we can handle reflinking a lot of extents
[xfstests-dev.git] / tests / generic / 181
1 #! /bin/bash
2 # FS QA Test No. 181
3 #
4 # Test the convention that reflink with length == 0 means "to the end of fileA"
5 #   - Create a file.
6 #   - Try to reflink "zero" bytes.
7 #   - Check that the reflink happened.
8 #
9 #-----------------------------------------------------------------------
10 # Copyright (c) 2015, Oracle and/or its affiliates.  All Rights Reserved.
11 #
12 # This program is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License as
14 # published by the Free Software Foundation.
15 #
16 # This program is distributed in the hope that it would be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write the Free Software Foundation,
23 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
24 #-----------------------------------------------------------------------
25
26 seq=`basename $0`
27 seqres=$RESULT_DIR/$seq
28 echo "QA output created by $seq"
29
30 here=`pwd`
31 tmp=/tmp/$$
32 status=1    # failure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
34
35 _cleanup()
36 {
37     cd /
38     rm -rf $tmp.* $testdir
39 }
40
41 # get standard environment, filters and checks
42 . ./common/rc
43 . ./common/filter
44 . ./common/reflink
45
46 # real QA test starts here
47 _supported_os Linux
48 _require_test_reflink
49 _require_cp_reflink
50
51 rm -f $seqres.full
52
53 testdir=$TEST_DIR/test-$seq
54 rm -rf $testdir
55 mkdir $testdir
56
57 echo "Create the original files"
58 blksz=65536
59 _pwrite_byte 0x61 0 $((blksz * 256)) $testdir/file1 >> $seqres.full
60 _pwrite_byte 0x62 0 $((blksz * 256)) $testdir/file2 >> $seqres.full
61 _pwrite_byte 0x62 0 $((blksz * 2)) $testdir/file2.chk >> $seqres.full
62 _pwrite_byte 0x61 $((blksz * 2)) $((blksz * 255)) $testdir/file2.chk >> $seqres.full
63 _reflink_range $testdir/file1 $blksz $testdir/file2 $((blksz * 2)) 0 >> $seqres.full
64 _test_remount
65
66 md5sum $testdir/file1 | _filter_test_dir
67 md5sum $testdir/file2 | _filter_test_dir
68 md5sum $testdir/file2.chk | _filter_test_dir
69
70 c1=$(_md5_checksum $testdir/file1)
71 c2=$(_md5_checksum $testdir/file2)
72
73 test ${c1} != ${c2} || echo "file1 and file2 should not match"
74
75 echo "Compare against check files"
76 cmp -s $testdir/file2 $testdir/file2.chk || echo "file2 and file2.chk do not match"
77
78 # success, all done
79 status=0
80 exit