1 #ifndef _BCACHEFS_ERROR_H
2 #define _BCACHEFS_ERROR_H
4 #include <linux/list.h>
5 #include <linux/printk.h>
12 * XXX: separate out errors that indicate on disk data is inconsistent, and flag
19 * Very fatal logic/inconsistency errors: these indicate that we've majorly
20 * screwed up at runtime, i.e. it's not likely that it was just caused by the
21 * data on disk being inconsistent. These BUG():
23 * XXX: audit and convert to inconsistent() checks
26 #define bch2_fs_bug(c, ...) \
28 bch_err(c, __VA_ARGS__); \
32 #define bch2_fs_bug_on(cond, c, ...) \
35 bch2_fs_bug(c, __VA_ARGS__); \
39 * Inconsistency errors: The on disk data is inconsistent. If these occur during
40 * initial recovery, they don't indicate a bug in the running code - we walk all
41 * the metadata before modifying anything. If they occur at runtime, they
42 * indicate either a bug in the running code or (less likely) data is being
43 * silently corrupted under us.
45 * XXX: audit all inconsistent errors and make sure they're all recoverable, in
46 * BCH_ON_ERROR_CONTINUE mode
49 bool bch2_inconsistent_error(struct bch_fs *);
51 #define bch2_fs_inconsistent(c, ...) \
53 bch_err(c, __VA_ARGS__); \
54 bch2_inconsistent_error(c); \
57 #define bch2_fs_inconsistent_on(cond, c, ...) \
59 int _ret = !!(cond); \
62 bch2_fs_inconsistent(c, __VA_ARGS__); \
67 * Later we might want to mark only the particular device inconsistent, not the
71 #define bch2_dev_inconsistent(ca, ...) \
73 bch_err(ca, __VA_ARGS__); \
74 bch2_inconsistent_error((ca)->fs); \
77 #define bch2_dev_inconsistent_on(cond, ca, ...) \
79 int _ret = !!(cond); \
82 bch2_dev_inconsistent(ca, __VA_ARGS__); \
87 * Fsck errors: inconsistency errors we detect at mount time, and should ideally
93 BCH_FSCK_ERRORS_NOT_FIXED = 1,
94 BCH_FSCK_REPAIR_UNIMPLEMENTED = 2,
95 BCH_FSCK_REPAIR_IMPOSSIBLE = 3,
96 BCH_FSCK_UNKNOWN_VERSION = 4,
112 struct fsck_err_state {
113 struct list_head list;
119 #define FSCK_CAN_FIX (1 << 0)
120 #define FSCK_CAN_IGNORE (1 << 1)
121 #define FSCK_NEED_FSCK (1 << 2)
123 enum fsck_err_ret bch2_fsck_err(struct bch_fs *,
124 unsigned, const char *, ...);
125 void bch2_flush_fsck_errs(struct bch_fs *);
127 #define __fsck_err(c, _flags, msg, ...) \
129 int _fix = bch2_fsck_err(c, _flags, msg, ##__VA_ARGS__);\
131 if (_fix == FSCK_ERR_EXIT) { \
132 bch_err(c, "Unable to continue, halting"); \
133 ret = BCH_FSCK_ERRORS_NOT_FIXED; \
140 /* These macros return true if error should be fixed: */
142 /* XXX: mark in superblock that filesystem contains errors, if we ignore: */
144 #define __fsck_err_on(cond, c, _flags, ...) \
145 ((cond) ? __fsck_err(c, _flags, ##__VA_ARGS__) : false)
147 #define need_fsck_err_on(cond, c, ...) \
148 __fsck_err_on(cond, c, FSCK_CAN_IGNORE|FSCK_NEED_FSCK, ##__VA_ARGS__)
150 #define need_fsck_err(c, ...) \
151 __fsck_err(c, FSCK_CAN_IGNORE|FSCK_NEED_FSCK, ##__VA_ARGS__)
153 #define mustfix_fsck_err(c, ...) \
154 __fsck_err(c, FSCK_CAN_FIX, ##__VA_ARGS__)
156 #define mustfix_fsck_err_on(cond, c, ...) \
157 __fsck_err_on(cond, c, FSCK_CAN_FIX, ##__VA_ARGS__)
159 #define fsck_err(c, ...) \
160 __fsck_err(c, FSCK_CAN_FIX|FSCK_CAN_IGNORE, ##__VA_ARGS__)
162 #define fsck_err_on(cond, c, ...) \
163 __fsck_err_on(cond, c, FSCK_CAN_FIX|FSCK_CAN_IGNORE, ##__VA_ARGS__)
166 * Fatal errors: these don't indicate a bug, but we can't continue running in RW
167 * mode - pretty much just due to metadata IO errors:
170 void bch2_fatal_error(struct bch_fs *);
172 #define bch2_fs_fatal_error(c, ...) \
174 bch_err(c, __VA_ARGS__); \
175 bch2_fatal_error(c); \
178 #define bch2_fs_fatal_err_on(cond, c, ...) \
180 int _ret = !!(cond); \
183 bch2_fs_fatal_error(c, __VA_ARGS__); \
188 * IO errors: either recoverable metadata IO (because we have replicas), or data
189 * IO - we need to log it and print out a message, but we don't (necessarily)
190 * want to shut down the fs:
193 void bch2_io_error_work(struct work_struct *);
195 /* Does the error handling without logging a message */
196 void bch2_io_error(struct bch_dev *);
198 /* Logs message and handles the error: */
199 #define bch2_dev_io_error(ca, fmt, ...) \
201 printk_ratelimited(KERN_ERR bch2_fmt((ca)->fs, \
202 "IO error on %s for " fmt), \
203 (ca)->name, ##__VA_ARGS__); \
207 #define bch2_dev_io_err_on(cond, ca, ...) \
209 bool _ret = (cond); \
212 bch2_dev_io_error(ca, __VA_ARGS__); \
218 #define __bcache_io_error(c, fmt, ...) \
219 printk_ratelimited(KERN_ERR bch2_fmt(c, \
220 "IO error: " fmt), ##__VA_ARGS__)
222 #define bcache_io_error(c, bio, fmt, ...) \
224 __bcache_io_error(c, fmt, ##__VA_ARGS__); \
225 (bio)->bi_status = BLK_STS_IOERR; \
228 #endif /* _BCACHEFS_ERROR_H */