xfs: add a test for atomic writes
PATCH v2 1/1 xfs: add a test for atomic writes
Add a test to validate the new atomic writes feature.
--- common/rc | 14 ++++++++ tests/xfs/611 | 81 +++++++++++++++++++++++++++++++++++++++++++++++ tests/xfs/611.out | 2 ++ 3 files changed, 97 insertions(+) create mode 100755 tests/xfs/611 create mode 100644 tests/xfs/611.out
common/rc +14 -0
@@ -5148,6 +5148,20 @@ _require_scratch_btime() _scratch_unmount } +_require_scratch_write_atomic() +{ + _require_scratch + _scratch_mkfs > /dev/null 2>&1 + _scratch_mount + + export STATX_WRITE_ATOMIC=0x10000 + $XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $SCRATCH_MNT \ + | grep atomic >>$seqres.full 2>&1 || \ + _notrun "write atomic not supported by this filesystem" + + _scratch_unmount +} + _require_inode_limits() { if [ $(_get_free_inode $TEST_DIR) -eq 0 ]; then
tests/xfs/611 new file +81 -0
81 lines not on this page · raw message
tests/xfs/611.out new file +2 -0
@@ -0,0 +1,2 @@ +QA output created by 611 +Silence is golden
Signature · 1 line
2.34.1
Quoted 46 lines · Catherine Hoang
Add a test to validate the new atomic writes feature.
Signed-off-by Catherine Hoang <[email protected]>--- common/rc | 14 ++++++++ tests/xfs/611 | 81 +++++++++++++++++++++++++++++++++++++++++++++++ tests/xfs/611.out | 2 ++ 3 files changed, 97 insertions(+) create mode 100755 tests/xfs/611 create mode 100644 tests/xfs/611.outcommon/rc +14
-0@@ -5148,6 +5148,20 @@ _require_scratch_btime() _scratch_unmount } +_require_scratch_write_atomic() +{ + _require_scratch + _scratch_mkfs > /dev/null 2>&1 + _scratch_mount + + export STATX_WRITE_ATOMIC=0x10000 + $XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $SCRATCH_MNT \ + | grep atomic >>$seqres.full 2>&1 || \ + _notrun "write atomic not supported by this filesystem" + + _scratch_unmount +} + _require_inode_limits() { if [ $(_get_free_inode $TEST_DIR) -eq 0 ]; thentests/xfs/611 new file +4
-0@@ -0,0 +1,81 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2024 Oracle. All Rights Reserved. +#
tests/xfs/611 line 14
Quoted 10 lines
tests/xfs/611 new file +10
-0+# FS QA Test 611 +# +# Validate atomic write support +# +. ./common/preamble +_begin_fstest auto quick rw + +_supported_fs xfs +_require_scratch +_require_scratch_write_atomic
You can omit the _require_scratch since _require_scratch_write_atomic does it for you.
Quoted 21 lines
tests/xfs/611 new file +21
-0+ +test_atomic_writes() +{ + local bsize=$1 + + _scratch_mkfs_xfs -b size=$bsize >> $seqres.full + _scratch_mount + _xfs_force_bdev data $SCRATCH_MNT + + testfile=$SCRATCH_MNT/testfile + touch $testfile + + file_min_write=$($XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $testfile | \ + grep atomic_write_unit_min | cut -d ' ' -f 3) + file_max_write=$($XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $testfile | \ + grep atomic_write_unit_max | cut -d ' ' -f 3) + file_max_segments=$($XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $testfile | \ + grep atomic_write_segments_max | cut -d ' ' -f 3) + + # Check that atomic min/max = FS block size + test $file_min_write -eq $bsize || \
tests/xfs/611 line 45
Quoted 10 lines
tests/xfs/611 new file +10
-0+ 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 0 $bsize" $testfile | \ + grep wrote | awk -F'[/ ]' '{print $2}') + test $bytes_written -eq $bsize || echo "atomic write len=$bsize failed"
Hmm, ok, so that's an extending write, good...
tests/xfs/611 line 57
Quoted 11 lines
tests/xfs/611 new file +11
-0+ # 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 $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 0 $bsize" $testfile | \ + grep wrote | awk -F'[/ ]' '{print $2}') + test $bytes_written -eq $bsize || echo "atomic write to sparse hole failed"
...and those check unwritten and non-mapped ranges.
Now that the the file range has been filled with a written block, should there be a second atomic pwrite here to check that it works for a fully mapped block?
If reflink is supported, could you also cp --reflink $testfile to make sure that atomic single-block cow writes work?
Other than that, everything looks good.
--D
Quoted 35 lines
tests/xfs/611 new file +23
-0+ # Reject atomic write if len is out of bounds + $XFS_IO_PROG -dc "pwrite -A -D 0 $((bsize - 1))" $testfile 2>> $seqres.full && \ + echo "atomic write len=$((bsize - 1)) should fail" + $XFS_IO_PROG -dc "pwrite -A -D 0 $((bsize + 1))" $testfile 2>> $seqres.full && \ + echo "atomic write len=$((bsize + 1)) should fail" + + _scratch_unmount +} + +bdev_min_write=$($XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $SCRATCH_DEV | \ + grep atomic_write_unit_min | cut -d ' ' -f 3) +bdev_max_write=$($XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $SCRATCH_DEV | \ + grep atomic_write_unit_max | cut -d ' ' -f 3) + +for ((bsize=$bdev_min_write; bsize<=bdev_max_write; bsize*=2)); do + _scratch_mkfs_xfs_supported -b size=$bsize >> $seqres.full 2>&1 && \ + test_atomic_writes $bsize +done; + +# success, all done +echo Silence is golden +status=0 +exittests/xfs/611.out new file +2
-0@@ -0,0 +1,2 @@ +QA output created by 611 +Silence is goldenSignature · 1 line
2.34.1
Quoted 1 line · Catherine Hoang
Add a test to validate the new atomic writes feature.
Generally this look ok, just a couple of comments/questions, below.
Thanks,
John
Quoted 51 lines
Signed-off-by Catherine Hoang <[email protected]>--- common/rc | 14 ++++++++ tests/xfs/611 | 81 +++++++++++++++++++++++++++++++++++++++++++++++ tests/xfs/611.out | 2 ++ 3 files changed, 97 insertions(+)create mode 100755 tests/xfs/611
create mode 100644 tests/xfs/611.outcommon/rc +14
-0@@ -5148,6 +5148,20 @@ _require_scratch_btime() _scratch_unmount } +_require_scratch_write_atomic() +{ + _require_scratch + _scratch_mkfs > /dev/null 2>&1 + _scratch_mount + + export STATX_WRITE_ATOMIC=0x10000 + $XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $SCRATCH_MNT \ + | grep atomic >>$seqres.full 2>&1 || \ + _notrun "write atomic not supported by this filesystem" + + _scratch_unmount +} + _require_inode_limits() { if [ $(_get_free_inode $TEST_DIR) -eq 0 ]; thentests/xfs/611 new file +10
-0@@ -0,0 +1,81 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2024 Oracle. All Rights Reserved. +# +# FS QA Test 611 +# +# Validate atomic write support +# +. ./common/preamble +_begin_fstest auto quick rw
tests/xfs/611 line 20
Quoted 10 lines
tests/xfs/611 new file +10
-0+ +_supported_fs xfs +_require_scratch +_require_scratch_write_atomic + +test_atomic_writes() +{ + local bsize=$1 + + _scratch_mkfs_xfs -b size=$bsize >> $seqres.full
bsize (bdev max) can be upto 0.5M - are we really possibly testing FS blocksize == 0.5M?
Apart from that, it would be nice if we fixed FS blocksize at 4K or 64K, and fed bdev min/max and ensured that we can only support atomic writes for bdev min <= fs blocksize <= bdev max. But maybe what you are doing is ok.
Quoted 4 lines
tests/xfs/611 new file +4
-0+ _scratch_mount + _xfs_force_bdev data $SCRATCH_MNT + + testfile=$SCRATCH_MNT/testfile
tests/xfs/611 line 34
Quoted 10 lines
tests/xfs/611 new file +10
-0+ touch $testfile + + file_min_write=$($XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $testfile | \ + grep atomic_write_unit_min | cut -d ' ' -f 3) + file_max_write=$($XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $testfile | \ + grep atomic_write_unit_max | cut -d ' ' -f 3) + file_max_segments=$($XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $testfile | \ + grep atomic_write_segments_max | cut -d ' ' -f 3) + + # Check that atomic min/max = FS block size
Hopefully we can have max > FS block size soon, but I am not sure how .... so it's hard to consider now how the test could be expanded to cover that.
Quoted 55 lines
tests/xfs/611 new file +47
-0+ 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 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 write on an unwritten block + $XFS_IO_PROG -c "falloc $bsize $bsize" $testfile + bytes_written=$($XFS_IO_PROG -dc "pwrite -A -D $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 0 $bsize" $testfile | \ + grep wrote | awk -F'[/ ]' '{print $2}') + test $bytes_written -eq $bsize || echo "atomic write to sparse hole failed" + + # Reject atomic write if len is out of bounds + $XFS_IO_PROG -dc "pwrite -A -D 0 $((bsize - 1))" $testfile 2>> $seqres.full && \ + echo "atomic write len=$((bsize - 1)) should fail" + $XFS_IO_PROG -dc "pwrite -A -D 0 $((bsize + 1))" $testfile 2>> $seqres.full && \ + echo "atomic write len=$((bsize + 1)) should fail" + + _scratch_unmount +} + +bdev_min_write=$($XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $SCRATCH_DEV | \ + grep atomic_write_unit_min | cut -d ' ' -f 3) +bdev_max_write=$($XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $SCRATCH_DEV | \ + grep atomic_write_unit_max | cut -d ' ' -f 3) + +for ((bsize=$bdev_min_write; bsize<=bdev_max_write; bsize*=2)); do + _scratch_mkfs_xfs_supported -b size=$bsize >> $seqres.full 2>&1 && \ + test_atomic_writes $bsize +done; + +# success, all done +echo Silence is golden +status=0 +exittests/xfs/611.out new file +2
-0@@ -0,0 +1,2 @@ +QA output created by 611 +Silence is golden
Quoted 63 lines · John Garry
Quoted 1 line · Catherine Hoang
Add a test to validate the new atomic writes feature.
Generally this look ok, just a couple of comments/questions, below.
Thanks,
JohnQuoted 55 lines
Signed-off-by Catherine Hoang <[email protected]>--- common/rc | 14 ++++++++ tests/xfs/611 | 81 +++++++++++++++++++++++++++++++++++++++++++++++ tests/xfs/611.out | 2 ++ 3 files changed, 97 insertions(+)create mode 100755 tests/xfs/611
create mode 100644 tests/xfs/611.outcommon/rc +14
-0@@ -5148,6 +5148,20 @@ _require_scratch_btime() _scratch_unmount } +_require_scratch_write_atomic() +{ + _require_scratch + _scratch_mkfs > /dev/null 2>&1 + _scratch_mount + + export STATX_WRITE_ATOMIC=0x10000 + $XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $SCRATCH_MNT \ + | grep atomic >>$seqres.full 2>&1 || \ + _notrun "write atomic not supported by this filesystem" + + _scratch_unmount +} + _require_inode_limits() { if [ $(_get_free_inode $TEST_DIR) -eq 0 ]; thentests/xfs/611 new file +15
-0@@ -0,0 +1,81 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2024 Oracle. All Rights Reserved. +# +# FS QA Test 611 +# +# Validate atomic write support +# +. ./common/preamble +_begin_fstest auto quick rw + +_supported_fs xfs +_require_scratch +_require_scratch_write_atomic +
Quoted 8 lines
tests/xfs/611 line 20
Quoted 5 lines
tests/xfs/611 new file +5
-0+test_atomic_writes() +{ + local bsize=$1 + + _scratch_mkfs_xfs -b size=$bsize >> $seqres.fullbsize (bdev max) can be upto 0.5M - are we really possibly testing FS blocksize == 0.5M?
No, but I suppose the for loop at the bottom should stop at 64k.
Quoted 13 lines
Apart from that, it would be nice if we fixed FS blocksize at 4K or 64K, and fed bdev min/max and ensured that we can only support atomic writes for bdev min <= fs blocksize <= bdev max. But maybe what you are doing is ok.
Quoted 9 lines
tests/xfs/611 new file +9
-0+ _scratch_mount + _xfs_force_bdev data $SCRATCH_MNT + + testfile=$SCRATCH_MNT/testfile + touch $testfile + + file_min_write=$($XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $testfile | \ + grep atomic_write_unit_min | cut -d ' ' -f 3) + file_max_write=$($XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $testfile | \
Quoted 8 lines
tests/xfs/611 line 34
Quoted 5 lines
tests/xfs/611 new file +5
-0+ grep atomic_write_unit_max | cut -d ' ' -f 3) + file_max_segments=$($XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $testfile | \ + grep atomic_write_segments_max | cut -d ' ' -f 3) + + # Check that atomic min/max = FS block sizeHopefully we can have max > FS block size soon, but I am not sure how .... so it's hard to consider now how the test could be expanded to cover that.
Yeah, this test will need revision whenever we manage to finishing running this marathon and get the next phase merged. Until then, let's at least test the existing functionality. :/
--D
Quoted 57 lines
Quoted 55 lines
tests/xfs/611 new file +47
-0+ 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 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 write on an unwritten block + $XFS_IO_PROG -c "falloc $bsize $bsize" $testfile + bytes_written=$($XFS_IO_PROG -dc "pwrite -A -D $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 0 $bsize" $testfile | \ + grep wrote | awk -F'[/ ]' '{print $2}') + test $bytes_written -eq $bsize || echo "atomic write to sparse hole failed" + + # Reject atomic write if len is out of bounds + $XFS_IO_PROG -dc "pwrite -A -D 0 $((bsize - 1))" $testfile 2>> $seqres.full && \ + echo "atomic write len=$((bsize - 1)) should fail" + $XFS_IO_PROG -dc "pwrite -A -D 0 $((bsize + 1))" $testfile 2>> $seqres.full && \ + echo "atomic write len=$((bsize + 1)) should fail" + + _scratch_unmount +} + +bdev_min_write=$($XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $SCRATCH_DEV | \ + grep atomic_write_unit_min | cut -d ' ' -f 3) +bdev_max_write=$($XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $SCRATCH_DEV | \ + grep atomic_write_unit_max | cut -d ' ' -f 3) + +for ((bsize=$bdev_min_write; bsize<=bdev_max_write; bsize*=2)); do + _scratch_mkfs_xfs_supported -b size=$bsize >> $seqres.full 2>&1 && \ + test_atomic_writes $bsize +done; + +# success, all done +echo Silence is golden +status=0 +exittests/xfs/611.out new file +2
-0@@ -0,0 +1,2 @@ +QA output created by 611 +Silence is golden
Quoted 71 lines · John Garry
Quoted 1 line · Catherine Hoang
Add a test to validate the new atomic writes feature.
Generally this look ok, just a couple of comments/questions, below.
Thanks,
JohnQuoted 48 lines
Signed-off-by Catherine Hoang <[email protected]>--- common/rc | 14 ++++++++ tests/xfs/611 | 81 +++++++++++++++++++++++++++++++++++++++++++++++ tests/xfs/611.out | 2 ++ 3 files changed, 97 insertions(+) create mode 100755 tests/xfs/611 create mode 100644 tests/xfs/611.outcommon/rc +13
-0@@ -5148,6 +5148,20 @@ _require_scratch_btime() _scratch_unmount } +_require_scratch_write_atomic() +{ + _require_scratch + _scratch_mkfs > /dev/null 2>&1 + _scratch_mount + + export STATX_WRITE_ATOMIC=0x10000 + $XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $SCRATCH_MNT \ + | grep atomic >>$seqres.full 2>&1 || \ + _notrun "write atomic not supported by this filesystem" + + _scratch_unmount +} + _require_inode_limits() { if [ $(_get_free_inode $TEST_DIR) -eq 0 ]; thentests/xfs/611 new file +10
-0@@ -0,0 +1,81 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2024 Oracle. All Rights Reserved. +# +# FS QA Test 611 +# +# Validate atomic write support +# +. ./common/preamble +_begin_fstest auto quick rwtests/xfs/611 line 20
Quoted 10 lines
tests/xfs/611 new file +10
-0+ +_supported_fs xfs +_require_scratch +_require_scratch_write_atomic + +test_atomic_writes() +{ + local bsize=$1 + + _scratch_mkfs_xfs -b size=$bsize >> $seqres.fullbsize (bdev max) can be upto 0.5M - are we really possibly testing FS blocksize == 0.5M?
Quoted 1 line
Apart from that, it would be nice if we fixed FS blocksize at 4K or 64K, and fed bdev min/max and ensured that we can only support atomic writes for bdev min <= fs blocksize <= bdev max. But maybe what you are doing is ok.
Currently I’m testing every valid block size between the bdev min and bdev max. But I can also add a test to make sure we aren’t doing atomic writes if block size < bdev min or block size > bdev max.
Quoted 73 lines
Quoted 5 lines
tests/xfs/611 new file +4
-0+ _scratch_mount + _xfs_force_bdev data $SCRATCH_MNT + + testfile=$SCRATCH_MNT/testfiletests/xfs/611 line 34
Quoted 10 lines
tests/xfs/611 new file +10
-0+ touch $testfile + + file_min_write=$($XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $testfile | \ + grep atomic_write_unit_min | cut -d ' ' -f 3) + file_max_write=$($XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $testfile | \ + grep atomic_write_unit_max | cut -d ' ' -f 3) + file_max_segments=$($XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $testfile | \ + grep atomic_write_segments_max | cut -d ' ' -f 3) + + # Check that atomic min/max = FS block sizeHopefully we can have max > FS block size soon, but I am not sure how .... so it's hard to consider now how the test could be expanded to cover that.
Quoted 55 lines
tests/xfs/611 new file +47
-0+ 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 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 write on an unwritten block + $XFS_IO_PROG -c "falloc $bsize $bsize" $testfile + bytes_written=$($XFS_IO_PROG -dc "pwrite -A -D $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 0 $bsize" $testfile | \ + grep wrote | awk -F'[/ ]' '{print $2}') + test $bytes_written -eq $bsize || echo "atomic write to sparse hole failed" + + # Reject atomic write if len is out of bounds + $XFS_IO_PROG -dc "pwrite -A -D 0 $((bsize - 1))" $testfile 2>> $seqres.full && \ + echo "atomic write len=$((bsize - 1)) should fail" + $XFS_IO_PROG -dc "pwrite -A -D 0 $((bsize + 1))" $testfile 2>> $seqres.full && \ + echo "atomic write len=$((bsize + 1)) should fail" + + _scratch_unmount +} + +bdev_min_write=$($XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $SCRATCH_DEV | \ + grep atomic_write_unit_min | cut -d ' ' -f 3) +bdev_max_write=$($XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $SCRATCH_DEV | \ + grep atomic_write_unit_max | cut -d ' ' -f 3) + +for ((bsize=$bdev_min_write; bsize<=bdev_max_write; bsize*=2)); do + _scratch_mkfs_xfs_supported -b size=$bsize >> $seqres.full 2>&1 && \ + test_atomic_writes $bsize +done; + +# success, all done +echo Silence is golden +status=0 +exittests/xfs/611.out new file +2
-0@@ -0,0 +1,2 @@ +QA output created by 611 +Silence is golden
Quoted 8 lines · Catherine Hoang
Add a test to validate the new atomic writes feature.
Signed-off-by Catherine Hoang <[email protected]>--- common/rc | 14 ++++++++ tests/xfs/611 | 81 +++++++++++++++++++++++++++++++++++++++++++++++ tests/xfs/611.out | 2 ++
Now that ext4 also has support for block atomic writes, do you think it appropritate to put it under generic?
Quoted 9 lines
3 files changed, 97 insertions(+) create mode 100755 tests/xfs/611 create mode 100644 tests/xfs/611.outcommon/rc +0
-0
common/rc _require_scratch_btime() · line 5155
Quoted 8 lines
common/rc +5
-0@@ -5148,6 +5148,20 @@ _require_scratch_btime() _scratch_unmount } +_require_scratch_write_atomic() +{ + _require_scratch + _scratch_mkfs > /dev/null 2>&1 + _scratch_mount
Minor: Do we need the _scratch_mount and _scratch_unmount? We can directly statx the underlying device too, right?
common/rc _require_scratch_btime() · line 5160
Quoted 6 lines
common/rc +5
-0+ + export STATX_WRITE_ATOMIC=0x10000 + $XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $SCRATCH_MNT \ + | grep atomic >>$seqres.full 2>&1 || \ + _notrun "write atomic not supported by this filesystem"
Are we assuming that the SCRATCH_DEV supports atomic writes here? If not, do you think the idea of checking if the underlying device supports atomic writes will be appropriate here?
I tried running the test with a loop device (with no atomic writes support) and this function did not execute _notrun. The test did fail expectedly with "atomic write min 0, should be fs block size 4096". However, the test shouldn't have begun or reached this stage if the underlying device doesn't support atomic writes, right?
Maybe look at how scsi_debug is used? Tests like tests/generic/704 and common/scsi_debug?
Quoted 47 lines
common/rc +4
-0+ + _scratch_unmount +} + _require_inode_limits() {common/rc +0
-0if [ $(_get_free_inode $TEST_DIR) -eq 0 ]; thentests/xfs/611 new file +27
-0@@ -0,0 +1,81 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2024 Oracle. All Rights Reserved. +# +# FS QA Test 611 +# +# Validate atomic write support +# +. ./common/preamble +_begin_fstest auto quick rw + +_supported_fs xfs +_require_scratch +_require_scratch_write_atomic + +test_atomic_writes() +{ + local bsize=$1 + + _scratch_mkfs_xfs -b size=$bsize >> $seqres.full + _scratch_mount + _xfs_force_bdev data $SCRATCH_MNT + + testfile=$SCRATCH_MNT/testfile + touch $testfile + + file_min_write=$($XFS_IO_PROG -c "statx -r -m$STATX_WRITE_ATOMIC" $testfile | \
tests/xfs/611 new file +2
-0+ grep atomic_write_unit_min | cut -d ' ' -f 3) + file_max_write=$($XFS_IO_PROG -c "statx -r -m$STATX_WRITE_ATOMIC" $testfile | \
tests/xfs/611 new file +2
-0+ grep atomic_write_unit_max | cut -d ' ' -f 3) + file_max_segments=$($XFS_IO_PROG -c "statx -r -m$STATX_WRITE_ATOMIC" $testfile | \
tests/xfs/611
Quoted 2 lines
tests/xfs/611 new file +2
-0+ grep atomic_write_segments_max | cut -d ' ' -f 3) +
Minor: A refactoring suggestion. Can we put the commands to fetch the atomic_write_unit_min , atomic_write_unit_max and atomic_write_segments_max in a function and re-use them? We are using these commands to get bdev_min_write/bdev_max_write as well, so a function might make the code look more compact. Some maybe something like:
_get_at_wr_unit_min()
{
$XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $1 | grep
atomic_write_unit_min | \ grep -o '[0-9]\+' }
_get_at_wr_unit_max()
{
$XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $1 | grep
atomic_write_unit_max | \ grep -o '[0-9]\+' }
and then,
file_min_write=$(_get_at_wr_unit_min $testfile) and similarly for file_max_write, file_max_segments, bdev_min_write/bdev_max_write
Quoted 12 lines
tests/xfs/611 new file +3
-0+ # Check that atomic min/max = FS block size + test $file_min_write -eq $bsize || \ + echo "atomic write min $file_min_write, should be fs blocksize $bsize"
tests/xfs/611 new file +2
-0+ test $file_min_write -eq $bsize || \ + echo "atomic write max $file_max_write, should be fs blocksize $bsize"
tests/xfs/611 new file +2
-0+ test $file_max_segments -eq 1 || \ + echo "atomic write max segments $file_max_segments, shouldbe 1"
tests/xfs/611 new file +2
-0+ + # Check that we can perform an atomic write of len = FS block
Quoted 4 lines
size
+ bytes_written=$($XFS_IO_PROG -dc "pwrite -A -D 0 $bsize"
$testfile | \
+ grep wrote | awk -F'[/ ]' '{print $2}')
is "$XFS_IO_PROG -dc pwrite -A -D 0 $bsize" $testfile actually making a pwritev2 syscall?
Let's look at the output below:
(tested with latest master of xfsprogs-dev (commit 90d6da68) on pagesize and block size 4k (x86_64 vm)
mount /dev/sdc /mnt1/test
touch /mnt1/test/new
strace -f xfs_io -c "pwrite -A -D 0 4096" /mnt1/test/new
<last few lines>openat(AT_FDCWD, "/mnt1/test/new", O_RDWR) = 3
...
...
pwrite64(3, "\315\315\315\315\315\315\315\315\315\315\315\315\315\315\315\315\315\3 15\315\315\315\315\315\315\315\315\315\315\315\315\315\315"..., 4096,
0) = 4096newfstatat(1, "", {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0x1), ...}, AT_EMPTY_PATH) = 0
write(1, "wrote 4096/4096 bytes at offset "..., 34wrote 4096/4096 bytes at offset 0
) = 34
write(1, "4 KiB, 1 ops; 0.0001 sec (23.819"..., 644 KiB, 1 ops; 0.0001 sec (23.819 MiB/sec and 6097.5610 ops/sec)
) = 64exit_group(0)
So the issues are as follows:
1. file /mnt1/test/new is NOT opened with O_DIRECT flag i.e, direct io mode which is one of the requirements for atomic write (buffered io doesn't support atomic write, correct me if I am wrong).
2. pwrite64 doesn't take the RWF_ATOMIC flag and hence I think this write is just a non-atomic write with no stdout output difference as such.
Also if you look at the function
do_pwrite() in xfsprogs-dev/io/pwrite.c
static ssize_t
do_pwrite(
int fd, off_t offset, long long count, size_t buffer_size, int pwritev2_flags)
{
if (!vectors)
return pwrite(fd, io_buffer, min(count, buffer_size),
offset);
return do_pwritev(fd, offset, count, pwritev2_flags); }
it will not call pwritev/pwritev2 unless we have vectors for which you will need -V parameter with pwrite subcommand of xfs_io.
So I think the correct way to do this would be the following:
bytes_written=$($XFS_IO_PROGS -c "open -d $testfile" -c "pwrite -A -D -V 1 0 $bsize" | grep wrote | awk -F'[/ ]' '{print $2}').
This also bring us to 2 more test cases that we can add:
a. Atomic write with vec count > 1
$XFS_IO_PROGS -c "open -d $testfile" -c "pwrite -A -D -V 2 0 $bsize" (This should fail with Invalid argument since currently iovec count is restricted to 1)
b.
Open a file withOUT O_DIRECT and try to perform an atomic write. This should fail with Operation not Supported (EOPNOTSUPP). So something like
$XFS_IO_PROGS -c "open -f $testfile" -c "pwrite -A -V 1 0 $bsize"
3. It is better to use -b $bsize with pwrite else, the write might be spilitted into multiple atomic writes. For example try the following:
$XFS_IO_PROGS -c "open -fd $testfile" -c "pwrite -A -D -V 1 0 $(( $bsize * 2 ))"
The above is expected to fail as the size of the atomic write is greater than the limit i.e, 1 block but it will still succeed. Look at the strace and you will see 2 pwritev2 system calls. However the following will fail expectedly with -EINVAL:
$XFS_IO_PROGS -c "open -fd $testfile" -c "pwrite -A -D -V 1 -b $(( $bsize * 2 )) 0 $(( $bsize * 2 ))"
Quoted 25 lines
+ test $bytes_written -eq $bsize || echo "atomic write len=$bsize
failed"tests/xfs/611 new file +2
-0+ + # Check that we can perform an atomic write on an unwrittenblock
tests/xfs/611 new file +2
-0+ $XFS_IO_PROG -c "falloc $bsize $bsize" $testfile + bytes_written=$($XFS_IO_PROG -dc "pwrite -A -D $bsize $bsize"$testfile | \
tests/xfs/611 new file +2
-0+ grep wrote | awk -F'[/ ]' '{print $2}') + test $bytes_written -eq $bsize || echo "atomic write tounwritten block failed"
tests/xfs/611 new file +4
-0+ + # 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 0 $bsize"$testfile | \
tests/xfs/611 new file +2
-0+ grep wrote | awk -F'[/ ]' '{print $2}') + test $bytes_written -eq $bsize || echo "atomic write to sparsehole failed"
tests/xfs/611 new file +3
-0+ + # Reject atomic write if len is out of bounds + $XFS_IO_PROG -dc "pwrite -A -D 0 $((bsize - 1))" $testfile 2>>$seqres.full && \
tests/xfs/611 new file +2
-0+ echo "atomic write len=$((bsize - 1)) should fail" + $XFS_IO_PROG -dc "pwrite -A -D 0 $((bsize + 1))" $testfile 2>>
Quoted 2 lines
$seqres.full && \
+ echo "atomic write len=$((bsize + 1)) should fail"
Have we covered the scenario where the offset % len != 0 Should fail - Should fail with Invalid arguments -EINVAL.
Also do you think adding similar tests with raw writes to the underlying devices bypassing the fs layer will add some value? There are slight less strict or different rules in the block layer which IMO worth to be tested. Please let me know your thoughts.
tests/xfs/611
Quoted 11 lines
tests/xfs/611 new file +5
-0+ + _scratch_unmount +} + +bdev_min_write=$($XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC"$SCRATCH_DEV | \
tests/xfs/611 new file +2
-0+ grep atomic_write_unit_min | cut -d ' ' -f 3) +bdev_max_write=$($XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC"$SCRATCH_DEV | \
tests/xfs/611 new file +2
-0+ grep atomic_write_unit_max | cut -d ' ' -f 3) +
Similar comment before - Refactor this into a function.
tests/xfs/611 line 76
Quoted 5 lines
tests/xfs/611 new file +2
-0+for ((bsize=$bdev_min_write; bsize<=bdev_max_write; bsize*=2)); do + _scratch_mkfs_xfs_supported -b size=$bsize >> $seqres.full 2>&1&& \
tests/xfs/611 new file +2
-0+ test_atomic_writes $bsize +done;
Minor: This might fail on some archs(x86_64) if the kernel isn't compiled without CONFIG_TRANSPARENT_HUGEPAGE to enable block size greater than 4k on x86_64.
--
NR
Quoted 13 lines
tests/xfs/611 new file +5
-0+ +# success, all done +echo Silence is golden +status=0 +exittests/xfs/611.out new file +2
-0@@ -0,0 +1,2 @@ +QA output created by 611 +Silence is golden
Quoted 23 lines · Nirjhar Roy
Quoted 8 lines · Catherine Hoang
Add a test to validate the new atomic writes feature.
Signed-off-by Catherine Hoang <[email protected]>--- common/rc | 14 ++++++++ tests/xfs/611 | 81 +++++++++++++++++++++++++++++++++++++++++++++++ tests/xfs/611.out | 2 ++Now that ext4 also has support for block atomic writes, do you think it appropritate to put it under generic?
Quoted 12 lines
3 files changed, 97 insertions(+) create mode 100755 tests/xfs/611 create mode 100644 tests/xfs/611.outcommon/rc +0
-0@@ -5148,6 +5148,20 @@ _require_scratch_btime() _scratch_unmount }
Quoted 7 lines
common/rc _require_scratch_btime() · line 5155
Quoted 5 lines
common/rc +5
-0+_require_scratch_write_atomic() +{ + _require_scratch + _scratch_mkfs > /dev/null 2>&1 + _scratch_mountMinor: Do we need the
_scratch_mountand_scratch_unmount? We can directly statx the underlying device too, right?
Yes, we need the scratch fs, because the filesystem might not support untorn writes even if the underlying block device does. Or it can decide to constrain the supported io sizes.
Quoted 10 lines
common/rc _require_scratch_btime() · line 5160
Quoted 6 lines
common/rc +5
-0+ + export STATX_WRITE_ATOMIC=0x10000 + $XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $SCRATCH_MNT \ + | grep atomic >>$seqres.full 2>&1 || \ + _notrun "write atomic not supported by this filesystem"Are we assuming that the
SCRATCH_DEVsupports atomic writes here? If not, do you think the idea of checking if the underlying device supports atomic writes will be appropriate here?
Quoted 3 lines
I tried running the test with a loop device (with no atomic writes support) and this function did not execute
_notrun. The test did fail expectedly with "atomic write min 0, should be fs block size 4096".
Oh, yeah, awu_min==awu_max==0 should be an automatic _notrun.
Quoted 2 lines
However, the test shouldn't have begun or reached this stage if the underlying device doesn't support atomic writes, right?
_require* helpers decide if the test preconditions have been satisfied, so this is exactly where the test would bail out.
Quoted 58 lines
Maybe look at how
scsi_debugis used? Tests like tests/generic/704 and common/scsi_debug?Quoted 47 lines
common/rc +4
-0+ + _scratch_unmount +} + _require_inode_limits() {common/rc +0
-0if [ $(_get_free_inode $TEST_DIR) -eq 0 ]; thentests/xfs/611 new file +27
-0@@ -0,0 +1,81 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2024 Oracle. All Rights Reserved. +# +# FS QA Test 611 +# +# Validate atomic write support +# +. ./common/preamble +_begin_fstest auto quick rw + +_supported_fs xfs +_require_scratch +_require_scratch_write_atomic + +test_atomic_writes() +{ + local bsize=$1 + + _scratch_mkfs_xfs -b size=$bsize >> $seqres.full + _scratch_mount + _xfs_force_bdev data $SCRATCH_MNT + + testfile=$SCRATCH_MNT/testfile + touch $testfile + + file_min_write=$($XFS_IO_PROG -c "statx -r -m$STATX_WRITE_ATOMIC" $testfile | \
tests/xfs/611 new file +2
-0+ grep atomic_write_unit_min | cut -d ' ' -f 3) + file_max_write=$($XFS_IO_PROG -c "statx -r -m$STATX_WRITE_ATOMIC" $testfile | \
tests/xfs/611 new file +2
-0+ grep atomic_write_unit_max | cut -d ' ' -f 3) + file_max_segments=$($XFS_IO_PROG -c "statx -r -m$STATX_WRITE_ATOMIC" $testfile | \
tests/xfs/611
Quoted 2 lines
tests/xfs/611 new file +2
-0+ grep atomic_write_segments_max | cut -d ' ' -f 3) +Minor: A refactoring suggestion. Can we put the commands to fetch the
atomic_write_unit_min,atomic_write_unit_maxandatomic_write_segments_maxin a function and re-use them? We are using these commands to get bdev_min_write/bdev_max_write as well, so a function might make the code look more compact. Some maybe something like:
Quoted 1 line
_get_at_wr_unit_min()
Don't reuse another English word ("at") as an abbreviation, please.
_atomic_write_unit_min()
Quoted 35 lines
{
$XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $1 | grepatomic_write_unit_min | \ grep -o '[0-9]\+' }
_get_at_wr_unit_max()
{
$XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $1 | grepatomic_write_unit_max | \ grep -o '[0-9]\+' }and then,
file_min_write=$(_get_at_wr_unit_min $testfile) and similarly forfile_max_write,file_max_segments, bdev_min_write/bdev_max_writeQuoted 12 lines
tests/xfs/611 new file +3
-0+ # Check that atomic min/max = FS block size + test $file_min_write -eq $bsize || \ + echo "atomic write min $file_min_write, should be fs blocksize $bsize"
tests/xfs/611 new file +2
-0+ test $file_min_write -eq $bsize || \ + echo "atomic write max $file_max_write, should be fs blocksize $bsize"
tests/xfs/611 new file +2
-0+ test $file_max_segments -eq 1 || \ + echo "atomic write max segments $file_max_segments, shouldbe 1"
tests/xfs/611 new file +2
-0+ + # Check that we can perform an atomic write of len = FS blockQuoted 4 lines
size
+ bytes_written=$($XFS_IO_PROG -dc "pwrite -A -D 0 $bsize"
$testfile | \
+ grep wrote | awk -F'[/ ]' '{print $2}')is "$XFS_IO_PROG -dc pwrite -A -D 0 $bsize" $testfile actually making a pwritev2 syscall?
Quoted 7 lines
Let's look at the output below:
(tested with latest master of xfsprogs-dev (commit90d6da68) on pagesize and block size 4k (x86_64vm)mount
/dev/sdc/mnt1/test
touch /mnt1/test/new
strace -fxfs_io-c "pwrite -A -D 0 4096" /mnt1/test/new
You need to pass -d to xfs_io to get directio mode. The test does that, but your command line doesn't.
Quoted 8 lines
<last few lines>
openat(AT_FDCWD, "/mnt1/test/new", O_RDWR)= 3
...
...
pwrite64(3, "\315\315\315\315\315\315\315\315\315\315\315\315\315\315\315\315\315\3 15\315\315\315\315\315\315\315\315\315\315\315\315\315\315"..., 4096,
0) = 4096
That seems like a bug though. "pwrite -A -D -V1 0 4096"?
Quoted 37 lines
newfstatat(1, "", {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0x1), ...}, AT_EMPTY_PATH)= 0
write(1, "wrote 4096/4096 bytes at offset "..., 34wrote 4096/4096 bytes at offset 0
) = 34
write(1, "4 KiB, 1 ops; 0.0001 sec (23.819"..., 644 KiB, 1 ops; 0.0001 sec (23.819 MiB/sec and 6097.5610 ops/sec)
) = 64exit_group(0)So the issues are as follows:
1. file /mnt1/test/new is NOT opened withO_DIRECTflag i.e, direct io mode which is one of the requirements for atomic write (buffered io doesn't support atomic write, correct me if I am wrong).
2. pwrite64 doesn't take theRWF_ATOMICflag and hence I think this write is just a non-atomic write with no stdout output difference as such.Also if you look at the function
do_pwrite()inxfsprogs-dev/io/pwrite.cstatic
ssize_t
do_pwrite(int fd, off_t offset, long long count, size_t buffer_size, int pwritev2_flags){
if (!vectors)
return pwrite(fd,io_buffer,min(count, buffer_size),
offset);return do_pwritev(fd, offset, count, pwritev2_flags); }
Quoted 8 lines
it will not call pwritev/pwritev2 unless we have vectors for which you will need -V parameter with pwrite subcommand of
xfs_io.So I think the correct way to do this would be the following:
bytes_written=$($XFS_IO_PROGS -c "open -d $testfile" -c "pwrite -A -D -V 1 0 $bsize" | grep wrote | awk -F'[/ ]' '{print $2}').
Agreed.
Quoted 7 lines
This also bring us to 2 more test cases that we can add:
a. Atomic write with vec count > 1
$XFS_IO_PROGS -c "open -d $testfile" -c "pwrite -A -D -V 2 0 $bsize" (This should fail with Invalid argument since currently iovec count is restricted to 1)
Quoted 5 lines
b.
Open a file withOUTO_DIRECTand try to perform an atomic write. This should fail with Operation not Supported (EOPNOTSUPP). So something like
$XFS_IO_PROGS -c "open -f $testfile" -c "pwrite -A -V 1 0 $bsize"
Yeah, those are good subcases.
Quoted 11 lines
3. It is better to use -b $bsize with pwrite else, the write might be spilitted into multiple atomic writes. For example try the following:
$XFS_IO_PROGS -c "open -fd $testfile" -c "pwrite -A -D -V 1 0 $(( $bsize * 2 ))"
The above is expected to fail as the size of the atomic write is greater than the limit i.e, 1 block but it will still succeed. Look at the strace and you will see 2 pwritev2 system calls. However the following will fail expectedly with-EINVAL:
$XFS_IO_PROGS -c "open -fd $testfile" -c "pwrite -A -D -V 1 -b $(( $bsize * 2 )) 0 $(( $bsize * 2 ))"
Good catch.
Quoted 24 lines
Quoted 24 lines
+ test $bytes_written -eq $bsize || echo "atomic write len=$bsize
failed"tests/xfs/611 new file +2
-0+ + # Check that we can perform an atomic write on an unwrittenblock
tests/xfs/611 new file +2
-0+ $XFS_IO_PROG -c "falloc $bsize $bsize" $testfile + bytes_written=$($XFS_IO_PROG -dc "pwrite -A -D $bsize $bsize"$testfile | \
tests/xfs/611 new file +2
-0+ grep wrote | awk -F'[/ ]' '{print $2}') + test $bytes_written -eq $bsize || echo "atomic write tounwritten block failed"
tests/xfs/611 new file +4
-0+ + # 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 0 $bsize"$testfile | \
tests/xfs/611 new file +2
-0+ grep wrote | awk -F'[/ ]' '{print $2}') + test $bytes_written -eq $bsize || echo "atomic write to sparsehole failed"
tests/xfs/611 new file +2
-0+ + # Reject atomic write if len is out of bounds
Quoted 8 lines
Quoted 6 lines
+ $XFS_IO_PROG -dc "pwrite -A -D 0 $((bsize - 1))" $testfile 2>>
$seqres.full && \tests/xfs/611 new file +2
-0+ echo "atomic write len=$((bsize - 1)) should fail" + $XFS_IO_PROG -dc "pwrite -A -D 0 $((bsize + 1))" $testfile 2>>$seqres.full && \
+ echo "atomic write len=$((bsize + 1)) should fail"Have we covered the scenario where the offset % len != 0 Should fail - Should fail with Invalid arguments
-EINVAL.
I think you're right.
Quoted 4 lines
Also do you think adding similar tests with raw writes to the underlying devices bypassing the fs layer will add some value? There are slight less strict or different rules in the block layer which IMO worth to be tested. Please let me know your thoughts.
That should be in blktests.
Quoted 12 lines
tests/xfs/611
Quoted 11 lines
tests/xfs/611 new file +5
-0+ + _scratch_unmount +} + +bdev_min_write=$($XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC"$SCRATCH_DEV | \
tests/xfs/611 new file +2
-0+ grep atomic_write_unit_min | cut -d ' ' -f 3) +bdev_max_write=$($XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC"$SCRATCH_DEV | \
tests/xfs/611 new file +2
-0+ grep atomic_write_unit_max | cut -d ' ' -f 3) +Similar comment before - Refactor this into a function.
Quoted 8 lines
tests/xfs/611 line 76
Quoted 5 lines
tests/xfs/611 new file +2
-0+for ((bsize=$bdev_min_write; bsize<=bdev_max_write; bsize*=2)); do + _scratch_mkfs_xfs_supported -b size=$bsize >> $seqres.full 2>&1&& \
tests/xfs/611 new file +2
-0+ test_atomic_writes $bsize +done;Minor: This might fail on some
archs(x86_64)if the kernel isn't compiled withoutCONFIG_TRANSPARENT_HUGEPAGEto enable block size greater than 4k onx86_64.
Oh, yeah, that's a good catch.
--D
Quoted 18 lines
--
NRQuoted 13 lines
tests/xfs/611 new file +5
-0+ +# success, all done +echo Silence is golden +status=0 +exittests/xfs/611.out new file +2
-0@@ -0,0 +1,2 @@ +QA output created by 611 +Silence is golden
Quoted 31 lines · Darrick J. Wong
Quoted 23 lines · Nirjhar Roy
Quoted 8 lines · Catherine Hoang
Add a test to validate the new atomic writes feature.
Signed-off-by Catherine Hoang <[email protected]>--- common/rc | 14 ++++++++ tests/xfs/611 | 81 +++++++++++++++++++++++++++++++++++++++++++++++ tests/xfs/611.out | 2 ++Now that ext4 also has support for block atomic writes, do you think it appropritate to put it under generic?
Quoted 12 lines
3 files changed, 97 insertions(+)create mode 100755 tests/xfs/611
create mode 100644 tests/xfs/611.outcommon/rc +0
-0@@ -5148,6 +5148,20 @@ _require_scratch_btime() _scratch_unmount }Quoted 7 lines
common/rc _require_scratch_btime() · line 5155
Quoted 5 lines
common/rc +5
-0+_require_scratch_write_atomic() +{ + _require_scratch + _scratch_mkfs > /dev/null 2>&1 + _scratch_mountMinor: Do we need the
_scratch_mountand_scratch_unmount? We can directly statx the underlying device too, right?
Quoted 3 lines
Yes, we need the scratch fs, because the filesystem might not support untorn writes even if the underlying block device does. Or it can decide to constrain the supported io sizes.
Oh, right. We need both the file system and the device to support the atomic write feature.
Quoted 11 lines
Quoted 11 lines
common/rc _require_scratch_btime() · line 5160
Quoted 7 lines
common/rc +5
-0+ + export STATX_WRITE_ATOMIC=0x10000 + $XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $SCRATCH_MNT \ + | grep atomic >>$seqres.full 2>&1 || \ + _notrun "write atomic not supported by this filesystem"Are we assuming that the
SCRATCH_DEVsupports atomic writes here? If not, do you think the idea of checking if the underlying device supports atomic writes will be appropriate here?
Quoted 4 lines
Quoted 3 lines
I tried running the test with a loop device (with no atomic writes support) and this function did not execute
_notrun. The test did fail expectedly with "atomic write min 0, should be fs block size 4096".Oh, yeah, awu_min==awu_max==0 should be an automatic
_notrun.
Yes.
Quoted 63 lines
Quoted 3 lines
However, the test shouldn't have begun or reached this stage if the underlying device doesn't support atomic writes, right?
_require* helpers decide if the test preconditions have been satisfied, so this is exactly where the test would bail out.
Quoted 58 lines
Maybe look at how
scsi_debugis used? Tests like tests/generic/704 and common/scsi_debug?Quoted 47 lines
common/rc +4
-0+ + _scratch_unmount +} + _require_inode_limits() {if [ $(_get_free_inode $TEST_DIR) -eq 0 ]; thentests/xfs/611 new file +27
-0@@ -0,0 +1,81 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2024 Oracle. All Rights Reserved. +# +# FS QA Test 611 +# +# Validate atomic write support +# +. ./common/preamble +_begin_fstest auto quick rw + +_supported_fs xfs +_require_scratch +_require_scratch_write_atomic + +test_atomic_writes() +{ + local bsize=$1 + + _scratch_mkfs_xfs -b size=$bsize >> $seqres.full + _scratch_mount + _xfs_force_bdev data $SCRATCH_MNT + + testfile=$SCRATCH_MNT/testfile + touch $testfile + + file_min_write=$($XFS_IO_PROG -c "statx -r -m$STATX_WRITE_ATOMIC" $testfile | \
tests/xfs/611 new file +2
-0+ grep atomic_write_unit_min | cut -d ' ' -f 3) + file_max_write=$($XFS_IO_PROG -c "statx -r -m$STATX_WRITE_ATOMIC" $testfile | \
tests/xfs/611 new file +2
-0+ grep atomic_write_unit_max | cut -d ' ' -f 3) + file_max_segments=$($XFS_IO_PROG -c "statx -r -m$STATX_WRITE_ATOMIC" $testfile | \
tests/xfs/611
Quoted 2 lines
tests/xfs/611 new file +2
-0+ grep atomic_write_segments_max | cut -d ' ' -f 3) +Minor: A refactoring suggestion. Can we put the commands to fetch the
atomic_write_unit_min,atomic_write_unit_maxandatomic_write_segments_maxin a function and re-use them? We are using these commands to get bdev_min_write/bdev_max_write as well, so a function might make the code look more compact. Some maybe something like:
Quoted 4 lines
Quoted 1 line
_get_at_wr_unit_min()Don't reuse another English word ("at") as an abbreviation, please.
_atomic_write_unit_min()
Okay.
Quoted 40 lines
Quoted 40 lines
{
$XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $1 | grepatomic_write_unit_min | \ grep -o '[0-9]\+' }
_get_at_wr_unit_max()
{
$XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $1 | grepatomic_write_unit_max | \ grep -o '[0-9]\+' }and then,
file_min_write=$(_get_at_wr_unit_min $testfile) and similarly forfile_max_write,file_max_segments, bdev_min_write/bdev_max_writeQuoted 12 lines
tests/xfs/611 new file +3
-0+ # Check that atomic min/max = FS block size + test $file_min_write -eq $bsize || \ + echo "atomic write min $file_min_write, should be fs blocksize $bsize"
tests/xfs/611 new file +2
-0+ test $file_min_write -eq $bsize || \ + echo "atomic write max $file_max_write, should be fs blocksize $bsize"
tests/xfs/611 new file +2
-0+ test $file_max_segments -eq 1 || \ + echo "atomic write max segments $file_max_segments, shouldbe 1"
tests/xfs/611 new file +2
-0+ + # Check that we can perform an atomic write of len = FS blockQuoted 4 lines
size
+ bytes_written=$($XFS_IO_PROG -dc "pwrite -A -D 0 $bsize"
$testfile | \
+ grep wrote | awk -F'[/ ]' '{print $2}')is "$XFS_IO_PROG -dc pwrite -A -D 0 $bsize" $testfile actually making a pwritev2 syscall?
Let's look at the output below:
(tested with latest master of xfsprogs-dev (commit90d6da68) on pagesize and block size 4k (x86_64vm)
Quoted 5 lines
Quoted 3 lines
mount
/dev/sdc/mnt1/test
touch /mnt1/test/new
strace -fxfs_io-c "pwrite -A -D 0 4096" /mnt1/test/newYou need to pass -d to
xfs_ioto get directio mode. The test does that, but your command line doesn't.
Yes. Sorry I missed that.
Quoted 10 lines
Quoted 9 lines
<last few lines>
openat(AT_FDCWD, "/mnt1/test/new", O_RDWR)= 3
...
...
pwrite64(3, "\315\315\315\315\315\315\315\315\315\315\315\315\315\315\315\315\315\3 15\315\315\315\315\315\315\315\315\315\315\315\315\315\315"..., 4096,
0) = 4096That seems like a bug though. "pwrite -A -D -V1 0 4096"?
Sorry, what is the bug that you are pointing out here?
The command given by you i.e, xfs_io -dc "pwrite -A -D -V1 4096" <path> works fine.
--
NR
Quoted 154 lines
Quoted 38 lines
newfstatat(1, "", {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0x1), ...}, AT_EMPTY_PATH)= 0
write(1, "wrote 4096/4096 bytes at offset "..., 34wrote 4096/4096 bytes at offset 0
) = 34
write(1, "4 KiB, 1 ops; 0.0001 sec (23.819"..., 644 KiB, 1 ops; 0.0001 sec (23.819 MiB/sec and 6097.5610 ops/sec)
) = 64exit_group(0)So the issues are as follows:
1. file /mnt1/test/new is NOT opened withO_DIRECTflag i.e, direct io mode which is one of the requirements for atomic write (buffered io doesn't support atomic write, correct me if I am wrong).
2. pwrite64 doesn't take theRWF_ATOMICflag and hence I think this write is just a non-atomic write with no stdout output difference as such.Also if you look at the function
do_pwrite()inxfsprogs-dev/io/pwrite.cstatic
ssize_t
do_pwrite(int fd, off_t offset, long long count, size_t buffer_size, int pwritev2_flags){
if (!vectors)
return pwrite(fd,io_buffer,min(count, buffer_size),
offset);return do_pwritev(fd, offset, count, pwritev2_flags); }Quoted 8 lines
it will not call pwritev/pwritev2 unless we have vectors for which you will need -V parameter with pwrite subcommand of
xfs_io.So I think the correct way to do this would be the following:
bytes_written=$($XFS_IO_PROGS -c "open -d $testfile" -c "pwrite -A -D -V 1 0 $bsize" | grep wrote | awk -F'[/ ]' '{print $2}').
Agreed.
Quoted 7 lines
This also bring us to 2 more test cases that we can add:
a. Atomic write with vec count > 1
$XFS_IO_PROGS -c "open -d $testfile" -c "pwrite -A -D -V 2 0 $bsize" (This should fail with Invalid argument since currently iovec count is restricted to 1)Quoted 5 lines
b.
Open a file withOUTO_DIRECTand try to perform an atomic write. This should fail with Operation not Supported (EOPNOTSUPP). So something like
$XFS_IO_PROGS -c "open -f $testfile" -c "pwrite -A -V 1 0 $bsize"Yeah, those are good subcases.
Quoted 11 lines
3. It is better to use -b $bsize with pwrite else, the write might be spilitted into multiple atomic writes. For example try the following:
$XFS_IO_PROGS -c "open -fd $testfile" -c "pwrite -A -D -V 1 0 $(( $bsize * 2 ))"
The above is expected to fail as the size of the atomic write is greater than the limit i.e, 1 block but it will still succeed. Look at the strace and you will see 2 pwritev2 system calls. However the following will fail expectedly with-EINVAL:
$XFS_IO_PROGS -c "open -fd $testfile" -c "pwrite -A -D -V 1 -b $(( $bsize * 2 )) 0 $(( $bsize * 2 ))"Good catch.
Quoted 23 lines
Quoted 23 lines
+ test $bytes_written -eq $bsize || echo "atomic write len=$bsize
failed"tests/xfs/611 new file +2
-0+ + # Check that we can perform an atomic write on an unwrittenblock
tests/xfs/611 new file +2
-0+ $XFS_IO_PROG -c "falloc $bsize $bsize" $testfile + bytes_written=$($XFS_IO_PROG -dc "pwrite -A -D $bsize $bsize"$testfile | \
tests/xfs/611 new file +2
-0+ grep wrote | awk -F'[/ ]' '{print $2}') + test $bytes_written -eq $bsize || echo "atomic write tounwritten block failed"
tests/xfs/611 new file +4
-0+ + # 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 0 $bsize"$testfile | \
tests/xfs/611 new file +2
-0+ grep wrote | awk -F'[/ ]' '{print $2}') + test $bytes_written -eq $bsize || echo "atomic write to sparsehole failed"
tests/xfs/611 new file +2
-0+ + # Reject atomic write if len is out of boundsQuoted 8 lines
Quoted 6 lines
+ $XFS_IO_PROG -dc "pwrite -A -D 0 $((bsize - 1))" $testfile 2>>
$seqres.full && \tests/xfs/611 new file +2
-0+ echo "atomic write len=$((bsize - 1)) should fail" + $XFS_IO_PROG -dc "pwrite -A -D 0 $((bsize + 1))" $testfile 2>>$seqres.full && \
+ echo "atomic write len=$((bsize + 1)) should fail"Have we covered the scenario where the offset % len != 0 Should fail - Should fail with Invalid arguments
-EINVAL.I think you're right.
Quoted 4 lines
Also do you think adding similar tests with raw writes to the underlying devices bypassing the fs layer will add some value? There are slight less strict or different rules in the block layer which IMO worth to be tested. Please let me know your thoughts.
That should be in blktests.
Quoted 12 lines
tests/xfs/611
Quoted 11 lines
tests/xfs/611 new file +5
-0+ + _scratch_unmount +} + +bdev_min_write=$($XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC"$SCRATCH_DEV | \
tests/xfs/611 new file +2
-0+ grep atomic_write_unit_min | cut -d ' ' -f 3) +bdev_max_write=$($XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC"$SCRATCH_DEV | \
tests/xfs/611 new file +2
-0+ grep atomic_write_unit_max | cut -d ' ' -f 3) +Similar comment before - Refactor this into a function.
Quoted 8 lines
tests/xfs/611 line 76
Quoted 5 lines
tests/xfs/611 new file +2
-0+for ((bsize=$bdev_min_write; bsize<=bdev_max_write; bsize*=2)); do + _scratch_mkfs_xfs_supported -b size=$bsize >> $seqres.full 2>&1&& \
tests/xfs/611 new file +2
-0+ test_atomic_writes $bsize +done;Minor: This might fail on some
archs(x86_64)if the kernel isn't compiled withoutCONFIG_TRANSPARENT_HUGEPAGEto enable block size greater than 4k onx86_64.Oh, yeah, that's a good catch.
--D
Quoted 16 lines
--
NRQuoted 13 lines
tests/xfs/611 new file +5
-0+ +# success, all done +echo Silence is golden +status=0 +exittests/xfs/611.out new file +2
-0@@ -0,0 +1,2 @@ +QA output created by 611 +Silence is golden
Signature · 4 lines
--- Nirjhar Roy Linux Kernel Developer IBM, Bangalore
Quoted 6 lines · Nirjhar Roy
Quoted 4 lines · Darrick J. Wong
Quoted 3 lines · Nirjhar Roy
Quoted 2 lines · Catherine Hoang
Add a test to validate the new atomic writes feature.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Signed-off-by Catherine Hoang <[email protected]>--- common/rc | 14 ++++++++ tests/xfs/611 | 81 +++++++++++++++++++++++++++++++++++++++++++++++ tests/xfs/611.out | 2 ++Now that ext4 also has support for block atomic writes, do you think it appropritate to put it under generic?
Yeah, it ought to be a generic test.
Quoted 162 lines
Quoted 18 lines
Quoted 4 lines
Quoted 4 lines
3 files changed, 97 insertions(+)create mode 100755 tests/xfs/611
create mode 100644 tests/xfs/611.outQuoted 14 lines
common/rc _require_scratch_btime() · line 5154
Quoted 12 lines
common/rc +5
-0@@ -5148,6 +5148,20 @@ _require_scratch_btime() _scratch_unmount } +_require_scratch_write_atomic() +{ + _require_scratch + _scratch_mkfs > /dev/null 2>&1 + _scratch_mountMinor: Do we need the
_scratch_mountand_scratch_unmount? We can directly statx the underlying device too, right?Quoted 3 lines
Yes, we need the scratch fs, because the filesystem might not support untorn writes even if the underlying block device does. Or it can decide to constrain the supported io sizes.
Oh, right. We need both the file system and the device to support the atomic write feature.
Quoted 11 lines
Quoted 11 lines
common/rc _require_scratch_btime() · line 5160
Quoted 7 lines
common/rc +5
-0+ + export STATX_WRITE_ATOMIC=0x10000 + $XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $SCRATCH_MNT \ + | grep atomic >>$seqres.full 2>&1 || \ + _notrun "write atomic not supported by this filesystem"Are we assuming that the
SCRATCH_DEVsupports atomic writes here? If not, do you think the idea of checking if the underlying device supports atomic writes will be appropriate here?Quoted 4 lines
Quoted 3 lines
I tried running the test with a loop device (with no atomic writes support) and this function did not execute
_notrun. The test did fail expectedly with "atomic write min 0, should be fs block size 4096".Oh, yeah, awu_min==awu_max==0 should be an automatic
_notrun.Yes.
Quoted 63 lines
Quoted 3 lines
However, the test shouldn't have begun or reached this stage if the underlying device doesn't support atomic writes, right?
_require* helpers decide if the test preconditions have been satisfied, so this is exactly where the test would bail out.
Quoted 58 lines
Maybe look at how
scsi_debugis used? Tests like tests/generic/704 and common/scsi_debug?Quoted 47 lines
common/rc +4
-0+ + _scratch_unmount +} + _require_inode_limits() { if [ $(_get_free_inode $TEST_DIR) -eq 0 ]; thentests/xfs/611 new file +27
-0@@ -0,0 +1,81 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2024 Oracle. All Rights Reserved. +# +# FS QA Test 611 +# +# Validate atomic write support +# +. ./common/preamble +_begin_fstest auto quick rw + +_supported_fs xfs +_require_scratch +_require_scratch_write_atomic + +test_atomic_writes() +{ + local bsize=$1 + + _scratch_mkfs_xfs -b size=$bsize >> $seqres.full + _scratch_mount + _xfs_force_bdev data $SCRATCH_MNT + + testfile=$SCRATCH_MNT/testfile + touch $testfile + + file_min_write=$($XFS_IO_PROG -c "statx -r -m$STATX_WRITE_ATOMIC" $testfile | \
tests/xfs/611 new file +2
-0+ grep atomic_write_unit_min | cut -d ' ' -f 3) + file_max_write=$($XFS_IO_PROG -c "statx -r -m$STATX_WRITE_ATOMIC" $testfile | \
tests/xfs/611 new file +2
-0+ grep atomic_write_unit_max | cut -d ' ' -f 3) + file_max_segments=$($XFS_IO_PROG -c "statx -r -m$STATX_WRITE_ATOMIC" $testfile | \
tests/xfs/611
Quoted 2 lines
tests/xfs/611 new file +2
-0+ grep atomic_write_segments_max | cut -d ' ' -f 3) +Minor: A refactoring suggestion. Can we put the commands to fetch the
atomic_write_unit_min,atomic_write_unit_maxandatomic_write_segments_maxin a function and re-use them? We are using these commands to get bdev_min_write/bdev_max_write as well, so a function might make the code look more compact. Some maybe something like:Quoted 4 lines
Quoted 1 line
_get_at_wr_unit_min()Don't reuse another English word ("at") as an abbreviation, please.
_atomic_write_unit_min()Okay.
Quoted 40 lines
Quoted 40 lines
{
$XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $1 | grepatomic_write_unit_min | \ grep -o '[0-9]\+' }
_get_at_wr_unit_max()
{
$XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $1 | grepatomic_write_unit_max | \ grep -o '[0-9]\+' }and then,
file_min_write=$(_get_at_wr_unit_min $testfile) and similarly forfile_max_write,file_max_segments, bdev_min_write/bdev_max_writeQuoted 12 lines
tests/xfs/611 new file +3
-0+ # Check that atomic min/max = FS block size + test $file_min_write -eq $bsize || \ + echo "atomic write min $file_min_write, should be fs blocksize $bsize"
tests/xfs/611 new file +2
-0+ test $file_min_write -eq $bsize || \ + echo "atomic write max $file_max_write, should be fs blocksize $bsize"
tests/xfs/611 new file +2
-0+ test $file_max_segments -eq 1 || \ + echo "atomic write max segments $file_max_segments, shouldbe 1"
tests/xfs/611 new file +2
-0+ + # Check that we can perform an atomic write of len = FS blockQuoted 4 lines
size
+ bytes_written=$($XFS_IO_PROG -dc "pwrite -A -D 0 $bsize"
$testfile | \
+ grep wrote | awk -F'[/ ]' '{print $2}')is "$XFS_IO_PROG -dc pwrite -A -D 0 $bsize" $testfile actually making a pwritev2 syscall?
Let's look at the output below:
(tested with latest master of xfsprogs-dev (commit90d6da68) on pagesize and block size 4k (x86_64vm)Quoted 5 lines
Quoted 3 lines
mount
/dev/sdc/mnt1/test
touch /mnt1/test/new
strace -fxfs_io-c "pwrite -A -D 0 4096" /mnt1/test/newYou need to pass -d to
xfs_ioto get directio mode. The test does that, but your command line doesn't.Yes. Sorry I missed that.
Quoted 9 lines
Quoted 9 lines
<last few lines>
openat(AT_FDCWD, "/mnt1/test/new", O_RDWR)= 3
...
...
pwrite64(3, "\315\315\315\315\315\315\315\315\315\315\315\315\315\315\315\315\315\3 15\315\315\315\315\315\315\315\315\315\315\315\315\315\315"..., 4096,
0) = 4096
Quoted 6 lines
Quoted 1 line
That seems like a bug though. "pwrite -A -D -V1 0 4096"?
Sorry, what is the bug that you are pointing out here?
The command given by you i.e,
xfs_io-dc "pwrite -A -D -V1 4096" <path> works fine.
Yeah, sorry, I was clumsily agreeing with your version. Zarro boogs here, as it were. :)
--D
Quoted 165 lines
--
NR
Quoted 154 lines
Quoted 38 lines
newfstatat(1, "", {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0x1), ...}, AT_EMPTY_PATH)= 0
write(1, "wrote 4096/4096 bytes at offset "..., 34wrote 4096/4096 bytes at offset 0
) = 34
write(1, "4 KiB, 1 ops; 0.0001 sec (23.819"..., 644 KiB, 1 ops; 0.0001 sec (23.819 MiB/sec and 6097.5610 ops/sec)
) = 64exit_group(0)So the issues are as follows:
1. file /mnt1/test/new is NOT opened withO_DIRECTflag i.e, direct io mode which is one of the requirements for atomic write (buffered io doesn't support atomic write, correct me if I am wrong).
2. pwrite64 doesn't take theRWF_ATOMICflag and hence I think this write is just a non-atomic write with no stdout output difference as such.Also if you look at the function
do_pwrite()inxfsprogs-dev/io/pwrite.cstatic
ssize_t
do_pwrite(int fd, off_t offset, long long count, size_t buffer_size, int pwritev2_flags){
if (!vectors)
return pwrite(fd,io_buffer,min(count, buffer_size),
offset);return do_pwritev(fd, offset, count, pwritev2_flags); }Quoted 8 lines
it will not call pwritev/pwritev2 unless we have vectors for which you will need -V parameter with pwrite subcommand of
xfs_io.So I think the correct way to do this would be the following:
bytes_written=$($XFS_IO_PROGS -c "open -d $testfile" -c "pwrite -A -D -V 1 0 $bsize" | grep wrote | awk -F'[/ ]' '{print $2}').
Agreed.
Quoted 7 lines
This also bring us to 2 more test cases that we can add:
a. Atomic write with vec count > 1
$XFS_IO_PROGS -c "open -d $testfile" -c "pwrite -A -D -V 2 0 $bsize" (This should fail with Invalid argument since currently iovec count is restricted to 1)Quoted 5 lines
b.
Open a file withOUTO_DIRECTand try to perform an atomic write. This should fail with Operation not Supported (EOPNOTSUPP). So something like
$XFS_IO_PROGS -c "open -f $testfile" -c "pwrite -A -V 1 0 $bsize"Yeah, those are good subcases.
Quoted 11 lines
3. It is better to use -b $bsize with pwrite else, the write might be spilitted into multiple atomic writes. For example try the following:
$XFS_IO_PROGS -c "open -fd $testfile" -c "pwrite -A -D -V 1 0 $(( $bsize * 2 ))"
The above is expected to fail as the size of the atomic write is greater than the limit i.e, 1 block but it will still succeed. Look at the strace and you will see 2 pwritev2 system calls. However the following will fail expectedly with-EINVAL:
$XFS_IO_PROGS -c "open -fd $testfile" -c "pwrite -A -D -V 1 -b $(( $bsize * 2 )) 0 $(( $bsize * 2 ))"Good catch.
Quoted 23 lines
Quoted 23 lines
+ test $bytes_written -eq $bsize || echo "atomic write len=$bsize
failed"tests/xfs/611 new file +2
-0+ + # Check that we can perform an atomic write on an unwrittenblock
tests/xfs/611 new file +2
-0+ $XFS_IO_PROG -c "falloc $bsize $bsize" $testfile + bytes_written=$($XFS_IO_PROG -dc "pwrite -A -D $bsize $bsize"$testfile | \
tests/xfs/611 new file +2
-0+ grep wrote | awk -F'[/ ]' '{print $2}') + test $bytes_written -eq $bsize || echo "atomic write tounwritten block failed"
tests/xfs/611 new file +4
-0+ + # 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 0 $bsize"$testfile | \
tests/xfs/611 new file +2
-0+ grep wrote | awk -F'[/ ]' '{print $2}') + test $bytes_written -eq $bsize || echo "atomic write to sparsehole failed"
tests/xfs/611 new file +2
-0+ + # Reject atomic write if len is out of boundsQuoted 8 lines
Quoted 6 lines
+ $XFS_IO_PROG -dc "pwrite -A -D 0 $((bsize - 1))" $testfile 2>>
$seqres.full && \tests/xfs/611 new file +2
-0+ echo "atomic write len=$((bsize - 1)) should fail" + $XFS_IO_PROG -dc "pwrite -A -D 0 $((bsize + 1))" $testfile 2>>$seqres.full && \
+ echo "atomic write len=$((bsize + 1)) should fail"Have we covered the scenario where the offset % len != 0 Should fail - Should fail with Invalid arguments
-EINVAL.I think you're right.
Quoted 4 lines
Also do you think adding similar tests with raw writes to the underlying devices bypassing the fs layer will add some value? There are slight less strict or different rules in the block layer which IMO worth to be tested. Please let me know your thoughts.
That should be in blktests.
Quoted 12 lines
tests/xfs/611
Quoted 11 lines
tests/xfs/611 new file +5
-0+ + _scratch_unmount +} + +bdev_min_write=$($XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC"$SCRATCH_DEV | \
tests/xfs/611 new file +2
-0+ grep atomic_write_unit_min | cut -d ' ' -f 3) +bdev_max_write=$($XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC"$SCRATCH_DEV | \
tests/xfs/611 new file +2
-0+ grep atomic_write_unit_max | cut -d ' ' -f 3) +Similar comment before - Refactor this into a function.
Quoted 8 lines
tests/xfs/611 line 76
Quoted 5 lines
tests/xfs/611 new file +2
-0+for ((bsize=$bdev_min_write; bsize<=bdev_max_write; bsize*=2)); do + _scratch_mkfs_xfs_supported -b size=$bsize >> $seqres.full 2>&1&& \
tests/xfs/611 new file +2
-0+ test_atomic_writes $bsize +done;Minor: This might fail on some
archs(x86_64)if the kernel isn't compiled withoutCONFIG_TRANSPARENT_HUGEPAGEto enable block size greater than 4k onx86_64.Oh, yeah, that's a good catch.
--D
Quoted 16 lines
--
NRQuoted 13 lines
tests/xfs/611 new file +5
-0+ +# success, all done +echo Silence is golden +status=0 +exittests/xfs/611.out new file +2
-0@@ -0,0 +1,2 @@ +QA output created by 611 +Silence is goldenSignature · 4 lines
--- Nirjhar Roy Linux Kernel Developer IBM, Bangalore
Quoted 175 lines · Darrick J. Wong
Quoted 5 lines · Nirjhar Roy
Quoted 4 lines · Darrick J. Wong
Quoted 3 lines · Nirjhar Roy
Quoted 2 lines · Catherine Hoang
Add a test to validate the new atomic writes feature.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Signed-off-by Catherine Hoang <[email protected]>--- common/rc | 14 ++++++++ tests/xfs/611 | 81 +++++++++++++++++++++++++++++++++++++++++++++++ tests/xfs/611.out | 2 ++Now that ext4 also has support for block atomic writes, do you think it appropritate to put it under generic?
Yeah, it ought to be a generic test.
Quoted 159 lines
Quoted 18 lines
Quoted 4 lines
Quoted 4 lines
3 files changed, 97 insertions(+)create mode 100755 tests/xfs/611
create mode 100644 tests/xfs/611.outQuoted 14 lines
common/rc _require_scratch_btime() · line 5154
Quoted 12 lines
common/rc +5
-0@@ -5148,6 +5148,20 @@ _require_scratch_btime() _scratch_unmount } +_require_scratch_write_atomic() +{ + _require_scratch + _scratch_mkfs > /dev/null 2>&1 + _scratch_mountMinor: Do we need the
_scratch_mountand_scratch_unmount? We can directly statx the underlying device too, right?Quoted 3 lines
Yes, we need the scratch fs, because the filesystem might not support untorn writes even if the underlying block device does. Or it can decide to constrain the supported io sizes.
Oh, right. We need both the file system and the device to support the atomic write feature.
Quoted 10 lines
Quoted 10 lines
common/rc _require_scratch_btime() · line 5160
Quoted 6 lines
common/rc +5
-0+ + export STATX_WRITE_ATOMIC=0x10000 + $XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $SCRATCH_MNT \ + | grep atomic >>$seqres.full 2>&1 || \ + _notrun "write atomic not supported by this filesystem"Are we assuming that the
SCRATCH_DEVsupports atomic writes here? If not, do you think the idea of checking if the underlying device supports atomic writes will be appropriate here?Quoted 4 lines
Quoted 3 lines
I tried running the test with a loop device (with no atomic writes support) and this function did not execute
_notrun. The test did fail expectedly with "atomic write min 0, should be fs block size 4096".Oh, yeah, awu_min==awu_max==0 should be an automatic
_notrun.Yes.
Quoted 62 lines
Quoted 2 lines
However, the test shouldn't have begun or reached this stage if the underlying device doesn't support atomic writes, right?
_require* helpers decide if the test preconditions have been satisfied, so this is exactly where the test would bail out.
Quoted 58 lines
Maybe look at how
scsi_debugis used? Tests like tests/generic/704 and common/scsi_debug?Quoted 47 lines
common/rc +4
-0+ + _scratch_unmount +} + _require_inode_limits() { if [ $(_get_free_inode $TEST_DIR) -eq 0 ]; thentests/xfs/611 new file +27
-0@@ -0,0 +1,81 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2024 Oracle. All Rights Reserved. +# +# FS QA Test 611 +# +# Validate atomic write support +# +. ./common/preamble +_begin_fstest auto quick rw + +_supported_fs xfs +_require_scratch +_require_scratch_write_atomic + +test_atomic_writes() +{ + local bsize=$1 + + _scratch_mkfs_xfs -b size=$bsize >> $seqres.full + _scratch_mount + _xfs_force_bdev data $SCRATCH_MNT + + testfile=$SCRATCH_MNT/testfile + touch $testfile + + file_min_write=$($XFS_IO_PROG -c "statx -r -m$STATX_WRITE_ATOMIC" $testfile | \
tests/xfs/611 new file +2
-0+ grep atomic_write_unit_min | cut -d ' ' -f 3) + file_max_write=$($XFS_IO_PROG -c "statx -r -m$STATX_WRITE_ATOMIC" $testfile | \
tests/xfs/611 new file +2
-0+ grep atomic_write_unit_max | cut -d ' ' -f 3) + file_max_segments=$($XFS_IO_PROG -c "statx -r -m$STATX_WRITE_ATOMIC" $testfile | \
tests/xfs/611
Quoted 2 lines
tests/xfs/611 new file +2
-0+ grep atomic_write_segments_max | cut -d ' ' -f 3) +Minor: A refactoring suggestion. Can we put the commands to fetch the
atomic_write_unit_min,atomic_write_unit_maxandatomic_write_segments_maxin a function and re-use them? We are using these commands to get bdev_min_write/bdev_max_write as well, so a function might make the code look more compact. Some maybe something like:Quoted 4 lines
Quoted 1 line
_get_at_wr_unit_min()Don't reuse another English word ("at") as an abbreviation, please.
_atomic_write_unit_min()Okay.
Quoted 39 lines
Quoted 39 lines
{
$XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $1 | grepatomic_write_unit_min | \ grep -o '[0-9]\+' }
_get_at_wr_unit_max()
{
$XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $1 | grepatomic_write_unit_max | \ grep -o '[0-9]\+' }and then,
file_min_write=$(_get_at_wr_unit_min $testfile) and similarly forfile_max_write,file_max_segments, bdev_min_write/bdev_max_writeQuoted 12 lines
tests/xfs/611 new file +3
-0+ # Check that atomic min/max = FS block size + test $file_min_write -eq $bsize || \ + echo "atomic write min $file_min_write, should be fs blocksize $bsize"
tests/xfs/611 new file +2
-0+ test $file_min_write -eq $bsize || \ + echo "atomic write max $file_max_write, should be fs blocksize $bsize"
tests/xfs/611 new file +2
-0+ test $file_max_segments -eq 1 || \ + echo "atomic write max segments $file_max_segments, shouldbe 1"
tests/xfs/611 new file +2
-0+ + # Check that we can perform an atomic write of len = FS blockQuoted 4 lines
size
+ bytes_written=$($XFS_IO_PROG -dc "pwrite -A -D 0 $bsize"
$testfile | \
+ grep wrote | awk -F'[/ ]' '{print $2}')is "$XFS_IO_PROG -dc pwrite -A -D 0 $bsize" $testfile actually making a pwritev2 syscall?
Let's look at the output below:
(tested with latest master of xfsprogs-dev (commit90d6da68) on pagesize and block size 4k (x86_64vm)Quoted 5 lines
Quoted 3 lines
mount
/dev/sdc/mnt1/test
touch /mnt1/test/new
strace -fxfs_io-c "pwrite -A -D 0 4096" /mnt1/test/newYou need to pass -d to
xfs_ioto get directio mode. The test does that, but your command line doesn't.Yes. Sorry I missed that.
Quoted 9 lines
Quoted 8 lines
<last few lines>
openat(AT_FDCWD, "/mnt1/test/new", O_RDWR)= 3
...
...
pwrite64(3, "\315\315\315\315\315\315\315\315\315\315\315\315\315\315\315\315\315\3 15\315\315\315\315\315\315\315\315\315\315\315\315\315\315"..., 4096,
0) = 4096That seems like a bug though. "pwrite -A -D -V1 0 4096"?
Quoted 8 lines
Quoted 4 lines
Sorry, what is the bug that you are pointing out here?
The command given by you i.e,
xfs_io-dc "pwrite -A -D -V1 4096" <path> works fine.Yeah, sorry, I was clumsily agreeing with your version. Zarro boogs here, as it were. :)
--D
Okay got it.
--
NR
Quoted 163 lines
Quoted 163 lines
--
NR
Quoted 151 lines
Quoted 37 lines
newfstatat(1, "", {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0x1), ...}, AT_EMPTY_PATH)= 0
write(1, "wrote 4096/4096 bytes at offset "..., 34wrote 4096/4096 bytes at offset 0
) = 34
write(1, "4 KiB, 1 ops; 0.0001 sec (23.819"..., 644 KiB, 1 ops; 0.0001 sec (23.819 MiB/sec and 6097.5610 ops/sec)
) = 64exit_group(0)So the issues are as follows:
1. file /mnt1/test/new is NOT opened withO_DIRECTflag i.e, direct io mode which is one of the requirements for atomic write (buffered io doesn't support atomic write, correct me if I am wrong).
2. pwrite64 doesn't take theRWF_ATOMICflag and hence I think this write is just a non-atomic write with no stdout output difference as such.Also if you look at the function
do_pwrite()inxfsprogs-dev/io/pwrite.cstatic
ssize_t
do_pwrite(int fd, off_t offset, long long count, size_t buffer_size, int pwritev2_flags){
if (!vectors)
return pwrite(fd,io_buffer,min(count, buffer_size),
offset);return do_pwritev(fd, offset, count, pwritev2_flags); }Quoted 8 lines
it will not call pwritev/pwritev2 unless we have vectors for which you will need -V parameter with pwrite subcommand of
xfs_io.So I think the correct way to do this would be the following:
bytes_written=$($XFS_IO_PROGS -c "open -d $testfile" -c "pwrite -A -D -V 1 0 $bsize" | grep wrote | awk -F'[/ ]' '{print $2}').
Agreed.
Quoted 7 lines
This also bring us to 2 more test cases that we can add:
a. Atomic write with vec count > 1
$XFS_IO_PROGS -c "open -d $testfile" -c "pwrite -A -D -V 2 0 $bsize" (This should fail with Invalid argument since currently iovec count is restricted to 1)Quoted 5 lines
b.
Open a file withOUTO_DIRECTand try to perform an atomic write. This should fail with Operation not Supported (EOPNOTSUPP). So something like
$XFS_IO_PROGS -c "open -f $testfile" -c "pwrite -A -V 1 0 $bsize"Yeah, those are good subcases.
Quoted 11 lines
3. It is better to use -b $bsize with pwrite else, the write might be spilitted into multiple atomic writes. For example try the following:
$XFS_IO_PROGS -c "open -fd $testfile" -c "pwrite -A -D -V 1 0 $(( $bsize * 2 ))"
The above is expected to fail as the size of the atomic write is greater than the limit i.e, 1 block but it will still succeed. Look at the strace and you will see 2 pwritev2 system calls. However the following will fail expectedly with-EINVAL:
$XFS_IO_PROGS -c "open -fd $testfile" -c "pwrite -A -D -V 1 -b $(( $bsize * 2 )) 0 $(( $bsize * 2 ))"Good catch.
Quoted 22 lines
Quoted 22 lines
+ test $bytes_written -eq $bsize || echo "atomic write len=$bsize
failed"tests/xfs/611 new file +2
-0+ + # Check that we can perform an atomic write on an unwrittenblock
tests/xfs/611 new file +2
-0+ $XFS_IO_PROG -c "falloc $bsize $bsize" $testfile + bytes_written=$($XFS_IO_PROG -dc "pwrite -A -D $bsize $bsize"$testfile | \
tests/xfs/611 new file +2
-0+ grep wrote | awk -F'[/ ]' '{print $2}') + test $bytes_written -eq $bsize || echo "atomic write tounwritten block failed"
tests/xfs/611 new file +4
-0+ + # 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 0 $bsize"$testfile | \
tests/xfs/611 new file +2
-0+ grep wrote | awk -F'[/ ]' '{print $2}') + test $bytes_written -eq $bsize || echo "atomic write to sparsehole failed"
tests/xfs/611 new file +2
-0+ + # Reject atomic write if len is out of boundsQuoted 8 lines
Quoted 6 lines
+ $XFS_IO_PROG -dc "pwrite -A -D 0 $((bsize - 1))" $testfile 2>>
$seqres.full && \tests/xfs/611 new file +2
-0+ echo "atomic write len=$((bsize - 1)) should fail" + $XFS_IO_PROG -dc "pwrite -A -D 0 $((bsize + 1))" $testfile 2>>$seqres.full && \
+ echo "atomic write len=$((bsize + 1)) should fail"Have we covered the scenario where the offset % len != 0 Should fail - Should fail with Invalid arguments
-EINVAL.I think you're right.
Quoted 4 lines
Also do you think adding similar tests with raw writes to the underlying devices bypassing the fs layer will add some value? There are slight less strict or different rules in the block layer which IMO worth to be tested. Please let me know your thoughts.
That should be in blktests.
Quoted 12 lines
tests/xfs/611
Quoted 11 lines
tests/xfs/611 new file +5
-0+ + _scratch_unmount +} + +bdev_min_write=$($XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC"$SCRATCH_DEV | \
tests/xfs/611 new file +2
-0+ grep atomic_write_unit_min | cut -d ' ' -f 3) +bdev_max_write=$($XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC"$SCRATCH_DEV | \
tests/xfs/611 new file +2
-0+ grep atomic_write_unit_max | cut -d ' ' -f 3) +Similar comment before - Refactor this into a function.
Quoted 8 lines
tests/xfs/611 line 76
Quoted 5 lines
tests/xfs/611 new file +2
-0+for ((bsize=$bdev_min_write; bsize<=bdev_max_write; bsize*=2)); do + _scratch_mkfs_xfs_supported -b size=$bsize >> $seqres.full 2>&1&& \
tests/xfs/611 new file +2
-0+ test_atomic_writes $bsize +done;Minor: This might fail on some
archs(x86_64)if the kernel isn't compiled withoutCONFIG_TRANSPARENT_HUGEPAGEto enable block size greater than 4k onx86_64.Oh, yeah, that's a good catch.
--D
Quoted 15 lines
--
NRQuoted 13 lines
tests/xfs/611 new file +5
-0+ +# success, all done +echo Silence is golden +status=0 +exittests/xfs/611.out new file +2
-0@@ -0,0 +1,2 @@ +QA output created by 611 +Silence is goldenSignature · 4 lines
--- Nirjhar Roy Linux Kernel Developer IBM, Bangalore
Signature · 4 lines
--- Nirjhar Roy Linux Kernel Developer IBM, Bangalore
Quoted 1 line · Catherine Hoang
Add a test to validate the new atomic writes feature.
Thanks!
Quoted 74 lines
Signed-off-by Catherine Hoang <[email protected]>--- common/rc | 14 ++++++++ tests/xfs/611 | 81 +++++++++++++++++++++++++++++++++++++++++++++++ tests/xfs/611.out | 2 ++ 3 files changed, 97 insertions(+) create mode 100755 tests/xfs/611 create mode 100644 tests/xfs/611.outcommon/rc +14
-0@@ -5148,6 +5148,20 @@ _require_scratch_btime() _scratch_unmount } +_require_scratch_write_atomic() +{ + _require_scratch + _scratch_mkfs > /dev/null 2>&1 + _scratch_mount + + export STATX_WRITE_ATOMIC=0x10000 + $XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $SCRATCH_MNT \ + | grep atomic >>$seqres.full 2>&1 || \ + _notrun "write atomic not supported by this filesystem" + + _scratch_unmount +} + _require_inode_limits() { if [ $(_get_free_inode $TEST_DIR) -eq 0 ]; thentests/xfs/611 new file +33
-0@@ -0,0 +1,81 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2024 Oracle. All Rights Reserved. +# +# FS QA Test 611 +# +# Validate atomic write support +# +. ./common/preamble +_begin_fstest auto quick rw + +_supported_fs xfs +_require_scratch +_require_scratch_write_atomic + +test_atomic_writes() +{ + local bsize=$1 + + _scratch_mkfs_xfs -b size=$bsize >> $seqres.full + _scratch_mount + _xfs_force_bdev data $SCRATCH_MNT + + testfile=$SCRATCH_MNT/testfile + touch $testfile + + file_min_write=$($XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $testfile | \ + grep atomic_write_unit_min | cut -d ' ' -f 3) + file_max_write=$($XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $testfile | \ + grep atomic_write_unit_max | cut -d ' ' -f 3) + file_max_segments=$($XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $testfile | \ + grep atomic_write_segments_max | cut -d ' ' -f 3) +
tests/xfs/611 line 43
Quoted 10 lines
tests/xfs/611 new file +10
-0+ # 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 0 $bsize" $testfile | \
Shouldn't we also have something like below to see whether pwrite supports -A option or not?
_require_xfs_io_command pwrite -A
So maybe like this?
common/rc: Add support to validate -A option for pwrite
common/rc +7 -0
@@ -2837,6 +2837,13 @@ _require_xfs_io_command() opts+=" -d" pwrite_opts+="-V 1 -b 4k" fi + # Let's check if -A option is supported in xfs_io or not + if [ "$param" == "-A" ]; then + testio=$($XFS_IO_PROG -f -d -c \ + "pwrite -V 1 -b 4k -A 0 4k" $testfile 2>&1) + echo $testio |grep -q "invalid option" && \ + _notrun "xfs_io $command $param support is missing" + fi testio=`$XFS_IO_PROG -f $opts -c \ "pwrite $pwrite_opts $param 0 4k" $testfile 2>&1` param_checked="$pwrite_opts $param"
tests/xfs/611 line 45
Quoted 2 lines
tests/xfs/611 new file +2
-0+ grep wrote | awk -F'[/ ]' '{print $2}') + test $bytes_written -eq $bsize || echo "atomic write len=$bsize failed"
-ritesh