Skip to content

Commit a3581ca

Browse files
author
Kent Overstreet
committed
bcachefs: Fix BCH_TRANS_COMMIT_skip_accounting_apply
This was added to avoid double-counting accounting keys in journal replay. But applied incorrectly (easily done since it applies to the transaction commit, not a particular update), it leads to skipping in-mem accounting for real accounting updates, and failure to give them a version number - which leads to journal replay becoming very confused the next time around. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent f8911ad commit a3581ca

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

fs/bcachefs/btree_trans_commit.c

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -700,27 +700,31 @@ bch2_trans_commit_write_locked(struct btree_trans *trans, unsigned flags,
700700

701701
struct jset_entry *entry = trans->journal_entries;
702702

703-
if (likely(!(flags & BCH_TRANS_COMMIT_skip_accounting_apply))) {
704-
percpu_down_read(&c->mark_lock);
705-
706-
for (entry = trans->journal_entries;
707-
entry != (void *) ((u64 *) trans->journal_entries + trans->journal_entries_u64s);
708-
entry = vstruct_next(entry))
709-
if (jset_entry_is_key(entry) && entry->start->k.type == KEY_TYPE_accounting) {
710-
struct bkey_i_accounting *a = bkey_i_to_accounting(entry->start);
711-
712-
a->k.bversion = journal_pos_to_bversion(&trans->journal_res,
713-
(u64 *) entry - (u64 *) trans->journal_entries);
714-
BUG_ON(bversion_zero(a->k.bversion));
703+
percpu_down_read(&c->mark_lock);
704+
705+
for (entry = trans->journal_entries;
706+
entry != (void *) ((u64 *) trans->journal_entries + trans->journal_entries_u64s);
707+
entry = vstruct_next(entry))
708+
if (entry->type == BCH_JSET_ENTRY_write_buffer_keys &&
709+
entry->start->k.type == KEY_TYPE_accounting) {
710+
BUG_ON(!trans->journal_res.ref);
711+
712+
struct bkey_i_accounting *a = bkey_i_to_accounting(entry->start);
713+
714+
a->k.bversion = journal_pos_to_bversion(&trans->journal_res,
715+
(u64 *) entry - (u64 *) trans->journal_entries);
716+
BUG_ON(bversion_zero(a->k.bversion));
717+
718+
if (likely(!(flags & BCH_TRANS_COMMIT_skip_accounting_apply))) {
715719
ret = bch2_accounting_mem_mod_locked(trans, accounting_i_to_s_c(a), BCH_ACCOUNTING_normal);
716720
if (ret)
717721
goto revert_fs_usage;
718722
}
719-
percpu_up_read(&c->mark_lock);
723+
}
724+
percpu_up_read(&c->mark_lock);
720725

721-
/* XXX: we only want to run this if deltas are nonzero */
722-
bch2_trans_account_disk_usage_change(trans);
723-
}
726+
/* XXX: we only want to run this if deltas are nonzero */
727+
bch2_trans_account_disk_usage_change(trans);
724728

725729
trans_for_each_update(trans, i)
726730
if (btree_node_type_has_atomic_triggers(i->bkey_type)) {

0 commit comments

Comments
 (0)