1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BCACHEFS_ERROR_H
3 #define _BCACHEFS_ERROR_H
5 #include <linux/list.h>
6 #include <linux/printk.h>
14 * XXX: separate out errors that indicate on disk data is inconsistent, and flag
21 * Inconsistency errors: The on disk data is inconsistent. If these occur during
22 * initial recovery, they don't indicate a bug in the running code - we walk all
23 * the metadata before modifying anything. If they occur at runtime, they
24 * indicate either a bug in the running code or (less likely) data is being
25 * silently corrupted under us.
27 * XXX: audit all inconsistent errors and make sure they're all recoverable, in
28 * BCH_ON_ERROR_CONTINUE mode
31 bool bch2_inconsistent_error(struct bch_fs *);
33 int bch2_topology_error(struct bch_fs *);
35 #define bch2_fs_topology_error(c, ...) \
37 bch_err(c, "btree topology error: " __VA_ARGS__); \
38 bch2_topology_error(c); \
41 #define bch2_fs_inconsistent(c, ...) \
43 bch_err(c, __VA_ARGS__); \
44 bch2_inconsistent_error(c); \
47 #define bch2_fs_inconsistent_on(cond, c, ...) \
49 bool _ret = unlikely(!!(cond)); \
52 bch2_fs_inconsistent(c, __VA_ARGS__); \
57 * Later we might want to mark only the particular device inconsistent, not the
61 #define bch2_dev_inconsistent(ca, ...) \
63 bch_err(ca, __VA_ARGS__); \
64 bch2_inconsistent_error((ca)->fs); \
67 #define bch2_dev_inconsistent_on(cond, ca, ...) \
69 bool _ret = unlikely(!!(cond)); \
72 bch2_dev_inconsistent(ca, __VA_ARGS__); \
77 * When a transaction update discovers or is causing a fs inconsistency, it's
78 * helpful to also dump the pending updates:
80 #define bch2_trans_inconsistent(trans, ...) \
82 bch_err(trans->c, __VA_ARGS__); \
83 bch2_dump_trans_updates(trans); \
84 bch2_inconsistent_error(trans->c); \
87 #define bch2_trans_inconsistent_on(cond, trans, ...) \
89 bool _ret = unlikely(!!(cond)); \
92 bch2_trans_inconsistent(trans, __VA_ARGS__); \
97 * Fsck errors: inconsistency errors we detect at mount time, and should ideally
101 struct fsck_err_state {
102 struct list_head list;
111 #define fsck_err_count(_c, _err) bch2_sb_err_count(_c, BCH_FSCK_ERR_##_err)
113 __printf(4, 5) __cold
114 int bch2_fsck_err(struct bch_fs *,
116 enum bch_sb_error_id,
118 void bch2_flush_fsck_errs(struct bch_fs *);
120 #define __fsck_err(c, _flags, _err_type, ...) \
122 int _ret = bch2_fsck_err(c, _flags, BCH_FSCK_ERR_##_err_type, \
125 if (_ret != -BCH_ERR_fsck_fix && \
126 _ret != -BCH_ERR_fsck_ignore) { \
131 _ret == -BCH_ERR_fsck_fix; \
134 /* These macros return true if error should be fixed: */
136 /* XXX: mark in superblock that filesystem contains errors, if we ignore: */
138 #define __fsck_err_on(cond, c, _flags, _err_type, ...) \
139 (unlikely(cond) ? __fsck_err(c, _flags, _err_type, __VA_ARGS__) : false)
141 #define need_fsck_err_on(cond, c, _err_type, ...) \
142 __fsck_err_on(cond, c, FSCK_CAN_IGNORE|FSCK_NEED_FSCK, _err_type, __VA_ARGS__)
144 #define need_fsck_err(c, _err_type, ...) \
145 __fsck_err(c, FSCK_CAN_IGNORE|FSCK_NEED_FSCK, _err_type, __VA_ARGS__)
147 #define mustfix_fsck_err(c, _err_type, ...) \
148 __fsck_err(c, FSCK_CAN_FIX, _err_type, __VA_ARGS__)
150 #define mustfix_fsck_err_on(cond, c, _err_type, ...) \
151 __fsck_err_on(cond, c, FSCK_CAN_FIX, _err_type, __VA_ARGS__)
153 #define fsck_err(c, _err_type, ...) \
154 __fsck_err(c, FSCK_CAN_FIX|FSCK_CAN_IGNORE, _err_type, __VA_ARGS__)
156 #define fsck_err_on(cond, c, _err_type, ...) \
157 __fsck_err_on(cond, c, FSCK_CAN_FIX|FSCK_CAN_IGNORE, _err_type, __VA_ARGS__)
160 static inline void bch2_bkey_fsck_err(struct bch_fs *c,
161 struct printbuf *err_msg,
162 enum bch_sb_error_id err_type,
163 const char *fmt, ...)
168 prt_vprintf(err_msg, fmt, args);
172 #define bkey_fsck_err(c, _err_msg, _err_type, ...) \
174 prt_printf(_err_msg, __VA_ARGS__); \
175 bch2_sb_error_count(c, BCH_FSCK_ERR_##_err_type); \
176 ret = -BCH_ERR_invalid_bkey; \
180 #define bkey_fsck_err_on(cond, ...) \
182 if (unlikely(cond)) \
183 bkey_fsck_err(__VA_ARGS__); \
187 * Fatal errors: these don't indicate a bug, but we can't continue running in RW
188 * mode - pretty much just due to metadata IO errors:
191 void bch2_fatal_error(struct bch_fs *);
193 #define bch2_fs_fatal_error(c, _msg, ...) \
195 bch_err(c, "%s(): fatal error " _msg, __func__, ##__VA_ARGS__); \
196 bch2_fatal_error(c); \
199 #define bch2_fs_fatal_err_on(cond, c, ...) \
201 bool _ret = unlikely(!!(cond)); \
204 bch2_fs_fatal_error(c, __VA_ARGS__); \
209 * IO errors: either recoverable metadata IO (because we have replicas), or data
210 * IO - we need to log it and print out a message, but we don't (necessarily)
211 * want to shut down the fs:
214 void bch2_io_error_work(struct work_struct *);
216 /* Does the error handling without logging a message */
217 void bch2_io_error(struct bch_dev *, enum bch_member_error_type);
219 #define bch2_dev_io_err_on(cond, ca, _type, ...) \
221 bool _ret = (cond); \
224 bch_err_dev_ratelimited(ca, __VA_ARGS__); \
225 bch2_io_error(ca, _type); \
230 #define bch2_dev_inum_io_err_on(cond, ca, _type, ...) \
232 bool _ret = (cond); \
235 bch_err_inum_offset_ratelimited(ca, __VA_ARGS__); \
236 bch2_io_error(ca, _type); \
241 #endif /* _BCACHEFS_ERROR_H */