From 00b8ccf7074fddb5607a26673f331ceac2ecd319 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Mon, 25 May 2020 14:57:06 -0400 Subject: bcachefs: Interior btree updates are now fully transactional We now update the alloc info (bucket sector counts) atomically with journalling the update to the interior btree nodes, and we also set new btree roots atomically with the journalled part of the btree update. Signed-off-by: Kent Overstreet Signed-off-by: Kent Overstreet --- fs/bcachefs/journal.h | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'fs/bcachefs/journal.h') diff --git a/fs/bcachefs/journal.h b/fs/bcachefs/journal.h index 6630db6ecc14..2c55f74522e2 100644 --- a/fs/bcachefs/journal.h +++ b/fs/bcachefs/journal.h @@ -200,33 +200,40 @@ bch2_journal_add_entry_noreservation(struct journal_buf *buf, size_t u64s) } static inline struct jset_entry * -bch2_journal_reservation_entry(struct journal *j, struct journal_res *res) +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, + enum btree_id id, unsigned level, + const void *data, unsigned u64s) +{ + entry->u64s = cpu_to_le16(u64s); + entry->btree_id = id; + entry->level = level; + entry->type = 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, const void *data, unsigned u64s) { - struct jset_entry *entry = bch2_journal_reservation_entry(j, res); - unsigned actual = jset_u64s(u64s); + unsigned actual = journal_entry_set(journal_res_entry(j, res), + type, id, level, data, u64s); EBUG_ON(!res->ref); EBUG_ON(actual > res->u64s); res->offset += actual; res->u64s -= actual; - - entry->u64s = cpu_to_le16(u64s); - entry->btree_id = id; - entry->level = level; - entry->type = type; - entry->pad[0] = 0; - entry->pad[1] = 0; - entry->pad[2] = 0; - memcpy_u64s_small(entry->_data, data, u64s); } static inline void bch2_journal_add_keys(struct journal *j, struct journal_res *res, -- cgit v1.2.3