Message ID | 20250408075933.32541-1-catherine.hoang@oracle.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | [v4] generic: add a test for atomic writes | expand |
On 08/04/2025 08:59, Catherine Hoang wrote: > Add a test to validate the new atomic writes feature. > > Signed-off-by: Catherine Hoang<catherine.hoang@oracle.com> > Reviewed-by: Nirjhar Roy (IBM)<nirjhar.roy.lists@gmail.com> Please see comment below, but this seems ok apart from that: Reviewed-by: John Garry <john.g.garry@oracle.com> > --- > common/rc | 51 +++++++++++++ > tests/generic/765 | 172 ++++++++++++++++++++++++++++++++++++++++++ > tests/generic/765.out | 2 + > 3 files changed, 225 insertions(+) > create mode 100755 tests/generic/765 > create mode 100644 tests/generic/765.out > > diff --git a/common/rc b/common/rc > index 16d627e1..25e6a1f7 100644 > +} > + > +sys_min_write=$(cat "/sys/block/$(_short_dev $SCRATCH_DEV)/queue/atomic_write_unit_min_bytes") > +sys_max_write=$(cat "/sys/block/$(_short_dev $SCRATCH_DEV)/queue/atomic_write_unit_max_bytes") > + > +bdev_min_write=$(_get_atomic_write_unit_min $SCRATCH_DEV) > +bdev_max_write=$(_get_atomic_write_unit_max $SCRATCH_DEV) > + > +if [ "$sys_min_write" -ne "$bdev_min_write" ]; then > + echo "bdev min write != sys min write" > +fi > +if [ "$sys_max_write" -ne "$bdev_max_write" ]; then > + echo "bdev max write != sys max write" Note: for large atomic writes according to [0], these may not be the same. I am not sure how this will affect your test. [0] https://lore.kernel.org/linux-xfs/20250408104209.1852036-1-john.g.garry@oracle.com/T/#m374933d93697082f9267515f807930d774c8634b > +fi > + > +# Test all supported block sizes between bdev min and max > +for ((bsize=$bdev_min_write; bsize<=bdev_max_write; bsize*=2)); do > + test_atomic_writes $bsize > +done; > + > +# Check that atomic write fails if bsize < bdev min or bsize > bdev max > +test_atomic_write_bounds $((bdev_min_write / 2)) > +test_atomic_write_bounds $((bdev_max_write * 2)) > + > +# success, all done > +echo Silence is golden > +status=0 > +exit > diff --git a/tests/generic/765.out b/tests/generic/765.out > new file mode 100644 > index 00000000..39c254ae > --- /dev/null > +++ b/tests/generic/765.out > @@ -0,0 +1,2 @@ > +QA output created by 765 > +Silence is golden > -- 2.34.1 >
On Tue, Apr 08, 2025 at 12:59:33AM -0700, Catherine Hoang wrote: > Add a test to validate the new atomic writes feature. > > Signed-off-by: Catherine Hoang <catherine.hoang@oracle.com> > Reviewed-by: Nirjhar Roy (IBM) <nirjhar.roy.lists@gmail.com> > --- > common/rc | 51 +++++++++++++ > tests/generic/765 | 172 ++++++++++++++++++++++++++++++++++++++++++ > tests/generic/765.out | 2 + > 3 files changed, 225 insertions(+) > create mode 100755 tests/generic/765 > create mode 100644 tests/generic/765.out > > diff --git a/common/rc b/common/rc > index 16d627e1..25e6a1f7 100644 > --- a/common/rc > +++ b/common/rc > @@ -2996,6 +2996,10 @@ _require_xfs_io_command() > opts+=" -d" > pwrite_opts+="-V 1 -b 4k" > fi > + if [ "$param" == "-A" ]; then > + opts+=" -d" > + pwrite_opts+="-D -V 1 -b 4k" > + fi > testio=`$XFS_IO_PROG -f $opts -c \ > "pwrite $pwrite_opts $param 0 4k" $testfile 2>&1` > param_checked="$pwrite_opts $param" > @@ -5443,6 +5447,53 @@ _require_scratch_btime() > _scratch_unmount > } > > +_get_atomic_write_unit_min() > +{ > + $XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $1 | \ > + grep atomic_write_unit_min | grep -o '[0-9]\+' > +} > + > +_get_atomic_write_unit_max() > +{ > + $XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $1 | \ > + grep atomic_write_unit_max | grep -o '[0-9]\+' > +} > + > +_get_atomic_write_segments_max() > +{ > + $XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $1 | \ > + grep atomic_write_segments_max | grep -o '[0-9]\+' > +} > + > +_require_scratch_write_atomic() > +{ > + _require_scratch > + > + export STATX_WRITE_ATOMIC=0x10000 > + > + awu_min_bdev=$(_get_atomic_write_unit_min $SCRATCH_DEV) > + awu_max_bdev=$(_get_atomic_write_unit_max $SCRATCH_DEV) > + > + if [ $awu_min_bdev -eq 0 ] && [ $awu_max_bdev -eq 0 ]; then > + _notrun "write atomic not supported by this block device" > + fi > + > + _scratch_mkfs > /dev/null 2>&1 > + _scratch_mount > + > + testfile=$SCRATCH_MNT/testfile > + touch $testfile > + > + awu_min_fs=$(_get_atomic_write_unit_min $testfile) > + awu_max_fs=$(_get_atomic_write_unit_max $testfile) > + > + _scratch_unmount > + > + if [ $awu_min_fs -eq 0 ] && [ $awu_max_fs -eq 0 ]; then > + _notrun "write atomic not supported by this filesystem" > + fi > +} > + > _require_inode_limits() > { > if [ $(_get_free_inode $TEST_DIR) -eq 0 ]; then > diff --git a/tests/generic/765 b/tests/generic/765 > new file mode 100755 > index 00000000..f54f2e2e > --- /dev/null > +++ b/tests/generic/765 > @@ -0,0 +1,172 @@ > +#! /bin/bash > +# SPDX-License-Identifier: GPL-2.0 > +# Copyright (c) 2025 Oracle. All Rights Reserved. > +# > +# FS QA Test 765 > +# > +# Validate atomic write support > +# > +. ./common/preamble > +_begin_fstest auto quick rw > + > +_require_scratch_write_atomic > +_require_xfs_io_command pwrite -A > + > +check_supported_bsize() > +{ > + local bsize=$1 > + > + case "$FSTYP" in > + "xfs") > + min_bsize=1024 > + knob="/sys/kernel/mm/transparent_hugepage/shmem_enabled" > + test -w "$knob" && max_bsize=65536 || max_bsize=4096 What if the bsae page size is 64k and THP are not enabled? This detection will not result in max_bsize=65536. Regrettably I think the only way to find out for sure is to format in a loop: for ((i = 65536; i >= 1024; i /= 2)); do mkfs.xfs -b size=$i... || continue if mount...; then max_bsize=$i umount break; fi done > + mkfs_opts="-b size=$bsize" > + ;; > + "ext4") > + min_bsize=1024 > + max_bsize=4096 > + mkfs_opts="-b $bsize" > + ;; > + *) > + _notrun "$FSTYP does not support atomic writes" > + ;; > + esac > + > + if [ "$bsize" -lt "$min_bsize" ] || [ "$bsize" -gt "$max_bsize" ]; then > + return 1 > + fi > + > + return 0 > +} > + > +test_atomic_writes() > +{ > + local bsize=$1 > + > + if ! check_supported_bsize $bsize; then > + return > + fi > + > + _scratch_mkfs $mkfs_opts >> $seqres.full > + _scratch_mount > + > + test "$FSTYP" = "xfs" && _xfs_force_bdev data $SCRATCH_MNT > + > + testfile=$SCRATCH_MNT/testfile > + touch $testfile > + > + file_min_write=$(_get_atomic_write_unit_min $testfile) > + file_max_write=$(_get_atomic_write_unit_max $testfile) > + file_max_segments=$(_get_atomic_write_segments_max $testfile) > + > + # Check that atomic min/max = FS block size > + test $file_min_write -eq $bsize || \ > + echo "atomic write min $file_min_write, should be fs block size $bsize" > + test $file_min_write -eq $bsize || \ > + echo "atomic write max $file_max_write, should be fs block size $bsize" > + test $file_max_segments -eq 1 || \ > + echo "atomic write max segments $file_max_segments, should be 1" > + > + # Check that we can perform an atomic write of len = FS block size > + bytes_written=$($XFS_IO_PROG -dc "pwrite -A -D -V1 -b $bsize 0 $bsize" $testfile | \ > + grep wrote | awk -F'[/ ]' '{print $2}') > + test $bytes_written -eq $bsize || echo "atomic write len=$bsize failed" > + > + # Check that we can perform an atomic single-block cow write > + if [ "$FSTYP" == "xfs" ]; then > + testfile_cp=$SCRATCH_MNT/testfile_copy > + if _xfs_has_feature $SCRATCH_MNT reflink; then > + cp --reflink $testfile $testfile_cp _cp_reflink from common/rc > + fi > + bytes_written=$($XFS_IO_PROG -dc "pwrite -A -D -V1 -b $bsize 0 $bsize" $testfile_cp | \ > + grep wrote | awk -F'[/ ]' '{print $2}') > + test $bytes_written -eq $bsize || echo "atomic write on reflinked file failed" > + fi > + > + # Check that we can perform an atomic write on an unwritten block > + $XFS_IO_PROG -c "falloc $bsize $bsize" $testfile > + bytes_written=$($XFS_IO_PROG -dc "pwrite -A -D -V1 -b $bsize $bsize $bsize" $testfile | \ > + grep wrote | awk -F'[/ ]' '{print $2}') > + test $bytes_written -eq $bsize || echo "atomic write to unwritten block failed" > + > + # Check that we can perform an atomic write on a sparse hole > + $XFS_IO_PROG -c "fpunch 0 $bsize" $testfile > + bytes_written=$($XFS_IO_PROG -dc "pwrite -A -D -V1 -b $bsize 0 $bsize" $testfile | \ > + grep wrote | awk -F'[/ ]' '{print $2}') > + test $bytes_written -eq $bsize || echo "atomic write to sparse hole failed" > + > + # Check that we can perform an atomic write on a fully mapped block > + bytes_written=$($XFS_IO_PROG -dc "pwrite -A -D -V1 -b $bsize 0 $bsize" $testfile | \ > + grep wrote | awk -F'[/ ]' '{print $2}') > + test $bytes_written -eq $bsize || echo "atomic write to mapped block failed" > + > + # Reject atomic write if len is out of bounds > + $XFS_IO_PROG -dc "pwrite -A -D -V1 -b $bsize 0 $((bsize - 1))" $testfile 2>> $seqres.full && \ > + echo "atomic write len=$((bsize - 1)) should fail" > + $XFS_IO_PROG -dc "pwrite -A -D -V1 -b $bsize 0 $((bsize + 1))" $testfile 2>> $seqres.full && \ > + echo "atomic write len=$((bsize + 1)) should fail" > + > + # Reject atomic write when iovecs > 1 > + $XFS_IO_PROG -dc "pwrite -A -D -V2 -b $bsize 0 $bsize" $testfile 2>> $seqres.full && \ > + echo "atomic write only supports iovec count of 1" > + > + # Reject atomic write when not using direct I/O > + $XFS_IO_PROG -c "pwrite -A -V1 -b $bsize 0 $bsize" $testfile 2>> $seqres.full && \ > + echo "atomic write requires direct I/O" > + > + # Reject atomic write when offset % bsize != 0 > + $XFS_IO_PROG -dc "pwrite -A -D -V1 -b $bsize 1 $bsize" $testfile 2>> $seqres.full && \ > + echo "atomic write requires offset to be aligned to bsize" > + > + _scratch_unmount > +} > + > +test_atomic_write_bounds() > +{ > + local bsize=$1 > + > + if ! check_supported_bsize $bsize; then > + return > + fi > + > + _scratch_mkfs $mkfs_opts >> $seqres.full > + _scratch_mount > + > + test "$FSTYP" = "xfs" && _xfs_force_bdev data $SCRATCH_MNT > + > + testfile=$SCRATCH_MNT/testfile > + touch $testfile > + > + $XFS_IO_PROG -dc "pwrite -A -D -V1 -b $bsize 0 $bsize" $testfile 2>> $seqres.full && \ > + echo "atomic write should fail when bsize is out of bounds" > + > + _scratch_unmount > +} > + > +sys_min_write=$(cat "/sys/block/$(_short_dev $SCRATCH_DEV)/queue/atomic_write_unit_min_bytes") > +sys_max_write=$(cat "/sys/block/$(_short_dev $SCRATCH_DEV)/queue/atomic_write_unit_max_bytes") Aren't these the block device min/max untorn write units? > +bdev_min_write=$(_get_atomic_write_unit_min $SCRATCH_DEV) > +bdev_max_write=$(_get_atomic_write_unit_max $SCRATCH_DEV) And aren't these the filesystem min/max untorn write units? Shouldn't the names be switched? bdev_awu_min=$(cat /sys/block...) file_awu_min=$(_get_atomic_write_unit_min...) --D > + > +if [ "$sys_min_write" -ne "$bdev_min_write" ]; then > + echo "bdev min write != sys min write" > +fi > +if [ "$sys_max_write" -ne "$bdev_max_write" ]; then > + echo "bdev max write != sys max write" > +fi > + > +# Test all supported block sizes between bdev min and max > +for ((bsize=$bdev_min_write; bsize<=bdev_max_write; bsize*=2)); do > + test_atomic_writes $bsize > +done; > + > +# Check that atomic write fails if bsize < bdev min or bsize > bdev max > +test_atomic_write_bounds $((bdev_min_write / 2)) > +test_atomic_write_bounds $((bdev_max_write * 2)) > + > +# success, all done > +echo Silence is golden > +status=0 > +exit > diff --git a/tests/generic/765.out b/tests/generic/765.out > new file mode 100644 > index 00000000..39c254ae > --- /dev/null > +++ b/tests/generic/765.out > @@ -0,0 +1,2 @@ > +QA output created by 765 > +Silence is golden > -- > 2.34.1 > >
> On Apr 8, 2025, at 9:24 AM, John Garry <john.g.garry@oracle.com> wrote: > > On 08/04/2025 08:59, Catherine Hoang wrote: >> Add a test to validate the new atomic writes feature. >> Signed-off-by: Catherine Hoang<catherine.hoang@oracle.com> >> Reviewed-by: Nirjhar Roy (IBM)<nirjhar.roy.lists@gmail.com> > > Please see comment below, but this seems ok apart from that: > > Reviewed-by: John Garry <john.g.garry@oracle.com> Thanks! > >> --- >> common/rc | 51 +++++++++++++ >> tests/generic/765 | 172 ++++++++++++++++++++++++++++++++++++++++++ >> tests/generic/765.out | 2 + >> 3 files changed, 225 insertions(+) >> create mode 100755 tests/generic/765 >> create mode 100644 tests/generic/765.out >> diff --git a/common/rc b/common/rc >> index 16d627e1..25e6a1f7 100644 > > > >> +} >> + >> +sys_min_write=$(cat "/sys/block/$(_short_dev $SCRATCH_DEV)/queue/atomic_write_unit_min_bytes") >> +sys_max_write=$(cat "/sys/block/$(_short_dev $SCRATCH_DEV)/queue/atomic_write_unit_max_bytes") >> + >> +bdev_min_write=$(_get_atomic_write_unit_min $SCRATCH_DEV) >> +bdev_max_write=$(_get_atomic_write_unit_max $SCRATCH_DEV) >> + >> +if [ "$sys_min_write" -ne "$bdev_min_write" ]; then >> + echo "bdev min write != sys min write" >> +fi >> +if [ "$sys_max_write" -ne "$bdev_max_write" ]; then >> + echo "bdev max write != sys max write" > > Note: for large atomic writes according to [0], these may not be the same. I am not sure how this will affect your test. > > [0] https://lore.kernel.org/linux-xfs/20250408104209.1852036-1-john.g.garry@oracle.com/T/#m374933d93697082f9267515f807930d774c8634b Ok, I can remove this when large atomic writes gets merged (unless you think it should be removed now?) > >> +fi >> + >> +# Test all supported block sizes between bdev min and max >> +for ((bsize=$bdev_min_write; bsize<=bdev_max_write; bsize*=2)); do >> + test_atomic_writes $bsize >> +done; >> + >> +# Check that atomic write fails if bsize < bdev min or bsize > bdev max >> +test_atomic_write_bounds $((bdev_min_write / 2)) >> +test_atomic_write_bounds $((bdev_max_write * 2)) >> + >> +# success, all done >> +echo Silence is golden >> +status=0 >> +exit >> diff --git a/tests/generic/765.out b/tests/generic/765.out >> new file mode 100644 >> index 00000000..39c254ae >> --- /dev/null >> +++ b/tests/generic/765.out >> @@ -0,0 +1,2 @@ >> +QA output created by 765 >> +Silence is golden >> -- 2.34.1
On 08/04/2025 21:44, Catherine Hoang wrote: >>> --- >>> common/rc | 51 +++++++++++++ >>> tests/generic/765 | 172 ++++++++++++++++++++++++++++++++++++++++++ >>> tests/generic/765.out | 2 + >>> 3 files changed, 225 insertions(+) >>> create mode 100755 tests/generic/765 >>> create mode 100644 tests/generic/765.out >>> diff --git a/common/rc b/common/rc >>> index 16d627e1..25e6a1f7 100644 >> >> >>> +} >>> + >>> +sys_min_write=$(cat "/sys/block/$(_short_dev $SCRATCH_DEV)/queue/atomic_write_unit_min_bytes") >>> +sys_max_write=$(cat "/sys/block/$(_short_dev $SCRATCH_DEV)/queue/atomic_write_unit_max_bytes") >>> + >>> +bdev_min_write=$(_get_atomic_write_unit_min $SCRATCH_DEV) >>> +bdev_max_write=$(_get_atomic_write_unit_max $SCRATCH_DEV) >>> + >>> +if [ "$sys_min_write" -ne "$bdev_min_write" ]; then >>> + echo "bdev min write != sys min write" >>> +fi >>> +if [ "$sys_max_write" -ne "$bdev_max_write" ]; then >>> + echo "bdev max write != sys max write" >> Note: for large atomic writes according to [0], these may not be the same. I am not sure how this will affect your test. >> >> [0]https://lore.kernel.org/linux-xfs/20250408104209.1852036-1- >> john.g.garry@oracle.com/T/#m374933d93697082f9267515f807930d774c8634b > Ok, I can remove this when large atomic writes gets merged (unless you think > it should be removed now?) Actually this check is for ensuring that the statx for the bdev is the same as we get from sysfs for the bdev, right? If so, then it is ok to stay. Thanks, John
diff --git a/common/rc b/common/rc index 16d627e1..25e6a1f7 100644 --- a/common/rc +++ b/common/rc @@ -2996,6 +2996,10 @@ _require_xfs_io_command() opts+=" -d" pwrite_opts+="-V 1 -b 4k" fi + if [ "$param" == "-A" ]; then + opts+=" -d" + pwrite_opts+="-D -V 1 -b 4k" + fi testio=`$XFS_IO_PROG -f $opts -c \ "pwrite $pwrite_opts $param 0 4k" $testfile 2>&1` param_checked="$pwrite_opts $param" @@ -5443,6 +5447,53 @@ _require_scratch_btime() _scratch_unmount } +_get_atomic_write_unit_min() +{ + $XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $1 | \ + grep atomic_write_unit_min | grep -o '[0-9]\+' +} + +_get_atomic_write_unit_max() +{ + $XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $1 | \ + grep atomic_write_unit_max | grep -o '[0-9]\+' +} + +_get_atomic_write_segments_max() +{ + $XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $1 | \ + grep atomic_write_segments_max | grep -o '[0-9]\+' +} + +_require_scratch_write_atomic() +{ + _require_scratch + + export STATX_WRITE_ATOMIC=0x10000 + + awu_min_bdev=$(_get_atomic_write_unit_min $SCRATCH_DEV) + awu_max_bdev=$(_get_atomic_write_unit_max $SCRATCH_DEV) + + if [ $awu_min_bdev -eq 0 ] && [ $awu_max_bdev -eq 0 ]; then + _notrun "write atomic not supported by this block device" + fi + + _scratch_mkfs > /dev/null 2>&1 + _scratch_mount + + testfile=$SCRATCH_MNT/testfile + touch $testfile + + awu_min_fs=$(_get_atomic_write_unit_min $testfile) + awu_max_fs=$(_get_atomic_write_unit_max $testfile) + + _scratch_unmount + + if [ $awu_min_fs -eq 0 ] && [ $awu_max_fs -eq 0 ]; then + _notrun "write atomic not supported by this filesystem" + fi +} + _require_inode_limits() { if [ $(_get_free_inode $TEST_DIR) -eq 0 ]; then diff --git a/tests/generic/765 b/tests/generic/765 new file mode 100755 index 00000000..f54f2e2e --- /dev/null +++ b/tests/generic/765 @@ -0,0 +1,172 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2025 Oracle. All Rights Reserved. +# +# FS QA Test 765 +# +# Validate atomic write support +# +. ./common/preamble +_begin_fstest auto quick rw + +_require_scratch_write_atomic +_require_xfs_io_command pwrite -A + +check_supported_bsize() +{ + local bsize=$1 + + case "$FSTYP" in + "xfs") + min_bsize=1024 + knob="/sys/kernel/mm/transparent_hugepage/shmem_enabled" + test -w "$knob" && max_bsize=65536 || max_bsize=4096 + mkfs_opts="-b size=$bsize" + ;; + "ext4") + min_bsize=1024 + max_bsize=4096 + mkfs_opts="-b $bsize" + ;; + *) + _notrun "$FSTYP does not support atomic writes" + ;; + esac + + if [ "$bsize" -lt "$min_bsize" ] || [ "$bsize" -gt "$max_bsize" ]; then + return 1 + fi + + return 0 +} + +test_atomic_writes() +{ + local bsize=$1 + + if ! check_supported_bsize $bsize; then + return + fi + + _scratch_mkfs $mkfs_opts >> $seqres.full + _scratch_mount + + test "$FSTYP" = "xfs" && _xfs_force_bdev data $SCRATCH_MNT + + testfile=$SCRATCH_MNT/testfile + touch $testfile + + file_min_write=$(_get_atomic_write_unit_min $testfile) + file_max_write=$(_get_atomic_write_unit_max $testfile) + file_max_segments=$(_get_atomic_write_segments_max $testfile) + + # Check that atomic min/max = FS block size + test $file_min_write -eq $bsize || \ + echo "atomic write min $file_min_write, should be fs block size $bsize" + test $file_min_write -eq $bsize || \ + echo "atomic write max $file_max_write, should be fs block size $bsize" + test $file_max_segments -eq 1 || \ + echo "atomic write max segments $file_max_segments, should be 1" + + # Check that we can perform an atomic write of len = FS block size + bytes_written=$($XFS_IO_PROG -dc "pwrite -A -D -V1 -b $bsize 0 $bsize" $testfile | \ + grep wrote | awk -F'[/ ]' '{print $2}') + test $bytes_written -eq $bsize || echo "atomic write len=$bsize failed" + + # Check that we can perform an atomic single-block cow write + if [ "$FSTYP" == "xfs" ]; then + testfile_cp=$SCRATCH_MNT/testfile_copy + if _xfs_has_feature $SCRATCH_MNT reflink; then + cp --reflink $testfile $testfile_cp + fi + bytes_written=$($XFS_IO_PROG -dc "pwrite -A -D -V1 -b $bsize 0 $bsize" $testfile_cp | \ + grep wrote | awk -F'[/ ]' '{print $2}') + test $bytes_written -eq $bsize || echo "atomic write on reflinked file failed" + fi + + # Check that we can perform an atomic write on an unwritten block + $XFS_IO_PROG -c "falloc $bsize $bsize" $testfile + bytes_written=$($XFS_IO_PROG -dc "pwrite -A -D -V1 -b $bsize $bsize $bsize" $testfile | \ + grep wrote | awk -F'[/ ]' '{print $2}') + test $bytes_written -eq $bsize || echo "atomic write to unwritten block failed" + + # Check that we can perform an atomic write on a sparse hole + $XFS_IO_PROG -c "fpunch 0 $bsize" $testfile + bytes_written=$($XFS_IO_PROG -dc "pwrite -A -D -V1 -b $bsize 0 $bsize" $testfile | \ + grep wrote | awk -F'[/ ]' '{print $2}') + test $bytes_written -eq $bsize || echo "atomic write to sparse hole failed" + + # Check that we can perform an atomic write on a fully mapped block + bytes_written=$($XFS_IO_PROG -dc "pwrite -A -D -V1 -b $bsize 0 $bsize" $testfile | \ + grep wrote | awk -F'[/ ]' '{print $2}') + test $bytes_written -eq $bsize || echo "atomic write to mapped block failed" + + # Reject atomic write if len is out of bounds + $XFS_IO_PROG -dc "pwrite -A -D -V1 -b $bsize 0 $((bsize - 1))" $testfile 2>> $seqres.full && \ + echo "atomic write len=$((bsize - 1)) should fail" + $XFS_IO_PROG -dc "pwrite -A -D -V1 -b $bsize 0 $((bsize + 1))" $testfile 2>> $seqres.full && \ + echo "atomic write len=$((bsize + 1)) should fail" + + # Reject atomic write when iovecs > 1 + $XFS_IO_PROG -dc "pwrite -A -D -V2 -b $bsize 0 $bsize" $testfile 2>> $seqres.full && \ + echo "atomic write only supports iovec count of 1" + + # Reject atomic write when not using direct I/O + $XFS_IO_PROG -c "pwrite -A -V1 -b $bsize 0 $bsize" $testfile 2>> $seqres.full && \ + echo "atomic write requires direct I/O" + + # Reject atomic write when offset % bsize != 0 + $XFS_IO_PROG -dc "pwrite -A -D -V1 -b $bsize 1 $bsize" $testfile 2>> $seqres.full && \ + echo "atomic write requires offset to be aligned to bsize" + + _scratch_unmount +} + +test_atomic_write_bounds() +{ + local bsize=$1 + + if ! check_supported_bsize $bsize; then + return + fi + + _scratch_mkfs $mkfs_opts >> $seqres.full + _scratch_mount + + test "$FSTYP" = "xfs" && _xfs_force_bdev data $SCRATCH_MNT + + testfile=$SCRATCH_MNT/testfile + touch $testfile + + $XFS_IO_PROG -dc "pwrite -A -D -V1 -b $bsize 0 $bsize" $testfile 2>> $seqres.full && \ + echo "atomic write should fail when bsize is out of bounds" + + _scratch_unmount +} + +sys_min_write=$(cat "/sys/block/$(_short_dev $SCRATCH_DEV)/queue/atomic_write_unit_min_bytes") +sys_max_write=$(cat "/sys/block/$(_short_dev $SCRATCH_DEV)/queue/atomic_write_unit_max_bytes") + +bdev_min_write=$(_get_atomic_write_unit_min $SCRATCH_DEV) +bdev_max_write=$(_get_atomic_write_unit_max $SCRATCH_DEV) + +if [ "$sys_min_write" -ne "$bdev_min_write" ]; then + echo "bdev min write != sys min write" +fi +if [ "$sys_max_write" -ne "$bdev_max_write" ]; then + echo "bdev max write != sys max write" +fi + +# Test all supported block sizes between bdev min and max +for ((bsize=$bdev_min_write; bsize<=bdev_max_write; bsize*=2)); do + test_atomic_writes $bsize +done; + +# Check that atomic write fails if bsize < bdev min or bsize > bdev max +test_atomic_write_bounds $((bdev_min_write / 2)) +test_atomic_write_bounds $((bdev_max_write * 2)) + +# success, all done +echo Silence is golden +status=0 +exit diff --git a/tests/generic/765.out b/tests/generic/765.out new file mode 100644 index 00000000..39c254ae --- /dev/null +++ b/tests/generic/765.out @@ -0,0 +1,2 @@ +QA output created by 765 +Silence is golden