diff mbox series

Btrfs: remove level==0 check in balance_level

Message ID 1536703587-94565-4-git-send-email-bo.liu@linux.alibaba.com (mailing list archive)
State New, archived
Headers show
Series Btrfs: remove level==0 check in balance_level | expand

Commit Message

Liu Bo Sept. 11, 2018, 10:06 p.m. UTC
btrfs_search_slot()
   if (level != 0)
      setup_nodes_for_search()
          balance_level()

It is just impossible to have level=0 in balance_level.

Signed-off-by: Liu Bo <bo.liu@linux.alibaba.com>
---
 fs/btrfs/ctree.c | 3 ---
 1 file changed, 3 deletions(-)

Comments

Nikolay Borisov Sept. 12, 2018, 6:42 a.m. UTC | #1
On 12.09.2018 01:06, Liu Bo wrote:
> btrfs_search_slot()
>    if (level != 0)
>       setup_nodes_for_search()
>           balance_level()
> 
> It is just impossible to have level=0 in balance_level.
> 
> Signed-off-by: Liu Bo <bo.liu@linux.alibaba.com>

I concur with the analysis:

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

> ---
>  fs/btrfs/ctree.c | 3 ---
>  1 file changed, 3 deletions(-)
> 
> diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
> index 8b31caa60b0a..858085490e23 100644
> --- a/fs/btrfs/ctree.c
> +++ b/fs/btrfs/ctree.c
> @@ -1778,9 +1778,6 @@ static noinline int balance_level(struct btrfs_trans_handle *trans,
>  	int orig_slot = path->slots[level];
>  	u64 orig_ptr;
>  
> -	if (level == 0)
> -		return 0;
> -
>  	mid = path->nodes[level];
>  
>  	WARN_ON(path->locks[level] != BTRFS_WRITE_LOCK &&
>
David Sterba Sept. 12, 2018, 12:52 p.m. UTC | #2
On Wed, Sep 12, 2018 at 06:06:23AM +0800, Liu Bo wrote:
> btrfs_search_slot()
>    if (level != 0)
>       setup_nodes_for_search()
>           balance_level()
> 
> It is just impossible to have level=0 in balance_level.

While this is true, what do you think about adding ASSERT(level > 0) ?
This is to catch accidentally passing level 0.
Liu Bo Sept. 12, 2018, 7:30 p.m. UTC | #3
On Wed, Sep 12, 2018 at 02:52:38PM +0200, David Sterba wrote:
> On Wed, Sep 12, 2018 at 06:06:23AM +0800, Liu Bo wrote:
> > btrfs_search_slot()
> >    if (level != 0)
> >       setup_nodes_for_search()
> >           balance_level()
> > 
> > It is just impossible to have level=0 in balance_level.
> 
> While this is true, what do you think about adding ASSERT(level > 0) ?
> This is to catch accidentally passing level 0.

Sounds good, will update it.

thanks,
-liubo
diff mbox series

Patch

diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 8b31caa60b0a..858085490e23 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -1778,9 +1778,6 @@  static noinline int balance_level(struct btrfs_trans_handle *trans,
 	int orig_slot = path->slots[level];
 	u64 orig_ptr;
 
-	if (level == 0)
-		return 0;
-
 	mid = path->nodes[level];
 
 	WARN_ON(path->locks[level] != BTRFS_WRITE_LOCK &&