Skip to contentSkip to conversation

generic/365: Fix false failure when mapping ends with free space

PATCH In review Ojaswin Mujoo 3 participants 5 messages Aug 5, 2025 – Aug 29, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 generic/365: Fix false failure when mapping ends with free space

If we have a small FS where the first free space mapping is also the last mapping of the FS, then the following sub-test fails:

echo "test whatever came after freesp"
$XFS_IO_PROG -c "fsmap -d $((freesp_end + 2)) $((freesp_end + 3))" $SCRATCH_MNT

since there is nothing after the freespace. Fix this by punching a 1M hole in a 3M file to ensure that the first free space is always surrounded by allocated blocks.

---
 tests/generic/365 | 4 ++++
 1 file changed, 4 insertions(+)
tests/generic/365 +4 -0
index 36cb2530..bbadae71 100755
@@ -32,6 +32,10 @@ if ((blksz < 2048)); then
 	_notrun "test requires at least 4 bblocks per fsblock"
 fi
 
+# This makes sure there is free space surrounded by allocated blocks, which
+# is needed for some sub tests.
+$XFS_IO_PROG -fc 'falloc 0 3M' -c 'fpunch 1M 1M' -c 'fsync' $SCRATCH_MNT/f
+
 $XFS_IO_PROG -c 'fsmap' $SCRATCH_MNT >> $seqres.full
 
 find_freesp() {
Signature · 1 line
2.49.0
Tested-by on v1 1/1
#1 lore raw
Quoted 11 lines · Ojaswin Mujoo

If we have a small FS where the first free space mapping is also the last mapping of the FS, then the following sub-test fails:

echo "test whatever came after freesp"
$XFS_IO_PROG -c "fsmap -d $((freesp_end + 2)) $((freesp_end + 3))" $SCRATCH_MNT

since there is nothing after the freespace. Fix this by punching a 1M hole in a 3M file to ensure that the first free space is always surrounded by allocated blocks.

I tested the patch on Power, and it resolves the test failures with a 64k block size.

SECTION       -- ext4_64k
RECREATING    -- ext4 on /dev/loop0
FSTYP         -- ext4
PLATFORM      -- Linux/ppc64le localhost 6.17.0-rc2-00060-g068a56e56fa8 #2 SMP Thu Aug 21 16:28:18 IST 2025
MKFS_OPTIONS  -- -F -b 65536 /dev/loop1

MOUNT_OPTIONS -- -o block_validity /dev/loop1 /mnt/scratch

generic/365 1s ... 1s
Ran: generic/365
Passed all 1 tests

Quoted 19 lines
---
  tests/generic/365 | 4 ++++
  1 file changed, 4 insertions(+)
tests/generic/365 +4 -0
index 36cb2530..bbadae71 100755
@@ -32,6 +32,10 @@ if ((blksz < 2048)); then
  	_notrun "test requires at least 4 bblocks per fsblock"
  fi
 
+# This makes sure there is free space surrounded by allocated blocks, which
+# is needed for some sub tests.
+$XFS_IO_PROG -fc 'falloc 0 3M' -c 'fpunch 1M 1M' -c 'fsync' $SCRATCH_MNT/f
+
  $XFS_IO_PROG -c 'fsmap' $SCRATCH_MNT >> $seqres.full
 
  find_freesp() {
#2 lore raw
In reply to Ojaswin Mujoo
Quoted 20 lines · Ojaswin Mujoo

If we have a small FS where the first free space mapping is also the last mapping of the FS, then the following sub-test fails:

echo "test whatever came after freesp"
$XFS_IO_PROG -c "fsmap -d $((freesp_end + 2)) $((freesp_end + 3))" $SCRATCH_MNT

since there is nothing after the freespace. Fix this by punching a 1M hole in a 3M file to ensure that the first free space is always surrounded by allocated blocks.

---
 tests/generic/365 | 4 ++++
 1 file changed, 4 insertions(+)
tests/generic/365 +0 -0
index 36cb2530..bbadae71 100755

tests/generic/365 if ((blksz < 2048)); then · line 37

Quoted 6 lines
tests/generic/365 +3 -0
@@ -32,6 +32,10 @@ if ((blksz < 2048)); then
 	_notrun "test requires at least 4 bblocks per fsblock"
 fi
 
+# This makes sure there is free space surrounded by allocated blocks, which
+# is needed for some sub tests.
+$XFS_IO_PROG -fc 'falloc 0 3M' -c 'fpunch 1M 1M' -c 'fsync' $SCRATCH_MNT/f

If you add "falloc" and "fpunch" operations, you need to:

_require_xfs_io_command "falloc"
_require_xfs_io_command "fpunch"

Due to not all fileystems support these two fs operations.

BTW, I'm wondering how small (and what kind of) the fs you use, cause there's only one unused region, even this's a clean fs, there're some still many different metadatas. I even tried a 100M ext2 fs (which doesn't has log space), there're many free space regions. So I'm curious, how can you hit this issue? And if the SCRATCH_DEV is too small (e.g. 10M), do we really need to test with that fs size:)

Thanks,
Zorro

Quoted 7 lines
tests/generic/365 +1 -0
+
 $XFS_IO_PROG -c 'fsmap' $SCRATCH_MNT >> $seqres.full
 
 find_freesp() {
Signature · 1 line
2.49.0
#3 lore raw
Quoted 24 lines · Zorro Lang
Quoted 23 lines · Ojaswin Mujoo

If we have a small FS where the first free space mapping is also the last mapping of the FS, then the following sub-test fails:

echo "test whatever came after freesp"
$XFS_IO_PROG -c "fsmap -d $((freesp_end + 2)) $((freesp_end + 3))" $SCRATCH_MNT

since there is nothing after the freespace. Fix this by punching a 1M hole in a 3M file to ensure that the first free space is always surrounded by allocated blocks.

---
 tests/generic/365 | 4 ++++
 1 file changed, 4 insertions(+)
tests/generic/365 +0 -0
index 36cb2530..bbadae71 100755
@@ -32,6 +32,10 @@ if ((blksz < 2048)); then
 	_notrun "test requires at least 4 bblocks per fsblock"
 fi
 
Quoted 8 lines

tests/generic/365 if ((blksz < 2048)); then · line 37

Quoted 3 lines
tests/generic/365 +3 -0
+# This makes sure there is free space surrounded by allocated blocks, which
+# is needed for some sub tests.
+$XFS_IO_PROG -fc 'falloc 0 3M' -c 'fpunch 1M 1M' -c 'fsync' $SCRATCH_MNT/f

If you add "falloc" and "fpunch" operations, you need to:

_require_xfs_io_command "falloc"
_require_xfs_io_command "fpunch"

Hey Zorro thanks for the review and sorry I keep missing this helper :/ I'll fix it.

Quoted 8 lines

Due to not all fileystems support these two fs operations.

BTW, I'm wondering how small (and what kind of) the fs you use, cause there's only one unused region, even this's a clean fs, there're some still many different metadatas. I even tried a 100M ext2 fs (which doesn't has log space), there're many free space regions. So I'm curious, how can you hit this issue? And if the SCRATCH_DEV is too small (e.g. 10M), do we really need to test with that fs size:)

Right so actually we used the standard 5G SCRATCH_DEV however we were testing for 64kb blocksize as well as ext4 bigalloc:

 $ mkfs.ext4 -b 65536 -O bigalloc $SCRATCH_DEV

which can actually format an ext4 FS that can hold 65528 * 64KB = ~40G in a single block group, so we end up with 1 block group where metadata is at the top and free space is in the end.

Adding a small file like above seems like a easy and universal way of getting around this issue.

Regards,
ojaswin

Quoted 13 lines

Thanks,
Zorro

Quoted 7 lines
tests/generic/365 +1 -0
+
 $XFS_IO_PROG -c 'fsmap' $SCRATCH_MNT >> $seqres.full
 
 find_freesp() {
Signature · 1 line
2.49.0
Reviewed-by
#4 lore raw
Quoted 49 lines · Ojaswin Mujoo
Quoted 24 lines · Zorro Lang
Quoted 23 lines · Ojaswin Mujoo

If we have a small FS where the first free space mapping is also the last mapping of the FS, then the following sub-test fails:

echo "test whatever came after freesp"
$XFS_IO_PROG -c "fsmap -d $((freesp_end + 2)) $((freesp_end + 3))" $SCRATCH_MNT

since there is nothing after the freespace. Fix this by punching a 1M hole in a 3M file to ensure that the first free space is always surrounded by allocated blocks.

---
 tests/generic/365 | 4 ++++
 1 file changed, 4 insertions(+)
tests/generic/365 +0 -0
index 36cb2530..bbadae71 100755
@@ -32,6 +32,10 @@ if ((blksz < 2048)); then
 	_notrun "test requires at least 4 bblocks per fsblock"
 fi
 
Quoted 8 lines

tests/generic/365 if ((blksz < 2048)); then · line 37

Quoted 3 lines
tests/generic/365 +3 -0
+# This makes sure there is free space surrounded by allocated blocks, which
+# is needed for some sub tests.
+$XFS_IO_PROG -fc 'falloc 0 3M' -c 'fpunch 1M 1M' -c 'fsync' $SCRATCH_MNT/f

If you add "falloc" and "fpunch" operations, you need to:

_require_xfs_io_command "falloc"
_require_xfs_io_command "fpunch"

Hey Zorro thanks for the review and sorry I keep missing this helper :/ I'll fix it.

Quoted 8 lines

Due to not all fileystems support these two fs operations.

BTW, I'm wondering how small (and what kind of) the fs you use, cause there's only one unused region, even this's a clean fs, there're some still many different metadatas. I even tried a 100M ext2 fs (which doesn't has log space), there're many free space regions. So I'm curious, how can you hit this issue? And if the SCRATCH_DEV is too small (e.g. 10M), do we really need to test with that fs size:)

Right so actually we used the standard 5G SCRATCH_DEV however we were testing for 64kb blocksize as well as ext4 bigalloc:

Quoted 8 lines
 $ mkfs.ext4 -b 65536 -O bigalloc $SCRATCH_DEV

which can actually format an ext4 FS that can hold 65528 * 64KB = ~40G in a single block group, so we end up with 1 block group where metadata is at the top and free space is in the end.

Adding a small file like above seems like a easy and universal way of getting around this issue.

Thanks Ojaswin, if so I think we can accept this change :)

Quoted 18 lines

Regards,
ojaswin

Quoted 13 lines

Thanks,
Zorro

Quoted 7 lines
tests/generic/365 +1 -0
+
 $XFS_IO_PROG -c 'fsmap' $SCRATCH_MNT >> $seqres.full
 
 find_freesp() {
Signature · 1 line
2.49.0