1

bcachefs: simplify bch2_trans_start_alloc_update()

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2024-04-30 03:27:30 -04:00
parent 0acf2169a5
commit abe2f470bc
4 changed files with 37 additions and 46 deletions

View File

@ -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 * struct bkey_i_alloc_v4 *
bch2_trans_start_alloc_update(struct btree_trans *trans, struct btree_iter *iter, bch2_trans_start_alloc_update_noupdate(struct btree_trans *trans, struct btree_iter *iter,
struct bpos pos) struct bpos pos)
{ {
struct bkey_s_c k; struct bkey_s_c k = bch2_bkey_get_iter(trans, iter, BTREE_ID_alloc, pos,
struct bkey_i_alloc_v4 *a; BTREE_ITER_with_updates|
int ret; BTREE_ITER_cached|
BTREE_ITER_intent);
k = bch2_bkey_get_iter(trans, iter, BTREE_ID_alloc, pos, int ret = bkey_err(k);
BTREE_ITER_with_updates|
BTREE_ITER_cached|
BTREE_ITER_intent);
ret = bkey_err(k);
if (unlikely(ret)) if (unlikely(ret))
return ERR_PTR(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); ret = PTR_ERR_OR_ZERO(a);
if (unlikely(ret)) if (unlikely(ret))
goto err; goto err;
@ -454,6 +450,20 @@ err:
return ERR_PTR(ret); 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) static struct bpos alloc_gens_pos(struct bpos pos, unsigned *offset)
{ {
*offset = pos.offset & KEY_TYPE_BUCKET_GENS_MASK; *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) s64 *nr_to_invalidate)
{ {
struct bch_fs *c = trans->c; struct bch_fs *c = trans->c;
struct btree_iter alloc_iter = { NULL };
struct bkey_i_alloc_v4 *a = NULL; struct bkey_i_alloc_v4 *a = NULL;
struct printbuf buf = PRINTBUF; struct printbuf buf = PRINTBUF;
struct bpos bucket = u64_to_bucket(lru_k.k->p.offset); 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)) if (bch2_bucket_is_open_safe(c, bucket.inode, bucket.offset))
return 0; 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); ret = PTR_ERR_OR_ZERO(a);
if (ret) if (ret)
goto out; 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[READ] = atomic64_read(&c->io_clock[READ].now);
a->v.io_time[WRITE] = atomic64_read(&c->io_clock[WRITE].now); a->v.io_time[WRITE] = atomic64_read(&c->io_clock[WRITE].now);
ret = bch2_trans_update(trans, &alloc_iter, &a->k_i, ret = bch2_trans_commit(trans, NULL, NULL,
BTREE_TRIGGER_bucket_invalidate) ?: BCH_WATERMARK_btree|
bch2_trans_commit(trans, NULL, NULL, BCH_TRANS_COMMIT_no_enospc);
BCH_WATERMARK_btree|
BCH_TRANS_COMMIT_no_enospc);
if (ret) if (ret)
goto out; goto out;
trace_and_count(c, bucket_invalidate, c, bucket.inode, bucket.offset, cached_sectors); trace_and_count(c, bucket_invalidate, c, bucket.inode, bucket.offset, cached_sectors);
--*nr_to_invalidate; --*nr_to_invalidate;
out: out:
bch2_trans_iter_exit(trans, &alloc_iter);
printbuf_exit(&buf); printbuf_exit(&buf);
return ret; return ret;
err: err:
@ -2175,7 +2181,7 @@ int bch2_bucket_io_time_reset(struct btree_trans *trans, unsigned dev,
if (bch2_trans_relock(trans)) if (bch2_trans_relock(trans))
bch2_trans_begin(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); ret = PTR_ERR_OR_ZERO(a);
if (ret) if (ret)
return ret; return ret;

View File

@ -179,7 +179,9 @@ static inline void set_alloc_v4_u64s(struct bkey_i_alloc_v4 *a)
} }
struct bkey_i_alloc_v4 * 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 *); void __bch2_alloc_to_v4(struct bkey_s_c, struct bch_alloc_v4 *);

View File

@ -973,16 +973,9 @@ static int bch2_trigger_pointer(struct btree_trans *trans,
*sectors = insert ? bp.bucket_len : -((s64) bp.bucket_len); *sectors = insert ? bp.bucket_len : -((s64) bp.bucket_len);
if (flags & BTREE_TRIGGER_transactional) { if (flags & BTREE_TRIGGER_transactional) {
struct btree_iter iter; struct bkey_i_alloc_v4 *a = bch2_trans_start_alloc_update(trans, bucket);
struct bkey_i_alloc_v4 *a = bch2_trans_start_alloc_update(trans, &iter, bucket); int ret = PTR_ERR_OR_ZERO(a) ?:
int ret = PTR_ERR_OR_ZERO(a); __mark_pointer(trans, k, &p.ptr, *sectors, bp.data_type, &a->v);
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);
if (ret) if (ret)
return ret; return ret;
@ -1266,7 +1259,7 @@ static int __bch2_trans_mark_metadata_bucket(struct btree_trans *trans,
int ret = 0; int ret = 0;
struct bkey_i_alloc_v4 *a = 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)) if (IS_ERR(a))
return PTR_ERR(a); return PTR_ERR(a);

View File

@ -269,20 +269,10 @@ static int mark_stripe_bucket(struct btree_trans *trans,
struct bpos bucket = PTR_BUCKET_POS(c, ptr); struct bpos bucket = PTR_BUCKET_POS(c, ptr);
if (flags & BTREE_TRIGGER_transactional) { if (flags & BTREE_TRIGGER_transactional) {
struct btree_iter iter;
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, bucket);
int ret = PTR_ERR_OR_ZERO(a) ?: return PTR_ERR_OR_ZERO(a) ?:
__mark_stripe_bucket(trans, s, ptr_idx, deleting, iter.pos, &a->v); __mark_stripe_bucket(trans, s, ptr_idx, deleting, bucket, &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;
} }
if (flags & BTREE_TRIGGER_gc) { if (flags & BTREE_TRIGGER_gc) {