Skip to content

Commit 1ece532

Browse files
author
Kent Overstreet
committed
bcachefs: Consistent indentation of multiline fsck errors
Add the new helper printbuf_indent_add_nextline(), and use it in __bch2_fsck_err() to centralize setting the indentation of multiline fsck errors. Signed-off-by: Kent Overstreet <[email protected]>
1 parent a7cdf22 commit 1ece532

20 files changed

+113
-94
lines changed

fs/bcachefs/alloc_background.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -676,8 +676,7 @@ static int __need_discard_or_freespace_err(struct btree_trans *trans,
676676
bch2_bkey_val_to_text(&buf, c, alloc_k);
677677

678678
int ret = __bch2_fsck_err(NULL, trans, flags, err_id,
679-
"bucket incorrectly %sset in %s btree\n"
680-
" %s",
679+
"bucket incorrectly %sset in %s btree\n%s",
681680
set ? "" : "un",
682681
bch2_btree_id_str(btree),
683682
buf.buf);
@@ -1030,7 +1029,7 @@ int bch2_trigger_alloc(struct btree_trans *trans,
10301029
bch2_dev_put(ca);
10311030
return ret;
10321031
invalid_bucket:
1033-
bch2_fs_inconsistent(c, "reference to invalid bucket\n %s",
1032+
bch2_fs_inconsistent(c, "reference to invalid bucket\n%s",
10341033
(bch2_bkey_val_to_text(&buf, c, new.s_c), buf.buf));
10351034
ret = -BCH_ERR_trigger_alloc;
10361035
goto err;
@@ -1204,8 +1203,7 @@ int bch2_check_alloc_key(struct btree_trans *trans,
12041203

12051204
if (fsck_err_on(a->gen != alloc_gen(k, gens_offset),
12061205
trans, bucket_gens_key_wrong,
1207-
"incorrect gen in bucket_gens btree (got %u should be %u)\n"
1208-
" %s",
1206+
"incorrect gen in bucket_gens btree (got %u should be %u)\n%s",
12091207
alloc_gen(k, gens_offset), a->gen,
12101208
(printbuf_reset(&buf),
12111209
bch2_bkey_val_to_text(&buf, c, alloc_k), buf.buf))) {
@@ -1263,7 +1261,7 @@ int bch2_check_alloc_hole_freespace(struct btree_trans *trans,
12631261
if (fsck_err_on(k.k->type != KEY_TYPE_set,
12641262
trans, freespace_hole_missing,
12651263
"hole in alloc btree missing in freespace btree\n"
1266-
" device %llu buckets %llu-%llu",
1264+
"device %llu buckets %llu-%llu",
12671265
freespace_iter->pos.inode,
12681266
freespace_iter->pos.offset,
12691267
end->offset)) {
@@ -1422,7 +1420,7 @@ int bch2_check_discard_freespace_key(struct btree_trans *trans, struct btree_ite
14221420
(state == BCH_DATA_free &&
14231421
genbits != alloc_freespace_genbits(*a))) {
14241422
if (fsck_err(trans, need_discard_freespace_key_bad,
1425-
"%s\n incorrectly set at %s:%llu:%llu:0 (free %u, genbits %llu should be %llu)",
1423+
"%s\nincorrectly set at %s:%llu:%llu:0 (free %u, genbits %llu should be %llu)",
14261424
(bch2_bkey_val_to_text(&buf, c, alloc_k), buf.buf),
14271425
bch2_btree_id_str(iter->btree_id),
14281426
iter->pos.inode,
@@ -1503,7 +1501,7 @@ int bch2_check_bucket_gens_key(struct btree_trans *trans,
15031501
struct bch_dev *ca = bch2_dev_tryget_noerror(c, k.k->p.inode);
15041502
if (!ca) {
15051503
if (fsck_err(trans, bucket_gens_to_invalid_dev,
1506-
"bucket_gens key for invalid device:\n %s",
1504+
"bucket_gens key for invalid device:\n%s",
15071505
(bch2_bkey_val_to_text(&buf, c, k), buf.buf)))
15081506
ret = bch2_btree_delete_at(trans, iter, 0);
15091507
goto out;
@@ -1512,7 +1510,7 @@ int bch2_check_bucket_gens_key(struct btree_trans *trans,
15121510
if (fsck_err_on(end <= ca->mi.first_bucket ||
15131511
start >= ca->mi.nbuckets,
15141512
trans, bucket_gens_to_invalid_buckets,
1515-
"bucket_gens key for invalid buckets:\n %s",
1513+
"bucket_gens key for invalid buckets:\n%s",
15161514
(bch2_bkey_val_to_text(&buf, c, k), buf.buf))) {
15171515
ret = bch2_btree_delete_at(trans, iter, 0);
15181516
goto out;
@@ -1715,8 +1713,7 @@ static int bch2_check_alloc_to_lru_ref(struct btree_trans *trans,
17151713

17161714
if (fsck_err_on(!a->io_time[READ],
17171715
trans, alloc_key_cached_but_read_time_zero,
1718-
"cached bucket with read_time 0\n"
1719-
" %s",
1716+
"cached bucket with read_time 0\n%s",
17201717
(printbuf_reset(&buf),
17211718
bch2_bkey_val_to_text(&buf, c, alloc_k), buf.buf))) {
17221719
struct bkey_i_alloc_v4 *a_mut =

fs/bcachefs/backpointers.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -210,19 +210,19 @@ static int backpointer_target_not_found(struct btree_trans *trans,
210210
if (ret)
211211
return ret;
212212

213-
prt_printf(&buf, "backpointer doesn't match %s it points to:\n ",
213+
prt_printf(&buf, "backpointer doesn't match %s it points to:\n",
214214
bp.v->level ? "btree node" : "extent");
215215
bch2_bkey_val_to_text(&buf, c, bp.s_c);
216216

217-
prt_printf(&buf, "\n ");
217+
prt_newline(&buf);
218218
bch2_bkey_val_to_text(&buf, c, target_k);
219219

220220
struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(target_k);
221221
const union bch_extent_entry *entry;
222222
struct extent_ptr_decoded p;
223223
bkey_for_each_ptr_decode(target_k.k, ptrs, p, entry)
224224
if (p.ptr.dev == bp.k->p.inode) {
225-
prt_printf(&buf, "\n ");
225+
prt_newline(&buf);
226226
struct bkey_i_backpointer bp2;
227227
bch2_extent_ptr_to_bp(c, bp.v->btree_id, bp.v->level, target_k, p, entry, &bp2);
228228
bch2_bkey_val_to_text(&buf, c, bkey_i_to_s_c(&bp2.k_i));
@@ -443,12 +443,11 @@ static int check_extent_checksum(struct btree_trans *trans,
443443
if (ret)
444444
goto err;
445445

446-
prt_str(&buf, "extents pointing to same space, but first extent checksum bad:");
447-
prt_printf(&buf, "\n ");
446+
prt_printf(&buf, "extents pointing to same space, but first extent checksum bad:\n");
448447
bch2_btree_id_to_text(&buf, btree);
449448
prt_str(&buf, " ");
450449
bch2_bkey_val_to_text(&buf, c, extent);
451-
prt_printf(&buf, "\n ");
450+
prt_newline(&buf);
452451
bch2_btree_id_to_text(&buf, o_btree);
453452
prt_str(&buf, " ");
454453
bch2_bkey_val_to_text(&buf, c, extent2);
@@ -539,9 +538,9 @@ static int check_bp_exists(struct btree_trans *trans,
539538

540539
if (bch2_extents_match(orig_k, other_extent)) {
541540
printbuf_reset(&buf);
542-
prt_printf(&buf, "duplicate versions of same extent, deleting smaller\n ");
541+
prt_printf(&buf, "duplicate versions of same extent, deleting smaller\n");
543542
bch2_bkey_val_to_text(&buf, c, orig_k);
544-
prt_str(&buf, "\n ");
543+
prt_newline(&buf);
545544
bch2_bkey_val_to_text(&buf, c, other_extent);
546545
bch_err(c, "%s", buf.buf);
547546

@@ -580,20 +579,20 @@ static int check_bp_exists(struct btree_trans *trans,
580579
}
581580

582581
printbuf_reset(&buf);
583-
prt_printf(&buf, "duplicate extents pointing to same space on dev %llu\n ", bp->k.p.inode);
582+
prt_printf(&buf, "duplicate extents pointing to same space on dev %llu\n", bp->k.p.inode);
584583
bch2_bkey_val_to_text(&buf, c, orig_k);
585-
prt_str(&buf, "\n ");
584+
prt_newline(&buf);
586585
bch2_bkey_val_to_text(&buf, c, other_extent);
587586
bch_err(c, "%s", buf.buf);
588587
ret = -BCH_ERR_fsck_repair_unimplemented;
589588
goto err;
590589
missing:
591590
printbuf_reset(&buf);
592-
prt_str(&buf, "missing backpointer\n for: ");
591+
prt_str(&buf, "missing backpointer\nfor: ");
593592
bch2_bkey_val_to_text(&buf, c, orig_k);
594-
prt_printf(&buf, "\n want: ");
593+
prt_printf(&buf, "\nwant: ");
595594
bch2_bkey_val_to_text(&buf, c, bkey_i_to_s_c(&bp->k_i));
596-
prt_printf(&buf, "\n got: ");
595+
prt_printf(&buf, "\ngot: ");
597596
bch2_bkey_val_to_text(&buf, c, bp_k);
598597

599598
if (fsck_err(trans, ptr_to_missing_backpointer, "%s", buf.buf))

fs/bcachefs/btree_cache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1417,7 +1417,7 @@ void __bch2_btree_pos_to_text(struct printbuf *out, struct bch_fs *c,
14171417
prt_printf(out, "%u", r->level);
14181418
else
14191419
prt_printf(out, "(unknown)");
1420-
prt_printf(out, "\n ");
1420+
prt_newline(out);
14211421

14221422
bch2_bkey_val_to_text(out, c, k);
14231423
}

fs/bcachefs/btree_gc.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,15 @@ static int btree_check_node_boundaries(struct btree_trans *trans, struct btree *
213213

214214
prt_printf(&buf, " at ");
215215
bch2_btree_id_level_to_text(&buf, b->c.btree_id, b->c.level);
216-
prt_printf(&buf, ":\n parent: ");
216+
prt_printf(&buf, ":\nparent: ");
217217
bch2_bkey_val_to_text(&buf, c, bkey_i_to_s_c(&b->key));
218218

219219
if (prev) {
220-
prt_printf(&buf, "\n prev: ");
220+
prt_printf(&buf, "\nprev: ");
221221
bch2_bkey_val_to_text(&buf, c, bkey_i_to_s_c(&prev->key));
222222
}
223223

224-
prt_str(&buf, "\n next: ");
224+
prt_str(&buf, "\nnext: ");
225225
bch2_bkey_val_to_text(&buf, c, bkey_i_to_s_c(&cur->key));
226226

227227
if (bpos_lt(expected_start, cur->data->min_key)) { /* gap */
@@ -280,12 +280,12 @@ static int btree_repair_node_end(struct btree_trans *trans, struct btree *b,
280280
if (bpos_eq(child->key.k.p, b->key.k.p))
281281
return 0;
282282

283-
prt_printf(&buf, " at ");
283+
prt_printf(&buf, "\nat: ");
284284
bch2_btree_id_level_to_text(&buf, b->c.btree_id, b->c.level);
285-
prt_printf(&buf, ":\n parent: ");
285+
prt_printf(&buf, "\nparent: ");
286286
bch2_bkey_val_to_text(&buf, c, bkey_i_to_s_c(&b->key));
287287

288-
prt_str(&buf, "\n child: ");
288+
prt_str(&buf, "\nchild: ");
289289
bch2_bkey_val_to_text(&buf, c, bkey_i_to_s_c(&child->key));
290290

291291
if (mustfix_fsck_err(trans, btree_node_topology_bad_max_key,
@@ -351,8 +351,7 @@ static int bch2_btree_repair_topology_recurse(struct btree_trans *trans, struct
351351

352352
if (mustfix_fsck_err_on(bch2_err_matches(ret, EIO),
353353
trans, btree_node_read_error,
354-
"Topology repair: unreadable btree node at\n"
355-
" %s",
354+
"Topology repair: unreadable btree node at\n%s",
356355
buf.buf)) {
357356
bch2_btree_node_evict(trans, cur_k.k);
358357
cur = NULL;
@@ -612,15 +611,15 @@ static int bch2_gc_mark_key(struct btree_trans *trans, enum btree_id btree_id,
612611
if (fsck_err_on(btree_id != BTREE_ID_accounting &&
613612
k.k->bversion.lo > atomic64_read(&c->key_version),
614613
trans, bkey_version_in_future,
615-
"key version number higher than recorded %llu\n %s",
614+
"key version number higher than recorded %llu\n%s",
616615
atomic64_read(&c->key_version),
617616
(bch2_bkey_val_to_text(&buf, c, k), buf.buf)))
618617
atomic64_set(&c->key_version, k.k->bversion.lo);
619618
}
620619

621620
if (mustfix_fsck_err_on(level && !bch2_dev_btree_bitmap_marked(c, k),
622621
trans, btree_bitmap_not_marked,
623-
"btree ptr not marked in member info btree allocated bitmap\n %s",
622+
"btree ptr not marked in member info btree allocated bitmap\n%s",
624623
(printbuf_reset(&buf),
625624
bch2_bkey_val_to_text(&buf, c, k),
626625
buf.buf))) {

fs/bcachefs/btree_io.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,6 @@ static void btree_err_msg(struct printbuf *out, struct bch_fs *c,
525525
prt_printf(out, "at btree ");
526526
bch2_btree_pos_to_text(out, c, b);
527527

528-
printbuf_indent_add(out, 2);
529-
530528
prt_printf(out, "\nnode offset %u/%u",
531529
b->written, btree_ptr_sectors_written(bkey_i_to_s_c(&b->key)));
532530
if (i)
@@ -817,7 +815,7 @@ static int validate_bset(struct bch_fs *c, struct bch_dev *ca,
817815
-BCH_ERR_btree_node_read_err_bad_node,
818816
c, ca, b, i, NULL,
819817
btree_node_bad_format,
820-
"invalid bkey format: %s\n %s", buf1.buf,
818+
"invalid bkey format: %s\n%s", buf1.buf,
821819
(printbuf_reset(&buf2),
822820
bch2_bkey_format_to_text(&buf2, &bn->format), buf2.buf));
823821
printbuf_reset(&buf1);

fs/bcachefs/btree_update_interior.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,13 @@ int bch2_btree_node_check_topology(struct btree_trans *trans, struct btree *b)
9797
bch2_topology_error(c);
9898

9999
printbuf_reset(&buf);
100-
prt_str(&buf, "end of prev node doesn't match start of next node\n in ");
100+
prt_str(&buf, "end of prev node doesn't match start of next node\nin ");
101101
bch2_btree_id_level_to_text(&buf, b->c.btree_id, b->c.level);
102102
prt_str(&buf, " node ");
103103
bch2_bkey_val_to_text(&buf, c, bkey_i_to_s_c(&b->key));
104-
prt_str(&buf, "\n prev ");
104+
prt_str(&buf, "\nprev ");
105105
bch2_bkey_val_to_text(&buf, c, bkey_i_to_s_c(prev.k));
106-
prt_str(&buf, "\n next ");
106+
prt_str(&buf, "\nnext ");
107107
bch2_bkey_val_to_text(&buf, c, k);
108108

109109
log_fsck_err(trans, btree_node_topology_bad_min_key, "%s", buf.buf);
@@ -118,7 +118,7 @@ int bch2_btree_node_check_topology(struct btree_trans *trans, struct btree *b)
118118
bch2_topology_error(c);
119119

120120
printbuf_reset(&buf);
121-
prt_str(&buf, "empty interior node\n in ");
121+
prt_str(&buf, "empty interior node\nin ");
122122
bch2_btree_id_level_to_text(&buf, b->c.btree_id, b->c.level);
123123
prt_str(&buf, " node ");
124124
bch2_bkey_val_to_text(&buf, c, bkey_i_to_s_c(&b->key));
@@ -129,11 +129,11 @@ int bch2_btree_node_check_topology(struct btree_trans *trans, struct btree *b)
129129
bch2_topology_error(c);
130130

131131
printbuf_reset(&buf);
132-
prt_str(&buf, "last child node doesn't end at end of parent node\n in ");
132+
prt_str(&buf, "last child node doesn't end at end of parent node\nin ");
133133
bch2_btree_id_level_to_text(&buf, b->c.btree_id, b->c.level);
134134
prt_str(&buf, " node ");
135135
bch2_bkey_val_to_text(&buf, c, bkey_i_to_s_c(&b->key));
136-
prt_str(&buf, "\n last key ");
136+
prt_str(&buf, "\nlast key ");
137137
bch2_bkey_val_to_text(&buf, c, bkey_i_to_s_c(prev.k));
138138

139139
log_fsck_err(trans, btree_node_topology_bad_max_key, "%s", buf.buf);

fs/bcachefs/disk_accounting.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ static int bch2_disk_accounting_validate_late(struct btree_trans *trans,
646646

647647
if (fsck_err_on(!bch2_replicas_marked_locked(c, &r.e),
648648
trans, accounting_replicas_not_marked,
649-
"accounting not marked in superblock replicas\n %s",
649+
"accounting not marked in superblock replicas\n%s",
650650
(printbuf_reset(&buf),
651651
bch2_accounting_key_to_text(&buf, &acc),
652652
buf.buf))) {
@@ -676,7 +676,7 @@ static int bch2_disk_accounting_validate_late(struct btree_trans *trans,
676676
return ret;
677677
invalid_device:
678678
if (fsck_err(trans, accounting_to_invalid_device,
679-
"accounting entry points to invalid device %i\n %s",
679+
"accounting entry points to invalid device %i\n%s",
680680
invalid_dev,
681681
(printbuf_reset(&buf),
682682
bch2_accounting_key_to_text(&buf, &acc),

fs/bcachefs/ec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ static int mark_stripe_bucket(struct btree_trans *trans,
320320

321321
if (flags & BTREE_TRIGGER_gc) {
322322
struct bucket *g = gc_bucket(ca, bucket.offset);
323-
if (bch2_fs_inconsistent_on(!g, c, "reference to invalid bucket on device %u\n %s",
323+
if (bch2_fs_inconsistent_on(!g, c, "reference to invalid bucket on device %u\n%s",
324324
ptr->dev,
325325
(bch2_bkey_val_to_text(&buf, c, s.s_c), buf.buf))) {
326326
ret = -BCH_ERR_mark_stripe;

fs/bcachefs/error.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,13 @@ int __bch2_fsck_err(struct bch_fs *c,
305305

306306
bch2_sb_error_count(c, err);
307307

308+
printbuf_indent_add_nextline(out, 2);
309+
310+
#ifdef BCACHEFS_LOG_PREFIX
311+
if (strncmp(fmt, "bcachefs", 8))
312+
prt_printf(out, bch2_log_msg(c, ""));
313+
#endif
314+
308315
va_start(args, fmt);
309316
prt_vprintf(out, fmt, args);
310317
va_end(args);
@@ -354,11 +361,6 @@ int __bch2_fsck_err(struct bch_fs *c,
354361
s->nr++;
355362
}
356363

357-
#ifdef BCACHEFS_LOG_PREFIX
358-
if (!strncmp(fmt, "bcachefs:", 9))
359-
prt_printf(out, bch2_log_msg(c, ""));
360-
#endif
361-
362364
if ((flags & FSCK_AUTOFIX) &&
363365
(c->opts.errors == BCH_ON_ERROR_continue ||
364366
c->opts.errors == BCH_ON_ERROR_fix_safe)) {
@@ -435,18 +437,22 @@ int __bch2_fsck_err(struct bch_fs *c,
435437
print = true;
436438
}
437439
print:
440+
prt_newline(out);
441+
442+
if (inconsistent)
443+
bch2_inconsistent_error(c);
444+
else if (exiting)
445+
prt_printf(out, "Unable to continue, halting\n");
446+
else if (suppressing)
447+
prt_printf(out, "Ratelimiting new instances of previous error\n");
448+
438449
if (print) {
439450
if (bch2_fs_stdio_redirect(c))
440451
bch2_print(c, "%s\n", out->buf);
441452
else
442453
bch2_print_string_as_lines(KERN_ERR, out->buf);
443454
}
444455

445-
if (exiting)
446-
bch_err(c, "Unable to continue, halting");
447-
else if (suppressing)
448-
bch_err(c, "Ratelimiting new instances of previous error");
449-
450456
if (s)
451457
s->ret = ret;
452458

@@ -514,7 +520,7 @@ int __bch2_bkey_fsck_err(struct bch_fs *c,
514520
prt_printf(&buf, " level=%u: ", from.level);
515521

516522
bch2_bkey_val_to_text(&buf, c, k);
517-
prt_str(&buf, "\n ");
523+
prt_newline(&buf);
518524

519525
va_list args;
520526
va_start(args, fmt);
@@ -536,7 +542,7 @@ void bch2_flush_fsck_errs(struct bch_fs *c)
536542

537543
list_for_each_entry_safe(s, n, &c->fsck_error_msgs, list) {
538544
if (s->ratelimited && s->last_msg)
539-
bch_err(c, "Saw %llu errors like:\n %s", s->nr, s->last_msg);
545+
bch_err(c, "Saw %llu errors like:\n %s", s->nr, s->last_msg);
540546

541547
list_del(&s->list);
542548
kfree(s->last_msg);

fs/bcachefs/fs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ static struct bch_inode_info *bch2_lookup_trans(struct btree_trans *trans,
673673
* back to this dirent
674674
*/
675675
bch2_fs_inconsistent_on(bch2_err_matches(ret, ENOENT),
676-
c, "dirent to missing inode:\n %s",
676+
c, "dirent to missing inode:\n%s",
677677
(bch2_bkey_val_to_text(&buf, c, d.s_c), buf.buf));
678678
if (ret)
679679
goto err;

0 commit comments

Comments
 (0)