diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2022-06-08 23:44:24 -0400 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@gmail.com> | 2022-06-09 15:37:04 -0400 |
commit | a70496b1c523ec064b861e4b1b2612e4a1d4d4b8 (patch) | |
tree | dfd3e1173302ac135b7defea641bd65b24d1ceba | |
parent | d7e9d638d085ddaef1d92449f97c545b1627ac8b (diff) |
bcachefs: better backpointer not found err msg
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
-rw-r--r-- | fs/bcachefs/backpointers.c | 69 | ||||
-rw-r--r-- | fs/bcachefs/backpointers.h | 4 | ||||
-rw-r--r-- | fs/bcachefs/move.c | 6 |
3 files changed, 47 insertions, 32 deletions
diff --git a/fs/bcachefs/backpointers.c b/fs/bcachefs/backpointers.c index 17bd9fef3c1a..7fa37c768b74 100644 --- a/fs/bcachefs/backpointers.c +++ b/fs/bcachefs/backpointers.c @@ -424,9 +424,46 @@ out: return ret; } +static void backpointer_not_found(struct btree_trans *trans, + struct bpos alloc_pos, + u64 bp_offset, + struct bch_backpointer bp, + struct bkey_s_c k, + const char *thing_it_points_to) +{ + struct bch_fs *c = trans->c; + struct printbuf buf = PRINTBUF; + + prt_printf(&buf, "backpointer doesn't match %s it points to:\n ", + thing_it_points_to); + prt_printf(&buf, "bucket: "); + bch2_bpos_to_text(&buf, alloc_pos); + prt_printf(&buf, "\n "); + + if (bp_offset >= BACKPOINTER_OFFSET_MAX) { + struct bpos bp_pos = + backpointer_pos(c, alloc_pos, + bp_offset - BACKPOINTER_OFFSET_MAX); + prt_printf(&buf, "backpointer pos: "); + bch2_bpos_to_text(&buf, bp_pos); + prt_printf(&buf, "\n "); + } + + bch2_backpointer_to_text(&buf, &bp); + prt_printf(&buf, "\n "); + bch2_bkey_val_to_text(&buf, c, k); + if (!test_bit(BCH_FS_CHECK_BACKPOINTERS_DONE, &c->flags)) + bch_err(c, "%s", buf.buf); + else + bch2_trans_inconsistent(trans, "%s", buf.buf); + + printbuf_exit(&buf); +} + struct bkey_s_c bch2_backpointer_get_key(struct btree_trans *trans, struct btree_iter *iter, struct bpos alloc_pos, + u64 bp_offset, struct bch_backpointer bp) { struct bch_fs *c = trans->c; @@ -434,7 +471,6 @@ struct bkey_s_c bch2_backpointer_get_key(struct btree_trans *trans, const union bch_extent_entry *entry; struct extent_ptr_decoded p; struct bkey_s_c k; - struct printbuf buf = PRINTBUF; bch2_trans_node_iter_init(trans, iter, bp.btree_id, @@ -464,27 +500,16 @@ struct bkey_s_c bch2_backpointer_get_key(struct btree_trans *trans, return k; } - prt_printf(&buf, "backpointer doesn't match extent it points to:\n "); - prt_printf(&buf, "bucket: "); - bch2_bpos_to_text(&buf, alloc_pos); - prt_printf(&buf, "\n "); - bch2_backpointer_to_text(&buf, &bp); - prt_printf(&buf, "\n "); - bch2_bkey_val_to_text(&buf, c, k); - - if (!test_bit(BCH_FS_CHECK_BACKPOINTERS_DONE, &c->flags)) - bch_err(c, "%s", buf.buf); - else - bch2_trans_inconsistent(trans, "%s", buf.buf); + backpointer_not_found(trans, alloc_pos, bp_offset, bp, k, "extent"); bch2_trans_iter_exit(trans, iter); - printbuf_exit(&buf); return bkey_s_c_null; } struct btree *bch2_backpointer_get_node(struct btree_trans *trans, struct btree_iter *iter, struct bpos alloc_pos, + u64 bp_offset, struct bch_backpointer bp) { struct bch_fs *c = trans->c; @@ -493,7 +518,6 @@ struct btree *bch2_backpointer_get_node(struct btree_trans *trans, struct extent_ptr_decoded p; struct btree *b; struct bkey_s_c k; - struct printbuf buf = PRINTBUF; BUG_ON(!bp.level); @@ -526,20 +550,9 @@ struct btree *bch2_backpointer_get_node(struct btree_trans *trans, if (btree_node_will_make_reachable(b)) goto out; - prt_printf(&buf, "backpointer doesn't match btree node it points to:\n "); - prt_printf(&buf, "bucket: "); - bch2_bpos_to_text(&buf, alloc_pos); - prt_printf(&buf, "\n "); - bch2_backpointer_to_text(&buf, &bp); - prt_printf(&buf, "\n "); - bch2_bkey_val_to_text(&buf, c, k); - if (!test_bit(BCH_FS_CHECK_BACKPOINTERS_DONE, &c->flags)) - bch_err(c, "%s", buf.buf); - else - bch2_trans_inconsistent(trans, "%s", buf.buf); + backpointer_not_found(trans, alloc_pos, bp_offset, bp, k, "btree node"); out: bch2_trans_iter_exit(trans, iter); - printbuf_exit(&buf); return NULL; } @@ -822,7 +835,7 @@ static int check_one_backpointer(struct btree_trans *trans, if (ret || *bp_offset == U64_MAX) return ret; - k = bch2_backpointer_get_key(trans, &iter, alloc_pos, bp); + k = bch2_backpointer_get_key(trans, &iter, alloc_pos, *bp_offset, bp); ret = bkey_err(k); if (ret) return ret; diff --git a/fs/bcachefs/backpointers.h b/fs/bcachefs/backpointers.h index beb40fdac602..d22be9b7df2a 100644 --- a/fs/bcachefs/backpointers.h +++ b/fs/bcachefs/backpointers.h @@ -27,9 +27,9 @@ int bch2_bucket_backpointer_add(struct btree_trans *, struct bkey_i_alloc_v4 *, int bch2_get_next_backpointer(struct btree_trans *, unsigned, u64, int, u64 *, struct bch_backpointer *); struct bkey_s_c bch2_backpointer_get_key(struct btree_trans *, struct btree_iter *, - struct bpos, struct bch_backpointer); + struct bpos, u64, struct bch_backpointer); struct btree *bch2_backpointer_get_node(struct btree_trans *, struct btree_iter *, - struct bpos, struct bch_backpointer); + struct bpos, u64, struct bch_backpointer); int bch2_check_backpointers(struct bch_fs *); int bch2_check_extents_to_backpointers(struct bch_fs *); diff --git a/fs/bcachefs/move.c b/fs/bcachefs/move.c index aeba91ad65a8..d6e3f21e3c70 100644 --- a/fs/bcachefs/move.c +++ b/fs/bcachefs/move.c @@ -923,7 +923,8 @@ int bch2_evacuate_bucket(struct bch_fs *c, struct bkey_s_c k; k = bch2_backpointer_get_key(&trans, &iter, - POS(ca->dev_idx, bucket), bp); + POS(ca->dev_idx, bucket), + bp_offset, bp); ret = bkey_err(k); if (ret == -EINTR) continue; @@ -962,7 +963,8 @@ int bch2_evacuate_bucket(struct bch_fs *c, struct btree *b; b = bch2_backpointer_get_node(&trans, &iter, - POS(ca->dev_idx, bucket), bp); + POS(ca->dev_idx, bucket), + bp_offset, bp); ret = PTR_ERR_OR_ZERO(b); if (ret == -EINTR) continue; |