Commit 96e2aa1b authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Add a mechanism for passing extra journal entries to bch2_trans_commit()

Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent b2930396
...@@ -2153,6 +2153,9 @@ void bch2_trans_reset(struct btree_trans *trans, unsigned flags) ...@@ -2153,6 +2153,9 @@ 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->extra_journal_entries = NULL;
trans->extra_journal_entry_u64s = 0;
if (trans->fs_usage_deltas) { if (trans->fs_usage_deltas) {
trans->fs_usage_deltas->used = 0; trans->fs_usage_deltas->used = 0;
memset((void *) trans->fs_usage_deltas + memset((void *) trans->fs_usage_deltas +
......
...@@ -308,6 +308,9 @@ struct btree_trans { ...@@ -308,6 +308,9 @@ struct btree_trans {
struct btree_insert_entry *updates2; struct btree_insert_entry *updates2;
/* update path: */ /* update path: */
struct jset_entry *extra_journal_entries;
unsigned extra_journal_entry_u64s;
struct journal_res journal_res; struct journal_res journal_res;
struct journal_preres journal_preres; struct journal_preres journal_preres;
u64 *journal_seq; u64 *journal_seq;
......
...@@ -413,6 +413,16 @@ bch2_trans_commit_write_locked(struct btree_trans *trans, ...@@ -413,6 +413,16 @@ bch2_trans_commit_write_locked(struct btree_trans *trans,
goto err; goto err;
} }
if (unlikely(trans->extra_journal_entry_u64s)) {
memcpy_u64s_small(bch2_journal_reservation_entry(&c->journal,
&trans->journal_res),
trans->extra_journal_entries,
trans->extra_journal_entry_u64s);
trans->journal_res.offset += trans->extra_journal_entry_u64s;
trans->journal_res.u64s -= trans->extra_journal_entry_u64s;
}
/* /*
* Not allowed to fail after we've gotten our journal reservation - we * Not allowed to fail after we've gotten our journal reservation - we
* have to use it: * have to use it:
...@@ -800,7 +810,7 @@ int __bch2_trans_commit(struct btree_trans *trans) ...@@ -800,7 +810,7 @@ int __bch2_trans_commit(struct btree_trans *trans)
memset(&trans->journal_preres, 0, sizeof(trans->journal_preres)); memset(&trans->journal_preres, 0, sizeof(trans->journal_preres));
trans->journal_u64s = 0; trans->journal_u64s = trans->extra_journal_entry_u64s;
trans->journal_preres_u64s = 0; trans->journal_preres_u64s = 0;
if (!(trans->flags & BTREE_INSERT_NOCHECK_RW) && if (!(trans->flags & BTREE_INSERT_NOCHECK_RW) &&
......
...@@ -199,13 +199,18 @@ bch2_journal_add_entry_noreservation(struct journal_buf *buf, size_t u64s) ...@@ -199,13 +199,18 @@ bch2_journal_add_entry_noreservation(struct journal_buf *buf, size_t u64s)
return entry; return entry;
} }
static inline struct jset_entry *
bch2_journal_reservation_entry(struct journal *j, struct journal_res *res)
{
return vstruct_idx(j->buf[res->idx].data, res->offset);
}
static inline void bch2_journal_add_entry(struct journal *j, struct journal_res *res, static inline void bch2_journal_add_entry(struct journal *j, struct journal_res *res,
unsigned type, enum btree_id id, unsigned type, enum btree_id id,
unsigned level, unsigned level,
const void *data, unsigned u64s) const void *data, unsigned u64s)
{ {
struct journal_buf *buf = &j->buf[res->idx]; struct jset_entry *entry = bch2_journal_reservation_entry(j, res);
struct jset_entry *entry = vstruct_idx(buf->data, res->offset);
unsigned actual = jset_u64s(u64s); unsigned actual = jset_u64s(u64s);
EBUG_ON(!res->ref); EBUG_ON(!res->ref);
...@@ -221,7 +226,7 @@ static inline void bch2_journal_add_entry(struct journal *j, struct journal_res ...@@ -221,7 +226,7 @@ static inline void bch2_journal_add_entry(struct journal *j, struct journal_res
entry->pad[0] = 0; entry->pad[0] = 0;
entry->pad[1] = 0; entry->pad[1] = 0;
entry->pad[2] = 0; entry->pad[2] = 0;
memcpy_u64s(entry->_data, data, u64s); memcpy_u64s_small(entry->_data, data, u64s);
} }
static inline void bch2_journal_add_keys(struct journal *j, struct journal_res *res, static inline void bch2_journal_add_keys(struct journal *j, struct journal_res *res,
......
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