public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Mark Harmstone <mark@harmstone.com>
To: Boris Burkov <boris@bur.io>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] btrfs: abort transaction in do_remap_reloc_trans() on failure
Date: Wed, 8 Apr 2026 17:59:35 +0100	[thread overview]
Message-ID: <b6ac97c6-ba2d-49e2-8a4a-5b2ce4bc50c7@harmstone.com> (raw)
In-Reply-To: <20260407213110.GC1564178@zen.localdomain>

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


      reply	other threads:[~2026-04-08 16:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b6ac97c6-ba2d-49e2-8a4a-5b2ce4bc50c7@harmstone.com \
    --to=mark@harmstone.com \
    --cc=boris@bur.io \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox