Commit 51d2dfb8 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Add BTREE_PTR_RANGE_UPDATED

This is so that when we discover btree topology issues, we can just
update the pointer to a btree node and signal btree read path that the
min/max keys in the node header should be updated from the node pointer.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent a66f7989
...@@ -607,13 +607,14 @@ struct bch_btree_ptr_v2 { ...@@ -607,13 +607,14 @@ struct bch_btree_ptr_v2 {
__u64 mem_ptr; __u64 mem_ptr;
__le64 seq; __le64 seq;
__le16 sectors_written; __le16 sectors_written;
/* In case we ever decide to do variable size btree nodes: */ __le16 flags;
__le16 sectors;
struct bpos min_key; struct bpos min_key;
__u64 _data[0]; __u64 _data[0];
struct bch_extent_ptr start[]; struct bch_extent_ptr start[];
} __attribute__((packed, aligned(8))); } __attribute__((packed, aligned(8)));
LE16_BITMASK(BTREE_PTR_RANGE_UPDATED, struct bch_btree_ptr_v2, flags, 0, 1);
struct bch_extent { struct bch_extent {
struct bch_val v; struct bch_val v;
......
...@@ -753,6 +753,11 @@ static int validate_bset(struct bch_fs *c, struct btree *b, ...@@ -753,6 +753,11 @@ static int validate_bset(struct bch_fs *c, struct btree *b,
struct bch_btree_ptr_v2 *bp = struct bch_btree_ptr_v2 *bp =
&bkey_i_to_btree_ptr_v2(&b->key)->v; &bkey_i_to_btree_ptr_v2(&b->key)->v;
if (BTREE_PTR_RANGE_UPDATED(bp)) {
b->data->min_key = bp->min_key;
b->data->max_key = b->key.k.p;
}
btree_err_on(bkey_cmp(b->data->min_key, bp->min_key), btree_err_on(bkey_cmp(b->data->min_key, bp->min_key),
BTREE_ERR_MUST_RETRY, c, b, NULL, BTREE_ERR_MUST_RETRY, c, b, NULL,
"incorrect min_key: got %llu:%llu should be %llu:%llu", "incorrect min_key: got %llu:%llu should be %llu:%llu",
......
...@@ -297,7 +297,6 @@ static struct btree *bch2_btree_node_alloc(struct btree_update *as, unsigned lev ...@@ -297,7 +297,6 @@ static struct btree *bch2_btree_node_alloc(struct btree_update *as, unsigned lev
bp->v.mem_ptr = 0; bp->v.mem_ptr = 0;
bp->v.seq = b->data->keys.seq; bp->v.seq = b->data->keys.seq;
bp->v.sectors_written = 0; bp->v.sectors_written = 0;
bp->v.sectors = cpu_to_le16(c->opts.btree_node_size);
} }
if (c->sb.features & (1ULL << BCH_FEATURE_new_extent_overwrite)) if (c->sb.features & (1ULL << BCH_FEATURE_new_extent_overwrite))
......
...@@ -214,9 +214,8 @@ void bch2_btree_ptr_v2_to_text(struct printbuf *out, struct bch_fs *c, ...@@ -214,9 +214,8 @@ void bch2_btree_ptr_v2_to_text(struct printbuf *out, struct bch_fs *c,
{ {
struct bkey_s_c_btree_ptr_v2 bp = bkey_s_c_to_btree_ptr_v2(k); struct bkey_s_c_btree_ptr_v2 bp = bkey_s_c_to_btree_ptr_v2(k);
pr_buf(out, "seq %llx sectors %u written %u min_key ", pr_buf(out, "seq %llx written %u min_key ",
le64_to_cpu(bp.v->seq), le64_to_cpu(bp.v->seq),
le16_to_cpu(bp.v->sectors),
le16_to_cpu(bp.v->sectors_written)); le16_to_cpu(bp.v->sectors_written));
bch2_bpos_to_text(out, bp.v->min_key); bch2_bpos_to_text(out, bp.v->min_key);
...@@ -1081,10 +1080,9 @@ const char *bch2_bkey_ptrs_invalid(const struct bch_fs *c, struct bkey_s_c k) ...@@ -1081,10 +1080,9 @@ const char *bch2_bkey_ptrs_invalid(const struct bch_fs *c, struct bkey_s_c k)
unsigned nonce = UINT_MAX; unsigned nonce = UINT_MAX;
unsigned i; unsigned i;
if (k.k->type == KEY_TYPE_btree_ptr) if (k.k->type == KEY_TYPE_btree_ptr ||
k.k->type == KEY_TYPE_btree_ptr_v2)
size_ondisk = c->opts.btree_node_size; size_ondisk = c->opts.btree_node_size;
if (k.k->type == KEY_TYPE_btree_ptr_v2)
size_ondisk = le16_to_cpu(bkey_s_c_to_btree_ptr_v2(k).v->sectors);
bkey_extent_entry_for_each(ptrs, entry) { bkey_extent_entry_for_each(ptrs, entry) {
if (__extent_entry_type(entry) >= BCH_EXTENT_ENTRY_MAX) if (__extent_entry_type(entry) >= BCH_EXTENT_ENTRY_MAX)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment