1 #ifndef _BCACHE_ERROR_H
2 #define _BCACHE_ERROR_H
4 #include <linux/printk.h>
11 * XXX: separate out errors that indicate on disk data is inconsistent, and flag
18 * Very fatal logic/inconsistency errors: these indicate that we've majorly
19 * screwed up at runtime, i.e. it's not likely that it was just caused by the
20 * data on disk being inconsistent. These BUG():
22 * XXX: audit and convert to inconsistent() checks
25 #define bch2_fs_bug(c, ...) \
27 bch_err(c, __VA_ARGS__); \
31 #define bch2_fs_bug_on(cond, c, ...) \
34 bch2_fs_bug(c, __VA_ARGS__); \
38 * Inconsistency errors: The on disk data is inconsistent. If these occur during
39 * initial recovery, they don't indicate a bug in the running code - we walk all
40 * the metadata before modifying anything. If they occur at runtime, they
41 * indicate either a bug in the running code or (less likely) data is being
42 * silently corrupted under us.
44 * XXX: audit all inconsistent errors and make sure they're all recoverable, in
45 * BCH_ON_ERROR_CONTINUE mode
48 void bch2_inconsistent_error(struct bch_fs *);
50 #define bch2_fs_inconsistent(c, ...) \
52 bch_err(c, __VA_ARGS__); \
53 bch2_inconsistent_error(c); \
56 #define bch2_fs_inconsistent_on(cond, c, ...) \
58 int _ret = !!(cond); \
61 bch2_fs_inconsistent(c, __VA_ARGS__); \
66 * Later we might want to mark only the particular device inconsistent, not the
70 #define bch2_dev_inconsistent(ca, ...) \
72 bch_err(ca, __VA_ARGS__); \
73 bch2_inconsistent_error((ca)->fs); \
76 #define bch2_dev_inconsistent_on(cond, ca, ...) \
78 int _ret = !!(cond); \
81 bch2_dev_inconsistent(ca, __VA_ARGS__); \
86 * Fsck errors: inconsistency errors we detect at mount time, and should ideally
92 BCH_FSCK_ERRORS_NOT_FIXED = 1,
93 BCH_FSCK_REPAIR_UNIMPLEMENTED = 2,
94 BCH_FSCK_REPAIR_IMPOSSIBLE = 3,
95 BCH_FSCK_UNKNOWN_VERSION = 4,
110 struct fsck_err_state {
111 struct list_head list;
117 #define FSCK_CAN_FIX (1 << 0)
118 #define FSCK_CAN_IGNORE (1 << 1)
119 #define FSCK_NEED_FSCK (1 << 2)
121 enum fsck_err_ret bch2_fsck_err(struct bch_fs *,
122 unsigned, const char *, ...);
123 void bch2_flush_fsck_errs(struct bch_fs *);
125 #define __fsck_err(c, _flags, msg, ...) \
127 int _fix = bch2_fsck_err(c, _flags, msg, ##__VA_ARGS__);\
129 if (_fix == FSCK_ERR_EXIT) { \
130 bch_err(c, "Unable to continue, halting"); \
131 ret = BCH_FSCK_ERRORS_NOT_FIXED; \
138 /* These macros return true if error should be fixed: */
140 /* XXX: mark in superblock that filesystem contains errors, if we ignore: */
142 #define __fsck_err_on(cond, c, _flags, ...) \
143 ((cond) ? __fsck_err(c, _flags, ##__VA_ARGS__) : false)
145 #define unfixable_fsck_err_on(cond, c, ...) \
146 __fsck_err_on(cond, c, FSCK_CAN_IGNORE, ##__VA_ARGS__)
148 #define need_fsck_err_on(cond, c, ...) \
149 __fsck_err_on(cond, c, FSCK_CAN_IGNORE|FSCK_NEED_FSCK, ##__VA_ARGS__)
151 #define mustfix_fsck_err(c, ...) \
152 __fsck_err(c, FSCK_CAN_FIX, ##__VA_ARGS__)
154 #define mustfix_fsck_err_on(cond, c, ...) \
155 __fsck_err_on(cond, c, FSCK_CAN_FIX, ##__VA_ARGS__)
157 #define fsck_err_on(cond, c, ...) \
158 __fsck_err_on(cond, c, FSCK_CAN_FIX|FSCK_CAN_IGNORE, ##__VA_ARGS__)
161 * Fatal errors: these don't indicate a bug, but we can't continue running in RW
162 * mode - pretty much just due to metadata IO errors:
165 void bch2_fatal_error(struct bch_fs *);
167 #define bch2_fs_fatal_error(c, ...) \
169 bch_err(c, __VA_ARGS__); \
170 bch2_fatal_error(c); \
173 #define bch2_fs_fatal_err_on(cond, c, ...) \
175 int _ret = !!(cond); \
178 bch2_fs_fatal_error(c, __VA_ARGS__); \
182 #define bch2_dev_fatal_error(ca, ...) \
184 bch_err(ca, __VA_ARGS__); \
185 bch2_fatal_error(c); \
188 #define bch2_dev_fatal_io_error(ca, fmt, ...) \
190 printk_ratelimited(KERN_ERR bch2_fmt((ca)->fs, \
191 "fatal IO error on %s for " fmt), \
192 (ca)->name, ##__VA_ARGS__); \
193 bch2_fatal_error((ca)->fs); \
196 #define bch2_dev_fatal_io_err_on(cond, ca, ...) \
198 int _ret = !!(cond); \
201 bch2_dev_fatal_io_error(ca, __VA_ARGS__); \
206 * Nonfatal IO errors: either recoverable metadata IO (because we have
207 * replicas), or data IO - we need to log it and print out a message, but we
208 * don't (necessarily) want to shut down the fs:
211 void bch2_nonfatal_io_error_work(struct work_struct *);
213 /* Does the error handling without logging a message */
214 void bch2_nonfatal_io_error(struct bch_dev *);
217 #define bch2_fs_nonfatal_io_error(c, ...) \
219 bch_err(c, __VA_ARGS__); \
220 bch2_nonfatal_io_error(c); \
224 /* Logs message and handles the error: */
225 #define bch2_dev_nonfatal_io_error(ca, fmt, ...) \
227 printk_ratelimited(KERN_ERR bch2_fmt((ca)->fs, \
228 "IO error on %s for " fmt), \
229 (ca)->name, ##__VA_ARGS__); \
230 bch2_nonfatal_io_error(ca); \
233 #define bch2_dev_nonfatal_io_err_on(cond, ca, ...) \
235 bool _ret = (cond); \
238 bch2_dev_nonfatal_io_error(ca, __VA_ARGS__); \
244 #define __bcache_io_error(c, fmt, ...) \
245 printk_ratelimited(KERN_ERR bch2_fmt(c, \
246 "IO error: " fmt), ##__VA_ARGS__)
248 #define bcache_io_error(c, bio, fmt, ...) \
250 __bcache_io_error(c, fmt, ##__VA_ARGS__); \
251 (bio)->bi_error = -EIO; \
254 #endif /* _BCACHE_ERROR_H */