public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Boris Burkov <boris@bur.io>
To: Mark Harmstone <mark@harmstone.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] btrfs: abort transaction in do_remap_reloc_trans() on failure
Date: Tue, 7 Apr 2026 14:31:10 -0700	[thread overview]
Message-ID: <20260407213110.GC1564178@zen.localdomain> (raw)
In-Reply-To: <20260407161703.123545-1-mark@harmstone.com>

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
> 

  reply	other threads:[~2026-04-07 21:31 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 [this message]
2026-04-08 16:59   ` Mark Harmstone

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=20260407213110.GC1564178@zen.localdomain \
    --to=boris@bur.io \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=mark@harmstone.com \
    /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