Commit 07a1006a authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Reduce/kill BKEY_PADDED use

With various newer key types - stripe keys, inline data extents - the
old approach of calculating the maximum size of the value is becoming
more and more error prone. Better to switch to bkey_on_stack, which can
dynamically allocate if necessary to handle any size bkey.

In particular we also want to get rid of BKEY_EXTENT_VAL_U64s_MAX.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 8deed5f4
...@@ -638,8 +638,6 @@ struct bch_reservation { ...@@ -638,8 +638,6 @@ struct bch_reservation {
#define BKEY_EXTENT_VAL_U64s_MAX \ #define BKEY_EXTENT_VAL_U64s_MAX \
(1 + BKEY_EXTENT_PTR_U64s_MAX * (BCH_REPLICAS_MAX + 1)) (1 + BKEY_EXTENT_PTR_U64s_MAX * (BCH_REPLICAS_MAX + 1))
#define BKEY_PADDED(key) __BKEY_PADDED(key, BKEY_EXTENT_VAL_U64s_MAX)
/* * Maximum possible size of an entire extent, key + value: */ /* * Maximum possible size of an entire extent, key + value: */
#define BKEY_EXTENT_U64s_MAX (BKEY_U64s + BKEY_EXTENT_VAL_U64s_MAX) #define BKEY_EXTENT_U64s_MAX (BKEY_U64s + BKEY_EXTENT_VAL_U64s_MAX)
......
/* SPDX-License-Identifier: GPL-2.0 */ /* SPDX-License-Identifier: GPL-2.0 */
#ifndef _BCACHEFS_BKEY_ON_STACK_H #ifndef _BCACHEFS_BKEY_BUF_H
#define _BCACHEFS_BKEY_ON_STACK_H #define _BCACHEFS_BKEY_BUF_H
#include "bcachefs.h" #include "bcachefs.h"
struct bkey_on_stack { struct bkey_buf {
struct bkey_i *k; struct bkey_i *k;
u64 onstack[12]; u64 onstack[12];
}; };
static inline void bkey_on_stack_realloc(struct bkey_on_stack *s, static inline void bch2_bkey_buf_realloc(struct bkey_buf *s,
struct bch_fs *c, unsigned u64s) struct bch_fs *c, unsigned u64s)
{ {
if (s->k == (void *) s->onstack && if (s->k == (void *) s->onstack &&
...@@ -19,25 +19,42 @@ static inline void bkey_on_stack_realloc(struct bkey_on_stack *s, ...@@ -19,25 +19,42 @@ static inline void bkey_on_stack_realloc(struct bkey_on_stack *s,
} }
} }
static inline void bkey_on_stack_reassemble(struct bkey_on_stack *s, static inline void bch2_bkey_buf_reassemble(struct bkey_buf *s,
struct bch_fs *c, struct bch_fs *c,
struct bkey_s_c k) struct bkey_s_c k)
{ {
bkey_on_stack_realloc(s, c, k.k->u64s); bch2_bkey_buf_realloc(s, c, k.k->u64s);
bkey_reassemble(s->k, k); bkey_reassemble(s->k, k);
} }
static inline void bkey_on_stack_init(struct bkey_on_stack *s) static inline void bch2_bkey_buf_copy(struct bkey_buf *s,
struct bch_fs *c,
struct bkey_i *src)
{
bch2_bkey_buf_realloc(s, c, src->k.u64s);
bkey_copy(s->k, src);
}
static inline void bch2_bkey_buf_unpack(struct bkey_buf *s,
struct bch_fs *c,
struct btree *b,
struct bkey_packed *src)
{
bch2_bkey_buf_realloc(s, c, BKEY_U64s +
bkeyp_val_u64s(&b->format, src));
bch2_bkey_unpack(b, s->k, src);
}
static inline void bch2_bkey_buf_init(struct bkey_buf *s)
{ {
s->k = (void *) s->onstack; s->k = (void *) s->onstack;
} }
static inline void bkey_on_stack_exit(struct bkey_on_stack *s, static inline void bch2_bkey_buf_exit(struct bkey_buf *s, struct bch_fs *c)
struct bch_fs *c)
{ {
if (s->k != (void *) s->onstack) if (s->k != (void *) s->onstack)
mempool_free(s->k, &c->large_bkey_pool); mempool_free(s->k, &c->large_bkey_pool);
s->k = NULL; s->k = NULL;
} }
#endif /* _BCACHEFS_BKEY_ON_STACK_H */ #endif /* _BCACHEFS_BKEY_BUF_H */
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#include "bcachefs.h" #include "bcachefs.h"
#include "bkey_on_stack.h" #include "bkey_buf.h"
#include "bkey_sort.h" #include "bkey_sort.h"
#include "bset.h" #include "bset.h"
#include "extents.h" #include "extents.h"
...@@ -187,11 +187,11 @@ bch2_sort_repack_merge(struct bch_fs *c, ...@@ -187,11 +187,11 @@ bch2_sort_repack_merge(struct bch_fs *c,
bool filter_whiteouts) bool filter_whiteouts)
{ {
struct bkey_packed *out = vstruct_last(dst), *k_packed; struct bkey_packed *out = vstruct_last(dst), *k_packed;
struct bkey_on_stack k; struct bkey_buf k;
struct btree_nr_keys nr; struct btree_nr_keys nr;
memset(&nr, 0, sizeof(nr)); memset(&nr, 0, sizeof(nr));
bkey_on_stack_init(&k); bch2_bkey_buf_init(&k);
while ((k_packed = bch2_btree_node_iter_next_all(iter, src))) { while ((k_packed = bch2_btree_node_iter_next_all(iter, src))) {
if (filter_whiteouts && bkey_whiteout(k_packed)) if (filter_whiteouts && bkey_whiteout(k_packed))
...@@ -204,7 +204,7 @@ bch2_sort_repack_merge(struct bch_fs *c, ...@@ -204,7 +204,7 @@ bch2_sort_repack_merge(struct bch_fs *c,
* node; we have to make a copy of the entire key before calling * node; we have to make a copy of the entire key before calling
* normalize * normalize
*/ */
bkey_on_stack_realloc(&k, c, k_packed->u64s + BKEY_U64s); bch2_bkey_buf_realloc(&k, c, k_packed->u64s + BKEY_U64s);
bch2_bkey_unpack(src, k.k, k_packed); bch2_bkey_unpack(src, k.k, k_packed);
if (filter_whiteouts && if (filter_whiteouts &&
...@@ -215,7 +215,7 @@ bch2_sort_repack_merge(struct bch_fs *c, ...@@ -215,7 +215,7 @@ bch2_sort_repack_merge(struct bch_fs *c,
} }
dst->u64s = cpu_to_le16((u64 *) out - dst->_data); dst->u64s = cpu_to_le16((u64 *) out - dst->_data);
bkey_on_stack_exit(&k, c); bch2_bkey_buf_exit(&k, c);
return nr; return nr;
} }
...@@ -315,11 +315,11 @@ bch2_extent_sort_fix_overlapping(struct bch_fs *c, struct bset *dst, ...@@ -315,11 +315,11 @@ bch2_extent_sort_fix_overlapping(struct bch_fs *c, struct bset *dst,
struct bkey l_unpacked, r_unpacked; struct bkey l_unpacked, r_unpacked;
struct bkey_s l, r; struct bkey_s l, r;
struct btree_nr_keys nr; struct btree_nr_keys nr;
struct bkey_on_stack split; struct bkey_buf split;
unsigned i; unsigned i;
memset(&nr, 0, sizeof(nr)); memset(&nr, 0, sizeof(nr));
bkey_on_stack_init(&split); bch2_bkey_buf_init(&split);
sort_iter_sort(iter, extent_sort_fix_overlapping_cmp); sort_iter_sort(iter, extent_sort_fix_overlapping_cmp);
for (i = 0; i < iter->used;) { for (i = 0; i < iter->used;) {
...@@ -379,7 +379,7 @@ bch2_extent_sort_fix_overlapping(struct bch_fs *c, struct bset *dst, ...@@ -379,7 +379,7 @@ bch2_extent_sort_fix_overlapping(struct bch_fs *c, struct bset *dst,
/* /*
* 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_on_stack_reassemble(&split, c, l.s_c); bch2_bkey_buf_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);
...@@ -398,7 +398,7 @@ bch2_extent_sort_fix_overlapping(struct bch_fs *c, struct bset *dst, ...@@ -398,7 +398,7 @@ bch2_extent_sort_fix_overlapping(struct bch_fs *c, struct bset *dst,
dst->u64s = cpu_to_le16((u64 *) out - dst->_data); dst->u64s = cpu_to_le16((u64 *) out - dst->_data);
bkey_on_stack_exit(&split, c); bch2_bkey_buf_exit(&split, c);
return nr; return nr;
} }
......
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#include "bcachefs.h" #include "bcachefs.h"
#include "bkey_buf.h"
#include "btree_cache.h" #include "btree_cache.h"
#include "btree_io.h" #include "btree_io.h"
#include "btree_iter.h" #include "btree_iter.h"
...@@ -899,10 +900,12 @@ struct btree *bch2_btree_node_get_sibling(struct bch_fs *c, ...@@ -899,10 +900,12 @@ struct btree *bch2_btree_node_get_sibling(struct bch_fs *c,
struct btree *parent; struct btree *parent;
struct btree_node_iter node_iter; struct btree_node_iter node_iter;
struct bkey_packed *k; struct bkey_packed *k;
BKEY_PADDED(k) tmp; struct bkey_buf tmp;
struct btree *ret = NULL; struct btree *ret = NULL;
unsigned level = b->c.level; unsigned level = b->c.level;
bch2_bkey_buf_init(&tmp);
parent = btree_iter_node(iter, level + 1); parent = btree_iter_node(iter, level + 1);
if (!parent) if (!parent)
return NULL; return NULL;
...@@ -936,9 +939,9 @@ struct btree *bch2_btree_node_get_sibling(struct bch_fs *c, ...@@ -936,9 +939,9 @@ struct btree *bch2_btree_node_get_sibling(struct bch_fs *c,
if (!k) if (!k)
goto out; goto out;
bch2_bkey_unpack(parent, &tmp.k, k); bch2_bkey_buf_unpack(&tmp, c, parent, k);
ret = bch2_btree_node_get(c, iter, &tmp.k, level, ret = bch2_btree_node_get(c, iter, tmp.k, level,
SIX_LOCK_intent, _THIS_IP_); SIX_LOCK_intent, _THIS_IP_);
if (PTR_ERR_OR_ZERO(ret) == -EINTR && !trans->nounlock) { if (PTR_ERR_OR_ZERO(ret) == -EINTR && !trans->nounlock) {
...@@ -958,7 +961,7 @@ struct btree *bch2_btree_node_get_sibling(struct bch_fs *c, ...@@ -958,7 +961,7 @@ struct btree *bch2_btree_node_get_sibling(struct bch_fs *c,
if (sib == btree_prev_sib) if (sib == btree_prev_sib)
btree_node_unlock(iter, level); btree_node_unlock(iter, level);
ret = bch2_btree_node_get(c, iter, &tmp.k, level, ret = bch2_btree_node_get(c, iter, tmp.k, level,
SIX_LOCK_intent, _THIS_IP_); SIX_LOCK_intent, _THIS_IP_);
/* /*
...@@ -999,6 +1002,8 @@ struct btree *bch2_btree_node_get_sibling(struct bch_fs *c, ...@@ -999,6 +1002,8 @@ struct btree *bch2_btree_node_get_sibling(struct bch_fs *c,
bch2_btree_trans_verify_locks(trans); bch2_btree_trans_verify_locks(trans);
bch2_bkey_buf_exit(&tmp, c);
return ret; return ret;
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include "alloc_background.h" #include "alloc_background.h"
#include "alloc_foreground.h" #include "alloc_foreground.h"
#include "bkey_methods.h" #include "bkey_methods.h"
#include "bkey_on_stack.h" #include "bkey_buf.h"
#include "btree_locking.h" #include "btree_locking.h"
#include "btree_update_interior.h" #include "btree_update_interior.h"
#include "btree_io.h" #include "btree_io.h"
...@@ -267,10 +267,12 @@ static int bch2_gc_btree_init_recurse(struct bch_fs *c, struct btree *b, ...@@ -267,10 +267,12 @@ static int bch2_gc_btree_init_recurse(struct bch_fs *c, struct btree *b,
struct btree_and_journal_iter iter; struct btree_and_journal_iter iter;
struct bkey_s_c k; struct bkey_s_c k;
struct bpos next_node_start = b->data->min_key; struct bpos next_node_start = b->data->min_key;
struct bkey_buf tmp;
u8 max_stale = 0; u8 max_stale = 0;
int ret = 0; int ret = 0;
bch2_btree_and_journal_iter_init_node_iter(&iter, journal_keys, b); bch2_btree_and_journal_iter_init_node_iter(&iter, journal_keys, b);
bch2_bkey_buf_init(&tmp);
while ((k = bch2_btree_and_journal_iter_peek(&iter)).k) { while ((k = bch2_btree_and_journal_iter_peek(&iter)).k) {
bch2_bkey_debugcheck(c, b, k); bch2_bkey_debugcheck(c, b, k);
...@@ -284,10 +286,9 @@ static int bch2_gc_btree_init_recurse(struct bch_fs *c, struct btree *b, ...@@ -284,10 +286,9 @@ static int bch2_gc_btree_init_recurse(struct bch_fs *c, struct btree *b,
if (b->c.level) { if (b->c.level) {
struct btree *child; struct btree *child;
BKEY_PADDED(k) tmp;
bkey_reassemble(&tmp.k, k); bch2_bkey_buf_reassemble(&tmp, c, k);
k = bkey_i_to_s_c(&tmp.k); k = bkey_i_to_s_c(tmp.k);
bch2_btree_and_journal_iter_advance(&iter); bch2_btree_and_journal_iter_advance(&iter);
...@@ -299,7 +300,7 @@ static int bch2_gc_btree_init_recurse(struct bch_fs *c, struct btree *b, ...@@ -299,7 +300,7 @@ static int bch2_gc_btree_init_recurse(struct bch_fs *c, struct btree *b,
break; break;
if (b->c.level > target_depth) { if (b->c.level > target_depth) {
child = bch2_btree_node_get_noiter(c, &tmp.k, child = bch2_btree_node_get_noiter(c, tmp.k,
b->c.btree_id, b->c.level - 1); b->c.btree_id, b->c.level - 1);
ret = PTR_ERR_OR_ZERO(child); ret = PTR_ERR_OR_ZERO(child);
if (ret) if (ret)
...@@ -317,6 +318,7 @@ static int bch2_gc_btree_init_recurse(struct bch_fs *c, struct btree *b, ...@@ -317,6 +318,7 @@ static int bch2_gc_btree_init_recurse(struct bch_fs *c, struct btree *b,
} }
} }
bch2_bkey_buf_exit(&tmp, c);
return ret; return ret;
} }
...@@ -929,10 +931,10 @@ static int bch2_gc_btree_gens(struct bch_fs *c, enum btree_id btree_id) ...@@ -929,10 +931,10 @@ static int bch2_gc_btree_gens(struct bch_fs *c, enum btree_id btree_id)
struct btree_trans trans; struct btree_trans trans;
struct btree_iter *iter; struct btree_iter *iter;
struct bkey_s_c k; struct bkey_s_c k;
struct bkey_on_stack sk; struct bkey_buf sk;
int ret = 0; int ret = 0;
bkey_on_stack_init(&sk); bch2_bkey_buf_init(&sk);
bch2_trans_init(&trans, c, 0, 0); bch2_trans_init(&trans, c, 0, 0);
iter = bch2_trans_get_iter(&trans, btree_id, POS_MIN, iter = bch2_trans_get_iter(&trans, btree_id, POS_MIN,
...@@ -941,7 +943,7 @@ static int bch2_gc_btree_gens(struct bch_fs *c, enum btree_id btree_id) ...@@ -941,7 +943,7 @@ static int bch2_gc_btree_gens(struct bch_fs *c, enum btree_id btree_id)
while ((k = bch2_btree_iter_peek(iter)).k && while ((k = bch2_btree_iter_peek(iter)).k &&
!(ret = bkey_err(k))) { !(ret = bkey_err(k))) {
if (gc_btree_gens_key(c, k)) { if (gc_btree_gens_key(c, k)) {
bkey_on_stack_reassemble(&sk, c, k); bch2_bkey_buf_reassemble(&sk, c, k);
bch2_extent_normalize(c, bkey_i_to_s(sk.k)); bch2_extent_normalize(c, bkey_i_to_s(sk.k));
bch2_btree_iter_set_pos(iter, bkey_start_pos(&sk.k->k)); bch2_btree_iter_set_pos(iter, bkey_start_pos(&sk.k->k));
...@@ -961,7 +963,7 @@ static int bch2_gc_btree_gens(struct bch_fs *c, enum btree_id btree_id) ...@@ -961,7 +963,7 @@ static int bch2_gc_btree_gens(struct bch_fs *c, enum btree_id btree_id)
} }
bch2_trans_exit(&trans); bch2_trans_exit(&trans);
bkey_on_stack_exit(&sk, c); bch2_bkey_buf_exit(&sk, c);
return ret; return ret;
} }
...@@ -1073,7 +1075,7 @@ static void bch2_coalesce_nodes(struct bch_fs *c, struct btree_iter *iter, ...@@ -1073,7 +1075,7 @@ static void bch2_coalesce_nodes(struct bch_fs *c, struct btree_iter *iter,
} }
if (bch2_keylist_realloc(&keylist, NULL, 0, if (bch2_keylist_realloc(&keylist, NULL, 0,
(BKEY_U64s + BKEY_EXTENT_U64s_MAX) * nr_old_nodes)) { BKEY_BTREE_PTR_U64s_MAX * nr_old_nodes)) {
trace_btree_gc_coalesce_fail(c, trace_btree_gc_coalesce_fail(c,
BTREE_GC_COALESCE_FAIL_KEYLIST_REALLOC); BTREE_GC_COALESCE_FAIL_KEYLIST_REALLOC);
return; return;
......
...@@ -1320,12 +1320,13 @@ static void bch2_btree_node_write_error(struct bch_fs *c, ...@@ -1320,12 +1320,13 @@ static void bch2_btree_node_write_error(struct bch_fs *c,
struct btree_write_bio *wbio) struct btree_write_bio *wbio)
{ {
struct btree *b = wbio->wbio.bio.bi_private; struct btree *b = wbio->wbio.bio.bi_private;
__BKEY_PADDED(k, BKEY_BTREE_PTR_VAL_U64s_MAX) tmp; struct bkey_buf k;
struct bch_extent_ptr *ptr; struct bch_extent_ptr *ptr;
struct btree_trans trans; struct btree_trans trans;
struct btree_iter *iter; struct btree_iter *iter;
int ret; int ret;
bch2_bkey_buf_init(&k);
bch2_trans_init(&trans, c, 0, 0); bch2_trans_init(&trans, c, 0, 0);
iter = bch2_trans_get_node_iter(&trans, b->c.btree_id, b->key.k.p, iter = bch2_trans_get_node_iter(&trans, b->c.btree_id, b->key.k.p,
...@@ -1344,21 +1345,22 @@ static void bch2_btree_node_write_error(struct bch_fs *c, ...@@ -1344,21 +1345,22 @@ static void bch2_btree_node_write_error(struct bch_fs *c,
BUG_ON(!btree_node_hashed(b)); BUG_ON(!btree_node_hashed(b));
bkey_copy(&tmp.k, &b->key); bch2_bkey_buf_copy(&k, c, &b->key);
bch2_bkey_drop_ptrs(bkey_i_to_s(&tmp.k), ptr, bch2_bkey_drop_ptrs(bkey_i_to_s(k.k), ptr,
bch2_dev_list_has_dev(wbio->wbio.failed, ptr->dev)); bch2_dev_list_has_dev(wbio->wbio.failed, ptr->dev));
if (!bch2_bkey_nr_ptrs(bkey_i_to_s_c(&tmp.k))) if (!bch2_bkey_nr_ptrs(bkey_i_to_s_c(k.k)))
goto err; goto err;
ret = bch2_btree_node_update_key(c, iter, b, &tmp.k); ret = bch2_btree_node_update_key(c, iter, b, k.k);
if (ret == -EINTR) if (ret == -EINTR)
goto retry; goto retry;
if (ret) if (ret)
goto err; goto err;
out: out:
bch2_trans_exit(&trans); bch2_trans_exit(&trans);
bch2_bkey_buf_exit(&k, c);
bio_put(&wbio->wbio.bio); bio_put(&wbio->wbio.bio);
btree_node_write_done(c, b); btree_node_write_done(c, b);
return; return;
...@@ -1476,7 +1478,7 @@ void __bch2_btree_node_write(struct bch_fs *c, struct btree *b, ...@@ -1476,7 +1478,7 @@ void __bch2_btree_node_write(struct bch_fs *c, struct btree *b,
struct bset *i; struct bset *i;
struct btree_node *bn = NULL; struct btree_node *bn = NULL;
struct btree_node_entry *bne = NULL; struct btree_node_entry *bne = NULL;
BKEY_PADDED(key) k; struct bkey_buf k;
struct bch_extent_ptr *ptr; struct bch_extent_ptr *ptr;
struct sort_iter sort_iter; struct sort_iter sort_iter;
struct nonce nonce; struct nonce nonce;
...@@ -1487,6 +1489,8 @@ void __bch2_btree_node_write(struct bch_fs *c, struct btree *b, ...@@ -1487,6 +1489,8 @@ void __bch2_btree_node_write(struct bch_fs *c, struct btree *b,
bool validate_before_checksum = false; bool validate_before_checksum = false;
void *data; void *data;
bch2_bkey_buf_init(&k);
if (test_bit(BCH_FS_HOLD_BTREE_WRITES, &c->flags)) if (test_bit(BCH_FS_HOLD_BTREE_WRITES, &c->flags))
return; return;
...@@ -1696,15 +1700,16 @@ void __bch2_btree_node_write(struct bch_fs *c, struct btree *b, ...@@ -1696,15 +1700,16 @@ void __bch2_btree_node_write(struct bch_fs *c, struct btree *b,
* just make all btree node writes FUA to keep things sane. * just make all btree node writes FUA to keep things sane.
*/ */
bkey_copy(&k.key, &b->key); bch2_bkey_buf_copy(&k, c, &b->key);
bkey_for_each_ptr(bch2_bkey_ptrs(bkey_i_to_s(&k.key)), ptr) bkey_for_each_ptr(bch2_bkey_ptrs(bkey_i_to_s(k.k)), ptr)
ptr->offset += b->written; ptr->offset += b->written;
b->written += sectors_to_write; b->written += sectors_to_write;
/* XXX: submitting IO with btree locks held: */ /* XXX: submitting IO with btree locks held: */
bch2_submit_wbio_replicas(&wbio->wbio, c, BCH_DATA_btree, &k.key); bch2_submit_wbio_replicas(&wbio->wbio, c, BCH_DATA_btree, k.k);
bch2_bkey_buf_exit(&k, c);
return; return;
err: err:
set_btree_node_noevict(b); set_btree_node_noevict(b);
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include "bcachefs.h" #include "bcachefs.h"
#include "bkey_methods.h" #include "bkey_methods.h"
#include "bkey_buf.h"
#include "btree_cache.h" #include "btree_cache.h"
#include "btree_iter.h" #include "btree_iter.h"
#include "btree_key_cache.h" #include "btree_key_cache.h"
...@@ -1048,27 +1049,31 @@ static void btree_iter_prefetch(struct btree_iter *iter) ...@@ -1048,27 +1049,31 @@ static void btree_iter_prefetch(struct btree_iter *iter)
struct btree_iter_level *l = &iter->l[iter->level]; struct btree_iter_level *l = &iter->l[iter->level];
struct btree_node_iter node_iter = l->iter; struct btree_node_iter node_iter = l->iter;
struct bkey_packed *k; struct bkey_packed *k;
BKEY_PADDED(k) tmp; struct bkey_buf tmp;
unsigned nr = test_bit(BCH_FS_STARTED, &c->flags) unsigned nr = test_bit(BCH_FS_STARTED, &c->flags)
? (iter->level > 1 ? 0 : 2) ? (iter->level > 1 ? 0 : 2)
: (iter->level > 1 ? 1 : 16); : (iter->level > 1 ? 1 : 16);
bool was_locked = btree_node_locked(iter, iter->level); bool was_locked = btree_node_locked(iter, iter->level);
bch2_bkey_buf_init(&tmp);
while (nr) { while (nr) {
if (!bch2_btree_node_relock(iter, iter->level)) if (!bch2_btree_node_relock(iter, iter->level))
return; break;
bch2_btree_node_iter_advance(&node_iter, l->b); bch2_btree_node_iter_advance(&node_iter, l->b);
k = bch2_btree_node_iter_peek(&node_iter, l->b); k = bch2_btree_node_iter_peek(&node_iter, l->b);
if (!k) if (!k)
break; break;
bch2_bkey_unpack(l->b, &tmp.k, k); bch2_bkey_buf_unpack(&tmp, c, l->b, k);
bch2_btree_node_prefetch(c, iter, &tmp.k, iter->level - 1); bch2_btree_node_prefetch(c, iter, tmp.k, iter->level - 1);
} }
if (!was_locked) if (!was_locked)
btree_node_unlock(iter, iter->level); btree_node_unlock(iter, iter->level);
bch2_bkey_buf_exit(&tmp, c);
} }
static noinline void btree_node_mem_ptr_set(struct btree_iter *iter, static noinline void btree_node_mem_ptr_set(struct btree_iter *iter,
...@@ -1100,30 +1105,34 @@ static __always_inline int btree_iter_down(struct btree_iter *iter, ...@@ -1100,30 +1105,34 @@ static __always_inline int btree_iter_down(struct btree_iter *iter,
struct btree *b; struct btree *b;
unsigned level = iter->level - 1; unsigned level = iter->level - 1;
enum six_lock_type lock_type = __btree_lock_want(iter, level); enum six_lock_type lock_type = __btree_lock_want(iter, level);
BKEY_PADDED(k) tmp; struct bkey_buf tmp;
int ret;
EBUG_ON(!btree_node_locked(iter, iter->level)); EBUG_ON(!btree_node_locked(iter, iter->level));
bch2_bkey_unpack(l->b, &tmp.k, bch2_bkey_buf_init(&tmp);
bch2_bkey_buf_unpack(&tmp, c, l->b,
bch2_btree_node_iter_peek(&l->iter, l->b)); bch2_btree_node_iter_peek(&l->iter, l->b));
b = bch2_btree_node_get(c, iter, &tmp.k, level, lock_type, trace_ip); b = bch2_btree_node_get(c, iter, tmp.k, level, lock_type, trace_ip);
if (unlikely(IS_ERR(b))) ret = PTR_ERR_OR_ZERO(b);
return PTR_ERR(b); if (unlikely(ret))
goto err;
mark_btree_node_locked(iter, level, lock_type); mark_btree_node_locked(iter, level, lock_type);
btree_iter_node_set(iter, b); btree_iter_node_set(iter, b);
if (tmp.k.k.type == KEY_TYPE_btree_ptr_v2 && if (tmp.k->k.type == KEY_TYPE_btree_ptr_v2 &&
unlikely(b != btree_node_mem_ptr(&tmp.k))) unlikely(b != btree_node_mem_ptr(tmp.k)))
btree_node_mem_ptr_set(iter, level + 1, b); btree_node_mem_ptr_set(iter, level + 1, b);
if (iter->flags & BTREE_ITER_PREFETCH) if (iter->flags & BTREE_ITER_PREFETCH)
btree_iter_prefetch(iter); btree_iter_prefetch(iter);
iter->level = level; iter->level = level;
err:
return 0; bch2_bkey_buf_exit(&tmp, c);
return ret;
} }
static void btree_iter_up(struct btree_iter *iter) static void btree_iter_up(struct btree_iter *iter)
......
...@@ -57,7 +57,7 @@ struct btree_write { ...@@ -57,7 +57,7 @@ struct btree_write {
struct btree_alloc { struct btree_alloc {
struct open_buckets ob; struct open_buckets ob;
BKEY_PADDED(k); __BKEY_PADDED(k, BKEY_BTREE_PTR_VAL_U64s_MAX);
}; };
struct btree_bkey_cached_common { struct btree_bkey_cached_common {
......
...@@ -195,7 +195,7 @@ static struct btree *__bch2_btree_node_alloc(struct bch_fs *c, ...@@ -195,7 +195,7 @@ static struct btree *__bch2_btree_node_alloc(struct bch_fs *c,
{ {
struct write_point *wp; struct write_point *wp;
struct btree *b; struct btree *b;
BKEY_PADDED(k) tmp; __BKEY_PADDED(k, BKEY_BTREE_PTR_VAL_U64s_MAX) tmp;
struct open_buckets ob = { .nr = 0 }; struct open_buckets ob = { .nr = 0 };
struct bch_devs_list devs_have = (struct bch_devs_list) { 0 }; struct bch_devs_list devs_have = (struct bch_devs_list) { 0 };
unsigned nr_reserve; unsigned nr_reserve;
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include "bcachefs.h" #include "bcachefs.h"
#include "alloc_foreground.h" #include "alloc_foreground.h"
#include "bkey_on_stack.h" #include "bkey_buf.h"
#include "bset.h" #include "bset.h"
#include "btree_gc.h" #include "btree_gc.h"
#include "btree_update.h" #include "btree_update.h"
...@@ -783,10 +783,10 @@ static int ec_stripe_update_ptrs(struct bch_fs *c, ...@@ -783,10 +783,10 @@ static int ec_stripe_update_ptrs(struct bch_fs *c,
struct btree_iter *iter; struct btree_iter *iter;
struct bkey_s_c k; struct bkey_s_c k;
struct bkey_s_extent e; struct bkey_s_extent e;
struct bkey_on_stack sk; struct bkey_buf sk;
int ret = 0, dev, idx; int ret = 0, dev, idx;
bkey_on_stack_init(&sk); bch2_bkey_buf_init(&sk);
bch2_trans_init(&trans, c, BTREE_ITER_MAX, 0); bch2_trans_init(&trans, c, BTREE_ITER_MAX, 0);
/* XXX this doesn't support the reflink btree */ /* XXX this doesn't support the reflink btree */
...@@ -813,7 +813,7 @@ static int ec_stripe_update_ptrs(struct bch_fs *c, ...@@ -813,7 +813,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_reassemble(&sk, c, k); bch2_bkey_buf_reassemble(&sk, c, k);
e = bkey_i_to_s_extent(sk.k); e = bkey_i_to_s_extent(sk.k);
bch2_bkey_drop_ptrs(e.s, ptr, ptr->dev != dev); bch2_bkey_drop_ptrs(e.s, ptr, ptr->dev != dev);
...@@ -834,7 +834,7 @@ static int ec_stripe_update_ptrs(struct bch_fs *c, ...@@ -834,7 +834,7 @@ static int ec_stripe_update_ptrs(struct bch_fs *c,
} }
bch2_trans_exit(&trans); bch2_trans_exit(&trans);
bkey_on_stack_exit(&sk, c); bch2_bkey_buf_exit(&sk, c);
return ret; return ret;
} }
......
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#include "bcachefs.h" #include "bcachefs.h"
#include "bkey_on_stack.h"
#include "btree_update.h" #include "btree_update.h"
#include "btree_update_interior.h" #include "btree_update_interior.h"
#include "buckets.h" #include "buckets.h"
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include "bcachefs.h" #include "bcachefs.h"
#include "alloc_foreground.h" #include "alloc_foreground.h"
#include "bkey_on_stack.h" #include "bkey_buf.h"
#include "btree_update.h" #include "btree_update.h"
#include "buckets.h" #include "buckets.h"
#include "clock.h" #include "clock.h"
...@@ -774,7 +774,7 @@ static void bchfs_read(struct btree_trans *trans, struct btree_iter *iter, ...@@ -774,7 +774,7 @@ static void bchfs_read(struct btree_trans *trans, struct btree_iter *iter,
struct readpages_iter *readpages_iter) struct readpages_iter *readpages_iter)
{ {
struct bch_fs *c = trans->c; struct bch_fs *c = trans->c;
struct bkey_on_stack sk; struct bkey_buf sk;
int flags = BCH_READ_RETRY_IF_STALE| int flags = BCH_READ_RETRY_IF_STALE|
BCH_READ_MAY_PROMOTE; BCH_READ_MAY_PROMOTE;
int ret = 0; int ret = 0;
...@@ -782,7 +782,7 @@ static void bchfs_read(struct btree_trans *trans, struct btree_iter *iter, ...@@ -782,7 +782,7 @@ static void bchfs_read(struct btree_trans *trans, struct btree_iter *iter,
rbio->c = c; rbio->c = c;
rbio->start_time = local_clock(); rbio->start_time = local_clock();
bkey_on_stack_init(&sk); bch2_bkey_buf_init(&sk);
retry: retry:
while (1) { while (1) {
struct bkey_s_c k; struct bkey_s_c k;
...@@ -800,7 +800,7 @@ static void bchfs_read(struct btree_trans *trans, struct btree_iter *iter, ...@@ -800,7 +800,7 @@ static void bchfs_read(struct btree_trans *trans, struct btree_iter *iter,
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_reassemble(&sk, c, k); bch2_bkey_buf_reassemble(&sk, c, k);
ret = bch2_read_indirect_extent(trans, ret = bch2_read_indirect_extent(trans,
&offset_into_extent, &sk); &offset_into_extent, &sk);
...@@ -845,7 +845,7 @@ static void bchfs_read(struct btree_trans *trans, struct btree_iter *iter, ...@@ -845,7 +845,7 @@ static void bchfs_read(struct btree_trans *trans, struct btree_iter *iter,
bio_endio(&rbio->bio); bio_endio(&rbio->bio);
} }
bkey_on_stack_exit(&sk, c); bch2_bkey_buf_exit(&sk, c);
} }
void bch2_readahead(struct readahead_control *ractl) void bch2_readahead(struct readahead_control *ractl)
...@@ -2431,7 +2431,7 @@ static long bchfs_fcollapse_finsert(struct bch_inode_info *inode, ...@@ -2431,7 +2431,7 @@ static long bchfs_fcollapse_finsert(struct bch_inode_info *inode,
{ {
struct bch_fs *c = inode->v.i_sb->s_fs_info; struct bch_fs *c = inode->v.i_sb->s_fs_info;
struct address_space *mapping = inode->v.i_mapping; struct address_space *mapping = inode->v.i_mapping;
struct bkey_on_stack copy; struct bkey_buf copy;
struct btree_trans trans; struct btree_trans trans;
struct btree_iter *src, *dst; struct btree_iter *src, *dst;
loff_t shift, new_size; loff_t shift, new_size;
...@@ -2441,7 +2441,7 @@ static long bchfs_fcollapse_finsert(struct bch_inode_info *inode, ...@@ -2441,7 +2441,7 @@ static long bchfs_fcollapse_finsert(struct bch_inode_info *inode,
if ((offset | len) & (block_bytes(c) - 1)) if ((offset | len) & (block_bytes(c) - 1))
return -EINVAL; return -EINVAL;
bkey_on_stack_init(&copy); bch2_bkey_buf_init(&copy);
bch2_trans_init(&trans, c, BTREE_ITER_MAX, 256); bch2_trans_init(&trans, c, BTREE_ITER_MAX, 256);
/* /*
...@@ -2529,7 +2529,7 @@ static long bchfs_fcollapse_finsert(struct bch_inode_info *inode, ...@@ -2529,7 +2529,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_reassemble(&copy, c, k); bch2_bkey_buf_reassemble(&copy, c, 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)
...@@ -2606,7 +2606,7 @@ static long bchfs_fcollapse_finsert(struct bch_inode_info *inode, ...@@ -2606,7 +2606,7 @@ static long bchfs_fcollapse_finsert(struct bch_inode_info *inode,
} }
err: err:
bch2_trans_exit(&trans); bch2_trans_exit(&trans);
bkey_on_stack_exit(&copy, c); bch2_bkey_buf_exit(&copy, c);
bch2_pagecache_block_put(&inode->ei_pagecache_lock); bch2_pagecache_block_put(&inode->ei_pagecache_lock);
inode_unlock(&inode->v); inode_unlock(&inode->v);
return ret; return ret;
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include "bcachefs.h" #include "bcachefs.h"
#include "acl.h" #include "acl.h"
#include "bkey_on_stack.h" #include "bkey_buf.h"
#include "btree_update.h" #include "btree_update.h"
#include "buckets.h" #include "buckets.h"
#include "chardev.h" #include "chardev.h"
...@@ -899,7 +899,7 @@ static int bch2_fiemap(struct inode *vinode, struct fiemap_extent_info *info, ...@@ -899,7 +899,7 @@ static int bch2_fiemap(struct inode *vinode, struct fiemap_extent_info *info,
struct btree_trans trans; struct btree_trans trans;
struct btree_iter *iter; struct btree_iter *iter;
struct bkey_s_c k; struct bkey_s_c k;
struct bkey_on_stack cur, prev; struct bkey_buf cur, prev;
struct bpos end = POS(ei->v.i_ino, (start + len) >> 9); struct bpos end = POS(ei->v.i_ino, (start + len) >> 9);
unsigned offset_into_extent, sectors; unsigned offset_into_extent, sectors;
bool have_extent = false; bool have_extent = false;
...@@ -912,8 +912,8 @@ static int bch2_fiemap(struct inode *vinode, struct fiemap_extent_info *info, ...@@ -912,8 +912,8 @@ static int bch2_fiemap(struct inode *vinode, struct fiemap_extent_info *info,
if (start + len < start) if (start + len < start)
return -EINVAL; return -EINVAL;
bkey_on_stack_init(&cur); bch2_bkey_buf_init(&cur);
bkey_on_stack_init(&prev); bch2_bkey_buf_init(&prev);
bch2_trans_init(&trans, c, 0, 0); bch2_trans_init(&trans, c, 0, 0);
iter = bch2_trans_get_iter(&trans, BTREE_ID_EXTENTS, iter = bch2_trans_get_iter(&trans, BTREE_ID_EXTENTS,
...@@ -932,7 +932,7 @@ static int bch2_fiemap(struct inode *vinode, struct fiemap_extent_info *info, ...@@ -932,7 +932,7 @@ static int bch2_fiemap(struct inode *vinode, struct fiemap_extent_info *info,
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_reassemble(&cur, c, k); bch2_bkey_buf_reassemble(&cur, c, k);
ret = bch2_read_indirect_extent(&trans, ret = bch2_read_indirect_extent(&trans,
&offset_into_extent, &cur); &offset_into_extent, &cur);
...@@ -940,7 +940,7 @@ static int bch2_fiemap(struct inode *vinode, struct fiemap_extent_info *info, ...@@ -940,7 +940,7 @@ static int bch2_fiemap(struct inode *vinode, struct fiemap_extent_info *info,
break; break;
k = bkey_i_to_s_c(cur.k); k = bkey_i_to_s_c(cur.k);
bkey_on_stack_realloc(&prev, c, k.k->u64s); bch2_bkey_buf_realloc(&prev, c, k.k->u64s);
sectors = min(sectors, k.k->size - offset_into_extent); sectors = min(sectors, k.k->size - offset_into_extent);
...@@ -974,8 +974,8 @@ static int bch2_fiemap(struct inode *vinode, struct fiemap_extent_info *info, ...@@ -974,8 +974,8 @@ static int bch2_fiemap(struct inode *vinode, struct fiemap_extent_info *info,
FIEMAP_EXTENT_LAST); FIEMAP_EXTENT_LAST);
ret = bch2_trans_exit(&trans) ?: ret; ret = bch2_trans_exit(&trans) ?: ret;
bkey_on_stack_exit(&cur, c); bch2_bkey_buf_exit(&cur, c);
bkey_on_stack_exit(&prev, c); bch2_bkey_buf_exit(&prev, c);
return ret < 0 ? ret : 0; return ret < 0 ? ret : 0;
} }
......
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#include "bcachefs.h" #include "bcachefs.h"
#include "bkey_on_stack.h" #include "bkey_buf.h"
#include "btree_update.h" #include "btree_update.h"
#include "dirent.h" #include "dirent.h"
#include "error.h" #include "error.h"
...@@ -464,11 +464,11 @@ static int check_extents(struct bch_fs *c) ...@@ -464,11 +464,11 @@ static int check_extents(struct bch_fs *c)
struct btree_trans trans; struct btree_trans trans;
struct btree_iter *iter; struct btree_iter *iter;
struct bkey_s_c k; struct bkey_s_c k;
struct bkey_on_stack prev; struct bkey_buf prev;
u64 i_sectors; u64 i_sectors;
int ret = 0; int ret = 0;
bkey_on_stack_init(&prev); bch2_bkey_buf_init(&prev);
prev.k->k = KEY(0, 0, 0); prev.k->k = KEY(0, 0, 0);
bch2_trans_init(&trans, c, BTREE_ITER_MAX, 0); bch2_trans_init(&trans, c, BTREE_ITER_MAX, 0);
...@@ -500,7 +500,7 @@ static int check_extents(struct bch_fs *c) ...@@ -500,7 +500,7 @@ static int check_extents(struct bch_fs *c)
goto err; goto err;
} }
} }
bkey_on_stack_reassemble(&prev, c, k); bch2_bkey_buf_reassemble(&prev, c, k);
ret = walk_inode(&trans, &w, k.k->p.inode); ret = walk_inode(&trans, &w, k.k->p.inode);
if (ret) if (ret)
...@@ -569,7 +569,7 @@ static int check_extents(struct bch_fs *c) ...@@ -569,7 +569,7 @@ static int check_extents(struct bch_fs *c)
fsck_err: fsck_err:
if (ret == -EINTR) if (ret == -EINTR)
goto retry; goto retry;
bkey_on_stack_exit(&prev, c); bch2_bkey_buf_exit(&prev, c);
return bch2_trans_exit(&trans) ?: ret; return bch2_trans_exit(&trans) ?: ret;
} }
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "bcachefs.h" #include "bcachefs.h"
#include "alloc_background.h" #include "alloc_background.h"
#include "alloc_foreground.h" #include "alloc_foreground.h"
#include "bkey_on_stack.h" #include "bkey_buf.h"
#include "bset.h" #include "bset.h"
#include "btree_update.h" #include "btree_update.h"
#include "buckets.h" #include "buckets.h"
...@@ -425,14 +425,14 @@ int bch2_fpunch(struct bch_fs *c, u64 inum, u64 start, u64 end, ...@@ -425,14 +425,14 @@ int bch2_fpunch(struct bch_fs *c, u64 inum, u64 start, u64 end,
int bch2_write_index_default(struct bch_write_op *op) int bch2_write_index_default(struct bch_write_op *op)
{ {
struct bch_fs *c = op->c; struct bch_fs *c = op->c;
struct bkey_on_stack sk; struct bkey_buf sk;
struct keylist *keys = &op->insert_keys; struct keylist *keys = &op->insert_keys;
struct bkey_i *k = bch2_keylist_front(keys); struct bkey_i *k = bch2_keylist_front(keys);
struct btree_trans trans; struct btree_trans trans;
struct btree_iter *iter; struct btree_iter *iter;
int ret; int ret;
bkey_on_stack_init(&sk); bch2_bkey_buf_init(&sk);
bch2_trans_init(&trans, c, BTREE_ITER_MAX, 1024); bch2_trans_init(&trans, c, BTREE_ITER_MAX, 1024);
iter = bch2_trans_get_iter(&trans, BTREE_ID_EXTENTS, iter = bch2_trans_get_iter(&trans, BTREE_ID_EXTENTS,
...@@ -444,7 +444,7 @@ int bch2_write_index_default(struct bch_write_op *op) ...@@ -444,7 +444,7 @@ int bch2_write_index_default(struct bch_write_op *op)
k = bch2_keylist_front(keys); k = bch2_keylist_front(keys);
bkey_on_stack_realloc(&sk, c, k->k.u64s); bch2_bkey_buf_realloc(&sk, c, k->k.u64s);
bkey_copy(sk.k, k); bkey_copy(sk.k, k);
bch2_cut_front(iter->pos, sk.k); bch2_cut_front(iter->pos, sk.k);
...@@ -461,7 +461,7 @@ int bch2_write_index_default(struct bch_write_op *op) ...@@ -461,7 +461,7 @@ int bch2_write_index_default(struct bch_write_op *op)
} while (!bch2_keylist_empty(keys)); } while (!bch2_keylist_empty(keys));
bch2_trans_exit(&trans); bch2_trans_exit(&trans);
bkey_on_stack_exit(&sk, c); bch2_bkey_buf_exit(&sk, c);
return ret; return ret;
} }
...@@ -1620,14 +1620,14 @@ static void bch2_read_retry_nodecode(struct bch_fs *c, struct bch_read_bio *rbio ...@@ -1620,14 +1620,14 @@ static void bch2_read_retry_nodecode(struct bch_fs *c, struct bch_read_bio *rbio
{ {
struct btree_trans trans; struct btree_trans trans;
struct btree_iter *iter; struct btree_iter *iter;
struct bkey_on_stack sk; struct bkey_buf sk;
struct bkey_s_c k; struct bkey_s_c k;
int ret; int ret;
flags &= ~BCH_READ_LAST_FRAGMENT; flags &= ~BCH_READ_LAST_FRAGMENT;
flags |= BCH_READ_MUST_CLONE; flags |= BCH_READ_MUST_CLONE;
bkey_on_stack_init(&sk); bch2_bkey_buf_init(&sk);
bch2_trans_init(&trans, c, 0, 0); bch2_trans_init(&trans, c, 0, 0);
iter = bch2_trans_get_iter(&trans, BTREE_ID_EXTENTS, iter = bch2_trans_get_iter(&trans, BTREE_ID_EXTENTS,
...@@ -1639,7 +1639,7 @@ static void bch2_read_retry_nodecode(struct bch_fs *c, struct bch_read_bio *rbio ...@@ -1639,7 +1639,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_reassemble(&sk, c, k); bch2_bkey_buf_reassemble(&sk, c, 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);
...@@ -1660,7 +1660,7 @@ static void bch2_read_retry_nodecode(struct bch_fs *c, struct bch_read_bio *rbio ...@@ -1660,7 +1660,7 @@ static void bch2_read_retry_nodecode(struct bch_fs *c, struct bch_read_bio *rbio
out: out:
bch2_rbio_done(rbio); bch2_rbio_done(rbio);
bch2_trans_exit(&trans); bch2_trans_exit(&trans);
bkey_on_stack_exit(&sk, c); bch2_bkey_buf_exit(&sk, c);
return; return;
err: err:
rbio->bio.bi_status = BLK_STS_IOERR; rbio->bio.bi_status = BLK_STS_IOERR;
...@@ -1673,14 +1673,14 @@ static void bch2_read_retry(struct bch_fs *c, struct bch_read_bio *rbio, ...@@ -1673,14 +1673,14 @@ static void bch2_read_retry(struct bch_fs *c, struct bch_read_bio *rbio,
{ {
struct btree_trans trans; struct btree_trans trans;
struct btree_iter *iter; struct btree_iter *iter;
struct bkey_on_stack sk; struct bkey_buf sk;
struct bkey_s_c k; struct bkey_s_c k;
int ret; int ret;
flags &= ~BCH_READ_LAST_FRAGMENT; flags &= ~BCH_READ_LAST_FRAGMENT;
flags |= BCH_READ_MUST_CLONE; flags |= BCH_READ_MUST_CLONE;
bkey_on_stack_init(&sk); bch2_bkey_buf_init(&sk);
bch2_trans_init(&trans, c, 0, 0); bch2_trans_init(&trans, c, 0, 0);
retry: retry:
bch2_trans_begin(&trans); bch2_trans_begin(&trans);
...@@ -1690,7 +1690,7 @@ static void bch2_read_retry(struct bch_fs *c, struct bch_read_bio *rbio, ...@@ -1690,7 +1690,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_reassemble(&sk, c, k); bch2_bkey_buf_reassemble(&sk, c, k);
offset_into_extent = iter->pos.offset - offset_into_extent = iter->pos.offset -
bkey_start_offset(k.k); bkey_start_offset(k.k);
...@@ -1739,7 +1739,7 @@ static void bch2_read_retry(struct bch_fs *c, struct bch_read_bio *rbio, ...@@ -1739,7 +1739,7 @@ static void bch2_read_retry(struct bch_fs *c, struct bch_read_bio *rbio,
rbio->bio.bi_status = BLK_STS_IOERR; rbio->bio.bi_status = BLK_STS_IOERR;
out: out:
bch2_trans_exit(&trans); bch2_trans_exit(&trans);
bkey_on_stack_exit(&sk, c); bch2_bkey_buf_exit(&sk, c);
bch2_rbio_done(rbio); bch2_rbio_done(rbio);
} }
...@@ -1810,17 +1810,6 @@ static int __bch2_rbio_narrow_crcs(struct btree_trans *trans, ...@@ -1810,17 +1810,6 @@ static int __bch2_rbio_narrow_crcs(struct btree_trans *trans,
if ((ret = bkey_err(k))) if ((ret = bkey_err(k)))
goto out; goto out;
/*
* going to be temporarily appending another checksum entry:
*/
new = bch2_trans_kmalloc(trans, bkey_bytes(k.k) +
BKEY_EXTENT_U64s_MAX * 8);
if ((ret = PTR_ERR_OR_ZERO(new)))
goto out;
bkey_reassemble(new, k);
k = bkey_i_to_s_c(new);
if (bversion_cmp(k.k->version, rbio->version) || if (bversion_cmp(k.k->version, rbio->version) ||
!bch2_bkey_matches_ptr(c, k, rbio->pick.ptr, data_offset)) !bch2_bkey_matches_ptr(c, k, rbio->pick.ptr, data_offset))
goto out; goto out;
...@@ -1839,6 +1828,16 @@ static int __bch2_rbio_narrow_crcs(struct btree_trans *trans, ...@@ -1839,6 +1828,16 @@ static int __bch2_rbio_narrow_crcs(struct btree_trans *trans,
goto out; goto out;
} }
/*
* going to be temporarily appending another checksum entry:
*/
new = bch2_trans_kmalloc(trans, bkey_bytes(k.k) +
sizeof(struct bch_extent_crc128));
if ((ret = PTR_ERR_OR_ZERO(new)))
goto out;
bkey_reassemble(new, k);
if (!bch2_bkey_narrow_crcs(new, new_crc)) if (!bch2_bkey_narrow_crcs(new, new_crc))
goto out; goto out;
...@@ -2005,7 +2004,7 @@ static void bch2_read_endio(struct bio *bio) ...@@ -2005,7 +2004,7 @@ static void bch2_read_endio(struct bio *bio)
int __bch2_read_indirect_extent(struct btree_trans *trans, int __bch2_read_indirect_extent(struct btree_trans *trans,
unsigned *offset_into_extent, unsigned *offset_into_extent,
struct bkey_on_stack *orig_k) struct bkey_buf *orig_k)
{ {
struct btree_iter *iter; struct btree_iter *iter;
struct bkey_s_c k; struct bkey_s_c k;
...@@ -2032,7 +2031,7 @@ int __bch2_read_indirect_extent(struct btree_trans *trans, ...@@ -2032,7 +2031,7 @@ int __bch2_read_indirect_extent(struct btree_trans *trans,
} }
*offset_into_extent = iter->pos.offset - bkey_start_offset(k.k); *offset_into_extent = iter->pos.offset - bkey_start_offset(k.k);
bkey_on_stack_reassemble(orig_k, trans->c, k); bch2_bkey_buf_reassemble(orig_k, trans->c, k);
err: err:
bch2_trans_iter_put(trans, iter); bch2_trans_iter_put(trans, iter);
return ret; return ret;
...@@ -2304,7 +2303,7 @@ void bch2_read(struct bch_fs *c, struct bch_read_bio *rbio, u64 inode) ...@@ -2304,7 +2303,7 @@ void bch2_read(struct bch_fs *c, struct bch_read_bio *rbio, u64 inode)
{ {
struct btree_trans trans; struct btree_trans trans;
struct btree_iter *iter; struct btree_iter *iter;
struct bkey_on_stack sk; struct bkey_buf sk;
struct bkey_s_c k; struct bkey_s_c k;
unsigned flags = BCH_READ_RETRY_IF_STALE| unsigned flags = BCH_READ_RETRY_IF_STALE|
BCH_READ_MAY_PROMOTE| BCH_READ_MAY_PROMOTE|
...@@ -2318,7 +2317,7 @@ void bch2_read(struct bch_fs *c, struct bch_read_bio *rbio, u64 inode) ...@@ -2318,7 +2317,7 @@ void bch2_read(struct bch_fs *c, struct bch_read_bio *rbio, u64 inode)
rbio->c = c; rbio->c = c;
rbio->start_time = local_clock(); rbio->start_time = local_clock();
bkey_on_stack_init(&sk); bch2_bkey_buf_init(&sk);
bch2_trans_init(&trans, c, 0, 0); bch2_trans_init(&trans, c, 0, 0);
retry: retry:
bch2_trans_begin(&trans); bch2_trans_begin(&trans);
...@@ -2341,7 +2340,7 @@ void bch2_read(struct bch_fs *c, struct bch_read_bio *rbio, u64 inode) ...@@ -2341,7 +2340,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_reassemble(&sk, c, k); bch2_bkey_buf_reassemble(&sk, c, k);
ret = bch2_read_indirect_extent(&trans, ret = bch2_read_indirect_extent(&trans,
&offset_into_extent, &sk); &offset_into_extent, &sk);
...@@ -2378,7 +2377,7 @@ void bch2_read(struct bch_fs *c, struct bch_read_bio *rbio, u64 inode) ...@@ -2378,7 +2377,7 @@ void bch2_read(struct bch_fs *c, struct bch_read_bio *rbio, u64 inode)
} }
out: out:
bch2_trans_exit(&trans); bch2_trans_exit(&trans);
bkey_on_stack_exit(&sk, c); bch2_bkey_buf_exit(&sk, c);
return; return;
err: err:
if (ret == -EINTR) if (ret == -EINTR)
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#define _BCACHEFS_IO_H #define _BCACHEFS_IO_H
#include "checksum.h" #include "checksum.h"
#include "bkey_on_stack.h" #include "bkey_buf.h"
#include "io_types.h" #include "io_types.h"
#define to_wbio(_bio) \ #define to_wbio(_bio) \
...@@ -118,11 +118,11 @@ struct cache_promote_op; ...@@ -118,11 +118,11 @@ struct cache_promote_op;
struct extent_ptr_decoded; struct extent_ptr_decoded;
int __bch2_read_indirect_extent(struct btree_trans *, unsigned *, int __bch2_read_indirect_extent(struct btree_trans *, unsigned *,
struct bkey_on_stack *); struct bkey_buf *);
static inline int bch2_read_indirect_extent(struct btree_trans *trans, static inline int bch2_read_indirect_extent(struct btree_trans *trans,
unsigned *offset_into_extent, unsigned *offset_into_extent,
struct bkey_on_stack *k) struct bkey_buf *k)
{ {
return k->k->k.type == KEY_TYPE_reflink_p return k->k->k.type == KEY_TYPE_reflink_p
? __bch2_read_indirect_extent(trans, offset_into_extent, k) ? __bch2_read_indirect_extent(trans, offset_into_extent, k)
......
...@@ -1097,7 +1097,7 @@ int bch2_fs_journal_init(struct journal *j) ...@@ -1097,7 +1097,7 @@ int bch2_fs_journal_init(struct journal *j)
/* Btree roots: */ /* Btree roots: */
j->entry_u64s_reserved += j->entry_u64s_reserved +=
BTREE_ID_NR * (JSET_KEYS_U64s + BKEY_EXTENT_U64s_MAX); BTREE_ID_NR * (JSET_KEYS_U64s + BKEY_BTREE_PTR_U64s_MAX);
atomic64_set(&j->reservations.counter, atomic64_set(&j->reservations.counter,
((union journal_res_state) ((union journal_res_state)
......
...@@ -989,6 +989,8 @@ static int journal_write_alloc(struct journal *j, struct journal_buf *w, ...@@ -989,6 +989,8 @@ static int journal_write_alloc(struct journal *j, struct journal_buf *w,
done: done:
rcu_read_unlock(); rcu_read_unlock();
BUG_ON(bkey_val_u64s(&w->key.k) > BCH_REPLICAS_MAX);
return replicas >= c->opts.metadata_replicas_required ? 0 : -EROFS; return replicas >= c->opts.metadata_replicas_required ? 0 : -EROFS;
} }
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
struct journal_buf { struct journal_buf {
struct jset *data; struct jset *data;
BKEY_PADDED(key); __BKEY_PADDED(key, BCH_REPLICAS_MAX);
struct closure_waitlist wait; struct closure_waitlist wait;
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
*/ */
#include "bcachefs.h" #include "bcachefs.h"
#include "bkey_on_stack.h" #include "bkey_buf.h"
#include "btree_update.h" #include "btree_update.h"
#include "btree_update_interior.h" #include "btree_update_interior.h"
#include "buckets.h" #include "buckets.h"
...@@ -41,10 +41,10 @@ static int __bch2_dev_usrdata_drop(struct bch_fs *c, unsigned dev_idx, int flags ...@@ -41,10 +41,10 @@ static int __bch2_dev_usrdata_drop(struct bch_fs *c, unsigned dev_idx, int flags
struct btree_trans trans; struct btree_trans trans;
struct btree_iter *iter; struct btree_iter *iter;
struct bkey_s_c k; struct bkey_s_c k;
struct bkey_on_stack sk; struct bkey_buf sk;
int ret = 0; int ret = 0;
bkey_on_stack_init(&sk); bch2_bkey_buf_init(&sk);
bch2_trans_init(&trans, c, BTREE_ITER_MAX, 0); bch2_trans_init(&trans, c, BTREE_ITER_MAX, 0);
iter = bch2_trans_get_iter(&trans, btree_id, POS_MIN, iter = bch2_trans_get_iter(&trans, btree_id, POS_MIN,
...@@ -57,7 +57,7 @@ static int __bch2_dev_usrdata_drop(struct bch_fs *c, unsigned dev_idx, int flags ...@@ -57,7 +57,7 @@ static int __bch2_dev_usrdata_drop(struct bch_fs *c, unsigned dev_idx, int flags
continue; continue;
} }
bkey_on_stack_reassemble(&sk, c, k); bch2_bkey_buf_reassemble(&sk, c, 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);
...@@ -90,7 +90,7 @@ static int __bch2_dev_usrdata_drop(struct bch_fs *c, unsigned dev_idx, int flags ...@@ -90,7 +90,7 @@ static int __bch2_dev_usrdata_drop(struct bch_fs *c, unsigned dev_idx, int flags
} }
ret = bch2_trans_exit(&trans) ?: ret; ret = bch2_trans_exit(&trans) ?: ret;
bkey_on_stack_exit(&sk, c); bch2_bkey_buf_exit(&sk, c);
BUG_ON(ret == -EINTR); BUG_ON(ret == -EINTR);
...@@ -109,6 +109,7 @@ static int bch2_dev_metadata_drop(struct bch_fs *c, unsigned dev_idx, int flags) ...@@ -109,6 +109,7 @@ static int bch2_dev_metadata_drop(struct bch_fs *c, unsigned dev_idx, int flags)
struct btree_iter *iter; struct btree_iter *iter;
struct closure cl; struct closure cl;
struct btree *b; struct btree *b;
struct bkey_buf k;
unsigned id; unsigned id;
int ret; int ret;
...@@ -116,28 +117,28 @@ static int bch2_dev_metadata_drop(struct bch_fs *c, unsigned dev_idx, int flags) ...@@ -116,28 +117,28 @@ static int bch2_dev_metadata_drop(struct bch_fs *c, unsigned dev_idx, int flags)
if (flags & BCH_FORCE_IF_METADATA_LOST) if (flags & BCH_FORCE_IF_METADATA_LOST)
return -EINVAL; return -EINVAL;
bch2_bkey_buf_init(&k);
bch2_trans_init(&trans, c, 0, 0); bch2_trans_init(&trans, c, 0, 0);
closure_init_stack(&cl); closure_init_stack(&cl);
for (id = 0; id < BTREE_ID_NR; id++) { for (id = 0; id < BTREE_ID_NR; id++) {
for_each_btree_node(&trans, iter, id, POS_MIN, for_each_btree_node(&trans, iter, id, POS_MIN,
BTREE_ITER_PREFETCH, b) { BTREE_ITER_PREFETCH, b) {
__BKEY_PADDED(k, BKEY_BTREE_PTR_VAL_U64s_MAX) tmp;
retry: retry:
if (!bch2_bkey_has_device(bkey_i_to_s_c(&b->key), if (!bch2_bkey_has_device(bkey_i_to_s_c(&b->key),
dev_idx)) dev_idx))
continue; continue;
bkey_copy(&tmp.k, &b->key); bch2_bkey_buf_copy(&k, c, &b->key);
ret = drop_dev_ptrs(c, bkey_i_to_s(&tmp.k), ret = drop_dev_ptrs(c, bkey_i_to_s(k.k),
dev_idx, flags, true); dev_idx, flags, true);
if (ret) { if (ret) {
bch_err(c, "Cannot drop device without losing data"); bch_err(c, "Cannot drop device without losing data");
goto err; goto err;
} }
ret = bch2_btree_node_update_key(c, iter, b, &tmp.k); ret = bch2_btree_node_update_key(c, iter, b, k.k);
if (ret == -EINTR) { if (ret == -EINTR) {
b = bch2_btree_iter_peek_node(iter); b = bch2_btree_iter_peek_node(iter);
goto retry; goto retry;
...@@ -157,6 +158,7 @@ static int bch2_dev_metadata_drop(struct bch_fs *c, unsigned dev_idx, int flags) ...@@ -157,6 +158,7 @@ static int bch2_dev_metadata_drop(struct bch_fs *c, unsigned dev_idx, int flags)
ret = 0; ret = 0;
err: err:
ret = bch2_trans_exit(&trans) ?: ret; ret = bch2_trans_exit(&trans) ?: ret;
bch2_bkey_buf_exit(&k, c);
BUG_ON(ret == -EINTR); BUG_ON(ret == -EINTR);
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include "bcachefs.h" #include "bcachefs.h"
#include "alloc_foreground.h" #include "alloc_foreground.h"
#include "bkey_on_stack.h" #include "bkey_buf.h"
#include "btree_gc.h" #include "btree_gc.h"
#include "btree_update.h" #include "btree_update.h"
#include "btree_update_interior.h" #include "btree_update_interior.h"
...@@ -60,8 +60,13 @@ static int bch2_migrate_index_update(struct bch_write_op *op) ...@@ -60,8 +60,13 @@ static int bch2_migrate_index_update(struct bch_write_op *op)
struct migrate_write *m = struct migrate_write *m =
container_of(op, struct migrate_write, op); container_of(op, struct migrate_write, op);
struct keylist *keys = &op->insert_keys; struct keylist *keys = &op->insert_keys;
struct bkey_buf _new, _insert;
int ret = 0; int ret = 0;
bch2_bkey_buf_init(&_new);
bch2_bkey_buf_init(&_insert);
bch2_bkey_buf_realloc(&_insert, c, U8_MAX);
bch2_trans_init(&trans, c, BTREE_ITER_MAX, 0); bch2_trans_init(&trans, c, BTREE_ITER_MAX, 0);
iter = bch2_trans_get_iter(&trans, m->btree_id, iter = bch2_trans_get_iter(&trans, m->btree_id,
...@@ -72,7 +77,6 @@ static int bch2_migrate_index_update(struct bch_write_op *op) ...@@ -72,7 +77,6 @@ static int bch2_migrate_index_update(struct bch_write_op *op)
struct bkey_s_c k; struct bkey_s_c k;
struct bkey_i *insert; struct bkey_i *insert;
struct bkey_i_extent *new; struct bkey_i_extent *new;
BKEY_PADDED(k) _new, _insert;
const union bch_extent_entry *entry; const union bch_extent_entry *entry;
struct extent_ptr_decoded p; struct extent_ptr_decoded p;
bool did_work = false; bool did_work = false;
...@@ -92,11 +96,11 @@ static int bch2_migrate_index_update(struct bch_write_op *op) ...@@ -92,11 +96,11 @@ static int bch2_migrate_index_update(struct bch_write_op *op)
!bch2_bkey_matches_ptr(c, k, m->ptr, m->offset)) !bch2_bkey_matches_ptr(c, k, m->ptr, m->offset))
goto nomatch; goto nomatch;
bkey_reassemble(&_insert.k, k); bkey_reassemble(_insert.k, k);
insert = &_insert.k; insert = _insert.k;
bkey_copy(&_new.k, bch2_keylist_front(keys)); bch2_bkey_buf_copy(&_new, c, bch2_keylist_front(keys));
new = bkey_i_to_extent(&_new.k); new = bkey_i_to_extent(_new.k);
bch2_cut_front(iter->pos, &new->k_i); bch2_cut_front(iter->pos, &new->k_i);
bch2_cut_front(iter->pos, insert); bch2_cut_front(iter->pos, insert);
...@@ -192,6 +196,8 @@ static int bch2_migrate_index_update(struct bch_write_op *op) ...@@ -192,6 +196,8 @@ static int bch2_migrate_index_update(struct bch_write_op *op)
} }
out: out:
bch2_trans_exit(&trans); bch2_trans_exit(&trans);
bch2_bkey_buf_exit(&_insert, c);
bch2_bkey_buf_exit(&_new, c);
BUG_ON(ret == -EINTR); BUG_ON(ret == -EINTR);
return ret; return ret;
} }
...@@ -511,7 +517,7 @@ static int __bch2_move_data(struct bch_fs *c, ...@@ -511,7 +517,7 @@ static int __bch2_move_data(struct bch_fs *c,
{ {
bool kthread = (current->flags & PF_KTHREAD) != 0; bool kthread = (current->flags & PF_KTHREAD) != 0;
struct bch_io_opts io_opts = bch2_opts_to_inode_opts(c->opts); struct bch_io_opts io_opts = bch2_opts_to_inode_opts(c->opts);
struct bkey_on_stack sk; struct bkey_buf sk;
struct btree_trans trans; struct btree_trans trans;
struct btree_iter *iter; struct btree_iter *iter;
struct bkey_s_c k; struct bkey_s_c k;
...@@ -520,7 +526,7 @@ static int __bch2_move_data(struct bch_fs *c, ...@@ -520,7 +526,7 @@ static int __bch2_move_data(struct bch_fs *c,
u64 delay, cur_inum = U64_MAX; u64 delay, cur_inum = U64_MAX;
int ret = 0, ret2; int ret = 0, ret2;
bkey_on_stack_init(&sk); bch2_bkey_buf_init(&sk);
bch2_trans_init(&trans, c, 0, 0); bch2_trans_init(&trans, c, 0, 0);
stats->data_type = BCH_DATA_user; stats->data_type = BCH_DATA_user;
...@@ -600,7 +606,7 @@ static int __bch2_move_data(struct bch_fs *c, ...@@ -600,7 +606,7 @@ static int __bch2_move_data(struct bch_fs *c,
} }
/* unlock before doing IO: */ /* unlock before doing IO: */
bkey_on_stack_reassemble(&sk, c, k); bch2_bkey_buf_reassemble(&sk, c, 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);
...@@ -634,7 +640,7 @@ static int __bch2_move_data(struct bch_fs *c, ...@@ -634,7 +640,7 @@ static int __bch2_move_data(struct bch_fs *c,
} }
out: out:
ret = bch2_trans_exit(&trans) ?: ret; ret = bch2_trans_exit(&trans) ?: ret;
bkey_on_stack_exit(&sk, c); bch2_bkey_buf_exit(&sk, c);
return ret; return ret;
} }
......
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#include "bcachefs.h" #include "bcachefs.h"
#include "bkey_buf.h"
#include "alloc_background.h" #include "alloc_background.h"
#include "btree_gc.h" #include "btree_gc.h"
#include "btree_update.h" #include "btree_update.h"
...@@ -224,28 +225,29 @@ static int bch2_btree_and_journal_walk_recurse(struct bch_fs *c, struct btree *b ...@@ -224,28 +225,29 @@ static int bch2_btree_and_journal_walk_recurse(struct bch_fs *c, struct btree *b
if (b->c.level) { if (b->c.level) {
struct btree *child; struct btree *child;
BKEY_PADDED(k) tmp; struct bkey_buf tmp;
bkey_reassemble(&tmp.k, k); bch2_bkey_buf_init(&tmp);
k = bkey_i_to_s_c(&tmp.k); bch2_bkey_buf_reassemble(&tmp, c, k);
k = bkey_i_to_s_c(tmp.k);
bch2_btree_and_journal_iter_advance(&iter); bch2_btree_and_journal_iter_advance(&iter);
if (b->c.level > 0) { child = bch2_btree_node_get_noiter(c, tmp.k,
child = bch2_btree_node_get_noiter(c, &tmp.k, b->c.btree_id, b->c.level - 1);
b->c.btree_id, b->c.level - 1); bch2_bkey_buf_exit(&tmp, c);
ret = PTR_ERR_OR_ZERO(child);
if (ret)
break;
ret = (node_fn ? node_fn(c, b) : 0) ?: ret = PTR_ERR_OR_ZERO(child);
bch2_btree_and_journal_walk_recurse(c, child, if (ret)
journal_keys, btree_id, node_fn, key_fn); break;
six_unlock_read(&child->c.lock);
if (ret) ret = (node_fn ? node_fn(c, b) : 0) ?:
break; bch2_btree_and_journal_walk_recurse(c, child,
} journal_keys, btree_id, node_fn, key_fn);
six_unlock_read(&child->c.lock);
if (ret)
break;
} else { } else {
bch2_btree_and_journal_iter_advance(&iter); bch2_btree_and_journal_iter_advance(&iter);
} }
......
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#include "bcachefs.h" #include "bcachefs.h"
#include "bkey_on_stack.h" #include "bkey_buf.h"
#include "btree_update.h" #include "btree_update.h"
#include "extents.h" #include "extents.h"
#include "inode.h" #include "inode.h"
...@@ -198,8 +198,7 @@ s64 bch2_remap_range(struct bch_fs *c, ...@@ -198,8 +198,7 @@ s64 bch2_remap_range(struct bch_fs *c,
struct btree_trans trans; struct btree_trans trans;
struct btree_iter *dst_iter, *src_iter; struct btree_iter *dst_iter, *src_iter;
struct bkey_s_c src_k; struct bkey_s_c src_k;
BKEY_PADDED(k) new_dst; struct bkey_buf new_dst, new_src;
struct bkey_on_stack new_src;
struct bpos dst_end = dst_start, src_end = src_start; struct bpos dst_end = dst_start, src_end = src_start;
struct bpos dst_want, src_want; struct bpos dst_want, src_want;
u64 src_done, dst_done; u64 src_done, dst_done;
...@@ -216,7 +215,8 @@ s64 bch2_remap_range(struct bch_fs *c, ...@@ -216,7 +215,8 @@ s64 bch2_remap_range(struct bch_fs *c,
dst_end.offset += remap_sectors; dst_end.offset += remap_sectors;
src_end.offset += remap_sectors; src_end.offset += remap_sectors;
bkey_on_stack_init(&new_src); bch2_bkey_buf_init(&new_dst);
bch2_bkey_buf_init(&new_src);
bch2_trans_init(&trans, c, BTREE_ITER_MAX, 4096); bch2_trans_init(&trans, c, BTREE_ITER_MAX, 4096);
src_iter = bch2_trans_get_iter(&trans, BTREE_ID_EXTENTS, src_start, src_iter = bch2_trans_get_iter(&trans, BTREE_ID_EXTENTS, src_start,
...@@ -257,7 +257,7 @@ s64 bch2_remap_range(struct bch_fs *c, ...@@ -257,7 +257,7 @@ s64 bch2_remap_range(struct bch_fs *c,
break; break;
if (src_k.k->type != KEY_TYPE_reflink_p) { if (src_k.k->type != KEY_TYPE_reflink_p) {
bkey_on_stack_reassemble(&new_src, c, src_k); bch2_bkey_buf_reassemble(&new_src, c, 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);
...@@ -275,7 +275,7 @@ s64 bch2_remap_range(struct bch_fs *c, ...@@ -275,7 +275,7 @@ s64 bch2_remap_range(struct bch_fs *c,
struct bkey_s_c_reflink_p src_p = struct bkey_s_c_reflink_p src_p =
bkey_s_c_to_reflink_p(src_k); bkey_s_c_to_reflink_p(src_k);
struct bkey_i_reflink_p *dst_p = struct bkey_i_reflink_p *dst_p =
bkey_reflink_p_init(&new_dst.k); bkey_reflink_p_init(new_dst.k);
u64 offset = le64_to_cpu(src_p.v->idx) + u64 offset = le64_to_cpu(src_p.v->idx) +
(src_iter->pos.offset - (src_iter->pos.offset -
...@@ -286,12 +286,12 @@ s64 bch2_remap_range(struct bch_fs *c, ...@@ -286,12 +286,12 @@ s64 bch2_remap_range(struct bch_fs *c,
BUG(); BUG();
} }
new_dst.k.k.p = dst_iter->pos; new_dst.k->k.p = dst_iter->pos;
bch2_key_resize(&new_dst.k.k, bch2_key_resize(&new_dst.k->k,
min(src_k.k->p.offset - src_iter->pos.offset, min(src_k.k->p.offset - src_iter->pos.offset,
dst_end.offset - dst_iter->pos.offset)); dst_end.offset - dst_iter->pos.offset));
ret = bch2_extent_update(&trans, dst_iter, &new_dst.k, ret = bch2_extent_update(&trans, dst_iter, new_dst.k,
NULL, journal_seq, NULL, journal_seq,
new_i_size, i_sectors_delta); new_i_size, i_sectors_delta);
if (ret) if (ret)
...@@ -333,7 +333,8 @@ s64 bch2_remap_range(struct bch_fs *c, ...@@ -333,7 +333,8 @@ s64 bch2_remap_range(struct bch_fs *c,
} while (ret2 == -EINTR); } while (ret2 == -EINTR);
ret = bch2_trans_exit(&trans) ?: ret; ret = bch2_trans_exit(&trans) ?: ret;
bkey_on_stack_exit(&new_src, c); bch2_bkey_buf_exit(&new_src, c);
bch2_bkey_buf_exit(&new_dst, c);
percpu_ref_put(&c->writes); percpu_ref_put(&c->writes);
......
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