Skip to contentSkip to conversation

Tree-checker unlikely annotations, error code updates

PATCH In review David Sterba 2 participants 4 messages Apr 4, 2025 Btrfs file system

lore
Share & tools
lore

David Sterba

author maintainer
#0 lore raw

cover Tree-checker unlikely annotations, error code updates

David Sterba (2):
btrfs: tree-checker: more unlikely annotations
btrfs: tree-checker: adjust error code for header level check

 fs/btrfs/tree-checker.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
Signature · 1 line
2.47.1
author maintainer
#1 lore raw

PATCH 1/2 btrfs: tree-checker: more unlikely annotations

Add more unlikely annotations to branches that lead to EUCLEAN, overall in the tree checker this helps to reorder instructions for the no-error case.

---
 fs/btrfs/tree-checker.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
fs/btrfs/tree-checker.c +4 -4
index 43979891f7c8..732e0ca8f447 100644
@@ -2229,7 +2229,7 @@ int btrfs_verify_level_key(struct extent_buffer *eb,
 	int ret;
 
 	found_level = btrfs_header_level(eb);
-	if (found_level != check->level) {
+	if (unlikely(found_level != check->level)) {
 		WARN(IS_ENABLED(CONFIG_BTRFS_DEBUG),
 		     KERN_ERR "BTRFS: tree level check failed\n");
 		btrfs_err(fs_info,
@@ -2251,7 +2251,7 @@ int btrfs_verify_level_key(struct extent_buffer *eb,
 		return 0;
 
 	/* We have @first_key, so this @eb must have at least one item */
-	if (btrfs_header_nritems(eb) == 0) {
+	if (unlikely(btrfs_header_nritems(eb) == 0)) {
 		btrfs_err(fs_info,
 		"invalid tree nritems, bytenr=%llu nritems=0 expect >0",
 			  eb->start);
@@ -2263,9 +2263,9 @@ int btrfs_verify_level_key(struct extent_buffer *eb,
 		btrfs_node_key_to_cpu(eb, &found_key, 0);
 	else
 		btrfs_item_key_to_cpu(eb, &found_key, 0);
-	ret = btrfs_comp_cpu_keys(&check->first_key, &found_key);
 
-	if (ret) {
+	ret = btrfs_comp_cpu_keys(&check->first_key, &found_key);
+	if (unlikely(ret)) {
 		WARN(IS_ENABLED(CONFIG_BTRFS_DEBUG),
 		     KERN_ERR "BTRFS: tree first key check failed\n");
 		btrfs_err(fs_info,
Signature · 1 line
2.47.1
author maintainer
#2 lore raw

PATCH 2/2 btrfs: tree-checker: adjust error code for header level check

In reply to David Sterba

The whole tree checker returns EUCLEAN, except the one check in btrfs_verify_level_key(). This was inherited from the function that was moved from disk-io.c in 2cac5af16537 ("btrfs: move btrfs_verify_level_key into tree-checker.c") but this should be unified with the rest.

---
 fs/btrfs/tree-checker.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/tree-checker.c +1 -1
index 732e0ca8f447..5cd98776a612 100644
@@ -2235,7 +2235,7 @@ int btrfs_verify_level_key(struct extent_buffer *eb,
 		btrfs_err(fs_info,
 "tree level mismatch detected, bytenr=%llu level expected=%u has=%u",
 			  eb->start, check->level, found_level);
-		return -EIO;
+		return -EUCLEAN;
 	}
 
 	if (!check->has_first_key)
Signature · 1 line
2.47.1
Reviewed-by on the v1 series
#3 lore raw
In reply to David Sterba
Quoted 7 lines · David Sterba

David Sterba (2):
btrfs: tree-checker: more unlikely annotations
btrfs: tree-checker: adjust error code for header level check

  fs/btrfs/tree-checker.c | 10 +++++-----
  1 file changed, 5 insertions(+), 5 deletions(-)

Thanks,
Qu