public inbox for fstests@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] fstests: btrfs: add a regression test for incorrect inode incompressible flag
@ 2026-02-09  9:57 Qu Wenruo
  2026-02-12 18:40 ` Zorro Lang
  0 siblings, 1 reply; 4+ messages in thread
From: Qu Wenruo @ 2026-02-09  9:57 UTC (permalink / raw)
  To: linux-btrfs, fstests; +Cc: Filipe Manana

[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.

[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

Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
Changelog:
v2:
- Remove an unnessary sentence
  Which is confusing because I missed the "and" to connect the two
  sentences, and it's not needed after the first paragraph anyway.

- Use full "btrfs inspect-internal" group name instead

- Add missing punctures

v3:
- Properly commit the modification
  Facepalm
---
 tests/btrfs/343     | 48 +++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/343.out |  2 ++
 2 files changed, 50 insertions(+)
 create mode 100755 tests/btrfs/343
 create mode 100644 tests/btrfs/343.out

diff --git a/tests/btrfs/343 b/tests/btrfs/343
new file mode 100755
index 00000000..3781373c
--- /dev/null
+++ b/tests/btrfs/343
@@ -0,0 +1,48 @@
+#! /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
+_require_btrfs_command inspect-internal dump-tree
+
+_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-internal dump-tree -t 5 $SCRATCH_DEV >> $seqres.full
+
+# Check the NOCOMPRESS flag of the inode.
+$BTRFS_UTIL_PROG inspect-internal 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-internal 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
diff --git a/tests/btrfs/343.out b/tests/btrfs/343.out
new file mode 100644
index 00000000..2eb30e4f
--- /dev/null
+++ b/tests/btrfs/343.out
@@ -0,0 +1,2 @@
+QA output created by 343
+Silence is golden
-- 
2.51.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v3] fstests: btrfs: add a regression test for incorrect inode incompressible flag
  2026-02-09  9:57 [PATCH v3] fstests: btrfs: add a regression test for incorrect inode incompressible flag Qu Wenruo
@ 2026-02-12 18:40 ` Zorro Lang
  2026-02-12 20:54   ` Qu Wenruo
  0 siblings, 1 reply; 4+ messages in thread
From: Zorro Lang @ 2026-02-12 18:40 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: linux-btrfs, fstests, Filipe Manana

On Mon, Feb 09, 2026 at 08:27:35PM +1030, Qu Wenruo wrote:
> [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.
> 
> [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
> 
> Reviewed-by: Filipe Manana <fdmanana@suse.com>
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
> Changelog:
> v2:
> - Remove an unnessary sentence
>   Which is confusing because I missed the "and" to connect the two
>   sentences, and it's not needed after the first paragraph anyway.
> 
> - Use full "btrfs inspect-internal" group name instead
> 
> - Add missing punctures
> 
> v3:
> - Properly commit the modification
>   Facepalm
> ---
>  tests/btrfs/343     | 48 +++++++++++++++++++++++++++++++++++++++++++++
>  tests/btrfs/343.out |  2 ++
>  2 files changed, 50 insertions(+)
>  create mode 100755 tests/btrfs/343
>  create mode 100644 tests/btrfs/343.out
> 
> diff --git a/tests/btrfs/343 b/tests/btrfs/343
> new file mode 100755
> index 00000000..3781373c
> --- /dev/null
> +++ b/tests/btrfs/343
> @@ -0,0 +1,48 @@
> +#! /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
> +_require_btrfs_command inspect-internal dump-tree
> +
> +_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)

Do you mind I replace _get_block_size with _get_file_block_size when I merge it?
Even though btrfs currently doesn't require special handling to get the correct block
size, using this interface is more future-proof. It will help us to easily add specific
logic later if btrfs ever needs it. Others are good to me,

Reviewed-by: Zorro Lang <zlang@redhat.com>

> +
> +# 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-internal dump-tree -t 5 $SCRATCH_DEV >> $seqres.full
> +
> +# Check the NOCOMPRESS flag of the inode.
> +$BTRFS_UTIL_PROG inspect-internal 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-internal 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
> diff --git a/tests/btrfs/343.out b/tests/btrfs/343.out
> new file mode 100644
> index 00000000..2eb30e4f
> --- /dev/null
> +++ b/tests/btrfs/343.out
> @@ -0,0 +1,2 @@
> +QA output created by 343
> +Silence is golden
> -- 
> 2.51.2
> 
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v3] fstests: btrfs: add a regression test for incorrect inode incompressible flag
  2026-02-12 18:40 ` Zorro Lang
@ 2026-02-12 20:54   ` Qu Wenruo
  2026-02-13 20:14     ` Zorro Lang
  0 siblings, 1 reply; 4+ messages in thread
From: Qu Wenruo @ 2026-02-12 20:54 UTC (permalink / raw)
  To: Zorro Lang, Qu Wenruo; +Cc: linux-btrfs, fstests, Filipe Manana



在 2026/2/13 05:10, Zorro Lang 写道:
[...]
>> +
>> +blocksize=$(_get_block_size $SCRATCH_MNT)
> 
> Do you mind I replace _get_block_size with _get_file_block_size when I merge it?

Sure, and I'll try to remember to use that newer helper in the future.

And if needed, I can replace the existing callsites with the newer 
helper in a dedicated patch.

Thanks,
Qu

> Even though btrfs currently doesn't require special handling to get the correct block
> size, using this interface is more future-proof. It will help us to easily add specific
> logic later if btrfs ever needs it. Others are good to me,
> 
> Reviewed-by: Zorro Lang <zlang@redhat.com>
> 
>> +
>> +# 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-internal dump-tree -t 5 $SCRATCH_DEV >> $seqres.full
>> +
>> +# Check the NOCOMPRESS flag of the inode.
>> +$BTRFS_UTIL_PROG inspect-internal 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-internal 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
>> diff --git a/tests/btrfs/343.out b/tests/btrfs/343.out
>> new file mode 100644
>> index 00000000..2eb30e4f
>> --- /dev/null
>> +++ b/tests/btrfs/343.out
>> @@ -0,0 +1,2 @@
>> +QA output created by 343
>> +Silence is golden
>> -- 
>> 2.51.2
>>
>>
> 
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v3] fstests: btrfs: add a regression test for incorrect inode incompressible flag
  2026-02-12 20:54   ` Qu Wenruo
@ 2026-02-13 20:14     ` Zorro Lang
  0 siblings, 0 replies; 4+ messages in thread
From: Zorro Lang @ 2026-02-13 20:14 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: Qu Wenruo, linux-btrfs, fstests, Filipe Manana

On Fri, Feb 13, 2026 at 07:24:17AM +1030, Qu Wenruo wrote:
> 
> 
> 在 2026/2/13 05:10, Zorro Lang 写道:
> [...]
> > > +
> > > +blocksize=$(_get_block_size $SCRATCH_MNT)
> > 
> > Do you mind I replace _get_block_size with _get_file_block_size when I merge it?
> 
> Sure, and I'll try to remember to use that newer helper in the future.
> 
> And if needed, I can replace the existing callsites with the newer helper in
> a dedicated patch.

Don't worry, since some cases might genuinely need the bare _get_block_size, so I
didn't do a blanket replacement, just keep an eye on it during code reviewing :)
Anyway, I'll review this patch at first.

Thanks,
Zorro

> 
> Thanks,
> Qu
> 
> > Even though btrfs currently doesn't require special handling to get the correct block
> > size, using this interface is more future-proof. It will help us to easily add specific
> > logic later if btrfs ever needs it. Others are good to me,
> > 
> > Reviewed-by: Zorro Lang <zlang@redhat.com>
> > 
> > > +
> > > +# 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-internal dump-tree -t 5 $SCRATCH_DEV >> $seqres.full
> > > +
> > > +# Check the NOCOMPRESS flag of the inode.
> > > +$BTRFS_UTIL_PROG inspect-internal 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-internal 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
> > > diff --git a/tests/btrfs/343.out b/tests/btrfs/343.out
> > > new file mode 100644
> > > index 00000000..2eb30e4f
> > > --- /dev/null
> > > +++ b/tests/btrfs/343.out
> > > @@ -0,0 +1,2 @@
> > > +QA output created by 343
> > > +Silence is golden
> > > -- 
> > > 2.51.2
> > > 
> > > 
> > 
> > 
> 
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-02-13 20:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-09  9:57 [PATCH v3] fstests: btrfs: add a regression test for incorrect inode incompressible flag Qu Wenruo
2026-02-12 18:40 ` Zorro Lang
2026-02-12 20:54   ` Qu Wenruo
2026-02-13 20:14     ` Zorro Lang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox