public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Anand Jain <anand.jain@oracle.com>
To: fdmanana@kernel.org, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] btrfs: do not BUG_ON() on failure to update inode when setting xattr
Date: Thu, 21 Apr 2022 19:51:32 +0800	[thread overview]
Message-ID: <93c95b82-148b-6fd0-a1a3-bf735e91c145@oracle.com> (raw)
In-Reply-To: <bf2fb575bc7b960b925693b9d64a802f4c477fc3.1650535321.git.fdmanana@suse.com>

On 21/04/2022 18:03, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
> 
> We are doing a BUG_ON() if we fail to update an inode after setting (or
> clearing) a xattr, but there's really no reason to not instead simply
> abort the transaction and return the error to the caller. This should be
> a rare error because we have previously reserved enough metadata space to
> update the inode and the delayed inode should have already been setup, so
> an -ENOSPC or -ENOMEM, which are the possible errors, are very unlikely to
> happen.
> 
> So replace the BUG_ON()s with a transaction abort.
> 
> Signed-off-by: Filipe Manana <fdmanana@suse.com>
> ---
>   fs/btrfs/xattr.c | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/btrfs/xattr.c b/fs/btrfs/xattr.c
> index f9d22ff3567f..4a2a5cb1c202 100644
> --- a/fs/btrfs/xattr.c
> +++ b/fs/btrfs/xattr.c
> @@ -262,7 +262,8 @@ int btrfs_setxattr_trans(struct inode *inode, const char *name,
>   	inode_inc_iversion(inode);
>   	inode->i_ctime = current_time(inode);
>   	ret = btrfs_update_inode(trans, root, BTRFS_I(inode));
> -	BUG_ON(ret);
> +	if (ret)
> +		btrfs_abort_transaction(trans, ret);
>   out:
>   	if (start_trans)
>   		btrfs_end_transaction(trans);
> @@ -401,7 +402,8 @@ static int btrfs_xattr_handler_set_prop(const struct xattr_handler *handler,
>   		inode_inc_iversion(inode);
>   		inode->i_ctime = current_time(inode);
>   		ret = btrfs_update_inode(trans, root, BTRFS_I(inode));
> -		BUG_ON(ret);
> +		if (ret)
> +			btrfs_abort_transaction(trans, ret);
>   	}
>   
>   	btrfs_end_transaction(trans);


Reviewed-by: Anand Jain <anand.jain@oracle.com>

Thanks, Anand

  parent reply	other threads:[~2022-04-21 11:51 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-21 10:03 [PATCH] btrfs: do not BUG_ON() on failure to update inode when setting xattr fdmanana
2022-04-21 10:20 ` Qu Wenruo
2022-04-21 11:51 ` Anand Jain [this message]
2022-04-21 15:05 ` 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=93c95b82-148b-6fd0-a1a3-bf735e91c145@oracle.com \
    --to=anand.jain@oracle.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