182 lines
6.0 KiB
Diff
182 lines
6.0 KiB
Diff
From 283dcbb80c18b9d9cc2f17dc81bfb2a049cbef0e Mon Sep 17 00:00:00 2001
|
|
From: Kent Overstreet <kent.overstreet@linux.dev>
|
|
Date: Mon, 18 Nov 2024 00:32:57 -0500
|
|
Subject: [PATCH 107/233] bcachefs: Fix check_backpointers_to_extents range
|
|
limiting
|
|
Content-Type: text/plain; charset="utf-8"
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
bch2_get_btree_in_memory_pos() will return positions that refer directly
|
|
to the btree it's checking will fit in memory - i.e. backpointer
|
|
positions, not buckets.
|
|
|
|
This also means check_bp_exists() no longer has to refer to the device,
|
|
and we can delete some code.
|
|
|
|
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
|
|
Signed-off-by: Alexander Miroshnichenko <alex@millerson.name>
|
|
---
|
|
fs/bcachefs/backpointers.c | 63 +++++++++++++++-----------------------
|
|
1 file changed, 25 insertions(+), 38 deletions(-)
|
|
|
|
diff --git a/fs/bcachefs/backpointers.c b/fs/bcachefs/backpointers.c
|
|
index 24804f0bb2fd..5963217cd90c 100644
|
|
--- a/fs/bcachefs/backpointers.c
|
|
+++ b/fs/bcachefs/backpointers.c
|
|
@@ -352,8 +352,8 @@ int bch2_check_btree_backpointers(struct bch_fs *c)
|
|
}
|
|
|
|
struct extents_to_bp_state {
|
|
- struct bpos bucket_start;
|
|
- struct bpos bucket_end;
|
|
+ struct bpos bp_start;
|
|
+ struct bpos bp_end;
|
|
struct bkey_buf last_flushed;
|
|
};
|
|
|
|
@@ -445,29 +445,16 @@ static int check_bp_exists(struct btree_trans *trans,
|
|
struct bkey_s_c orig_k)
|
|
{
|
|
struct bch_fs *c = trans->c;
|
|
- struct btree_iter bp_iter = {};
|
|
struct btree_iter other_extent_iter = {};
|
|
struct printbuf buf = PRINTBUF;
|
|
- struct bkey_s_c bp_k;
|
|
- int ret = 0;
|
|
|
|
- struct bch_dev *ca = bch2_dev_tryget_noerror(c, bp->k.p.inode);
|
|
- if (!ca) {
|
|
- prt_printf(&buf, "extent for nonexistent device %llu\n", bp->k.p.inode);
|
|
- bch2_bkey_val_to_text(&buf, c, orig_k);
|
|
- bch_err(c, "%s", buf.buf);
|
|
- ret = -BCH_ERR_fsck_repair_unimplemented;
|
|
- goto err;
|
|
- }
|
|
-
|
|
- struct bpos bucket = bp_pos_to_bucket(ca, bp->k.p);
|
|
-
|
|
- if (bpos_lt(bucket, s->bucket_start) ||
|
|
- bpos_gt(bucket, s->bucket_end))
|
|
- goto out;
|
|
+ if (bpos_lt(bp->k.p, s->bp_start) ||
|
|
+ bpos_gt(bp->k.p, s->bp_end))
|
|
+ return 0;
|
|
|
|
- bp_k = bch2_bkey_get_iter(trans, &bp_iter, BTREE_ID_backpointers, bp->k.p, 0);
|
|
- ret = bkey_err(bp_k);
|
|
+ struct btree_iter bp_iter;
|
|
+ struct bkey_s_c bp_k = bch2_bkey_get_iter(trans, &bp_iter, BTREE_ID_backpointers, bp->k.p, 0);
|
|
+ int ret = bkey_err(bp_k);
|
|
if (ret)
|
|
goto err;
|
|
|
|
@@ -484,7 +471,6 @@ static int check_bp_exists(struct btree_trans *trans,
|
|
fsck_err:
|
|
bch2_trans_iter_exit(trans, &other_extent_iter);
|
|
bch2_trans_iter_exit(trans, &bp_iter);
|
|
- bch2_dev_put(ca);
|
|
printbuf_exit(&buf);
|
|
return ret;
|
|
check_existing_bp:
|
|
@@ -514,12 +500,13 @@ static int check_bp_exists(struct btree_trans *trans,
|
|
bch_err(c, "%s", buf.buf);
|
|
|
|
if (other_extent.k->size <= orig_k.k->size) {
|
|
- ret = drop_dev_and_update(trans, other_bp.v->btree_id, other_extent, bucket.inode);
|
|
+ ret = drop_dev_and_update(trans, other_bp.v->btree_id,
|
|
+ other_extent, bp->k.p.inode);
|
|
if (ret)
|
|
goto err;
|
|
goto out;
|
|
} else {
|
|
- ret = drop_dev_and_update(trans, bp->v.btree_id, orig_k, bucket.inode);
|
|
+ ret = drop_dev_and_update(trans, bp->v.btree_id, orig_k, bp->k.p.inode);
|
|
if (ret)
|
|
goto err;
|
|
goto missing;
|
|
@@ -529,7 +516,7 @@ static int check_bp_exists(struct btree_trans *trans,
|
|
ret = check_extent_checksum(trans,
|
|
other_bp.v->btree_id, other_extent,
|
|
bp->v.btree_id, orig_k,
|
|
- bucket.inode);
|
|
+ bp->k.p.inode);
|
|
if (ret < 0)
|
|
goto err;
|
|
if (ret) {
|
|
@@ -538,7 +525,7 @@ static int check_bp_exists(struct btree_trans *trans,
|
|
}
|
|
|
|
ret = check_extent_checksum(trans, bp->v.btree_id, orig_k,
|
|
- other_bp.v->btree_id, other_extent, bucket.inode);
|
|
+ other_bp.v->btree_id, other_extent, bp->k.p.inode);
|
|
if (ret < 0)
|
|
goto err;
|
|
if (ret) {
|
|
@@ -547,7 +534,7 @@ static int check_bp_exists(struct btree_trans *trans,
|
|
}
|
|
|
|
printbuf_reset(&buf);
|
|
- prt_printf(&buf, "duplicate extents pointing to same space on dev %llu\n ", bucket.inode);
|
|
+ prt_printf(&buf, "duplicate extents pointing to same space on dev %llu\n ", bp->k.p.inode);
|
|
bch2_bkey_val_to_text(&buf, c, orig_k);
|
|
prt_str(&buf, "\n ");
|
|
bch2_bkey_val_to_text(&buf, c, other_extent);
|
|
@@ -811,7 +798,7 @@ static int bch2_check_extents_to_backpointers_pass(struct btree_trans *trans,
|
|
int bch2_check_extents_to_backpointers(struct bch_fs *c)
|
|
{
|
|
struct btree_trans *trans = bch2_trans_get(c);
|
|
- struct extents_to_bp_state s = { .bucket_start = POS_MIN };
|
|
+ struct extents_to_bp_state s = { .bp_start = POS_MIN };
|
|
int ret;
|
|
|
|
bch2_bkey_buf_init(&s.last_flushed);
|
|
@@ -822,35 +809,35 @@ int bch2_check_extents_to_backpointers(struct bch_fs *c)
|
|
ret = bch2_get_btree_in_memory_pos(trans,
|
|
BIT_ULL(BTREE_ID_backpointers),
|
|
BIT_ULL(BTREE_ID_backpointers),
|
|
- BBPOS(BTREE_ID_backpointers, s.bucket_start), &end);
|
|
+ BBPOS(BTREE_ID_backpointers, s.bp_start), &end);
|
|
if (ret)
|
|
break;
|
|
|
|
- s.bucket_end = end.pos;
|
|
+ s.bp_end = end.pos;
|
|
|
|
- if ( bpos_eq(s.bucket_start, POS_MIN) &&
|
|
- !bpos_eq(s.bucket_end, SPOS_MAX))
|
|
+ if ( bpos_eq(s.bp_start, POS_MIN) &&
|
|
+ !bpos_eq(s.bp_end, SPOS_MAX))
|
|
bch_verbose(c, "%s(): alloc info does not fit in ram, running in multiple passes with %zu nodes per pass",
|
|
__func__, btree_nodes_fit_in_ram(c));
|
|
|
|
- if (!bpos_eq(s.bucket_start, POS_MIN) ||
|
|
- !bpos_eq(s.bucket_end, SPOS_MAX)) {
|
|
+ if (!bpos_eq(s.bp_start, POS_MIN) ||
|
|
+ !bpos_eq(s.bp_end, SPOS_MAX)) {
|
|
struct printbuf buf = PRINTBUF;
|
|
|
|
prt_str(&buf, "check_extents_to_backpointers(): ");
|
|
- bch2_bpos_to_text(&buf, s.bucket_start);
|
|
+ bch2_bpos_to_text(&buf, s.bp_start);
|
|
prt_str(&buf, "-");
|
|
- bch2_bpos_to_text(&buf, s.bucket_end);
|
|
+ bch2_bpos_to_text(&buf, s.bp_end);
|
|
|
|
bch_verbose(c, "%s", buf.buf);
|
|
printbuf_exit(&buf);
|
|
}
|
|
|
|
ret = bch2_check_extents_to_backpointers_pass(trans, &s);
|
|
- if (ret || bpos_eq(s.bucket_end, SPOS_MAX))
|
|
+ if (ret || bpos_eq(s.bp_end, SPOS_MAX))
|
|
break;
|
|
|
|
- s.bucket_start = bpos_successor(s.bucket_end);
|
|
+ s.bp_start = bpos_successor(s.bp_end);
|
|
}
|
|
bch2_trans_put(trans);
|
|
bch2_bkey_buf_exit(&s.last_flushed, c);
|
|
--
|
|
2.45.2
|
|
|