btrfs-progs: check: report more specific info about invalid location
[platform/upstream/btrfs-progs.git] / ctree.c
diff --git a/ctree.c b/ctree.c
index 43f283c..4fc33b1 100644 (file)
--- a/ctree.c
+++ b/ctree.c
@@ -650,7 +650,6 @@ struct extent_buffer *read_node_slot(struct btrfs_fs_info *fs_info,
                return NULL;
 
        return read_tree_block(fs_info, btrfs_node_blockptr(parent, slot),
-                      fs_info->nodesize,
                       btrfs_node_ptr_generation(parent, slot));
 }
 
@@ -968,6 +967,7 @@ static int noinline push_nodes_for_insert(struct btrfs_trans_handle *trans,
 void reada_for_search(struct btrfs_root *root, struct btrfs_path *path,
                             int level, int slot, u64 objectid)
 {
+       struct btrfs_fs_info *fs_info = root->fs_info;
        struct extent_buffer *node;
        struct btrfs_disk_key disk_key;
        u32 nritems;
@@ -978,7 +978,6 @@ void reada_for_search(struct btrfs_root *root, struct btrfs_path *path,
        int direction = path->reada;
        struct extent_buffer *eb;
        u32 nr;
-       u32 blocksize;
        u32 nscan = 0;
 
        if (level != 1)
@@ -989,8 +988,7 @@ void reada_for_search(struct btrfs_root *root, struct btrfs_path *path,
 
        node = path->nodes[level];
        search = btrfs_node_blockptr(node, slot);
-       blocksize = root->fs_info->nodesize;
-       eb = btrfs_find_tree_block(root, search, blocksize);
+       eb = btrfs_find_tree_block(fs_info, search, fs_info->nodesize);
        if (eb) {
                free_extent_buffer(eb);
                return;
@@ -1020,9 +1018,9 @@ void reada_for_search(struct btrfs_root *root, struct btrfs_path *path,
                if ((search >= lowest_read && search <= highest_read) ||
                    (search < lowest_read && lowest_read - search <= 32768) ||
                    (search > highest_read && search - highest_read <= 32768)) {
-                       readahead_tree_block(root, search, blocksize,
+                       readahead_tree_block(fs_info, search,
                                     btrfs_node_ptr_generation(node, nr));
-                       nread += blocksize;
+                       nread += fs_info->nodesize;
                }
                nscan++;
                if (path->reada < 2 && (nread > SZ_256K || nscan > 32))
@@ -1490,7 +1488,8 @@ static int insert_ptr(struct btrfs_trans_handle *trans, struct btrfs_root
                BUG();
        if (nritems == BTRFS_NODEPTRS_PER_BLOCK(root))
                BUG();
-       if (slot != nritems) {
+       if (slot < nritems) {
+               /* shift the items */
                memmove_extent_buffer(lower,
                              btrfs_node_key_ptr_offset(slot + 1),
                              btrfs_node_key_ptr_offset(slot),
@@ -2254,7 +2253,7 @@ split:
 
        nritems = btrfs_header_nritems(leaf);
 
-       if (slot != nritems) {
+       if (slot < nritems) {
                /* shift the items */
                memmove_extent_buffer(leaf, btrfs_item_nr_offset(slot + 1),
                              btrfs_item_nr_offset(slot),
@@ -2505,7 +2504,7 @@ int btrfs_insert_empty_items(struct btrfs_trans_handle *trans,
        slot = path->slots[0];
        BUG_ON(slot < 0);
 
-       if (slot != nritems) {
+       if (slot < nritems) {
                unsigned int old_data = btrfs_item_end_nr(leaf, slot);
 
                if (old_data < data_end) {
@@ -2608,7 +2607,8 @@ int btrfs_del_ptr(struct btrfs_root *root, struct btrfs_path *path,
        int ret = 0;
 
        nritems = btrfs_header_nritems(parent);
-       if (slot != nritems -1) {
+       if (slot < nritems - 1) {
+               /* shift the items */
                memmove_extent_buffer(parent,
                              btrfs_node_key_ptr_offset(slot),
                              btrfs_node_key_ptr_offset(slot + 1),