mirror of
https://github.com/koverstreet/bcachefs-tools.git
synced 2025-02-23 00:00:02 +03:00
Heap-allocate printbufs
Signed-off-by: Aleksei Kharlamov <aleksei@devass.club>
This commit is contained in:
parent
63805882d4
commit
b1a2ab6eef
65
cmd_debug.c
65
cmd_debug.c
@ -189,7 +189,7 @@ static void list_keys(struct bch_fs *c, enum btree_id btree_id,
|
|||||||
struct btree_trans trans;
|
struct btree_trans trans;
|
||||||
struct btree_iter iter;
|
struct btree_iter iter;
|
||||||
struct bkey_s_c k;
|
struct bkey_s_c k;
|
||||||
char buf[512];
|
struct printbuf buf = PRINTBUF;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
bch2_trans_init(&trans, c, 0, 0);
|
bch2_trans_init(&trans, c, 0, 0);
|
||||||
@ -200,12 +200,15 @@ static void list_keys(struct bch_fs *c, enum btree_id btree_id,
|
|||||||
if (bkey_cmp(k.k->p, end) > 0)
|
if (bkey_cmp(k.k->p, end) > 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
bch2_bkey_val_to_text(&PBUF(buf), c, k);
|
printbuf_reset(&buf);
|
||||||
puts(buf);
|
bch2_bkey_val_to_text(&buf, c, k);
|
||||||
|
puts(buf.buf);
|
||||||
}
|
}
|
||||||
bch2_trans_iter_exit(&trans, &iter);
|
bch2_trans_iter_exit(&trans, &iter);
|
||||||
|
|
||||||
bch2_trans_exit(&trans);
|
bch2_trans_exit(&trans);
|
||||||
|
|
||||||
|
printbuf_exit(&buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void list_btree_formats(struct bch_fs *c, enum btree_id btree_id, unsigned level,
|
static void list_btree_formats(struct bch_fs *c, enum btree_id btree_id, unsigned level,
|
||||||
@ -214,7 +217,7 @@ static void list_btree_formats(struct bch_fs *c, enum btree_id btree_id, unsigne
|
|||||||
struct btree_trans trans;
|
struct btree_trans trans;
|
||||||
struct btree_iter iter;
|
struct btree_iter iter;
|
||||||
struct btree *b;
|
struct btree *b;
|
||||||
char buf[4096];
|
struct printbuf buf = PRINTBUF;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
bch2_trans_init(&trans, c, 0, 0);
|
bch2_trans_init(&trans, c, 0, 0);
|
||||||
@ -223,8 +226,9 @@ static void list_btree_formats(struct bch_fs *c, enum btree_id btree_id, unsigne
|
|||||||
if (bkey_cmp(b->key.k.p, end) > 0)
|
if (bkey_cmp(b->key.k.p, end) > 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
bch2_btree_node_to_text(&PBUF(buf), c, b);
|
printbuf_reset(&buf);
|
||||||
puts(buf);
|
bch2_btree_node_to_text(&buf, c, b);
|
||||||
|
puts(buf.buf);
|
||||||
}
|
}
|
||||||
bch2_trans_iter_exit(&trans, &iter);
|
bch2_trans_iter_exit(&trans, &iter);
|
||||||
|
|
||||||
@ -232,6 +236,7 @@ static void list_btree_formats(struct bch_fs *c, enum btree_id btree_id, unsigne
|
|||||||
die("error %s walking btree nodes", strerror(-ret));
|
die("error %s walking btree nodes", strerror(-ret));
|
||||||
|
|
||||||
bch2_trans_exit(&trans);
|
bch2_trans_exit(&trans);
|
||||||
|
printbuf_exit(&buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void list_nodes(struct bch_fs *c, enum btree_id btree_id, unsigned level,
|
static void list_nodes(struct bch_fs *c, enum btree_id btree_id, unsigned level,
|
||||||
@ -240,7 +245,7 @@ static void list_nodes(struct bch_fs *c, enum btree_id btree_id, unsigned level,
|
|||||||
struct btree_trans trans;
|
struct btree_trans trans;
|
||||||
struct btree_iter iter;
|
struct btree_iter iter;
|
||||||
struct btree *b;
|
struct btree *b;
|
||||||
char buf[4096];
|
struct printbuf buf = PRINTBUF;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
bch2_trans_init(&trans, c, 0, 0);
|
bch2_trans_init(&trans, c, 0, 0);
|
||||||
@ -249,8 +254,9 @@ static void list_nodes(struct bch_fs *c, enum btree_id btree_id, unsigned level,
|
|||||||
if (bkey_cmp(b->key.k.p, end) > 0)
|
if (bkey_cmp(b->key.k.p, end) > 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
bch2_bkey_val_to_text(&PBUF(buf), c, bkey_i_to_s_c(&b->key));
|
printbuf_reset(&buf);
|
||||||
fputs(buf, stdout);
|
bch2_bkey_val_to_text(&buf, c, bkey_i_to_s_c(&b->key));
|
||||||
|
fputs(buf.buf, stdout);
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
}
|
}
|
||||||
bch2_trans_iter_exit(&trans, &iter);
|
bch2_trans_iter_exit(&trans, &iter);
|
||||||
@ -259,6 +265,7 @@ static void list_nodes(struct bch_fs *c, enum btree_id btree_id, unsigned level,
|
|||||||
die("error %s walking btree nodes", strerror(-ret));
|
die("error %s walking btree nodes", strerror(-ret));
|
||||||
|
|
||||||
bch2_trans_exit(&trans);
|
bch2_trans_exit(&trans);
|
||||||
|
printbuf_exit(&buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_node_ondisk(struct bch_fs *c, struct btree *b)
|
static void print_node_ondisk(struct bch_fs *c, struct btree *b)
|
||||||
@ -347,10 +354,12 @@ static void print_node_ondisk(struct bch_fs *c, struct btree *b)
|
|||||||
|
|
||||||
for (k = i->start; k != vstruct_last(i); k = bkey_next(k)) {
|
for (k = i->start; k != vstruct_last(i); k = bkey_next(k)) {
|
||||||
struct bkey u;
|
struct bkey u;
|
||||||
char buf[4096];
|
struct printbuf buf = PRINTBUF;
|
||||||
|
|
||||||
bch2_bkey_val_to_text(&PBUF(buf), c, bkey_disassemble(b, k, &u));
|
bch2_bkey_val_to_text(&buf, c, bkey_disassemble(b, k, &u));
|
||||||
fprintf(stdout, " %s\n", buf);
|
fprintf(stdout, " %s\n", buf.buf);
|
||||||
|
|
||||||
|
printbuf_exit(&buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -363,7 +372,7 @@ static void list_nodes_ondisk(struct bch_fs *c, enum btree_id btree_id, unsigned
|
|||||||
struct btree_trans trans;
|
struct btree_trans trans;
|
||||||
struct btree_iter iter;
|
struct btree_iter iter;
|
||||||
struct btree *b;
|
struct btree *b;
|
||||||
char buf[4096];
|
struct printbuf buf = PRINTBUF;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
bch2_trans_init(&trans, c, 0, 0);
|
bch2_trans_init(&trans, c, 0, 0);
|
||||||
@ -372,8 +381,9 @@ static void list_nodes_ondisk(struct bch_fs *c, enum btree_id btree_id, unsigned
|
|||||||
if (bkey_cmp(b->key.k.p, end) > 0)
|
if (bkey_cmp(b->key.k.p, end) > 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
bch2_bkey_val_to_text(&PBUF(buf), c, bkey_i_to_s_c(&b->key));
|
printbuf_reset(&buf);
|
||||||
fputs(buf, stdout);
|
bch2_bkey_val_to_text(&buf, c, bkey_i_to_s_c(&b->key));
|
||||||
|
fputs(buf.buf, stdout);
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
|
|
||||||
print_node_ondisk(c, b);
|
print_node_ondisk(c, b);
|
||||||
@ -384,6 +394,7 @@ static void list_nodes_ondisk(struct bch_fs *c, enum btree_id btree_id, unsigned
|
|||||||
die("error %s walking btree nodes", strerror(-ret));
|
die("error %s walking btree nodes", strerror(-ret));
|
||||||
|
|
||||||
bch2_trans_exit(&trans);
|
bch2_trans_exit(&trans);
|
||||||
|
printbuf_exit(&buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void list_nodes_keys(struct bch_fs *c, enum btree_id btree_id, unsigned level,
|
static void list_nodes_keys(struct bch_fs *c, enum btree_id btree_id, unsigned level,
|
||||||
@ -395,7 +406,7 @@ static void list_nodes_keys(struct bch_fs *c, enum btree_id btree_id, unsigned l
|
|||||||
struct bkey unpacked;
|
struct bkey unpacked;
|
||||||
struct bkey_s_c k;
|
struct bkey_s_c k;
|
||||||
struct btree *b;
|
struct btree *b;
|
||||||
char buf[4096];
|
struct printbuf buf = PRINTBUF;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
bch2_trans_init(&trans, c, 0, 0);
|
bch2_trans_init(&trans, c, 0, 0);
|
||||||
@ -404,13 +415,15 @@ static void list_nodes_keys(struct bch_fs *c, enum btree_id btree_id, unsigned l
|
|||||||
if (bkey_cmp(b->key.k.p, end) > 0)
|
if (bkey_cmp(b->key.k.p, end) > 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
bch2_btree_node_to_text(&PBUF(buf), c, b);
|
printbuf_reset(&buf);
|
||||||
fputs(buf, stdout);
|
bch2_btree_node_to_text(&buf, c, b);
|
||||||
|
fputs(buf.buf, stdout);
|
||||||
|
|
||||||
for_each_btree_node_key_unpack(b, k, &node_iter, &unpacked) {
|
for_each_btree_node_key_unpack(b, k, &node_iter, &unpacked) {
|
||||||
bch2_bkey_val_to_text(&PBUF(buf), c, k);
|
printbuf_reset(&buf);
|
||||||
|
bch2_bkey_val_to_text(&buf, c, k);
|
||||||
putchar('\t');
|
putchar('\t');
|
||||||
puts(buf);
|
puts(buf.buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bch2_trans_iter_exit(&trans, &iter);
|
bch2_trans_iter_exit(&trans, &iter);
|
||||||
@ -419,6 +432,7 @@ static void list_nodes_keys(struct bch_fs *c, enum btree_id btree_id, unsigned l
|
|||||||
die("error %s walking btree nodes", strerror(-ret));
|
die("error %s walking btree nodes", strerror(-ret));
|
||||||
|
|
||||||
bch2_trans_exit(&trans);
|
bch2_trans_exit(&trans);
|
||||||
|
printbuf_exit(&buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void list_keys_usage(void)
|
static void list_keys_usage(void)
|
||||||
@ -598,8 +612,7 @@ int cmd_list_journal(int argc, char *argv[])
|
|||||||
struct jset_entry *entry;
|
struct jset_entry *entry;
|
||||||
|
|
||||||
list_for_each_entry(p, &c->journal_entries, list) {
|
list_for_each_entry(p, &c->journal_entries, list) {
|
||||||
char _buf[4096];
|
struct printbuf buf = PRINTBUF;
|
||||||
struct printbuf buf = PBUF(_buf);
|
|
||||||
|
|
||||||
bch2_journal_ptrs_to_text(&buf, c, p);
|
bch2_journal_ptrs_to_text(&buf, c, p);
|
||||||
|
|
||||||
@ -611,10 +624,10 @@ int cmd_list_journal(int argc, char *argv[])
|
|||||||
le64_to_cpu(p->j.seq),
|
le64_to_cpu(p->j.seq),
|
||||||
le32_to_cpu(p->j.version),
|
le32_to_cpu(p->j.version),
|
||||||
le64_to_cpu(p->j.last_seq),
|
le64_to_cpu(p->j.last_seq),
|
||||||
_buf);
|
buf.buf);
|
||||||
|
|
||||||
vstruct_for_each(&p->j, entry) {
|
vstruct_for_each(&p->j, entry) {
|
||||||
buf = PBUF(_buf);
|
printbuf_reset(&buf);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* log entries denote the start of a new transaction
|
* log entries denote the start of a new transaction
|
||||||
@ -623,8 +636,10 @@ int cmd_list_journal(int argc, char *argv[])
|
|||||||
pr_indent_push(&buf,
|
pr_indent_push(&buf,
|
||||||
entry->type == BCH_JSET_ENTRY_log ? 2 : 4);
|
entry->type == BCH_JSET_ENTRY_log ? 2 : 4);
|
||||||
bch2_journal_entry_to_text(&buf, c, entry);
|
bch2_journal_entry_to_text(&buf, c, entry);
|
||||||
printf("%s\n", _buf);
|
printf("%s\n", buf.buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printbuf_exit(&buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
bch2_fs_stop(c);
|
bch2_fs_stop(c);
|
||||||
|
21
cmd_format.c
21
cmd_format.c
@ -237,13 +237,14 @@ int cmd_format(int argc, char *argv[])
|
|||||||
bch2_opt_strs_free(&fs_opt_strs);
|
bch2_opt_strs_free(&fs_opt_strs);
|
||||||
|
|
||||||
if (!quiet) {
|
if (!quiet) {
|
||||||
char buf[4096];
|
struct printbuf buf = PRINTBUF;
|
||||||
struct printbuf out = PBUF(buf);
|
|
||||||
|
|
||||||
out.units = PRINTBUF_UNITS_HUMAN_READABLE;
|
buf.units = PRINTBUF_UNITS_HUMAN_READABLE;
|
||||||
|
|
||||||
bch2_sb_to_text(&PBUF(buf), sb, false, 1 << BCH_SB_FIELD_members);
|
bch2_sb_to_text(&buf, sb, false, 1 << BCH_SB_FIELD_members);
|
||||||
printf("%s", buf);
|
printf("%s", buf.buf);
|
||||||
|
|
||||||
|
printbuf_exit(&buf);
|
||||||
}
|
}
|
||||||
free(sb);
|
free(sb);
|
||||||
|
|
||||||
@ -332,14 +333,14 @@ int cmd_show_super(int argc, char *argv[])
|
|||||||
if (ret)
|
if (ret)
|
||||||
die("Error opening %s: %s", dev, strerror(-ret));
|
die("Error opening %s: %s", dev, strerror(-ret));
|
||||||
|
|
||||||
char buf[4096 << 2];
|
struct printbuf buf = PRINTBUF;
|
||||||
struct printbuf out = PBUF(buf);
|
|
||||||
|
|
||||||
out.units = PRINTBUF_UNITS_HUMAN_READABLE;
|
buf.units = PRINTBUF_UNITS_HUMAN_READABLE;
|
||||||
|
|
||||||
bch2_sb_to_text(&PBUF(buf), sb.sb, print_layout, fields);
|
bch2_sb_to_text(&buf, sb.sb, print_layout, fields);
|
||||||
printf("%s", buf);
|
printf("%s", buf.buf);
|
||||||
|
|
||||||
bch2_free_super(&sb);
|
bch2_free_super(&sb);
|
||||||
|
printbuf_exit(&buf);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
14
cmd_fs.c
14
cmd_fs.c
@ -291,8 +291,7 @@ int fs_usage(void)
|
|||||||
int cmd_fs_usage(int argc, char *argv[])
|
int cmd_fs_usage(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
enum printbuf_units units = PRINTBUF_UNITS_BYTES;
|
enum printbuf_units units = PRINTBUF_UNITS_BYTES;
|
||||||
char _buf[1 << 16];
|
struct printbuf buf = PRINTBUF;
|
||||||
struct printbuf buf;
|
|
||||||
char *fs;
|
char *fs;
|
||||||
int opt;
|
int opt;
|
||||||
|
|
||||||
@ -305,20 +304,19 @@ int cmd_fs_usage(int argc, char *argv[])
|
|||||||
args_shift(optind);
|
args_shift(optind);
|
||||||
|
|
||||||
if (!argc) {
|
if (!argc) {
|
||||||
buf = PBUF(_buf);
|
printbuf_reset(&buf);
|
||||||
buf.units = units;
|
buf.units = units;
|
||||||
fs_usage_to_text(&buf, ".");
|
fs_usage_to_text(&buf, ".");
|
||||||
*buf.pos = 0;
|
printf("%s", buf.buf);
|
||||||
printf("%s", _buf);
|
|
||||||
} else {
|
} else {
|
||||||
while ((fs = arg_pop())) {
|
while ((fs = arg_pop())) {
|
||||||
buf = PBUF(_buf);
|
printbuf_reset(&buf);
|
||||||
buf.units = units;
|
buf.units = units;
|
||||||
fs_usage_to_text(&buf, fs);
|
fs_usage_to_text(&buf, fs);
|
||||||
*buf.pos = 0;
|
printf("%s", buf.buf);
|
||||||
printf("%s", _buf);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printbuf_exit(&buf);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user