linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nikolay Borisov <nborisov@suse.com>
To: Omar Sandoval <osandov@osandov.com>, linux-btrfs@vger.kernel.org
Cc: kernel-team@fb.com, Chris Mason <clm@fb.com>,
	Josef Bacik <josef@toxicpanda.com>
Subject: Re: [PATCH 02/10] Btrfs: fix error handling in btrfs_truncate_inode_items()
Date: Thu, 10 May 2018 11:09:19 +0300	[thread overview]
Message-ID: <a037daf3-0e42-ec48-d249-aaef0c558ee4@suse.com> (raw)
In-Reply-To: <950455336c0b0b935f010d6658a03a9de529af0c.1525932796.git.osandov@fb.com>



On 10.05.2018 09:21, Omar Sandoval wrote:
> From: Omar Sandoval <osandov@fb.com>
> 
> btrfs_truncate_inode_items() uses two variables for error handling, ret
> and err. These are not handled consistently, leading to a couple of
> bugs.
> 
> - Errors from btrfs_del_items() are handled but not propagated to the
>   caller
> - If btrfs_run_delayed_refs() fails and aborts the transaction, we
>   continue running
> 
> Just use ret everywhere and simplify things a bit, fixing both of these
> issues.
> 
> Fixes: 79787eaab461 ("btrfs: replace many BUG_ONs with proper error handling")
> Fixes: 1262133b8d6f ("Btrfs: account for crcs in delayed ref processing")
> Signed-off-by: Omar Sandoval <osandov@fb.com>

That function is horrendous so it needs much loving and this is a step
in the right direction.

LGTM:

Reviewed-by: Nikolay Borisov <nborisov@suse.com>

> ---
>  fs/btrfs/inode.c | 55 ++++++++++++++++++++++++------------------------
>  1 file changed, 28 insertions(+), 27 deletions(-)
> 
> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
> index fef8dbb6a93f..79d1da01a90d 100644
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -4442,7 +4442,6 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
>  	int pending_del_slot = 0;
>  	int extent_type = -1;
>  	int ret;
> -	int err = 0;
>  	u64 ino = btrfs_ino(BTRFS_I(inode));
>  	u64 bytes_deleted = 0;
>  	bool be_nice = false;
> @@ -4494,22 +4493,19 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
>  	 * up a huge file in a single leaf.  Most of the time that
>  	 * bytes_deleted is > 0, it will be huge by the time we get here
>  	 */
> -	if (be_nice && bytes_deleted > SZ_32M) {
> -		if (btrfs_should_end_transaction(trans)) {
> -			err = -EAGAIN;
> -			goto error;
> -		}
> +	if (be_nice && bytes_deleted > SZ_32M &&
> +	    btrfs_should_end_transaction(trans)) {
> +		ret = -EAGAIN;
> +		goto out;
>  	}
>  
> -
>  	path->leave_spinning = 1;
>  	ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
> -	if (ret < 0) {
> -		err = ret;
> +	if (ret < 0)
>  		goto out;
> -	}
>  
>  	if (ret > 0) {
> +		ret = 0;
>  		/* there are no items in the tree for us to truncate, we're
>  		 * done
>  		 */
> @@ -4620,7 +4616,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
>  				 * We have to bail so the last_size is set to
>  				 * just before this extent.
>  				 */
> -				err = NEED_TRUNCATE_BLOCK;
> +				ret = NEED_TRUNCATE_BLOCK;
>  				break;
>  			}
>  
> @@ -4687,7 +4683,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
>  						pending_del_nr);
>  				if (ret) {
>  					btrfs_abort_transaction(trans, ret);
> -					goto error;
> +					break;
>  				}
>  				pending_del_nr = 0;
>  			}
> @@ -4698,8 +4694,8 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
>  					trans->delayed_ref_updates = 0;
>  					ret = btrfs_run_delayed_refs(trans,
>  								   updates * 2);
> -					if (ret && !err)
> -						err = ret;
> +					if (ret)
> +						break;
>  				}
>  			}
>  			/*
> @@ -4707,8 +4703,8 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
>  			 * and let the transaction restart
>  			 */
>  			if (should_end) {
> -				err = -EAGAIN;
> -				goto error;
> +				ret = -EAGAIN;
> +				break;
>  			}
>  			goto search_again;
>  		} else {
> @@ -4716,32 +4712,37 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
>  		}
>  	}
>  out:
> -	if (pending_del_nr) {
> -		ret = btrfs_del_items(trans, root, path, pending_del_slot,
> +	if (ret >= 0 && pending_del_nr) {
> +		int err;
> +
> +		err = btrfs_del_items(trans, root, path, pending_del_slot,
>  				      pending_del_nr);
> -		if (ret)
> -			btrfs_abort_transaction(trans, ret);
> +		if (err) {
> +			btrfs_abort_transaction(trans, err);
> +			ret = err;
> +		}
>  	}
> -error:
>  	if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) {
>  		ASSERT(last_size >= new_size);
> -		if (!err && last_size > new_size)
> +		if (!ret && last_size > new_size)
>  			last_size = new_size;
>  		btrfs_ordered_update_i_size(inode, last_size, NULL);
>  	}
>  
>  	btrfs_free_path(path);
>  
> -	if (be_nice && bytes_deleted > SZ_32M) {
> +	if (be_nice && bytes_deleted > SZ_32M && (ret >= 0 || ret == -EAGAIN)) {
>  		unsigned long updates = trans->delayed_ref_updates;
> +		int err;
> +
>  		if (updates) {
>  			trans->delayed_ref_updates = 0;
> -			ret = btrfs_run_delayed_refs(trans, updates * 2);
> -			if (ret && !err)
> -				err = ret;
> +			err = btrfs_run_delayed_refs(trans, updates * 2);
> +			if (err)
> +				ret = err;
>  		}
>  	}
> -	return err;
> +	return ret;
>  }
>  
>  /*
> 

  reply	other threads:[~2018-05-10  8:09 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-10  6:21 [PATCH 00/10] Btrfs: orphan and truncate fixes Omar Sandoval
2018-05-10  6:21 ` [PATCH 01/10] Btrfs: remove stale comment referencing vmtruncate() Omar Sandoval
2018-05-10  6:21 ` [PATCH 02/10] Btrfs: fix error handling in btrfs_truncate_inode_items() Omar Sandoval
2018-05-10  8:09   ` Nikolay Borisov [this message]
2018-05-10  6:21 ` [PATCH 03/10] Btrfs: don't BUG_ON() " Omar Sandoval
2018-05-10  8:10   ` Nikolay Borisov
2018-05-10  6:21 ` [PATCH 04/10] Btrfs: stop creating orphan items for truncate Omar Sandoval
2018-05-10  6:21 ` [PATCH 05/10] Btrfs: don't release reserve or decrement orphan count if orphan item already existed Omar Sandoval
2018-05-10  8:23   ` Nikolay Borisov
2018-05-10  6:21 ` [PATCH 06/10] Btrfs: don't return ino if inode item removal fails Omar Sandoval
2018-05-10  8:29   ` Nikolay Borisov
2018-05-10 21:44     ` Omar Sandoval
2018-05-10  6:21 ` [PATCH 07/10] Btrfs: refactor btrfs_evict_inode() reserve refill dance Omar Sandoval
2018-05-10  8:35   ` Nikolay Borisov
2018-05-10  6:21 ` [PATCH 08/10] Btrfs: fix ENOSPC caused by orphan items reservations Omar Sandoval
2018-05-10  8:50   ` Nikolay Borisov
2018-05-10 23:25     ` Omar Sandoval
2018-05-10  6:21 ` [PATCH 09/10] Btrfs: get rid of unused orphan infrastructure Omar Sandoval
2018-05-10  6:21 ` [PATCH 10/10] Btrfs: reserve space for O_TMPFILE orphan item deletion Omar Sandoval
2018-05-10 15:25   ` Filipe Manana

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=a037daf3-0e42-ec48-d249-aaef0c558ee4@suse.com \
    --to=nborisov@suse.com \
    --cc=clm@fb.com \
    --cc=josef@toxicpanda.com \
    --cc=kernel-team@fb.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=osandov@osandov.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;
as well as URLs for NNTP newsgroup(s).