Commit 5934a0ca authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: bkey_on_stack_reassemble()

Small helper function.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent bd7e82ee
...@@ -19,6 +19,14 @@ static inline void bkey_on_stack_realloc(struct bkey_on_stack *s, ...@@ -19,6 +19,14 @@ static inline void bkey_on_stack_realloc(struct bkey_on_stack *s,
} }
} }
static inline void bkey_on_stack_reassemble(struct bkey_on_stack *s,
struct bch_fs *c,
struct bkey_s_c k)
{
bkey_on_stack_realloc(s, c, k.k->u64s);
bkey_reassemble(s->k, k);
}
static inline void bkey_on_stack_init(struct bkey_on_stack *s) static inline void bkey_on_stack_init(struct bkey_on_stack *s)
{ {
s->k = (void *) s->onstack; s->k = (void *) s->onstack;
......
...@@ -356,12 +356,11 @@ struct btree_nr_keys bch2_extent_sort_fix_overlapping(struct bch_fs *c, ...@@ -356,12 +356,11 @@ struct btree_nr_keys bch2_extent_sort_fix_overlapping(struct bch_fs *c,
extent_sort_sift(iter, b, _r - iter->data); extent_sort_sift(iter, b, _r - iter->data);
} else if (bkey_cmp(l.k->p, r.k->p) > 0) { } else if (bkey_cmp(l.k->p, r.k->p) > 0) {
bkey_on_stack_realloc(&split, c, l.k->u64s);
/* /*
* r wins, but it overlaps in the middle of l - split l: * r wins, but it overlaps in the middle of l - split l:
*/ */
bkey_reassemble(split.k, l.s_c); bkey_on_stack_reassemble(&split, c, l.s_c);
bch2_cut_back(bkey_start_pos(r.k), split.k); bch2_cut_back(bkey_start_pos(r.k), split.k);
bch2_cut_front_s(r.k->p, l); bch2_cut_front_s(r.k->p, l);
......
...@@ -807,8 +807,7 @@ static int ec_stripe_update_ptrs(struct bch_fs *c, ...@@ -807,8 +807,7 @@ static int ec_stripe_update_ptrs(struct bch_fs *c,
dev = s->key.v.ptrs[idx].dev; dev = s->key.v.ptrs[idx].dev;
bkey_on_stack_realloc(&sk, c, k.k->u64s); bkey_on_stack_reassemble(&sk, c, k);
bkey_reassemble(sk.k, k);
e = bkey_i_to_s_extent(sk.k); e = bkey_i_to_s_extent(sk.k);
extent_for_each_ptr(e, ptr) { extent_for_each_ptr(e, ptr) {
......
...@@ -347,7 +347,7 @@ extent_squash(struct bch_fs *c, struct btree_iter *iter, ...@@ -347,7 +347,7 @@ extent_squash(struct bch_fs *c, struct btree_iter *iter,
struct bkey_on_stack split; struct bkey_on_stack split;
bkey_on_stack_init(&split); bkey_on_stack_init(&split);
bkey_on_stack_realloc(&split, c, k.k->u64s); bkey_on_stack_reassemble(&split, c, k.s_c);
/* /*
* The insert key falls 'in the middle' of k * The insert key falls 'in the middle' of k
...@@ -363,7 +363,6 @@ extent_squash(struct bch_fs *c, struct btree_iter *iter, ...@@ -363,7 +363,6 @@ extent_squash(struct bch_fs *c, struct btree_iter *iter,
* modify k _before_ doing the insert (which will move * modify k _before_ doing the insert (which will move
* what k points to) * what k points to)
*/ */
bkey_reassemble(split.k, k.s_c);
split.k->k.needs_whiteout |= bkey_written(l->b, _k); split.k->k.needs_whiteout |= bkey_written(l->b, _k);
bch2_cut_back(bkey_start_pos(&insert->k), split.k); bch2_cut_back(bkey_start_pos(&insert->k), split.k);
......
...@@ -780,8 +780,7 @@ static void bchfs_read(struct btree_trans *trans, struct btree_iter *iter, ...@@ -780,8 +780,7 @@ static void bchfs_read(struct btree_trans *trans, struct btree_iter *iter,
if (ret) if (ret)
break; break;
bkey_on_stack_realloc(&sk, c, k.k->u64s); bkey_on_stack_reassemble(&sk, c, k);
bkey_reassemble(sk.k, k);
k = bkey_i_to_s_c(sk.k); k = bkey_i_to_s_c(sk.k);
offset_into_extent = iter->pos.offset - offset_into_extent = iter->pos.offset -
...@@ -2476,8 +2475,7 @@ static long bchfs_fcollapse_finsert(struct bch_inode_info *inode, ...@@ -2476,8 +2475,7 @@ static long bchfs_fcollapse_finsert(struct bch_inode_info *inode,
bkey_cmp(k.k->p, POS(inode->v.i_ino, offset >> 9)) <= 0) bkey_cmp(k.k->p, POS(inode->v.i_ino, offset >> 9)) <= 0)
break; break;
reassemble: reassemble:
bkey_on_stack_realloc(&copy, c, k.k->u64s); bkey_on_stack_reassemble(&copy, c, k);
bkey_reassemble(copy.k, k);
if (insert && if (insert &&
bkey_cmp(bkey_start_pos(k.k), move_pos) < 0) { bkey_cmp(bkey_start_pos(k.k), move_pos) < 0) {
......
...@@ -1538,8 +1538,7 @@ static void bch2_read_retry_nodecode(struct bch_fs *c, struct bch_read_bio *rbio ...@@ -1538,8 +1538,7 @@ static void bch2_read_retry_nodecode(struct bch_fs *c, struct bch_read_bio *rbio
if (bkey_err(k)) if (bkey_err(k))
goto err; goto err;
bkey_on_stack_realloc(&sk, c, k.k->u64s); bkey_on_stack_reassemble(&sk, c, k);
bkey_reassemble(sk.k, k);
k = bkey_i_to_s_c(sk.k); k = bkey_i_to_s_c(sk.k);
bch2_trans_unlock(&trans); bch2_trans_unlock(&trans);
...@@ -1590,8 +1589,7 @@ static void bch2_read_retry(struct bch_fs *c, struct bch_read_bio *rbio, ...@@ -1590,8 +1589,7 @@ static void bch2_read_retry(struct bch_fs *c, struct bch_read_bio *rbio,
BTREE_ITER_SLOTS, k, ret) { BTREE_ITER_SLOTS, k, ret) {
unsigned bytes, sectors, offset_into_extent; unsigned bytes, sectors, offset_into_extent;
bkey_on_stack_realloc(&sk, c, k.k->u64s); bkey_on_stack_reassemble(&sk, c, k);
bkey_reassemble(sk.k, k);
k = bkey_i_to_s_c(sk.k); k = bkey_i_to_s_c(sk.k);
offset_into_extent = iter->pos.offset - offset_into_extent = iter->pos.offset -
...@@ -1714,8 +1712,7 @@ static void bch2_rbio_narrow_crcs(struct bch_read_bio *rbio) ...@@ -1714,8 +1712,7 @@ static void bch2_rbio_narrow_crcs(struct bch_read_bio *rbio)
if (IS_ERR_OR_NULL(k.k)) if (IS_ERR_OR_NULL(k.k))
goto out; goto out;
bkey_on_stack_realloc(&new, c, k.k->u64s); bkey_on_stack_reassemble(&new, c, k);
bkey_reassemble(new.k, k);
k = bkey_i_to_s_c(new.k); k = bkey_i_to_s_c(new.k);
if (bversion_cmp(k.k->version, rbio->version) || if (bversion_cmp(k.k->version, rbio->version) ||
...@@ -2229,8 +2226,7 @@ void bch2_read(struct bch_fs *c, struct bch_read_bio *rbio, u64 inode) ...@@ -2229,8 +2226,7 @@ void bch2_read(struct bch_fs *c, struct bch_read_bio *rbio, u64 inode)
bkey_start_offset(k.k); bkey_start_offset(k.k);
sectors = k.k->size - offset_into_extent; sectors = k.k->size - offset_into_extent;
bkey_on_stack_realloc(&sk, c, k.k->u64s); bkey_on_stack_reassemble(&sk, c, k);
bkey_reassemble(sk.k, k);
k = bkey_i_to_s_c(sk.k); k = bkey_i_to_s_c(sk.k);
ret = bch2_read_indirect_extent(&trans, ret = bch2_read_indirect_extent(&trans,
......
...@@ -60,8 +60,7 @@ static int __bch2_dev_usrdata_drop(struct bch_fs *c, unsigned dev_idx, int flags ...@@ -60,8 +60,7 @@ static int __bch2_dev_usrdata_drop(struct bch_fs *c, unsigned dev_idx, int flags
continue; continue;
} }
bkey_on_stack_realloc(&sk, c, k.k->u64s); bkey_on_stack_reassemble(&sk, c, k);
bkey_reassemble(sk.k, k);
ret = drop_dev_ptrs(c, bkey_i_to_s(sk.k), ret = drop_dev_ptrs(c, bkey_i_to_s(sk.k),
dev_idx, flags, false); dev_idx, flags, false);
......
...@@ -578,8 +578,7 @@ static int __bch2_move_data(struct bch_fs *c, ...@@ -578,8 +578,7 @@ static int __bch2_move_data(struct bch_fs *c,
} }
/* unlock before doing IO: */ /* unlock before doing IO: */
bkey_on_stack_realloc(&sk, c, k.k->u64s); bkey_on_stack_reassemble(&sk, c, k);
bkey_reassemble(sk.k, k);
k = bkey_i_to_s_c(sk.k); k = bkey_i_to_s_c(sk.k);
bch2_trans_unlock(&trans); bch2_trans_unlock(&trans);
......
...@@ -225,8 +225,7 @@ s64 bch2_remap_range(struct bch_fs *c, ...@@ -225,8 +225,7 @@ s64 bch2_remap_range(struct bch_fs *c,
break; break;
if (src_k.k->type == KEY_TYPE_extent) { if (src_k.k->type == KEY_TYPE_extent) {
bkey_on_stack_realloc(&new_src, c, src_k.k->u64s); bkey_on_stack_reassemble(&new_src, c, src_k);
bkey_reassemble(new_src.k, src_k);
src_k = bkey_i_to_s_c(new_src.k); src_k = bkey_i_to_s_c(new_src.k);
bch2_cut_front(src_iter->pos, new_src.k); bch2_cut_front(src_iter->pos, new_src.k);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment