Linux Btrfs filesystem development
 help / color / mirror / Atom feed
* [PATCH v2 1/2] common/dmlogwrites: add _require_log_writes_sized helper
@ 2026-04-27 12:25 Disha Goel
  2026-04-27 12:25 ` [PATCH v2 2/2] btrfs/291: fix state transition logic and add size requirement Disha Goel
  2026-05-04 21:53 ` [PATCH v2 1/2] common/dmlogwrites: add _require_log_writes_sized helper Anand Jain
  0 siblings, 2 replies; 7+ messages in thread
From: Disha Goel @ 2026-04-27 12:25 UTC (permalink / raw)
  To: fstests
  Cc: linux-btrfs, ritesh.list, ojaswin, djwong, fdmanana,
	quwenruo.btrfs, zlang, anajain.sg, Disha Goel

Add a new helper function _require_log_writes_sized() to check if the
LOGWRITES_DEV meets a minimum size requirement.

This is useful for tests that use dm-log-writes with additional space
requirements, such as creating LVM snapshots during log replay or tests
that generate large amounts of logged I/O operations.

The function takes a size parameter in KB, calls _require_log_writes()
internally, and skips the test if LOGWRITES_DEV is smaller than the
required size.

v2:
- Renamed function from _require_logwrites_size to _require_log_writes_sized
- Added documentation comment clarifying the parameter is in KB
- Made function call _require_log_writes() internally to avoid redundant
  calls in test code

Suggested-by: Darrick J. Wong <djwong@kernel.org>
Suggested-by: Anand Jain <anajain.sg@gmail.com>
Signed-off-by: Disha Goel <disgoel@linux.ibm.com>
---
 common/dmlogwrites | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/common/dmlogwrites b/common/dmlogwrites
index a27e1966..0925b333 100644
--- a/common/dmlogwrites
+++ b/common/dmlogwrites
@@ -14,6 +14,21 @@ _require_log_writes()
 	_require_test_program "log-writes/replay-log"
 }
 
+# Require a log writes device of a minimum size
+# $1: minimum size in KB
+_require_log_writes_sized()
+{
+        local size=$1
+
+        [ $# -eq 1 ] || _fail "_require_log_writes_sized: expected size param"
+
+        _require_log_writes
+
+        local devsize=$(_get_device_size $LOGWRITES_DEV)
+        [ $devsize -lt $1 ] && \
+                _notrun "LOGWRITES_DEV too small, ${devsize}KB < ${size}KB"
+}
+
 # Starting from v4.15-rc1, DAX support was added to dm-log-writes, but note
 # that it doesn't track the data that we write via the mmap(), so we can't do
 # any data integrity checking. We can only verify that the metadata writes for
-- 
2.45.1


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

* [PATCH v2 2/2] btrfs/291: fix state transition logic and add size requirement
  2026-04-27 12:25 [PATCH v2 1/2] common/dmlogwrites: add _require_log_writes_sized helper Disha Goel
@ 2026-04-27 12:25 ` Disha Goel
  2026-05-05  2:46   ` Anand Jain
  2026-05-04 21:53 ` [PATCH v2 1/2] common/dmlogwrites: add _require_log_writes_sized helper Anand Jain
  1 sibling, 1 reply; 7+ messages in thread
From: Disha Goel @ 2026-04-27 12:25 UTC (permalink / raw)
  To: fstests
  Cc: linux-btrfs, ritesh.list, ojaswin, djwong, fdmanana,
	quwenruo.btrfs, zlang, anajain.sg, Disha Goel

This patch fixes two issues in btrfs/291:

1. Add minimum 9GB LOGWRITES_DEV size requirement
   The test creates LVM snapshots at each FUA point during replay,
   requiring significant space. Use _require_log_writes_sized to
   ensure sufficient space is available before running the test.

2. Fix state transition logic for verity enablement
   The original test assumed orphan items would always be created
   during verity enablement (state 0->1 transition). However, in
   some cases verity completes without creating orphan items,
   causing the test to fail with "expected to reach verity done state".

   Fix by transitioning to state 1 when either orphan items exist
   OR merkle items appear, handling both verity enablement paths.
   Also improve state 1 validation to only check for cleared merkle
   items when measurement actually fails.

The test now correctly handles verity enablement with or without
orphan items while maintaining crash consistency validation.

v2:
- Use _require_log_writes_sized instead of separate _require_log_writes
  and _require_logwrites_size calls

Signed-off-by: Disha Goel <disgoel@linux.ibm.com>
---
 tests/btrfs/291 | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/tests/btrfs/291 b/tests/btrfs/291
index 122aeaa5..ac1d192d 100755
--- a/tests/btrfs/291
+++ b/tests/btrfs/291
@@ -36,7 +36,7 @@ _cleanup()
 _require_scratch
 _require_test
 _require_loop
-_require_log_writes
+_require_log_writes_sized $((9 * 1024 * 1024))
 _require_dm_target snapshot
 _require_command $LVM_PROG lvm
 _require_scratch_verity
@@ -129,9 +129,14 @@ do
 	_udev_wait /dev/mapper/$vgname-$snapname
 
 	orphan=$(count_item $snap_dev ORPHAN)
-	[ $state -eq 0 ] && [ $orphan -gt 0 ] && state=1
-
 	pre_mount=$(count_merkle_items $snap_dev)
+
+	if [ $state -eq 0 ]; then
+		if [ $orphan -gt 0 ] || [ $pre_mount -gt 0 ]; then
+			state=1
+		fi
+	fi
+
 	_mount $snap_dev $SCRATCH_MNT || _fail "mount failed at entry $cur"
 	fsverity measure $SCRATCH_MNT/fsv >>$seqres.full 2>&1
 	measured=$?
@@ -143,8 +148,10 @@ do
 	echo "entry: $cur, state: $state, orphan: $orphan, pre_mount: $pre_mount, post_mount: $post_mount" >> $seqres.full
 
 	if [ $state -eq 1 ]; then
-		[ $post_mount -eq 0 ] || \
-			_fail "mount failed to clear under-construction merkle items pre: $pre_mount, post: $post_mount at entry $cur";
+		if [ $measured -ne 0 ]; then
+			[ $post_mount -eq 0 ] || \
+				_fail "mount failed to clear under-construction merkle items pre: $pre_mount, post: $post_mount at entry $cur";
+		fi
 	fi
 	if [ $state -eq 2 ]; then
 		[ $pre_mount -gt 0 ] || \
-- 
2.45.1


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

* Re: [PATCH v2 1/2] common/dmlogwrites: add _require_log_writes_sized helper
  2026-04-27 12:25 [PATCH v2 1/2] common/dmlogwrites: add _require_log_writes_sized helper Disha Goel
  2026-04-27 12:25 ` [PATCH v2 2/2] btrfs/291: fix state transition logic and add size requirement Disha Goel
@ 2026-05-04 21:53 ` Anand Jain
  2026-05-04 23:16   ` Anand Jain
  1 sibling, 1 reply; 7+ messages in thread
From: Anand Jain @ 2026-05-04 21:53 UTC (permalink / raw)
  To: Disha Goel, fstests
  Cc: linux-btrfs, ritesh.list, ojaswin, djwong, fdmanana,
	quwenruo.btrfs, zlang


looks good.

Reviewed-by: Anand Jain <asj@kernel.org>

Thanks


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

* Re: [PATCH v2 1/2] common/dmlogwrites: add _require_log_writes_sized helper
  2026-05-04 21:53 ` [PATCH v2 1/2] common/dmlogwrites: add _require_log_writes_sized helper Anand Jain
@ 2026-05-04 23:16   ` Anand Jain
  2026-05-04 23:43     ` Anand Jain
  0 siblings, 1 reply; 7+ messages in thread
From: Anand Jain @ 2026-05-04 23:16 UTC (permalink / raw)
  To: Disha Goel, fstests
  Cc: linux-btrfs, ritesh.list, ojaswin, djwong, fdmanana,
	quwenruo.btrfs, zlang



On 5/5/26 05:53, Anand Jain wrote:
> 
> looks good.
> 
> Reviewed-by: Anand Jain <asj@kernel.org>
> 
> Thanks
> 

sorry, not yet; I'm canceling the RVB.
Details below.


> v2:
> - Renamed function from _require_logwrites_size to
_require_log_writes_sized
> - Added documentation comment clarifying the parameter is in KB
> - Made function call _require_log_writes() internally to avoid redundant
>   calls in test code


 This change log should be below the Signed-off-by "---"


> Suggested-by: Darrick J. Wong <djwong@kernel.org>
> Suggested-by: Anand Jain <anajain.sg@gmail.com>
> Signed-off-by: Disha Goel <disgoel@linux.ibm.com>
> ---

... v2 changes  here...


>  common/dmlogwrites | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
>
> diff --git a/common/dmlogwrites b/common/dmlogwrites
> index a27e1966..0925b333 100644
> --- a/common/dmlogwrites
> +++ b/common/dmlogwrites
> @@ -14,6 +14,21 @@ _require_log_writes()
>  	_require_test_program "log-writes/replay-log"
>  }
>
> +# Require a log writes device of a minimum size
> +# $1: minimum size in KB
> +_require_log_writes_sized()
> +{
> +        local size=$1
> +
> +        [ $# -eq 1 ] || _fail "_require_log_writes_sized: expected
size param"
> +
> +        _require_log_writes
> +
> +        local devsize=$(_get_device_size $LOGWRITES_DEV)

Please keep all declarations at the beginning of the function.

> +        [ $devsize -lt $1 ] && \

use $size instead of $1 and

$devsize and $size units are different, 512 sectors vs KiB


> +                _notrun "LOGWRITES_DEV too small, ${devsize}KB <
${size}KB"
> +}
> +

$devsize is not in KB and $size is in KiB




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

* Re: [PATCH v2 1/2] common/dmlogwrites: add _require_log_writes_sized helper
  2026-05-04 23:16   ` Anand Jain
@ 2026-05-04 23:43     ` Anand Jain
  0 siblings, 0 replies; 7+ messages in thread
From: Anand Jain @ 2026-05-04 23:43 UTC (permalink / raw)
  To: Disha Goel, fstests
  Cc: linux-btrfs, ritesh.list, ojaswin, djwong, fdmanana,
	quwenruo.btrfs, zlang



On 5/5/26 07:16, Anand Jain wrote:
> 
> 
> On 5/5/26 05:53, Anand Jain wrote:
>>
>> looks good.
>>
>> Reviewed-by: Anand Jain <asj@kernel.org>
>>
>> Thanks
>>
> 
> sorry, not yet; I'm canceling the RVB.
> Details below.
> 
> 
>> v2:
>> - Renamed function from _require_logwrites_size to
> _require_log_writes_sized
>> - Added documentation comment clarifying the parameter is in KB
>> - Made function call _require_log_writes() internally to avoid redundant
>>   calls in test code
> 
> 
>  This change log should be below the Signed-off-by "---"
> 
> 
>> Suggested-by: Darrick J. Wong <djwong@kernel.org>
>> Suggested-by: Anand Jain <anajain.sg@gmail.com>
>> Signed-off-by: Disha Goel <disgoel@linux.ibm.com>
>> ---
> 
> ... v2 changes  here...
> 
> 
>>  common/dmlogwrites | 15 +++++++++++++++
>>  1 file changed, 15 insertions(+)
>>
>> diff --git a/common/dmlogwrites b/common/dmlogwrites
>> index a27e1966..0925b333 100644
>> --- a/common/dmlogwrites
>> +++ b/common/dmlogwrites
>> @@ -14,6 +14,21 @@ _require_log_writes()
>>  	_require_test_program "log-writes/replay-log"
>>  }
>>
>> +# Require a log writes device of a minimum size
>> +# $1: minimum size in KB
>> +_require_log_writes_sized()
>> +{
>> +        local size=$1
>> +
>> +        [ $# -eq 1 ] || _fail "_require_log_writes_sized: expected
> size param"
>> +
>> +        _require_log_writes
>> +
>> +        local devsize=$(_get_device_size $LOGWRITES_DEV)
> 
> Please keep all declarations at the beginning of the function.
> 
>> +        [ $devsize -lt $1 ] && \
> 
> use $size instead of $1 and
> 


> $devsize and $size units are different, 512 sectors vs KiB
  My bad, devsize is also in KiB. So this is fine.

> 
>> +                _notrun "LOGWRITES_DEV too small, ${devsize}KB <
> ${size}KB"
>> +}
>> +
> 
> $devsize is not in KB and $size is in KiB

 This is fine as well.

Thanks, Anand




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

* Re: [PATCH v2 2/2] btrfs/291: fix state transition logic and add size requirement
  2026-04-27 12:25 ` [PATCH v2 2/2] btrfs/291: fix state transition logic and add size requirement Disha Goel
@ 2026-05-05  2:46   ` Anand Jain
  2026-05-08 14:52     ` Disha Goel
  0 siblings, 1 reply; 7+ messages in thread
From: Anand Jain @ 2026-05-05  2:46 UTC (permalink / raw)
  To: Disha Goel, fstests
  Cc: linux-btrfs, ritesh.list, ojaswin, djwong, fdmanana,
	quwenruo.btrfs, zlang

On 27/4/26 20:25, Disha Goel wrote:
> This patch fixes two issues in btrfs/291:
> 
> 1. Add minimum 9GB LOGWRITES_DEV size requirement
>    The test creates LVM snapshots at each FUA point during replay,
>    requiring significant space. Use _require_log_writes_sized to
>    ensure sufficient space is available before running the test.
> 

It also depends on the SCRATCH_DEV size; the fix fails if SCRATCH_DEV is
 10G.

[  173.478493] BTRFS error (device dm-3): device total_bytes should be
at most 9663676416 but found 10737418240
[  173.482763] BTRFS error (device dm-3): failed to read chunk tree: -22
[  173.485457] BTRFS error (device dm-3): open_ctree failed: -22

Thanks.


> 2. Fix state transition logic for verity enablement
>    The original test assumed orphan items would always be created
>    during verity enablement (state 0->1 transition). However, in
>    some cases verity completes without creating orphan items,
>    causing the test to fail with "expected to reach verity done state".
> 
>    Fix by transitioning to state 1 when either orphan items exist
>    OR merkle items appear, handling both verity enablement paths.
>    Also improve state 1 validation to only check for cleared merkle
>    items when measurement actually fails.
> 
> The test now correctly handles verity enablement with or without
> orphan items while maintaining crash consistency validation.
> 
> v2:
> - Use _require_log_writes_sized instead of separate _require_log_writes
>   and _require_logwrites_size calls
> 
> Signed-off-by: Disha Goel <disgoel@linux.ibm.com>
> ---
>  tests/btrfs/291 | 17 ++++++++++++-----
>  1 file changed, 12 insertions(+), 5 deletions(-)
> 
> diff --git a/tests/btrfs/291 b/tests/btrfs/291
> index 122aeaa5..ac1d192d 100755
> --- a/tests/btrfs/291
> +++ b/tests/btrfs/291
> @@ -36,7 +36,7 @@ _cleanup()
>  _require_scratch
>  _require_test
>  _require_loop
> -_require_log_writes
> +_require_log_writes_sized $((9 * 1024 * 1024))
>  _require_dm_target snapshot
>  _require_command $LVM_PROG lvm
>  _require_scratch_verity
> @@ -129,9 +129,14 @@ do
>  	_udev_wait /dev/mapper/$vgname-$snapname
>  
>  	orphan=$(count_item $snap_dev ORPHAN)
> -	[ $state -eq 0 ] && [ $orphan -gt 0 ] && state=1
> -
>  	pre_mount=$(count_merkle_items $snap_dev)
> +
> +	if [ $state -eq 0 ]; then
> +		if [ $orphan -gt 0 ] || [ $pre_mount -gt 0 ]; then
> +			state=1
> +		fi
> +	fi
> +
>  	_mount $snap_dev $SCRATCH_MNT || _fail "mount failed at entry $cur"
>  	fsverity measure $SCRATCH_MNT/fsv >>$seqres.full 2>&1
>  	measured=$?
> @@ -143,8 +148,10 @@ do
>  	echo "entry: $cur, state: $state, orphan: $orphan, pre_mount: $pre_mount, post_mount: $post_mount" >> $seqres.full
>  
>  	if [ $state -eq 1 ]; then
> -		[ $post_mount -eq 0 ] || \
> -			_fail "mount failed to clear under-construction merkle items pre: $pre_mount, post: $post_mount at entry $cur";
> +		if [ $measured -ne 0 ]; then
> +			[ $post_mount -eq 0 ] || \
> +				_fail "mount failed to clear under-construction merkle items pre: $pre_mount, post: $post_mount at entry $cur";
> +		fi
>  	fi
>  	if [ $state -eq 2 ]; then
>  		[ $pre_mount -gt 0 ] || \


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

* Re: [PATCH v2 2/2] btrfs/291: fix state transition logic and add size requirement
  2026-05-05  2:46   ` Anand Jain
@ 2026-05-08 14:52     ` Disha Goel
  0 siblings, 0 replies; 7+ messages in thread
From: Disha Goel @ 2026-05-08 14:52 UTC (permalink / raw)
  To: Anand Jain, fstests
  Cc: linux-btrfs, ritesh.list, ojaswin, djwong, fdmanana,
	quwenruo.btrfs, zlang

On 05/05/26 8:16 am, Anand Jain wrote:
> On 27/4/26 20:25, Disha Goel wrote:
>> This patch fixes two issues in btrfs/291:
>>
>> 1. Add minimum 9GB LOGWRITES_DEV size requirement
>>     The test creates LVM snapshots at each FUA point during replay,
>>     requiring significant space. Use _require_log_writes_sized to
>>     ensure sufficient space is available before running the test.
>>
> 
> It also depends on the SCRATCH_DEV size; the fix fails if SCRATCH_DEV is
>   10G.
> 
> [  173.478493] BTRFS error (device dm-3): device total_bytes should be
> at most 9663676416 but found 10737418240
> [  173.482763] BTRFS error (device dm-3): failed to read chunk tree: -22
> [  173.485457] BTRFS error (device dm-3): open_ctree failed: -22
> 
> Thanks.
> 

Thanks for the detailed review! I've addressed all the feedback in v3.

I've tested the fix with multiple SCRATCH_DEV sizes and confirmed it
works correctly.

> 
>> 2. Fix state transition logic for verity enablement
>>     The original test assumed orphan items would always be created
>>     during verity enablement (state 0->1 transition). However, in
>>     some cases verity completes without creating orphan items,
>>     causing the test to fail with "expected to reach verity done state".
>>
>>     Fix by transitioning to state 1 when either orphan items exist
>>     OR merkle items appear, handling both verity enablement paths.
>>     Also improve state 1 validation to only check for cleared merkle
>>     items when measurement actually fails.
>>
>> The test now correctly handles verity enablement with or without
>> orphan items while maintaining crash consistency validation.
>>
>> v2:
>> - Use _require_log_writes_sized instead of separate _require_log_writes
>>    and _require_logwrites_size calls
>>
>> Signed-off-by: Disha Goel <disgoel@linux.ibm.com>
>> ---
>>   tests/btrfs/291 | 17 ++++++++++++-----
>>   1 file changed, 12 insertions(+), 5 deletions(-)
>>
>> diff --git a/tests/btrfs/291 b/tests/btrfs/291
>> index 122aeaa5..ac1d192d 100755
>> --- a/tests/btrfs/291
>> +++ b/tests/btrfs/291
>> @@ -36,7 +36,7 @@ _cleanup()
>>   _require_scratch
>>   _require_test
>>   _require_loop
>> -_require_log_writes
>> +_require_log_writes_sized $((9 * 1024 * 1024))
>>   _require_dm_target snapshot
>>   _require_command $LVM_PROG lvm
>>   _require_scratch_verity
>> @@ -129,9 +129,14 @@ do
>>   	_udev_wait /dev/mapper/$vgname-$snapname
>>   
>>   	orphan=$(count_item $snap_dev ORPHAN)
>> -	[ $state -eq 0 ] && [ $orphan -gt 0 ] && state=1
>> -
>>   	pre_mount=$(count_merkle_items $snap_dev)
>> +
>> +	if [ $state -eq 0 ]; then
>> +		if [ $orphan -gt 0 ] || [ $pre_mount -gt 0 ]; then
>> +			state=1
>> +		fi
>> +	fi
>> +
>>   	_mount $snap_dev $SCRATCH_MNT || _fail "mount failed at entry $cur"
>>   	fsverity measure $SCRATCH_MNT/fsv >>$seqres.full 2>&1
>>   	measured=$?
>> @@ -143,8 +148,10 @@ do
>>   	echo "entry: $cur, state: $state, orphan: $orphan, pre_mount: $pre_mount, post_mount: $post_mount" >> $seqres.full
>>   
>>   	if [ $state -eq 1 ]; then
>> -		[ $post_mount -eq 0 ] || \
>> -			_fail "mount failed to clear under-construction merkle items pre: $pre_mount, post: $post_mount at entry $cur";
>> +		if [ $measured -ne 0 ]; then
>> +			[ $post_mount -eq 0 ] || \
>> +				_fail "mount failed to clear under-construction merkle items pre: $pre_mount, post: $post_mount at entry $cur";
>> +		fi
>>   	fi
>>   	if [ $state -eq 2 ]; then
>>   		[ $pre_mount -gt 0 ] || \
> 

-- 
Regards,
Disha


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

end of thread, other threads:[~2026-05-08 14:52 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-27 12:25 [PATCH v2 1/2] common/dmlogwrites: add _require_log_writes_sized helper Disha Goel
2026-04-27 12:25 ` [PATCH v2 2/2] btrfs/291: fix state transition logic and add size requirement Disha Goel
2026-05-05  2:46   ` Anand Jain
2026-05-08 14:52     ` Disha Goel
2026-05-04 21:53 ` [PATCH v2 1/2] common/dmlogwrites: add _require_log_writes_sized helper Anand Jain
2026-05-04 23:16   ` Anand Jain
2026-05-04 23:43     ` Anand Jain

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