4 # Ensuring that copy on write in buffered mode works when the CoW
5 # range originally covers multiple extents, some unwritten, some not.
6 # - Create a file with the following repeating sequence of blocks:
12 # - CoW across the halfway mark, starting with the unwritten extent.
13 # - Check that the files are now different where we say they're different.
15 #-----------------------------------------------------------------------
16 # Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
18 # This program is free software; you can redistribute it and/or
19 # modify it under the terms of the GNU General Public License as
20 # published by the Free Software Foundation.
22 # This program is distributed in the hope that it would be useful,
23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 # GNU General Public License for more details.
27 # You should have received a copy of the GNU General Public License
28 # along with this program; if not, write the Free Software Foundation,
29 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 #-----------------------------------------------------------------------
33 seqres="$RESULT_DIR/$seq"
34 echo "QA output created by $seq"
38 status=1 # failure is the default!
39 trap "_cleanup; exit \$status" 0 1 2 3 15
44 rm -rf "$tmp".* "$TESTDIR"
47 # get standard environment, filters and checks
52 # real QA test starts here
54 _require_scratch_reflink
55 _require_xfs_io_command "falloc"
56 _require_xfs_io_command "fpunch"
61 echo "Format and mount"
62 _scratch_mkfs > "$seqres.full" 2>&1
63 _scratch_mount >> "$seqres.full" 2>&1
65 TESTDIR="$SCRATCH_MNT/test-$seq"
69 echo "Create the original files"
72 _pwrite_byte 0x61 0 $((BLKSZ * NR)) "$TESTDIR/file1" >> "$seqres.full"
73 $XFS_IO_PROG -f -c "truncate $((BLKSZ * NR))" "$TESTDIR/file3" >> "$seqres.full"
74 # 0 blocks are reflinked
75 seq 0 5 $NR | while read f; do
76 _reflink_range "$TESTDIR/file1" $((BLKSZ * f)) "$TESTDIR/file3" $((BLKSZ * f)) $BLKSZ >> "$seqres.full"
77 _pwrite_byte 0x61 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3.chk" >> "$seqres.full"
80 # 1 blocks are unwritten
81 seq 1 5 $NR | while read f; do
82 $XFS_IO_PROG -f -c "falloc $((BLKSZ * f)) $BLKSZ" "$TESTDIR/file3" >> "$seqres.full"
83 _pwrite_byte 0x00 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3.chk" >> "$seqres.full"
87 seq 2 5 $NR | while read f; do
88 _pwrite_byte 0x00 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3.chk" >> "$seqres.full"
90 # 3 blocks are regular
91 seq 3 5 $NR | while read f; do
92 _pwrite_byte 0x71 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3" >> "$seqres.full"
93 _pwrite_byte 0x71 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3.chk" >> "$seqres.full"
99 md5sum "$TESTDIR/file1" | _filter_scratch
100 md5sum "$TESTDIR/file3" | _filter_scratch
101 md5sum "$TESTDIR/file3.chk" | _filter_scratch
103 echo "directio CoW across the transition"
104 # 4 blocks are delalloc (do later)
105 seq 4 5 $NR | while read f; do
106 _pwrite_byte 0x62 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3" >> "$seqres.full"
107 _pwrite_byte 0x62 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3.chk" >> "$seqres.full"
110 "$XFS_IO_PROG" -f -c "pwrite -S 0x63 -b $((BLKSZ * NR / 2)) $((BLKSZ * NR / 4)) $((BLKSZ * NR / 2))" "$TESTDIR/file3" >> "$seqres.full"
111 _pwrite_byte 0x63 $((BLKSZ * NR / 4)) $((BLKSZ * NR / 2)) "$TESTDIR/file3.chk" >> "$seqres.full"
115 md5sum "$TESTDIR/file1" | _filter_scratch
116 md5sum "$TESTDIR/file3" | _filter_scratch
117 md5sum "$TESTDIR/file3.chk" | _filter_scratch
119 echo "Check for damage"
120 umount "$SCRATCH_MNT"