]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/btree_cache.c
Update bcachefs sources to 6d44812757dd bcachefs: BCH_IOCTL_FSCK_ONLINE
[bcachefs-tools-debian] / libbcachefs / btree_cache.c
index 47e7770d05831757d45c4aee9331f52a10c06e76..9574c8c4d70864b8617df8d68dff6d8e47bdf855 100644 (file)
@@ -9,6 +9,7 @@
 #include "debug.h"
 #include "errcode.h"
 #include "error.h"
+#include "journal.h"
 #include "trace.h"
 
 #include <linux/prefetch.h>
@@ -424,14 +425,11 @@ void bch2_fs_btree_cache_exit(struct bch_fs *c)
                BUG_ON(btree_node_read_in_flight(b) ||
                       btree_node_write_in_flight(b));
 
-               if (btree_node_dirty(b))
-                       bch2_btree_complete_write(c, b, btree_current_write(b));
-               clear_btree_node_dirty_acct(c, b);
-
                btree_node_data_free(c, b);
        }
 
-       BUG_ON(atomic_read(&c->btree_cache.dirty));
+       BUG_ON(!bch2_journal_error(&c->journal) &&
+              atomic_read(&c->btree_cache.dirty));
 
        list_splice(&bc->freed_pcpu, &bc->freed_nonpcpu);
 
@@ -502,19 +500,21 @@ void bch2_fs_btree_cache_init_early(struct btree_cache *bc)
  * cannibalize_bucket() will take. This means every time we unlock the root of
  * the btree, we need to release this lock if we have it held.
  */
-void bch2_btree_cache_cannibalize_unlock(struct bch_fs *c)
+void bch2_btree_cache_cannibalize_unlock(struct btree_trans *trans)
 {
+       struct bch_fs *c = trans->c;
        struct btree_cache *bc = &c->btree_cache;
 
        if (bc->alloc_lock == current) {
-               trace_and_count(c, btree_cache_cannibalize_unlock, c);
+               trace_and_count(c, btree_cache_cannibalize_unlock, trans);
                bc->alloc_lock = NULL;
                closure_wake_up(&bc->alloc_wait);
        }
 }
 
-int bch2_btree_cache_cannibalize_lock(struct bch_fs *c, struct closure *cl)
+int bch2_btree_cache_cannibalize_lock(struct btree_trans *trans, struct closure *cl)
 {
+       struct bch_fs *c = trans->c;
        struct btree_cache *bc = &c->btree_cache;
        struct task_struct *old;
 
@@ -523,7 +523,7 @@ int bch2_btree_cache_cannibalize_lock(struct bch_fs *c, struct closure *cl)
                goto success;
 
        if (!cl) {
-               trace_and_count(c, btree_cache_cannibalize_lock_fail, c);
+               trace_and_count(c, btree_cache_cannibalize_lock_fail, trans);
                return -BCH_ERR_ENOMEM_btree_cache_cannibalize_lock;
        }
 
@@ -537,11 +537,11 @@ int bch2_btree_cache_cannibalize_lock(struct bch_fs *c, struct closure *cl)
                goto success;
        }
 
-       trace_and_count(c, btree_cache_cannibalize_lock_fail, c);
+       trace_and_count(c, btree_cache_cannibalize_lock_fail, trans);
        return -BCH_ERR_btree_cache_cannibalize_lock_blocked;
 
 success:
-       trace_and_count(c, btree_cache_cannibalize_lock, c);
+       trace_and_count(c, btree_cache_cannibalize_lock, trans);
        return 0;
 }
 
@@ -675,7 +675,7 @@ err:
 
                mutex_unlock(&bc->lock);
 
-               trace_and_count(c, btree_cache_cannibalize, c);
+               trace_and_count(c, btree_cache_cannibalize, trans);
                goto out;
        }
 
@@ -751,7 +751,7 @@ static noinline struct btree *bch2_btree_node_fill(struct btree_trans *trans,
        if (path && sync)
                bch2_trans_unlock_noassert(trans);
 
-       bch2_btree_node_read(c, b, sync);
+       bch2_btree_node_read(trans, b, sync);
 
        if (!sync)
                return NULL;
@@ -1041,7 +1041,7 @@ retry:
                        goto retry;
 
                if (IS_ERR(b) &&
-                   !bch2_btree_cache_cannibalize_lock(c, NULL))
+                   !bch2_btree_cache_cannibalize_lock(trans, NULL))
                        goto retry;
 
                if (IS_ERR(b))
@@ -1089,7 +1089,7 @@ lock_node:
        EBUG_ON(BTREE_NODE_LEVEL(b->data) != level);
        btree_check_header(c, b);
 out:
-       bch2_btree_cache_cannibalize_unlock(c);
+       bch2_btree_cache_cannibalize_unlock(trans);
        return b;
 }