]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
bcachefs: bch2_trans_log_str()
authorKent Overstreet <kent.overstreet@linux.dev>
Thu, 22 May 2025 16:49:56 +0000 (12:49 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Thu, 22 May 2025 19:13:17 +0000 (15:13 -0400)
The data update path doesn't need a printbuf for its log message - this
will help reduce stack usage.

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

index 20fba8d17431b3fff87e7437fa0e6d64839581e6..5dac09c98026ca27e3e0d4bfd7ed3c77f53184f7 100644 (file)
@@ -828,25 +828,35 @@ int bch2_btree_bit_mod_buffered(struct btree_trans *trans, enum btree_id btree,
        return bch2_trans_update_buffered(trans, btree, &k);
 }
 
-int bch2_trans_log_msg(struct btree_trans *trans, struct printbuf *buf)
+static int __bch2_trans_log_str(struct btree_trans *trans, const char *str, unsigned len)
 {
-       unsigned u64s = DIV_ROUND_UP(buf->pos, sizeof(u64));
-
-       int ret = buf->allocation_failure ? -BCH_ERR_ENOMEM_trans_log_msg : 0;
-       if (ret)
-               return ret;
+       unsigned u64s = DIV_ROUND_UP(len, sizeof(u64));
 
        struct jset_entry *e = bch2_trans_jset_entry_alloc(trans, jset_u64s(u64s));
-       ret = PTR_ERR_OR_ZERO(e);
+       int ret = PTR_ERR_OR_ZERO(e);
        if (ret)
                return ret;
 
        struct jset_entry_log *l = container_of(e, struct jset_entry_log, entry);
        journal_entry_init(e, BCH_JSET_ENTRY_log, 0, 1, u64s);
-       memcpy_and_pad(l->d, u64s * sizeof(u64), buf->buf, buf->pos, 0);
+       memcpy_and_pad(l->d, u64s * sizeof(u64), str, len, 0);
        return 0;
 }
 
+int bch2_trans_log_str(struct btree_trans *trans, const char *str)
+{
+       return __bch2_trans_log_str(trans, str, strlen(str));
+}
+
+int bch2_trans_log_msg(struct btree_trans *trans, struct printbuf *buf)
+{
+       int ret = buf->allocation_failure ? -BCH_ERR_ENOMEM_trans_log_msg : 0;
+       if (ret)
+               return ret;
+
+       return __bch2_trans_log_str(trans, buf->buf, buf->pos);
+}
+
 int bch2_trans_log_bkey(struct btree_trans *trans, enum btree_id btree,
                        unsigned level, struct bkey_i *k)
 {
index a54dc7277177ed6167690ecf5ce7bbad16ad5786..f907eaa8b1854732b311014a8ac76a852ea82bcd 100644 (file)
@@ -205,6 +205,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_str(struct btree_trans *, const char *);
 int bch2_trans_log_msg(struct btree_trans *, struct printbuf *);
 int bch2_trans_log_bkey(struct btree_trans *, enum btree_id, unsigned, struct bkey_i *);