]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/btree_trans_commit.c
Update bcachefs sources to 1336a995cbc3 bcachefs: Silence transaction restart error...
[bcachefs-tools-debian] / libbcachefs / btree_trans_commit.c
index 83cc7f64c57c9841ed1b288a57f0c271adb3428d..04c1f4610972599686c18ada9591a1f83dbd1557 100644 (file)
@@ -97,6 +97,7 @@ bool bch2_btree_bset_insert_key(struct btree_trans *trans,
        EBUG_ON(bpos_gt(insert->k.p, b->data->max_key));
        EBUG_ON(insert->k.u64s >
                bch_btree_keys_u64s_remaining(trans->c, b));
+       EBUG_ON(!b->c.level && !bpos_eq(insert->k.p, path->pos));
 
        k = bch2_btree_node_iter_peek_all(node_iter, b);
        if (k && bkey_cmp_left_packed(b, k, &insert->k.p))
@@ -162,13 +163,11 @@ static int __btree_node_flush(struct journal *j, struct journal_entry_pin *pin,
        struct bch_fs *c = container_of(j, struct bch_fs, journal);
        struct btree_write *w = container_of(pin, struct btree_write, journal);
        struct btree *b = container_of(w, struct btree, writes[i]);
-       struct btree_trans trans;
+       struct btree_trans *trans = bch2_trans_get(c);
        unsigned long old, new, v;
        unsigned idx = w - b->writes;
 
-       bch2_trans_init(&trans, c, 0, 0);
-
-       btree_node_lock_nopath_nofail(&trans, &b->c, SIX_LOCK_read);
+       btree_node_lock_nopath_nofail(trans, &b->c, SIX_LOCK_read);
        v = READ_ONCE(b->flags);
 
        do {
@@ -187,7 +186,7 @@ static int __btree_node_flush(struct journal *j, struct journal_entry_pin *pin,
        btree_node_write_if_need(c, b, SIX_LOCK_read);
        six_unlock_read(&b->c.lock);
 
-       bch2_trans_exit(&trans);
+       bch2_trans_put(trans);
        return 0;
 }
 
@@ -213,7 +212,11 @@ inline void bch2_btree_add_journal_pin(struct bch_fs *c,
 }
 
 /**
- * btree_insert_key - insert a key one key into a leaf node
+ * bch2_btree_insert_key_leaf() - insert a key one key into a leaf node
+ * @trans:             btree transaction object
+ * @path:              path pointing to @insert's pos
+ * @insert:            key to insert
+ * @journal_seq:       sequence number of journal reservation
  */
 inline void bch2_btree_insert_key_leaf(struct btree_trans *trans,
                                       struct btree_path *path,
@@ -554,7 +557,6 @@ bch2_trans_commit_write_locked(struct btree_trans *trans, unsigned flags,
        struct btree_write_buffered_key *wb;
        struct btree_trans_commit_hook *h;
        unsigned u64s = 0;
-       bool marking = false;
        int ret;
 
        if (race_fault()) {
@@ -583,9 +585,6 @@ bch2_trans_commit_write_locked(struct btree_trans *trans, unsigned flags,
                        *stopped_at = i;
                        return ret;
                }
-
-               if (btree_node_type_needs_gc(i->bkey_type))
-                       marking = true;
        }
 
        if (trans->nr_wb_updates &&
@@ -777,7 +776,6 @@ static noinline void bch2_drop_overwrites_from_journal(struct btree_trans *trans
                bch2_journal_key_overwritten(trans->c, wb->btree, 0, wb->k.k.p);
 }
 
-#ifdef CONFIG_BCACHEFS_DEBUG
 static noinline int bch2_trans_commit_bkey_invalid(struct btree_trans *trans, unsigned flags,
                                                   struct btree_insert_entry *i,
                                                   struct printbuf *err)
@@ -800,11 +798,9 @@ static noinline int bch2_trans_commit_bkey_invalid(struct btree_trans *trans, un
 
        bch2_inconsistent_error(c);
        bch2_dump_trans_updates(trans);
-       printbuf_exit(err);
 
        return -EINVAL;
 }
-#endif
 
 /*
  * Get journal reservation, take write locks, and attempt to do btree update(s):
@@ -817,25 +813,6 @@ static inline int do_bch2_trans_commit(struct btree_trans *trans, unsigned flags
        struct btree_insert_entry *i;
        int ret = 0, u64s_delta = 0;
 
-#ifdef CONFIG_BCACHEFS_DEBUG
-       trans_for_each_update(trans, i) {
-               struct printbuf buf = PRINTBUF;
-               enum bkey_invalid_flags invalid_flags = 0;
-
-               if (!(flags & BTREE_INSERT_JOURNAL_REPLAY))
-                       invalid_flags |= BKEY_INVALID_WRITE|BKEY_INVALID_COMMIT;
-
-               if (unlikely(bch2_bkey_invalid(c, bkey_i_to_s_c(i->k),
-                                              i->bkey_type, invalid_flags, &buf)))
-                       ret = bch2_trans_commit_bkey_invalid(trans, flags, i, &buf);
-               btree_insert_entry_checks(trans, i);
-               printbuf_exit(&buf);
-
-               if (ret)
-                       return ret;
-       }
-#endif
-
        trans_for_each_update(trans, i) {
                if (i->cached)
                        continue;
@@ -1048,6 +1025,23 @@ int __bch2_trans_commit(struct btree_trans *trans, unsigned flags)
        if (ret)
                goto out_reset;
 
+       trans_for_each_update(trans, i) {
+               struct printbuf buf = PRINTBUF;
+               enum bkey_invalid_flags invalid_flags = 0;
+
+               if (!(flags & BTREE_INSERT_JOURNAL_REPLAY))
+                       invalid_flags |= BKEY_INVALID_WRITE|BKEY_INVALID_COMMIT;
+
+               if (unlikely(bch2_bkey_invalid(c, bkey_i_to_s_c(i->k),
+                                              i->bkey_type, invalid_flags, &buf)))
+                       ret = bch2_trans_commit_bkey_invalid(trans, flags, i, &buf);
+               btree_insert_entry_checks(trans, i);
+               printbuf_exit(&buf);
+
+               if (ret)
+                       return ret;
+       }
+
        if (unlikely(!test_bit(BCH_FS_MAY_GO_RW, &c->flags))) {
                ret = do_bch2_trans_commit_to_journal_replay(trans);
                goto out_reset;