@@ -1678,7 +1678,7 @@ static enum btrfs_tree_block_status check_leaf_item(struct extent_buffer *leaf,
1678
1678
return BTRFS_TREE_BLOCK_CLEAN ;
1679
1679
}
1680
1680
1681
- int btrfs_check_leaf (struct extent_buffer * leaf )
1681
+ enum btrfs_tree_block_status __btrfs_check_leaf (struct extent_buffer * leaf )
1682
1682
{
1683
1683
struct btrfs_fs_info * fs_info = leaf -> fs_info ;
1684
1684
/* No valid key type is 0, so all key should be larger than this key */
@@ -1691,7 +1691,7 @@ int btrfs_check_leaf(struct extent_buffer *leaf)
1691
1691
generic_err (leaf , 0 ,
1692
1692
"invalid level for leaf, have %d expect 0" ,
1693
1693
btrfs_header_level (leaf ));
1694
- return - EUCLEAN ;
1694
+ return BTRFS_TREE_BLOCK_INVALID_LEVEL ;
1695
1695
}
1696
1696
1697
1697
/*
@@ -1714,32 +1714,32 @@ int btrfs_check_leaf(struct extent_buffer *leaf)
1714
1714
generic_err (leaf , 0 ,
1715
1715
"invalid root, root %llu must never be empty" ,
1716
1716
owner );
1717
- return - EUCLEAN ;
1717
+ return BTRFS_TREE_BLOCK_INVALID_NRITEMS ;
1718
1718
}
1719
1719
1720
1720
/* Unknown tree */
1721
1721
if (unlikely (owner == 0 )) {
1722
1722
generic_err (leaf , 0 ,
1723
1723
"invalid owner, root 0 is not defined" );
1724
- return - EUCLEAN ;
1724
+ return BTRFS_TREE_BLOCK_INVALID_OWNER ;
1725
1725
}
1726
1726
1727
1727
/* EXTENT_TREE_V2 can have empty extent trees. */
1728
1728
if (btrfs_fs_incompat (fs_info , EXTENT_TREE_V2 ))
1729
- return 0 ;
1729
+ return BTRFS_TREE_BLOCK_CLEAN ;
1730
1730
1731
1731
if (unlikely (owner == BTRFS_EXTENT_TREE_OBJECTID )) {
1732
1732
generic_err (leaf , 0 ,
1733
1733
"invalid root, root %llu must never be empty" ,
1734
1734
owner );
1735
- return - EUCLEAN ;
1735
+ return BTRFS_TREE_BLOCK_INVALID_NRITEMS ;
1736
1736
}
1737
1737
1738
- return 0 ;
1738
+ return BTRFS_TREE_BLOCK_CLEAN ;
1739
1739
}
1740
1740
1741
1741
if (unlikely (nritems == 0 ))
1742
- return 0 ;
1742
+ return BTRFS_TREE_BLOCK_CLEAN ;
1743
1743
1744
1744
/*
1745
1745
* Check the following things to make sure this is a good leaf, and
@@ -1765,7 +1765,7 @@ int btrfs_check_leaf(struct extent_buffer *leaf)
1765
1765
prev_key .objectid , prev_key .type ,
1766
1766
prev_key .offset , key .objectid , key .type ,
1767
1767
key .offset );
1768
- return - EUCLEAN ;
1768
+ return BTRFS_TREE_BLOCK_BAD_KEY_ORDER ;
1769
1769
}
1770
1770
1771
1771
item_data_end = (u64 )btrfs_item_offset (leaf , slot ) +
@@ -1784,7 +1784,7 @@ int btrfs_check_leaf(struct extent_buffer *leaf)
1784
1784
generic_err (leaf , slot ,
1785
1785
"unexpected item end, have %llu expect %u" ,
1786
1786
item_data_end , item_end_expected );
1787
- return - EUCLEAN ;
1787
+ return BTRFS_TREE_BLOCK_INVALID_OFFSETS ;
1788
1788
}
1789
1789
1790
1790
/*
@@ -1796,7 +1796,7 @@ int btrfs_check_leaf(struct extent_buffer *leaf)
1796
1796
generic_err (leaf , slot ,
1797
1797
"slot end outside of leaf, have %llu expect range [0, %u]" ,
1798
1798
item_data_end , BTRFS_LEAF_DATA_SIZE (fs_info ));
1799
- return - EUCLEAN ;
1799
+ return BTRFS_TREE_BLOCK_INVALID_OFFSETS ;
1800
1800
}
1801
1801
1802
1802
/* Also check if the item pointer overlaps with btrfs item. */
@@ -1807,7 +1807,7 @@ int btrfs_check_leaf(struct extent_buffer *leaf)
1807
1807
btrfs_item_nr_offset (leaf , slot ) +
1808
1808
sizeof (struct btrfs_item ),
1809
1809
btrfs_item_ptr_offset (leaf , slot ));
1810
- return - EUCLEAN ;
1810
+ return BTRFS_TREE_BLOCK_INVALID_OFFSETS ;
1811
1811
}
1812
1812
1813
1813
/*
@@ -1823,14 +1823,24 @@ int btrfs_check_leaf(struct extent_buffer *leaf)
1823
1823
*/
1824
1824
ret = check_leaf_item (leaf , & key , slot , & prev_key );
1825
1825
if (unlikely (ret != BTRFS_TREE_BLOCK_CLEAN ))
1826
- return - EUCLEAN ;
1826
+ return ret ;
1827
1827
}
1828
1828
1829
1829
prev_key .objectid = key .objectid ;
1830
1830
prev_key .type = key .type ;
1831
1831
prev_key .offset = key .offset ;
1832
1832
}
1833
1833
1834
+ return BTRFS_TREE_BLOCK_CLEAN ;
1835
+ }
1836
+
1837
+ int btrfs_check_leaf (struct extent_buffer * leaf )
1838
+ {
1839
+ enum btrfs_tree_block_status ret ;
1840
+
1841
+ ret = __btrfs_check_leaf (leaf );
1842
+ if (unlikely (ret != BTRFS_TREE_BLOCK_CLEAN ))
1843
+ return - EUCLEAN ;
1834
1844
return 0 ;
1835
1845
}
1836
1846
ALLOW_ERROR_INJECTION (btrfs_check_leaf , ERRNO );
0 commit comments