reflink: add test support routines to a separate file
[xfstests-dev.git] / tests / generic / 115
1 #! /bin/bash
2 # FS QA Test No. 115
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 . ./common/reflink
45
46 # real QA test starts here
47 _require_test_reflink
48 _supported_os Linux
49
50 _require_xfs_io_command "fiemap"
51 _require_cp_reflink
52 _require_test
53
54 rm -f $seqres.full
55
56 TESTDIR1=$TEST_DIR/test-$seq
57 rm -rf $TESTDIR1
58 mkdir $TESTDIR1
59
60 echo "Create the original files and reflink dirs"
61 $XFS_IO_PROG -f -c 'pwrite -S 0x61 0 9000' $TESTDIR1/original \
62     >> $seqres.full
63 cp --reflink $TESTDIR1/original $TESTDIR1/copy
64
65 _verify_reflink $TESTDIR1/original $TESTDIR1/copy
66
67 echo "Move orig & reflink copy to subdir and md5sum:"
68 mkdir $TESTDIR1/subdir
69 mv $TESTDIR1/original $TESTDIR1/subdir/original_moved
70 mv $TESTDIR1/copy $TESTDIR1/subdir/copy_moved
71 _verify_reflink $TESTDIR1/subdir/original_moved \
72     $TESTDIR1/subdir/copy_moved
73
74 md5sum $TESTDIR1/subdir/original_moved | _filter_test_dir
75 md5sum $TESTDIR1/subdir/copy_moved | _filter_test_dir
76
77 echo "remove orig from subdir and md5sum reflink copy:"
78 rm $TESTDIR1/subdir/original_moved
79 md5sum $TESTDIR1/subdir/copy_moved | _filter_test_dir
80 rm -rf $TESTDIR1/subdir
81
82 # success, all done
83 status=0
84 exit