Commit 0acf2169 authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: __mark_stripe_bucket() now takes bch_alloc_v4

Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent be11ae16
...@@ -1001,7 +1001,6 @@ static int bch2_trigger_pointer(struct btree_trans *trans, ...@@ -1001,7 +1001,6 @@ static int bch2_trigger_pointer(struct btree_trans *trans,
struct bucket *g = gc_bucket(ca, bucket.offset); struct bucket *g = gc_bucket(ca, bucket.offset);
bucket_lock(g); bucket_lock(g);
struct bch_alloc_v4 old = bucket_m_to_alloc(*g), new = old; struct bch_alloc_v4 old = bucket_m_to_alloc(*g), new = old;
int ret = __mark_pointer(trans, k, &p.ptr, *sectors, bp.data_type, &new); int ret = __mark_pointer(trans, k, &p.ptr, *sectors, bp.data_type, &new);
if (!ret) { if (!ret) {
alloc_to_bucket(g, new); alloc_to_bucket(g, new);
......
...@@ -167,12 +167,7 @@ static int __mark_stripe_bucket(struct btree_trans *trans, ...@@ -167,12 +167,7 @@ static int __mark_stripe_bucket(struct btree_trans *trans,
struct bkey_s_c_stripe s, struct bkey_s_c_stripe s,
unsigned ptr_idx, bool deleting, unsigned ptr_idx, bool deleting,
struct bpos bucket, struct bpos bucket,
u8 bucket_gen, struct bch_alloc_v4 *a)
u8 *bucket_data_type,
u32 *bucket_dirty_sectors,
u32 *bucket_cached_sectors,
u32 *bucket_stripe,
u8 *bucket_stripe_redundancy)
{ {
struct bch_fs *c = trans->c; struct bch_fs *c = trans->c;
const struct bch_extent_ptr *ptr = s.v->ptrs + ptr_idx; const struct bch_extent_ptr *ptr = s.v->ptrs + ptr_idx;
...@@ -187,43 +182,43 @@ static int __mark_stripe_bucket(struct btree_trans *trans, ...@@ -187,43 +182,43 @@ static int __mark_stripe_bucket(struct btree_trans *trans,
sectors = -sectors; sectors = -sectors;
if (!deleting) { if (!deleting) {
if (bch2_trans_inconsistent_on(*bucket_stripe || if (bch2_trans_inconsistent_on(a->stripe ||
*bucket_stripe_redundancy, trans, a->stripe_redundancy, trans,
"bucket %llu:%llu gen %u data type %s dirty_sectors %u: multiple stripes using same bucket (%u, %llu)\n%s", "bucket %llu:%llu gen %u data type %s dirty_sectors %u: multiple stripes using same bucket (%u, %llu)\n%s",
bucket.inode, bucket.offset, bucket_gen, bucket.inode, bucket.offset, a->gen,
bch2_data_type_str(*bucket_data_type), bch2_data_type_str(a->data_type),
*bucket_dirty_sectors, a->dirty_sectors,
*bucket_stripe, s.k->p.offset, a->stripe, s.k->p.offset,
(bch2_bkey_val_to_text(&buf, c, s.s_c), buf.buf))) { (bch2_bkey_val_to_text(&buf, c, s.s_c), buf.buf))) {
ret = -EIO; ret = -EIO;
goto err; goto err;
} }
if (bch2_trans_inconsistent_on(parity && (*bucket_dirty_sectors || *bucket_cached_sectors), trans, if (bch2_trans_inconsistent_on(parity && bch2_bucket_sectors_total(*a), trans,
"bucket %llu:%llu gen %u data type %s dirty_sectors %u cached_sectors %u: data already in parity bucket\n%s", "bucket %llu:%llu gen %u data type %s dirty_sectors %u cached_sectors %u: data already in parity bucket\n%s",
bucket.inode, bucket.offset, bucket_gen, bucket.inode, bucket.offset, a->gen,
bch2_data_type_str(*bucket_data_type), bch2_data_type_str(a->data_type),
*bucket_dirty_sectors, a->dirty_sectors,
*bucket_cached_sectors, a->cached_sectors,
(bch2_bkey_val_to_text(&buf, c, s.s_c), buf.buf))) { (bch2_bkey_val_to_text(&buf, c, s.s_c), buf.buf))) {
ret = -EIO; ret = -EIO;
goto err; goto err;
} }
} else { } else {
if (bch2_trans_inconsistent_on(*bucket_stripe != s.k->p.offset || if (bch2_trans_inconsistent_on(a->stripe != s.k->p.offset ||
*bucket_stripe_redundancy != s.v->nr_redundant, trans, a->stripe_redundancy != s.v->nr_redundant, trans,
"bucket %llu:%llu gen %u: not marked as stripe when deleting stripe (got %u)\n%s", "bucket %llu:%llu gen %u: not marked as stripe when deleting stripe (got %u)\n%s",
bucket.inode, bucket.offset, bucket_gen, bucket.inode, bucket.offset, a->gen,
*bucket_stripe, a->stripe,
(bch2_bkey_val_to_text(&buf, c, s.s_c), buf.buf))) { (bch2_bkey_val_to_text(&buf, c, s.s_c), buf.buf))) {
ret = -EIO; ret = -EIO;
goto err; goto err;
} }
if (bch2_trans_inconsistent_on(*bucket_data_type != data_type, trans, if (bch2_trans_inconsistent_on(a->data_type != data_type, trans,
"bucket %llu:%llu gen %u data type %s: wrong data type when stripe, should be %s\n%s", "bucket %llu:%llu gen %u data type %s: wrong data type when stripe, should be %s\n%s",
bucket.inode, bucket.offset, bucket_gen, bucket.inode, bucket.offset, a->gen,
bch2_data_type_str(*bucket_data_type), bch2_data_type_str(a->data_type),
bch2_data_type_str(data_type), bch2_data_type_str(data_type),
(bch2_bkey_val_to_text(&buf, c, s.s_c), buf.buf))) { (bch2_bkey_val_to_text(&buf, c, s.s_c), buf.buf))) {
ret = -EIO; ret = -EIO;
...@@ -231,12 +226,12 @@ static int __mark_stripe_bucket(struct btree_trans *trans, ...@@ -231,12 +226,12 @@ static int __mark_stripe_bucket(struct btree_trans *trans,
} }
if (bch2_trans_inconsistent_on(parity && if (bch2_trans_inconsistent_on(parity &&
(*bucket_dirty_sectors != -sectors || (a->dirty_sectors != -sectors ||
*bucket_cached_sectors), trans, a->cached_sectors), trans,
"bucket %llu:%llu gen %u dirty_sectors %u cached_sectors %u: wrong sectors when deleting parity block of stripe\n%s", "bucket %llu:%llu gen %u dirty_sectors %u cached_sectors %u: wrong sectors when deleting parity block of stripe\n%s",
bucket.inode, bucket.offset, bucket_gen, bucket.inode, bucket.offset, a->gen,
*bucket_dirty_sectors, a->dirty_sectors,
*bucket_cached_sectors, a->cached_sectors,
(bch2_bkey_val_to_text(&buf, c, s.s_c), buf.buf))) { (bch2_bkey_val_to_text(&buf, c, s.s_c), buf.buf))) {
ret = -EIO; ret = -EIO;
goto err; goto err;
...@@ -245,21 +240,20 @@ static int __mark_stripe_bucket(struct btree_trans *trans, ...@@ -245,21 +240,20 @@ static int __mark_stripe_bucket(struct btree_trans *trans,
if (sectors) { if (sectors) {
ret = bch2_bucket_ref_update(trans, s.s_c, ptr, sectors, data_type, ret = bch2_bucket_ref_update(trans, s.s_c, ptr, sectors, data_type,
bucket_gen, *bucket_data_type, a->gen, a->data_type, &a->dirty_sectors);
bucket_dirty_sectors);
if (ret) if (ret)
goto err; goto err;
} }
if (!deleting) { if (!deleting) {
*bucket_stripe = s.k->p.offset; a->stripe = s.k->p.offset;
*bucket_stripe_redundancy = s.v->nr_redundant; a->stripe_redundancy = s.v->nr_redundant;
*bucket_data_type = data_type;
} else { } else {
*bucket_stripe = 0; a->stripe = 0;
*bucket_stripe_redundancy = 0; a->stripe_redundancy = 0;
*bucket_data_type = BCH_DATA_free;
} }
alloc_data_type_set(a, data_type);
err: err:
printbuf_exit(&buf); printbuf_exit(&buf);
return ret; return ret;
...@@ -279,19 +273,10 @@ static int mark_stripe_bucket(struct btree_trans *trans, ...@@ -279,19 +273,10 @@ static int mark_stripe_bucket(struct btree_trans *trans,
struct bkey_i_alloc_v4 *a = struct bkey_i_alloc_v4 *a =
bch2_trans_start_alloc_update(trans, &iter, bucket); bch2_trans_start_alloc_update(trans, &iter, bucket);
int ret = PTR_ERR_OR_ZERO(a) ?: int ret = PTR_ERR_OR_ZERO(a) ?:
__mark_stripe_bucket(trans, s, ptr_idx, deleting, iter.pos, __mark_stripe_bucket(trans, s, ptr_idx, deleting, iter.pos, &a->v);
a->v.gen,
&a->v.data_type,
&a->v.dirty_sectors,
&a->v.cached_sectors,
&a->v.stripe,
&a->v.stripe_redundancy);
if (ret) if (ret)
goto err; goto err;
if (deleting)
alloc_data_type_set(&a->v, BCH_DATA_user);
ret = bch2_trans_update(trans, &iter, &a->k_i, 0); ret = bch2_trans_update(trans, &iter, &a->k_i, 0);
if (ret) if (ret)
goto err; goto err;
...@@ -305,23 +290,14 @@ static int mark_stripe_bucket(struct btree_trans *trans, ...@@ -305,23 +290,14 @@ static int mark_stripe_bucket(struct btree_trans *trans,
percpu_down_read(&c->mark_lock); percpu_down_read(&c->mark_lock);
struct bucket *g = gc_bucket(ca, bucket.offset); struct bucket *g = gc_bucket(ca, bucket.offset);
bucket_lock(g); bucket_lock(g);
struct bch_alloc_v4 old = bucket_m_to_alloc(*g); struct bch_alloc_v4 old = bucket_m_to_alloc(*g), new = old;
u8 data_type = g->data_type; int ret = __mark_stripe_bucket(trans, s, ptr_idx, deleting, bucket, &new);
if (!ret) {
int ret = __mark_stripe_bucket(trans, s, ptr_idx, deleting, bucket, alloc_to_bucket(g, new);
g->gen,
&data_type,
&g->dirty_sectors,
&g->cached_sectors,
&g->stripe,
&g->stripe_redundancy);
g->data_type = data_type;
struct bch_alloc_v4 new = bucket_m_to_alloc(*g);
bucket_unlock(g);
if (!ret)
bch2_dev_usage_update(c, ca, &old, &new, 0, true); bch2_dev_usage_update(c, ca, &old, &new, 0, true);
}
bucket_unlock(g);
percpu_up_read(&c->mark_lock); percpu_up_read(&c->mark_lock);
return ret; return 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