btrfs: move btrfs_verify_level_key into tree-checker.c
authorJosef Bacik <josef@toxicpanda.com>
Sat, 29 Apr 2023 20:07:17 +0000 (16:07 -0400)
committerDavid Sterba <dsterba@suse.com>
Mon, 19 Jun 2023 11:59:25 +0000 (13:59 +0200)
This is more a buffer validation helper, move it into the tree-checker
files where it makes more sense.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/disk-io.c
fs/btrfs/disk-io.h
fs/btrfs/tree-checker.c
fs/btrfs/tree-checker.h

index 9227559..83518ed 100644 (file)
@@ -180,64 +180,6 @@ int btrfs_check_super_csum(struct btrfs_fs_info *fs_info,
        return 0;
 }
 
-int btrfs_verify_level_key(struct extent_buffer *eb, int level,
-                          struct btrfs_key *first_key, u64 parent_transid)
-{
-       struct btrfs_fs_info *fs_info = eb->fs_info;
-       int found_level;
-       struct btrfs_key found_key;
-       int ret;
-
-       found_level = btrfs_header_level(eb);
-       if (found_level != level) {
-               WARN(IS_ENABLED(CONFIG_BTRFS_DEBUG),
-                    KERN_ERR "BTRFS: tree level check failed\n");
-               btrfs_err(fs_info,
-"tree level mismatch detected, bytenr=%llu level expected=%u has=%u",
-                         eb->start, level, found_level);
-               return -EIO;
-       }
-
-       if (!first_key)
-               return 0;
-
-       /*
-        * For live tree block (new tree blocks in current transaction),
-        * we need proper lock context to avoid race, which is impossible here.
-        * So we only checks tree blocks which is read from disk, whose
-        * generation <= fs_info->last_trans_committed.
-        */
-       if (btrfs_header_generation(eb) > fs_info->last_trans_committed)
-               return 0;
-
-       /* We have @first_key, so this @eb must have at least one item */
-       if (btrfs_header_nritems(eb) == 0) {
-               btrfs_err(fs_info,
-               "invalid tree nritems, bytenr=%llu nritems=0 expect >0",
-                         eb->start);
-               WARN_ON(IS_ENABLED(CONFIG_BTRFS_DEBUG));
-               return -EUCLEAN;
-       }
-
-       if (found_level)
-               btrfs_node_key_to_cpu(eb, &found_key, 0);
-       else
-               btrfs_item_key_to_cpu(eb, &found_key, 0);
-       ret = btrfs_comp_cpu_keys(first_key, &found_key);
-
-       if (ret) {
-               WARN(IS_ENABLED(CONFIG_BTRFS_DEBUG),
-                    KERN_ERR "BTRFS: tree first key check failed\n");
-               btrfs_err(fs_info,
-"tree first key mismatch detected, bytenr=%llu parent_transid=%llu key expected=(%llu,%u,%llu) has=(%llu,%u,%llu)",
-                         eb->start, parent_transid, first_key->objectid,
-                         first_key->type, first_key->offset,
-                         found_key.objectid, found_key.type,
-                         found_key.offset);
-       }
-       return ret;
-}
-
 static int btrfs_repair_eb_io_failure(const struct extent_buffer *eb,
                                      int mirror_num)
 {
index 4d57723..a26ab3c 100644 (file)
@@ -31,8 +31,6 @@ struct btrfs_tree_parent_check;
 
 void btrfs_check_leaked_roots(struct btrfs_fs_info *fs_info);
 void btrfs_init_fs_info(struct btrfs_fs_info *fs_info);
-int btrfs_verify_level_key(struct extent_buffer *eb, int level,
-                          struct btrfs_key *first_key, u64 parent_transid);
 struct extent_buffer *read_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr,
                                      struct btrfs_tree_parent_check *check);
 struct extent_buffer *btrfs_find_create_tree_block(
index bd85205..9e92548 100644 (file)
@@ -1963,3 +1963,61 @@ int btrfs_check_eb_owner(const struct extent_buffer *eb, u64 root_owner)
        }
        return 0;
 }
+
+int btrfs_verify_level_key(struct extent_buffer *eb, int level,
+                          struct btrfs_key *first_key, u64 parent_transid)
+{
+       struct btrfs_fs_info *fs_info = eb->fs_info;
+       int found_level;
+       struct btrfs_key found_key;
+       int ret;
+
+       found_level = btrfs_header_level(eb);
+       if (found_level != level) {
+               WARN(IS_ENABLED(CONFIG_BTRFS_DEBUG),
+                    KERN_ERR "BTRFS: tree level check failed\n");
+               btrfs_err(fs_info,
+"tree level mismatch detected, bytenr=%llu level expected=%u has=%u",
+                         eb->start, level, found_level);
+               return -EIO;
+       }
+
+       if (!first_key)
+               return 0;
+
+       /*
+        * For live tree block (new tree blocks in current transaction),
+        * we need proper lock context to avoid race, which is impossible here.
+        * So we only checks tree blocks which is read from disk, whose
+        * generation <= fs_info->last_trans_committed.
+        */
+       if (btrfs_header_generation(eb) > fs_info->last_trans_committed)
+               return 0;
+
+       /* We have @first_key, so this @eb must have at least one item */
+       if (btrfs_header_nritems(eb) == 0) {
+               btrfs_err(fs_info,
+               "invalid tree nritems, bytenr=%llu nritems=0 expect >0",
+                         eb->start);
+               WARN_ON(IS_ENABLED(CONFIG_BTRFS_DEBUG));
+               return -EUCLEAN;
+       }
+
+       if (found_level)
+               btrfs_node_key_to_cpu(eb, &found_key, 0);
+       else
+               btrfs_item_key_to_cpu(eb, &found_key, 0);
+       ret = btrfs_comp_cpu_keys(first_key, &found_key);
+
+       if (ret) {
+               WARN(IS_ENABLED(CONFIG_BTRFS_DEBUG),
+                    KERN_ERR "BTRFS: tree first key check failed\n");
+               btrfs_err(fs_info,
+"tree first key mismatch detected, bytenr=%llu parent_transid=%llu key expected=(%llu,%u,%llu) has=(%llu,%u,%llu)",
+                         eb->start, parent_transid, first_key->objectid,
+                         first_key->type, first_key->offset,
+                         found_key.objectid, found_key.type,
+                         found_key.offset);
+       }
+       return ret;
+}
index c0861ce..3c2a02a 100644 (file)
@@ -66,5 +66,7 @@ int btrfs_check_node(struct extent_buffer *node);
 int btrfs_check_chunk_valid(struct extent_buffer *leaf,
                            struct btrfs_chunk *chunk, u64 logical);
 int btrfs_check_eb_owner(const struct extent_buffer *eb, u64 root_owner);
+int btrfs_verify_level_key(struct extent_buffer *eb, int level,
+                          struct btrfs_key *first_key, u64 parent_transid);
 
 #endif