50cffd35a5008b8670f190ed748616cd154afb05
[xfstests-dev.git] / tests / btrfs / 028
1 #! /bin/bash
2 # FS QA Test No. 028
3 #
4 # Moving and deleting cloned ("reflinked") files on btrfs:
5 #   - Create a file and a reflink
6 #   - Move both to a directory
7 #   - Delete the original (moved) file, check that the copy still exists.
8 #
9 #-----------------------------------------------------------------------
10 # Copyright (c) 2014, 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 -f $tmp.*
39 }
40
41 # get standard environment, filters and checks
42 . ./common/rc
43 . ./common/filter
44
45 # real QA test starts here
46 _supported_fs btrfs
47 _supported_os Linux
48
49 _require_xfs_io_command "fiemap"
50 _require_cp_reflink
51
52 rm -f $seqres.full
53
54 TESTDIR1=$TEST_DIR/test-$seq
55 rm -rf $TESTDIR1
56 mkdir $TESTDIR1
57
58 echo "Create the original files and reflink dirs"
59 $XFS_IO_PROG -f -c 'pwrite -S 0x61 0 9000' $TESTDIR1/original \
60     >> $seqres.full
61 cp --reflink $TESTDIR1/original $TESTDIR1/copy
62
63 _verify_reflink $TESTDIR1/original $TESTDIR1/copy
64
65 echo "Move orig & reflink copy to subdir and md5sum:"
66 mkdir $TESTDIR1/subdir
67 mv $TESTDIR1/original $TESTDIR1/subdir/original_moved
68 mv $TESTDIR1/copy $TESTDIR1/subdir/copy_moved
69 _verify_reflink $TESTDIR1/subdir/original_moved \
70     $TESTDIR1/subdir/copy_moved
71
72 md5sum $TESTDIR1/subdir/original_moved | _filter_test_dir
73 md5sum $TESTDIR1/subdir/copy_moved | _filter_test_dir
74
75 echo "remove orig from subdir and md5sum reflink copy:"
76 rm $TESTDIR1/subdir/original_moved
77 md5sum $TESTDIR1/subdir/copy_moved | _filter_test_dir
78 rm -rf $TESTDIR1/subdir
79
80 # success, all done
81 status=0
82 exit