bcachefs: Add a mechanism for running callbacks at trans commit time
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
331194a230
commit
43d002432d
@ -2144,6 +2144,7 @@ void bch2_trans_reset(struct btree_trans *trans, unsigned flags)
|
||||
trans->nr_updates2 = 0;
|
||||
trans->mem_top = 0;
|
||||
|
||||
trans->hooks = NULL;
|
||||
trans->extra_journal_entries = NULL;
|
||||
trans->extra_journal_entry_u64s = 0;
|
||||
|
||||
|
@ -343,6 +343,14 @@ struct btree_insert_entry {
|
||||
#define BTREE_ITER_MAX 32
|
||||
#endif
|
||||
|
||||
struct btree_trans_commit_hook;
|
||||
typedef int (btree_trans_commit_hook_fn)(struct btree_trans *, struct btree_trans_commit_hook *);
|
||||
|
||||
struct btree_trans_commit_hook {
|
||||
btree_trans_commit_hook_fn *fn;
|
||||
struct btree_trans_commit_hook *next;
|
||||
};
|
||||
|
||||
#define BTREE_TRANS_MEM_MAX (1U << 14)
|
||||
|
||||
struct btree_trans {
|
||||
@ -379,6 +387,7 @@ struct btree_trans {
|
||||
struct btree_insert_entry *updates2;
|
||||
|
||||
/* update path: */
|
||||
struct btree_trans_commit_hook *hooks;
|
||||
struct jset_entry *extra_journal_entries;
|
||||
unsigned extra_journal_entry_u64s;
|
||||
struct journal_entry_pin *journal_pin;
|
||||
|
@ -77,6 +77,8 @@ int bch2_btree_node_update_key(struct bch_fs *, struct btree_iter *,
|
||||
|
||||
int bch2_trans_update(struct btree_trans *, struct btree_iter *,
|
||||
struct bkey_i *, enum btree_trigger_flags);
|
||||
void bch2_trans_commit_hook(struct btree_trans *,
|
||||
struct btree_trans_commit_hook *);
|
||||
int __bch2_trans_commit(struct btree_trans *);
|
||||
|
||||
/**
|
||||
|
@ -369,6 +369,7 @@ bch2_trans_commit_write_locked(struct btree_trans *trans,
|
||||
struct bch_fs *c = trans->c;
|
||||
struct bch_fs_usage_online *fs_usage = NULL;
|
||||
struct btree_insert_entry *i;
|
||||
struct btree_trans_commit_hook *h;
|
||||
unsigned u64s = 0;
|
||||
bool marking = false;
|
||||
int ret;
|
||||
@ -386,6 +387,14 @@ bch2_trans_commit_write_locked(struct btree_trans *trans,
|
||||
|
||||
prefetch(&trans->c->journal.flags);
|
||||
|
||||
h = trans->hooks;
|
||||
while (h) {
|
||||
ret = h->fn(trans, h);
|
||||
if (ret)
|
||||
return ret;
|
||||
h = h->next;
|
||||
}
|
||||
|
||||
trans_for_each_update2(trans, i) {
|
||||
/* Multiple inserts might go to same leaf: */
|
||||
if (!same_leaf_as_prev(trans, i))
|
||||
@ -1057,6 +1066,13 @@ int bch2_trans_update(struct btree_trans *trans, struct btree_iter *iter,
|
||||
return 0;
|
||||
}
|
||||
|
||||
void bch2_trans_commit_hook(struct btree_trans *trans,
|
||||
struct btree_trans_commit_hook *h)
|
||||
{
|
||||
h->next = trans->hooks;
|
||||
trans->hooks = h;
|
||||
}
|
||||
|
||||
int __bch2_btree_insert(struct btree_trans *trans,
|
||||
enum btree_id id, struct bkey_i *k)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user