reflink: test a big CoW operation
[xfstests-dev.git] / tests / generic / 242
1 #! /bin/bash
2 # FS QA Test No. 242
3 #
4 # Reflink two large files and CoW them in big chunks.
5 #
6 # This test is dependent on the system page size, so we cannot use md5 in
7 # the golden output; we can only compare to a check file.
8 #
9 #-----------------------------------------------------------------------
10 # Copyright (c) 2015, 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 -rf "$tmp".* "$TESTDIR"
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 _supported_os Linux
48 _require_scratch_reflink
49 _require_cp_reflink
50
51 rm -f "$seqres.full"
52
53
54 echo "Format and mount"
55 _scratch_mkfs > "$seqres.full" 2>&1
56 _scratch_mount >> "$seqres.full" 2>&1
57
58 TESTDIR="$SCRATCH_MNT/test-$seq"
59 rm -rf $TESTDIR
60 mkdir $TESTDIR
61
62 BLKSZ=65536
63 NR=6400
64 BSZ=1280
65
66 FREE_BLOCKS=$(stat -f -c '%a' "$TESTDIR")
67 REAL_BLKSZ=$(stat -f -c '%S' "$TESTDIR")
68 SPACE_NEEDED=$(((BLKSZ * NR * 3) * 5 / 4))
69 SPACE_AVAIL=$((FREE_BLOCKS * REAL_BLKSZ))
70 test $SPACE_NEEDED -gt $SPACE_AVAIL && _notrun "Not enough space. $SPACE_AVAIL < $SPACE_NEEDED"
71
72 echo "Create the original files"
73 "$XFS_IO_PROG" -f -c "pwrite -S 0x61 -b $((BLKSZ * BSZ)) 0 $((BLKSZ * NR))" "$TESTDIR/file1" >> "$seqres.full"
74 _cp_reflink "$TESTDIR/file1" "$TESTDIR/file2" >> "$seqres.full"
75 "$XFS_IO_PROG" -f -c "pwrite -S 0x61 -b $((BLKSZ * BSZ)) 0 $((BLKSZ * NR))" "$TESTDIR/file2.chk" >> "$seqres.full"
76 _scratch_remount
77
78 echo "Compare files"
79 md5sum "$TESTDIR/file1" | _filter_scratch
80 md5sum "$TESTDIR/file2" | _filter_scratch
81 md5sum "$TESTDIR/file2.chk" | _filter_scratch
82
83 echo "CoW and unmount"
84 "$XFS_IO_PROG" -f -c "pwrite -S 0x63 -b $((BLKSZ * BSZ)) 0 $((BLKSZ * NR))" "$TESTDIR/file2" >> "$seqres.full"
85 "$XFS_IO_PROG" -f -c "pwrite -S 0x63 -b $((BLKSZ * BSZ)) 0 $((BLKSZ * NR))" "$TESTDIR/file2.chk" >> "$seqres.full"
86 _scratch_remount
87
88 echo "Compare files"
89 md5sum "$TESTDIR/file1" | _filter_scratch
90 md5sum "$TESTDIR/file2" | _filter_scratch
91 md5sum "$TESTDIR/file2.chk" | _filter_scratch
92
93 echo "Check for damage"
94 umount "$SCRATCH_MNT"
95 _check_scratch_fs
96
97 # success, all done
98 status=0
99 exit