c2ac561760e04d1f724b1ab690b4351889d0b30b
[xfstests-dev.git] / tests / btrfs / 026
1 #! /bin/bash
2 # FS QA Test No. 026
3 #
4 # Tests file clone functionality of btrfs ("reflinks"):
5 #   - Reflink a file
6 #   - Reflink the reflinked file
7 #   - Modify the original file
8 #   - Modify the reflinked file
9 #
10 #-----------------------------------------------------------------------
11 # Copyright (c) 2014, Oracle and/or its affiliates.  All Rights Reserved.
12 #
13 # This program is free software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License as
15 # published by the Free Software Foundation.
16 #
17 # This program is distributed in the hope that it would be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write the Free Software Foundation,
24 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
25 #-----------------------------------------------------------------------
26 #
27
28 seq=`basename $0`
29 seqres=$RESULT_DIR/$seq
30 echo "QA output created by $seq"
31
32 here=`pwd`
33 tmp=/tmp/$$
34 status=1    # failure is the default!
35 trap "_cleanup; exit \$status" 0 1 2 3 15
36
37 _cleanup()
38 {
39     cd /
40     rm -f $tmp.*
41 }
42
43 # get standard environment, filters and checks
44 . common/rc
45 . common/filter
46
47 # real QA test starts here
48 _supported_fs btrfs
49 _supported_os Linux
50
51 _require_xfs_io_command "fiemap"
52 _require_cp_reflink
53
54 TESTDIR1=$TEST_DIR/test-$seq
55 rm -rf $TESTDIR1
56 mkdir $TESTDIR1
57
58 _checksum_files() {
59     for F in original copy1 copy2
60     do
61         md5sum $TESTDIR1/$F | _filter_test_dir
62     done
63 }
64
65 rm -f $seqres.full
66
67 echo "Create the original file and reflink to copy1, copy2"
68 $XFS_IO_PROG -f -c 'pwrite -S 0x61 0 9000' $TESTDIR1/original \
69     >> $seqres.full 2>&1
70 cp --reflink $TESTDIR1/original $TESTDIR1/copy1
71 cp --reflink $TESTDIR1/copy1 $TESTDIR1/copy2
72 _verify_reflink $TESTDIR1/original $TESTDIR1/copy1
73 _verify_reflink $TESTDIR1/original $TESTDIR1/copy2
74 echo "Original md5sums:"
75 _checksum_files
76
77 echo "Overwrite original file with new data"
78 $XFS_IO_PROG -c 'pwrite -S 0x62 0 9000' $TESTDIR1/original \
79     >> $seqres.full 2>&1
80 echo "md5sums after overwriting original:"
81 _checksum_files
82
83 echo "Overwrite copy1 with different new data"
84 $XFS_IO_PROG -c 'pwrite -S 0x63 0 9000' $TESTDIR1/copy1 \
85     >> $seqres.full 2>&1
86 echo "md5sums after overwriting copy1:"
87 _checksum_files
88
89 # success, all done
90 status=0
91 exit