All of lore.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 04/12] btrfs: add assertions when deleting batches of delayed items
Date: Wed, 1 Jun 2022 07:04:20 +0530	[thread overview]
Message-ID: <be347268-b093-498b-77ff-6600b03abf74@oracle.com> (raw)
In-Reply-To: <cfcaa0d48b19913fee8598e0899f1b6f132b0cce.1654009356.git.fdmanana@suse.com>

On 5/31/22 20:36, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
> 
> There are a few impossible cases that btrfs_batch_delete_items() tries to
> deal with:
> 
> 1) Getting a path pointing to a NULL leaf;
> 2) The leaf slot is pointing beyond the last item in the leaf;
> 3) We can't find a single item to delete.
> 
> The first case is impossible because the given path was returned by a
> successful call to btrfs_search_slot(). Replace the BUG_ON() with an
> ASSERT for this.
> 
> The second case is impossible because we are always called when a delayed
> item matches an item in the given leaf. So add an ASSERT() for that and
> if that condition is not satisfied, trigger a warning and return an error.
> 
> The third case is impossible exactly because of the same reason as the
> second case. The given delayed item matches one item in the leaf, so we
> know that our batch always has at least one item. Add an ASSERT to check
> that, trigger a warning if that expectation fails and return an error.
> 
> Signed-off-by: Filipe Manana <fdmanana@suse.com>

LGTM

Anand Jain <anand.jain@oracle.com>


> ---
>   fs/btrfs/delayed-inode.c | 24 ++++++++++++++++--------
>   1 file changed, 16 insertions(+), 8 deletions(-)
> 
> diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
> index 66779ab3ed4a..bb9955e74a51 100644
> --- a/fs/btrfs/delayed-inode.c
> +++ b/fs/btrfs/delayed-inode.c
> @@ -790,20 +790,23 @@ static int btrfs_batch_delete_items(struct btrfs_trans_handle *trans,
>   				    struct btrfs_delayed_item *item)
>   {
>   	struct btrfs_delayed_item *curr, *next;
> -	struct extent_buffer *leaf;
> +	struct extent_buffer *leaf = path->nodes[0];
>   	struct btrfs_key key;
>   	struct list_head head;
>   	int nitems, i, last_item;
>   	int ret = 0;
>   
> -	BUG_ON(!path->nodes[0]);
> -
> -	leaf = path->nodes[0];
> +	ASSERT(leaf != NULL);
>   
>   	i = path->slots[0];
>   	last_item = btrfs_header_nritems(leaf) - 1;
> -	if (i > last_item)
> -		return -ENOENT;	/* FIXME: Is errno suitable? */
> +	/*
> +	 * Our caller always gives us a path pointing to an existing item, so
> +	 * this can not happen.
> +	 */
> +	ASSERT(i <= last_item);
> +	if (WARN_ON(i > last_item))
> +		return -ENOENT;
>   
>   	next = item;
>   	INIT_LIST_HEAD(&head);
> @@ -830,8 +833,13 @@ static int btrfs_batch_delete_items(struct btrfs_trans_handle *trans,
>   		btrfs_item_key_to_cpu(leaf, &key, i);
>   	}
>   
> -	if (!nitems)
> -		return 0;
> +	/*
> +	 * Our caller always gives us a path pointing to an existing item, so
> +	 * this can not happen.
> +	 */
> +	ASSERT(nitems >= 1);
> +	if (nitems < 1)
> +		return -ENOENT;
>   
>   	ret = btrfs_del_items(trans, root, path, path->slots[0], nitems);
>   	if (ret)


  reply	other threads:[~2022-06-01  1:34 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-31 15:06 [PATCH 00/12] btrfs: some improvements and cleanups around delayed items fdmanana
2022-05-31 15:06 ` [PATCH 01/12] btrfs: balance btree dirty pages and delayed items after a rename fdmanana
2022-05-31 15:16   ` Nikolay Borisov
2022-05-31 23:13   ` Anand Jain
2022-05-31 15:06 ` [PATCH 02/12] btrfs: free the path earlier when creating a new inode fdmanana
2022-05-31 15:21   ` Nikolay Borisov
2022-05-31 23:22   ` Anand Jain
2022-06-01  9:34     ` Filipe Manana
2022-06-01 11:11       ` Anand Jain
2022-06-01 11:51         ` David Sterba
2022-05-31 15:06 ` [PATCH 03/12] btrfs: balance btree dirty pages and delayed items after clone and dedupe fdmanana
2022-06-01  0:54   ` Anand Jain
2022-05-31 15:06 ` [PATCH 04/12] btrfs: add assertions when deleting batches of delayed items fdmanana
2022-06-01  1:34   ` Anand Jain [this message]
2022-05-31 15:06 ` [PATCH 05/12] btrfs: deal with deletion errors when deleting " fdmanana
2022-06-01  1:44   ` Anand Jain
2022-05-31 15:06 ` [PATCH 06/12] btrfs: refactor the delayed item deletion entry point fdmanana
2022-05-31 15:06 ` [PATCH 07/12] btrfs: improve batch deletion of delayed dir index items fdmanana
2022-06-02  8:24   ` Nikolay Borisov
2022-06-02  8:55     ` Filipe Manana
2022-05-31 15:06 ` [PATCH 08/12] btrfs: assert that delayed item is a dir index item when adding it fdmanana
2022-05-31 15:06 ` [PATCH 09/12] btrfs: improve batch insertion of delayed dir index items fdmanana
2022-05-31 15:06 ` [PATCH 10/12] btrfs: do not BUG_ON() on failure to reserve metadata for delayed item fdmanana
2022-05-31 15:06 ` [PATCH 11/12] btrfs: set delayed item type when initializing it fdmanana
2022-05-31 15:06 ` [PATCH 12/12] btrfs: reduce amount of reserved metadata for delayed item insertion fdmanana
2022-06-08 15:23   ` [btrfs] 62bd8124e2: WARNING:at_fs/btrfs/block-rsv.c:#btrfs_release_global_block_rsv[btrfs] kernel test robot
2022-06-08 15:23     ` kernel test robot
2022-06-09  9:46     ` Filipe Manana
2022-06-09  9:46       ` Filipe Manana
2022-06-10  1:26       ` Oliver Sang
2022-06-10  1:26         ` Oliver Sang
2022-06-12 14:36         ` Oliver Sang
2022-06-12 14:36           ` Oliver Sang
2022-06-13 10:50           ` Filipe Manana
2022-06-13 10:50             ` Filipe Manana
2022-06-16  2:42             ` Oliver Sang
2022-06-16  2:42               ` Oliver Sang
2022-06-17 10:32               ` Filipe Manana
2022-06-17 10:32                 ` Filipe Manana
2022-06-01 18:35 ` [PATCH 00/12] btrfs: some improvements and cleanups around delayed items David Sterba
2022-06-02  9:34 ` Nikolay Borisov

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=be347268-b093-498b-77ff-6600b03abf74@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.