1 #ifndef _BCACHE_ERROR_H
2 #define _BCACHE_ERROR_H
4 #include <linux/printk.h>
10 * XXX: separate out errors that indicate on disk data is inconsistent, and flag
17 * Very fatal logic/inconsistency errors: these indicate that we've majorly
18 * screwed up at runtime, i.e. it's not likely that it was just caused by the
19 * data on disk being inconsistent. These BUG():
21 * XXX: audit and convert to inconsistent() checks
24 #define bch2_fs_bug(c, ...) \
26 bch_err(c, __VA_ARGS__); \
30 #define bch2_fs_bug_on(cond, c, ...) \
33 bch2_fs_bug(c, __VA_ARGS__); \
37 * Inconsistency errors: The on disk data is inconsistent. If these occur during
38 * initial recovery, they don't indicate a bug in the running code - we walk all
39 * the metadata before modifying anything. If they occur at runtime, they
40 * indicate either a bug in the running code or (less likely) data is being
41 * silently corrupted under us.
43 * XXX: audit all inconsistent errors and make sure they're all recoverable, in
44 * BCH_ON_ERROR_CONTINUE mode
47 void bch2_inconsistent_error(struct bch_fs *);
49 #define bch2_fs_inconsistent(c, ...) \
51 bch_err(c, __VA_ARGS__); \
52 bch2_inconsistent_error(c); \
55 #define bch2_fs_inconsistent_on(cond, c, ...) \
57 int _ret = !!(cond); \
60 bch2_fs_inconsistent(c, __VA_ARGS__); \
65 * Later we might want to mark only the particular device inconsistent, not the
69 #define bch2_dev_inconsistent(ca, ...) \
71 bch_err(ca, __VA_ARGS__); \
72 bch2_inconsistent_error((ca)->fs); \
75 #define bch2_dev_inconsistent_on(cond, ca, ...) \
77 int _ret = !!(cond); \
80 bch2_dev_inconsistent(ca, __VA_ARGS__); \
85 * Fsck errors: inconsistency errors we detect at mount time, and should ideally
91 BCH_FSCK_ERRORS_NOT_FIXED = 1,
92 BCH_FSCK_REPAIR_UNIMPLEMENTED = 2,
93 BCH_FSCK_REPAIR_IMPOSSIBLE = 3,
94 BCH_FSCK_UNKNOWN_VERSION = 4,
97 /* These macros return true if error should be fixed: */
99 /* XXX: mark in superblock that filesystem contains errors, if we ignore: */
102 #define __fsck_err(c, _can_fix, _can_ignore, _nofix_msg, msg, ...) \
106 if (_can_fix && (c)->opts.fix_errors) { \
107 bch_err(c, msg ", fixing", ##__VA_ARGS__); \
108 set_bit(BCH_FS_FSCK_FIXED_ERRORS, &(c)->flags); \
110 } else if (_can_ignore && \
111 (c)->opts.errors == BCH_ON_ERROR_CONTINUE) { \
112 bch_err(c, msg " (ignoring)", ##__VA_ARGS__); \
114 bch_err(c, msg " ("_nofix_msg")", ##__VA_ARGS__); \
115 ret = BCH_FSCK_ERRORS_NOT_FIXED; \
119 BUG_ON(!_fix && !_can_ignore); \
124 #define __fsck_err_on(cond, c, _can_fix, _can_ignore, _nofix_msg, ...) \
125 ((cond) ? __fsck_err(c, _can_fix, _can_ignore, \
126 _nofix_msg, ##__VA_ARGS__) : false)
128 #define unfixable_fsck_err_on(cond, c, ...) \
129 __fsck_err_on(cond, c, false, true, "repair unimplemented", ##__VA_ARGS__)
131 #define need_fsck_err_on(cond, c, ...) \
132 __fsck_err_on(cond, c, false, true, "run fsck to correct", ##__VA_ARGS__)
134 #define mustfix_fsck_err(c, ...) \
135 __fsck_err(c, true, false, "not fixing", ##__VA_ARGS__)
137 #define mustfix_fsck_err_on(cond, c, ...) \
138 __fsck_err_on(cond, c, true, false, "not fixing", ##__VA_ARGS__)
140 #define fsck_err_on(cond, c, ...) \
141 __fsck_err_on(cond, c, true, true, "not fixing", ##__VA_ARGS__)
144 * Fatal errors: these don't indicate a bug, but we can't continue running in RW
145 * mode - pretty much just due to metadata IO errors:
148 void bch2_fatal_error(struct bch_fs *);
150 #define bch2_fs_fatal_error(c, ...) \
152 bch_err(c, __VA_ARGS__); \
153 bch2_fatal_error(c); \
156 #define bch2_fs_fatal_err_on(cond, c, ...) \
158 int _ret = !!(cond); \
161 bch2_fs_fatal_error(c, __VA_ARGS__); \
165 #define bch2_dev_fatal_error(ca, ...) \
167 bch_err(ca, __VA_ARGS__); \
168 bch2_fatal_error(c); \
171 #define bch2_dev_fatal_io_error(ca, fmt, ...) \
173 printk_ratelimited(KERN_ERR bch2_fmt((ca)->fs, \
174 "fatal IO error on %s for " fmt), \
175 (ca)->name, ##__VA_ARGS__); \
176 bch2_fatal_error((ca)->fs); \
179 #define bch2_dev_fatal_io_err_on(cond, ca, ...) \
181 int _ret = !!(cond); \
184 bch2_dev_fatal_io_error(ca, __VA_ARGS__); \
189 * Nonfatal IO errors: either recoverable metadata IO (because we have
190 * replicas), or data IO - we need to log it and print out a message, but we
191 * don't (necessarily) want to shut down the fs:
194 void bch2_nonfatal_io_error_work(struct work_struct *);
196 /* Does the error handling without logging a message */
197 void bch2_nonfatal_io_error(struct bch_dev *);
200 #define bch2_fs_nonfatal_io_error(c, ...) \
202 bch_err(c, __VA_ARGS__); \
203 bch2_nonfatal_io_error(c); \
207 /* Logs message and handles the error: */
208 #define bch2_dev_nonfatal_io_error(ca, fmt, ...) \
210 printk_ratelimited(KERN_ERR bch2_fmt((ca)->fs, \
211 "IO error on %s for " fmt), \
212 (ca)->name, ##__VA_ARGS__); \
213 bch2_nonfatal_io_error(ca); \
216 #define bch2_dev_nonfatal_io_err_on(cond, ca, ...) \
218 bool _ret = (cond); \
221 bch2_dev_nonfatal_io_error(ca, __VA_ARGS__); \
227 #define __bcache_io_error(c, fmt, ...) \
228 printk_ratelimited(KERN_ERR bch2_fmt(c, \
229 "IO error: " fmt), ##__VA_ARGS__)
231 #define bcache_io_error(c, bio, fmt, ...) \
233 __bcache_io_error(c, fmt, ##__VA_ARGS__); \
234 (bio)->bi_error = -EIO; \
237 #endif /* _BCACHE_ERROR_H */