summaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2021-04-03 19:27:05 -0400
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-22 17:08:58 -0400
commit6167f7c8ff5ce564423fe8b416b5f95d1712859b (patch)
treefa4e4542b6a9c8d9448204801403db1779bb18d2 /fs
parentb753d4b338df70df1ee75db21a216385bb88b90b (diff)
downloadlwn-6167f7c8ff5ce564423fe8b416b5f95d1712859b.tar.gz
lwn-6167f7c8ff5ce564423fe8b416b5f95d1712859b.zip
bcachefs: Fix journal deadlock
After we get a journal reservation, we need to use it - if we erorr out of a transaction commit, we'll be eating into space in the journal and if our transaction needs to make forward progress in order to reclaim space in the journal, we'll deadlock. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs')
-rw-r--r--fs/bcachefs/btree_update_leaf.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/fs/bcachefs/btree_update_leaf.c b/fs/bcachefs/btree_update_leaf.c
index 592f9516d4e7..d3d86aa0ee95 100644
--- a/fs/bcachefs/btree_update_leaf.c
+++ b/fs/bcachefs/btree_update_leaf.c
@@ -426,6 +426,14 @@ bch2_trans_commit_write_locked(struct btree_trans *trans,
fs_usage = bch2_fs_usage_scratch_get(c);
}
+ /* Must be called under mark_lock: */
+ if (marking && trans->fs_usage_deltas &&
+ bch2_replicas_delta_list_apply(c, &fs_usage->u,
+ trans->fs_usage_deltas)) {
+ ret = BTREE_INSERT_NEED_MARK_REPLICAS;
+ goto err;
+ }
+
/*
* Don't get journal reservation until after we know insert will
* succeed:
@@ -462,14 +470,6 @@ bch2_trans_commit_write_locked(struct btree_trans *trans,
i->k->k.version = MAX_VERSION;
}
- /* Must be called under mark_lock: */
- if (marking && trans->fs_usage_deltas &&
- bch2_replicas_delta_list_apply(c, &fs_usage->u,
- trans->fs_usage_deltas)) {
- ret = BTREE_INSERT_NEED_MARK_REPLICAS;
- goto err;
- }
-
trans_for_each_update(trans, i)
if (BTREE_NODE_TYPE_HAS_MEM_TRIGGERS & (1U << i->bkey_type))
bch2_mark_update(trans, i->iter, i->k,