summaryrefslogtreecommitdiff
path: root/libbcachefs/util.h
diff options
context:
space:
mode:
authorAleksei Kharlamov <der@2-47.ru>2022-02-26 18:05:28 +0100
committerAleksei Kharlamov <der@2-47.ru>2022-02-26 21:31:11 +0100
commit63805882d4a60de63ed82d81ef4cfbb6e499753a (patch)
tree682f0c0b33175883f87c9c597a597a5a7644c358 /libbcachefs/util.h
parent5528e3ae62ead1cfd5be36c1712d1a2dd5ccb3af (diff)
Update bcachefs sources to 31718a2: bcachefs: Don't spin in journal reclaim
Signed-off-by: Aleksei Kharlamov <aleksei@devass.club>
Diffstat (limited to 'libbcachefs/util.h')
-rw-r--r--libbcachefs/util.h74
1 files changed, 39 insertions, 35 deletions
diff --git a/libbcachefs/util.h b/libbcachefs/util.h
index 58d55704..25ae98cc 100644
--- a/libbcachefs/util.h
+++ b/libbcachefs/util.h
@@ -242,19 +242,39 @@ enum printbuf_units {
};
struct printbuf {
- char *pos;
- char *end;
- char *last_newline;
- char *last_field;
+ char *buf;
+ unsigned size;
+ unsigned pos;
+ unsigned last_newline;
+ unsigned last_field;
unsigned indent;
- enum printbuf_units units;
- unsigned tabstop;
- unsigned tabstops[4];
+ enum printbuf_units units:8;
+ u8 atomic;
+ bool allocation_failure:1;
+ u8 tabstop;
+ u8 tabstops[4];
};
+#define PRINTBUF ((struct printbuf) { NULL })
+
+static inline void printbuf_exit(struct printbuf *buf)
+{
+ kfree(buf->buf);
+ buf->buf = ERR_PTR(-EINTR); /* poison value */
+}
+
+static inline void printbuf_reset(struct printbuf *buf)
+{
+ buf->pos = 0;
+ buf->last_newline = 0;
+ buf->last_field = 0;
+ buf->indent = 0;
+ buf->tabstop = 0;
+}
+
static inline size_t printbuf_remaining(struct printbuf *buf)
{
- return buf->end - buf->pos;
+ return buf->size - buf->pos;
}
static inline size_t printbuf_linelen(struct printbuf *buf)
@@ -262,29 +282,13 @@ static inline size_t printbuf_linelen(struct printbuf *buf)
return buf->pos - buf->last_newline;
}
-#define _PBUF(_buf, _len) \
- ((struct printbuf) { \
- .pos = _buf, \
- .end = _buf + _len, \
- .last_newline = _buf, \
- .last_field = _buf, \
- })
-
-#define PBUF(_buf) _PBUF(_buf, sizeof(_buf))
-
+void bch2_pr_buf(struct printbuf *out, const char *fmt, ...);
-#define pr_buf(_out, ...) \
-do { \
- (_out)->pos += scnprintf((_out)->pos, printbuf_remaining(_out), \
- __VA_ARGS__); \
-} while (0)
+#define pr_buf(_out, ...) bch2_pr_buf(_out, __VA_ARGS__)
static inline void pr_char(struct printbuf *out, char c)
{
- if (printbuf_remaining(out) > 1) {
- *out->pos = c;
- out->pos++;
- }
+ bch2_pr_buf(out, "%c", c);
}
static inline void pr_indent_push(struct printbuf *buf, unsigned spaces)
@@ -337,12 +341,12 @@ static inline void pr_tab_rjust(struct printbuf *buf)
BUG_ON(buf->tabstop > ARRAY_SIZE(buf->tabstops));
if (shift > 0) {
- memmove(buf->last_field + shift,
- buf->last_field,
+ memmove(buf->buf + buf->last_field + shift,
+ buf->buf + buf->last_field,
move);
- memset(buf->last_field, ' ', shift);
+ memset(buf->buf + buf->last_field, ' ', shift);
buf->pos += shift;
- *buf->pos = 0;
+ buf->buf[buf->pos] = 0;
}
buf->last_field = buf->pos;
@@ -456,8 +460,8 @@ static inline int bch2_strtoul_h(const char *cp, long *res)
_r; \
})
-#define snprint(buf, size, var) \
- snprintf(buf, size, \
+#define snprint(out, var) \
+ pr_buf(out, \
type_is(var, int) ? "%i\n" \
: type_is(var, unsigned) ? "%u\n" \
: type_is(var, long) ? "%li\n" \
@@ -574,7 +578,7 @@ struct bch_pd_controller {
void bch2_pd_controller_update(struct bch_pd_controller *, s64, s64, int);
void bch2_pd_controller_init(struct bch_pd_controller *);
-size_t bch2_pd_controller_print_debug(struct bch_pd_controller *, char *);
+void bch2_pd_controller_debug_to_text(struct printbuf *, struct bch_pd_controller *);
#define sysfs_pd_controller_attribute(name) \
rw_attribute(name##_rate); \
@@ -598,7 +602,7 @@ do { \
sysfs_print(name##_rate_p_term_inverse, (var)->p_term_inverse); \
\
if (attr == &sysfs_##name##_rate_debug) \
- return bch2_pd_controller_print_debug(var, buf); \
+ bch2_pd_controller_debug_to_text(out, var); \
} while (0)
#define sysfs_pd_controller_store(name, var) \