5
5
#include "backpointers.h"
6
6
#include "btree_cache.h"
7
7
#include "btree_update.h"
8
+ #include "btree_update_interior.h"
8
9
#include "btree_write_buffer.h"
9
10
#include "error.h"
10
11
@@ -226,6 +227,11 @@ static void backpointer_not_found(struct btree_trans *trans,
226
227
struct printbuf buf = PRINTBUF ;
227
228
struct bpos bucket = bp_pos_to_bucket (c , bp_pos );
228
229
230
+ /*
231
+ * If we're using the btree write buffer, the backpointer we were
232
+ * looking at may have already been deleted - failure to find what it
233
+ * pointed to is not an error:
234
+ */
229
235
if (likely (!bch2_backpointers_no_use_write_buffer ))
230
236
return ;
231
237
@@ -256,56 +262,37 @@ struct bkey_s_c bch2_backpointer_get_key(struct btree_trans *trans,
256
262
struct bch_backpointer bp ,
257
263
unsigned iter_flags )
258
264
{
259
- struct bch_fs * c = trans -> c ;
260
- struct btree_root * r = bch2_btree_id_root (c , bp .btree_id );
261
- struct bpos bucket = bp_pos_to_bucket (c , bp_pos );
262
- struct bkey_s_c k ;
263
-
264
- bch2_trans_node_iter_init (trans , iter ,
265
- bp .btree_id ,
266
- bp .pos ,
267
- 0 ,
268
- min (bp .level , r -> level ),
269
- iter_flags );
270
- k = bch2_btree_iter_peek_slot (iter );
271
- if (bkey_err (k )) {
272
- bch2_trans_iter_exit (trans , iter );
273
- return k ;
274
- }
275
-
276
- if (bp .level == r -> level + 1 )
277
- k = bkey_i_to_s_c (& r -> key );
278
-
279
- if (k .k && extent_matches_bp (c , bp .btree_id , bp .level , k , bucket , bp ))
280
- return k ;
281
-
282
- bch2_trans_iter_exit (trans , iter );
265
+ if (likely (!bp .level )) {
266
+ struct bch_fs * c = trans -> c ;
267
+ struct bpos bucket = bp_pos_to_bucket (c , bp_pos );
268
+ struct bkey_s_c k ;
269
+
270
+ bch2_trans_node_iter_init (trans , iter ,
271
+ bp .btree_id ,
272
+ bp .pos ,
273
+ 0 , 0 ,
274
+ iter_flags );
275
+ k = bch2_btree_iter_peek_slot (iter );
276
+ if (bkey_err (k )) {
277
+ bch2_trans_iter_exit (trans , iter );
278
+ return k ;
279
+ }
283
280
284
- if (unlikely (bch2_backpointers_no_use_write_buffer )) {
285
- if (bp .level ) {
286
- struct btree * b ;
281
+ if (k .k && extent_matches_bp (c , bp .btree_id , bp .level , k , bucket , bp ))
282
+ return k ;
287
283
288
- /*
289
- * If a backpointer for a btree node wasn't found, it may be
290
- * because it was overwritten by a new btree node that hasn't
291
- * been written out yet - backpointer_get_node() checks for
292
- * this:
293
- */
294
- b = bch2_backpointer_get_node (trans , iter , bp_pos , bp );
295
- if (!IS_ERR_OR_NULL (b ))
296
- return bkey_i_to_s_c (& b -> key );
284
+ bch2_trans_iter_exit (trans , iter );
285
+ backpointer_not_found (trans , bp_pos , bp , k );
286
+ return bkey_s_c_null ;
287
+ } else {
288
+ struct btree * b = bch2_backpointer_get_node (trans , iter , bp_pos , bp );
297
289
290
+ if (IS_ERR_OR_NULL (b )) {
298
291
bch2_trans_iter_exit (trans , iter );
299
-
300
- if (IS_ERR (b ))
301
- return bkey_s_c_err (PTR_ERR (b ));
302
- return bkey_s_c_null ;
292
+ return IS_ERR (b ) ? bkey_s_c_err (PTR_ERR (b )) : bkey_s_c_null ;
303
293
}
304
-
305
- backpointer_not_found (trans , bp_pos , bp , k );
294
+ return bkey_i_to_s_c (& b -> key );
306
295
}
307
-
308
- return bkey_s_c_null ;
309
296
}
310
297
311
298
struct btree * bch2_backpointer_get_node (struct btree_trans * trans ,
@@ -329,6 +316,8 @@ struct btree *bch2_backpointer_get_node(struct btree_trans *trans,
329
316
if (IS_ERR (b ))
330
317
goto err ;
331
318
319
+ BUG_ON (b -> c .level != bp .level - 1 );
320
+
332
321
if (b && extent_matches_bp (c , bp .btree_id , bp .level ,
333
322
bkey_i_to_s_c (& b -> key ),
334
323
bucket , bp ))
0 commit comments