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

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2020-05-25 19:29:48 -04:00 committed by Kent Overstreet
parent b29303966b
commit 96e2aa1be5
4 changed files with 25 additions and 4 deletions

View file

@ -2153,6 +2153,9 @@ void bch2_trans_reset(struct btree_trans *trans, unsigned flags)
trans->nr_updates2 = 0;
trans->mem_top = 0;
trans->extra_journal_entries = NULL;
trans->extra_journal_entry_u64s = 0;
if (trans->fs_usage_deltas) {
trans->fs_usage_deltas->used = 0;
memset((void *) trans->fs_usage_deltas +

View file

@ -308,6 +308,9 @@ struct btree_trans {
struct btree_insert_entry *updates2;
/* update path: */
struct jset_entry *extra_journal_entries;
unsigned extra_journal_entry_u64s;
struct journal_res journal_res;
struct journal_preres journal_preres;
u64 *journal_seq;

View file

@ -413,6 +413,16 @@ bch2_trans_commit_write_locked(struct btree_trans *trans,
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
* have to use it:
@ -800,7 +810,7 @@ int __bch2_trans_commit(struct btree_trans *trans)
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;
if (!(trans->flags & BTREE_INSERT_NOCHECK_RW) &&

View file

@ -199,13 +199,18 @@ bch2_journal_add_entry_noreservation(struct journal_buf *buf, size_t u64s)
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,
unsigned type, enum btree_id id,
unsigned level,
const void *data, unsigned u64s)
{
struct journal_buf *buf = &j->buf[res->idx];
struct jset_entry *entry = vstruct_idx(buf->data, res->offset);
struct jset_entry *entry = bch2_journal_reservation_entry(j, res);
unsigned actual = jset_u64s(u64s);
EBUG_ON(!res->ref);
@ -221,7 +226,7 @@ static inline void bch2_journal_add_entry(struct journal *j, struct journal_res
entry->pad[0] = 0;
entry->pad[1] = 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,