public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: abort transaction in do_remap_reloc_trans() on failure
@ 2026-04-07 16:16 Mark Harmstone
  2026-04-07 21:31 ` Boris Burkov
  0 siblings, 1 reply; 3+ messages in thread
From: Mark Harmstone @ 2026-04-07 16:16 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Mark Harmstone

If one of the calls made by do_remap_reloc_trans() fails, we can leave
the remap tree in an inconsistent state. Abort the transaction if this
happens, to prevent the corrupt state from reaching the disk.

Signed-off-by: Mark Harmstone <mark@harmstone.com>
---
 fs/btrfs/relocation.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 1c42c5180bddd5..277a0042967665 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -5089,6 +5089,7 @@ static int do_remap_reloc_trans(struct btrfs_fs_info *fs_info,
 	btrfs_free_reserved_extent(fs_info, new_addr, length, 0);
 
 	mutex_unlock(&fs_info->remap_mutex);
+	btrfs_abort_transaction(trans, ret);
 	btrfs_end_transaction(trans);
 
 	return ret;
-- 
2.52.0


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

* Re: [PATCH] btrfs: abort transaction in do_remap_reloc_trans() on failure
  2026-04-07 16:16 [PATCH] btrfs: abort transaction in do_remap_reloc_trans() on failure Mark Harmstone
@ 2026-04-07 21:31 ` Boris Burkov
  2026-04-08 16:59   ` Mark Harmstone
  0 siblings, 1 reply; 3+ messages in thread
From: Boris Burkov @ 2026-04-07 21:31 UTC (permalink / raw)
  To: Mark Harmstone; +Cc: linux-btrfs

On Tue, Apr 07, 2026 at 05:16:56PM +0100, Mark Harmstone wrote:
> If one of the calls made by do_remap_reloc_trans() fails, we can leave
> the remap tree in an inconsistent state. Abort the transaction if this
> happens, to prevent the corrupt state from reaching the disk.
> 
> Signed-off-by: Mark Harmstone <mark@harmstone.com>
> ---
>  fs/btrfs/relocation.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
> index 1c42c5180bddd5..277a0042967665 100644
> --- a/fs/btrfs/relocation.c
> +++ b/fs/btrfs/relocation.c
> @@ -5089,6 +5089,7 @@ static int do_remap_reloc_trans(struct btrfs_fs_info *fs_info,
>  	btrfs_free_reserved_extent(fs_info, new_addr, length, 0);
>  
>  	mutex_unlock(&fs_info->remap_mutex);
> +	btrfs_abort_transaction(trans, ret);

Counterintuitively to the usual pattern of sharing code in fail: labels,
I think it is quite nice to put a separate abort at each failing code
path that requires an abort. That way we get better diagnostic
information on what actually went wrong.

e.g. a recent patch from Filipe unfolding it across a function call:
https://lore.kernel.org/linux-btrfs/99743ac0b4b9a69dcaa8f9adcaf301bd1a0f1a89.1769163248.git.fdmanana@suse.com/

Thanks,
Boris

>  	btrfs_end_transaction(trans);
>  
>  	return ret;
> -- 
> 2.52.0
> 

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

* Re: [PATCH] btrfs: abort transaction in do_remap_reloc_trans() on failure
  2026-04-07 21:31 ` Boris Burkov
@ 2026-04-08 16:59   ` Mark Harmstone
  0 siblings, 0 replies; 3+ messages in thread
From: Mark Harmstone @ 2026-04-08 16:59 UTC (permalink / raw)
  To: Boris Burkov; +Cc: linux-btrfs

On 07/04/2026 10.31 pm, Boris Burkov wrote:
> On Tue, Apr 07, 2026 at 05:16:56PM +0100, Mark Harmstone wrote:
>> If one of the calls made by do_remap_reloc_trans() fails, we can leave
>> the remap tree in an inconsistent state. Abort the transaction if this
>> happens, to prevent the corrupt state from reaching the disk.
>>
>> Signed-off-by: Mark Harmstone <mark@harmstone.com>
>> ---
>>   fs/btrfs/relocation.c | 1 +
>>   1 file changed, 1 insertion(+)
>>
>> diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
>> index 1c42c5180bddd5..277a0042967665 100644
>> --- a/fs/btrfs/relocation.c
>> +++ b/fs/btrfs/relocation.c
>> @@ -5089,6 +5089,7 @@ static int do_remap_reloc_trans(struct btrfs_fs_info *fs_info,
>>   	btrfs_free_reserved_extent(fs_info, new_addr, length, 0);
>>   
>>   	mutex_unlock(&fs_info->remap_mutex);
>> +	btrfs_abort_transaction(trans, ret);
> 
> Counterintuitively to the usual pattern of sharing code in fail: labels,
> I think it is quite nice to put a separate abort at each failing code
> path that requires an abort. That way we get better diagnostic
> information on what actually went wrong.
> 
> e.g. a recent patch from Filipe unfolding it across a function call:
> https://lore.kernel.org/linux-btrfs/99743ac0b4b9a69dcaa8f9adcaf301bd1a0f1a89.1769163248.git.fdmanana@suse.com/

Thanks Boris - if aborting a transaction logs the line number, that's a 
very good reason to do it in place. This also shows that the call to 
btrfs_add_to_free_space_tree after add_remap_entry fails is pointless, 
as the transaction is about to be aborted.

> Thanks,
> Boris
> 
>>   	btrfs_end_transaction(trans);
>>   
>>   	return ret;
>> -- 
>> 2.52.0
>>


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

end of thread, other threads:[~2026-04-08 16:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-07 16:16 [PATCH] btrfs: abort transaction in do_remap_reloc_trans() on failure Mark Harmstone
2026-04-07 21:31 ` Boris Burkov
2026-04-08 16:59   ` Mark Harmstone

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