Commit 43d00243 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Add a mechanism for running callbacks at trans commit time

Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 331194a2
...@@ -2144,6 +2144,7 @@ void bch2_trans_reset(struct btree_trans *trans, unsigned flags) ...@@ -2144,6 +2144,7 @@ void bch2_trans_reset(struct btree_trans *trans, unsigned flags)
trans->nr_updates2 = 0; trans->nr_updates2 = 0;
trans->mem_top = 0; trans->mem_top = 0;
trans->hooks = NULL;
trans->extra_journal_entries = NULL; trans->extra_journal_entries = NULL;
trans->extra_journal_entry_u64s = 0; trans->extra_journal_entry_u64s = 0;
......
...@@ -343,6 +343,14 @@ struct btree_insert_entry { ...@@ -343,6 +343,14 @@ struct btree_insert_entry {
#define BTREE_ITER_MAX 32 #define BTREE_ITER_MAX 32
#endif #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) #define BTREE_TRANS_MEM_MAX (1U << 14)
struct btree_trans { struct btree_trans {
...@@ -379,6 +387,7 @@ struct btree_trans { ...@@ -379,6 +387,7 @@ struct btree_trans {
struct btree_insert_entry *updates2; struct btree_insert_entry *updates2;
/* update path: */ /* update path: */
struct btree_trans_commit_hook *hooks;
struct jset_entry *extra_journal_entries; struct jset_entry *extra_journal_entries;
unsigned extra_journal_entry_u64s; unsigned extra_journal_entry_u64s;
struct journal_entry_pin *journal_pin; struct journal_entry_pin *journal_pin;
......
...@@ -77,6 +77,8 @@ int bch2_btree_node_update_key(struct bch_fs *, struct btree_iter *, ...@@ -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 *, int bch2_trans_update(struct btree_trans *, struct btree_iter *,
struct bkey_i *, enum btree_trigger_flags); 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 *); int __bch2_trans_commit(struct btree_trans *);
/** /**
......
...@@ -369,6 +369,7 @@ bch2_trans_commit_write_locked(struct btree_trans *trans, ...@@ -369,6 +369,7 @@ bch2_trans_commit_write_locked(struct btree_trans *trans,
struct bch_fs *c = trans->c; struct bch_fs *c = trans->c;
struct bch_fs_usage_online *fs_usage = NULL; struct bch_fs_usage_online *fs_usage = NULL;
struct btree_insert_entry *i; struct btree_insert_entry *i;
struct btree_trans_commit_hook *h;
unsigned u64s = 0; unsigned u64s = 0;
bool marking = false; bool marking = false;
int ret; int ret;
...@@ -386,6 +387,14 @@ bch2_trans_commit_write_locked(struct btree_trans *trans, ...@@ -386,6 +387,14 @@ bch2_trans_commit_write_locked(struct btree_trans *trans,
prefetch(&trans->c->journal.flags); 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) { trans_for_each_update2(trans, i) {
/* Multiple inserts might go to same leaf: */ /* Multiple inserts might go to same leaf: */
if (!same_leaf_as_prev(trans, i)) if (!same_leaf_as_prev(trans, i))
...@@ -1057,6 +1066,13 @@ int bch2_trans_update(struct btree_trans *trans, struct btree_iter *iter, ...@@ -1057,6 +1066,13 @@ int bch2_trans_update(struct btree_trans *trans, struct btree_iter *iter,
return 0; 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, int __bch2_btree_insert(struct btree_trans *trans,
enum btree_id id, struct bkey_i *k) enum btree_id id, struct bkey_i *k)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment