bcachefs: simplify bch2_trans_start_alloc_update()
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
0acf2169a5
commit
abe2f470bc
@ -429,22 +429,18 @@ struct bkey_i_alloc_v4 *bch2_alloc_to_v4_mut(struct btree_trans *trans, struct b
|
||||
}
|
||||
|
||||
struct bkey_i_alloc_v4 *
|
||||
bch2_trans_start_alloc_update(struct btree_trans *trans, struct btree_iter *iter,
|
||||
struct bpos pos)
|
||||
bch2_trans_start_alloc_update_noupdate(struct btree_trans *trans, struct btree_iter *iter,
|
||||
struct bpos pos)
|
||||
{
|
||||
struct bkey_s_c k;
|
||||
struct bkey_i_alloc_v4 *a;
|
||||
int ret;
|
||||
|
||||
k = bch2_bkey_get_iter(trans, iter, BTREE_ID_alloc, pos,
|
||||
BTREE_ITER_with_updates|
|
||||
BTREE_ITER_cached|
|
||||
BTREE_ITER_intent);
|
||||
ret = bkey_err(k);
|
||||
struct bkey_s_c k = bch2_bkey_get_iter(trans, iter, BTREE_ID_alloc, pos,
|
||||
BTREE_ITER_with_updates|
|
||||
BTREE_ITER_cached|
|
||||
BTREE_ITER_intent);
|
||||
int ret = bkey_err(k);
|
||||
if (unlikely(ret))
|
||||
return ERR_PTR(ret);
|
||||
|
||||
a = bch2_alloc_to_v4_mut_inlined(trans, k);
|
||||
struct bkey_i_alloc_v4 *a = bch2_alloc_to_v4_mut_inlined(trans, k);
|
||||
ret = PTR_ERR_OR_ZERO(a);
|
||||
if (unlikely(ret))
|
||||
goto err;
|
||||
@ -454,6 +450,20 @@ err:
|
||||
return ERR_PTR(ret);
|
||||
}
|
||||
|
||||
__flatten
|
||||
struct bkey_i_alloc_v4 *bch2_trans_start_alloc_update(struct btree_trans *trans, struct bpos pos)
|
||||
{
|
||||
struct btree_iter iter;
|
||||
struct bkey_i_alloc_v4 *a = bch2_trans_start_alloc_update_noupdate(trans, &iter, pos);
|
||||
int ret = PTR_ERR_OR_ZERO(a);
|
||||
if (ret)
|
||||
return ERR_PTR(ret);
|
||||
|
||||
ret = bch2_trans_update(trans, &iter, &a->k_i, 0);
|
||||
bch2_trans_iter_exit(trans, &iter);
|
||||
return unlikely(ret) ? ERR_PTR(ret) : a;
|
||||
}
|
||||
|
||||
static struct bpos alloc_gens_pos(struct bpos pos, unsigned *offset)
|
||||
{
|
||||
*offset = pos.offset & KEY_TYPE_BUCKET_GENS_MASK;
|
||||
@ -1908,7 +1918,6 @@ static int invalidate_one_bucket(struct btree_trans *trans,
|
||||
s64 *nr_to_invalidate)
|
||||
{
|
||||
struct bch_fs *c = trans->c;
|
||||
struct btree_iter alloc_iter = { NULL };
|
||||
struct bkey_i_alloc_v4 *a = NULL;
|
||||
struct printbuf buf = PRINTBUF;
|
||||
struct bpos bucket = u64_to_bucket(lru_k.k->p.offset);
|
||||
@ -1926,7 +1935,7 @@ static int invalidate_one_bucket(struct btree_trans *trans,
|
||||
if (bch2_bucket_is_open_safe(c, bucket.inode, bucket.offset))
|
||||
return 0;
|
||||
|
||||
a = bch2_trans_start_alloc_update(trans, &alloc_iter, bucket);
|
||||
a = bch2_trans_start_alloc_update(trans, bucket);
|
||||
ret = PTR_ERR_OR_ZERO(a);
|
||||
if (ret)
|
||||
goto out;
|
||||
@ -1951,18 +1960,15 @@ static int invalidate_one_bucket(struct btree_trans *trans,
|
||||
a->v.io_time[READ] = atomic64_read(&c->io_clock[READ].now);
|
||||
a->v.io_time[WRITE] = atomic64_read(&c->io_clock[WRITE].now);
|
||||
|
||||
ret = bch2_trans_update(trans, &alloc_iter, &a->k_i,
|
||||
BTREE_TRIGGER_bucket_invalidate) ?:
|
||||
bch2_trans_commit(trans, NULL, NULL,
|
||||
BCH_WATERMARK_btree|
|
||||
BCH_TRANS_COMMIT_no_enospc);
|
||||
ret = bch2_trans_commit(trans, NULL, NULL,
|
||||
BCH_WATERMARK_btree|
|
||||
BCH_TRANS_COMMIT_no_enospc);
|
||||
if (ret)
|
||||
goto out;
|
||||
|
||||
trace_and_count(c, bucket_invalidate, c, bucket.inode, bucket.offset, cached_sectors);
|
||||
--*nr_to_invalidate;
|
||||
out:
|
||||
bch2_trans_iter_exit(trans, &alloc_iter);
|
||||
printbuf_exit(&buf);
|
||||
return ret;
|
||||
err:
|
||||
@ -2175,7 +2181,7 @@ int bch2_bucket_io_time_reset(struct btree_trans *trans, unsigned dev,
|
||||
if (bch2_trans_relock(trans))
|
||||
bch2_trans_begin(trans);
|
||||
|
||||
a = bch2_trans_start_alloc_update(trans, &iter, POS(dev, bucket_nr));
|
||||
a = bch2_trans_start_alloc_update_noupdate(trans, &iter, POS(dev, bucket_nr));
|
||||
ret = PTR_ERR_OR_ZERO(a);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
@ -179,7 +179,9 @@ static inline void set_alloc_v4_u64s(struct bkey_i_alloc_v4 *a)
|
||||
}
|
||||
|
||||
struct bkey_i_alloc_v4 *
|
||||
bch2_trans_start_alloc_update(struct btree_trans *, struct btree_iter *, struct bpos);
|
||||
bch2_trans_start_alloc_update_noupdate(struct btree_trans *, struct btree_iter *, struct bpos);
|
||||
struct bkey_i_alloc_v4 *
|
||||
bch2_trans_start_alloc_update(struct btree_trans *, struct bpos);
|
||||
|
||||
void __bch2_alloc_to_v4(struct bkey_s_c, struct bch_alloc_v4 *);
|
||||
|
||||
|
@ -973,16 +973,9 @@ static int bch2_trigger_pointer(struct btree_trans *trans,
|
||||
*sectors = insert ? bp.bucket_len : -((s64) bp.bucket_len);
|
||||
|
||||
if (flags & BTREE_TRIGGER_transactional) {
|
||||
struct btree_iter iter;
|
||||
struct bkey_i_alloc_v4 *a = bch2_trans_start_alloc_update(trans, &iter, bucket);
|
||||
int ret = PTR_ERR_OR_ZERO(a);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = __mark_pointer(trans, k, &p.ptr, *sectors, bp.data_type, &a->v) ?:
|
||||
bch2_trans_update(trans, &iter, &a->k_i, 0);
|
||||
bch2_trans_iter_exit(trans, &iter);
|
||||
|
||||
struct bkey_i_alloc_v4 *a = bch2_trans_start_alloc_update(trans, bucket);
|
||||
int ret = PTR_ERR_OR_ZERO(a) ?:
|
||||
__mark_pointer(trans, k, &p.ptr, *sectors, bp.data_type, &a->v);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
@ -1266,7 +1259,7 @@ static int __bch2_trans_mark_metadata_bucket(struct btree_trans *trans,
|
||||
int ret = 0;
|
||||
|
||||
struct bkey_i_alloc_v4 *a =
|
||||
bch2_trans_start_alloc_update(trans, &iter, POS(ca->dev_idx, b));
|
||||
bch2_trans_start_alloc_update_noupdate(trans, &iter, POS(ca->dev_idx, b));
|
||||
if (IS_ERR(a))
|
||||
return PTR_ERR(a);
|
||||
|
||||
|
@ -269,20 +269,10 @@ static int mark_stripe_bucket(struct btree_trans *trans,
|
||||
struct bpos bucket = PTR_BUCKET_POS(c, ptr);
|
||||
|
||||
if (flags & BTREE_TRIGGER_transactional) {
|
||||
struct btree_iter iter;
|
||||
struct bkey_i_alloc_v4 *a =
|
||||
bch2_trans_start_alloc_update(trans, &iter, bucket);
|
||||
int ret = PTR_ERR_OR_ZERO(a) ?:
|
||||
__mark_stripe_bucket(trans, s, ptr_idx, deleting, iter.pos, &a->v);
|
||||
if (ret)
|
||||
goto err;
|
||||
|
||||
ret = bch2_trans_update(trans, &iter, &a->k_i, 0);
|
||||
if (ret)
|
||||
goto err;
|
||||
err:
|
||||
bch2_trans_iter_exit(trans, &iter);
|
||||
return ret;
|
||||
bch2_trans_start_alloc_update(trans, bucket);
|
||||
return PTR_ERR_OR_ZERO(a) ?:
|
||||
__mark_stripe_bucket(trans, s, ptr_idx, deleting, bucket, &a->v);
|
||||
}
|
||||
|
||||
if (flags & BTREE_TRIGGER_gc) {
|
||||
|
Loading…
Reference in New Issue
Block a user