blob: d5c1835ca488403b763e0781f9f05c4021039cbe [file] [log] [blame]
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2025 Oracle. All Rights Reserved.
#
# FS QA Test No. 770
#
# basic tests for large atomic writes with mixed mappings
#
. ./common/preamble
_begin_fstest auto quick rw atomicwrites
. ./common/atomicwrites
. ./common/filter
. ./common/reflink
_require_scratch
_require_block_device $SCRATCH_DEV
_require_xfs_io_command "statx" "-r"
_require_atomic_write_test_commands
_require_scratch_write_atomic_multi_fsblock
_scratch_mkfs_sized $((500 * 1048576)) >> $seqres.full 2>&1
_scratch_mount
file1=$SCRATCH_MNT/file1
file2=$SCRATCH_MNT/file2
file3=$SCRATCH_MNT/file3
touch $file1
max_awu=$(_get_atomic_write_unit_max $file1)
test $max_awu -ge 65536 || _notrun "test requires atomic writes up to 64k"
min_awu=$(_get_atomic_write_unit_min $file1)
test $min_awu -le 4096 || _notrun "test requires atomic writes down to 4k"
bsize=$(_get_file_block_size $SCRATCH_MNT)
test $max_awu -gt $((bsize * 2)) || \
_notrun "max atomic write $max_awu less than 2 fsblocks $bsize"
# non-reflink tests
echo "atomic write hole+mapped+hole"
dd if=/dev/zero of=$file1 bs=1M count=10 conv=fsync >>$seqres.full 2>&1
$XFS_IO_PROG -dc "pwrite -D -V1 4096000 4096" $file1 >>$seqres.full 2>&1
$XFS_IO_PROG -dc "pwrite -D -V1 4096 4096" $file1 >>$seqres.full 2>&1
$XFS_IO_PROG -dc "pwrite -A -D -V1 0 65536" $file1 >>$seqres.full 2>&1
md5sum $file1 | _filter_scratch
echo "atomic write adjacent mapped+hole and hole+mapped"
dd if=/dev/zero of=$file1 bs=1M count=10 conv=fsync >>$seqres.full 2>&1
$XFS_IO_PROG -dc "pwrite -D -V1 4096000 4096" $file1 >>$seqres.full 2>&1
$XFS_IO_PROG -dc "pwrite -D -V1 0 4096" $file1 >>$seqres.full 2>&1
$XFS_IO_PROG -dc "pwrite -D -V1 61440 4096" $file1 >>$seqres.full 2>&1
$XFS_IO_PROG -dc "pwrite -A -D -V1 0 32768" $file1 >>$seqres.full 2>&1
$XFS_IO_PROG -dc "pwrite -A -D -V1 32768 32768" $file1 >>$seqres.full 2>&1
md5sum $file1 | _filter_scratch
echo "atomic write mapped+hole+mapped"
dd if=/dev/zero of=$file1 bs=1M count=10 conv=fsync >>$seqres.full 2>&1
$XFS_IO_PROG -dc "pwrite -D -V1 4096000 4096" $file1 >>$seqres.full 2>&1
$XFS_IO_PROG -dc "pwrite -D -V1 0 4096" $file1 >>$seqres.full 2>&1
$XFS_IO_PROG -dc "pwrite -D -V1 61440 4096" $file1 >>$seqres.full 2>&1
$XFS_IO_PROG -dc "pwrite -A -D -V1 0 65536" $file1 >>$seqres.full 2>&1
md5sum $file1 | _filter_scratch
echo "atomic write unwritten+mapped+unwritten"
dd if=/dev/zero of=$file1 bs=1M count=10 conv=fsync >>$seqres.full 2>&1
$XFS_IO_PROG -fc "falloc 0 4096000" $file1 >>$seqres.full 2>&1
$XFS_IO_PROG -dc "pwrite -D -V1 4096 4096" $file1 >>$seqres.full 2>&1
$XFS_IO_PROG -dc "pwrite -A -D -V1 0 65536" $file1 >>$seqres.full 2>&1
md5sum $file1 | _filter_scratch
echo "atomic write adjacent mapped+unwritten and unwritten+mapped"
dd if=/dev/zero of=$file1 bs=1M count=10 conv=fsync >>$seqres.full 2>&1
$XFS_IO_PROG -fc "falloc 0 4096000" $file1 >>$seqres.full 2>&1
$XFS_IO_PROG -dc "pwrite -D -V1 0 4096" $file1 >>$seqres.full 2>&1
$XFS_IO_PROG -dc "pwrite -D -V1 61440 4096" $file1 >>$seqres.full 2>&1
$XFS_IO_PROG -dc "pwrite -A -D -V1 0 32768" $file1 >>$seqres.full 2>&1
$XFS_IO_PROG -dc "pwrite -A -D -V1 32768 32768" $file1 >>$seqres.full 2>&1
md5sum $file1 | _filter_scratch
echo "atomic write mapped+unwritten+mapped"
dd if=/dev/zero of=$file1 bs=1M count=10 conv=fsync >>$seqres.full 2>&1
$XFS_IO_PROG -fc "falloc 0 4096000" $file1 >>$seqres.full 2>&1
$XFS_IO_PROG -dc "pwrite -D -V1 0 4096" $file1 >>$seqres.full 2>&1
$XFS_IO_PROG -dc "pwrite -D -V1 61440 4096" $file1 >>$seqres.full 2>&1
$XFS_IO_PROG -dc "pwrite -A -D -V1 0 65536" $file1 >>$seqres.full 2>&1
md5sum $file1 | _filter_scratch
echo "atomic write interweaved hole+unwritten+written"
dd if=/dev/zero of=$file1 bs=1M count=10 conv=fsync >>$seqres.full 2>&1
blksz=4096
nr=32
_weave_file_rainbow $blksz $nr $file1 >>$seqres.full 2>&1
$XFS_IO_PROG -dc "pwrite -A -D -V1 0 65536" $file1 >>$seqres.full 2>&1
md5sum $file1 | _filter_scratch
echo "atomic write at EOF"
dd if=/dev/zero of=$file1 bs=32K count=12 conv=fsync >>$seqres.full 2>&1
$XFS_IO_PROG -dc "pwrite -A -D -V1 360448 65536" $file1 >>$seqres.full 2>&1
md5sum $file1 | _filter_scratch
echo "atomic write preallocated region"
fallocate -l 10M $file1
$XFS_IO_PROG -dc "pwrite -A -D -V1 0 65536" $file1 >>$seqres.full 2>&1
md5sum $file1 | _filter_scratch
# atomic write max size
dd if=/dev/zero of=$file1 bs=1M count=10 conv=fsync >>$seqres.full 2>&1
aw_max=$(_get_atomic_write_unit_max $file1)
cp $file1 $file1.chk
$XFS_IO_PROG -dc "pwrite -A -D -V1 0 $aw_max" $file1 >>$seqres.full 2>&1
$XFS_IO_PROG -c "pwrite 0 $aw_max" $file1.chk >>$seqres.full 2>&1
cmp -s $file1 $file1.chk || echo "file1 doesnt match file1.chk"
echo "atomic write max size on fragmented fs"
avail=`_get_available_space $SCRATCH_MNT`
filesizemb=$((avail / 1024 / 1024 - 1))
fragmentedfile=$SCRATCH_MNT/fragmentedfile
$XFS_IO_PROG -fc "falloc 0 ${filesizemb}m" $fragmentedfile
$here/src/punch-alternating $fragmentedfile
touch $file3
$XFS_IO_PROG -dc "pwrite -A -D -V1 0 65536" $file3 >>$seqres.full 2>&1
md5sum $file3 | _filter_scratch
# success, all done
status=0
exit