--- /dev/null
+#! /bin/bash
+# FS QA Test No. 183
+#
+# Ensuring that copy on write in direct-io mode works when the CoW
+# range originally covers multiple extents.
+# - Create two files
+# - Reflink the odd blocks of the first file into a third file.
+# - Reflink the even blocks of the second file into the third file.
+# - directio CoW across the halfway mark.
+# - Check that the files are now different where we say they're different.
+#
+#-----------------------------------------------------------------------
+# Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#-----------------------------------------------------------------------
+
+seq=`basename "$0"`
+seqres="$RESULT_DIR/$seq"
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1 # failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+ cd /
+ rm -rf "$tmp".* "$TESTDIR"
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+. ./common/reflink
+
+# real QA test starts here
+_supported_os Linux
+_require_scratch_reflink
+
+rm -f "$seqres.full"
+
+echo "Format and mount"
+_scratch_mkfs > "$seqres.full" 2>&1
+_scratch_mount >> "$seqres.full" 2>&1
+
+TESTDIR="$SCRATCH_MNT/test-$seq"
+rm -rf $TESTDIR
+mkdir $TESTDIR
+
+echo "Create the original files"
+BLKSZ=65536
+NR=64
+_pwrite_byte 0x61 0 $((BLKSZ * NR)) "$TESTDIR/file1" >> "$seqres.full"
+_pwrite_byte 0x62 0 $((BLKSZ * NR)) "$TESTDIR/file2" >> "$seqres.full"
+seq 0 2 $((NR-1)) | while read f; do
+ _reflink_range "$TESTDIR/file1" $((BLKSZ * f)) "$TESTDIR/file3" $((BLKSZ * f)) $BLKSZ >> "$seqres.full"
+ _pwrite_byte 0x61 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3.chk" >> "$seqres.full"
+done
+seq 1 2 $NR | while read f; do
+ _reflink_range "$TESTDIR/file2" $((BLKSZ * f)) "$TESTDIR/file3" $((BLKSZ * f)) $BLKSZ >> "$seqres.full"
+ _pwrite_byte 0x62 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3.chk" >> "$seqres.full"
+done
+_scratch_remount
+
+echo "Compare files"
+md5sum "$TESTDIR/file1" | _filter_scratch
+md5sum "$TESTDIR/file2" | _filter_scratch
+md5sum "$TESTDIR/file3" | _filter_scratch
+md5sum "$TESTDIR/file3.chk" | _filter_scratch
+
+echo "directio CoW across the transition"
+"$XFS_IO_PROG" -d -f -c "pwrite -S 0x63 -b $((BLKSZ * NR / 2)) $((BLKSZ * NR / 4)) $((BLKSZ * NR / 2))" "$TESTDIR/file3" >> "$seqres.full"
+_pwrite_byte 0x63 $((BLKSZ * NR / 4)) $((BLKSZ * NR / 2)) "$TESTDIR/file3.chk" >> "$seqres.full"
+_scratch_remount
+
+echo "Compare files"
+md5sum "$TESTDIR/file1" | _filter_scratch
+md5sum "$TESTDIR/file2" | _filter_scratch
+md5sum "$TESTDIR/file3" | _filter_scratch
+md5sum "$TESTDIR/file3.chk" | _filter_scratch
+
+echo "Check for damage"
+umount "$SCRATCH_MNT"
+_check_scratch_fs
+
+# success, all done
+status=0
+exit
--- /dev/null
+QA output created by 183
+Format and mount
+Create the original files
+Compare files
+bdbcf02ee0aa977795a79d25fcfdccb1 SCRATCH_MNT/test-183/file1
+b83f9394092e15bdcda585cd8e776dc6 SCRATCH_MNT/test-183/file2
+d3959a68638c50af07f0258e032cb554 SCRATCH_MNT/test-183/file3
+d3959a68638c50af07f0258e032cb554 SCRATCH_MNT/test-183/file3.chk
+directio CoW across the transition
+Compare files
+bdbcf02ee0aa977795a79d25fcfdccb1 SCRATCH_MNT/test-183/file1
+b83f9394092e15bdcda585cd8e776dc6 SCRATCH_MNT/test-183/file2
+55968a95dfc0120df4e8485576514320 SCRATCH_MNT/test-183/file3
+55968a95dfc0120df4e8485576514320 SCRATCH_MNT/test-183/file3.chk
+Check for damage
--- /dev/null
+#! /bin/bash
+# FS QA Test No. 185
+#
+# Ensuring that copy on write in buffered mode works when the CoW
+# range originally covers multiple extents.
+# - Create two files
+# - Reflink the odd blocks of the first file into a third file.
+# - Reflink the even blocks of the second file into the third file.
+# - CoW across the halfway mark.
+# - Check that the files are now different where we say they're different.
+#
+#-----------------------------------------------------------------------
+# Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#-----------------------------------------------------------------------
+
+seq=`basename "$0"`
+seqres="$RESULT_DIR/$seq"
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1 # failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+ cd /
+ rm -rf "$tmp".* "$TESTDIR"
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+. ./common/reflink
+
+# real QA test starts here
+_supported_os Linux
+_require_scratch_reflink
+
+rm -f "$seqres.full"
+
+echo "Format and mount"
+_scratch_mkfs > "$seqres.full" 2>&1
+_scratch_mount >> "$seqres.full" 2>&1
+
+TESTDIR="$SCRATCH_MNT/test-$seq"
+rm -rf $TESTDIR
+mkdir $TESTDIR
+
+echo "Create the original files"
+BLKSZ=65536
+NR=64
+_pwrite_byte 0x61 0 $((BLKSZ * NR)) "$TESTDIR/file1" >> "$seqres.full"
+_pwrite_byte 0x62 0 $((BLKSZ * NR)) "$TESTDIR/file2" >> "$seqres.full"
+seq 0 2 $((NR-1)) | while read f; do
+ _reflink_range "$TESTDIR/file1" $((BLKSZ * f)) "$TESTDIR/file3" $((BLKSZ * f)) $BLKSZ >> "$seqres.full"
+ _pwrite_byte 0x61 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3.chk" >> "$seqres.full"
+done
+seq 1 2 $NR | while read f; do
+ _reflink_range "$TESTDIR/file2" $((BLKSZ * f)) "$TESTDIR/file3" $((BLKSZ * f)) $BLKSZ >> "$seqres.full"
+ _pwrite_byte 0x62 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3.chk" >> "$seqres.full"
+done
+_scratch_remount
+
+echo "Compare files"
+md5sum "$TESTDIR/file1" | _filter_scratch
+md5sum "$TESTDIR/file2" | _filter_scratch
+md5sum "$TESTDIR/file3" | _filter_scratch
+md5sum "$TESTDIR/file3.chk" | _filter_scratch
+
+echo "CoW across the transition"
+_pwrite_byte 0x63 $((BLKSZ * NR / 4)) $((BLKSZ * NR / 2)) "$TESTDIR/file3" >> "$seqres.full"
+_pwrite_byte 0x63 $((BLKSZ * NR / 4)) $((BLKSZ * NR / 2)) "$TESTDIR/file3.chk" >> "$seqres.full"
+_scratch_remount
+
+echo "Compare files"
+md5sum "$TESTDIR/file1" | _filter_scratch
+md5sum "$TESTDIR/file2" | _filter_scratch
+md5sum "$TESTDIR/file3" | _filter_scratch
+md5sum "$TESTDIR/file3.chk" | _filter_scratch
+
+echo "Check for damage"
+umount "$SCRATCH_MNT"
+_check_scratch_fs
+
+# success, all done
+status=0
+exit
--- /dev/null
+QA output created by 185
+Format and mount
+Create the original files
+Compare files
+bdbcf02ee0aa977795a79d25fcfdccb1 SCRATCH_MNT/test-185/file1
+b83f9394092e15bdcda585cd8e776dc6 SCRATCH_MNT/test-185/file2
+d3959a68638c50af07f0258e032cb554 SCRATCH_MNT/test-185/file3
+d3959a68638c50af07f0258e032cb554 SCRATCH_MNT/test-185/file3.chk
+CoW across the transition
+Compare files
+bdbcf02ee0aa977795a79d25fcfdccb1 SCRATCH_MNT/test-185/file1
+b83f9394092e15bdcda585cd8e776dc6 SCRATCH_MNT/test-185/file2
+55968a95dfc0120df4e8485576514320 SCRATCH_MNT/test-185/file3
+55968a95dfc0120df4e8485576514320 SCRATCH_MNT/test-185/file3.chk
+Check for damage
--- /dev/null
+#! /bin/bash
+# FS QA Test No. 186
+#
+# Ensuring that copy on write in buffered mode works when free space
+# is heavily fragmented.
+# - Create two files
+# - Reflink the odd blocks of the first file into a third file.
+# - Reflink the even blocks of the second file into the third file.
+# - Try to fragment the free space by allocating a huge file and
+# punching out every other block.
+# - CoW across the halfway mark.
+# - Check that the files are now different where we say they're different.
+#
+#-----------------------------------------------------------------------
+# Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#-----------------------------------------------------------------------
+
+seq=`basename "$0"`
+seqres="$RESULT_DIR/$seq"
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1 # failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+ cd /
+# rm -rf "$tmp".* "$TESTDIR"
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+. ./common/reflink
+
+# real QA test starts here
+_supported_os Linux
+_require_scratch_reflink
+_require_cp_reflink
+_require_xfs_io_command "falloc"
+_require_xfs_io_command "fpunch"
+test "$FSTYP" = "btrfs" && _notrun "Can't fragment free space on btrfs."
+
+rm -f "$seqres.full"
+
+_fragment_freesp()
+{
+ file="$1"
+
+ # consume nearly all available space (leave ~1MB)
+ avail=`_get_available_space $SCRATCH_MNT`
+ echo "$avail bytes left"
+ filesize=$((avail - 1048576))
+ $XFS_IO_PROG -fc "truncate $filesize" "$file"
+
+ chunks=20
+ chunksizemb=$((filesize / chunks / 1048576))
+ seq 1 $chunks | while read f; do
+ echo "$((f * chunksizemb)) file size $f / 20"
+ $XFS_IO_PROG -fc "falloc -k $(( (f - 1) * chunksizemb))m ${chunksizemb}m" "$file"
+ done
+
+ chunks=100
+ chunksizemb=$((filesize / chunks / 1048576))
+ seq 80 $chunks | while read f; do
+ echo "$((f * chunksizemb)) file size $f / $chunks"
+ $XFS_IO_PROG -fc "falloc -k $(( (f - 1) * chunksizemb))m ${chunksizemb}m" "$file"
+ done
+
+ filesizemb=$((filesize / 1048576))
+ $XFS_IO_PROG -fc "falloc -k 0 ${filesizemb}m" "$file"
+
+ # Try again anyway
+ avail=`_get_available_space $SCRATCH_MNT`
+ $XFS_IO_PROG -fc "pwrite -S 0x65 0 $avail" "${file}.${i}"
+
+ # Punch out whatever we need
+ seq 1 $((NR * 4)) | while read f; do
+ $XFS_IO_PROG -f -c "fpunch $((f * 2 * BLKSZ)) $BLKSZ" "$file"
+ done
+}
+
+echo "Format and mount"
+_scratch_mkfs > "$seqres.full" 2>&1
+_scratch_mount >> "$seqres.full" 2>&1
+
+TESTDIR="$SCRATCH_MNT/test-$seq"
+rm -rf $TESTDIR
+mkdir $TESTDIR
+
+echo "Create the original files"
+BLKSZ=65536
+NR=1024
+_pwrite_byte 0x61 0 $((BLKSZ * NR)) "$TESTDIR/file1" >> "$seqres.full"
+_pwrite_byte 0x62 0 $((BLKSZ * NR)) "$TESTDIR/file2" >> "$seqres.full"
+seq 0 2 $((NR-1)) | while read f; do
+ _reflink_range "$TESTDIR/file1" $((BLKSZ * f)) "$TESTDIR/file3" $((BLKSZ * f)) $BLKSZ >> "$seqres.full"
+ _pwrite_byte 0x61 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3.chk" >> "$seqres.full"
+done
+seq 1 2 $NR | while read f; do
+ _reflink_range "$TESTDIR/file2" $((BLKSZ * f)) "$TESTDIR/file3" $((BLKSZ * f)) $BLKSZ >> "$seqres.full"
+ _pwrite_byte 0x62 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3.chk" >> "$seqres.full"
+done
+_scratch_remount
+_fragment_freesp "$TESTDIR/bigfile" >> "$seqres.full" 2>&1
+_scratch_remount
+
+echo "Compare files"
+md5sum "$TESTDIR/file1" | _filter_scratch
+md5sum "$TESTDIR/file2" | _filter_scratch
+md5sum "$TESTDIR/file3" | _filter_scratch
+md5sum "$TESTDIR/file3.chk" | _filter_scratch
+
+echo "CoW with multiple extents?"
+"$XFS_IO_PROG" -f -c "pwrite -S 0x63 -b $((BLKSZ * NR / 2)) $((BLKSZ * NR / 4)) $((BLKSZ * NR / 2))" "$TESTDIR/file3" >> "$seqres.full"
+_pwrite_byte 0x63 $((BLKSZ * NR / 4)) $((BLKSZ * NR / 2)) "$TESTDIR/file3.chk" >> "$seqres.full"
+_scratch_remount
+
+echo "Compare files"
+md5sum "$TESTDIR/file1" | _filter_scratch
+md5sum "$TESTDIR/file2" | _filter_scratch
+md5sum "$TESTDIR/file3" | _filter_scratch
+md5sum "$TESTDIR/file3.chk" | _filter_scratch
+
+echo "Check for damage"
+umount "$SCRATCH_MNT"
+_check_scratch_fs
+
+# success, all done
+status=0
+exit
--- /dev/null
+QA output created by 186
+Format and mount
+Create the original files
+Compare files
+6488f52f2d2351fa5ca1f6410df8684d SCRATCH_MNT/test-186/file1
+35219c511215d00a857243965ea5ed9c SCRATCH_MNT/test-186/file2
+8d9ea4925db533da10a45d2919d8d2d9 SCRATCH_MNT/test-186/file3
+8d9ea4925db533da10a45d2919d8d2d9 SCRATCH_MNT/test-186/file3.chk
+CoW with multiple extents?
+Compare files
+6488f52f2d2351fa5ca1f6410df8684d SCRATCH_MNT/test-186/file1
+35219c511215d00a857243965ea5ed9c SCRATCH_MNT/test-186/file2
+1801718b8daeb8d3ad4900bd9137b3e8 SCRATCH_MNT/test-186/file3
+1801718b8daeb8d3ad4900bd9137b3e8 SCRATCH_MNT/test-186/file3.chk
+Check for damage
--- /dev/null
+#! /bin/bash
+# FS QA Test No. 187
+#
+# Ensuring that copy on write in directio mode works when free space
+# is heavily fragmented.
+# - Create two files
+# - Reflink the odd blocks of the first file into a third file.
+# - Reflink the even blocks of the second file into the third file.
+# - Try to fragment the free space by allocating a huge file and
+# punching out every other block.
+# - CoW across the halfway mark.
+# - Check that the files are now different where we say they're different.
+#
+#-----------------------------------------------------------------------
+# Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#-----------------------------------------------------------------------
+
+seq=`basename "$0"`
+seqres="$RESULT_DIR/$seq"
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1 # failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+ cd /
+# rm -rf "$tmp".* "$TESTDIR"
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+. ./common/reflink
+
+# real QA test starts here
+_supported_os Linux
+_require_scratch_reflink
+_require_cp_reflink
+_require_xfs_io_command "falloc"
+_require_xfs_io_command "fpunch"
+test "$FSTYP" = "btrfs" && _notrun "Can't fragment free space on btrfs."
+
+rm -f "$seqres.full"
+
+_fragment_freesp()
+{
+ file="$1"
+
+ # consume nearly all available space (leave ~1MB)
+ avail=`_get_available_space $SCRATCH_MNT`
+ echo "$avail bytes left"
+ filesize=$((avail - 1048576))
+ $XFS_IO_PROG -fc "truncate $filesize" "$file"
+
+ chunks=20
+ chunksizemb=$((filesize / chunks / 1048576))
+ seq 1 $chunks | while read f; do
+ echo "$((f * chunksizemb)) file size $f / 20"
+ $XFS_IO_PROG -fc "falloc -k $(( (f - 1) * chunksizemb))m ${chunksizemb}m" "$file"
+ done
+
+ chunks=100
+ chunksizemb=$((filesize / chunks / 1048576))
+ seq 80 $chunks | while read f; do
+ echo "$((f * chunksizemb)) file size $f / $chunks"
+ $XFS_IO_PROG -fc "falloc -k $(( (f - 1) * chunksizemb))m ${chunksizemb}m" "$file"
+ done
+
+ filesizemb=$((filesize / 1048576))
+ $XFS_IO_PROG -fc "falloc -k 0 ${filesizemb}m" "$file"
+
+ # Try again anyway
+ avail=`_get_available_space $SCRATCH_MNT`
+ $XFS_IO_PROG -fc "pwrite -S 0x65 0 $avail" "${file}.${i}"
+
+ # Punch out whatever we need
+ seq 1 $((NR * 4)) | while read f; do
+ $XFS_IO_PROG -f -c "fpunch $((f * 2 * BLKSZ)) $BLKSZ" "$file"
+ done
+}
+
+echo "Format and mount"
+_scratch_mkfs > "$seqres.full" 2>&1
+_scratch_mount >> "$seqres.full" 2>&1
+
+TESTDIR="$SCRATCH_MNT/test-$seq"
+rm -rf $TESTDIR
+mkdir $TESTDIR
+
+echo "Create the original files"
+BLKSZ=65536
+NR=1024
+_pwrite_byte 0x61 0 $((BLKSZ * NR)) "$TESTDIR/file1" >> "$seqres.full"
+_pwrite_byte 0x62 0 $((BLKSZ * NR)) "$TESTDIR/file2" >> "$seqres.full"
+seq 0 2 $((NR-1)) | while read f; do
+ _reflink_range "$TESTDIR/file1" $((BLKSZ * f)) "$TESTDIR/file3" $((BLKSZ * f)) $BLKSZ >> "$seqres.full"
+ _pwrite_byte 0x61 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3.chk" >> "$seqres.full"
+done
+seq 1 2 $NR | while read f; do
+ _reflink_range "$TESTDIR/file2" $((BLKSZ * f)) "$TESTDIR/file3" $((BLKSZ * f)) $BLKSZ >> "$seqres.full"
+ _pwrite_byte 0x62 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3.chk" >> "$seqres.full"
+done
+_scratch_remount
+_fragment_freesp "$TESTDIR/bigfile" >> "$seqres.full" 2>&1
+_scratch_remount
+
+echo "Compare files"
+md5sum "$TESTDIR/file1" | _filter_scratch
+md5sum "$TESTDIR/file2" | _filter_scratch
+md5sum "$TESTDIR/file3" | _filter_scratch
+md5sum "$TESTDIR/file3.chk" | _filter_scratch
+
+echo "CoW with multiple extents?"
+"$XFS_IO_PROG" -d -f -c "pwrite -S 0x63 -b $((BLKSZ * NR / 2)) $((BLKSZ * NR / 4)) $((BLKSZ * NR / 2))" "$TESTDIR/file3" >> "$seqres.full"
+_pwrite_byte 0x63 $((BLKSZ * NR / 4)) $((BLKSZ * NR / 2)) "$TESTDIR/file3.chk" >> "$seqres.full"
+_scratch_remount
+
+echo "Compare files"
+md5sum "$TESTDIR/file1" | _filter_scratch
+md5sum "$TESTDIR/file2" | _filter_scratch
+md5sum "$TESTDIR/file3" | _filter_scratch
+md5sum "$TESTDIR/file3.chk" | _filter_scratch
+
+echo "Check for damage"
+umount "$SCRATCH_MNT"
+_check_scratch_fs
+
+# success, all done
+status=0
+exit
--- /dev/null
+QA output created by 187
+Format and mount
+Create the original files
+Compare files
+6488f52f2d2351fa5ca1f6410df8684d SCRATCH_MNT/test-187/file1
+35219c511215d00a857243965ea5ed9c SCRATCH_MNT/test-187/file2
+8d9ea4925db533da10a45d2919d8d2d9 SCRATCH_MNT/test-187/file3
+8d9ea4925db533da10a45d2919d8d2d9 SCRATCH_MNT/test-187/file3.chk
+CoW with multiple extents?
+Compare files
+6488f52f2d2351fa5ca1f6410df8684d SCRATCH_MNT/test-187/file1
+35219c511215d00a857243965ea5ed9c SCRATCH_MNT/test-187/file2
+1801718b8daeb8d3ad4900bd9137b3e8 SCRATCH_MNT/test-187/file3
+1801718b8daeb8d3ad4900bd9137b3e8 SCRATCH_MNT/test-187/file3.chk
+Check for damage
--- /dev/null
+#! /bin/bash
+# FS QA Test No. 188
+#
+# Ensuring that copy on write in direct-io mode works when the CoW
+# range originally covers multiple extents, some unwritten, some not.
+# - Create a file and fallocate a second file.
+# - Reflink the odd blocks of the first file into the second file.
+# - directio CoW across the halfway mark, starting with the unwritten extent.
+# - Check that the files are now different where we say they're different.
+#
+#-----------------------------------------------------------------------
+# Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#-----------------------------------------------------------------------
+
+seq=`basename "$0"`
+seqres="$RESULT_DIR/$seq"
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1 # failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+ cd /
+ rm -rf "$tmp".* "$TESTDIR"
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+. ./common/reflink
+
+# real QA test starts here
+_supported_os Linux
+_require_scratch_reflink
+_require_xfs_io_command "falloc"
+
+rm -f "$seqres.full"
+
+echo "Format and mount"
+_scratch_mkfs > "$seqres.full" 2>&1
+_scratch_mount >> "$seqres.full" 2>&1
+
+TESTDIR="$SCRATCH_MNT/test-$seq"
+rm -rf $TESTDIR
+mkdir $TESTDIR
+
+echo "Create the original files"
+BLKSZ=65536
+NR=64
+_pwrite_byte 0x61 0 $((BLKSZ * NR)) "$TESTDIR/file1" >> "$seqres.full"
+$XFS_IO_PROG -f -c "falloc 0 $((BLKSZ * NR))" "$TESTDIR/file3" >> "$seqres.full"
+_pwrite_byte 0x00 0 $((BLKSZ * NR)) "$TESTDIR/file3.chk" >> "$seqres.full"
+seq 0 2 $((NR-1)) | while read f; do
+ _reflink_range "$TESTDIR/file1" $((BLKSZ * f)) "$TESTDIR/file3" $((BLKSZ * f)) $BLKSZ >> "$seqres.full"
+ _pwrite_byte 0x61 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3.chk" >> "$seqres.full"
+done
+_scratch_remount
+
+echo "Compare files"
+md5sum "$TESTDIR/file1" | _filter_scratch
+md5sum "$TESTDIR/file3" | _filter_scratch
+md5sum "$TESTDIR/file3.chk" | _filter_scratch
+
+echo "directio CoW across the transition"
+"$XFS_IO_PROG" -d -f -c "pwrite -S 0x63 -b $((BLKSZ * NR / 2)) $((BLKSZ * NR / 4)) $((BLKSZ * NR / 2))" "$TESTDIR/file3" >> "$seqres.full"
+_pwrite_byte 0x63 $((BLKSZ * NR / 4)) $((BLKSZ * NR / 2)) "$TESTDIR/file3.chk" >> "$seqres.full"
+_scratch_remount
+
+echo "Compare files"
+md5sum "$TESTDIR/file1" | _filter_scratch
+md5sum "$TESTDIR/file3" | _filter_scratch
+md5sum "$TESTDIR/file3.chk" | _filter_scratch
+
+echo "Check for damage"
+umount "$SCRATCH_MNT"
+_check_scratch_fs
+
+# success, all done
+status=0
+exit
--- /dev/null
+QA output created by 188
+Format and mount
+Create the original files
+Compare files
+bdbcf02ee0aa977795a79d25fcfdccb1 SCRATCH_MNT/test-188/file1
+fa50dba51826899c372464a153cb2117 SCRATCH_MNT/test-188/file3
+fa50dba51826899c372464a153cb2117 SCRATCH_MNT/test-188/file3.chk
+directio CoW across the transition
+Compare files
+bdbcf02ee0aa977795a79d25fcfdccb1 SCRATCH_MNT/test-188/file1
+09101629908f9bdd5d178e7ce20bb1bb SCRATCH_MNT/test-188/file3
+09101629908f9bdd5d178e7ce20bb1bb SCRATCH_MNT/test-188/file3.chk
+Check for damage
--- /dev/null
+#! /bin/bash
+# FS QA Test No. 189
+#
+# Ensuring that copy on write in buffered mode works when the CoW
+# range originally covers multiple extents, some unwritten, some not.
+# - Create a file and fallocate a second file.
+# - Reflink the odd blocks of the first file into the second file.
+# - CoW across the halfway mark, starting with the unwritten extent.
+# - Check that the files are now different where we say they're different.
+#
+#-----------------------------------------------------------------------
+# Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#-----------------------------------------------------------------------
+
+seq=`basename "$0"`
+seqres="$RESULT_DIR/$seq"
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1 # failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+ cd /
+ rm -rf "$tmp".* "$TESTDIR"
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+. ./common/reflink
+
+# real QA test starts here
+_supported_os Linux
+_require_scratch_reflink
+_require_xfs_io_command "falloc"
+
+rm -f "$seqres.full"
+
+echo "Format and mount"
+_scratch_mkfs > "$seqres.full" 2>&1
+_scratch_mount >> "$seqres.full" 2>&1
+
+TESTDIR="$SCRATCH_MNT/test-$seq"
+rm -rf $TESTDIR
+mkdir $TESTDIR
+
+echo "Create the original files"
+BLKSZ=65536
+NR=64
+_pwrite_byte 0x61 0 $((BLKSZ * NR)) "$TESTDIR/file1" >> "$seqres.full"
+$XFS_IO_PROG -f -c "falloc 0 $((BLKSZ * NR))" "$TESTDIR/file3" >> "$seqres.full"
+_pwrite_byte 0x00 0 $((BLKSZ * NR)) "$TESTDIR/file3.chk" >> "$seqres.full"
+seq 0 2 $((NR-1)) | while read f; do
+ _reflink_range "$TESTDIR/file1" $((BLKSZ * f)) "$TESTDIR/file3" $((BLKSZ * f)) $BLKSZ >> "$seqres.full"
+ _pwrite_byte 0x61 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3.chk" >> "$seqres.full"
+done
+_scratch_remount
+
+echo "Compare files"
+md5sum "$TESTDIR/file1" | _filter_scratch
+md5sum "$TESTDIR/file3" | _filter_scratch
+md5sum "$TESTDIR/file3.chk" | _filter_scratch
+
+echo "CoW across the transition"
+"$XFS_IO_PROG" -f -c "pwrite -S 0x63 -b $((BLKSZ * NR / 2)) $((BLKSZ * NR / 4)) $((BLKSZ * NR / 2))" "$TESTDIR/file3" >> "$seqres.full"
+_pwrite_byte 0x63 $((BLKSZ * NR / 4)) $((BLKSZ * NR / 2)) "$TESTDIR/file3.chk" >> "$seqres.full"
+_scratch_remount
+
+echo "Compare files"
+md5sum "$TESTDIR/file1" | _filter_scratch
+md5sum "$TESTDIR/file3" | _filter_scratch
+md5sum "$TESTDIR/file3.chk" | _filter_scratch
+
+echo "Check for damage"
+umount "$SCRATCH_MNT"
+_check_scratch_fs
+
+# success, all done
+status=0
+exit
--- /dev/null
+QA output created by 189
+Format and mount
+Create the original files
+Compare files
+bdbcf02ee0aa977795a79d25fcfdccb1 SCRATCH_MNT/test-189/file1
+fa50dba51826899c372464a153cb2117 SCRATCH_MNT/test-189/file3
+fa50dba51826899c372464a153cb2117 SCRATCH_MNT/test-189/file3.chk
+CoW across the transition
+Compare files
+bdbcf02ee0aa977795a79d25fcfdccb1 SCRATCH_MNT/test-189/file1
+09101629908f9bdd5d178e7ce20bb1bb SCRATCH_MNT/test-189/file3
+09101629908f9bdd5d178e7ce20bb1bb SCRATCH_MNT/test-189/file3.chk
+Check for damage
--- /dev/null
+#! /bin/bash
+# FS QA Test No. 190
+#
+# Ensuring that copy on write in direct-io mode works when the CoW
+# range originally covers multiple extents, some holes, some not.
+# - Create a file and truncate a second file.
+# - Reflink the odd blocks of the first file into the second file.
+# - directio CoW across the halfway mark, starting with the unwritten extent.
+# - Check that the files are now different where we say they're different.
+#
+#-----------------------------------------------------------------------
+# Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#-----------------------------------------------------------------------
+
+seq=`basename "$0"`
+seqres="$RESULT_DIR/$seq"
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1 # failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+ cd /
+ rm -rf "$tmp".* "$TESTDIR"
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+. ./common/reflink
+
+# real QA test starts here
+_supported_os Linux
+_require_scratch_reflink
+_require_xfs_io_command "falloc"
+
+rm -f "$seqres.full"
+
+echo "Format and mount"
+_scratch_mkfs > "$seqres.full" 2>&1
+_scratch_mount >> "$seqres.full" 2>&1
+
+TESTDIR="$SCRATCH_MNT/test-$seq"
+rm -rf $TESTDIR
+mkdir $TESTDIR
+
+echo "Create the original files"
+BLKSZ=65536
+NR=64
+_pwrite_byte 0x61 0 $((BLKSZ * NR)) "$TESTDIR/file1" >> "$seqres.full"
+$XFS_IO_PROG -f -c "truncate $((BLKSZ * NR))" "$TESTDIR/file3" >> "$seqres.full"
+_pwrite_byte 0x00 0 $((BLKSZ * NR)) "$TESTDIR/file3.chk" >> "$seqres.full"
+seq 0 2 $((NR-1)) | while read f; do
+ _reflink_range "$TESTDIR/file1" $((BLKSZ * f)) "$TESTDIR/file3" $((BLKSZ * f)) $BLKSZ >> "$seqres.full"
+ _pwrite_byte 0x61 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3.chk" >> "$seqres.full"
+done
+_scratch_remount
+
+echo "Compare files"
+md5sum "$TESTDIR/file1" | _filter_scratch
+md5sum "$TESTDIR/file3" | _filter_scratch
+md5sum "$TESTDIR/file3.chk" | _filter_scratch
+
+echo "directio CoW across the transition"
+"$XFS_IO_PROG" -d -f -c "pwrite -S 0x63 -b $((BLKSZ * NR / 2)) $((BLKSZ * NR / 4)) $((BLKSZ * NR / 2))" "$TESTDIR/file3" >> "$seqres.full"
+_pwrite_byte 0x63 $((BLKSZ * NR / 4)) $((BLKSZ * NR / 2)) "$TESTDIR/file3.chk" >> "$seqres.full"
+_scratch_remount
+
+echo "Compare files"
+md5sum "$TESTDIR/file1" | _filter_scratch
+md5sum "$TESTDIR/file3" | _filter_scratch
+md5sum "$TESTDIR/file3.chk" | _filter_scratch
+
+echo "Check for damage"
+umount "$SCRATCH_MNT"
+_check_scratch_fs
+
+# success, all done
+status=0
+exit
--- /dev/null
+QA output created by 190
+Format and mount
+Create the original files
+Compare files
+bdbcf02ee0aa977795a79d25fcfdccb1 SCRATCH_MNT/test-190/file1
+fa50dba51826899c372464a153cb2117 SCRATCH_MNT/test-190/file3
+fa50dba51826899c372464a153cb2117 SCRATCH_MNT/test-190/file3.chk
+directio CoW across the transition
+Compare files
+bdbcf02ee0aa977795a79d25fcfdccb1 SCRATCH_MNT/test-190/file1
+09101629908f9bdd5d178e7ce20bb1bb SCRATCH_MNT/test-190/file3
+09101629908f9bdd5d178e7ce20bb1bb SCRATCH_MNT/test-190/file3.chk
+Check for damage
--- /dev/null
+#! /bin/bash
+# FS QA Test No. 191
+#
+# Ensuring that copy on write in buffered mode works when the CoW
+# range originally covers multiple extents, some holes, some not.
+# - Create a file and truncate a second file.
+# - Reflink the odd blocks of the first file into the second file.
+# - CoW across the halfway mark, starting with the unwritten extent.
+# - Check that the files are now different where we say they're different.
+#
+#-----------------------------------------------------------------------
+# Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#-----------------------------------------------------------------------
+
+seq=`basename "$0"`
+seqres="$RESULT_DIR/$seq"
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1 # failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+ cd /
+ rm -rf "$tmp".* "$TESTDIR"
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+. ./common/reflink
+
+# real QA test starts here
+_supported_os Linux
+_require_scratch_reflink
+_require_xfs_io_command "falloc"
+
+rm -f "$seqres.full"
+
+echo "Format and mount"
+_scratch_mkfs > "$seqres.full" 2>&1
+_scratch_mount >> "$seqres.full" 2>&1
+
+TESTDIR="$SCRATCH_MNT/test-$seq"
+rm -rf $TESTDIR
+mkdir $TESTDIR
+
+echo "Create the original files"
+BLKSZ=65536
+NR=64
+_pwrite_byte 0x61 0 $((BLKSZ * NR)) "$TESTDIR/file1" >> "$seqres.full"
+$XFS_IO_PROG -f -c "truncate $((BLKSZ * NR))" "$TESTDIR/file3" >> "$seqres.full"
+_pwrite_byte 0x00 0 $((BLKSZ * NR)) "$TESTDIR/file3.chk" >> "$seqres.full"
+seq 0 2 $((NR-1)) | while read f; do
+ _reflink_range "$TESTDIR/file1" $((BLKSZ * f)) "$TESTDIR/file3" $((BLKSZ * f)) $BLKSZ >> "$seqres.full"
+ _pwrite_byte 0x61 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3.chk" >> "$seqres.full"
+done
+_scratch_remount
+
+echo "Compare files"
+md5sum "$TESTDIR/file1" | _filter_scratch
+md5sum "$TESTDIR/file3" | _filter_scratch
+md5sum "$TESTDIR/file3.chk" | _filter_scratch
+
+echo "CoW across the transition"
+"$XFS_IO_PROG" -f -c "pwrite -S 0x63 -b $((BLKSZ * NR / 2)) $((BLKSZ * NR / 4)) $((BLKSZ * NR / 2))" "$TESTDIR/file3" >> "$seqres.full"
+_pwrite_byte 0x63 $((BLKSZ * NR / 4)) $((BLKSZ * NR / 2)) "$TESTDIR/file3.chk" >> "$seqres.full"
+_scratch_remount
+
+echo "Compare files"
+md5sum "$TESTDIR/file1" | _filter_scratch
+md5sum "$TESTDIR/file3" | _filter_scratch
+md5sum "$TESTDIR/file3.chk" | _filter_scratch
+
+echo "Check for damage"
+umount "$SCRATCH_MNT"
+_check_scratch_fs
+
+# success, all done
+status=0
+exit
--- /dev/null
+QA output created by 191
+Format and mount
+Create the original files
+Compare files
+bdbcf02ee0aa977795a79d25fcfdccb1 SCRATCH_MNT/test-191/file1
+fa50dba51826899c372464a153cb2117 SCRATCH_MNT/test-191/file3
+fa50dba51826899c372464a153cb2117 SCRATCH_MNT/test-191/file3.chk
+CoW across the transition
+Compare files
+bdbcf02ee0aa977795a79d25fcfdccb1 SCRATCH_MNT/test-191/file1
+09101629908f9bdd5d178e7ce20bb1bb SCRATCH_MNT/test-191/file3
+09101629908f9bdd5d178e7ce20bb1bb SCRATCH_MNT/test-191/file3.chk
+Check for damage
--- /dev/null
+#! /bin/bash
+# FS QA Test No. 194
+#
+# Ensuring that copy on write in direct-io mode works when the CoW
+# range originally covers multiple extents, some delalloc, some not.
+# - Create a file.
+# - Reflink the odd blocks of the first file into the second file.
+# - Buffered write the even blocks of the second file.
+# - directio CoW across the halfway mark, starting with the unwritten extent.
+# - Check that the files are now different where we say they're different.
+#
+#-----------------------------------------------------------------------
+# Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#-----------------------------------------------------------------------
+
+seq=`basename "$0"`
+seqres="$RESULT_DIR/$seq"
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1 # failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+ cd /
+ rm -rf "$tmp".* "$TESTDIR"
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+. ./common/reflink
+
+# real QA test starts here
+_supported_os Linux
+_require_scratch_reflink
+_require_xfs_io_command "falloc"
+
+rm -f "$seqres.full"
+
+echo "Format and mount"
+_scratch_mkfs > "$seqres.full" 2>&1
+_scratch_mount >> "$seqres.full" 2>&1
+
+TESTDIR="$SCRATCH_MNT/test-$seq"
+rm -rf $TESTDIR
+mkdir $TESTDIR
+
+echo "Create the original files"
+BLKSZ=65536
+NR=64
+_pwrite_byte 0x61 0 $((BLKSZ * NR)) "$TESTDIR/file1" >> "$seqres.full"
+$XFS_IO_PROG -f -c "truncate $((BLKSZ * NR))" "$TESTDIR/file3" >> "$seqres.full"
+_pwrite_byte 0x00 0 $((BLKSZ * NR)) "$TESTDIR/file3.chk" >> "$seqres.full"
+seq 0 2 $((NR-1)) | while read f; do
+ _reflink_range "$TESTDIR/file1" $((BLKSZ * f)) "$TESTDIR/file3" $((BLKSZ * f)) $BLKSZ >> "$seqres.full"
+ _pwrite_byte 0x61 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3.chk" >> "$seqres.full"
+done
+_scratch_remount
+
+echo "Compare files"
+md5sum "$TESTDIR/file1" | _filter_scratch
+md5sum "$TESTDIR/file3" | _filter_scratch
+md5sum "$TESTDIR/file3.chk" | _filter_scratch
+
+echo "directio CoW across the transition"
+seq 1 2 $NR | while read f; do
+ _pwrite_byte 0x62 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3" >> "$seqres.full"
+ _pwrite_byte 0x62 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3.chk" >> "$seqres.full"
+done
+"$XFS_IO_PROG" -d -f -c "pwrite -S 0x63 -b $((BLKSZ * NR / 2)) $((BLKSZ * NR / 4)) $((BLKSZ * NR / 2))" "$TESTDIR/file3" >> "$seqres.full"
+_pwrite_byte 0x63 $((BLKSZ * NR / 4)) $((BLKSZ * NR / 2)) "$TESTDIR/file3.chk" >> "$seqres.full"
+_scratch_remount
+
+echo "Compare files"
+md5sum "$TESTDIR/file1" | _filter_scratch
+md5sum "$TESTDIR/file3" | _filter_scratch
+md5sum "$TESTDIR/file3.chk" | _filter_scratch
+
+echo "Check for damage"
+umount "$SCRATCH_MNT"
+_check_scratch_fs
+
+# success, all done
+status=0
+exit
--- /dev/null
+QA output created by 194
+Format and mount
+Create the original files
+Compare files
+bdbcf02ee0aa977795a79d25fcfdccb1 SCRATCH_MNT/test-194/file1
+fa50dba51826899c372464a153cb2117 SCRATCH_MNT/test-194/file3
+fa50dba51826899c372464a153cb2117 SCRATCH_MNT/test-194/file3.chk
+directio CoW across the transition
+Compare files
+bdbcf02ee0aa977795a79d25fcfdccb1 SCRATCH_MNT/test-194/file1
+55968a95dfc0120df4e8485576514320 SCRATCH_MNT/test-194/file3
+55968a95dfc0120df4e8485576514320 SCRATCH_MNT/test-194/file3.chk
+Check for damage
--- /dev/null
+#! /bin/bash
+# FS QA Test No. 195
+#
+# Ensuring that copy on write in buffered mode works when the CoW
+# range originally covers multiple extents, some delalloc, some not.
+# - Create a file.
+# - Reflink the odd blocks of the first file into the second file.
+# - Buffered write the even blocks of the second file.
+# - CoW across the halfway mark, starting with the unwritten extent.
+# - Check that the files are now different where we say they're different.
+#
+#-----------------------------------------------------------------------
+# Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#-----------------------------------------------------------------------
+
+seq=`basename "$0"`
+seqres="$RESULT_DIR/$seq"
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1 # failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+ cd /
+ rm -rf "$tmp".* "$TESTDIR"
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+. ./common/reflink
+
+# real QA test starts here
+_supported_os Linux
+_require_scratch_reflink
+_require_xfs_io_command "falloc"
+
+rm -f "$seqres.full"
+
+echo "Format and mount"
+_scratch_mkfs > "$seqres.full" 2>&1
+_scratch_mount >> "$seqres.full" 2>&1
+
+TESTDIR="$SCRATCH_MNT/test-$seq"
+rm -rf $TESTDIR
+mkdir $TESTDIR
+
+echo "Create the original files"
+BLKSZ=65536
+NR=64
+_pwrite_byte 0x61 0 $((BLKSZ * NR)) "$TESTDIR/file1" >> "$seqres.full"
+$XFS_IO_PROG -f -c "truncate $((BLKSZ * NR))" "$TESTDIR/file3" >> "$seqres.full"
+_pwrite_byte 0x00 0 $((BLKSZ * NR)) "$TESTDIR/file3.chk" >> "$seqres.full"
+seq 0 2 $((NR-1)) | while read f; do
+ _reflink_range "$TESTDIR/file1" $((BLKSZ * f)) "$TESTDIR/file3" $((BLKSZ * f)) $BLKSZ >> "$seqres.full"
+ _pwrite_byte 0x61 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3.chk" >> "$seqres.full"
+done
+_scratch_remount
+
+echo "Compare files"
+md5sum "$TESTDIR/file1" | _filter_scratch
+md5sum "$TESTDIR/file3" | _filter_scratch
+md5sum "$TESTDIR/file3.chk" | _filter_scratch
+
+echo "CoW across the transition"
+seq 1 2 $NR | while read f; do
+ _pwrite_byte 0x62 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3" >> "$seqres.full"
+ _pwrite_byte 0x62 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3.chk" >> "$seqres.full"
+done
+"$XFS_IO_PROG" -f -c "pwrite -S 0x63 -b $((BLKSZ * NR / 2)) $((BLKSZ * NR / 4)) $((BLKSZ * NR / 2))" "$TESTDIR/file3" >> "$seqres.full"
+_pwrite_byte 0x63 $((BLKSZ * NR / 4)) $((BLKSZ * NR / 2)) "$TESTDIR/file3.chk" >> "$seqres.full"
+_scratch_remount
+
+echo "Compare files"
+md5sum "$TESTDIR/file1" | _filter_scratch
+md5sum "$TESTDIR/file3" | _filter_scratch
+md5sum "$TESTDIR/file3.chk" | _filter_scratch
+
+echo "Check for damage"
+umount "$SCRATCH_MNT"
+_check_scratch_fs
+
+# success, all done
+status=0
+exit
--- /dev/null
+QA output created by 195
+Format and mount
+Create the original files
+Compare files
+bdbcf02ee0aa977795a79d25fcfdccb1 SCRATCH_MNT/test-195/file1
+fa50dba51826899c372464a153cb2117 SCRATCH_MNT/test-195/file3
+fa50dba51826899c372464a153cb2117 SCRATCH_MNT/test-195/file3.chk
+CoW across the transition
+Compare files
+bdbcf02ee0aa977795a79d25fcfdccb1 SCRATCH_MNT/test-195/file1
+55968a95dfc0120df4e8485576514320 SCRATCH_MNT/test-195/file3
+55968a95dfc0120df4e8485576514320 SCRATCH_MNT/test-195/file3.chk
+Check for damage
--- /dev/null
+#! /bin/bash
+# FS QA Test No. 196
+#
+# Ensuring that copy on write in direct-io mode works when the CoW
+# range originally covers multiple extents, some unwritten, some not.
+# - Create two files.
+# - Reflink the odd blocks of the first file into the second file.
+# - directio CoW across the halfway mark, starting with the unwritten extent.
+# - Check that the files are now different where we say they're different.
+#
+#-----------------------------------------------------------------------
+# Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#-----------------------------------------------------------------------
+
+seq=`basename "$0"`
+seqres="$RESULT_DIR/$seq"
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1 # failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+ cd /
+ rm -rf "$tmp".* "$TESTDIR"
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+. ./common/reflink
+
+# real QA test starts here
+_supported_os Linux
+_require_scratch_reflink
+_require_xfs_io_command "falloc"
+
+rm -f "$seqres.full"
+
+echo "Format and mount"
+_scratch_mkfs > "$seqres.full" 2>&1
+_scratch_mount >> "$seqres.full" 2>&1
+
+TESTDIR="$SCRATCH_MNT/test-$seq"
+rm -rf $TESTDIR
+mkdir $TESTDIR
+
+echo "Create the original files"
+BLKSZ=65536
+NR=64
+_pwrite_byte 0x61 0 $((BLKSZ * NR)) "$TESTDIR/file1" >> "$seqres.full"
+_pwrite_byte 0x62 0 $((BLKSZ * NR)) "$TESTDIR/file3" >> "$seqres.full"
+_pwrite_byte 0x62 0 $((BLKSZ * NR)) "$TESTDIR/file3.chk" >> "$seqres.full"
+seq 0 2 $((NR-1)) | while read f; do
+ _reflink_range "$TESTDIR/file1" $((BLKSZ * f)) "$TESTDIR/file3" $((BLKSZ * f)) $BLKSZ >> "$seqres.full"
+ _pwrite_byte 0x61 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3.chk" >> "$seqres.full"
+done
+_scratch_remount
+
+echo "Compare files"
+md5sum "$TESTDIR/file1" | _filter_scratch
+md5sum "$TESTDIR/file3" | _filter_scratch
+md5sum "$TESTDIR/file3.chk" | _filter_scratch
+
+echo "directio CoW across the transition"
+"$XFS_IO_PROG" -d -f -c "pwrite -S 0x63 -b $((BLKSZ * NR / 2)) $((BLKSZ * NR / 4)) $((BLKSZ * NR / 2))" "$TESTDIR/file3" >> "$seqres.full"
+_pwrite_byte 0x63 $((BLKSZ * NR / 4)) $((BLKSZ * NR / 2)) "$TESTDIR/file3.chk" >> "$seqres.full"
+_scratch_remount
+
+echo "Compare files"
+md5sum "$TESTDIR/file1" | _filter_scratch
+md5sum "$TESTDIR/file3" | _filter_scratch
+md5sum "$TESTDIR/file3.chk" | _filter_scratch
+
+echo "Check for damage"
+umount "$SCRATCH_MNT"
+_check_scratch_fs
+
+# success, all done
+status=0
+exit
--- /dev/null
+QA output created by 196
+Format and mount
+Create the original files
+Compare files
+bdbcf02ee0aa977795a79d25fcfdccb1 SCRATCH_MNT/test-196/file1
+d3959a68638c50af07f0258e032cb554 SCRATCH_MNT/test-196/file3
+d3959a68638c50af07f0258e032cb554 SCRATCH_MNT/test-196/file3.chk
+directio CoW across the transition
+Compare files
+bdbcf02ee0aa977795a79d25fcfdccb1 SCRATCH_MNT/test-196/file1
+55968a95dfc0120df4e8485576514320 SCRATCH_MNT/test-196/file3
+55968a95dfc0120df4e8485576514320 SCRATCH_MNT/test-196/file3.chk
+Check for damage
--- /dev/null
+#! /bin/bash
+# FS QA Test No. 197
+#
+# Ensuring that copy on write in buffered mode works when the CoW
+# range originally covers multiple extents, some unwritten, some not.
+# - Create two files.
+# - Reflink the odd blocks of the first file into the second file.
+# - CoW across the halfway mark, starting with the unwritten extent.
+# - Check that the files are now different where we say they're different.
+#
+#-----------------------------------------------------------------------
+# Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#-----------------------------------------------------------------------
+
+seq=`basename "$0"`
+seqres="$RESULT_DIR/$seq"
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1 # failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+ cd /
+ rm -rf "$tmp".* "$TESTDIR"
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+. ./common/reflink
+
+# real QA test starts here
+_supported_os Linux
+_require_scratch_reflink
+_require_xfs_io_command "falloc"
+
+rm -f "$seqres.full"
+
+echo "Format and mount"
+_scratch_mkfs > "$seqres.full" 2>&1
+_scratch_mount >> "$seqres.full" 2>&1
+
+TESTDIR="$SCRATCH_MNT/test-$seq"
+rm -rf $TESTDIR
+mkdir $TESTDIR
+
+echo "Create the original files"
+BLKSZ=65536
+NR=64
+_pwrite_byte 0x61 0 $((BLKSZ * NR)) "$TESTDIR/file1" >> "$seqres.full"
+_pwrite_byte 0x62 0 $((BLKSZ * NR)) "$TESTDIR/file3" >> "$seqres.full"
+_pwrite_byte 0x62 0 $((BLKSZ * NR)) "$TESTDIR/file3.chk" >> "$seqres.full"
+seq 0 2 $((NR-1)) | while read f; do
+ _reflink_range "$TESTDIR/file1" $((BLKSZ * f)) "$TESTDIR/file3" $((BLKSZ * f)) $BLKSZ >> "$seqres.full"
+ _pwrite_byte 0x61 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3.chk" >> "$seqres.full"
+done
+_scratch_remount
+
+echo "Compare files"
+md5sum "$TESTDIR/file1" | _filter_scratch
+md5sum "$TESTDIR/file3" | _filter_scratch
+md5sum "$TESTDIR/file3.chk" | _filter_scratch
+
+echo "CoW across the transition"
+"$XFS_IO_PROG" -f -c "pwrite -S 0x63 -b $((BLKSZ * NR / 2)) $((BLKSZ * NR / 4)) $((BLKSZ * NR / 2))" "$TESTDIR/file3" >> "$seqres.full"
+_pwrite_byte 0x63 $((BLKSZ * NR / 4)) $((BLKSZ * NR / 2)) "$TESTDIR/file3.chk" >> "$seqres.full"
+_scratch_remount
+
+echo "Compare files"
+md5sum "$TESTDIR/file1" | _filter_scratch
+md5sum "$TESTDIR/file3" | _filter_scratch
+md5sum "$TESTDIR/file3.chk" | _filter_scratch
+
+echo "Check for damage"
+umount "$SCRATCH_MNT"
+_check_scratch_fs
+
+# success, all done
+status=0
+exit
--- /dev/null
+QA output created by 197
+Format and mount
+Create the original files
+Compare files
+bdbcf02ee0aa977795a79d25fcfdccb1 SCRATCH_MNT/test-197/file1
+d3959a68638c50af07f0258e032cb554 SCRATCH_MNT/test-197/file3
+d3959a68638c50af07f0258e032cb554 SCRATCH_MNT/test-197/file3.chk
+CoW across the transition
+Compare files
+bdbcf02ee0aa977795a79d25fcfdccb1 SCRATCH_MNT/test-197/file1
+55968a95dfc0120df4e8485576514320 SCRATCH_MNT/test-197/file3
+55968a95dfc0120df4e8485576514320 SCRATCH_MNT/test-197/file3.chk
+Check for damage
--- /dev/null
+#! /bin/bash
+# FS QA Test No. 199
+#
+# Ensuring that copy on write in direct-io mode works when the CoW
+# range originally covers multiple extents, some unwritten, some not.
+# - Create a file with the following repeating sequence of blocks:
+# 1. reflinked
+# 2. unwritten
+# 3. hole
+# 4. regular block
+# 5. delalloc
+# - directio CoW across the halfway mark, starting with the unwritten extent.
+# - Check that the files are now different where we say they're different.
+#
+#-----------------------------------------------------------------------
+# Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#-----------------------------------------------------------------------
+
+seq=`basename "$0"`
+seqres="$RESULT_DIR/$seq"
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1 # failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+ cd /
+ rm -rf "$tmp".* "$TESTDIR"
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+. ./common/reflink
+
+# real QA test starts here
+_supported_os Linux
+_require_scratch_reflink
+_require_xfs_io_command "falloc"
+_require_xfs_io_command "fpunch"
+_require_cp_reflink
+
+rm -f "$seqres.full"
+
+echo "Format and mount"
+_scratch_mkfs > "$seqres.full" 2>&1
+_scratch_mount >> "$seqres.full" 2>&1
+
+TESTDIR="$SCRATCH_MNT/test-$seq"
+rm -rf $TESTDIR
+mkdir $TESTDIR
+
+echo "Create the original files"
+BLKSZ=65536
+NR=64
+_pwrite_byte 0x61 0 $((BLKSZ * NR)) "$TESTDIR/file1" >> "$seqres.full"
+$XFS_IO_PROG -f -c "truncate $((BLKSZ * NR))" "$TESTDIR/file3" >> "$seqres.full"
+# 0 blocks are reflinked
+seq 0 5 $NR | while read f; do
+ _reflink_range "$TESTDIR/file1" $((BLKSZ * f)) "$TESTDIR/file3" $((BLKSZ * f)) $BLKSZ >> "$seqres.full"
+ _pwrite_byte 0x61 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3.chk" >> "$seqres.full"
+done
+sync
+# 1 blocks are unwritten
+seq 1 5 $NR | while read f; do
+ $XFS_IO_PROG -f -c "falloc $((BLKSZ * f)) $BLKSZ" "$TESTDIR/file3" >> "$seqres.full"
+ _pwrite_byte 0x00 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3.chk" >> "$seqres.full"
+done
+sync
+# 2 blocks are holes
+seq 2 5 $NR | while read f; do
+ _pwrite_byte 0x00 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3.chk" >> "$seqres.full"
+done
+# 3 blocks are regular
+seq 3 5 $NR | while read f; do
+ _pwrite_byte 0x71 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3" >> "$seqres.full"
+ _pwrite_byte 0x71 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3.chk" >> "$seqres.full"
+done
+sync
+_scratch_remount
+
+echo "Compare files"
+md5sum "$TESTDIR/file1" | _filter_scratch
+md5sum "$TESTDIR/file3" | _filter_scratch
+md5sum "$TESTDIR/file3.chk" | _filter_scratch
+
+echo "directio CoW across the transition"
+# 4 blocks are delalloc (do later)
+seq 4 5 $NR | while read f; do
+ _pwrite_byte 0x62 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3" >> "$seqres.full"
+ _pwrite_byte 0x62 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3.chk" >> "$seqres.full"
+done
+# now cow
+"$XFS_IO_PROG" -d -f -c "pwrite -S 0x63 -b $((BLKSZ * NR / 2)) $((BLKSZ * NR / 4)) $((BLKSZ * NR / 2))" "$TESTDIR/file3" >> "$seqres.full"
+_pwrite_byte 0x63 $((BLKSZ * NR / 4)) $((BLKSZ * NR / 2)) "$TESTDIR/file3.chk" >> "$seqres.full"
+_scratch_remount
+
+echo "Compare files"
+md5sum "$TESTDIR/file1" | _filter_scratch
+md5sum "$TESTDIR/file3" | _filter_scratch
+md5sum "$TESTDIR/file3.chk" | _filter_scratch
+
+echo "Check for damage"
+umount "$SCRATCH_MNT"
+_check_scratch_fs
+
+# success, all done
+status=0
+exit
--- /dev/null
+QA output created by 199
+Format and mount
+Create the original files
+Compare files
+bdbcf02ee0aa977795a79d25fcfdccb1 SCRATCH_MNT/test-199/file1
+6366fd359371414186688a0ef6988893 SCRATCH_MNT/test-199/file3
+6366fd359371414186688a0ef6988893 SCRATCH_MNT/test-199/file3.chk
+directio CoW across the transition
+Compare files
+bdbcf02ee0aa977795a79d25fcfdccb1 SCRATCH_MNT/test-199/file1
+36f6b5317a9a921fc91175390ccf7f69 SCRATCH_MNT/test-199/file3
+36f6b5317a9a921fc91175390ccf7f69 SCRATCH_MNT/test-199/file3.chk
+Check for damage
--- /dev/null
+#! /bin/bash
+# FS QA Test No. 200
+#
+# Ensuring that copy on write in buffered mode works when the CoW
+# range originally covers multiple extents, some unwritten, some not.
+# - Create a file with the following repeating sequence of blocks:
+# 1. reflinked
+# 2. unwritten
+# 3. hole
+# 4. regular block
+# 5. delalloc
+# - CoW across the halfway mark, starting with the unwritten extent.
+# - Check that the files are now different where we say they're different.
+#
+#-----------------------------------------------------------------------
+# Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#-----------------------------------------------------------------------
+
+seq=`basename "$0"`
+seqres="$RESULT_DIR/$seq"
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1 # failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+ cd /
+ rm -rf "$tmp".* "$TESTDIR"
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+. ./common/reflink
+
+# real QA test starts here
+_supported_os Linux
+_require_scratch_reflink
+_require_xfs_io_command "falloc"
+_require_xfs_io_command "fpunch"
+_require_cp_reflink
+
+rm -f "$seqres.full"
+
+echo "Format and mount"
+_scratch_mkfs > "$seqres.full" 2>&1
+_scratch_mount >> "$seqres.full" 2>&1
+
+TESTDIR="$SCRATCH_MNT/test-$seq"
+rm -rf $TESTDIR
+mkdir $TESTDIR
+
+echo "Create the original files"
+BLKSZ=65536
+NR=64
+_pwrite_byte 0x61 0 $((BLKSZ * NR)) "$TESTDIR/file1" >> "$seqres.full"
+$XFS_IO_PROG -f -c "truncate $((BLKSZ * NR))" "$TESTDIR/file3" >> "$seqres.full"
+# 0 blocks are reflinked
+seq 0 5 $NR | while read f; do
+ _reflink_range "$TESTDIR/file1" $((BLKSZ * f)) "$TESTDIR/file3" $((BLKSZ * f)) $BLKSZ >> "$seqres.full"
+ _pwrite_byte 0x61 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3.chk" >> "$seqres.full"
+done
+sync
+# 1 blocks are unwritten
+seq 1 5 $NR | while read f; do
+ $XFS_IO_PROG -f -c "falloc $((BLKSZ * f)) $BLKSZ" "$TESTDIR/file3" >> "$seqres.full"
+ _pwrite_byte 0x00 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3.chk" >> "$seqres.full"
+done
+sync
+# 2 blocks are holes
+seq 2 5 $NR | while read f; do
+ _pwrite_byte 0x00 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3.chk" >> "$seqres.full"
+done
+# 3 blocks are regular
+seq 3 5 $NR | while read f; do
+ _pwrite_byte 0x71 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3" >> "$seqres.full"
+ _pwrite_byte 0x71 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3.chk" >> "$seqres.full"
+done
+sync
+_scratch_remount
+
+echo "Compare files"
+md5sum "$TESTDIR/file1" | _filter_scratch
+md5sum "$TESTDIR/file3" | _filter_scratch
+md5sum "$TESTDIR/file3.chk" | _filter_scratch
+
+echo "directio CoW across the transition"
+# 4 blocks are delalloc (do later)
+seq 4 5 $NR | while read f; do
+ _pwrite_byte 0x62 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3" >> "$seqres.full"
+ _pwrite_byte 0x62 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3.chk" >> "$seqres.full"
+done
+# now cow
+"$XFS_IO_PROG" -f -c "pwrite -S 0x63 -b $((BLKSZ * NR / 2)) $((BLKSZ * NR / 4)) $((BLKSZ * NR / 2))" "$TESTDIR/file3" >> "$seqres.full"
+_pwrite_byte 0x63 $((BLKSZ * NR / 4)) $((BLKSZ * NR / 2)) "$TESTDIR/file3.chk" >> "$seqres.full"
+_scratch_remount
+
+echo "Compare files"
+md5sum "$TESTDIR/file1" | _filter_scratch
+md5sum "$TESTDIR/file3" | _filter_scratch
+md5sum "$TESTDIR/file3.chk" | _filter_scratch
+
+echo "Check for damage"
+umount "$SCRATCH_MNT"
+_check_scratch_fs
+
+# success, all done
+status=0
+exit
--- /dev/null
+QA output created by 200
+Format and mount
+Create the original files
+Compare files
+bdbcf02ee0aa977795a79d25fcfdccb1 SCRATCH_MNT/test-200/file1
+6366fd359371414186688a0ef6988893 SCRATCH_MNT/test-200/file3
+6366fd359371414186688a0ef6988893 SCRATCH_MNT/test-200/file3.chk
+directio CoW across the transition
+Compare files
+bdbcf02ee0aa977795a79d25fcfdccb1 SCRATCH_MNT/test-200/file1
+36f6b5317a9a921fc91175390ccf7f69 SCRATCH_MNT/test-200/file3
+36f6b5317a9a921fc91175390ccf7f69 SCRATCH_MNT/test-200/file3.chk
+Check for damage
--- /dev/null
+#! /bin/bash
+# FS QA Test No. 201
+#
+# See what happens if we dirty a lot of pages via CoW and immediately
+# unlink the file.
+#
+#-----------------------------------------------------------------------
+# Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#-----------------------------------------------------------------------
+
+seq=`basename "$0"`
+seqres="$RESULT_DIR/$seq"
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1 # failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+ cd /
+ rm -rf "$tmp".* "$TESTDIR"
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+. ./common/reflink
+
+# real QA test starts here
+_supported_os Linux
+_require_scratch_reflink
+_require_xfs_io_command "falloc"
+
+rm -f "$seqres.full"
+
+echo "Format and mount"
+_scratch_mkfs > "$seqres.full" 2>&1
+_scratch_mount >> "$seqres.full" 2>&1
+
+TESTDIR="$SCRATCH_MNT/test-$seq"
+rm -rf $TESTDIR
+mkdir $TESTDIR
+
+echo "Create the original files"
+BLKSZ=65536
+NR=64
+_pwrite_byte 0x61 0 $((BLKSZ * NR)) "$TESTDIR/file1" >> "$seqres.full"
+_pwrite_byte 0x62 0 $((BLKSZ * NR)) "$TESTDIR/file3" >> "$seqres.full"
+_pwrite_byte 0x62 0 $((BLKSZ * NR)) "$TESTDIR/file3.chk" >> "$seqres.full"
+seq 0 2 $((NR-1)) | while read f; do
+ _reflink_range "$TESTDIR/file1" $((BLKSZ * f)) "$TESTDIR/file3" $((BLKSZ * f)) $BLKSZ >> "$seqres.full"
+ _pwrite_byte 0x61 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3.chk" >> "$seqres.full"
+done
+_scratch_remount
+
+echo "Compare files"
+md5sum "$TESTDIR/file1" | _filter_scratch
+md5sum "$TESTDIR/file3" | _filter_scratch
+md5sum "$TESTDIR/file3.chk" | _filter_scratch
+
+echo "CoW and unmount"
+"$XFS_IO_PROG" -f -c "pwrite -S 0x63 -b $((BLKSZ * NR / 2)) $((BLKSZ * NR / 4)) $((BLKSZ * NR / 2))" "$TESTDIR/file3" >> "$seqres.full"
+rm "$TESTDIR/file3"
+
+echo "Check for damage"
+umount "$SCRATCH_MNT"
+_check_scratch_fs
+
+# success, all done
+status=0
+exit
--- /dev/null
+QA output created by 201
+Format and mount
+Create the original files
+Compare files
+bdbcf02ee0aa977795a79d25fcfdccb1 SCRATCH_MNT/test-201/file1
+d3959a68638c50af07f0258e032cb554 SCRATCH_MNT/test-201/file3
+d3959a68638c50af07f0258e032cb554 SCRATCH_MNT/test-201/file3.chk
+CoW and unmount
+Check for damage
--- /dev/null
+#! /bin/bash
+# FS QA Test No. 202
+#
+# See what happens if we CoW across not-block-aligned EOF.
+#
+#-----------------------------------------------------------------------
+# Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#-----------------------------------------------------------------------
+
+seq=`basename "$0"`
+seqres="$RESULT_DIR/$seq"
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1 # failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+ cd /
+ rm -rf "$tmp".* "$TESTDIR"
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+. ./common/reflink
+
+# real QA test starts here
+_supported_os Linux
+_require_scratch_reflink
+_require_cp_reflink
+
+rm -f "$seqres.full"
+
+echo "Format and mount"
+_scratch_mkfs > "$seqres.full" 2>&1
+_scratch_mount >> "$seqres.full" 2>&1
+
+TESTDIR="$SCRATCH_MNT/test-$seq"
+rm -rf $TESTDIR
+mkdir $TESTDIR
+
+echo "Create the original files"
+BLKSZ=65536
+_pwrite_byte 0x61 0 $((BLKSZ + 17)) "$TESTDIR/file1" >> "$seqres.full"
+_cp_reflink "$TESTDIR/file1" "$TESTDIR/file2"
+_pwrite_byte 0x61 0 $((BLKSZ + 17)) "$TESTDIR/file2.chk" >> "$seqres.full"
+_scratch_remount
+
+echo "Compare files"
+md5sum "$TESTDIR/file1" | _filter_scratch
+md5sum "$TESTDIR/file2" | _filter_scratch
+md5sum "$TESTDIR/file2.chk" | _filter_scratch
+
+echo "CoW and unmount"
+"$XFS_IO_PROG" -f -c "pwrite -S 0x63 $((BLKSZ + 17)) 17" "$TESTDIR/file2" >> "$seqres.full"
+"$XFS_IO_PROG" -f -c "pwrite -S 0x63 $((BLKSZ + 17)) 17" "$TESTDIR/file2.chk" >> "$seqres.full"
+_scratch_remount
+
+echo "Compare files"
+md5sum "$TESTDIR/file1" | _filter_scratch
+md5sum "$TESTDIR/file2" | _filter_scratch
+md5sum "$TESTDIR/file2.chk" | _filter_scratch
+
+echo "Check for damage"
+umount "$SCRATCH_MNT"
+_check_scratch_fs
+
+# success, all done
+status=0
+exit
--- /dev/null
+QA output created by 202
+Format and mount
+Create the original files
+Compare files
+75f550706b7d54e6ae59a8220b532285 SCRATCH_MNT/test-202/file1
+75f550706b7d54e6ae59a8220b532285 SCRATCH_MNT/test-202/file2
+75f550706b7d54e6ae59a8220b532285 SCRATCH_MNT/test-202/file2.chk
+CoW and unmount
+Compare files
+75f550706b7d54e6ae59a8220b532285 SCRATCH_MNT/test-202/file1
+7cd112044b63b2c979f45e7c1e7cc85f SCRATCH_MNT/test-202/file2
+7cd112044b63b2c979f45e7c1e7cc85f SCRATCH_MNT/test-202/file2.chk
+Check for damage
--- /dev/null
+#! /bin/bash
+# FS QA Test No. 203
+#
+# See what happens if we DIO CoW across not-block-aligned EOF.
+#
+#-----------------------------------------------------------------------
+# Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#-----------------------------------------------------------------------
+
+seq=`basename "$0"`
+seqres="$RESULT_DIR/$seq"
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1 # failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+ cd /
+ rm -rf "$tmp".* "$TESTDIR"
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+. ./common/reflink
+
+# real QA test starts here
+_supported_os Linux
+_require_scratch_reflink
+_require_cp_reflink
+
+rm -f "$seqres.full"
+
+echo "Format and mount"
+_scratch_mkfs > "$seqres.full" 2>&1
+_scratch_mount >> "$seqres.full" 2>&1
+
+TESTDIR="$SCRATCH_MNT/test-$seq"
+rm -rf $TESTDIR
+mkdir $TESTDIR
+
+echo "Create the original files"
+BLKSZ=65536
+_pwrite_byte 0x61 0 $((BLKSZ + 17)) "$TESTDIR/file1" >> "$seqres.full"
+_cp_reflink "$TESTDIR/file1" "$TESTDIR/file2"
+_pwrite_byte 0x61 0 $((BLKSZ + 17)) "$TESTDIR/file2.chk" >> "$seqres.full"
+_scratch_remount
+
+echo "Compare files"
+md5sum "$TESTDIR/file1" | _filter_scratch
+md5sum "$TESTDIR/file2" | _filter_scratch
+md5sum "$TESTDIR/file2.chk" | _filter_scratch
+
+echo "CoW and unmount"
+"$XFS_IO_PROG" -d -f -c "pwrite -S 0x63 $BLKSZ $BLKSZ" "$TESTDIR/file2" >> "$seqres.full"
+"$XFS_IO_PROG" -f -c "pwrite -S 0x63 $BLKSZ $BLKSZ" "$TESTDIR/file2.chk" >> "$seqres.full"
+_scratch_remount
+
+echo "Compare files"
+md5sum "$TESTDIR/file1" | _filter_scratch
+md5sum "$TESTDIR/file2" | _filter_scratch
+md5sum "$TESTDIR/file2.chk" | _filter_scratch
+
+echo "Check for damage"
+umount "$SCRATCH_MNT"
+_check_scratch_fs
+
+# success, all done
+status=0
+exit
--- /dev/null
+QA output created by 203
+Format and mount
+Create the original files
+Compare files
+75f550706b7d54e6ae59a8220b532285 SCRATCH_MNT/test-203/file1
+75f550706b7d54e6ae59a8220b532285 SCRATCH_MNT/test-203/file2
+75f550706b7d54e6ae59a8220b532285 SCRATCH_MNT/test-203/file2.chk
+CoW and unmount
+Compare files
+75f550706b7d54e6ae59a8220b532285 SCRATCH_MNT/test-203/file1
+227f44bb2dcf251ebf0217edaeb1e365 SCRATCH_MNT/test-203/file2
+227f44bb2dcf251ebf0217edaeb1e365 SCRATCH_MNT/test-203/file2.chk
+Check for damage
180 auto quick clone
181 auto quick clone
182 auto quick clone
+183 auto quick clone
184 metadata auto quick
+185 auto quick clone
+186 auto quick clone
+187 auto quick clone
+188 auto quick clone
+189 auto quick clone
+190 auto quick clone
+191 auto quick clone
192 atime auto
193 metadata auto quick
+194 auto quick clone
+195 auto quick clone
+196 auto quick clone
+197 auto quick clone
198 auto aio quick
+199 auto quick clone
+200 auto quick clone
+201 auto quick clone
+202 auto quick clone
+203 auto quick clone
204 metadata rw auto
207 auto aio quick
208 auto aio