Skip to content

Commit 7d886a8

Browse files
author
Kent Overstreet
committed
bcachefs: bch2_trans_log_str()
The data update path doesn't need a printbuf for its log message - this will help reduce stack usage. Signed-off-by: Kent Overstreet <[email protected]>
1 parent 4a9eb20 commit 7d886a8

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

fs/bcachefs/btree_update.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -828,25 +828,35 @@ int bch2_btree_bit_mod_buffered(struct btree_trans *trans, enum btree_id btree,
828828
return bch2_trans_update_buffered(trans, btree, &k);
829829
}
830830

831-
int bch2_trans_log_msg(struct btree_trans *trans, struct printbuf *buf)
831+
static int __bch2_trans_log_str(struct btree_trans *trans, const char *str, unsigned len)
832832
{
833-
unsigned u64s = DIV_ROUND_UP(buf->pos, sizeof(u64));
834-
835-
int ret = buf->allocation_failure ? -BCH_ERR_ENOMEM_trans_log_msg : 0;
836-
if (ret)
837-
return ret;
833+
unsigned u64s = DIV_ROUND_UP(len, sizeof(u64));
838834

839835
struct jset_entry *e = bch2_trans_jset_entry_alloc(trans, jset_u64s(u64s));
840-
ret = PTR_ERR_OR_ZERO(e);
836+
int ret = PTR_ERR_OR_ZERO(e);
841837
if (ret)
842838
return ret;
843839

844840
struct jset_entry_log *l = container_of(e, struct jset_entry_log, entry);
845841
journal_entry_init(e, BCH_JSET_ENTRY_log, 0, 1, u64s);
846-
memcpy_and_pad(l->d, u64s * sizeof(u64), buf->buf, buf->pos, 0);
842+
memcpy_and_pad(l->d, u64s * sizeof(u64), str, len, 0);
847843
return 0;
848844
}
849845

846+
int bch2_trans_log_str(struct btree_trans *trans, const char *str)
847+
{
848+
return __bch2_trans_log_str(trans, str, strlen(str));
849+
}
850+
851+
int bch2_trans_log_msg(struct btree_trans *trans, struct printbuf *buf)
852+
{
853+
int ret = buf->allocation_failure ? -BCH_ERR_ENOMEM_trans_log_msg : 0;
854+
if (ret)
855+
return ret;
856+
857+
return __bch2_trans_log_str(trans, buf->buf, buf->pos);
858+
}
859+
850860
int bch2_trans_log_bkey(struct btree_trans *trans, enum btree_id btree,
851861
unsigned level, struct bkey_i *k)
852862
{

fs/bcachefs/btree_update.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ void bch2_trans_commit_hook(struct btree_trans *,
205205
struct btree_trans_commit_hook *);
206206
int __bch2_trans_commit(struct btree_trans *, unsigned);
207207

208+
int bch2_trans_log_str(struct btree_trans *, const char *);
208209
int bch2_trans_log_msg(struct btree_trans *, struct printbuf *);
209210
int bch2_trans_log_bkey(struct btree_trans *, enum btree_id, unsigned, struct bkey_i *);
210211

0 commit comments

Comments
 (0)