Lines Matching full:leaf

10  * The objective is to do leaf/node validation checks when tree block is read
38 * @type: leaf or node
39 * @identifier: the necessary info to locate the leaf/node.
51 * Append generic "corrupt leaf/node root=%llu block=%llu slot=%d: " to @fmt.
71 btrfs_header_level(eb) == 0 ? "leaf" : "node", in generic_err()
99 btrfs_header_level(eb) == 0 ? "leaf" : "node", in file_extent_err()
109 #define CHECK_FE_ALIGNED(leaf, slot, fi, name, alignment) \ argument
111 if (unlikely(!IS_ALIGNED(btrfs_file_extent_##name((leaf), (fi)), \
113 file_extent_err((leaf), (slot), \
115 (#name), btrfs_file_extent_##name((leaf), (fi)), \
117 (!IS_ALIGNED(btrfs_file_extent_##name((leaf), (fi)), (alignment))); \
120 static u64 file_extent_end(struct extent_buffer *leaf, in file_extent_end() argument
127 if (btrfs_file_extent_type(leaf, extent) == BTRFS_FILE_EXTENT_INLINE) { in file_extent_end()
128 len = btrfs_file_extent_ram_bytes(leaf, extent); in file_extent_end()
129 end = ALIGN(key->offset + len, leaf->fs_info->sectorsize); in file_extent_end()
131 len = btrfs_file_extent_num_bytes(leaf, extent); in file_extent_end()
160 btrfs_header_level(eb) == 0 ? "leaf" : "node", in dir_item_err()
175 static bool check_prev_ino(struct extent_buffer *leaf, in check_prev_ino() argument
194 if (!is_fstree(btrfs_header_owner(leaf))) in check_prev_ino()
201 dir_item_err(leaf, slot, in check_prev_ino()
206 static int check_extent_data_item(struct extent_buffer *leaf, in check_extent_data_item() argument
210 struct btrfs_fs_info *fs_info = leaf->fs_info; in check_extent_data_item()
213 u32 item_size = btrfs_item_size(leaf, slot); in check_extent_data_item()
217 file_extent_err(leaf, slot, in check_extent_data_item()
229 if (unlikely(!check_prev_ino(leaf, key, slot, prev_key))) in check_extent_data_item()
232 fi = btrfs_item_ptr(leaf, slot, struct btrfs_file_extent_item); in check_extent_data_item()
239 file_extent_err(leaf, slot, in check_extent_data_item()
245 if (unlikely(btrfs_file_extent_type(leaf, fi) >= in check_extent_data_item()
247 file_extent_err(leaf, slot, in check_extent_data_item()
249 btrfs_file_extent_type(leaf, fi), in check_extent_data_item()
258 if (unlikely(btrfs_file_extent_compression(leaf, fi) >= in check_extent_data_item()
260 file_extent_err(leaf, slot, in check_extent_data_item()
262 btrfs_file_extent_compression(leaf, fi), in check_extent_data_item()
266 if (unlikely(btrfs_file_extent_encryption(leaf, fi))) { in check_extent_data_item()
267 file_extent_err(leaf, slot, in check_extent_data_item()
269 btrfs_file_extent_encryption(leaf, fi)); in check_extent_data_item()
272 if (btrfs_file_extent_type(leaf, fi) == BTRFS_FILE_EXTENT_INLINE) { in check_extent_data_item()
275 file_extent_err(leaf, slot, in check_extent_data_item()
282 if (btrfs_file_extent_compression(leaf, fi) != in check_extent_data_item()
288 btrfs_file_extent_ram_bytes(leaf, fi))) { in check_extent_data_item()
289 file_extent_err(leaf, slot, in check_extent_data_item()
292 btrfs_file_extent_ram_bytes(leaf, fi)); in check_extent_data_item()
300 file_extent_err(leaf, slot, in check_extent_data_item()
305 if (unlikely(CHECK_FE_ALIGNED(leaf, slot, fi, ram_bytes, sectorsize) || in check_extent_data_item()
306 CHECK_FE_ALIGNED(leaf, slot, fi, disk_bytenr, sectorsize) || in check_extent_data_item()
307 CHECK_FE_ALIGNED(leaf, slot, fi, disk_num_bytes, sectorsize) || in check_extent_data_item()
308 CHECK_FE_ALIGNED(leaf, slot, fi, offset, sectorsize) || in check_extent_data_item()
309 CHECK_FE_ALIGNED(leaf, slot, fi, num_bytes, sectorsize))) in check_extent_data_item()
313 if (unlikely(check_add_overflow(btrfs_file_extent_num_bytes(leaf, fi), in check_extent_data_item()
315 file_extent_err(leaf, slot, in check_extent_data_item()
318 btrfs_file_extent_num_bytes(leaf, fi)); in check_extent_data_item()
323 * Check that no two consecutive file extent items, in the same leaf, in check_extent_data_item()
332 prev_fi = btrfs_item_ptr(leaf, slot - 1, in check_extent_data_item()
334 prev_end = file_extent_end(leaf, prev_key, prev_fi); in check_extent_data_item()
336 file_extent_err(leaf, slot - 1, in check_extent_data_item()
351 btrfs_file_extent_compression(leaf, fi) == BTRFS_COMPRESS_NONE && in check_extent_data_item()
352 btrfs_file_extent_disk_bytenr(leaf, fi)) { in check_extent_data_item()
353 if (WARN_ON(btrfs_file_extent_ram_bytes(leaf, fi) != in check_extent_data_item()
354 btrfs_file_extent_disk_num_bytes(leaf, fi))) in check_extent_data_item()
355 file_extent_err(leaf, slot, in check_extent_data_item()
357 btrfs_file_extent_ram_bytes(leaf, fi), in check_extent_data_item()
358 btrfs_file_extent_disk_num_bytes(leaf, fi)); in check_extent_data_item()
364 static int check_csum_item(struct extent_buffer *leaf, struct btrfs_key *key, in check_csum_item() argument
367 struct btrfs_fs_info *fs_info = leaf->fs_info; in check_csum_item()
372 generic_err(leaf, slot, in check_csum_item()
378 generic_err(leaf, slot, in check_csum_item()
383 if (unlikely(!IS_ALIGNED(btrfs_item_size(leaf, slot), csumsize))) { in check_csum_item()
384 generic_err(leaf, slot, in check_csum_item()
386 btrfs_item_size(leaf, slot), csumsize); in check_csum_item()
393 prev_item_size = btrfs_item_size(leaf, slot - 1); in check_csum_item()
397 generic_err(leaf, slot - 1, in check_csum_item()
410 static int check_inode_key(struct extent_buffer *leaf, struct btrfs_key *key, in check_inode_key() argument
416 btrfs_item_key_to_cpu(leaf, &item_key, slot); in check_inode_key()
432 generic_err(leaf, slot, in check_inode_key()
439 dir_item_err(leaf, slot, in check_inode_key()
450 inode_item_err(leaf, slot, in check_inode_key()
454 dir_item_err(leaf, slot, in check_inode_key()
462 static int check_root_key(struct extent_buffer *leaf, struct btrfs_key *key, in check_root_key() argument
468 btrfs_item_key_to_cpu(leaf, &item_key, slot); in check_root_key()
479 generic_err(leaf, slot, in check_root_key()
488 generic_err(leaf, slot, "invalid root id 0"); in check_root_key()
490 dir_item_err(leaf, slot, in check_root_key()
497 dir_item_err(leaf, slot, in check_root_key()
514 generic_err(leaf, slot, "invalid root id 0 for reloc tree"); in check_root_key()
520 static int check_dir_item(struct extent_buffer *leaf, in check_dir_item() argument
524 struct btrfs_fs_info *fs_info = leaf->fs_info; in check_dir_item()
526 u32 item_size = btrfs_item_size(leaf, slot); in check_dir_item()
529 if (unlikely(!check_prev_ino(leaf, key, slot, prev_key))) in check_dir_item()
532 di = btrfs_item_ptr(leaf, slot, struct btrfs_dir_item); in check_dir_item()
545 dir_item_err(leaf, slot, in check_dir_item()
552 btrfs_dir_item_key_to_cpu(leaf, di, &location_key); in check_dir_item()
554 ret = check_root_key(leaf, &location_key, slot); in check_dir_item()
559 ret = check_inode_key(leaf, &location_key, slot); in check_dir_item()
563 dir_item_err(leaf, slot, in check_dir_item()
571 dir_type = btrfs_dir_ftype(leaf, di); in check_dir_item()
574 dir_item_err(leaf, slot, in check_dir_item()
582 dir_item_err(leaf, slot, in check_dir_item()
589 dir_item_err(leaf, slot, in check_dir_item()
599 name_len = btrfs_dir_name_len(leaf, di); in check_dir_item()
600 data_len = btrfs_dir_data_len(leaf, di); in check_dir_item()
602 dir_item_err(leaf, slot, in check_dir_item()
608 dir_item_err(leaf, slot, in check_dir_item()
616 dir_item_err(leaf, slot, in check_dir_item()
626 dir_item_err(leaf, slot, in check_dir_item()
640 read_extent_buffer(leaf, namebuf, in check_dir_item()
644 dir_item_err(leaf, slot, in check_dir_item()
675 btrfs_header_level(eb) == 0 ? "leaf" : "node", in block_group_err()
681 static int check_block_group_item(struct extent_buffer *leaf, in check_block_group_item() argument
684 struct btrfs_fs_info *fs_info = leaf->fs_info; in check_block_group_item()
686 u32 item_size = btrfs_item_size(leaf, slot); in check_block_group_item()
696 block_group_err(leaf, slot, in check_block_group_item()
702 block_group_err(leaf, slot, in check_block_group_item()
708 read_extent_buffer(leaf, &bgi, btrfs_item_ptr_offset(leaf, slot), in check_block_group_item()
720 block_group_err(leaf, slot, in check_block_group_item()
727 block_group_err(leaf, slot, in check_block_group_item()
735 block_group_err(leaf, slot, in check_block_group_item()
743 block_group_err(leaf, slot, in check_block_group_item()
756 block_group_err(leaf, slot, in check_block_group_item()
769 static void chunk_err(const struct extent_buffer *leaf, in chunk_err() argument
773 const struct btrfs_fs_info *fs_info = leaf->fs_info; in chunk_err()
781 is_sb = (leaf->start == BTRFS_SUPER_INFO_OFFSET); in chunk_err()
788 for (i = 0; i < btrfs_header_nritems(leaf); i++) { in chunk_err()
789 if (btrfs_item_ptr_offset(leaf, i) == in chunk_err()
806 "corrupt leaf: root=%llu block=%llu slot=%d chunk_start=%llu, %pV", in chunk_err()
807 BTRFS_CHUNK_TREE_OBJECTID, leaf->start, slot, in chunk_err()
818 int btrfs_check_chunk_valid(struct extent_buffer *leaf, in btrfs_check_chunk_valid() argument
821 struct btrfs_fs_info *fs_info = leaf->fs_info; in btrfs_check_chunk_valid()
834 length = btrfs_chunk_length(leaf, chunk); in btrfs_check_chunk_valid()
835 stripe_len = btrfs_chunk_stripe_len(leaf, chunk); in btrfs_check_chunk_valid()
836 num_stripes = btrfs_chunk_num_stripes(leaf, chunk); in btrfs_check_chunk_valid()
837 sub_stripes = btrfs_chunk_sub_stripes(leaf, chunk); in btrfs_check_chunk_valid()
838 type = btrfs_chunk_type(leaf, chunk); in btrfs_check_chunk_valid()
844 chunk_err(leaf, chunk, logical, in btrfs_check_chunk_valid()
849 chunk_err(leaf, chunk, logical, in btrfs_check_chunk_valid()
855 chunk_err(leaf, chunk, logical, in btrfs_check_chunk_valid()
861 chunk_err(leaf, chunk, logical, in btrfs_check_chunk_valid()
866 if (unlikely(btrfs_chunk_sector_size(leaf, chunk) != fs_info->sectorsize)) { in btrfs_check_chunk_valid()
867 chunk_err(leaf, chunk, logical, in btrfs_check_chunk_valid()
869 btrfs_chunk_sector_size(leaf, chunk), in btrfs_check_chunk_valid()
874 chunk_err(leaf, chunk, logical, in btrfs_check_chunk_valid()
879 chunk_err(leaf, chunk, logical, in btrfs_check_chunk_valid()
885 chunk_err(leaf, chunk, logical, in btrfs_check_chunk_valid()
899 chunk_err(leaf, chunk, logical, in btrfs_check_chunk_valid()
906 chunk_err(leaf, chunk, logical, in btrfs_check_chunk_valid()
910 btrfs_chunk_type(leaf, chunk)); in btrfs_check_chunk_valid()
916 chunk_err(leaf, chunk, logical, in btrfs_check_chunk_valid()
922 chunk_err(leaf, chunk, logical, in btrfs_check_chunk_valid()
931 chunk_err(leaf, chunk, logical, in btrfs_check_chunk_valid()
944 chunk_err(leaf, chunk, logical, in btrfs_check_chunk_valid()
966 chunk_err(leaf, chunk, logical, in btrfs_check_chunk_valid()
982 static int check_leaf_chunk_item(struct extent_buffer *leaf, in check_leaf_chunk_item() argument
988 if (unlikely(btrfs_item_size(leaf, slot) < sizeof(struct btrfs_chunk))) { in check_leaf_chunk_item()
989 chunk_err(leaf, chunk, key->offset, in check_leaf_chunk_item()
991 btrfs_item_size(leaf, slot), in check_leaf_chunk_item()
993 BTRFS_LEAF_DATA_SIZE(leaf->fs_info)); in check_leaf_chunk_item()
997 num_stripes = btrfs_chunk_num_stripes(leaf, chunk); in check_leaf_chunk_item()
1003 btrfs_item_size(leaf, slot))) { in check_leaf_chunk_item()
1004 chunk_err(leaf, chunk, key->offset, in check_leaf_chunk_item()
1006 btrfs_item_size(leaf, slot), in check_leaf_chunk_item()
1011 return btrfs_check_chunk_valid(leaf, chunk, key->offset); in check_leaf_chunk_item()
1032 btrfs_header_level(eb) == 0 ? "leaf" : "node", in dev_item_err()
1038 static int check_dev_item(struct extent_buffer *leaf, in check_dev_item() argument
1042 const u32 item_size = btrfs_item_size(leaf, slot); in check_dev_item()
1045 dev_item_err(leaf, slot, in check_dev_item()
1052 dev_item_err(leaf, slot, "invalid item size: has %u expect %zu", in check_dev_item()
1057 ditem = btrfs_item_ptr(leaf, slot, struct btrfs_dev_item); in check_dev_item()
1058 if (unlikely(btrfs_device_id(leaf, ditem) != key->offset)) { in check_dev_item()
1059 dev_item_err(leaf, slot, in check_dev_item()
1061 key->offset, btrfs_device_id(leaf, ditem)); in check_dev_item()
1070 if (unlikely(btrfs_device_bytes_used(leaf, ditem) > in check_dev_item()
1071 btrfs_device_total_bytes(leaf, ditem))) { in check_dev_item()
1072 dev_item_err(leaf, slot, in check_dev_item()
1074 btrfs_device_bytes_used(leaf, ditem), in check_dev_item()
1075 btrfs_device_total_bytes(leaf, ditem)); in check_dev_item()
1085 static int check_inode_item(struct extent_buffer *leaf, in check_inode_item() argument
1088 struct btrfs_fs_info *fs_info = leaf->fs_info; in check_inode_item()
1092 const u32 item_size = btrfs_item_size(leaf, slot); in check_inode_item()
1098 ret = check_inode_key(leaf, key, slot); in check_inode_item()
1103 generic_err(leaf, slot, "invalid item size: has %u expect %zu", in check_inode_item()
1108 iitem = btrfs_item_ptr(leaf, slot, struct btrfs_inode_item); in check_inode_item()
1111 if (unlikely(btrfs_inode_generation(leaf, iitem) > super_gen + 1)) { in check_inode_item()
1112 inode_item_err(leaf, slot, in check_inode_item()
1114 btrfs_inode_generation(leaf, iitem), in check_inode_item()
1119 if (unlikely(btrfs_inode_transid(leaf, iitem) > super_gen + 1)) { in check_inode_item()
1120 inode_item_err(leaf, slot, in check_inode_item()
1122 btrfs_inode_transid(leaf, iitem), super_gen + 1); in check_inode_item()
1131 mode = btrfs_inode_mode(leaf, iitem); in check_inode_item()
1133 inode_item_err(leaf, slot, in check_inode_item()
1146 inode_item_err(leaf, slot, in check_inode_item()
1152 if (unlikely(S_ISDIR(mode) && btrfs_inode_nlink(leaf, iitem) > 1)) { in check_inode_item()
1153 inode_item_err(leaf, slot, in check_inode_item()
1155 btrfs_inode_nlink(leaf, iitem)); in check_inode_item()
1158 btrfs_inode_split_flags(btrfs_inode_flags(leaf, iitem), &flags, &ro_flags); in check_inode_item()
1160 inode_item_err(leaf, slot, in check_inode_item()
1166 inode_item_err(leaf, slot, in check_inode_item()
1174 static int check_root_item(struct extent_buffer *leaf, struct btrfs_key *key, in check_root_item() argument
1177 struct btrfs_fs_info *fs_info = leaf->fs_info; in check_root_item()
1183 ret = check_root_key(leaf, key, slot); in check_root_item()
1187 if (unlikely(btrfs_item_size(leaf, slot) != sizeof(ri) && in check_root_item()
1188 btrfs_item_size(leaf, slot) != in check_root_item()
1190 generic_err(leaf, slot, in check_root_item()
1192 btrfs_item_size(leaf, slot), sizeof(ri), in check_root_item()
1202 read_extent_buffer(leaf, &ri, btrfs_item_ptr_offset(leaf, slot), in check_root_item()
1203 btrfs_item_size(leaf, slot)); in check_root_item()
1208 generic_err(leaf, slot, in check_root_item()
1216 generic_err(leaf, slot, in check_root_item()
1224 generic_err(leaf, slot, in check_root_item()
1233 generic_err(leaf, slot, in check_root_item()
1239 generic_err(leaf, slot, in check_root_item()
1245 generic_err(leaf, slot, in check_root_item()
1253 generic_err(leaf, slot, in check_root_item()
1288 btrfs_header_level(eb) == 0 ? "leaf" : "node", in extent_err()
1306 static int check_extent_item(struct extent_buffer *leaf, in check_extent_item() argument
1310 struct btrfs_fs_info *fs_info = leaf->fs_info; in check_extent_item()
1315 const u32 item_size = btrfs_item_size(leaf, slot); in check_extent_item()
1325 generic_err(leaf, slot, in check_extent_item()
1331 generic_err(leaf, slot, in check_extent_item()
1340 extent_err(leaf, slot, in check_extent_item()
1378 extent_err(leaf, slot, in check_extent_item()
1384 end = item_size + btrfs_item_ptr_offset(leaf, slot); in check_extent_item()
1387 ei = btrfs_item_ptr(leaf, slot, struct btrfs_extent_item); in check_extent_item()
1388 flags = btrfs_extent_flags(leaf, ei); in check_extent_item()
1389 total_refs = btrfs_extent_refs(leaf, ei); in check_extent_item()
1390 generation = btrfs_extent_generation(leaf, ei); in check_extent_item()
1393 extent_err(leaf, slot, in check_extent_item()
1401 extent_err(leaf, slot, in check_extent_item()
1411 extent_err(leaf, slot, in check_extent_item()
1418 extent_err(leaf, slot, in check_extent_item()
1424 extent_err(leaf, slot, in check_extent_item()
1430 extent_err(leaf, slot, in check_extent_item()
1442 if (unlikely(btrfs_tree_block_level(leaf, info) >= BTRFS_MAX_LEVEL)) { in check_extent_item()
1443 extent_err(leaf, slot, in check_extent_item()
1445 btrfs_tree_block_level(leaf, info), in check_extent_item()
1465 extent_err(leaf, slot, in check_extent_item()
1471 inline_type = btrfs_extent_inline_ref_type(leaf, iref); in check_extent_item()
1472 inline_offset = btrfs_extent_inline_ref_offset(leaf, iref); in check_extent_item()
1475 extent_err(leaf, slot, in check_extent_item()
1490 extent_err(leaf, slot, in check_extent_item()
1503 dref_root = btrfs_extent_data_ref_root(leaf, dref); in check_extent_item()
1504 dref_objectid = btrfs_extent_data_ref_objectid(leaf, dref); in check_extent_item()
1505 dref_offset = btrfs_extent_data_ref_offset(leaf, dref); in check_extent_item()
1507 btrfs_extent_data_ref_root(leaf, dref), in check_extent_item()
1508 btrfs_extent_data_ref_objectid(leaf, dref), in check_extent_item()
1509 btrfs_extent_data_ref_offset(leaf, dref)); in check_extent_item()
1511 extent_err(leaf, slot, in check_extent_item()
1518 extent_err(leaf, slot, in check_extent_item()
1525 extent_err(leaf, slot, in check_extent_item()
1530 inline_refs += btrfs_extent_data_ref_count(leaf, dref); in check_extent_item()
1537 extent_err(leaf, slot, in check_extent_item()
1542 inline_refs += btrfs_shared_data_ref_count(leaf, sref); in check_extent_item()
1548 extent_err(leaf, slot, "unknown inline ref type: %u", in check_extent_item()
1553 extent_err(leaf, slot, in check_extent_item()
1562 extent_err(leaf, slot, in check_extent_item()
1574 extent_err(leaf, slot, in check_extent_item()
1581 extent_err(leaf, slot, in check_extent_item()
1597 extent_err(leaf, slot, in check_extent_item()
1609 static int check_simple_keyed_refs(struct extent_buffer *leaf, in check_simple_keyed_refs() argument
1617 if (unlikely(btrfs_item_size(leaf, slot) != expect_item_size)) { in check_simple_keyed_refs()
1618 generic_err(leaf, slot, in check_simple_keyed_refs()
1620 btrfs_item_size(leaf, slot), in check_simple_keyed_refs()
1624 if (unlikely(!IS_ALIGNED(key->objectid, leaf->fs_info->sectorsize))) { in check_simple_keyed_refs()
1625 generic_err(leaf, slot, in check_simple_keyed_refs()
1627 key->objectid, leaf->fs_info->sectorsize); in check_simple_keyed_refs()
1631 !IS_ALIGNED(key->offset, leaf->fs_info->sectorsize))) { in check_simple_keyed_refs()
1632 extent_err(leaf, slot, in check_simple_keyed_refs()
1634 key->offset, leaf->fs_info->sectorsize); in check_simple_keyed_refs()
1640 static int check_extent_data_ref(struct extent_buffer *leaf, in check_extent_data_ref() argument
1644 unsigned long ptr = btrfs_item_ptr_offset(leaf, slot); in check_extent_data_ref()
1645 const unsigned long end = ptr + btrfs_item_size(leaf, slot); in check_extent_data_ref()
1647 if (unlikely(btrfs_item_size(leaf, slot) % sizeof(*dref) != 0)) { in check_extent_data_ref()
1648 generic_err(leaf, slot, in check_extent_data_ref()
1650 btrfs_item_size(leaf, slot), in check_extent_data_ref()
1654 if (unlikely(!IS_ALIGNED(key->objectid, leaf->fs_info->sectorsize))) { in check_extent_data_ref()
1655 generic_err(leaf, slot, in check_extent_data_ref()
1657 key->objectid, leaf->fs_info->sectorsize); in check_extent_data_ref()
1667 * overflow from the leaf due to hash collisions. in check_extent_data_ref()
1670 root = btrfs_extent_data_ref_root(leaf, dref); in check_extent_data_ref()
1671 objectid = btrfs_extent_data_ref_objectid(leaf, dref); in check_extent_data_ref()
1672 offset = btrfs_extent_data_ref_offset(leaf, dref); in check_extent_data_ref()
1674 extent_err(leaf, slot, in check_extent_data_ref()
1681 extent_err(leaf, slot, in check_extent_data_ref()
1686 if (unlikely(!IS_ALIGNED(offset, leaf->fs_info->sectorsize))) { in check_extent_data_ref()
1687 extent_err(leaf, slot, in check_extent_data_ref()
1689 offset, leaf->fs_info->sectorsize); in check_extent_data_ref()
1698 static int check_inode_ref(struct extent_buffer *leaf, in check_inode_ref() argument
1706 if (unlikely(!check_prev_ino(leaf, key, slot, prev_key))) in check_inode_ref()
1709 if (unlikely(btrfs_item_size(leaf, slot) <= sizeof(*iref))) { in check_inode_ref()
1710 inode_ref_err(leaf, slot, in check_inode_ref()
1712 btrfs_item_size(leaf, slot), in check_inode_ref()
1713 sizeof(*iref), BTRFS_LEAF_DATA_SIZE(leaf->fs_info)); in check_inode_ref()
1717 ptr = btrfs_item_ptr_offset(leaf, slot); in check_inode_ref()
1718 end = ptr + btrfs_item_size(leaf, slot); in check_inode_ref()
1723 inode_ref_err(leaf, slot, in check_inode_ref()
1730 namelen = btrfs_inode_ref_name_len(leaf, iref); in check_inode_ref()
1732 inode_ref_err(leaf, slot, in check_inode_ref()
1748 static int check_raid_stripe_extent(const struct extent_buffer *leaf, in check_raid_stripe_extent() argument
1751 if (unlikely(!IS_ALIGNED(key->objectid, leaf->fs_info->sectorsize))) { in check_raid_stripe_extent()
1752 generic_err(leaf, slot, in check_raid_stripe_extent()
1754 key->objectid, leaf->fs_info->sectorsize); in check_raid_stripe_extent()
1758 if (unlikely(!btrfs_fs_incompat(leaf->fs_info, RAID_STRIPE_TREE))) { in check_raid_stripe_extent()
1759 generic_err(leaf, slot, in check_raid_stripe_extent()
1767 static int check_dev_extent_item(const struct extent_buffer *leaf, in check_dev_extent_item() argument
1773 const u32 sectorsize = leaf->fs_info->sectorsize; in check_dev_extent_item()
1775 de = btrfs_item_ptr(leaf, slot, struct btrfs_dev_extent); in check_dev_extent_item()
1777 if (unlikely(btrfs_dev_extent_chunk_tree(leaf, de) != in check_dev_extent_item()
1779 generic_err(leaf, slot, in check_dev_extent_item()
1781 btrfs_dev_extent_chunk_tree(leaf, de), in check_dev_extent_item()
1785 if (unlikely(btrfs_dev_extent_chunk_objectid(leaf, de) != in check_dev_extent_item()
1787 generic_err(leaf, slot, in check_dev_extent_item()
1789 btrfs_dev_extent_chunk_objectid(leaf, de), in check_dev_extent_item()
1795 generic_err(leaf, slot, in check_dev_extent_item()
1800 if (unlikely(!IS_ALIGNED(btrfs_dev_extent_chunk_offset(leaf, de), in check_dev_extent_item()
1802 generic_err(leaf, slot, in check_dev_extent_item()
1804 btrfs_dev_extent_chunk_objectid(leaf, de), in check_dev_extent_item()
1808 if (unlikely(!IS_ALIGNED(btrfs_dev_extent_length(leaf, de), in check_dev_extent_item()
1810 generic_err(leaf, slot, in check_dev_extent_item()
1812 btrfs_dev_extent_length(leaf, de), sectorsize); in check_dev_extent_item()
1821 prev_de = btrfs_item_ptr(leaf, slot - 1, struct btrfs_dev_extent); in check_dev_extent_item()
1822 prev_len = btrfs_dev_extent_length(leaf, prev_de); in check_dev_extent_item()
1824 generic_err(leaf, slot, in check_dev_extent_item()
1836 static enum btrfs_tree_block_status check_leaf_item(struct extent_buffer *leaf, in check_leaf_item() argument
1846 ret = check_extent_data_item(leaf, key, slot, prev_key); in check_leaf_item()
1849 ret = check_csum_item(leaf, key, slot, prev_key); in check_leaf_item()
1854 ret = check_dir_item(leaf, key, prev_key, slot); in check_leaf_item()
1857 ret = check_inode_ref(leaf, key, prev_key, slot); in check_leaf_item()
1860 ret = check_block_group_item(leaf, key, slot); in check_leaf_item()
1863 chunk = btrfs_item_ptr(leaf, slot, struct btrfs_chunk); in check_leaf_item()
1864 ret = check_leaf_chunk_item(leaf, chunk, key, slot); in check_leaf_item()
1867 ret = check_dev_item(leaf, key, slot); in check_leaf_item()
1870 ret = check_dev_extent_item(leaf, key, slot, prev_key); in check_leaf_item()
1873 ret = check_inode_item(leaf, key, slot); in check_leaf_item()
1876 ret = check_root_item(leaf, key, slot); in check_leaf_item()
1880 ret = check_extent_item(leaf, key, slot, prev_key); in check_leaf_item()
1885 ret = check_simple_keyed_refs(leaf, key, slot); in check_leaf_item()
1888 ret = check_extent_data_ref(leaf, key, slot); in check_leaf_item()
1891 ret = check_raid_stripe_extent(leaf, key, slot); in check_leaf_item()
1900 enum btrfs_tree_block_status __btrfs_check_leaf(struct extent_buffer *leaf) in __btrfs_check_leaf() argument
1902 struct btrfs_fs_info *fs_info = leaf->fs_info; in __btrfs_check_leaf()
1906 u32 nritems = btrfs_header_nritems(leaf); in __btrfs_check_leaf()
1909 if (unlikely(btrfs_header_level(leaf) != 0)) { in __btrfs_check_leaf()
1910 generic_err(leaf, 0, in __btrfs_check_leaf()
1911 "invalid level for leaf, have %d expect 0", in __btrfs_check_leaf()
1912 btrfs_header_level(leaf)); in __btrfs_check_leaf()
1916 if (unlikely(!btrfs_header_flag(leaf, BTRFS_HEADER_FLAG_WRITTEN))) { in __btrfs_check_leaf()
1917 generic_err(leaf, 0, "invalid flag for leaf, WRITTEN not set"); in __btrfs_check_leaf()
1929 if (nritems == 0 && !btrfs_header_flag(leaf, BTRFS_HEADER_FLAG_RELOC)) { in __btrfs_check_leaf()
1930 u64 owner = btrfs_header_owner(leaf); in __btrfs_check_leaf()
1938 generic_err(leaf, 0, in __btrfs_check_leaf()
1946 generic_err(leaf, 0, in __btrfs_check_leaf()
1956 generic_err(leaf, 0, in __btrfs_check_leaf()
1969 * Check the following things to make sure this is a good leaf, and in __btrfs_check_leaf()
1970 * leaf users won't need to bother with similar sanity checks: in __btrfs_check_leaf()
1974 * No overlap, no hole, all inside the leaf. in __btrfs_check_leaf()
1984 btrfs_item_key_to_cpu(leaf, &key, slot); in __btrfs_check_leaf()
1988 generic_err(leaf, slot, in __btrfs_check_leaf()
1996 item_data_end = (u64)btrfs_item_offset(leaf, slot) + in __btrfs_check_leaf()
1997 btrfs_item_size(leaf, slot); in __btrfs_check_leaf()
2000 * item data starts at the end of the leaf and grows towards the in __btrfs_check_leaf()
2006 item_end_expected = btrfs_item_offset(leaf, in __btrfs_check_leaf()
2009 generic_err(leaf, slot, in __btrfs_check_leaf()
2016 * Check to make sure that we don't point outside of the leaf, in __btrfs_check_leaf()
2018 * all point outside of the leaf. in __btrfs_check_leaf()
2021 generic_err(leaf, slot, in __btrfs_check_leaf()
2022 "slot end outside of leaf, have %llu expect range [0, %u]", in __btrfs_check_leaf()
2028 if (unlikely(btrfs_item_ptr_offset(leaf, slot) < in __btrfs_check_leaf()
2029 btrfs_item_nr_offset(leaf, slot) + sizeof(struct btrfs_item))) { in __btrfs_check_leaf()
2030 generic_err(leaf, slot, in __btrfs_check_leaf()
2032 btrfs_item_nr_offset(leaf, slot) + in __btrfs_check_leaf()
2034 btrfs_item_ptr_offset(leaf, slot)); in __btrfs_check_leaf()
2039 ret = check_leaf_item(leaf, &key, slot, &prev_key); in __btrfs_check_leaf()
2051 int btrfs_check_leaf(struct extent_buffer *leaf) in btrfs_check_leaf() argument
2055 ret = __btrfs_check_leaf(leaf); in btrfs_check_leaf()
2163 btrfs_header_level(eb) == 0 ? "leaf" : "node", in btrfs_check_eb_owner()
2178 btrfs_header_level(eb) == 0 ? "leaf" : "node", in btrfs_check_eb_owner()