Commit 5a82ec3f authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: bch2_trigger_stripe_ptr()

Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent d55ddf6e
...@@ -868,85 +868,81 @@ static int bch2_trigger_pointer(struct btree_trans *trans, ...@@ -868,85 +868,81 @@ static int bch2_trigger_pointer(struct btree_trans *trans,
return 0; return 0;
} }
static int bch2_mark_stripe_ptr(struct btree_trans *trans, static int bch2_trigger_stripe_ptr(struct btree_trans *trans,
struct bkey_s_c k, struct bkey_s_c k,
struct bch_extent_stripe_ptr p, struct extent_ptr_decoded p,
enum bch_data_type data_type, enum bch_data_type data_type,
s64 sectors, s64 sectors, unsigned flags)
unsigned flags)
{ {
struct bch_fs *c = trans->c; if (flags & BTREE_TRIGGER_TRANSACTIONAL) {
struct bch_replicas_padded r; struct btree_iter iter;
struct gc_stripe *m; struct bkey_i_stripe *s = bch2_bkey_get_mut_typed(trans, &iter,
BTREE_ID_stripes, POS(0, p.ec.idx),
BUG_ON(!(flags & BTREE_TRIGGER_GC)); BTREE_ITER_WITH_UPDATES, stripe);
int ret = PTR_ERR_OR_ZERO(s);
if (unlikely(ret)) {
bch2_trans_inconsistent_on(bch2_err_matches(ret, ENOENT), trans,
"pointer to nonexistent stripe %llu",
(u64) p.ec.idx);
goto err;
}
m = genradix_ptr_alloc(&c->gc_stripes, p.idx, GFP_KERNEL); if (!bch2_ptr_matches_stripe(&s->v, p)) {
if (!m) { bch2_trans_inconsistent(trans,
bch_err(c, "error allocating memory for gc_stripes, idx %llu", "stripe pointer doesn't match stripe %llu",
(u64) p.idx); (u64) p.ec.idx);
return -BCH_ERR_ENOMEM_mark_stripe_ptr; ret = -EIO;
} goto err;
}
mutex_lock(&c->ec_stripes_heap_lock); stripe_blockcount_set(&s->v, p.ec.block,
stripe_blockcount_get(&s->v, p.ec.block) +
sectors);
if (!m || !m->alive) { struct bch_replicas_padded r;
mutex_unlock(&c->ec_stripes_heap_lock); bch2_bkey_to_replicas(&r.e, bkey_i_to_s_c(&s->k_i));
bch_err_ratelimited(c, "pointer to nonexistent stripe %llu", r.e.data_type = data_type;
(u64) p.idx); ret = bch2_update_replicas_list(trans, &r.e, sectors);
bch2_inconsistent_error(c); err:
return -EIO; bch2_trans_iter_exit(trans, &iter);
return ret;
} }
m->block_sectors[p.block] += sectors; if (flags & BTREE_TRIGGER_GC) {
struct bch_fs *c = trans->c;
r = m->r; BUG_ON(!(flags & BTREE_TRIGGER_GC));
mutex_unlock(&c->ec_stripes_heap_lock);
r.e.data_type = data_type; struct gc_stripe *m = genradix_ptr_alloc(&c->gc_stripes, p.ec.idx, GFP_KERNEL);
bch2_update_replicas(c, k, &r.e, sectors, trans->journal_res.seq, true); if (!m) {
bch_err(c, "error allocating memory for gc_stripes, idx %llu",
(u64) p.ec.idx);
return -BCH_ERR_ENOMEM_mark_stripe_ptr;
}
return 0; mutex_lock(&c->ec_stripes_heap_lock);
}
static int bch2_trans_mark_stripe_ptr(struct btree_trans *trans, if (!m || !m->alive) {
struct extent_ptr_decoded p, mutex_unlock(&c->ec_stripes_heap_lock);
s64 sectors, enum bch_data_type data_type) struct printbuf buf = PRINTBUF;
{ bch2_bkey_val_to_text(&buf, c, k);
struct btree_iter iter; bch_err_ratelimited(c, "pointer to nonexistent stripe %llu\n while marking %s",
struct bkey_i_stripe *s; (u64) p.ec.idx, buf.buf);
struct bch_replicas_padded r; printbuf_exit(&buf);
int ret = 0; bch2_inconsistent_error(c);
return -EIO;
}
s = bch2_bkey_get_mut_typed(trans, &iter, m->block_sectors[p.ec.block] += sectors;
BTREE_ID_stripes, POS(0, p.ec.idx),
BTREE_ITER_WITH_UPDATES, stripe);
ret = PTR_ERR_OR_ZERO(s);
if (unlikely(ret)) {
bch2_trans_inconsistent_on(bch2_err_matches(ret, ENOENT), trans,
"pointer to nonexistent stripe %llu",
(u64) p.ec.idx);
goto err;
}
if (!bch2_ptr_matches_stripe(&s->v, p)) { struct bch_replicas_padded r = m->r;
bch2_trans_inconsistent(trans, mutex_unlock(&c->ec_stripes_heap_lock);
"stripe pointer doesn't match stripe %llu",
(u64) p.ec.idx);
ret = -EIO;
goto err;
}
stripe_blockcount_set(&s->v, p.ec.block, r.e.data_type = data_type;
stripe_blockcount_get(&s->v, p.ec.block) + bch2_update_replicas(c, k, &r.e, sectors, trans->journal_res.seq, true);
sectors); }
bch2_bkey_to_replicas(&r.e, bkey_i_to_s_c(&s->k_i)); return 0;
r.e.data_type = data_type;
ret = bch2_update_replicas_list(trans, &r.e, sectors);
err:
bch2_trans_iter_exit(trans, &iter);
return ret;
} }
static int __mark_extent(struct btree_trans *trans, static int __mark_extent(struct btree_trans *trans,
...@@ -993,8 +989,7 @@ static int __mark_extent(struct btree_trans *trans, ...@@ -993,8 +989,7 @@ static int __mark_extent(struct btree_trans *trans,
dirty_sectors += disk_sectors; dirty_sectors += disk_sectors;
r.e.devs[r.e.nr_devs++] = p.ptr.dev; r.e.devs[r.e.nr_devs++] = p.ptr.dev;
} else { } else {
ret = bch2_mark_stripe_ptr(trans, k, p.ec, data_type, ret = bch2_trigger_stripe_ptr(trans, k, p, data_type, disk_sectors, flags);
disk_sectors, flags);
if (ret) if (ret)
return ret; return ret;
...@@ -1067,8 +1062,7 @@ static int __trans_mark_extent(struct btree_trans *trans, ...@@ -1067,8 +1062,7 @@ static int __trans_mark_extent(struct btree_trans *trans,
dirty_sectors += disk_sectors; dirty_sectors += disk_sectors;
r.e.devs[r.e.nr_devs++] = p.ptr.dev; r.e.devs[r.e.nr_devs++] = p.ptr.dev;
} else { } else {
ret = bch2_trans_mark_stripe_ptr(trans, p, ret = bch2_trigger_stripe_ptr(trans, k, p, data_type, disk_sectors, flags);
disk_sectors, data_type);
if (ret) if (ret)
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