1 #ifndef _BCACHEFS_ERROR_H
2 #define _BCACHEFS_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 bool 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,
111 struct fsck_err_state {
112 struct list_head list;
118 #define FSCK_CAN_FIX (1 << 0)
119 #define FSCK_CAN_IGNORE (1 << 1)
120 #define FSCK_NEED_FSCK (1 << 2)
122 enum fsck_err_ret bch2_fsck_err(struct bch_fs *,
123 unsigned, const char *, ...);
124 void bch2_flush_fsck_errs(struct bch_fs *);
126 #define __fsck_err(c, _flags, msg, ...) \
128 int _fix = bch2_fsck_err(c, _flags, msg, ##__VA_ARGS__);\
130 if (_fix == FSCK_ERR_EXIT) { \
131 bch_err(c, "Unable to continue, halting"); \
132 ret = BCH_FSCK_ERRORS_NOT_FIXED; \
139 /* These macros return true if error should be fixed: */
141 /* XXX: mark in superblock that filesystem contains errors, if we ignore: */
143 #define __fsck_err_on(cond, c, _flags, ...) \
144 ((cond) ? __fsck_err(c, _flags, ##__VA_ARGS__) : false)
146 #define need_fsck_err_on(cond, c, ...) \
147 __fsck_err_on(cond, c, FSCK_CAN_IGNORE|FSCK_NEED_FSCK, ##__VA_ARGS__)
149 #define mustfix_fsck_err(c, ...) \
150 __fsck_err(c, FSCK_CAN_FIX, ##__VA_ARGS__)
152 #define mustfix_fsck_err_on(cond, c, ...) \
153 __fsck_err_on(cond, c, FSCK_CAN_FIX, ##__VA_ARGS__)
155 #define fsck_err_on(cond, c, ...) \
156 __fsck_err_on(cond, c, FSCK_CAN_FIX|FSCK_CAN_IGNORE, ##__VA_ARGS__)
159 * Fatal errors: these don't indicate a bug, but we can't continue running in RW
160 * mode - pretty much just due to metadata IO errors:
163 void bch2_fatal_error(struct bch_fs *);
165 #define bch2_fs_fatal_error(c, ...) \
167 bch_err(c, __VA_ARGS__); \
168 bch2_fatal_error(c); \
171 #define bch2_fs_fatal_err_on(cond, c, ...) \
173 int _ret = !!(cond); \
176 bch2_fs_fatal_error(c, __VA_ARGS__); \
181 * IO errors: either recoverable metadata IO (because we have replicas), or data
182 * IO - we need to log it and print out a message, but we don't (necessarily)
183 * want to shut down the fs:
186 void bch2_io_error_work(struct work_struct *);
188 /* Does the error handling without logging a message */
189 void bch2_io_error(struct bch_dev *);
191 /* Logs message and handles the error: */
192 #define bch2_dev_io_error(ca, fmt, ...) \
194 printk_ratelimited(KERN_ERR bch2_fmt((ca)->fs, \
195 "IO error on %s for " fmt), \
196 (ca)->name, ##__VA_ARGS__); \
200 #define bch2_dev_io_err_on(cond, ca, ...) \
202 bool _ret = (cond); \
205 bch2_dev_io_error(ca, __VA_ARGS__); \
211 #define __bcache_io_error(c, fmt, ...) \
212 printk_ratelimited(KERN_ERR bch2_fmt(c, \
213 "IO error: " fmt), ##__VA_ARGS__)
215 #define bcache_io_error(c, bio, fmt, ...) \
217 __bcache_io_error(c, fmt, ##__VA_ARGS__); \
218 (bio)->bi_status = BLK_STS_IOERR; \
221 #endif /* _BCACHEFS_ERROR_H */