Skip to contentSkip to conversation

xfs: add a test for atomic writes

PATCH Superseded Catherine Hoang 2 participants 2 messages Dec 12, 2024

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH 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     | 48 +++++++++++++++++++++++++++++++++++++++++++++++
 tests/xfs/611.out | 17 +++++++++++++++++
 3 files changed, 79 insertions(+)
 create mode 100755 tests/xfs/611
 create mode 100644 tests/xfs/611.out
common/rc +14 -0
index 2ee46e51..b9da749e 100644
@@ -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 +48 -0

48 lines not on this page · raw message

tests/xfs/611.out new file +17 -0
new file mode 100644
index 00000000..ea28b971
@@ -0,0 +1,17 @@
+QA output created by 611
+
+Block size: 4096
+stat.atomic_write_unit_min = 4096
+stat.atomic_write_unit_max = 4096
+stat.atomic_write_segments_max = 1
+wrote 4096/4096 bytes at offset 0
+pwrite: Invalid argument
+pwrite: Invalid argument
+
+Block size: 16384
+stat.atomic_write_unit_min = 16384
+stat.atomic_write_unit_max = 16384
+stat.atomic_write_segments_max = 1
+wrote 16384/16384 bytes at offset 0
+pwrite: Invalid argument
+pwrite: Invalid argument
Signature · 1 line
2.34.1
#1 lore raw
Quoted 50 lines · Catherine Hoang

Add a test to validate the new atomic writes feature.

---
 common/rc         | 14 ++++++++++++++
 tests/xfs/611     | 48 +++++++++++++++++++++++++++++++++++++++++++++++
 tests/xfs/611.out | 17 +++++++++++++++++
 3 files changed, 79 insertions(+)
 create mode 100755 tests/xfs/611
 create mode 100644 tests/xfs/611.out
common/rc +14 -0
index 2ee46e51..b9da749e 100644
@@ -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 +8 -0
new file mode 100755
index 00000000..d193de86
@@ -0,0 +1,48 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2024 Oracle.  All Rights Reserved.
+#
+# FS QA Test 611
+#
+# Validate atomic write support
+#

tests/xfs/611 line 18

Quoted 10 lines
tests/xfs/611 new file +10 -0
+. ./common/preamble
+_begin_fstest auto quick rw
+
+_supported_fs xfs
+_require_scratch
+_require_scratch_write_atomic
+
+test_atomic_writes()
+{
+    bsize=$1

local bsize=$1

(don't pollute the global namespace)

tests/xfs/611 line 24

Quoted 6 lines
tests/xfs/611 new file +6 -0
+
+    echo ""
+    echo "Block size: $bsize"
+
+    _scratch_mkfs_xfs -b size=$bsize >> $seqres.full
+    _scratch_mount

You probably want:
_xfs_force_bdev data $SCRATCH_MNT

to force the data/rt status of $testfile to match whichever block device supports untorn writes.

Quoted 4 lines
tests/xfs/611 new file +4 -0
+
+    testfile=$SCRATCH_MNT/testfile
+    touch $testfile
+

tests/xfs/611 line 38

Quoted 10 lines
tests/xfs/611 new file +10 -0
+    # Check that atomic min/max = FS block size
+    $XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $testfile \
+        | grep atomic
+
+    # Check that we can perform an atomic write of len = FS block size
+    $XFS_IO_PROG -dc "pwrite -A -D 0 $bsize" $testfile | grep wrote
+
+    # Reject atomic write if len is out of bounds
+    $XFS_IO_PROG -dc "pwrite -A -D 0 $((bsize - 1))" $testfile
+    $XFS_IO_PROG -dc "pwrite -A -D 0 $((bsize + 1))" $testfile

Can you also check that untorn writes to an unwritten block and a sparse hole also work?

tests/xfs/611 line 44

Quoted 5 lines
tests/xfs/611 new file +5 -0
+    _scratch_unmount
+}
+
+test_atomic_writes 4096
+test_atomic_writes 16384

Shouldn't this be testing every fsblock size between the untorn write unit min and max of the underlying block device?

--D

Quoted 30 lines
tests/xfs/611 new file +3 -0
+# success, all done
+status=0
+exit
tests/xfs/611.out new file +17 -0
new file mode 100644
index 00000000..ea28b971
@@ -0,0 +1,17 @@
+QA output created by 611
+
+Block size: 4096
+stat.atomic_write_unit_min = 4096
+stat.atomic_write_unit_max = 4096
+stat.atomic_write_segments_max = 1
+wrote 4096/4096 bytes at offset 0
+pwrite: Invalid argument
+pwrite: Invalid argument
+
+Block size: 16384
+stat.atomic_write_unit_min = 16384
+stat.atomic_write_unit_max = 16384
+stat.atomic_write_segments_max = 1
+wrote 16384/16384 bytes at offset 0
+pwrite: Invalid argument
+pwrite: Invalid argument
Signature · 1 line
2.34.1