common/rc: factor out _scratch_xfs_[get|set]_sb_field
[xfstests-dev.git] / tests / xfs / 210
1 #! /bin/bash
2 # FS QA Test No. 210
3 #
4 # During reflink, XFS should carry the cowextsz setting to the destination file
5 # if the destination file size is less than the size of the source file, the
6 # length is the size of the source file, both offsets are zero, and the
7 # destination does not already have a cowextsz setting.  It should not do so
8 # otherwise.
9 #
10 #-----------------------------------------------------------------------
11 # Copyright (c) 2016, Oracle and/or its affiliates.  All Rights Reserved.
12 #
13 # This program is free software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License as
15 # published by the Free Software Foundation.
16 #
17 # This program is distributed in the hope that it would be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write the Free Software Foundation,
24 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
25 #-----------------------------------------------------------------------
26
27 seq=`basename $0`
28 seqres=$RESULT_DIR/$seq
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 -rf $tmp.*
40 }
41
42 # get standard environment, filters and checks
43 . ./common/rc
44 . ./common/filter
45 . ./common/reflink
46
47 # real QA test starts here
48 _supported_os Linux
49 _supported_fs xfs
50 _require_scratch_reflink
51 _require_cp_reflink
52 _require_xfs_io_command "fiemap"
53 _require_xfs_io_command "cowextsize"
54
55 rm -f $seqres.full
56
57 echo "Format and mount"
58 _scratch_mkfs > $seqres.full 2>&1
59 _scratch_mount >> $seqres.full 2>&1
60
61 testdir=$SCRATCH_MNT/test-$seq
62 mkdir $testdir
63
64 echo "Create initial file"
65 $XFS_IO_PROG -f -c "pwrite -S 0x61 0 131072" $testdir/file1 >> $seqres.full
66 $XFS_IO_PROG -c "cowextsize 1048576" $testdir/file1 >> $seqres.full
67 $XFS_IO_PROG -f -c "pwrite -S 0x61 0 1" $testdir/file4 >> $seqres.full
68 $XFS_IO_PROG -f -c "pwrite -S 0x61 0 262144" $testdir/file7 >> $seqres.full
69 $XFS_IO_PROG -f -c "pwrite -S 0x61 0 262144" $testdir/file9 >> $seqres.full
70 $XFS_IO_PROG -f -c "pwrite -S 0x61 0 262144" $testdir/file10 >> $seqres.full
71
72 echo "Reflink to an empty file"
73 _reflink_range $testdir/file1 0 $testdir/file2 0 0 >> $seqres.full
74
75 echo "Reflink to an empty file that already has cowextsz"
76 $XFS_IO_PROG -f -c "cowextsize 524288" $testdir/file3 >> $seqres.full
77 _reflink_range $testdir/file1 0 $testdir/file3 0 0 >> $seqres.full
78
79 echo "Reflink to a small file"
80 _reflink_range $testdir/file1 0 $testdir/file4 0 0 >> $seqres.full
81
82 echo "Reflink to a nonzero offset"
83 _reflink_range $testdir/file1 0 $testdir/file5 65536 0 >> $seqres.full
84
85 echo "Reflink from a nonzero offset"
86 _reflink_range $testdir/file1 65536 $testdir/file6 0 0 >> $seqres.full
87
88 echo "Reflink to a larger file"
89 _reflink_range $testdir/file1 0 $testdir/file7 0 0 >> $seqres.full
90
91 echo "Reflink less than the whole source file"
92 _reflink_range $testdir/file1 0 $testdir/file8 0 65536 >> $seqres.full
93
94 echo "cp reflink to a larger file"
95 _cp_reflink $testdir/file1 $testdir/file9 >> $seqres.full
96
97 echo "cp reflink to a larger file with cowextsize"
98 $XFS_IO_PROG -f -c "cowextsize 524288" $testdir/file10 >> $seqres.full
99 _cp_reflink $testdir/file1 $testdir/file10 >> $seqres.full
100
101 echo "Check cowextsz"
102 for i in `seq 1 10`; do
103         $XFS_IO_PROG -c "cowextsize" $testdir/file$i | _filter_scratch
104 done
105
106 # success, all done
107 status=0
108 exit