bcachefs: btree_update_nodes_written() requires alloc reserve
authorKent Overstreet <kent.overstreet@gmail.com>
Tue, 9 Jun 2020 19:59:03 +0000 (15:59 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:08:40 +0000 (17:08 -0400)
Also, in the btree_update_start() path, if we already have a journal
pre-reservation we don't want to take another - that's a deadlock.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/btree_update_interior.c

index 7d63c457a3bf4a3a51a8ac30d604a4e9835a47ea..4f244f983f3517118954238d80678622ce338524 100644 (file)
@@ -529,6 +529,8 @@ static void btree_update_nodes_written(struct btree_update *as)
         */
        ret = bch2_trans_do(c, &as->disk_res, &journal_seq,
                            BTREE_INSERT_NOFAIL|
+                           BTREE_INSERT_USE_RESERVE|
+                           BTREE_INSERT_USE_ALLOC_RESERVE|
                            BTREE_INSERT_NOCHECK_RW|
                            BTREE_INSERT_JOURNAL_RESERVED,
                            btree_update_nodes_written_trans(&trans, as));
@@ -886,9 +888,10 @@ bch2_btree_update_start(struct btree_trans *trans, enum btree_id id,
        bch2_keylist_init(&as->new_keys, as->_new_keys);
        bch2_keylist_init(&as->parent_keys, as->inline_keys);
 
-       ret = bch2_journal_preres_get(&c->journal, &as->journal_preres,
-                                     BTREE_UPDATE_JOURNAL_RES,
-                                     JOURNAL_RES_GET_NONBLOCK);
+       if (!(flags & BTREE_INSERT_JOURNAL_RESERVED))
+               ret = bch2_journal_preres_get(&c->journal, &as->journal_preres,
+                                             BTREE_UPDATE_JOURNAL_RES,
+                                             JOURNAL_RES_GET_NONBLOCK);
        if (ret == -EAGAIN) {
                if (flags & BTREE_INSERT_NOUNLOCK)
                        return ERR_PTR(-EINTR);