Skip to contentSkip to conversation

Btrfs: remove level==0 check in balance_level

PATCH Superseded Liu Bo 3 participants 6 messages Sep 12, 2018 – Sep 14, 2018 Btrfs file system

lore
Share & tools
lore

Liu Bo

author
#0 lore raw

PATCH 1/1 Btrfs: remove level==0 check in balance_level

btrfs_search_slot()
if (level != 0)
setup_nodes_for_search()
balance_level()

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

---
 fs/btrfs/ctree.c | 3 ---
 1 file changed, 3 deletions(-)
fs/btrfs/ctree.c +0 -3
index 8b31caa60b0a..858085490e23 100644
@@ -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 &&
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Liu Bo

btrfs_search_slot()
if (level != 0)
setup_nodes_for_search()
balance_level()

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

I concur with the analysis:

Quoted 19 lines
---
 fs/btrfs/ctree.c | 3 ---
 1 file changed, 3 deletions(-)
fs/btrfs/ctree.c +0 -3
index 8b31caa60b0a..858085490e23 100644
@@ -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 &&
#2 lore raw
In reply to Liu Bo
Quoted 6 lines · Liu Bo

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.

author
#3 lore raw
Quoted 10 lines · David Sterba
Quoted 6 lines · Liu Bo

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

author
#4 lore raw

PATCH v2 1/1 Btrfs: remove level==0 check in balance_level

In reply to Liu Bo

btrfs_search_slot()
if (level != 0)
setup_nodes_for_search()
balance_level()

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

---
v2: add assertion for level just in case someone breaks the rule in the future.

 fs/btrfs/ctree.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/btrfs/ctree.c +1 -2
index 8b31caa60b0a..ada44c786f2e 100644
@@ -1778,8 +1778,7 @@ static noinline int balance_level(struct btrfs_trans_handle *trans,
 	int orig_slot = path->slots[level];
 	u64 orig_ptr;
 
-	if (level == 0)
-		return 0;
+	ASSERT(level > 0);
 
 	mid = path->nodes[level];
 
Signature · 1 line
1.8.3.1