bcachefs: Add a mechanism for passing extra journal entries to bch2_trans_commit()
authorKent Overstreet <kent.overstreet@gmail.com>
Mon, 25 May 2020 23:29:48 +0000 (19:29 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:08:40 +0000 (17:08 -0400)
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/btree_iter.c
fs/bcachefs/btree_types.h
fs/bcachefs/btree_update_leaf.c
fs/bcachefs/journal.h

index 7b12bd163df79c774c855b8910b8caf7f01996f1..ca775e63b4c64f5c1f4d76ae77ea15b64697aa87 100644 (file)
@@ -2153,6 +2153,9 @@ void bch2_trans_reset(struct btree_trans *trans, unsigned flags)
        trans->nr_updates2              = 0;
        trans->mem_top                  = 0;
 
+       trans->extra_journal_entries    = NULL;
+       trans->extra_journal_entry_u64s = 0;
+
        if (trans->fs_usage_deltas) {
                trans->fs_usage_deltas->used = 0;
                memset((void *) trans->fs_usage_deltas +
index 57796340fb36693aafc6ded6e0ada4948b8325e5..769c05c8d9380a63cc8d9809aa1350e1bee454b5 100644 (file)
@@ -308,6 +308,9 @@ struct btree_trans {
        struct btree_insert_entry *updates2;
 
        /* update path: */
+       struct jset_entry       *extra_journal_entries;
+       unsigned                extra_journal_entry_u64s;
+
        struct journal_res      journal_res;
        struct journal_preres   journal_preres;
        u64                     *journal_seq;
index a93bc1890263c52d7abf04fd85b4cd7cf14d7ee5..98b60d230dce2abc4d5ae7b9251a85115c913e65 100644 (file)
@@ -413,6 +413,16 @@ bch2_trans_commit_write_locked(struct btree_trans *trans,
                        goto err;
        }
 
+       if (unlikely(trans->extra_journal_entry_u64s)) {
+               memcpy_u64s_small(bch2_journal_reservation_entry(&c->journal,
+                                                                &trans->journal_res),
+                                 trans->extra_journal_entries,
+                                 trans->extra_journal_entry_u64s);
+
+               trans->journal_res.offset       += trans->extra_journal_entry_u64s;
+               trans->journal_res.u64s         -= trans->extra_journal_entry_u64s;
+       }
+
        /*
         * Not allowed to fail after we've gotten our journal reservation - we
         * have to use it:
@@ -800,7 +810,7 @@ int __bch2_trans_commit(struct btree_trans *trans)
 
        memset(&trans->journal_preres, 0, sizeof(trans->journal_preres));
 
-       trans->journal_u64s             = 0;
+       trans->journal_u64s             = trans->extra_journal_entry_u64s;
        trans->journal_preres_u64s      = 0;
 
        if (!(trans->flags & BTREE_INSERT_NOCHECK_RW) &&
index 81e26ba43fa122cfdbb1b463c1c1201c4405b1aa..6630db6ecc14eda5715a17b4a0513c53378f673a 100644 (file)
@@ -199,13 +199,18 @@ bch2_journal_add_entry_noreservation(struct journal_buf *buf, size_t u64s)
        return entry;
 }
 
+static inline struct jset_entry *
+bch2_journal_reservation_entry(struct journal *j, struct journal_res *res)
+{
+       return vstruct_idx(j->buf[res->idx].data, res->offset);
+}
+
 static inline void bch2_journal_add_entry(struct journal *j, struct journal_res *res,
                                          unsigned type, enum btree_id id,
                                          unsigned level,
                                          const void *data, unsigned u64s)
 {
-       struct journal_buf *buf = &j->buf[res->idx];
-       struct jset_entry *entry = vstruct_idx(buf->data, res->offset);
+       struct jset_entry *entry = bch2_journal_reservation_entry(j, res);
        unsigned actual = jset_u64s(u64s);
 
        EBUG_ON(!res->ref);
@@ -221,7 +226,7 @@ static inline void bch2_journal_add_entry(struct journal *j, struct journal_res
        entry->pad[0]   = 0;
        entry->pad[1]   = 0;
        entry->pad[2]   = 0;
-       memcpy_u64s(entry->_data, data, u64s);
+       memcpy_u64s_small(entry->_data, data, u64s);
 }
 
 static inline void bch2_journal_add_keys(struct journal *j, struct journal_res *res,