@@ -99,7 +99,7 @@ static void btree_node_interior_verify(struct bch_fs *c, struct btree *b)
9999
100100/* Calculate ideal packed bkey format for new btree nodes: */
101101
102- void __bch2_btree_calc_format (struct bkey_format_state * s , struct btree * b )
102+ static void __bch2_btree_calc_format (struct bkey_format_state * s , struct btree * b )
103103{
104104 struct bkey_packed * k ;
105105 struct bset_tree * t ;
@@ -125,38 +125,39 @@ static struct bkey_format bch2_btree_calc_format(struct btree *b)
125125 return bch2_bkey_format_done (& s );
126126}
127127
128- static size_t btree_node_u64s_with_format (struct btree * b ,
128+ static size_t btree_node_u64s_with_format (struct btree_nr_keys nr ,
129+ struct bkey_format * old_f ,
129130 struct bkey_format * new_f )
130131{
131- struct bkey_format * old_f = & b -> format ;
132-
133132 /* stupid integer promotion rules */
134133 ssize_t delta =
135134 (((int ) new_f -> key_u64s - old_f -> key_u64s ) *
136- (int ) b -> nr .packed_keys ) +
135+ (int ) nr .packed_keys ) +
137136 (((int ) new_f -> key_u64s - BKEY_U64s ) *
138- (int ) b -> nr .unpacked_keys );
137+ (int ) nr .unpacked_keys );
139138
140- BUG_ON (delta + b -> nr .live_u64s < 0 );
139+ BUG_ON (delta + nr .live_u64s < 0 );
141140
142- return b -> nr .live_u64s + delta ;
141+ return nr .live_u64s + delta ;
143142}
144143
145144/**
146145 * bch2_btree_node_format_fits - check if we could rewrite node with a new format
147146 *
148147 * @c: filesystem handle
149148 * @b: btree node to rewrite
149+ * @nr: number of keys for new node (i.e. b->nr)
150150 * @new_f: bkey format to translate keys to
151151 *
152152 * Returns: true if all re-packed keys will be able to fit in a new node.
153153 *
154154 * Assumes all keys will successfully pack with the new format.
155155 */
156- bool bch2_btree_node_format_fits (struct bch_fs * c , struct btree * b ,
156+ static bool bch2_btree_node_format_fits (struct bch_fs * c , struct btree * b ,
157+ struct btree_nr_keys nr ,
157158 struct bkey_format * new_f )
158159{
159- size_t u64s = btree_node_u64s_with_format (b , new_f );
160+ size_t u64s = btree_node_u64s_with_format (nr , & b -> format , new_f );
160161
161162 return __vstruct_bytes (struct btree_node , u64s ) < btree_bytes (c );
162163}
@@ -391,7 +392,7 @@ static struct btree *bch2_btree_node_alloc_replacement(struct btree_update *as,
391392 * The keys might expand with the new format - if they wouldn't fit in
392393 * the btree node anymore, use the old format for now:
393394 */
394- if (!bch2_btree_node_format_fits (as -> c , b , & format ))
395+ if (!bch2_btree_node_format_fits (as -> c , b , b -> nr , & format ))
395396 format = b -> format ;
396397
397398 SET_BTREE_NODE_SEQ (n -> data , BTREE_NODE_SEQ (b -> data ) + 1 );
@@ -1822,8 +1823,8 @@ int __bch2_foreground_maybe_merge(struct btree_trans *trans,
18221823 bch2_bkey_format_add_pos (& new_s , next -> data -> max_key );
18231824 new_f = bch2_bkey_format_done (& new_s );
18241825
1825- sib_u64s = btree_node_u64s_with_format (b , & new_f ) +
1826- btree_node_u64s_with_format (m , & new_f );
1826+ sib_u64s = btree_node_u64s_with_format (b -> nr , & b -> format , & new_f ) +
1827+ btree_node_u64s_with_format (m -> nr , & m -> format , & new_f );
18271828
18281829 if (sib_u64s > BTREE_FOREGROUND_MERGE_HYSTERESIS (c )) {
18291830 sib_u64s -= BTREE_FOREGROUND_MERGE_HYSTERESIS (c );
0 commit comments