btrfs-progs: check: introduce function to check an extent
[platform/upstream/btrfs-progs.git] / backref.c
index 9a2efca..7b3b592 100644 (file)
--- a/backref.c
+++ b/backref.c
@@ -22,6 +22,7 @@
 #include "backref.h"
 #include "ulist.h"
 #include "transaction.h"
+#include "internal.h"
 
 #define pr_debug(...) do { } while (0)
 
@@ -323,9 +324,9 @@ static int __resolve_indirect_ref(struct btrfs_fs_info *fs_info,
 
        eb = path->nodes[level];
        while (!eb) {
-               WARN_ON(!level);
                if (!level) {
                        ret = 1;
+                       WARN_ON(1);
                        goto out;
                }
                level--;
@@ -450,7 +451,7 @@ static int __add_missing_keys(struct btrfs_fs_info *fs_info,
                        continue;
                BUG_ON(!ref->wanted_disk_byte);
                eb = read_tree_block(fs_info->tree_root, ref->wanted_disk_byte,
-                                    fs_info->tree_root->leafsize, 0);
+                                    fs_info->tree_root->nodesize, 0);
                if (!extent_buffer_uptodate(eb)) {
                        free_extent_buffer(eb);
                        return -EIO;
@@ -804,8 +805,7 @@ static int find_parent_nodes(struct btrfs_trans_handle *trans,
                            ref->level == 0) {
                                u32 bsz;
                                struct extent_buffer *eb;
-                               bsz = btrfs_level_size(fs_info->extent_root,
-                                                       ref->level);
+                               bsz = fs_info->extent_root->nodesize;
                                eb = read_tree_block(fs_info->extent_root,
                                                           ref->parent, bsz, 0);
                                if (!extent_buffer_uptodate(eb)) {
@@ -1156,7 +1156,7 @@ int extent_from_logical(struct btrfs_fs_info *fs_info, u64 logical,
        }
        btrfs_item_key_to_cpu(path->nodes[0], found_key, path->slots[0]);
        if (found_key->type == BTRFS_METADATA_ITEM_KEY)
-               size = fs_info->extent_root->leafsize;
+               size = fs_info->extent_root->nodesize;
        else if (found_key->type == BTRFS_EXTENT_ITEM_KEY)
                size = found_key->offset;
 
@@ -1178,7 +1178,6 @@ int extent_from_logical(struct btrfs_fs_info *fs_info, u64 logical,
                 logical, logical - found_key->objectid, found_key->objectid,
                 found_key->offset, flags, item_size);
 
-       WARN_ON(!flags_ret);
        if (flags_ret) {
                if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK)
                        *flags_ret = BTRFS_EXTENT_FLAG_TREE_BLOCK;
@@ -1187,9 +1186,10 @@ int extent_from_logical(struct btrfs_fs_info *fs_info, u64 logical,
                else
                        BUG_ON(1);
                return 0;
+       } else {
+               WARN_ON(1);
+               return -EIO;
        }
-
-       return -EIO;
 }
 
 /*
@@ -1578,8 +1578,8 @@ static int inode_to_path(u64 inum, u32 name_len, unsigned long name_off,
  * is has been created large enough. each path is zero-terminated and accessed
  * from ipath->fspath->val[i].
  * when it returns, there are ipath->fspath->elem_cnt number of paths available
- * in ipath->fspath->val[]. when the allocated space wasn't sufficient, the
- * number of missed paths in recored in ipath->fspath->elem_missed, otherwise,
+ * in ipath->fspath->val[]. When the allocated space wasn't sufficient, the
+ * number of missed paths is recorded in ipath->fspath->elem_missed, otherwise,
  * it's zero. ipath->fspath->bytes_missing holds the number of bytes that would
  * have been needed to return all paths.
  */