@@ -99,7 +99,7 @@ static void btree_node_interior_verify(struct bch_fs *c, struct btree *b)
99
99
100
100
/* Calculate ideal packed bkey format for new btree nodes: */
101
101
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 )
103
103
{
104
104
struct bkey_packed * k ;
105
105
struct bset_tree * t ;
@@ -125,38 +125,39 @@ static struct bkey_format bch2_btree_calc_format(struct btree *b)
125
125
return bch2_bkey_format_done (& s );
126
126
}
127
127
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 ,
129
130
struct bkey_format * new_f )
130
131
{
131
- struct bkey_format * old_f = & b -> format ;
132
-
133
132
/* stupid integer promotion rules */
134
133
ssize_t delta =
135
134
(((int ) new_f -> key_u64s - old_f -> key_u64s ) *
136
- (int ) b -> nr .packed_keys ) +
135
+ (int ) nr .packed_keys ) +
137
136
(((int ) new_f -> key_u64s - BKEY_U64s ) *
138
- (int ) b -> nr .unpacked_keys );
137
+ (int ) nr .unpacked_keys );
139
138
140
- BUG_ON (delta + b -> nr .live_u64s < 0 );
139
+ BUG_ON (delta + nr .live_u64s < 0 );
141
140
142
- return b -> nr .live_u64s + delta ;
141
+ return nr .live_u64s + delta ;
143
142
}
144
143
145
144
/**
146
145
* bch2_btree_node_format_fits - check if we could rewrite node with a new format
147
146
*
148
147
* @c: filesystem handle
149
148
* @b: btree node to rewrite
149
+ * @nr: number of keys for new node (i.e. b->nr)
150
150
* @new_f: bkey format to translate keys to
151
151
*
152
152
* Returns: true if all re-packed keys will be able to fit in a new node.
153
153
*
154
154
* Assumes all keys will successfully pack with the new format.
155
155
*/
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 ,
157
158
struct bkey_format * new_f )
158
159
{
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 );
160
161
161
162
return __vstruct_bytes (struct btree_node , u64s ) < btree_bytes (c );
162
163
}
@@ -391,7 +392,7 @@ static struct btree *bch2_btree_node_alloc_replacement(struct btree_update *as,
391
392
* The keys might expand with the new format - if they wouldn't fit in
392
393
* the btree node anymore, use the old format for now:
393
394
*/
394
- if (!bch2_btree_node_format_fits (as -> c , b , & format ))
395
+ if (!bch2_btree_node_format_fits (as -> c , b , b -> nr , & format ))
395
396
format = b -> format ;
396
397
397
398
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,
1822
1823
bch2_bkey_format_add_pos (& new_s , next -> data -> max_key );
1823
1824
new_f = bch2_bkey_format_done (& new_s );
1824
1825
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 );
1827
1828
1828
1829
if (sib_u64s > BTREE_FOREGROUND_MERGE_HYSTERESIS (c )) {
1829
1830
sib_u64s -= BTREE_FOREGROUND_MERGE_HYSTERESIS (c );
0 commit comments