Skip to content

Commit e36c877

Browse files
committed
bcachefs: Add an .invalid method for bch2_btree_ptr_v2
It was using the method for btree_ptr_v1, but that wasn't checking all the fields. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
1 parent f324c83 commit e36c877

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

fs/bcachefs/extents.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ int bch2_bkey_pick_read_device(struct bch_fs *c, struct bkey_s_c k,
158158

159159
const char *bch2_btree_ptr_invalid(const struct bch_fs *c, struct bkey_s_c k)
160160
{
161-
if (bkey_val_u64s(k.k) > BKEY_BTREE_PTR_VAL_U64s_MAX)
161+
if (bkey_val_u64s(k.k) > BCH_REPLICAS_MAX)
162162
return "value too big";
163163

164164
return bch2_bkey_ptrs_invalid(c, k);
@@ -170,6 +170,22 @@ void bch2_btree_ptr_to_text(struct printbuf *out, struct bch_fs *c,
170170
bch2_bkey_ptrs_to_text(out, c, k);
171171
}
172172

173+
const char *bch2_btree_ptr_v2_invalid(const struct bch_fs *c, struct bkey_s_c k)
174+
{
175+
struct bkey_s_c_btree_ptr_v2 bp = bkey_s_c_to_btree_ptr_v2(k);
176+
177+
if (bkey_val_bytes(k.k) <= sizeof(*bp.v))
178+
return "value too small";
179+
180+
if (bkey_val_u64s(k.k) > BKEY_BTREE_PTR_VAL_U64s_MAX)
181+
return "value too big";
182+
183+
if (bp.v->min_key.snapshot)
184+
return "invalid min_key.snapshot";
185+
186+
return bch2_bkey_ptrs_invalid(c, k);
187+
}
188+
173189
void bch2_btree_ptr_v2_to_text(struct printbuf *out, struct bch_fs *c,
174190
struct bkey_s_c k)
175191
{

fs/bcachefs/extents.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ const char *bch2_btree_ptr_invalid(const struct bch_fs *, struct bkey_s_c);
371371
void bch2_btree_ptr_to_text(struct printbuf *, struct bch_fs *,
372372
struct bkey_s_c);
373373

374+
const char *bch2_btree_ptr_v2_invalid(const struct bch_fs *, struct bkey_s_c);
374375
void bch2_btree_ptr_v2_to_text(struct printbuf *, struct bch_fs *,
375376
struct bkey_s_c);
376377
void bch2_btree_ptr_v2_compat(enum btree_id, unsigned, unsigned,
@@ -383,7 +384,7 @@ void bch2_btree_ptr_v2_compat(enum btree_id, unsigned, unsigned,
383384
}
384385

385386
#define bch2_bkey_ops_btree_ptr_v2 (struct bkey_ops) { \
386-
.key_invalid = bch2_btree_ptr_invalid, \
387+
.key_invalid = bch2_btree_ptr_v2_invalid, \
387388
.val_to_text = bch2_btree_ptr_v2_to_text, \
388389
.swab = bch2_ptr_swab, \
389390
.compat = bch2_btree_ptr_v2_compat, \

0 commit comments

Comments
 (0)