bcachefs: Refactor journal entry adding

This takes copying the payload out of bch2_journal_add_entry(), which
means we can use it for journal_transaction_name() - also prep work for
journalling overwrites.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
This commit is contained in:
Kent Overstreet 2022-06-05 15:29:00 -04:00 committed by Kent Overstreet
parent 4a7a7ea1f5
commit 43ddf44834
2 changed files with 35 additions and 41 deletions

View File

@ -309,25 +309,15 @@ static inline int bch2_trans_journal_res_get(struct btree_trans *trans,
static noinline void journal_transaction_name(struct btree_trans *trans)
{
struct bch_fs *c = trans->c;
struct jset_entry *entry = journal_res_entry(&c->journal, &trans->journal_res);
struct jset_entry_log *l = container_of(entry, struct jset_entry_log, entry);
unsigned u64s = JSET_ENTRY_LOG_U64s - 1;
unsigned b, buflen = u64s * sizeof(u64);
struct journal *j = &c->journal;
struct jset_entry *entry =
bch2_journal_add_entry(j, &trans->journal_res,
BCH_JSET_ENTRY_log, 0, 0,
JSET_ENTRY_LOG_U64s);
struct jset_entry_log *l =
container_of(entry, struct jset_entry_log, entry);
l->entry.u64s = cpu_to_le16(u64s);
l->entry.btree_id = 0;
l->entry.level = 0;
l->entry.type = BCH_JSET_ENTRY_log;
l->entry.pad[0] = 0;
l->entry.pad[1] = 0;
l->entry.pad[2] = 0;
b = min_t(unsigned, strlen(trans->fn), buflen);
memcpy(l->d, trans->fn, b);
while (b < buflen)
l->d[b++] = '\0';
trans->journal_res.offset += JSET_ENTRY_LOG_U64s;
trans->journal_res.u64s -= JSET_ENTRY_LOG_U64s;
strncpy(l->d, trans->fn, JSET_ENTRY_LOG_U64s * sizeof(u64));
}
static inline enum btree_insert_ret
@ -416,10 +406,13 @@ static inline void do_btree_insert_one(struct btree_trans *trans,
if (likely(!(trans->flags & BTREE_INSERT_JOURNAL_REPLAY)) &&
!(i->flags & BTREE_UPDATE_NOJOURNAL)) {
bch2_journal_add_keys(j, &trans->journal_res,
i->btree_id,
i->level,
i->k);
struct jset_entry *entry;
entry = bch2_journal_add_entry(j, &trans->journal_res,
BCH_JSET_ENTRY_btree_keys,
i->btree_id, i->level,
i->k->k.u64s);
bkey_copy(&entry->start[0], i->k);
if (trans->journal_seq)
*trans->journal_seq = trans->journal_res.seq;
@ -1127,7 +1120,7 @@ int __bch2_trans_commit(struct btree_trans *trans)
trans->journal_transaction_names = READ_ONCE(c->opts.journal_transaction_names);
if (trans->journal_transaction_names)
trans->journal_u64s += JSET_ENTRY_LOG_U64s;
trans->journal_u64s += jset_u64s(JSET_ENTRY_LOG_U64s);
trans_for_each_update(trans, i) {
BUG_ON(!i->path->should_be_locked);

View File

@ -199,9 +199,9 @@ journal_res_entry(struct journal *j, struct journal_res *res)
return vstruct_idx(j->buf[res->idx].data, res->offset);
}
static inline unsigned journal_entry_set(struct jset_entry *entry, unsigned type,
static inline unsigned journal_entry_init(struct jset_entry *entry, unsigned type,
enum btree_id id, unsigned level,
const void *data, unsigned u64s)
unsigned u64s)
{
entry->u64s = cpu_to_le16(u64s);
entry->btree_id = id;
@ -210,32 +210,33 @@ static inline unsigned journal_entry_set(struct jset_entry *entry, unsigned type
entry->pad[0] = 0;
entry->pad[1] = 0;
entry->pad[2] = 0;
memcpy_u64s_small(entry->_data, data, u64s);
return jset_u64s(u64s);
}
static inline void bch2_journal_add_entry(struct journal *j, struct journal_res *res,
unsigned type, enum btree_id id,
unsigned level,
static inline unsigned journal_entry_set(struct jset_entry *entry, unsigned type,
enum btree_id id, unsigned level,
const void *data, unsigned u64s)
{
unsigned actual = journal_entry_set(journal_res_entry(j, res),
type, id, level, data, u64s);
unsigned ret = journal_entry_init(entry, type, id, level, u64s);
memcpy_u64s_small(entry->_data, data, u64s);
return ret;
}
static inline struct jset_entry *
bch2_journal_add_entry(struct journal *j, struct journal_res *res,
unsigned type, enum btree_id id,
unsigned level, unsigned u64s)
{
struct jset_entry *entry = journal_res_entry(j, res);
unsigned actual = journal_entry_init(entry, type, id, level, u64s);
EBUG_ON(!res->ref);
EBUG_ON(actual > res->u64s);
res->offset += actual;
res->u64s -= actual;
}
static inline void bch2_journal_add_keys(struct journal *j, struct journal_res *res,
enum btree_id id, unsigned level,
const struct bkey_i *k)
{
bch2_journal_add_entry(j, res, BCH_JSET_ENTRY_btree_keys,
id, level, k, k->k.u64s);
return entry;
}
static inline bool journal_entry_empty(struct jset *j)
@ -283,7 +284,7 @@ static inline void bch2_journal_res_put(struct journal *j,
while (res->u64s)
bch2_journal_add_entry(j, res,
BCH_JSET_ENTRY_btree_keys,
0, 0, NULL, 0);
0, 0, 0);
bch2_journal_buf_put(j, res->idx);