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>
13 * XXX: separate out errors that indicate on disk data is inconsistent, and flag
20 * Very fatal logic/inconsistency errors: these indicate that we've majorly
21 * screwed up at runtime, i.e. it's not likely that it was just caused by the
22 * data on disk being inconsistent. These BUG():
24 * XXX: audit and convert to inconsistent() checks
27 #define bch2_fs_bug(c, ...) \
29 bch_err(c, __VA_ARGS__); \
33 #define bch2_fs_bug_on(cond, c, ...) \
36 bch2_fs_bug(c, __VA_ARGS__); \
40 * Inconsistency errors: The on disk data is inconsistent. If these occur during
41 * initial recovery, they don't indicate a bug in the running code - we walk all
42 * the metadata before modifying anything. If they occur at runtime, they
43 * indicate either a bug in the running code or (less likely) data is being
44 * silently corrupted under us.
46 * XXX: audit all inconsistent errors and make sure they're all recoverable, in
47 * BCH_ON_ERROR_CONTINUE mode
50 bool bch2_inconsistent_error(struct bch_fs *);
52 #define bch2_fs_inconsistent(c, ...) \
54 bch_err(c, __VA_ARGS__); \
55 bch2_inconsistent_error(c); \
58 #define bch2_fs_inconsistent_on(cond, c, ...) \
60 int _ret = !!(cond); \
63 bch2_fs_inconsistent(c, __VA_ARGS__); \
68 * Later we might want to mark only the particular device inconsistent, not the
72 #define bch2_dev_inconsistent(ca, ...) \
74 bch_err(ca, __VA_ARGS__); \
75 bch2_inconsistent_error((ca)->fs); \
78 #define bch2_dev_inconsistent_on(cond, ca, ...) \
80 int _ret = !!(cond); \
83 bch2_dev_inconsistent(ca, __VA_ARGS__); \
88 * Fsck errors: inconsistency errors we detect at mount time, and should ideally
94 BCH_FSCK_ERRORS_NOT_FIXED = 1,
95 BCH_FSCK_REPAIR_UNIMPLEMENTED = 2,
96 BCH_FSCK_REPAIR_IMPOSSIBLE = 3,
97 BCH_FSCK_UNKNOWN_VERSION = 4,
113 struct fsck_err_state {
114 struct list_head list;
120 #define FSCK_CAN_FIX (1 << 0)
121 #define FSCK_CAN_IGNORE (1 << 1)
122 #define FSCK_NEED_FSCK (1 << 2)
124 enum fsck_err_ret bch2_fsck_err(struct bch_fs *,
125 unsigned, const char *, ...);
126 void bch2_flush_fsck_errs(struct bch_fs *);
128 #define __fsck_err(c, _flags, msg, ...) \
130 int _fix = bch2_fsck_err(c, _flags, msg, ##__VA_ARGS__);\
132 if (_fix == FSCK_ERR_EXIT) { \
133 bch_err(c, "Unable to continue, halting"); \
134 ret = BCH_FSCK_ERRORS_NOT_FIXED; \
141 /* These macros return true if error should be fixed: */
143 /* XXX: mark in superblock that filesystem contains errors, if we ignore: */
145 #define __fsck_err_on(cond, c, _flags, ...) \
146 ((cond) ? __fsck_err(c, _flags, ##__VA_ARGS__) : false)
148 #define need_fsck_err_on(cond, c, ...) \
149 __fsck_err_on(cond, c, FSCK_CAN_IGNORE|FSCK_NEED_FSCK, ##__VA_ARGS__)
151 #define need_fsck_err(c, ...) \
152 __fsck_err(c, FSCK_CAN_IGNORE|FSCK_NEED_FSCK, ##__VA_ARGS__)
154 #define mustfix_fsck_err(c, ...) \
155 __fsck_err(c, FSCK_CAN_FIX, ##__VA_ARGS__)
157 #define mustfix_fsck_err_on(cond, c, ...) \
158 __fsck_err_on(cond, c, FSCK_CAN_FIX, ##__VA_ARGS__)
160 #define fsck_err(c, ...) \
161 __fsck_err(c, FSCK_CAN_FIX|FSCK_CAN_IGNORE, ##__VA_ARGS__)
163 #define fsck_err_on(cond, c, ...) \
164 __fsck_err_on(cond, c, FSCK_CAN_FIX|FSCK_CAN_IGNORE, ##__VA_ARGS__)
167 * Fatal errors: these don't indicate a bug, but we can't continue running in RW
168 * mode - pretty much just due to metadata IO errors:
171 void bch2_fatal_error(struct bch_fs *);
173 #define bch2_fs_fatal_error(c, ...) \
175 bch_err(c, __VA_ARGS__); \
176 bch2_fatal_error(c); \
179 #define bch2_fs_fatal_err_on(cond, c, ...) \
181 int _ret = !!(cond); \
184 bch2_fs_fatal_error(c, __VA_ARGS__); \
189 * IO errors: either recoverable metadata IO (because we have replicas), or data
190 * IO - we need to log it and print out a message, but we don't (necessarily)
191 * want to shut down the fs:
194 void bch2_io_error_work(struct work_struct *);
196 /* Does the error handling without logging a message */
197 void bch2_io_error(struct bch_dev *);
199 /* Logs message and handles the error: */
200 #define bch2_dev_io_error(ca, fmt, ...) \
202 printk_ratelimited(KERN_ERR bch2_fmt((ca)->fs, \
203 "IO error on %s for " fmt), \
204 (ca)->name, ##__VA_ARGS__); \
208 #define bch2_dev_io_err_on(cond, ca, ...) \
210 bool _ret = (cond); \
213 bch2_dev_io_error(ca, __VA_ARGS__); \
219 #define __bcache_io_error(c, fmt, ...) \
220 printk_ratelimited(KERN_ERR bch2_fmt(c, \
221 "IO error: " fmt), ##__VA_ARGS__)
223 #define bcache_io_error(c, bio, fmt, ...) \
225 __bcache_io_error(c, fmt, ##__VA_ARGS__); \
226 (bio)->bi_status = BLK_STS_IOERR; \
229 #endif /* _BCACHEFS_ERROR_H */