summaryrefslogtreecommitdiff
path: root/fs/bcachefs/ec.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2023-04-29 19:33:09 -0400
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-22 17:10:00 -0400
commitbcb79a51cb52033bb12c5ed2eb46770e984b5542 (patch)
tree9474d9d274906a44a8a49fba8cd4bb74144e6c64 /fs/bcachefs/ec.c
parent174f930b8e1cad3915819a46bb20da214f68f2b5 (diff)
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 <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/ec.c')
-rw-r--r--fs/bcachefs/ec.c15
1 files changed, 6 insertions, 9 deletions
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;