bcachefs: 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: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
717296c34c
commit
ad00bce07d
@ -31,7 +31,7 @@ struct bkey_ops {
|
|||||||
int (*trans_trigger)(struct btree_trans *, enum btree_id, unsigned,
|
int (*trans_trigger)(struct btree_trans *, enum btree_id, unsigned,
|
||||||
struct bkey_s_c, struct bkey_s, unsigned);
|
struct bkey_s_c, struct bkey_s, unsigned);
|
||||||
int (*atomic_trigger)(struct btree_trans *, enum btree_id, unsigned,
|
int (*atomic_trigger)(struct btree_trans *, enum btree_id, unsigned,
|
||||||
struct bkey_s_c, struct bkey_s_c, unsigned);
|
struct bkey_s_c, struct bkey_s, unsigned);
|
||||||
void (*compat)(enum btree_id id, unsigned version,
|
void (*compat)(enum btree_id id, unsigned version,
|
||||||
unsigned big_endian, int write,
|
unsigned big_endian, int write,
|
||||||
struct bkey_s);
|
struct bkey_s);
|
||||||
@ -80,7 +80,7 @@ bool bch2_bkey_merge(struct bch_fs *, struct bkey_s, struct bkey_s_c);
|
|||||||
|
|
||||||
static inline int bch2_mark_key(struct btree_trans *trans,
|
static inline int bch2_mark_key(struct btree_trans *trans,
|
||||||
enum btree_id btree, unsigned level,
|
enum btree_id btree, unsigned level,
|
||||||
struct bkey_s_c old, struct bkey_s_c new,
|
struct bkey_s_c old, struct bkey_s new,
|
||||||
unsigned flags)
|
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);
|
||||||
|
@ -41,6 +41,14 @@
|
|||||||
#define DROP_THIS_NODE 10
|
#define DROP_THIS_NODE 10
|
||||||
#define DROP_PREV_NODE 11
|
#define DROP_PREV_NODE 11
|
||||||
|
|
||||||
|
static struct bkey_s unsafe_bkey_s_c_to_s(struct bkey_s_c k)
|
||||||
|
{
|
||||||
|
return (struct bkey_s) {{{
|
||||||
|
(struct bkey *) k.k,
|
||||||
|
(struct bch_val *) k.v
|
||||||
|
}}};
|
||||||
|
}
|
||||||
|
|
||||||
static bool should_restart_for_topology_repair(struct bch_fs *c)
|
static bool should_restart_for_topology_repair(struct bch_fs *c)
|
||||||
{
|
{
|
||||||
return c->opts.fix_errors != FSCK_FIX_no &&
|
return c->opts.fix_errors != FSCK_FIX_no &&
|
||||||
@ -829,7 +837,7 @@ static int bch2_gc_mark_key(struct btree_trans *trans, enum btree_id btree_id,
|
|||||||
}
|
}
|
||||||
|
|
||||||
ret = commit_do(trans, NULL, NULL, 0,
|
ret = commit_do(trans, NULL, NULL, 0,
|
||||||
bch2_mark_key(trans, btree_id, level, old, *k, flags));
|
bch2_mark_key(trans, btree_id, level, old, unsafe_bkey_s_c_to_s(*k), flags));
|
||||||
fsck_err:
|
fsck_err:
|
||||||
err:
|
err:
|
||||||
bch_err_fn(c, ret);
|
bch_err_fn(c, ret);
|
||||||
|
@ -453,14 +453,14 @@ static int run_one_mem_trigger(struct btree_trans *trans,
|
|||||||
|
|
||||||
if (old_ops->atomic_trigger == new_ops->atomic_trigger) {
|
if (old_ops->atomic_trigger == new_ops->atomic_trigger) {
|
||||||
ret = bch2_mark_key(trans, i->btree_id, i->level,
|
ret = bch2_mark_key(trans, i->btree_id, i->level,
|
||||||
old, bkey_i_to_s_c(new),
|
old, bkey_i_to_s(new),
|
||||||
BTREE_TRIGGER_INSERT|BTREE_TRIGGER_OVERWRITE|flags);
|
BTREE_TRIGGER_INSERT|BTREE_TRIGGER_OVERWRITE|flags);
|
||||||
} else {
|
} else {
|
||||||
struct bkey _deleted = POS_KEY((trans->paths + i->path)->pos);
|
struct bkey _deleted = POS_KEY((trans->paths + i->path)->pos);
|
||||||
struct bkey_s_c deleted = (struct bkey_s_c) { &_deleted, NULL };
|
struct bkey_s deleted = (struct bkey_s) { { { &_deleted, NULL } } };
|
||||||
|
|
||||||
ret = bch2_mark_key(trans, i->btree_id, i->level,
|
ret = bch2_mark_key(trans, i->btree_id, i->level,
|
||||||
deleted, bkey_i_to_s_c(new),
|
deleted.s_c, bkey_i_to_s(new),
|
||||||
BTREE_TRIGGER_INSERT|flags) ?:
|
BTREE_TRIGGER_INSERT|flags) ?:
|
||||||
bch2_mark_key(trans, i->btree_id, i->level,
|
bch2_mark_key(trans, i->btree_id, i->level,
|
||||||
old, deleted,
|
old, deleted,
|
||||||
|
@ -498,7 +498,7 @@ int bch2_update_cached_sectors_list(struct btree_trans *trans, unsigned dev, s64
|
|||||||
|
|
||||||
int bch2_mark_alloc(struct btree_trans *trans,
|
int bch2_mark_alloc(struct btree_trans *trans,
|
||||||
enum btree_id btree, unsigned level,
|
enum btree_id btree, unsigned level,
|
||||||
struct bkey_s_c old, struct bkey_s_c new,
|
struct bkey_s_c old, struct bkey_s new,
|
||||||
unsigned flags)
|
unsigned flags)
|
||||||
{
|
{
|
||||||
bool gc = flags & BTREE_TRIGGER_GC;
|
bool gc = flags & BTREE_TRIGGER_GC;
|
||||||
@ -524,7 +524,7 @@ int bch2_mark_alloc(struct btree_trans *trans,
|
|||||||
ca = bch_dev_bkey_exists(c, new.k->p.inode);
|
ca = bch_dev_bkey_exists(c, new.k->p.inode);
|
||||||
|
|
||||||
old_a = bch2_alloc_to_v4(old, &old_a_convert);
|
old_a = bch2_alloc_to_v4(old, &old_a_convert);
|
||||||
new_a = bch2_alloc_to_v4(new, &new_a_convert);
|
new_a = bch2_alloc_to_v4(new.s_c, &new_a_convert);
|
||||||
|
|
||||||
bucket_journal_seq = new_a->journal_seq;
|
bucket_journal_seq = new_a->journal_seq;
|
||||||
|
|
||||||
@ -1008,7 +1008,7 @@ static int __mark_extent(struct btree_trans *trans,
|
|||||||
|
|
||||||
int bch2_mark_extent(struct btree_trans *trans,
|
int bch2_mark_extent(struct btree_trans *trans,
|
||||||
enum btree_id btree_id, unsigned level,
|
enum btree_id btree_id, unsigned level,
|
||||||
struct bkey_s_c old, struct bkey_s_c new,
|
struct bkey_s_c old, struct bkey_s new,
|
||||||
unsigned flags)
|
unsigned flags)
|
||||||
{
|
{
|
||||||
return mem_trigger_run_overwrite_then_insert(__mark_extent, trans, btree_id, level, old, new, flags);
|
return mem_trigger_run_overwrite_then_insert(__mark_extent, trans, btree_id, level, old, new, flags);
|
||||||
@ -1016,9 +1016,10 @@ int bch2_mark_extent(struct btree_trans *trans,
|
|||||||
|
|
||||||
int bch2_mark_stripe(struct btree_trans *trans,
|
int bch2_mark_stripe(struct btree_trans *trans,
|
||||||
enum btree_id btree_id, unsigned level,
|
enum btree_id btree_id, unsigned level,
|
||||||
struct bkey_s_c old, struct bkey_s_c new,
|
struct bkey_s_c old, struct bkey_s _new,
|
||||||
unsigned flags)
|
unsigned flags)
|
||||||
{
|
{
|
||||||
|
struct bkey_s_c new = _new.s_c;
|
||||||
bool gc = flags & BTREE_TRIGGER_GC;
|
bool gc = flags & BTREE_TRIGGER_GC;
|
||||||
u64 journal_seq = trans->journal_res.seq;
|
u64 journal_seq = trans->journal_res.seq;
|
||||||
struct bch_fs *c = trans->c;
|
struct bch_fs *c = trans->c;
|
||||||
@ -1153,7 +1154,7 @@ static int __mark_reservation(struct btree_trans *trans,
|
|||||||
|
|
||||||
int bch2_mark_reservation(struct btree_trans *trans,
|
int bch2_mark_reservation(struct btree_trans *trans,
|
||||||
enum btree_id btree_id, unsigned level,
|
enum btree_id btree_id, unsigned level,
|
||||||
struct bkey_s_c old, struct bkey_s_c new,
|
struct bkey_s_c old, struct bkey_s new,
|
||||||
unsigned flags)
|
unsigned flags)
|
||||||
{
|
{
|
||||||
return mem_trigger_run_overwrite_then_insert(__mark_reservation, trans, btree_id, level, old, new, flags);
|
return mem_trigger_run_overwrite_then_insert(__mark_reservation, trans, btree_id, level, old, new, flags);
|
||||||
|
@ -328,13 +328,13 @@ int bch2_mark_metadata_bucket(struct bch_fs *, struct bch_dev *,
|
|||||||
struct gc_pos, unsigned);
|
struct gc_pos, unsigned);
|
||||||
|
|
||||||
int bch2_mark_alloc(struct btree_trans *, enum btree_id, unsigned,
|
int bch2_mark_alloc(struct btree_trans *, enum btree_id, unsigned,
|
||||||
struct bkey_s_c, struct bkey_s_c, unsigned);
|
struct bkey_s_c, struct bkey_s, unsigned);
|
||||||
int bch2_mark_extent(struct btree_trans *, enum btree_id, unsigned,
|
int bch2_mark_extent(struct btree_trans *, enum btree_id, unsigned,
|
||||||
struct bkey_s_c, struct bkey_s_c, unsigned);
|
struct bkey_s_c, struct bkey_s, unsigned);
|
||||||
int bch2_mark_stripe(struct btree_trans *, enum btree_id, unsigned,
|
int bch2_mark_stripe(struct btree_trans *, enum btree_id, unsigned,
|
||||||
struct bkey_s_c, struct bkey_s_c, unsigned);
|
struct bkey_s_c, struct bkey_s, unsigned);
|
||||||
int bch2_mark_reservation(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);
|
struct bkey_s_c, struct bkey_s, 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_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_stripe(struct btree_trans *, enum btree_id, unsigned, struct bkey_s_c, struct bkey_s, unsigned);
|
||||||
@ -346,12 +346,12 @@ int bch2_trans_mark_reservation(struct btree_trans *, enum btree_id, unsigned, s
|
|||||||
if (_old.k->type) \
|
if (_old.k->type) \
|
||||||
ret = _fn(_trans, _btree_id, _level, _old, _flags & ~BTREE_TRIGGER_INSERT); \
|
ret = _fn(_trans, _btree_id, _level, _old, _flags & ~BTREE_TRIGGER_INSERT); \
|
||||||
if (!ret && _new.k->type) \
|
if (!ret && _new.k->type) \
|
||||||
ret = _fn(_trans, _btree_id, _level, _new, _flags & ~BTREE_TRIGGER_OVERWRITE); \
|
ret = _fn(_trans, _btree_id, _level, _new.s_c, _flags & ~BTREE_TRIGGER_OVERWRITE);\
|
||||||
ret; \
|
ret; \
|
||||||
})
|
})
|
||||||
|
|
||||||
#define trigger_run_overwrite_then_insert(_fn, _trans, _btree_id, _level, _old, _new, _flags) \
|
#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, _new.s_c, _flags)
|
mem_trigger_run_overwrite_then_insert(_fn, _trans, _btree_id, _level, _old, _new, _flags)
|
||||||
|
|
||||||
void bch2_trans_fs_usage_revert(struct btree_trans *, struct replicas_delta_list *);
|
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 *);
|
int bch2_trans_fs_usage_apply(struct btree_trans *, struct replicas_delta_list *);
|
||||||
|
@ -592,7 +592,7 @@ int bch2_trans_mark_inode(struct btree_trans *trans,
|
|||||||
|
|
||||||
int bch2_mark_inode(struct btree_trans *trans,
|
int bch2_mark_inode(struct btree_trans *trans,
|
||||||
enum btree_id btree_id, unsigned level,
|
enum btree_id btree_id, unsigned level,
|
||||||
struct bkey_s_c old, struct bkey_s_c new,
|
struct bkey_s_c old, struct bkey_s new,
|
||||||
unsigned flags)
|
unsigned flags)
|
||||||
{
|
{
|
||||||
struct bch_fs *c = trans->c;
|
struct bch_fs *c = trans->c;
|
||||||
@ -600,12 +600,9 @@ int bch2_mark_inode(struct btree_trans *trans,
|
|||||||
u64 journal_seq = trans->journal_res.seq;
|
u64 journal_seq = trans->journal_res.seq;
|
||||||
|
|
||||||
if (flags & BTREE_TRIGGER_INSERT) {
|
if (flags & BTREE_TRIGGER_INSERT) {
|
||||||
struct bch_inode_v3 *v = (struct bch_inode_v3 *) new.v;
|
|
||||||
|
|
||||||
BUG_ON(!journal_seq);
|
BUG_ON(!journal_seq);
|
||||||
BUG_ON(new.k->type != KEY_TYPE_inode_v3);
|
|
||||||
|
|
||||||
v->bi_journal_seq = cpu_to_le64(journal_seq);
|
bkey_s_to_inode_v3(new).v->bi_journal_seq = cpu_to_le64(journal_seq);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & BTREE_TRIGGER_GC) {
|
if (flags & BTREE_TRIGGER_GC) {
|
||||||
|
@ -20,7 +20,7 @@ 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,
|
int bch2_trans_mark_inode(struct btree_trans *, enum btree_id, unsigned,
|
||||||
struct bkey_s_c, struct bkey_s, unsigned);
|
struct bkey_s_c, struct bkey_s, unsigned);
|
||||||
int bch2_mark_inode(struct btree_trans *, enum btree_id, unsigned,
|
int bch2_mark_inode(struct btree_trans *, enum btree_id, unsigned,
|
||||||
struct bkey_s_c, struct bkey_s_c, unsigned);
|
struct bkey_s_c, struct bkey_s, unsigned);
|
||||||
|
|
||||||
#define bch2_bkey_ops_inode ((struct bkey_ops) { \
|
#define bch2_bkey_ops_inode ((struct bkey_ops) { \
|
||||||
.key_invalid = bch2_inode_invalid, \
|
.key_invalid = bch2_inode_invalid, \
|
||||||
|
@ -268,7 +268,7 @@ static int __mark_reflink_p(struct btree_trans *trans,
|
|||||||
|
|
||||||
int bch2_mark_reflink_p(struct btree_trans *trans,
|
int bch2_mark_reflink_p(struct btree_trans *trans,
|
||||||
enum btree_id btree_id, unsigned level,
|
enum btree_id btree_id, unsigned level,
|
||||||
struct bkey_s_c old, struct bkey_s_c new,
|
struct bkey_s_c old, struct bkey_s new,
|
||||||
unsigned flags)
|
unsigned flags)
|
||||||
{
|
{
|
||||||
return mem_trigger_run_overwrite_then_insert(__mark_reflink_p, trans, btree_id, level, old, new, flags);
|
return mem_trigger_run_overwrite_then_insert(__mark_reflink_p, trans, btree_id, level, old, new, flags);
|
||||||
|
@ -12,7 +12,7 @@ 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,
|
int bch2_trans_mark_reflink_p(struct btree_trans *, enum btree_id, unsigned,
|
||||||
struct bkey_s_c, struct bkey_s, unsigned);
|
struct bkey_s_c, struct bkey_s, unsigned);
|
||||||
int bch2_mark_reflink_p(struct btree_trans *, enum btree_id, unsigned,
|
int bch2_mark_reflink_p(struct btree_trans *, enum btree_id, unsigned,
|
||||||
struct bkey_s_c, struct bkey_s_c, unsigned);
|
struct bkey_s_c, struct bkey_s, unsigned);
|
||||||
|
|
||||||
#define bch2_bkey_ops_reflink_p ((struct bkey_ops) { \
|
#define bch2_bkey_ops_reflink_p ((struct bkey_ops) { \
|
||||||
.key_invalid = bch2_reflink_p_invalid, \
|
.key_invalid = bch2_reflink_p_invalid, \
|
||||||
|
@ -276,7 +276,7 @@ static void set_is_ancestor_bitmap(struct bch_fs *c, u32 id)
|
|||||||
mutex_unlock(&c->snapshot_table_lock);
|
mutex_unlock(&c->snapshot_table_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
int bch2_mark_snapshot(struct btree_trans *trans,
|
static int __bch2_mark_snapshot(struct btree_trans *trans,
|
||||||
enum btree_id btree, unsigned level,
|
enum btree_id btree, unsigned level,
|
||||||
struct bkey_s_c old, struct bkey_s_c new,
|
struct bkey_s_c old, struct bkey_s_c new,
|
||||||
unsigned flags)
|
unsigned flags)
|
||||||
@ -330,6 +330,14 @@ err:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int bch2_mark_snapshot(struct btree_trans *trans,
|
||||||
|
enum btree_id btree, unsigned level,
|
||||||
|
struct bkey_s_c old, struct bkey_s new,
|
||||||
|
unsigned flags)
|
||||||
|
{
|
||||||
|
return __bch2_mark_snapshot(trans, btree, level, old, new.s_c, flags);
|
||||||
|
}
|
||||||
|
|
||||||
int bch2_snapshot_lookup(struct btree_trans *trans, u32 id,
|
int bch2_snapshot_lookup(struct btree_trans *trans, u32 id,
|
||||||
struct bch_snapshot *s)
|
struct bch_snapshot *s)
|
||||||
{
|
{
|
||||||
@ -1055,7 +1063,7 @@ static int create_snapids(struct btree_trans *trans, u32 parent, u32 tree,
|
|||||||
bubble_sort(n->v.skip, ARRAY_SIZE(n->v.skip), cmp_le32);
|
bubble_sort(n->v.skip, ARRAY_SIZE(n->v.skip), cmp_le32);
|
||||||
SET_BCH_SNAPSHOT_SUBVOL(&n->v, true);
|
SET_BCH_SNAPSHOT_SUBVOL(&n->v, true);
|
||||||
|
|
||||||
ret = bch2_mark_snapshot(trans, BTREE_ID_snapshots, 0,
|
ret = __bch2_mark_snapshot(trans, BTREE_ID_snapshots, 0,
|
||||||
bkey_s_c_null, bkey_i_to_s_c(&n->k_i), 0);
|
bkey_s_c_null, bkey_i_to_s_c(&n->k_i), 0);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
@ -1664,7 +1672,7 @@ int bch2_snapshots_read(struct bch_fs *c)
|
|||||||
int ret = bch2_trans_run(c,
|
int ret = bch2_trans_run(c,
|
||||||
for_each_btree_key(trans, iter, BTREE_ID_snapshots,
|
for_each_btree_key(trans, iter, BTREE_ID_snapshots,
|
||||||
POS_MIN, 0, k,
|
POS_MIN, 0, k,
|
||||||
bch2_mark_snapshot(trans, BTREE_ID_snapshots, 0, bkey_s_c_null, k, 0) ?:
|
__bch2_mark_snapshot(trans, BTREE_ID_snapshots, 0, bkey_s_c_null, k, 0) ?:
|
||||||
bch2_snapshot_set_equiv(trans, k) ?:
|
bch2_snapshot_set_equiv(trans, k) ?:
|
||||||
bch2_check_snapshot_needs_deletion(trans, k)) ?:
|
bch2_check_snapshot_needs_deletion(trans, k)) ?:
|
||||||
for_each_btree_key(trans, iter, BTREE_ID_snapshots,
|
for_each_btree_key(trans, iter, BTREE_ID_snapshots,
|
||||||
|
@ -22,7 +22,7 @@ void bch2_snapshot_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
|
|||||||
int bch2_snapshot_invalid(struct bch_fs *, struct bkey_s_c,
|
int bch2_snapshot_invalid(struct bch_fs *, struct bkey_s_c,
|
||||||
enum bkey_invalid_flags, struct printbuf *);
|
enum bkey_invalid_flags, struct printbuf *);
|
||||||
int bch2_mark_snapshot(struct btree_trans *, enum btree_id, unsigned,
|
int bch2_mark_snapshot(struct btree_trans *, enum btree_id, unsigned,
|
||||||
struct bkey_s_c, struct bkey_s_c, unsigned);
|
struct bkey_s_c, struct bkey_s, unsigned);
|
||||||
|
|
||||||
#define bch2_bkey_ops_snapshot ((struct bkey_ops) { \
|
#define bch2_bkey_ops_snapshot ((struct bkey_ops) { \
|
||||||
.key_invalid = bch2_snapshot_invalid, \
|
.key_invalid = bch2_snapshot_invalid, \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user