11
11
12
12
#define FSCK_ERR_RATELIMIT_NR 10
13
13
14
- bool bch2_inconsistent_error (struct bch_fs * c )
14
+ void bch2_log_msg_start (struct bch_fs * c , struct printbuf * out )
15
+ {
16
+ printbuf_indent_add_nextline (out , 2 );
17
+
18
+ #ifdef BCACHEFS_LOG_PREFIX
19
+ prt_printf (out , bch2_log_msg (c , "" ));
20
+ #endif
21
+ }
22
+
23
+ bool __bch2_inconsistent_error (struct bch_fs * c , struct printbuf * out )
15
24
{
16
25
set_bit (BCH_FS_error , & c -> flags );
17
26
@@ -21,8 +30,8 @@ bool bch2_inconsistent_error(struct bch_fs *c)
21
30
case BCH_ON_ERROR_fix_safe :
22
31
case BCH_ON_ERROR_ro :
23
32
if (bch2_fs_emergency_read_only (c ))
24
- bch_err ( c , "inconsistency detected - emergency read only at journal seq %llu" ,
25
- journal_cur_seq (& c -> journal ));
33
+ prt_printf ( out , "inconsistency detected - emergency read only at journal seq %llu\n " ,
34
+ journal_cur_seq (& c -> journal ));
26
35
return true;
27
36
case BCH_ON_ERROR_panic :
28
37
panic (bch2_fmt (c , "panic after error" ));
@@ -32,6 +41,56 @@ bool bch2_inconsistent_error(struct bch_fs *c)
32
41
}
33
42
}
34
43
44
+ bool bch2_inconsistent_error (struct bch_fs * c )
45
+ {
46
+ struct printbuf buf = PRINTBUF ;
47
+ printbuf_indent_add_nextline (& buf , 2 );
48
+
49
+ bool ret = __bch2_inconsistent_error (c , & buf );
50
+ if (ret )
51
+ bch_err (c , "%s" , buf .buf );
52
+ printbuf_exit (& buf );
53
+ return ret ;
54
+ }
55
+
56
+ __printf (3 , 0 )
57
+ static bool bch2_fs_trans_inconsistent (struct bch_fs * c , struct btree_trans * trans ,
58
+ const char * fmt , va_list args )
59
+ {
60
+ struct printbuf buf = PRINTBUF ;
61
+
62
+ bch2_log_msg_start (c , & buf );
63
+
64
+ prt_vprintf (& buf , fmt , args );
65
+ prt_newline (& buf );
66
+
67
+ if (trans )
68
+ bch2_trans_updates_to_text (& buf , trans );
69
+ bool ret = __bch2_inconsistent_error (c , & buf );
70
+ bch2_print_string_as_lines (KERN_ERR , buf .buf );
71
+
72
+ printbuf_exit (& buf );
73
+ return ret ;
74
+ }
75
+
76
+ bool bch2_fs_inconsistent (struct bch_fs * c , const char * fmt , ...)
77
+ {
78
+ va_list args ;
79
+ va_start (args , fmt );
80
+ bool ret = bch2_fs_trans_inconsistent (c , NULL , fmt , args );
81
+ va_end (args );
82
+ return ret ;
83
+ }
84
+
85
+ bool bch2_trans_inconsistent (struct btree_trans * trans , const char * fmt , ...)
86
+ {
87
+ va_list args ;
88
+ va_start (args , fmt );
89
+ bool ret = bch2_fs_trans_inconsistent (trans -> c , trans , fmt , args );
90
+ va_end (args );
91
+ return ret ;
92
+ }
93
+
35
94
int bch2_topology_error (struct bch_fs * c )
36
95
{
37
96
set_bit (BCH_FS_topology_error , & c -> flags );
@@ -44,6 +103,31 @@ int bch2_topology_error(struct bch_fs *c)
44
103
}
45
104
}
46
105
106
+ int __bch2_topology_error (struct bch_fs * c , struct printbuf * out )
107
+ {
108
+ prt_printf (out , "btree topology error: " );
109
+
110
+ return bch2_topology_error (c );
111
+ }
112
+
113
+ int bch2_fs_topology_error (struct bch_fs * c , const char * fmt , ...)
114
+ {
115
+ struct printbuf buf = PRINTBUF ;
116
+
117
+ bch2_log_msg_start (c , & buf );
118
+
119
+ va_list args ;
120
+ va_start (args , fmt );
121
+ prt_vprintf (& buf , fmt , args );
122
+ va_end (args );
123
+
124
+ int ret = __bch2_topology_error (c , & buf );
125
+ bch2_print_string_as_lines (KERN_ERR , buf .buf );
126
+
127
+ printbuf_exit (& buf );
128
+ return ret ;
129
+ }
130
+
47
131
void bch2_fatal_error (struct bch_fs * c )
48
132
{
49
133
if (bch2_fs_emergency_read_only (c ))
@@ -379,6 +463,7 @@ int __bch2_fsck_err(struct bch_fs *c,
379
463
!(flags & (FSCK_CAN_FIX |FSCK_CAN_IGNORE ))) {
380
464
prt_str (out , ", shutting down" );
381
465
inconsistent = true;
466
+ print = true;
382
467
ret = - BCH_ERR_fsck_errors_not_fixed ;
383
468
} else if (flags & FSCK_CAN_FIX ) {
384
469
prt_str (out , ", " );
@@ -440,25 +525,27 @@ int __bch2_fsck_err(struct bch_fs *c,
440
525
prt_newline (out );
441
526
442
527
if (inconsistent )
443
- bch2_inconsistent_error ( c );
528
+ __bch2_inconsistent_error ( c , out );
444
529
else if (exiting )
445
530
prt_printf (out , "Unable to continue, halting\n" );
446
531
else if (suppressing )
447
532
prt_printf (out , "Ratelimiting new instances of previous error\n" );
448
533
449
534
if (print ) {
535
+ /* possibly strip an empty line, from printbuf_indent_add */
536
+ while (out -> pos && out -> buf [out -> pos - 1 ] == ' ' )
537
+ -- out -> pos ;
538
+ printbuf_nul_terminate (out );
539
+
450
540
if (bch2_fs_stdio_redirect (c ))
451
- bch2_print (c , "%s\n " , out -> buf );
541
+ bch2_print (c , "%s" , out -> buf );
452
542
else
453
543
bch2_print_string_as_lines (KERN_ERR , out -> buf );
454
544
}
455
545
456
546
if (s )
457
547
s -> ret = ret ;
458
548
459
- if (inconsistent )
460
- bch2_inconsistent_error (c );
461
-
462
549
/*
463
550
* We don't yet track whether the filesystem currently has errors, for
464
551
* log_fsck_err()s: that would require us to track for every error type
@@ -527,9 +614,7 @@ int __bch2_bkey_fsck_err(struct bch_fs *c,
527
614
prt_vprintf (& buf , fmt , args );
528
615
va_end (args );
529
616
530
- prt_str (& buf , ": delete?" );
531
-
532
- int ret = __bch2_fsck_err (c , NULL , fsck_flags , err , "%s" , buf .buf );
617
+ int ret = __bch2_fsck_err (c , NULL , fsck_flags , err , "%s, delete?" , buf .buf );
533
618
printbuf_exit (& buf );
534
619
return ret ;
535
620
}
0 commit comments