@@ -1774,61 +1774,65 @@ int bch2_bkey_print_bfloat(struct btree *b, struct bkey_packed *k,
17741774 struct bkey_packed * l , * r , * p ;
17751775 struct bkey uk , up ;
17761776 char buf1 [200 ], buf2 [200 ];
1777- unsigned j ;
1777+ unsigned j , inorder ;
17781778
17791779 if (!size )
17801780 return 0 ;
17811781
17821782 if (!bset_has_ro_aux_tree (t ))
17831783 goto out ;
17841784
1785- j = __inorder_to_eytzinger1 (bkey_to_cacheline (b , t , k ), t -> size , t -> extra );
1786- if (j &&
1787- j < t -> size &&
1788- k == tree_to_bkey (b , t , j ))
1789- switch (bkey_float (b , t , j )-> exponent ) {
1790- case BFLOAT_FAILED_UNPACKED :
1791- uk = bkey_unpack_key (b , k );
1792- return scnprintf (buf , size ,
1793- " failed unpacked at depth %u\n"
1794- "\t%llu:%llu\n" ,
1795- ilog2 (j ),
1796- uk .p .inode , uk .p .offset );
1797- case BFLOAT_FAILED_PREV :
1798- p = tree_to_prev_bkey (b , t , j );
1799- l = is_power_of_2 (j )
1800- ? btree_bkey_first (b , t )
1801- : tree_to_prev_bkey (b , t , j >> ffs (j ));
1802- r = is_power_of_2 (j + 1 )
1803- ? bch2_bkey_prev_all (b , t , btree_bkey_last (b , t ))
1804- : tree_to_bkey (b , t , j >> (ffz (j ) + 1 ));
1805-
1806- up = bkey_unpack_key (b , p );
1807- uk = bkey_unpack_key (b , k );
1808- bch2_to_binary (buf1 , high_word (& b -> format , p ), b -> nr_key_bits );
1809- bch2_to_binary (buf2 , high_word (& b -> format , k ), b -> nr_key_bits );
1810-
1811- return scnprintf (buf , size ,
1812- " failed prev at depth %u\n"
1813- "\tkey starts at bit %u but first differing bit at %u\n"
1814- "\t%llu:%llu\n"
1815- "\t%llu:%llu\n"
1816- "\t%s\n"
1817- "\t%s\n" ,
1818- ilog2 (j ),
1819- bch2_bkey_greatest_differing_bit (b , l , r ),
1820- bch2_bkey_greatest_differing_bit (b , p , k ),
1821- uk .p .inode , uk .p .offset ,
1822- up .p .inode , up .p .offset ,
1823- buf1 , buf2 );
1824- case BFLOAT_FAILED_OVERFLOW :
1825- uk = bkey_unpack_key (b , k );
1826- return scnprintf (buf , size ,
1827- " failed overflow at depth %u\n"
1828- "\t%llu:%llu\n" ,
1829- ilog2 (j ),
1830- uk .p .inode , uk .p .offset );
1831- }
1785+ inorder = bkey_to_cacheline (b , t , k );
1786+ if (!inorder || inorder >= t -> size )
1787+ goto out ;
1788+
1789+ j = __inorder_to_eytzinger1 (inorder , t -> size , t -> extra );
1790+ if (k != tree_to_bkey (b , t , j ))
1791+ goto out ;
1792+
1793+ switch (bkey_float (b , t , j )-> exponent ) {
1794+ case BFLOAT_FAILED_UNPACKED :
1795+ uk = bkey_unpack_key (b , k );
1796+ return scnprintf (buf , size ,
1797+ " failed unpacked at depth %u\n"
1798+ "\t%llu:%llu\n" ,
1799+ ilog2 (j ),
1800+ uk .p .inode , uk .p .offset );
1801+ case BFLOAT_FAILED_PREV :
1802+ p = tree_to_prev_bkey (b , t , j );
1803+ l = is_power_of_2 (j )
1804+ ? btree_bkey_first (b , t )
1805+ : tree_to_prev_bkey (b , t , j >> ffs (j ));
1806+ r = is_power_of_2 (j + 1 )
1807+ ? bch2_bkey_prev_all (b , t , btree_bkey_last (b , t ))
1808+ : tree_to_bkey (b , t , j >> (ffz (j ) + 1 ));
1809+
1810+ up = bkey_unpack_key (b , p );
1811+ uk = bkey_unpack_key (b , k );
1812+ bch2_to_binary (buf1 , high_word (& b -> format , p ), b -> nr_key_bits );
1813+ bch2_to_binary (buf2 , high_word (& b -> format , k ), b -> nr_key_bits );
1814+
1815+ return scnprintf (buf , size ,
1816+ " failed prev at depth %u\n"
1817+ "\tkey starts at bit %u but first differing bit at %u\n"
1818+ "\t%llu:%llu\n"
1819+ "\t%llu:%llu\n"
1820+ "\t%s\n"
1821+ "\t%s\n" ,
1822+ ilog2 (j ),
1823+ bch2_bkey_greatest_differing_bit (b , l , r ),
1824+ bch2_bkey_greatest_differing_bit (b , p , k ),
1825+ uk .p .inode , uk .p .offset ,
1826+ up .p .inode , up .p .offset ,
1827+ buf1 , buf2 );
1828+ case BFLOAT_FAILED_OVERFLOW :
1829+ uk = bkey_unpack_key (b , k );
1830+ return scnprintf (buf , size ,
1831+ " failed overflow at depth %u\n"
1832+ "\t%llu:%llu\n" ,
1833+ ilog2 (j ),
1834+ uk .p .inode , uk .p .offset );
1835+ }
18321836out :
18331837 * buf = '\0' ;
18341838 return 0 ;
0 commit comments