xfs: fix more xfs_db open-coding instances
[xfstests-dev.git] / tests / xfs / 257
1 #! /bin/bash
2 # FS QA Test No. 257
3 #
4 # Ensuring that copy on write in buffered mode to the source file when the
5 # CoW range covers delalloc blocks and regular shared blocks.
6 #   - Set cowextsz.
7 #   - Create two files.
8 #   - Truncate the first file.
9 #   - Write the odd blocks of the first file.
10 #   - Reflink the odd blocks of the first file into the second file.
11 #   - Write the even blocks of the first file.
12 #   - CoW the first file across the halfway mark, starting with the
13 #     regular extent.
14 #   - Check that the files are now different where we say they're different.
15 #
16 #-----------------------------------------------------------------------
17 # Copyright (c) 2016, Oracle and/or its affiliates.  All Rights Reserved.
18 #
19 # This program is free software; you can redistribute it and/or
20 # modify it under the terms of the GNU General Public License as
21 # published by the Free Software Foundation.
22 #
23 # This program is distributed in the hope that it would be useful,
24 # but WITHOUT ANY WARRANTY; without even the implied warranty of
25 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26 # GNU General Public License for more details.
27 #
28 # You should have received a copy of the GNU General Public License
29 # along with this program; if not, write the Free Software Foundation,
30 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
31 #-----------------------------------------------------------------------
32
33 seq=`basename $0`
34 seqres=$RESULT_DIR/$seq
35 echo "QA output created by $seq"
36
37 here=`pwd`
38 tmp=/tmp/$$
39 status=1    # failure is the default!
40 trap "_cleanup; exit \$status" 0 1 2 3 15
41
42 _cleanup()
43 {
44     cd /
45     rm -rf $tmp.*
46 }
47
48 # get standard environment, filters and checks
49 . ./common/rc
50 . ./common/filter
51 . ./common/reflink
52
53 # real QA test starts here
54 _supported_os Linux
55 _require_scratch_reflink
56 _require_xfs_io_command "falloc"
57 _require_xfs_io_command "cowextsize"
58
59 rm -f $seqres.full
60
61 echo "Format and mount"
62 _scratch_mkfs > $seqres.full 2>&1
63 _scratch_mount >> $seqres.full 2>&1
64
65 testdir=$SCRATCH_MNT/test-$seq
66 mkdir $testdir
67
68 echo "Create the original files"
69 blksz=65536
70 nr=64
71 filesize=$((blksz * nr))
72 $XFS_IO_PROG -c "cowextsize $((blksz * 16))" $testdir >> $seqres.full
73 _sweave_reflink_holes $blksz $nr $testdir/file1 $testdir/file3 >> $seqres.full
74 _scratch_cycle_mount
75
76 echo "Compare files"
77 md5sum $testdir/file1 | _filter_scratch
78 md5sum $testdir/file3 | _filter_scratch
79 md5sum $testdir/file1.chk | _filter_scratch
80
81 echo "CoW across the transition"
82 cowoff=$((filesize / 4))
83 cowsz=$((filesize / 2))
84 _sweave_reflink_holes_delalloc $blksz $nr $testdir/file1 >> $seqres.full
85 $XFS_IO_PROG -f -c "pwrite -S 0x63 -b $cowsz $cowoff $cowsz" $testdir/file1 >> $seqres.full
86 _pwrite_byte 0x63 $cowoff $cowsz $testdir/file1.chk >> $seqres.full
87 _scratch_cycle_mount
88
89 echo "Compare files"
90 md5sum $testdir/file1 | _filter_scratch
91 md5sum $testdir/file3 | _filter_scratch
92 md5sum $testdir/file1.chk | _filter_scratch
93
94 # success, all done
95 status=0
96 exit