Skip to contentSkip to conversation

atomic writes tests (part 1)

PATCH In review Catherine Hoang 3 participants 8 messages Jun 2, 2025 – Jun 12, 2025

lore
Share & tools
lore
#0 lore raw

cover atomic writes tests (part 1)

Hi all,

These are the first 5 patches from the previous atomic writes test series.
https://lore.kernel.org/linux-xfs/[email protected]/
I plan on addressing comments from patch 6 in a separate series since there were requests to split that up into multiple patches.

No changes were made except for picking up a couple rvb tags. This series is based on for-next at the time of sending.

Darrick J. Wong (5):
generic/765: fix a few issues
generic/765: adjust various things
generic/765: move common atomic write code to a library file common/atomicwrites: adjust a few more things common/atomicwrites: fix _require_scratch_write_atomic

 common/atomicwrites | 117 ++++++++++++++++++++++++++++++++++++++++++++
 common/rc           |  49 +------------------
 doc/group-names.txt |   1 +
 tests/generic/765   |  84 ++++++++++++-------------------
 4 files changed, 149 insertions(+), 102 deletions(-)
 create mode 100644 common/atomicwrites
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/5 generic/765: fix a few issues

From: "Darrick J. Wong" <[email protected]>

Fix a few bugs in the single block atomic writes test, such as not requiring directio, using the page size for the ext4 max bsize, and making sure we check the max atomic write size.

---
 common/rc         | 2 +-
 tests/generic/765 | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
common/rc +1 -1
index d8ee8328..d34763ff 100644
@@ -2989,7 +2989,7 @@ _require_xfs_io_command()
 		fi
 		if [ "$param" == "-A" ]; then
 			opts+=" -d"
-			pwrite_opts+="-D -V 1 -b 4k"
+			pwrite_opts+="-V 1 -b 4k"
 		fi
 		testio=`$XFS_IO_PROG -f $opts -c \
 		        "pwrite $pwrite_opts $param 0 4k" $testfile 2>&1`
tests/generic/765 +2 -2
index 9bab3b8a..8695a306 100755
@@ -28,7 +28,7 @@ get_supported_bsize()
         ;;
     "ext4")
         min_bsize=1024
-        max_bsize=4096
+        max_bsize=$(_get_page_size)
         ;;
     *)
         _notrun "$FSTYP does not support atomic writes"
@@ -73,7 +73,7 @@ test_atomic_writes()
     # 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 || \
+    test $file_max_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"
Signature · 1 line
2.34.1
Reviewed-by on v1 1/5
#2 lore raw

Re: [PATCH 1/5] generic/765: fix a few issues

Quoted 6 lines · Catherine Hoang

From: "Darrick J. Wong"<[email protected]>

Fix a few bugs in the single block atomic writes test, such as not requiring directio, using the page size for the ext4 max bsize, and making sure we check the max atomic write size.

Quoted 7 lines

---

BTW, it would have been nice to keep the series versioning as before, as this is really the same series, thanks!

#3 lore raw

PATCH 2/5 generic/765: adjust various things

In reply to Catherine Hoang

From: "Darrick J. Wong" <[email protected]>

Fix some bugs when detecting the atomic write geometry, record what atomic write geometry we're testing each time through the loop, and create a group for atomic writes tests.

---
 common/rc           |  4 ++--
 doc/group-names.txt |  1 +
 tests/generic/765   | 25 ++++++++++++++++++++++++-
 3 files changed, 27 insertions(+), 3 deletions(-)
common/rc +2 -2
index d34763ff..f7d38894 100644
@@ -5452,13 +5452,13 @@ _get_atomic_write_unit_min()
 _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]\+'
+        grep -w 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]\+'
+        grep -w atomic_write_segments_max | grep -o '[0-9]\+'
 }
 
 _require_scratch_write_atomic()
doc/group-names.txt +1 -0
index 58502131..10b49e50 100644
@@ -12,6 +12,7 @@ acl			Access Control Lists
 admin			xfs_admin functionality
 aio			general libaio async io tests
 atime			file access time
+atomicwrites		RWF_ATOMIC testing
 attr			extended attributes
 attr2			xfs v2 extended aributes
 balance			btrfs tree rebalance
tests/generic/765 +24 -1
index 8695a306..84381730 100755
@@ -7,7 +7,7 @@
 # Validate atomic write support
 #
 . ./common/preamble
-_begin_fstest auto quick rw
+_begin_fstest auto quick rw atomicwrites
 
 _require_scratch_write_atomic
 _require_xfs_io_command pwrite -A
@@ -34,6 +34,10 @@ get_supported_bsize()
         _notrun "$FSTYP does not support atomic writes"
         ;;
     esac
+
+    echo "fs config ------------" >> $seqres.full
+    echo "min_bsize $min_bsize" >> $seqres.full
+    echo "max_bsize $max_bsize" >> $seqres.full
 }
 
 get_mkfs_opts()
@@ -70,6 +74,11 @@ test_atomic_writes()
     file_max_write=$(_get_atomic_write_unit_max $testfile)
     file_max_segments=$(_get_atomic_write_segments_max $testfile)
 
+    echo "test $bsize --------------" >> $seqres.full
+    echo "file awu_min $file_min_write" >> $seqres.full
+    echo "file awu_max $file_max_write" >> $seqres.full
+    echo "file awu_segments $file_max_segments" >> $seqres.full
+
     # 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"
@@ -145,6 +154,15 @@ test_atomic_write_bounds()
     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)
+
+    echo "test awb $bsize --------------" >> $seqres.full
+    echo "file awu_min $file_min_write" >> $seqres.full
+    echo "file awu_max $file_max_write" >> $seqres.full
+    echo "file awu_segments $file_max_segments" >> $seqres.full
+
     $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"
 
@@ -157,6 +175,11 @@ sys_max_write=$(cat "/sys/block/$(_short_dev $SCRATCH_DEV)/queue/atomic_write_un
 bdev_min_write=$(_get_atomic_write_unit_min $SCRATCH_DEV)
 bdev_max_write=$(_get_atomic_write_unit_max $SCRATCH_DEV)
 
+echo "sysfs awu_min $sys_min_write" >> $seqres.full
+echo "sysfs awu_min $sys_max_write" >> $seqres.full
+echo "bdev awu_min $bdev_min_write" >> $seqres.full
+echo "bdev awu_min $bdev_max_write" >> $seqres.full
+
 # Test that statx atomic values are the same as sysfs values
 if [ "$sys_min_write" -ne "$bdev_min_write" ]; then
     echo "bdev min write != sys min write"
Signature · 1 line
2.34.1
#4 lore raw

PATCH 3/5 generic/765: move common atomic write code to a library file

In reply to Catherine Hoang

From: "Darrick J. Wong" <[email protected]>

Move the common atomic writes code to common/atomicwrites so we can share them.

---
 common/atomicwrites | 111 ++++++++++++++++++++++++++++++++++++++++++++
 common/rc           |  47 -------------------
 tests/generic/765   |  53 ++-------------------
 3 files changed, 114 insertions(+), 97 deletions(-)
 create mode 100644 common/atomicwrites
common/atomicwrites new file +111 -0
new file mode 100644
index 00000000..fd3a9b71
@@ -0,0 +1,111 @@
+##/bin/bash
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (c) 2025 Oracle.  All Rights Reserved.
+#
+# Routines for testing atomic writes.
+
+_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 -w 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 -w 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
+}
+
+_test_atomic_file_writes()
+{
+    local bsize="$1"
+    local testfile="$2"
+    local bytes_written
+    local testfile_cp="$testfile.copy"
+
+    # 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"
+}
common/rc +0 -47

53 lines not on this page · raw message

tests/generic/765 +3 -50

65 lines not on this page · raw message

Signature · 1 line
2.34.1
#5 lore raw

PATCH 4/5 common/atomicwrites: adjust a few more things

In reply to Catherine Hoang

From: "Darrick J. Wong" <[email protected]>

Always export STATX_WRITE_ATOMIC so anyone can use it, make the "cp reflink" logic work for any filesystem, not just xfs, and create a separate helper to check that the necessary xfs_io support is present.

---
 common/atomicwrites | 18 +++++++++++-------
 tests/generic/765   |  2 +-
 2 files changed, 12 insertions(+), 8 deletions(-)
common/atomicwrites +11 -7
index fd3a9b71..9ec1ca68 100644
@@ -4,6 +4,8 @@
 #
 # Routines for testing atomic writes.
 
+export STATX_WRITE_ATOMIC=0x10000
+
 _get_atomic_write_unit_min()
 {
 	$XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $1 | \
@@ -26,8 +28,6 @@ _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)
 
@@ -51,6 +51,14 @@ _require_scratch_write_atomic()
 	fi
 }
 
+# Check for xfs_io commands required to run _test_atomic_file_writes
+_require_atomic_write_test_commands()
+{
+	_require_xfs_io_command "falloc"
+	_require_xfs_io_command "fpunch"
+	_require_xfs_io_command pwrite -A
+}
+
 _test_atomic_file_writes()
 {
     local bsize="$1"
@@ -64,11 +72,7 @@ _test_atomic_file_writes()
     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
+    if cp --reflink=always $testfile $testfile_cp 2>> $seqres.full; then
         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"
tests/generic/765 +1 -1
index 09e9fa38..71604e5e 100755
@@ -12,7 +12,7 @@ _begin_fstest auto quick rw atomicwrites
 . ./common/atomicwrites
 
 _require_scratch_write_atomic
-_require_xfs_io_command pwrite -A
+_require_atomic_write_test_commands
 
 get_supported_bsize()
 {
Signature · 1 line
2.34.1
#6 lore raw

PATCH 5/5 common/atomicwrites: fix _require_scratch_write_atomic

In reply to Catherine Hoang

From: "Darrick J. Wong" <[email protected]>

Fix this function to call _notrun whenever something fails. If we can't figure out the atomic write geometry, then we haven't satisfied the preconditions for the test.

---
 common/atomicwrites | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
common/atomicwrites +9 -7
index 9ec1ca68..391bb6f6 100644
@@ -28,21 +28,23 @@ _require_scratch_write_atomic()
 {
 	_require_scratch
 
-	awu_min_bdev=$(_get_atomic_write_unit_min $SCRATCH_DEV)
-	awu_max_bdev=$(_get_atomic_write_unit_max $SCRATCH_DEV)
+	local awu_min_bdev=$(_get_atomic_write_unit_min $SCRATCH_DEV)
+	local 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
+	_scratch_mkfs > /dev/null 2>&1 || \
+		_notrun "cannot format scratch device for atomic write checks"
+	_try_scratch_mount || \
+		_notrun "cannot mount scratch device for atomic write checks"
 
-	testfile=$SCRATCH_MNT/testfile
+	local testfile=$SCRATCH_MNT/testfile
 	touch $testfile
 
-	awu_min_fs=$(_get_atomic_write_unit_min $testfile)
-	awu_max_fs=$(_get_atomic_write_unit_max $testfile)
+	local awu_min_fs=$(_get_atomic_write_unit_min $testfile)
+	local awu_max_fs=$(_get_atomic_write_unit_max $testfile)
 
 	_scratch_unmount
 
Signature · 1 line
2.34.1
Reviewed-by on v1 5/5
#7 lore raw

Re: [PATCH 5/5] common/atomicwrites: fix _require_scratch_write_atomic

Quoted 38 lines · Catherine Hoang

From: "Darrick J. Wong" <[email protected]>

Fix this function to call _notrun whenever something fails. If we can't figure out the atomic write geometry, then we haven't satisfied the preconditions for the test.

---
 common/atomicwrites | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
common/atomicwrites +6 -4
index 9ec1ca68..391bb6f6 100644
@@ -28,21 +28,23 @@ _require_scratch_write_atomic()
 {
 	_require_scratch
 
-	awu_min_bdev=$(_get_atomic_write_unit_min $SCRATCH_DEV)
-	awu_max_bdev=$(_get_atomic_write_unit_max $SCRATCH_DEV)
+	local awu_min_bdev=$(_get_atomic_write_unit_min $SCRATCH_DEV)
+	local 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
+	_scratch_mkfs > /dev/null 2>&1 || \
+		_notrun "cannot format scratch device for atomic write checks"
+	_try_scratch_mount || \
+		_notrun "cannot mount scratch device for atomic write checks"
 

common/atomicwrites _require_scratch_write_atomic() · line 49

Quoted 10 lines
common/atomicwrites +3 -3
-	testfile=$SCRATCH_MNT/testfile
+	local testfile=$SCRATCH_MNT/testfile
 	touch $testfile
 
-	awu_min_fs=$(_get_atomic_write_unit_min $testfile)
-	awu_max_fs=$(_get_atomic_write_unit_max $testfile)
+	local awu_min_fs=$(_get_atomic_write_unit_min $testfile)
+	local awu_max_fs=$(_get_atomic_write_unit_max $testfile)
 
 	_scratch_unmount

Looks good, feel free to add:

Regards,
ojaswin

Quoted 4 lines
Signature · 2 lines
-- 
2.34.1