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