Skip to contentSkip to conversation

tests: _fail on _scratch_mkfs_sized failure

PATCH Superseded David Disseldorp 2 participants 2 messages Apr 29, 2024

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 tests: _fail on _scratch_mkfs_sized failure

If _scratch_mkfs_sized() fails, e.g. due to an FS not supporting the provided size, tests may subsequently mount and run atop a previously created (e.g. non-size-bound) filesystem.
This can lead to difficult to debug failures, or for some -ENOSPC exercising tests, near infinite runtimes. Avoid this by renaming the current function to _try_scratch_mkfs_sized() and _fail in the parent _scratch_mkfs_sized() wrapper.

---
Changes since v1:
- call _fail in a wrapper function, instead of adding failure handlers to individual test _scratch_mkfs_sized() callers.

 common/rc | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
common/rc +7 -2
index 56f1afb6..e95070dd 100644
@@ -968,8 +968,8 @@ _small_fs_size_mb()
 }
 
 # Create fs of certain size on scratch device
-# _scratch_mkfs_sized <size in bytes> [optional blocksize]
-_scratch_mkfs_sized()
+# _try_scratch_mkfs_sized <size in bytes> [optional blocksize]
+_try_scratch_mkfs_sized()
 {
 	local fssize=$1
 	local blocksize=$2
@@ -1111,6 +1111,11 @@ _scratch_mkfs_sized()
 	esac
 }
 
+_scratch_mkfs_sized()
+{
+	_try_scratch_mkfs_sized $* || _fail "_scratch_mkfs_sized failed"
+}
+
 # Emulate an N-data-disk stripe w/ various stripe units
 # _scratch_mkfs_geom <sunit bytes> <swidth multiplier> [optional blocksize]
 _scratch_mkfs_geom()
Signature · 1 line
2.35.3
#1 lore raw
Quoted 8 lines · David Disseldorp

If _scratch_mkfs_sized() fails, e.g. due to an FS not supporting the provided size, tests may subsequently mount and run atop a previously created (e.g. non-size-bound) filesystem.
This can lead to difficult to debug failures, or for some -ENOSPC exercising tests, near infinite runtimes. Avoid this by renaming the current function to _try_scratch_mkfs_sized() and _fail in the parent _scratch_mkfs_sized() wrapper.

Quoted 6 lines

---
Changes since v1:
- call _fail in a wrapper function, instead of adding failure handlers to individual test _scratch_mkfs_sized() callers.

As we call _fail in _scratch_mkfs_sized, so don't need to do _fail after mkfs fails :

$ grep -rsn -A 1 _scratch_mkfs_sized tests/|grep -E "_fail "
tests/btrfs/007-47-             || _fail "size=$fsz mkfs failed"
tests/btrfs/007-74-             || _fail "size=$fsz mkfs failed"
tests/btrfs/004-161-            || _fail "size=$fsz mkfs failed"
tests/ext4/021:27:_scratch_mkfs_sized $fssize >> $seqres.full 2>&1 || _fail "mkfs failed"
tests/ext4/059-26-      >>$seqres.full 2>&1 || _fail "mkfs failed"
tests/generic/449-28-_scratch_mount || _fail "mount failed"
tests/generic/171:45:_scratch_mkfs_sized $sz_bytes >> $seqres.full 2>&1 || _fail "mkfs failed"
tests/generic/172:43:_scratch_mkfs_sized $fs_size >> $seqres.full 2>&1 || _fail "mkfs failed"
tests/generic/173:45:_scratch_mkfs_sized $sz_bytes >> $seqres.full 2>&1 || _fail "mkfs failed"
tests/generic/174:46:_scratch_mkfs_sized $sz_bytes >> $seqres.full 2>&1 || _fail "mkfs failed"
tests/generic/735:28:_scratch_mkfs_sized $dev_size >>$seqres.full 2>&1 || _fail "mkfs failed"
tests/generic/015-35-    || _fail "mkfs failed"
tests/generic/077:53:_scratch_mkfs_sized $fs_size >> $seqres.full 2>&1 || _fail "mkfs failed"
tests/generic/083-54-                   || _fail "size=$fsz mkfs failed"
tests/xfs/057-55-               _fail "mkfs failed"
tests/xfs/015:46:_scratch_mkfs_sized $((96 * 1024 * 1024)) > $tmp.mkfs.raw || _fail "mkfs failed"
Quoted 20 lines
 common/rc | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
common/rc +2 -2
index 56f1afb6..e95070dd 100644
@@ -968,8 +968,8 @@ _small_fs_size_mb()
 }
 
 # Create fs of certain size on scratch device
-# _scratch_mkfs_sized <size in bytes> [optional blocksize]
-_scratch_mkfs_sized()
+# _try_scratch_mkfs_sized <size in bytes> [optional blocksize]
+_try_scratch_mkfs_sized()
 {
 	local fssize=$1
 	local blocksize=$2

common/rc _scratch_mkfs_sized() · line 1116

Quoted 6 lines
common/rc +3 -0
@@ -1111,6 +1111,11 @@ _scratch_mkfs_sized()
 	esac
 }
 
+_scratch_mkfs_sized()
+{
+	_try_scratch_mkfs_sized $* || _fail "_scratch_mkfs_sized failed"

How about printing the "size" arguments?

Quoted 9 lines
common/rc +2 -0
+}
+
 # Emulate an N-data-disk stripe w/ various stripe units
 # _scratch_mkfs_geom <sunit bytes> <swidth multiplier> [optional blocksize]
 _scratch_mkfs_geom()
Signature · 1 line
2.35.3