Skip to content

Commit

Permalink
bcachefs: discard_one_bucket() now uses need_discard_or_freespace_err()
Browse files Browse the repository at this point in the history
More conversion of inconsistent errors to fsck errors.

Signed-off-by: Kent Overstreet <[email protected]>
  • Loading branch information
Kent Overstreet committed Nov 15, 2024
1 parent ae3f844 commit c7e3dd8
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions fs/bcachefs/alloc_background.c
Original file line number Diff line number Diff line change
Expand Up @@ -1770,11 +1770,13 @@ static int bch2_discard_one_bucket(struct btree_trans *trans,
goto out;

if (a->v.data_type != BCH_DATA_need_discard) {
if (bch2_trans_inconsistent_on(c->curr_recovery_pass > BCH_RECOVERY_PASS_check_alloc_info,
trans, "bucket incorrectly set in need_discard btree\n"
"%s",
(bch2_bkey_val_to_text(&buf, c, k), buf.buf)))
ret = -EIO;
if (need_discard_or_freespace_err(trans, k, true, true, true)) {
ret = bch2_btree_bit_mod_iter(trans, need_discard_iter, false);
if (ret)
goto out;
goto commit;
}

goto out;
}

Expand Down Expand Up @@ -1814,16 +1816,20 @@ static int bch2_discard_one_bucket(struct btree_trans *trans,
SET_BCH_ALLOC_V4_NEED_DISCARD(&a->v, false);
alloc_data_type_set(&a->v, a->v.data_type);

ret = bch2_trans_update(trans, &iter, &a->k_i, 0) ?:
bch2_trans_commit(trans, NULL, NULL,
BCH_WATERMARK_btree|
BCH_TRANS_COMMIT_no_enospc);
ret = bch2_trans_update(trans, &iter, &a->k_i, 0);
if (ret)
goto out;
commit:
ret = bch2_trans_commit(trans, NULL, NULL,
BCH_WATERMARK_btree|
BCH_TRANS_COMMIT_no_enospc);
if (ret)
goto out;

count_event(c, bucket_discard);
s->discarded++;
out:
fsck_err:
if (discard_locked)
discard_in_flight_remove(ca, iter.pos.offset);
s->seen++;
Expand Down

0 comments on commit c7e3dd8

Please sign in to comment.