bcachefs: bch2_trans_log_msg()
authorKent Overstreet <kent.overstreet@linux.dev>
Thu, 12 Dec 2024 05:44:28 +0000 (00:44 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 29 Dec 2024 18:30:39 +0000 (13:30 -0500)
Export a helper for logging to the journal when we're already in a
transaction context.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/btree_update.c
fs/bcachefs/btree_update.h

index 06fd5aa62296a3a7759f528f560a51799751593d..a4b70e3fe4c33d629290598ffd2a60d137673606 100644 (file)
@@ -823,10 +823,17 @@ int bch2_btree_bit_mod_buffered(struct btree_trans *trans, enum btree_id btree,
        return bch2_trans_update_buffered(trans, btree, &k);
 }
 
-static int __bch2_trans_log_msg(struct btree_trans *trans, struct printbuf *buf, unsigned u64s)
+int bch2_trans_log_msg(struct btree_trans *trans, struct printbuf *buf)
 {
+       unsigned u64s = DIV_ROUND_UP(buf->pos, sizeof(u64));
+       prt_chars(buf, '\0', u64s * sizeof(u64) - buf->pos);
+
+       int ret = buf->allocation_failure ? -BCH_ERR_ENOMEM_trans_log_msg : 0;
+       if (ret)
+               return ret;
+
        struct jset_entry *e = bch2_trans_jset_entry_alloc(trans, jset_u64s(u64s));
-       int ret = PTR_ERR_OR_ZERO(e);
+       ret = PTR_ERR_OR_ZERO(e);
        if (ret)
                return ret;
 
@@ -862,7 +869,7 @@ __bch2_fs_log_msg(struct bch_fs *c, unsigned commit_flags, const char *fmt,
                c->journal.early_journal_entries.nr += jset_u64s(u64s);
        } else {
                ret = bch2_trans_commit_do(c, NULL, NULL, commit_flags,
-                       __bch2_trans_log_msg(trans, &buf, u64s));
+                       bch2_trans_log_msg(trans, &buf));
        }
 err:
        printbuf_exit(&buf);
index 58df20194306de4ca491ca1f043bd3ad0b329abc..8f22ef9a7651aba4bd50f7639d3d4372042901b9 100644 (file)
@@ -159,6 +159,7 @@ void bch2_trans_commit_hook(struct btree_trans *,
                            struct btree_trans_commit_hook *);
 int __bch2_trans_commit(struct btree_trans *, unsigned);
 
+int bch2_trans_log_msg(struct btree_trans *, struct printbuf *);
 __printf(2, 3) int bch2_fs_log_msg(struct bch_fs *, const char *, ...);
 __printf(2, 3) int bch2_journal_log_msg(struct bch_fs *, const char *, ...);