Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: fdmanana@kernel.org, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 2/2] btrfs: check for commit error at btrfs_attach_transaction_barrier()
Date: Fri, 21 Jul 2023 18:20:00 +0800	[thread overview]
Message-ID: <25161be7-27dc-be3a-3215-0e770f729191@gmx.com> (raw)
In-Reply-To: <ce368edf9997c7bc4bd1f0a3e7b8c9fd96450db6.1689932501.git.fdmanana@suse.com>



On 2023/7/21 17:49, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
>
> btrfs_attach_transaction_barrier() is used to get a handle pointing to the
> current running transaction if the transaction has not started its commit
> yet (its state is < TRANS_STATE_COMMIT_START). If the transaction commit
> has started, then we wait for the transaction to commit and finish before
> returning - however we completely ignore if the transaction was aborted
> due to some error during its commit, we simply return ERR_PT(-ENOENT),
> which makes the caller assume everything is fine and no errors happened.
>
> This could make an fsync return success (0) to user space when in fact we
> had a transaction abort and the target inode changes were therefore not
> persisted.
>
> Fix this by checking for the return value from btrfs_wait_for_commit(),
> and if it returned an error, return it back to the caller.
>
> Fixes: d4edf39bd5db ("Btrfs: fix uncompleted transaction")
> Signed-off-by: Filipe Manana <fdmanana@suse.com>

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu
> ---
>   fs/btrfs/transaction.c | 9 +++++++--
>   1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
> index 8ab85465cdaa..4bb9716ad24a 100644
> --- a/fs/btrfs/transaction.c
> +++ b/fs/btrfs/transaction.c
> @@ -826,8 +826,13 @@ btrfs_attach_transaction_barrier(struct btrfs_root *root)
>
>   	trans = start_transaction(root, 0, TRANS_ATTACH,
>   				  BTRFS_RESERVE_NO_FLUSH, true);
> -	if (trans == ERR_PTR(-ENOENT))
> -		btrfs_wait_for_commit(root->fs_info, 0);
> +	if (trans == ERR_PTR(-ENOENT)) {
> +		int ret;
> +
> +		ret = btrfs_wait_for_commit(root->fs_info, 0);
> +		if (ret)
> +			return ERR_PTR(ret);
> +	}
>
>   	return trans;
>   }

  reply	other threads:[~2023-07-21 10:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-21  9:49 [PATCH 0/2] btrfs: fixes for missing error reporting when attaching to a transaction fdmanana
2023-07-21  9:49 ` [PATCH 1/2] btrfs: check if the transaction was aborted at btrfs_wait_for_commit() fdmanana
2023-07-21 10:18   ` Qu Wenruo
2023-07-21  9:49 ` [PATCH 2/2] btrfs: check for commit error at btrfs_attach_transaction_barrier() fdmanana
2023-07-21 10:20   ` Qu Wenruo [this message]
2023-07-21 23:17 ` [PATCH 0/2] btrfs: fixes for missing error reporting when attaching to a transaction David Sterba

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=25161be7-27dc-be3a-3215-0e770f729191@gmx.com \
    --to=quwenruo.btrfs@gmx.com \
    --cc=fdmanana@kernel.org \
    --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