Skip to content

Commit 9314e2f

Browse files
author
Kent Overstreet
committed
bcachefs: Fix btree iter flags in data move (2)
Data move -> move_get_io_opts -> bch2_get_update_rebalance_opts requires a not_extents iterator; this fixes the path where we're walking the extents btree and chase a reflink pointer into the reflink btree. bch2_lookup_indirect_extent() requires working with an extents iterator (due to peek_slot() semantics), so we implement bch2_lookup_indirect_extent_for_move(). This is simplified because there's no need to report indirect_extent_missing_errors here, that can be deferred until fsck or when a user reads that data. Reported-by: Maël Kerbiriou <[email protected]> Signed-off-by: Kent Overstreet <[email protected]>
1 parent 19ff84b commit 9314e2f

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

fs/bcachefs/move.c

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,37 @@ int bch2_move_ratelimit(struct moving_context *ctxt)
528528
return 0;
529529
}
530530

531+
/*
532+
* Move requires non extents iterators, and there's also no need for it to
533+
* signal indirect_extent_missing_error:
534+
*/
535+
static struct bkey_s_c bch2_lookup_indirect_extent_for_move(struct btree_trans *trans,
536+
struct btree_iter *iter,
537+
struct bkey_s_c_reflink_p p)
538+
{
539+
if (unlikely(REFLINK_P_ERROR(p.v)))
540+
return bkey_s_c_null;
541+
542+
struct bpos reflink_pos = POS(0, REFLINK_P_IDX(p.v));
543+
544+
bch2_trans_iter_init(trans, iter,
545+
BTREE_ID_reflink, reflink_pos,
546+
BTREE_ITER_not_extents);
547+
548+
struct bkey_s_c k = bch2_btree_iter_peek(iter);
549+
if (!k.k || bkey_err(k)) {
550+
bch2_trans_iter_exit(trans, iter);
551+
return k;
552+
}
553+
554+
if (bkey_lt(reflink_pos, bkey_start_pos(k.k))) {
555+
bch2_trans_iter_exit(trans, iter);
556+
return bkey_s_c_null;
557+
}
558+
559+
return k;
560+
}
561+
531562
static int bch2_move_data_btree(struct moving_context *ctxt,
532563
struct bpos start,
533564
struct bpos end,
@@ -592,17 +623,16 @@ static int bch2_move_data_btree(struct moving_context *ctxt,
592623
k.k->type == KEY_TYPE_reflink_p &&
593624
REFLINK_P_MAY_UPDATE_OPTIONS(bkey_s_c_to_reflink_p(k).v)) {
594625
struct bkey_s_c_reflink_p p = bkey_s_c_to_reflink_p(k);
595-
s64 offset_into_extent = 0;
596626

597627
bch2_trans_iter_exit(trans, &reflink_iter);
598-
k = bch2_lookup_indirect_extent(trans, &reflink_iter, &offset_into_extent, p, true, 0);
628+
k = bch2_lookup_indirect_extent_for_move(trans, &reflink_iter, p);
599629
ret = bkey_err(k);
600630
if (bch2_err_matches(ret, BCH_ERR_transaction_restart))
601631
continue;
602632
if (ret)
603633
break;
604634

605-
if (bkey_deleted(k.k))
635+
if (!k.k)
606636
goto next_nondata;
607637

608638
/*
@@ -611,7 +641,6 @@ static int bch2_move_data_btree(struct moving_context *ctxt,
611641
* pointer - need to fixup iter->k
612642
*/
613643
extent_iter = &reflink_iter;
614-
offset_into_extent = 0;
615644
}
616645

617646
if (!bkey_extent_is_direct_data(k.k))

0 commit comments

Comments
 (0)