Commit 717296c3 authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: trans_mark now takes bkey_s

Prep work for disk space accounting rewrite: we're going to want to use
a single callback for both of our current triggers, so we need to change
them to have the same type signature first.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent eff1f728
......@@ -751,7 +751,7 @@ static noinline int bch2_bucket_gen_update(struct btree_trans *trans,
int bch2_trans_mark_alloc(struct btree_trans *trans,
enum btree_id btree_id, unsigned level,
struct bkey_s_c old, struct bkey_i *new,
struct bkey_s_c old, struct bkey_s new,
unsigned flags)
{
struct bch_fs *c = trans->c;
......@@ -764,10 +764,10 @@ int bch2_trans_mark_alloc(struct btree_trans *trans,
* Deletion only happens in the device removal path, with
* BTREE_TRIGGER_NORUN:
*/
BUG_ON(new->k.type != KEY_TYPE_alloc_v4);
BUG_ON(new.k->type != KEY_TYPE_alloc_v4);
old_a = bch2_alloc_to_v4(old, &old_a_convert);
new_a = &bkey_i_to_alloc_v4(new)->v;
new_a = bkey_s_to_alloc_v4(new).v;
new_a->data_type = alloc_data_type(*new_a, new_a->data_type);
......@@ -780,7 +780,7 @@ int bch2_trans_mark_alloc(struct btree_trans *trans,
if (data_type_is_empty(new_a->data_type) &&
BCH_ALLOC_V4_NEED_INC_GEN(new_a) &&
!bch2_bucket_is_open_safe(c, new->k.p.inode, new->k.p.offset)) {
!bch2_bucket_is_open_safe(c, new.k->p.inode, new.k->p.offset)) {
new_a->gen++;
SET_BCH_ALLOC_V4_NEED_INC_GEN(new_a, false);
}
......@@ -789,7 +789,7 @@ int bch2_trans_mark_alloc(struct btree_trans *trans,
(new_a->data_type == BCH_DATA_free &&
alloc_freespace_genbits(*old_a) != alloc_freespace_genbits(*new_a))) {
ret = bch2_bucket_do_index(trans, old, old_a, false) ?:
bch2_bucket_do_index(trans, bkey_i_to_s_c(new), new_a, true);
bch2_bucket_do_index(trans, new.s_c, new_a, true);
if (ret)
return ret;
}
......@@ -802,27 +802,27 @@ int bch2_trans_mark_alloc(struct btree_trans *trans,
new_lru = alloc_lru_idx_read(*new_a);
if (old_lru != new_lru) {
ret = bch2_lru_change(trans, new->k.p.inode,
bucket_to_u64(new->k.p),
ret = bch2_lru_change(trans, new.k->p.inode,
bucket_to_u64(new.k->p),
old_lru, new_lru);
if (ret)
return ret;
}
new_a->fragmentation_lru = alloc_lru_idx_fragmentation(*new_a,
bch_dev_bkey_exists(c, new->k.p.inode));
bch_dev_bkey_exists(c, new.k->p.inode));
if (old_a->fragmentation_lru != new_a->fragmentation_lru) {
ret = bch2_lru_change(trans,
BCH_LRU_FRAGMENTATION_START,
bucket_to_u64(new->k.p),
bucket_to_u64(new.k->p),
old_a->fragmentation_lru, new_a->fragmentation_lru);
if (ret)
return ret;
}
if (old_a->gen != new_a->gen) {
ret = bch2_bucket_gen_update(trans, new->k.p, new_a->gen);
ret = bch2_bucket_gen_update(trans, new.k->p, new_a->gen);
if (ret)
return ret;
}
......@@ -834,7 +834,7 @@ int bch2_trans_mark_alloc(struct btree_trans *trans,
if ((flags & BTREE_TRIGGER_BUCKET_INVALIDATE) &&
old_a->cached_sectors) {
ret = bch2_update_cached_sectors_list(trans, new->k.p.inode,
ret = bch2_update_cached_sectors_list(trans, new.k->p.inode,
-((s64) old_a->cached_sectors));
if (ret)
return ret;
......
......@@ -233,7 +233,7 @@ static inline bool bkey_is_alloc(const struct bkey *k)
int bch2_alloc_read(struct bch_fs *);
int bch2_trans_mark_alloc(struct btree_trans *, enum btree_id, unsigned,
struct bkey_s_c, struct bkey_i *, unsigned);
struct bkey_s_c, struct bkey_s, unsigned);
int bch2_check_alloc_info(struct bch_fs *);
int bch2_check_alloc_to_lru_refs(struct bch_fs *);
void bch2_do_discards(struct bch_fs *);
......
......@@ -29,7 +29,7 @@ struct bkey_ops {
bool (*key_normalize)(struct bch_fs *, struct bkey_s);
bool (*key_merge)(struct bch_fs *, struct bkey_s, struct bkey_s_c);
int (*trans_trigger)(struct btree_trans *, enum btree_id, unsigned,
struct bkey_s_c, struct bkey_i *, unsigned);
struct bkey_s_c, struct bkey_s, unsigned);
int (*atomic_trigger)(struct btree_trans *, enum btree_id, unsigned,
struct bkey_s_c, struct bkey_s_c, unsigned);
void (*compat)(enum btree_id id, unsigned version,
......@@ -120,10 +120,10 @@ enum btree_update_flags {
static inline int bch2_trans_mark_key(struct btree_trans *trans,
enum btree_id btree_id, unsigned level,
struct bkey_s_c old, struct bkey_i *new,
struct bkey_s_c old, struct bkey_s new,
unsigned flags)
{
const struct bkey_ops *ops = bch2_bkey_type_ops(old.k->type ?: new->k.type);
const struct bkey_ops *ops = bch2_bkey_type_ops(old.k->type ?: new.k->type);
return ops->trans_trigger
? ops->trans_trigger(trans, btree_id, level, old, new, flags)
......@@ -139,18 +139,18 @@ static inline int bch2_trans_mark_old(struct btree_trans *trans,
bkey_init(&deleted.k);
deleted.k.p = old.k->p;
return bch2_trans_mark_key(trans, btree_id, level, old, &deleted,
return bch2_trans_mark_key(trans, btree_id, level, old, bkey_i_to_s(&deleted),
BTREE_TRIGGER_OVERWRITE|flags);
}
static inline int bch2_trans_mark_new(struct btree_trans *trans,
enum btree_id btree_id, unsigned level,
struct bkey_i *new, unsigned flags)
struct bkey_s new, unsigned flags)
{
struct bkey_i deleted;
bkey_init(&deleted.k);
deleted.k.p = new->k.p;
deleted.k.p = new.k->p;
return bch2_trans_mark_key(trans, btree_id, level, bkey_i_to_s_c(&deleted), new,
BTREE_TRIGGER_INSERT|flags);
......
......@@ -1589,7 +1589,7 @@ static int bch2_gc_write_reflink_key(struct btree_trans *trans,
if (!r->refcount)
new->k.type = KEY_TYPE_deleted;
else
*bkey_refcount(new) = cpu_to_le64(r->refcount);
*bkey_refcount(bkey_i_to_s(new)) = cpu_to_le64(r->refcount);
}
fsck_err:
printbuf_exit(&buf);
......
......@@ -494,7 +494,7 @@ static int run_one_trans_trigger(struct btree_trans *trans, struct btree_insert_
old_ops->trans_trigger == new_ops->trans_trigger) {
i->overwrite_trigger_run = true;
i->insert_trigger_run = true;
return bch2_trans_mark_key(trans, i->btree_id, i->level, old, i->k,
return bch2_trans_mark_key(trans, i->btree_id, i->level, old, bkey_i_to_s(i->k),
BTREE_TRIGGER_INSERT|
BTREE_TRIGGER_OVERWRITE|
i->flags) ?: 1;
......@@ -503,7 +503,7 @@ static int run_one_trans_trigger(struct btree_trans *trans, struct btree_insert_
return bch2_trans_mark_old(trans, i->btree_id, i->level, old, i->flags) ?: 1;
} else if (!overwrite && !i->insert_trigger_run) {
i->insert_trigger_run = true;
return bch2_trans_mark_new(trans, i->btree_id, i->level, i->k, i->flags) ?: 1;
return bch2_trans_mark_new(trans, i->btree_id, i->level, bkey_i_to_s(i->k), i->flags) ?: 1;
} else {
return 0;
}
......
......@@ -576,7 +576,7 @@ static int btree_update_nodes_written_trans(struct btree_trans *trans,
for_each_keylist_key(&as->new_keys, k) {
unsigned level = bkey_i_to_btree_ptr_v2(k)->v.mem_ptr;
ret = bch2_trans_mark_new(trans, as->btree_id, level, k, 0);
ret = bch2_trans_mark_new(trans, as->btree_id, level, bkey_i_to_s(k), 0);
if (ret)
return ret;
}
......@@ -2162,7 +2162,7 @@ static int __bch2_btree_node_update_key(struct btree_trans *trans,
return ret;
ret = bch2_trans_mark_new(trans, b->c.btree_id, b->c.level + 1,
new_key, 0);
bkey_i_to_s(new_key), 0);
if (ret)
return ret;
}
......
......@@ -1423,15 +1423,15 @@ static int __trans_mark_extent(struct btree_trans *trans,
int bch2_trans_mark_extent(struct btree_trans *trans,
enum btree_id btree_id, unsigned level,
struct bkey_s_c old, struct bkey_i *new,
struct bkey_s_c old, struct bkey_s new,
unsigned flags)
{
struct bch_fs *c = trans->c;
int mod = (int) bch2_bkey_needs_rebalance(c, bkey_i_to_s_c(new)) -
int mod = (int) bch2_bkey_needs_rebalance(c, new.s_c) -
(int) bch2_bkey_needs_rebalance(c, old);
if (mod) {
int ret = bch2_btree_bit_mod(trans, BTREE_ID_rebalance_work, new->k.p, mod > 0);
int ret = bch2_btree_bit_mod(trans, BTREE_ID_rebalance_work, new.k->p, mod > 0);
if (ret)
return ret;
}
......@@ -1519,7 +1519,7 @@ static int bch2_trans_mark_stripe_bucket(struct btree_trans *trans,
int bch2_trans_mark_stripe(struct btree_trans *trans,
enum btree_id btree_id, unsigned level,
struct bkey_s_c old, struct bkey_i *new,
struct bkey_s_c old, struct bkey_s new,
unsigned flags)
{
const struct bch_stripe *old_s = NULL;
......@@ -1530,8 +1530,8 @@ int bch2_trans_mark_stripe(struct btree_trans *trans,
if (old.k->type == KEY_TYPE_stripe)
old_s = bkey_s_c_to_stripe(old).v;
if (new->k.type == KEY_TYPE_stripe)
new_s = &bkey_i_to_stripe(new)->v;
if (new.k->type == KEY_TYPE_stripe)
new_s = bkey_s_to_stripe(new).v;
/*
* If the pointers aren't changing, we don't need to do anything:
......@@ -1552,7 +1552,7 @@ int bch2_trans_mark_stripe(struct btree_trans *trans,
if (new_s) {
s64 sectors = le16_to_cpu(new_s->sectors);
bch2_bkey_to_replicas(&r.e, bkey_i_to_s_c(new));
bch2_bkey_to_replicas(&r.e, new.s_c);
ret = bch2_update_replicas_list(trans, &r.e, sectors * new_s->nr_redundant);
if (ret)
return ret;
......@@ -1576,7 +1576,7 @@ int bch2_trans_mark_stripe(struct btree_trans *trans,
if (new_s) {
ret = bch2_trans_mark_stripe_bucket(trans,
bkey_i_to_s_c_stripe(new), i, false);
bkey_s_to_stripe(new).c, i, false);
if (ret)
break;
}
......@@ -1620,7 +1620,7 @@ static int __trans_mark_reservation(struct btree_trans *trans,
int bch2_trans_mark_reservation(struct btree_trans *trans,
enum btree_id btree_id, unsigned level,
struct bkey_s_c old,
struct bkey_i *new,
struct bkey_s new,
unsigned flags)
{
return trigger_run_overwrite_then_insert(__trans_mark_reservation, trans, btree_id, level, old, new, flags);
......
......@@ -336,9 +336,9 @@ int bch2_mark_stripe(struct btree_trans *, enum btree_id, unsigned,
int bch2_mark_reservation(struct btree_trans *, enum btree_id, unsigned,
struct bkey_s_c, struct bkey_s_c, unsigned);
int bch2_trans_mark_extent(struct btree_trans *, enum btree_id, unsigned, struct bkey_s_c, struct bkey_i *, unsigned);
int bch2_trans_mark_stripe(struct btree_trans *, enum btree_id, unsigned, struct bkey_s_c, struct bkey_i *, unsigned);
int bch2_trans_mark_reservation(struct btree_trans *, enum btree_id, unsigned, struct bkey_s_c, struct bkey_i *, unsigned);
int bch2_trans_mark_extent(struct btree_trans *, enum btree_id, unsigned, struct bkey_s_c, struct bkey_s, unsigned);
int bch2_trans_mark_stripe(struct btree_trans *, enum btree_id, unsigned, struct bkey_s_c, struct bkey_s, unsigned);
int bch2_trans_mark_reservation(struct btree_trans *, enum btree_id, unsigned, struct bkey_s_c, struct bkey_s, unsigned);
#define mem_trigger_run_overwrite_then_insert(_fn, _trans, _btree_id, _level, _old, _new, _flags)\
({ \
int ret = 0; \
......@@ -351,7 +351,7 @@ int bch2_trans_mark_reservation(struct btree_trans *, enum btree_id, unsigned, s
})
#define trigger_run_overwrite_then_insert(_fn, _trans, _btree_id, _level, _old, _new, _flags) \
mem_trigger_run_overwrite_then_insert(_fn, _trans, _btree_id, _level, _old, bkey_i_to_s_c(_new), _flags)
mem_trigger_run_overwrite_then_insert(_fn, _trans, _btree_id, _level, _old, _new.s_c, _flags)
void bch2_trans_fs_usage_revert(struct btree_trans *, struct replicas_delta_list *);
int bch2_trans_fs_usage_apply(struct btree_trans *, struct replicas_delta_list *);
......
......@@ -564,12 +564,12 @@ static inline bool bkey_is_deleted_inode(struct bkey_s_c k)
int bch2_trans_mark_inode(struct btree_trans *trans,
enum btree_id btree_id, unsigned level,
struct bkey_s_c old,
struct bkey_i *new,
struct bkey_s new,
unsigned flags)
{
int nr = bkey_is_inode(&new->k) - bkey_is_inode(old.k);
s64 nr = bkey_is_inode(new.k) - bkey_is_inode(old.k);
bool old_deleted = bkey_is_deleted_inode(old);
bool new_deleted = bkey_is_deleted_inode(bkey_i_to_s_c(new));
bool new_deleted = bkey_is_deleted_inode(new.s_c);
if (nr) {
int ret = bch2_replicas_deltas_realloc(trans, 0);
......@@ -582,7 +582,7 @@ int bch2_trans_mark_inode(struct btree_trans *trans,
}
if (old_deleted != new_deleted) {
int ret = bch2_btree_bit_mod(trans, BTREE_ID_deleted_inodes, new->k.p, new_deleted);
int ret = bch2_btree_bit_mod(trans, BTREE_ID_deleted_inodes, new.k->p, new_deleted);
if (ret)
return ret;
}
......
......@@ -18,7 +18,7 @@ int bch2_inode_v3_invalid(struct bch_fs *, struct bkey_s_c,
void bch2_inode_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
int bch2_trans_mark_inode(struct btree_trans *, enum btree_id, unsigned,
struct bkey_s_c, struct bkey_i *, unsigned);
struct bkey_s_c, struct bkey_s, unsigned);
int bch2_mark_inode(struct btree_trans *, enum btree_id, unsigned,
struct bkey_s_c, struct bkey_s_c, unsigned);
......
......@@ -93,7 +93,7 @@ static int trans_mark_reflink_p_segment(struct btree_trans *trans,
if (ret)
goto err;
refcount = bkey_refcount(k);
refcount = bkey_refcount(bkey_i_to_s(k));
if (!refcount) {
bch2_bkey_val_to_text(&buf, c, p.s_c);
bch2_trans_inconsistent(trans,
......@@ -161,11 +161,11 @@ static int __trans_mark_reflink_p(struct btree_trans *trans,
int bch2_trans_mark_reflink_p(struct btree_trans *trans,
enum btree_id btree_id, unsigned level,
struct bkey_s_c old,
struct bkey_i *new,
struct bkey_s new,
unsigned flags)
{
if (flags & BTREE_TRIGGER_INSERT) {
struct bch_reflink_p *v = &bkey_i_to_reflink_p(new)->v;
struct bch_reflink_p *v = bkey_s_to_reflink_p(new).v;
v->front_pad = v->back_pad = 0;
}
......@@ -305,29 +305,29 @@ bool bch2_reflink_v_merge(struct bch_fs *c, struct bkey_s _l, struct bkey_s_c _r
}
#endif
static inline void check_indirect_extent_deleting(struct bkey_i *new, unsigned *flags)
static inline void check_indirect_extent_deleting(struct bkey_s new, unsigned *flags)
{
if ((*flags & BTREE_TRIGGER_INSERT) && !*bkey_refcount(new)) {
new->k.type = KEY_TYPE_deleted;
new->k.size = 0;
set_bkey_val_u64s(&new->k, 0);
new.k->type = KEY_TYPE_deleted;
new.k->size = 0;
set_bkey_val_u64s(new.k, 0);
*flags &= ~BTREE_TRIGGER_INSERT;
}
}
int bch2_trans_mark_reflink_v(struct btree_trans *trans,
enum btree_id btree_id, unsigned level,
struct bkey_s_c old, struct bkey_i *new,
struct bkey_s_c old, struct bkey_s new,
unsigned flags)
{
check_indirect_extent_deleting(new, &flags);
if (old.k->type == KEY_TYPE_reflink_v &&
new->k.type == KEY_TYPE_reflink_v &&
old.k->u64s == new->k.u64s &&
new.k->type == KEY_TYPE_reflink_v &&
old.k->u64s == new.k->u64s &&
!memcmp(bkey_s_c_to_reflink_v(old).v->start,
bkey_i_to_reflink_v(new)->v.start,
bkey_val_bytes(&new->k) - 8))
bkey_s_to_reflink_v(new).v->start,
bkey_val_bytes(new.k) - 8))
return 0;
return bch2_trans_mark_extent(trans, btree_id, level, old, new, flags);
......@@ -355,7 +355,7 @@ void bch2_indirect_inline_data_to_text(struct printbuf *out,
int bch2_trans_mark_indirect_inline_data(struct btree_trans *trans,
enum btree_id btree_id, unsigned level,
struct bkey_s_c old, struct bkey_i *new,
struct bkey_s_c old, struct bkey_s new,
unsigned flags)
{
check_indirect_extent_deleting(new, &flags);
......@@ -398,7 +398,7 @@ static int bch2_make_extent_indirect(struct btree_trans *trans,
set_bkey_val_bytes(&r_v->k, sizeof(__le64) + bkey_val_bytes(&orig->k));
refcount = bkey_refcount(r_v);
refcount = bkey_refcount(bkey_i_to_s(r_v));
*refcount = 0;
memcpy(refcount + 1, &orig->v, bkey_val_bytes(&orig->k));
......
......@@ -10,7 +10,7 @@ void bch2_reflink_p_to_text(struct printbuf *, struct bch_fs *,
struct bkey_s_c);
bool bch2_reflink_p_merge(struct bch_fs *, struct bkey_s, struct bkey_s_c);
int bch2_trans_mark_reflink_p(struct btree_trans *, enum btree_id, unsigned,
struct bkey_s_c, struct bkey_i *, unsigned);
struct bkey_s_c, struct bkey_s, unsigned);
int bch2_mark_reflink_p(struct btree_trans *, enum btree_id, unsigned,
struct bkey_s_c, struct bkey_s_c, unsigned);
......@@ -28,7 +28,7 @@ int bch2_reflink_v_invalid(struct bch_fs *, struct bkey_s_c,
void bch2_reflink_v_to_text(struct printbuf *, struct bch_fs *,
struct bkey_s_c);
int bch2_trans_mark_reflink_v(struct btree_trans *, enum btree_id, unsigned,
struct bkey_s_c, struct bkey_i *, unsigned);
struct bkey_s_c, struct bkey_s, unsigned);
#define bch2_bkey_ops_reflink_v ((struct bkey_ops) { \
.key_invalid = bch2_reflink_v_invalid, \
......@@ -45,7 +45,7 @@ void bch2_indirect_inline_data_to_text(struct printbuf *,
struct bch_fs *, struct bkey_s_c);
int bch2_trans_mark_indirect_inline_data(struct btree_trans *,
enum btree_id, unsigned,
struct bkey_s_c, struct bkey_i *,
struct bkey_s_c, struct bkey_s,
unsigned);
#define bch2_bkey_ops_indirect_inline_data ((struct bkey_ops) { \
......@@ -67,13 +67,13 @@ static inline const __le64 *bkey_refcount_c(struct bkey_s_c k)
}
}
static inline __le64 *bkey_refcount(struct bkey_i *k)
static inline __le64 *bkey_refcount(struct bkey_s k)
{
switch (k->k.type) {
switch (k.k->type) {
case KEY_TYPE_reflink_v:
return &bkey_i_to_reflink_v(k)->v.refcount;
return &bkey_s_to_reflink_v(k).v->refcount;
case KEY_TYPE_indirect_inline_data:
return &bkey_i_to_indirect_inline_data(k)->v.refcount;
return &bkey_s_to_indirect_inline_data(k).v->refcount;
default:
return NULL;
}
......
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