From bcb79a51cb52033bb12c5ed2eb46770e984b5542 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Sat, 29 Apr 2023 19:33:09 -0400 Subject: bcachefs: bch2_bkey_get_iter() helpers Introduce new helpers for a common pattern: bch2_trans_iter_init(); bch2_btree_iter_peek_slot(); - bch2_bkey_get_iter_type() returns -ENOENT if it doesn't find a key of the correct type - bch2_bkey_get_val_typed() copies the val out of the btree to a (typically stack allocated) variable; it handles the case where the value in the btree is smaller than the current version of the type, zeroing out the remainder. Signed-off-by: Kent Overstreet --- fs/bcachefs/ec.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'fs/bcachefs/ec.c') diff --git a/fs/bcachefs/ec.c b/fs/bcachefs/ec.c index cf9f8c026034..439fa540323f 100644 --- a/fs/bcachefs/ec.c +++ b/fs/bcachefs/ec.c @@ -452,9 +452,8 @@ static int get_stripe_key_trans(struct btree_trans *trans, u64 idx, struct bkey_s_c k; int ret; - bch2_trans_iter_init(trans, &iter, BTREE_ID_stripes, - POS(0, idx), BTREE_ITER_SLOTS); - k = bch2_btree_iter_peek_slot(&iter); + k = bch2_bkey_get_iter(trans, &iter, BTREE_ID_stripes, + POS(0, idx), BTREE_ITER_SLOTS); ret = bkey_err(k); if (ret) goto err; @@ -755,9 +754,8 @@ static int ec_stripe_delete(struct btree_trans *trans, u64 idx) struct bkey_s_c_stripe s; int ret; - bch2_trans_iter_init(trans, &iter, BTREE_ID_stripes, POS(0, idx), - BTREE_ITER_INTENT); - k = bch2_btree_iter_peek_slot(&iter); + k = bch2_bkey_get_iter(trans, &iter, BTREE_ID_stripes, POS(0, idx), + BTREE_ITER_INTENT); ret = bkey_err(k); if (ret) goto err; @@ -835,9 +833,8 @@ static int ec_stripe_key_update(struct btree_trans *trans, struct bkey_s_c k; int ret; - bch2_trans_iter_init(trans, &iter, BTREE_ID_stripes, - new->k.p, BTREE_ITER_INTENT); - k = bch2_btree_iter_peek_slot(&iter); + k = bch2_bkey_get_iter(trans, &iter, BTREE_ID_stripes, + new->k.p, BTREE_ITER_INTENT); ret = bkey_err(k); if (ret) goto err; -- cgit v1.2.3