b93b6df682610a52bcd18e1e9db045c520ef39b8
[xfstests-dev.git] / tests / btrfs / 029
1 #! /bin/bash
2 # FS QA Test No. 029
3 #
4 # Check if creating a sparse copy ("reflink") of a file on btrfs
5 # expectedly fails when it's done between different filesystems or
6 # different mount points of the same filesystem.
7 #
8 # For both situations, these actions are executed:
9 #    - Copy a file with the reflink=auto option.
10 #      A normal copy should be created.
11 #    - Copy a file with the reflink=always option. Should result in
12 #      error.
13 #
14 #-----------------------------------------------------------------------
15 # Copyright (c) 2014, Oracle and/or its affiliates.  All Rights Reserved.
16 #
17 # This program is free software; you can redistribute it and/or
18 # modify it under the terms of the GNU General Public License as
19 # published by the Free Software Foundation.
20 #
21 # This program is distributed in the hope that it would be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 # GNU General Public License for more details.
25 #
26 # You should have received a copy of the GNU General Public License
27 # along with this program; if not, write the Free Software Foundation,
28 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
29 #-----------------------------------------------------------------------
30
31 seq=`basename $0`
32 seqres=$RESULT_DIR/$seq
33 echo "QA output created by $seq"
34
35 here=`pwd`
36 tmp=/tmp/$$
37 status=1    # failure is the default!
38 trap "_cleanup; exit \$status" 0 1 2 3 15
39
40 _cleanup()
41 {
42     umount $SCRATCH_MNT &>/dev/null
43     cd /
44     rm -f $tmp.*
45 }
46
47 # get standard environment, filters and checks
48 . ./common/rc
49 . ./common/filter
50
51 # real QA test starts here
52 _supported_fs btrfs
53 _supported_os Linux
54
55 _require_scratch
56 _require_cp_reflink
57
58 SOURCE_DIR=$TEST_DIR/test-$seq
59 CROSS_DEV_DIR=$SCRATCH_MNT/test-$seq
60 # mount point & target for twice-mounted device
61 TEST_DIR2=$TEST_DIR/mount2
62 DUAL_MOUNT_DIR=$SCRATCH_MNT/test-bis-$seq
63
64 rm -rf $SOURCE_DIR
65 mkdir $SOURCE_DIR
66
67 rm -f $seqres.full
68
69 _scratch_mkfs
70 $XFS_IO_PROG -f -c 'pwrite -S 0x61 0 9000' $SOURCE_DIR/original \
71  >> $seqres.full
72
73 _filter_testdirs()
74 {
75     _filter_test_dir | _filter_scratch
76 }
77
78 _create_reflinks_to()
79 {
80     # auto reflink, should fall back to non-reflink
81     rm -rf $1; mkdir $1
82     echo "reflink=auto:"
83     cp --reflink=auto $SOURCE_DIR/original $1/copy
84     md5sum $SOURCE_DIR/original | _filter_testdirs
85     md5sum $1/copy | _filter_testdirs
86
87     # always reflink, should fail outright
88     rm -rf $1; mkdir $1
89     echo "reflink=always:"
90     cp --reflink=always $SOURCE_DIR/original $1/copyfail \
91         2>&1 | _filter_testdirs
92
93     # The failed target actually gets created by cp:
94     ls $1/copyfail | _filter_testdirs
95 }
96
97 echo "test reflinks across different devices"
98 _scratch_mount
99 _create_reflinks_to $CROSS_DEV_DIR
100 _scratch_unmount
101
102 echo "test reflinks across different mountpoints of same device"
103 mount $TEST_DEV $SCRATCH_MNT || _fail "Couldn't double-mount $TEST_DEV"
104 _create_reflinks_to $DUAL_MOUNT_DIR
105 umount $SCRATCH_MNT
106
107 # success, all done
108 status=0
109 exit