Skip to content

Commit

Permalink
bcachefs: Fix bch2_indirect_extent_missing_error()
Browse files Browse the repository at this point in the history
We had some error handling confusion here;
-BCH_ERR_missing_indirect_extent is thrown by
trans_trigger_reflink_p_segment(); at this point we haven't decide
whether we're generating an error.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
  • Loading branch information
Kent Overstreet committed Feb 19, 2025
1 parent b9ddb3e commit 4fd509c
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions fs/bcachefs/reflink.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ static int bch2_indirect_extent_missing_error(struct btree_trans *trans,
bool should_commit)
{
if (REFLINK_P_ERROR(p.v))
return -BCH_ERR_missing_indirect_extent;
return 0;

struct bch_fs *c = trans->c;
u64 live_start = REFLINK_P_IDX(p.v);
Expand Down Expand Up @@ -259,23 +259,23 @@ struct bkey_s_c bch2_lookup_indirect_extent(struct btree_trans *trans,
return k;

if (unlikely(!bkey_extent_is_reflink_data(k.k))) {
bch2_trans_iter_exit(trans, iter);

unsigned size = min((u64) k.k->size,
REFLINK_P_IDX(p.v) + p.k->size + le32_to_cpu(p.v->back_pad) -
reflink_offset);
bch2_key_resize(&iter->k, size);

int ret = bch2_indirect_extent_missing_error(trans, p, reflink_offset,
k.k->p.offset, should_commit);
if (ret)
if (ret) {
bch2_trans_iter_exit(trans, iter);
return bkey_s_c_err(ret);
}
} else if (unlikely(REFLINK_P_ERROR(p.v))) {
bch2_trans_iter_exit(trans, iter);

int ret = bch2_indirect_extent_not_missing(trans, p, should_commit);
if (ret)
if (ret) {
bch2_trans_iter_exit(trans, iter);
return bkey_s_c_err(ret);
}
}

*offset_into_extent = reflink_offset - bkey_start_offset(k.k);
Expand All @@ -300,7 +300,7 @@ static int trans_trigger_reflink_p_segment(struct btree_trans *trans,
if (ret)
return ret;

if (bkey_deleted(k.k)) {
if (!bkey_refcount_c(k)) {
if (!(flags & BTREE_TRIGGER_overwrite))
ret = -BCH_ERR_missing_indirect_extent;
goto next;
Expand Down Expand Up @@ -381,8 +381,6 @@ static s64 gc_trigger_reflink_p_segment(struct btree_trans *trans,
not_found:
if (flags & BTREE_TRIGGER_check_repair) {
ret = bch2_indirect_extent_missing_error(trans, p, *idx, next_idx, false);
if (ret == -BCH_ERR_missing_indirect_extent)
ret = 0;
if (ret)
goto err;
}
Expand Down

0 comments on commit 4fd509c

Please sign in to comment.