diff options
author | Kent Overstreet <kent.overstreet@linux.dev> | 2023-04-30 02:33:09 +0300 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-23 00:10:00 +0300 |
commit | bcb79a51cb52033bb12c5ed2eb46770e984b5542 (patch) | |
tree | 9474d9d274906a44a8a49fba8cd4bb74144e6c64 /fs/bcachefs/io.c | |
parent | 174f930b8e1cad3915819a46bb20da214f68f2b5 (diff) | |
download | linux-bcb79a51cb52033bb12c5ed2eb46770e984b5542.tar.xz |
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/io.c')
-rw-r--r-- | fs/bcachefs/io.c | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/fs/bcachefs/io.c b/fs/bcachefs/io.c index cc2dfcf16dee..01911db786f5 100644 --- a/fs/bcachefs/io.c +++ b/fs/bcachefs/io.c @@ -2312,9 +2312,8 @@ static int __bch2_rbio_narrow_crcs(struct btree_trans *trans, if (crc_is_compressed(rbio->pick.crc)) return 0; - bch2_trans_iter_init(trans, &iter, rbio->data_btree, rbio->data_pos, - BTREE_ITER_SLOTS|BTREE_ITER_INTENT); - k = bch2_btree_iter_peek_slot(&iter); + k = bch2_bkey_get_iter(trans, &iter, rbio->data_btree, rbio->data_pos, + BTREE_ITER_SLOTS|BTREE_ITER_INTENT); if ((ret = bkey_err(k))) goto out; @@ -2550,10 +2549,8 @@ int __bch2_read_indirect_extent(struct btree_trans *trans, reflink_offset = le64_to_cpu(bkey_i_to_reflink_p(orig_k->k)->v.idx) + *offset_into_extent; - bch2_trans_iter_init(trans, &iter, BTREE_ID_reflink, - POS(0, reflink_offset), - BTREE_ITER_SLOTS); - k = bch2_btree_iter_peek_slot(&iter); + k = bch2_bkey_get_iter(trans, &iter, BTREE_ID_reflink, + POS(0, reflink_offset), 0); ret = bkey_err(k); if (ret) goto err; |