fstests: filter test and scratch together safely
[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     cd /
43     rm -f $tmp.*
44 }
45
46 # get standard environment, filters and checks
47 . ./common/rc
48 . ./common/filter
49 . ./common/reflink
50
51 # real QA test starts here
52 _supported_fs btrfs
53 _supported_os Linux
54
55 _require_test
56 _require_scratch
57 _require_cp_reflink
58
59 reflink_test_dir=$TEST_DIR/test-$seq
60 rm -rf $reflink_test_dir
61 mkdir $reflink_test_dir
62
63 rm -f $seqres.full
64
65 _scratch_mkfs > /dev/null 2>&1
66 _scratch_mount
67 $XFS_IO_PROG -f -c 'pwrite -S 0x61 0 9000' $SCRATCH_MNT/original >> $seqres.full
68
69 _create_reflinks()
70 {
71     # auto reflink, should fall back to non-reflink
72     rm -rf $2
73     echo "reflink=auto:"
74     cp --reflink=auto $1 $2
75     md5sum $1 | _filter_testdir_and_scratch
76     md5sum $2 | _filter_testdir_and_scratch
77
78     # always reflink, should fail outright
79     rm -rf $2
80     echo "reflink=always:"
81     cp --reflink=always $1 $2 >> $seqres.full 2>&1 || echo "cp reflink failed"
82
83     # The failed target actually gets created by cp:
84     ls $2 | _filter_testdir_and_scratch
85 }
86
87 echo "test reflinks across different devices"
88 _create_reflinks $SCRATCH_MNT/original $reflink_test_dir/copy
89
90 echo "test reflinks across different mountpoints of same device"
91 rm -rf $reflink_test_dir/*
92 _mount $SCRATCH_DEV $reflink_test_dir
93 _create_reflinks $SCRATCH_MNT/original $reflink_test_dir/copy
94 $UMOUNT_PROG $reflink_test_dir
95
96 # success, all done
97 status=0
98 exit