Commit 7807e143 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Convert various code to printbuf

printbufs know how big the buffer is that was allocated, so we can get
rid of the random PAGE_SIZEs all over the place.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 4580baec
...@@ -1835,9 +1835,8 @@ void bch2_btree_verify_flushed(struct bch_fs *c) ...@@ -1835,9 +1835,8 @@ void bch2_btree_verify_flushed(struct bch_fs *c)
rcu_read_unlock(); rcu_read_unlock();
} }
ssize_t bch2_dirty_btree_nodes_print(struct bch_fs *c, char *buf) void bch2_dirty_btree_nodes_to_text(struct printbuf *out, struct bch_fs *c)
{ {
struct printbuf out = _PBUF(buf, PAGE_SIZE);
struct bucket_table *tbl; struct bucket_table *tbl;
struct rhash_head *pos; struct rhash_head *pos;
struct btree *b; struct btree *b;
...@@ -1850,7 +1849,7 @@ ssize_t bch2_dirty_btree_nodes_print(struct bch_fs *c, char *buf) ...@@ -1850,7 +1849,7 @@ ssize_t bch2_dirty_btree_nodes_print(struct bch_fs *c, char *buf)
if (!(flags & (1 << BTREE_NODE_dirty))) if (!(flags & (1 << BTREE_NODE_dirty)))
continue; continue;
pr_buf(&out, "%p d %u n %u l %u w %u b %u r %u:%lu\n", pr_buf(out, "%p d %u n %u l %u w %u b %u r %u:%lu\n",
b, b,
(flags & (1 << BTREE_NODE_dirty)) != 0, (flags & (1 << BTREE_NODE_dirty)) != 0,
(flags & (1 << BTREE_NODE_need_write)) != 0, (flags & (1 << BTREE_NODE_need_write)) != 0,
...@@ -1861,6 +1860,4 @@ ssize_t bch2_dirty_btree_nodes_print(struct bch_fs *c, char *buf) ...@@ -1861,6 +1860,4 @@ ssize_t bch2_dirty_btree_nodes_print(struct bch_fs *c, char *buf)
b->will_make_reachable & 1); b->will_make_reachable & 1);
} }
rcu_read_unlock(); rcu_read_unlock();
return out.pos - buf;
} }
...@@ -140,7 +140,7 @@ do { \ ...@@ -140,7 +140,7 @@ do { \
void bch2_btree_flush_all_reads(struct bch_fs *); void bch2_btree_flush_all_reads(struct bch_fs *);
void bch2_btree_flush_all_writes(struct bch_fs *); void bch2_btree_flush_all_writes(struct bch_fs *);
void bch2_btree_verify_flushed(struct bch_fs *); void bch2_btree_verify_flushed(struct bch_fs *);
ssize_t bch2_dirty_btree_nodes_print(struct bch_fs *, char *); void bch2_dirty_btree_nodes_to_text(struct printbuf *, struct bch_fs *);
static inline void compat_bformat(unsigned level, enum btree_id btree_id, static inline void compat_bformat(unsigned level, enum btree_id btree_id,
unsigned version, unsigned big_endian, unsigned version, unsigned big_endian,
......
...@@ -1974,22 +1974,19 @@ void bch2_btree_root_alloc(struct bch_fs *c, enum btree_id id) ...@@ -1974,22 +1974,19 @@ void bch2_btree_root_alloc(struct bch_fs *c, enum btree_id id)
six_unlock_intent(&b->c.lock); six_unlock_intent(&b->c.lock);
} }
ssize_t bch2_btree_updates_print(struct bch_fs *c, char *buf) void bch2_btree_updates_to_text(struct printbuf *out, struct bch_fs *c)
{ {
struct printbuf out = _PBUF(buf, PAGE_SIZE);
struct btree_update *as; struct btree_update *as;
mutex_lock(&c->btree_interior_update_lock); mutex_lock(&c->btree_interior_update_lock);
list_for_each_entry(as, &c->btree_interior_update_list, list) list_for_each_entry(as, &c->btree_interior_update_list, list)
pr_buf(&out, "%p m %u w %u r %u j %llu\n", pr_buf(out, "%p m %u w %u r %u j %llu\n",
as, as,
as->mode, as->mode,
as->nodes_written, as->nodes_written,
atomic_read(&as->cl.remaining) & CLOSURE_REMAINING_MASK, atomic_read(&as->cl.remaining) & CLOSURE_REMAINING_MASK,
as->journal.seq); as->journal.seq);
mutex_unlock(&c->btree_interior_update_lock); mutex_unlock(&c->btree_interior_update_lock);
return out.pos - buf;
} }
size_t bch2_btree_interior_updates_nr_pending(struct bch_fs *c) size_t bch2_btree_interior_updates_nr_pending(struct bch_fs *c)
......
...@@ -317,7 +317,7 @@ static inline bool bch2_btree_node_insert_fits(struct bch_fs *c, ...@@ -317,7 +317,7 @@ static inline bool bch2_btree_node_insert_fits(struct bch_fs *c,
return u64s <= bch_btree_keys_u64s_remaining(c, b); return u64s <= bch_btree_keys_u64s_remaining(c, b);
} }
ssize_t bch2_btree_updates_print(struct bch_fs *, char *); void bch2_btree_updates_to_text(struct printbuf *, struct bch_fs *);
size_t bch2_btree_interior_updates_nr_pending(struct bch_fs *); size_t bch2_btree_interior_updates_nr_pending(struct bch_fs *);
......
...@@ -152,9 +152,8 @@ void __bch2_increment_clock(struct io_clock *clock, unsigned sectors) ...@@ -152,9 +152,8 @@ void __bch2_increment_clock(struct io_clock *clock, unsigned sectors)
timer->fn(timer); timer->fn(timer);
} }
ssize_t bch2_io_timers_show(struct io_clock *clock, char *buf) void bch2_io_timers_to_text(struct printbuf *out, struct io_clock *clock)
{ {
struct printbuf out = _PBUF(buf, PAGE_SIZE);
unsigned long now; unsigned long now;
unsigned i; unsigned i;
...@@ -162,12 +161,10 @@ ssize_t bch2_io_timers_show(struct io_clock *clock, char *buf) ...@@ -162,12 +161,10 @@ ssize_t bch2_io_timers_show(struct io_clock *clock, char *buf)
now = atomic_long_read(&clock->now); now = atomic_long_read(&clock->now);
for (i = 0; i < clock->timers.used; i++) for (i = 0; i < clock->timers.used; i++)
pr_buf(&out, "%ps:\t%li\n", pr_buf(out, "%ps:\t%li\n",
clock->timers.data[i]->fn, clock->timers.data[i]->fn,
clock->timers.data[i]->expire - now); clock->timers.data[i]->expire - now);
spin_unlock(&clock->timer_lock); spin_unlock(&clock->timer_lock);
return out.pos - buf;
} }
void bch2_io_clock_exit(struct io_clock *clock) void bch2_io_clock_exit(struct io_clock *clock)
......
...@@ -30,7 +30,7 @@ void bch2_io_clock_schedule_timeout(struct io_clock *, unsigned long); ...@@ -30,7 +30,7 @@ void bch2_io_clock_schedule_timeout(struct io_clock *, unsigned long);
__ret; \ __ret; \
}) })
ssize_t bch2_io_timers_show(struct io_clock *, char *); void bch2_io_timers_to_text(struct printbuf *, struct io_clock *);
void bch2_io_clock_exit(struct io_clock *); void bch2_io_clock_exit(struct io_clock *);
int bch2_io_clock_init(struct io_clock *); int bch2_io_clock_init(struct io_clock *);
......
...@@ -1575,6 +1575,35 @@ void bch2_stripes_heap_to_text(struct printbuf *out, struct bch_fs *c) ...@@ -1575,6 +1575,35 @@ void bch2_stripes_heap_to_text(struct printbuf *out, struct bch_fs *c)
spin_unlock(&c->ec_stripes_heap_lock); spin_unlock(&c->ec_stripes_heap_lock);
} }
void bch2_new_stripes_to_text(struct printbuf *out, struct bch_fs *c)
{
struct ec_stripe_head *h;
struct ec_stripe_new *s;
mutex_lock(&c->ec_stripe_head_lock);
list_for_each_entry(h, &c->ec_stripe_head_list, list) {
pr_buf(out, "target %u algo %u redundancy %u:\n",
h->target, h->algo, h->redundancy);
if (h->s)
pr_buf(out, "\tpending: blocks %u allocated %u\n",
h->s->blocks.nr,
bitmap_weight(h->s->blocks_allocated,
h->s->blocks.nr));
}
mutex_unlock(&c->ec_stripe_head_lock);
mutex_lock(&c->ec_stripe_new_lock);
list_for_each_entry(h, &c->ec_stripe_new_list, list) {
pr_buf(out, "\tin flight: blocks %u allocated %u pin %u\n",
s->blocks.nr,
bitmap_weight(s->blocks_allocated,
s->blocks.nr),
atomic_read(&s->pin));
}
mutex_unlock(&c->ec_stripe_new_lock);
}
void bch2_fs_ec_exit(struct bch_fs *c) void bch2_fs_ec_exit(struct bch_fs *c)
{ {
struct ec_stripe_head *h; struct ec_stripe_head *h;
......
...@@ -161,6 +161,7 @@ int bch2_stripes_write(struct bch_fs *, unsigned, bool *); ...@@ -161,6 +161,7 @@ int bch2_stripes_write(struct bch_fs *, unsigned, bool *);
int bch2_ec_mem_alloc(struct bch_fs *, bool); int bch2_ec_mem_alloc(struct bch_fs *, bool);
void bch2_stripes_heap_to_text(struct printbuf *, struct bch_fs *); void bch2_stripes_heap_to_text(struct printbuf *, struct bch_fs *);
void bch2_new_stripes_to_text(struct printbuf *, struct bch_fs *);
void bch2_fs_ec_exit(struct bch_fs *); void bch2_fs_ec_exit(struct bch_fs *);
int bch2_fs_ec_init(struct bch_fs *); int bch2_fs_ec_init(struct bch_fs *);
......
...@@ -1137,9 +1137,8 @@ int bch2_fs_journal_init(struct journal *j) ...@@ -1137,9 +1137,8 @@ int bch2_fs_journal_init(struct journal *j)
/* debug: */ /* debug: */
ssize_t bch2_journal_print_debug(struct journal *j, char *buf) void bch2_journal_debug_to_text(struct printbuf *out, struct journal *j)
{ {
struct printbuf out = _PBUF(buf, PAGE_SIZE);
struct bch_fs *c = container_of(j, struct bch_fs, journal); struct bch_fs *c = container_of(j, struct bch_fs, journal);
union journal_res_state s; union journal_res_state s;
struct bch_dev *ca; struct bch_dev *ca;
...@@ -1149,7 +1148,7 @@ ssize_t bch2_journal_print_debug(struct journal *j, char *buf) ...@@ -1149,7 +1148,7 @@ ssize_t bch2_journal_print_debug(struct journal *j, char *buf)
spin_lock(&j->lock); spin_lock(&j->lock);
s = READ_ONCE(j->reservations); s = READ_ONCE(j->reservations);
pr_buf(&out, pr_buf(out,
"active journal entries:\t%llu\n" "active journal entries:\t%llu\n"
"seq:\t\t\t%llu\n" "seq:\t\t\t%llu\n"
"last_seq:\t\t%llu\n" "last_seq:\t\t%llu\n"
...@@ -1167,31 +1166,31 @@ ssize_t bch2_journal_print_debug(struct journal *j, char *buf) ...@@ -1167,31 +1166,31 @@ ssize_t bch2_journal_print_debug(struct journal *j, char *buf)
switch (s.cur_entry_offset) { switch (s.cur_entry_offset) {
case JOURNAL_ENTRY_ERROR_VAL: case JOURNAL_ENTRY_ERROR_VAL:
pr_buf(&out, "error\n"); pr_buf(out, "error\n");
break; break;
case JOURNAL_ENTRY_CLOSED_VAL: case JOURNAL_ENTRY_CLOSED_VAL:
pr_buf(&out, "closed\n"); pr_buf(out, "closed\n");
break; break;
default: default:
pr_buf(&out, "%u/%u\n", pr_buf(out, "%u/%u\n",
s.cur_entry_offset, s.cur_entry_offset,
j->cur_entry_u64s); j->cur_entry_u64s);
break; break;
} }
pr_buf(&out, pr_buf(out,
"current entry refs:\t%u\n" "current entry refs:\t%u\n"
"prev entry unwritten:\t", "prev entry unwritten:\t",
journal_state_count(s, s.idx)); journal_state_count(s, s.idx));
if (s.prev_buf_unwritten) if (s.prev_buf_unwritten)
pr_buf(&out, "yes, ref %u sectors %u\n", pr_buf(out, "yes, ref %u sectors %u\n",
journal_state_count(s, !s.idx), journal_state_count(s, !s.idx),
journal_prev_buf(j)->sectors); journal_prev_buf(j)->sectors);
else else
pr_buf(&out, "no\n"); pr_buf(out, "no\n");
pr_buf(&out, pr_buf(out,
"need write:\t\t%i\n" "need write:\t\t%i\n"
"replay done:\t\t%i\n", "replay done:\t\t%i\n",
test_bit(JOURNAL_NEED_WRITE, &j->flags), test_bit(JOURNAL_NEED_WRITE, &j->flags),
...@@ -1204,7 +1203,7 @@ ssize_t bch2_journal_print_debug(struct journal *j, char *buf) ...@@ -1204,7 +1203,7 @@ ssize_t bch2_journal_print_debug(struct journal *j, char *buf)
if (!ja->nr) if (!ja->nr)
continue; continue;
pr_buf(&out, pr_buf(out,
"dev %u:\n" "dev %u:\n"
"\tnr\t\t%u\n" "\tnr\t\t%u\n"
"\tavailable\t%u:%u\n" "\tavailable\t%u:%u\n"
...@@ -1223,34 +1222,29 @@ ssize_t bch2_journal_print_debug(struct journal *j, char *buf) ...@@ -1223,34 +1222,29 @@ ssize_t bch2_journal_print_debug(struct journal *j, char *buf)
spin_unlock(&j->lock); spin_unlock(&j->lock);
rcu_read_unlock(); rcu_read_unlock();
return out.pos - buf;
} }
ssize_t bch2_journal_print_pins(struct journal *j, char *buf) void bch2_journal_pins_to_text(struct printbuf *out, struct journal *j)
{ {
struct printbuf out = _PBUF(buf, PAGE_SIZE);
struct journal_entry_pin_list *pin_list; struct journal_entry_pin_list *pin_list;
struct journal_entry_pin *pin; struct journal_entry_pin *pin;
u64 i; u64 i;
spin_lock(&j->lock); spin_lock(&j->lock);
fifo_for_each_entry_ptr(pin_list, &j->pin, i) { fifo_for_each_entry_ptr(pin_list, &j->pin, i) {
pr_buf(&out, "%llu: count %u\n", pr_buf(out, "%llu: count %u\n",
i, atomic_read(&pin_list->count)); i, atomic_read(&pin_list->count));
list_for_each_entry(pin, &pin_list->list, list) list_for_each_entry(pin, &pin_list->list, list)
pr_buf(&out, "\t%px %ps\n", pr_buf(out, "\t%px %ps\n",
pin, pin->flush); pin, pin->flush);
if (!list_empty(&pin_list->flushed)) if (!list_empty(&pin_list->flushed))
pr_buf(&out, "flushed:\n"); pr_buf(out, "flushed:\n");
list_for_each_entry(pin, &pin_list->flushed, list) list_for_each_entry(pin, &pin_list->flushed, list)
pr_buf(&out, "\t%px %ps\n", pr_buf(out, "\t%px %ps\n",
pin, pin->flush); pin, pin->flush);
} }
spin_unlock(&j->lock); spin_unlock(&j->lock);
return out.pos - buf;
} }
...@@ -501,8 +501,8 @@ static inline void bch2_journal_set_replay_done(struct journal *j) ...@@ -501,8 +501,8 @@ static inline void bch2_journal_set_replay_done(struct journal *j)
void bch2_journal_unblock(struct journal *); void bch2_journal_unblock(struct journal *);
void bch2_journal_block(struct journal *); void bch2_journal_block(struct journal *);
ssize_t bch2_journal_print_debug(struct journal *, char *); void bch2_journal_debug_to_text(struct printbuf *, struct journal *);
ssize_t bch2_journal_print_pins(struct journal *, char *); void bch2_journal_pins_to_text(struct printbuf *, struct journal *);
int bch2_set_nr_journal_buckets(struct bch_fs *, struct bch_dev *, int bch2_set_nr_journal_buckets(struct bch_fs *, struct bch_dev *,
unsigned nr); unsigned nr);
......
...@@ -249,45 +249,42 @@ static int bch2_rebalance_thread(void *arg) ...@@ -249,45 +249,42 @@ static int bch2_rebalance_thread(void *arg)
return 0; return 0;
} }
ssize_t bch2_rebalance_work_show(struct bch_fs *c, char *buf) void bch2_rebalance_work_to_text(struct printbuf *out, struct bch_fs *c)
{ {
struct printbuf out = _PBUF(buf, PAGE_SIZE);
struct bch_fs_rebalance *r = &c->rebalance; struct bch_fs_rebalance *r = &c->rebalance;
struct rebalance_work w = rebalance_work(c); struct rebalance_work w = rebalance_work(c);
char h1[21], h2[21]; char h1[21], h2[21];
bch2_hprint(&PBUF(h1), w.dev_most_full_work << 9); bch2_hprint(&PBUF(h1), w.dev_most_full_work << 9);
bch2_hprint(&PBUF(h2), w.dev_most_full_capacity << 9); bch2_hprint(&PBUF(h2), w.dev_most_full_capacity << 9);
pr_buf(&out, "fullest_dev (%i):\t%s/%s\n", pr_buf(out, "fullest_dev (%i):\t%s/%s\n",
w.dev_most_full_idx, h1, h2); w.dev_most_full_idx, h1, h2);
bch2_hprint(&PBUF(h1), w.total_work << 9); bch2_hprint(&PBUF(h1), w.total_work << 9);
bch2_hprint(&PBUF(h2), c->capacity << 9); bch2_hprint(&PBUF(h2), c->capacity << 9);
pr_buf(&out, "total work:\t\t%s/%s\n", h1, h2); pr_buf(out, "total work:\t\t%s/%s\n", h1, h2);
pr_buf(&out, "rate:\t\t\t%u\n", r->pd.rate.rate); pr_buf(out, "rate:\t\t\t%u\n", r->pd.rate.rate);
switch (r->state) { switch (r->state) {
case REBALANCE_WAITING: case REBALANCE_WAITING:
pr_buf(&out, "waiting\n"); pr_buf(out, "waiting\n");
break; break;
case REBALANCE_THROTTLED: case REBALANCE_THROTTLED:
bch2_hprint(&PBUF(h1), bch2_hprint(&PBUF(h1),
(r->throttled_until_iotime - (r->throttled_until_iotime -
atomic_long_read(&c->io_clock[WRITE].now)) << 9); atomic_long_read(&c->io_clock[WRITE].now)) << 9);
pr_buf(&out, "throttled for %lu sec or %s io\n", pr_buf(out, "throttled for %lu sec or %s io\n",
(r->throttled_until_cputime - jiffies) / HZ, (r->throttled_until_cputime - jiffies) / HZ,
h1); h1);
break; break;
case REBALANCE_RUNNING: case REBALANCE_RUNNING:
pr_buf(&out, "running\n"); pr_buf(out, "running\n");
pr_buf(&out, "pos %llu:%llu\n", pr_buf(out, "pos %llu:%llu\n",
r->move_stats.pos.inode, r->move_stats.pos.inode,
r->move_stats.pos.offset); r->move_stats.pos.offset);
break; break;
} }
return out.pos - buf;
} }
void bch2_rebalance_stop(struct bch_fs *c) void bch2_rebalance_stop(struct bch_fs *c)
......
...@@ -19,7 +19,7 @@ void bch2_rebalance_add_key(struct bch_fs *, struct bkey_s_c, ...@@ -19,7 +19,7 @@ void bch2_rebalance_add_key(struct bch_fs *, struct bkey_s_c,
struct bch_io_opts *); struct bch_io_opts *);
void bch2_rebalance_add_work(struct bch_fs *, u64); void bch2_rebalance_add_work(struct bch_fs *, u64);
ssize_t bch2_rebalance_work_show(struct bch_fs *, char *); void bch2_rebalance_work_to_text(struct printbuf *, struct bch_fs *);
void bch2_rebalance_stop(struct bch_fs *); void bch2_rebalance_stop(struct bch_fs *);
int bch2_rebalance_start(struct bch_fs *); int bch2_rebalance_start(struct bch_fs *);
......
This diff is collapsed.
...@@ -320,43 +320,40 @@ static void pr_time_units(struct printbuf *out, u64 ns) ...@@ -320,43 +320,40 @@ static void pr_time_units(struct printbuf *out, u64 ns)
pr_buf(out, "%llu %s", div_u64(ns, u->nsecs), u->name); pr_buf(out, "%llu %s", div_u64(ns, u->nsecs), u->name);
} }
size_t bch2_time_stats_print(struct bch2_time_stats *stats, char *buf, size_t len) void bch2_time_stats_to_text(struct printbuf *out, struct bch2_time_stats *stats)
{ {
struct printbuf out = _PBUF(buf, len);
const struct time_unit *u; const struct time_unit *u;
u64 freq = READ_ONCE(stats->average_frequency); u64 freq = READ_ONCE(stats->average_frequency);
u64 q, last_q = 0; u64 q, last_q = 0;
int i; int i;
pr_buf(&out, "count:\t\t%llu\n", pr_buf(out, "count:\t\t%llu\n",
stats->count); stats->count);
pr_buf(&out, "rate:\t\t%llu/sec\n", pr_buf(out, "rate:\t\t%llu/sec\n",
freq ? div64_u64(NSEC_PER_SEC, freq) : 0); freq ? div64_u64(NSEC_PER_SEC, freq) : 0);
pr_buf(&out, "frequency:\t"); pr_buf(out, "frequency:\t");
pr_time_units(&out, freq); pr_time_units(out, freq);
pr_buf(&out, "\navg duration:\t"); pr_buf(out, "\navg duration:\t");
pr_time_units(&out, stats->average_duration); pr_time_units(out, stats->average_duration);
pr_buf(&out, "\nmax duration:\t"); pr_buf(out, "\nmax duration:\t");
pr_time_units(&out, stats->max_duration); pr_time_units(out, stats->max_duration);
i = eytzinger0_first(NR_QUANTILES); i = eytzinger0_first(NR_QUANTILES);
u = pick_time_units(stats->quantiles.entries[i].m); u = pick_time_units(stats->quantiles.entries[i].m);
pr_buf(&out, "\nquantiles (%s):\t", u->name); pr_buf(out, "\nquantiles (%s):\t", u->name);
eytzinger0_for_each(i, NR_QUANTILES) { eytzinger0_for_each(i, NR_QUANTILES) {
bool is_last = eytzinger0_next(i, NR_QUANTILES) == -1; bool is_last = eytzinger0_next(i, NR_QUANTILES) == -1;
q = max(stats->quantiles.entries[i].m, last_q); q = max(stats->quantiles.entries[i].m, last_q);
pr_buf(&out, "%llu%s", pr_buf(out, "%llu%s",
div_u64(q, u->nsecs), div_u64(q, u->nsecs),
is_last ? "\n" : " "); is_last ? "\n" : " ");
last_q = q; last_q = q;
} }
return out.pos - buf;
} }
void bch2_time_stats_exit(struct bch2_time_stats *stats) void bch2_time_stats_exit(struct bch2_time_stats *stats)
......
...@@ -390,7 +390,7 @@ static inline void bch2_time_stats_update(struct bch2_time_stats *stats, u64 sta ...@@ -390,7 +390,7 @@ static inline void bch2_time_stats_update(struct bch2_time_stats *stats, u64 sta
__bch2_time_stats_update(stats, start, local_clock()); __bch2_time_stats_update(stats, start, local_clock());
} }
size_t bch2_time_stats_print(struct bch2_time_stats *, char *, size_t); void bch2_time_stats_to_text(struct printbuf *, struct bch2_time_stats *);
void bch2_time_stats_exit(struct bch2_time_stats *); void bch2_time_stats_exit(struct bch2_time_stats *);
void bch2_time_stats_init(struct bch2_time_stats *); void bch2_time_stats_init(struct bch2_time_stats *);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment