Skip to contentSkip to conversation

fstests: btrfs: add a regression test for incorrect inode incompressible flag

PATCH Superseded Qu Wenruo 2 participants 2 messages Feb 9 Btrfs file system

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Qu Wenruo

author
#0 lore raw

PATCH 1/1 fstests: btrfs: add a regression test for incorrect inode incompressible flag

[BUG]
Since kernel commit 59615e2c1f63 ("btrfs: reject single block sized compression early"), a single block write at file offset 0, which can not be inlined due the inode size, will mark the inode incompressible.

This is not the expected behavior is caused by that commit.

[REGRESSION TEST]
The new regression test will do:

- Create and mount the fs with compression,max_inline=2k

- Do the following operations:
* Truncate the inode to 2 * blocksize
This will rule out any future inlined writes.

* Buffered write [0, 2K)
Which will not be inlined.

* Sync
For affected kernels, this will set the inode with NOCOMPRESS and reject all future compression on that inode.

* Buffered write [1M, 2M)
For affected kernels, the range will not be compressed due to the NOCOMPRESS flag.

- Unmount the fs

- Make sure that:
* The inode has no NOCOMPRESS flag
* File extent at file offset 1M is being compressed

---
 tests/btrfs/343     | 47 +++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/343.out |  2 ++
 2 files changed, 49 insertions(+)
 create mode 100755 tests/btrfs/343
 create mode 100644 tests/btrfs/343.out
tests/btrfs/343 new file +47 -0
new file mode 100755
index 00000000..78079eff
@@ -0,0 +1,47 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 SUSE S.A.  All Rights Reserved.
+#
+# FS QA Test 343
+#
+# A regression test to make sure a single-block write at file offset 0 won't
+# incorrectly mark the inode incompressible.
+#
+. ./common/preamble
+_begin_fstest auto quick compress
+
+_require_scratch
+
+_fixed_by_kernel_commit xxxxxxxxxxxx \
+	"btrfs: fix the inline compressed extent check in inode_need_compress()"
+
+_scratch_mkfs >>$seqres.full 2>&1
+_scratch_mount "-o compress,max_inline=2048"
+
+blocksize=$(_get_block_size $SCRATCH_MNT)
+
+# Create a sparse file which is 2 * blocksize, then try a small write at
+# file offset 0 which should not be inlined.
+# Sync so that [0, 2K) range is written, then write a larger range which
+# should be able to be compressed.
+$XFS_IO_PROG -f -c "truncate $((2 * $blocksize))" -c "pwrite 0 2k" -c sync \
+		-c "pwrite 1m 1m" $SCRATCH_MNT/foobar >> $seqres.full
+ino=$(stat -c "%i" $SCRATCH_MNT/foobar)
+_scratch_unmount
+
+# Dump the fstree into seqres.full for debug
+$BTRFS_UTIL_PROG inspect dump-tree -t 5 $SCRATCH_DEV >> $seqres.full
+
+# Check the NOCOMPRESS flag of the inode.
+$BTRFS_UTIL_PROG inspect dump-tree -t 5 $SCRATCH_DEV |\
+grep -A 4 -e "item .* key ($ino INODE_ITEM 0)" | grep -q NOCOMPRESS
+[ $? -eq 0 ] && echo "inode $ino has NOCOMPRESS flag"
+
+# Check the file extent at fileoffset 1m
+$BTRFS_UTIL_PROG inspect dump-tree -t 5 $SCRATCH_DEV |\
+grep -A 4 -e "item .* key ($ino EXTENT_DATA 1048576)" | grep -q "compression 0"
+[ $? -eq 0 ] && echo "inode $ino file offset 1M is not compressed"
+
+echo "Silence is golden"
+# success, all done
+_exit 0
tests/btrfs/343.out new file +2 -0
new file mode 100644
index 00000000..2eb30e4f
@@ -0,0 +1,2 @@
+QA output created by 343
+Silence is golden
Signature · 1 line
2.51.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Qu Wenruo

[BUG]
Since kernel commit 59615e2c1f63 ("btrfs: reject single block sized compression early"), a single block write at file offset 0, which can not be inlined due the inode size, will mark the inode incompressible.

This is not the expected behavior is caused by that commit.

Something odd with this sentence.
But given the previous paragraph, it's not needed.

Quoted 63 lines

[REGRESSION TEST]
The new regression test will do:

- Create and mount the fs with compression,max_inline=2k

- Do the following operations:
* Truncate the inode to 2 * blocksize
This will rule out any future inlined writes.

* Buffered write [0, 2K)
Which will not be inlined.

* Sync
For affected kernels, this will set the inode with NOCOMPRESS and reject all future compression on that inode.

* Buffered write [1M, 2M)
For affected kernels, the range will not be compressed due to the NOCOMPRESS flag.

- Unmount the fs

- Make sure that:
* The inode has no NOCOMPRESS flag
* File extent at file offset 1M is being compressed

---
 tests/btrfs/343     | 47 +++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/343.out |  2 ++
 2 files changed, 49 insertions(+)
 create mode 100755 tests/btrfs/343
 create mode 100644 tests/btrfs/343.out
tests/btrfs/343 new file +22 -0
new file mode 100755
index 00000000..78079eff
@@ -0,0 +1,47 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 SUSE S.A.  All Rights Reserved.
+#
+# FS QA Test 343
+#
+# A regression test to make sure a single-block write at file offset 0 won't
+# incorrectly mark the inode incompressible.
+#
+. ./common/preamble
+_begin_fstest auto quick compress
+
+_require_scratch
+
+_fixed_by_kernel_commit xxxxxxxxxxxx \
+       "btrfs: fix the inline compressed extent check in inode_need_compress()"
+
+_scratch_mkfs >>$seqres.full 2>&1
+_scratch_mount "-o compress,max_inline=2048"
+
+blocksize=$(_get_block_size $SCRATCH_MNT)
+

tests/btrfs/343 line 32

Quoted 10 lines
tests/btrfs/343 new file +10 -0
+# Create a sparse file which is 2 * blocksize, then try a small write at
+# file offset 0 which should not be inlined.
+# Sync so that [0, 2K) range is written, then write a larger range which
+# should be able to be compressed.
+$XFS_IO_PROG -f -c "truncate $((2 * $blocksize))" -c "pwrite 0 2k" -c sync \
+               -c "pwrite 1m 1m" $SCRATCH_MNT/foobar >> $seqres.full
+ino=$(stat -c "%i" $SCRATCH_MNT/foobar)
+_scratch_unmount
+
+# Dump the fstree into seqres.full for debug

Please end the sentence with punctuation - some of the other comments end with punctuation, others don't.

tests/btrfs/343 line 33

Quoted 1 line
tests/btrfs/343 new file +1 -0
+$BTRFS_UTIL_PROG inspect dump-tree -t 5 $SCRATCH_DEV >> $seqres.full

Please use the full command name "inspect-internal". Also missing at the top:

_require_btrfs_command inspect-internal dump-tree

tests/btrfs/343 line 35

Quoted 2 lines
tests/btrfs/343 new file +2 -0
+
+# Check the NOCOMPRESS flag of the inode.

Here there is punctuation.

tests/btrfs/343 line 36

Quoted 1 line
tests/btrfs/343 new file +1 -0
+$BTRFS_UTIL_PROG inspect dump-tree -t 5 $SCRATCH_DEV |\

inspect-internal

tests/btrfs/343 line 40

Quoted 4 lines
tests/btrfs/343 new file +4 -0
+grep -A 4 -e "item .* key ($ino INODE_ITEM 0)" | grep -q NOCOMPRESS
+[ $? -eq 0 ] && echo "inode $ino has NOCOMPRESS flag"
+
+# Check the file extent at fileoffset 1m

Here, punctuation is missing again.

tests/btrfs/343 line 41

Quoted 1 line
tests/btrfs/343 new file +1 -0
+$BTRFS_UTIL_PROG inspect dump-tree -t 5 $SCRATCH_DEV |\

inspect-internal

With those minor fixes:

Thanks.

Quoted 18 lines
tests/btrfs/343 new file +6 -0
+grep -A 4 -e "item .* key ($ino EXTENT_DATA 1048576)" | grep -q "compression 0"
+[ $? -eq 0 ] && echo "inode $ino file offset 1M is not compressed"
+
+echo "Silence is golden"
+# success, all done
+_exit 0
tests/btrfs/343.out new file +2 -1
new file mode 100644
index 00000000..2eb30e4f
@@ -0,0 +1,2 @@
+QA output created by 343
+Silence is golden
--

2.51.2