Commit c4e8db2b authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: bucket_data_type_mismatch()

We're working on potentially unifying bch2_check_bucket_ref() and
bch2_check_fix_ptrs() - or at least eliminating gratuitious differences.

Most immediately, there's a bunch of cleanups to be done regarding
BCH_DATA_stripe.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent b769590f
...@@ -67,7 +67,20 @@ static inline enum bch_data_type alloc_data_type(struct bch_alloc_v4 a, ...@@ -67,7 +67,20 @@ static inline enum bch_data_type alloc_data_type(struct bch_alloc_v4 a,
static inline enum bch_data_type bucket_data_type(enum bch_data_type data_type) static inline enum bch_data_type bucket_data_type(enum bch_data_type data_type)
{ {
return data_type == BCH_DATA_stripe ? BCH_DATA_user : data_type; switch (data_type) {
case BCH_DATA_cached:
case BCH_DATA_stripe:
return BCH_DATA_user;
default:
return data_type;
}
}
static inline bool bucket_data_type_mismatch(enum bch_data_type bucket,
enum bch_data_type ptr)
{
return !data_type_is_empty(bucket) &&
bucket_data_type(bucket) != bucket_data_type(ptr);
} }
static inline unsigned bch2_bucket_sectors(struct bch_alloc_v4 a) static inline unsigned bch2_bucket_sectors(struct bch_alloc_v4 a)
......
...@@ -664,10 +664,8 @@ static int bch2_check_fix_ptrs(struct btree_trans *trans, enum btree_id btree_id ...@@ -664,10 +664,8 @@ static int bch2_check_fix_ptrs(struct btree_trans *trans, enum btree_id btree_id
if (data_type != BCH_DATA_btree && p.ptr.gen != g->gen) if (data_type != BCH_DATA_btree && p.ptr.gen != g->gen)
continue; continue;
if (fsck_err_on(bucket_data_type(g->data_type) && if (fsck_err_on(bucket_data_type_mismatch(g->data_type, data_type),
bucket_data_type(g->data_type) != c, ptr_bucket_data_type_mismatch,
bucket_data_type(data_type), c,
ptr_bucket_data_type_mismatch,
"bucket %u:%zu different types of data in same bucket: %s, %s\n" "bucket %u:%zu different types of data in same bucket: %s, %s\n"
"while marking %s", "while marking %s",
p.ptr.dev, PTR_BUCKET_NR(ca, &p.ptr), p.ptr.dev, PTR_BUCKET_NR(ca, &p.ptr),
......
...@@ -498,13 +498,6 @@ int bch2_check_bucket_ref(struct btree_trans *trans, ...@@ -498,13 +498,6 @@ int bch2_check_bucket_ref(struct btree_trans *trans,
struct printbuf buf = PRINTBUF; struct printbuf buf = PRINTBUF;
int ret = 0; int ret = 0;
if (bucket_data_type == BCH_DATA_cached)
bucket_data_type = BCH_DATA_user;
if ((bucket_data_type == BCH_DATA_stripe && ptr_data_type == BCH_DATA_user) ||
(bucket_data_type == BCH_DATA_user && ptr_data_type == BCH_DATA_stripe))
bucket_data_type = ptr_data_type = BCH_DATA_stripe;
if (gen_after(ptr->gen, b_gen)) { if (gen_after(ptr->gen, b_gen)) {
bch2_fsck_err(c, FSCK_CAN_IGNORE|FSCK_NEED_FSCK, bch2_fsck_err(c, FSCK_CAN_IGNORE|FSCK_NEED_FSCK,
BCH_FSCK_ERR_ptr_gen_newer_than_bucket_gen, BCH_FSCK_ERR_ptr_gen_newer_than_bucket_gen,
...@@ -552,9 +545,7 @@ int bch2_check_bucket_ref(struct btree_trans *trans, ...@@ -552,9 +545,7 @@ int bch2_check_bucket_ref(struct btree_trans *trans,
goto out; goto out;
} }
if (!data_type_is_empty(bucket_data_type) && if (bucket_data_type_mismatch(bucket_data_type, ptr_data_type)) {
ptr_data_type &&
bucket_data_type != ptr_data_type) {
bch2_fsck_err(c, FSCK_CAN_IGNORE|FSCK_NEED_FSCK, bch2_fsck_err(c, FSCK_CAN_IGNORE|FSCK_NEED_FSCK,
BCH_FSCK_ERR_ptr_bucket_data_type_mismatch, BCH_FSCK_ERR_ptr_bucket_data_type_mismatch,
"bucket %u:%zu gen %u different types of data in same bucket: %s, %s\n" "bucket %u:%zu gen %u different types of data in same bucket: %s, %s\n"
......
...@@ -165,15 +165,16 @@ void bch2_stripe_to_text(struct printbuf *out, struct bch_fs *c, ...@@ -165,15 +165,16 @@ void bch2_stripe_to_text(struct printbuf *out, struct bch_fs *c,
static int bch2_trans_mark_stripe_bucket(struct btree_trans *trans, static int bch2_trans_mark_stripe_bucket(struct btree_trans *trans,
struct bkey_s_c_stripe s, struct bkey_s_c_stripe s,
unsigned idx, bool deleting) unsigned ptr_idx, bool deleting)
{ {
struct bch_fs *c = trans->c; struct bch_fs *c = trans->c;
const struct bch_extent_ptr *ptr = &s.v->ptrs[idx]; const struct bch_extent_ptr *ptr = s.v->ptrs + ptr_idx;
struct btree_iter iter; struct btree_iter iter;
struct bkey_i_alloc_v4 *a; struct bkey_i_alloc_v4 *a;
enum bch_data_type data_type = idx >= s.v->nr_blocks - s.v->nr_redundant unsigned nr_data = s.v->nr_blocks - s.v->nr_redundant;
? BCH_DATA_parity : 0; bool parity = ptr_idx >= nr_data;
s64 sectors = data_type ? le16_to_cpu(s.v->sectors) : 0; enum bch_data_type data_type = parity ? BCH_DATA_parity : BCH_DATA_stripe;
s64 sectors = parity ? le16_to_cpu(s.v->sectors) : 0;
int ret = 0; int ret = 0;
if (deleting) if (deleting)
...@@ -201,8 +202,8 @@ static int bch2_trans_mark_stripe_bucket(struct btree_trans *trans, ...@@ -201,8 +202,8 @@ static int bch2_trans_mark_stripe_bucket(struct btree_trans *trans,
goto err; goto err;
} }
if (bch2_trans_inconsistent_on(data_type && a->v.dirty_sectors, trans, if (bch2_trans_inconsistent_on(parity && a->v.dirty_sectors, trans,
"bucket %llu:%llu gen %u data type %s dirty_sectors %u: data already in stripe bucket %llu", "bucket %llu:%llu gen %u data type %s dirty_sectors %u: data already in parity bucket %llu",
iter.pos.inode, iter.pos.offset, a->v.gen, iter.pos.inode, iter.pos.offset, a->v.gen,
bch2_data_type_str(a->v.data_type), bch2_data_type_str(a->v.data_type),
a->v.dirty_sectors, a->v.dirty_sectors,
...@@ -213,7 +214,7 @@ static int bch2_trans_mark_stripe_bucket(struct btree_trans *trans, ...@@ -213,7 +214,7 @@ static int bch2_trans_mark_stripe_bucket(struct btree_trans *trans,
a->v.stripe = s.k->p.offset; a->v.stripe = s.k->p.offset;
a->v.stripe_redundancy = s.v->nr_redundant; a->v.stripe_redundancy = s.v->nr_redundant;
a->v.data_type = BCH_DATA_stripe; a->v.data_type = data_type;
} else { } else {
if (bch2_trans_inconsistent_on(a->v.stripe != s.k->p.offset || if (bch2_trans_inconsistent_on(a->v.stripe != s.k->p.offset ||
a->v.stripe_redundancy != s.v->nr_redundant, trans, a->v.stripe_redundancy != s.v->nr_redundant, trans,
...@@ -230,8 +231,6 @@ static int bch2_trans_mark_stripe_bucket(struct btree_trans *trans, ...@@ -230,8 +231,6 @@ static int bch2_trans_mark_stripe_bucket(struct btree_trans *trans,
} }
a->v.dirty_sectors += sectors; a->v.dirty_sectors += sectors;
if (data_type)
a->v.data_type = !deleting ? data_type : 0;
ret = bch2_trans_update(trans, &iter, &a->k_i, 0); ret = bch2_trans_update(trans, &iter, &a->k_i, 0);
if (ret) if (ret)
......
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