From 3e2e3d468eed1d5ebbb4c6309d2eaebd081912c5 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Sun, 6 Mar 2022 14:07:16 -0500 Subject: [PATCH] Update bcachefs sources to e318fabeb4 bcachefs: Fix pr_tab_rjust() --- .bcachefs_revision | 2 +- libbcachefs/util.c | 37 +++++++++++++++++++++++++++++++++++-- libbcachefs/util.h | 22 +++------------------- 3 files changed, 39 insertions(+), 22 deletions(-) diff --git a/.bcachefs_revision b/.bcachefs_revision index 619cb828..8e1032ac 100644 --- a/.bcachefs_revision +++ b/.bcachefs_revision @@ -1 +1 @@ -259ff916050fb6a9ff742891fb8aa379924a187f +e318fabeb424d4b8fdd46329125c30aaa4f9006a diff --git a/libbcachefs/util.c b/libbcachefs/util.c index 766d08ae..37fc2041 100644 --- a/libbcachefs/util.c +++ b/libbcachefs/util.c @@ -101,8 +101,14 @@ STRTO_H(strtou64, u64) static int bch2_printbuf_realloc(struct printbuf *out, unsigned extra) { - unsigned new_size = roundup_pow_of_two(out->size + extra); - char *buf = krealloc(out->buf, new_size, !out->atomic ? GFP_KERNEL : GFP_ATOMIC); + unsigned new_size; + char *buf; + + if (out->pos + extra + 1 < out->size) + return 0; + + new_size = roundup_pow_of_two(out->size + extra); + buf = krealloc(out->buf, new_size, !out->atomic ? GFP_KERNEL : GFP_ATOMIC); if (!buf) { out->allocation_failure = true; @@ -131,6 +137,33 @@ void bch2_pr_buf(struct printbuf *out, const char *fmt, ...) out->pos += len; } +void bch2_pr_tab_rjust(struct printbuf *buf) +{ + BUG_ON(buf->tabstop > ARRAY_SIZE(buf->tabstops)); + + if (printbuf_linelen(buf) < buf->tabstops[buf->tabstop]) { + unsigned move = buf->pos - buf->last_field; + unsigned shift = buf->tabstops[buf->tabstop] - + printbuf_linelen(buf); + + bch2_printbuf_realloc(buf, shift); + + if (buf->last_field + shift + 1 < buf->size) { + move = min(move, buf->size - 1 - buf->last_field - shift); + + memmove(buf->buf + buf->last_field + shift, + buf->buf + buf->last_field, + move); + memset(buf->buf + buf->last_field, ' ', shift); + buf->pos += shift; + buf->buf[buf->pos] = 0; + } + } + + buf->last_field = buf->pos; + buf->tabstop++; +} + void bch2_hprint(struct printbuf *buf, s64 v) { int u, t = 0; diff --git a/libbcachefs/util.h b/libbcachefs/util.h index 4095df2f..2c9e9102 100644 --- a/libbcachefs/util.h +++ b/libbcachefs/util.h @@ -334,27 +334,11 @@ static inline void pr_tab(struct printbuf *buf) buf->tabstop++; } +void bch2_pr_tab_rjust(struct printbuf *); + static inline void pr_tab_rjust(struct printbuf *buf) { - ssize_t shift = min_t(ssize_t, buf->tabstops[buf->tabstop] - - printbuf_linelen(buf), - printbuf_remaining(buf)); - ssize_t move = min_t(ssize_t, buf->pos - buf->last_field, - printbuf_remaining(buf) - shift); - - BUG_ON(buf->tabstop > ARRAY_SIZE(buf->tabstops)); - - if (shift > 0) { - memmove(buf->buf + buf->last_field + shift, - buf->buf + buf->last_field, - move); - memset(buf->buf + buf->last_field, ' ', shift); - buf->pos += shift; - buf->buf[buf->pos] = 0; - } - - buf->last_field = buf->pos; - buf->tabstop++; + bch2_pr_tab_rjust(buf); } void bch2_pr_units(struct printbuf *, s64, s64);