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
16 #define __bch_dev_error(ca, fmt, ...) \
18 char _buf[BDEVNAME_SIZE]; \
19 bch_err((ca)->set, "%s: " fmt, \
20 bdevname((ca)->disk_sb.bdev, _buf), ##__VA_ARGS__); \
24 * Very fatal logic/inconsistency errors: these indicate that we've majorly
25 * screwed up at runtime, i.e. it's not likely that it was just caused by the
26 * data on disk being inconsistent. These BUG():
28 * XXX: audit and convert to inconsistent() checks
31 #define bch_fs_bug(c, ...) \
33 bch_err(c, __VA_ARGS__); \
37 #define bch_fs_bug_on(cond, c, ...) \
40 bch_fs_bug(c, __VA_ARGS__); \
44 * Inconsistency errors: The on disk data is inconsistent. If these occur during
45 * initial recovery, they don't indicate a bug in the running code - we walk all
46 * the metadata before modifying anything. If they occur at runtime, they
47 * indicate either a bug in the running code or (less likely) data is being
48 * silently corrupted under us.
50 * XXX: audit all inconsistent errors and make sure they're all recoverable, in
51 * BCH_ON_ERROR_CONTINUE mode
54 void bch_inconsistent_error(struct cache_set *);
56 #define bch_fs_inconsistent(c, ...) \
58 bch_err(c, __VA_ARGS__); \
59 bch_inconsistent_error(c); \
62 #define bch_fs_inconsistent_on(cond, c, ...) \
64 int _ret = !!(cond); \
67 bch_fs_inconsistent(c, __VA_ARGS__); \
72 * Later we might want to mark only the particular device inconsistent, not the
76 #define bch_dev_inconsistent(ca, ...) \
78 __bch_dev_error(ca, __VA_ARGS__); \
79 bch_inconsistent_error((ca)->set); \
82 #define bch_dev_inconsistent_on(cond, ca, ...) \
84 int _ret = !!(cond); \
87 bch_dev_inconsistent(ca, __VA_ARGS__); \
92 * Fsck errors: inconsistency errors we detect at mount time, and should ideally
98 BCH_FSCK_ERRORS_NOT_FIXED = 1,
99 BCH_FSCK_REPAIR_UNIMPLEMENTED = 2,
100 BCH_FSCK_REPAIR_IMPOSSIBLE = 3,
101 BCH_FSCK_UNKNOWN_VERSION = 4,
104 /* These macros return true if error should be fixed: */
106 /* XXX: mark in superblock that filesystem contains errors, if we ignore: */
109 #define __fsck_err(c, _can_fix, _can_ignore, _nofix_msg, msg, ...) \
113 if (_can_fix && (c)->opts.fix_errors) { \
114 bch_err(c, msg ", fixing", ##__VA_ARGS__); \
115 set_bit(BCH_FS_FSCK_FIXED_ERRORS, &(c)->flags); \
117 } else if (_can_ignore && \
118 (c)->opts.errors == BCH_ON_ERROR_CONTINUE) { \
119 bch_err(c, msg " (ignoring)", ##__VA_ARGS__); \
121 bch_err(c, msg " ("_nofix_msg")", ##__VA_ARGS__); \
122 ret = BCH_FSCK_ERRORS_NOT_FIXED; \
126 BUG_ON(!_fix && !_can_ignore); \
131 #define __fsck_err_on(cond, c, _can_fix, _can_ignore, _nofix_msg, ...) \
132 ((cond) ? __fsck_err(c, _can_fix, _can_ignore, \
133 _nofix_msg, ##__VA_ARGS__) : false)
135 #define unfixable_fsck_err_on(cond, c, ...) \
136 __fsck_err_on(cond, c, false, true, "repair unimplemented", ##__VA_ARGS__)
138 #define need_fsck_err_on(cond, c, ...) \
139 __fsck_err_on(cond, c, false, true, "run fsck to correct", ##__VA_ARGS__)
141 #define mustfix_fsck_err(c, ...) \
142 __fsck_err(c, true, false, "not fixing", ##__VA_ARGS__)
144 #define mustfix_fsck_err_on(cond, c, ...) \
145 __fsck_err_on(cond, c, true, false, "not fixing", ##__VA_ARGS__)
147 #define fsck_err_on(cond, c, ...) \
148 __fsck_err_on(cond, c, true, true, "not fixing", ##__VA_ARGS__)
151 * Fatal errors: these don't indicate a bug, but we can't continue running in RW
152 * mode - pretty much just due to metadata IO errors:
155 void bch_fatal_error(struct cache_set *);
157 #define bch_fs_fatal_error(c, ...) \
159 bch_err(c, __VA_ARGS__); \
160 bch_fatal_error(c); \
163 #define bch_fs_fatal_err_on(cond, c, ...) \
165 int _ret = !!(cond); \
168 bch_fs_fatal_error(c, __VA_ARGS__); \
172 #define bch_dev_fatal_error(ca, ...) \
174 __bch_dev_error(ca, __VA_ARGS__); \
175 bch_fatal_error(c); \
178 #define bch_dev_fatal_io_error(ca, fmt, ...) \
180 char _buf[BDEVNAME_SIZE]; \
182 printk_ratelimited(KERN_ERR bch_fmt((ca)->set, \
183 "fatal IO error on %s for " fmt), \
184 bdevname((ca)->disk_sb.bdev, _buf), ##__VA_ARGS__); \
185 bch_fatal_error((ca)->set); \
188 #define bch_dev_fatal_io_err_on(cond, ca, ...) \
190 int _ret = !!(cond); \
193 bch_dev_fatal_io_error(ca, __VA_ARGS__); \
198 * Nonfatal IO errors: either recoverable metadata IO (because we have
199 * replicas), or data IO - we need to log it and print out a message, but we
200 * don't (necessarily) want to shut down the fs:
203 void bch_account_io_completion(struct cache *);
204 void bch_account_io_completion_time(struct cache *, unsigned, int);
206 void bch_nonfatal_io_error_work(struct work_struct *);
208 /* Does the error handling without logging a message */
209 void bch_nonfatal_io_error(struct cache *);
212 #define bch_fs_nonfatal_io_error(c, ...) \
214 bch_err(c, __VA_ARGS__); \
215 bch_nonfatal_io_error(c); \
219 /* Logs message and handles the error: */
220 #define bch_dev_nonfatal_io_error(ca, fmt, ...) \
222 char _buf[BDEVNAME_SIZE]; \
224 printk_ratelimited(KERN_ERR bch_fmt((ca)->set, \
225 "IO error on %s for " fmt), \
226 bdevname((ca)->disk_sb.bdev, _buf), ##__VA_ARGS__); \
227 bch_nonfatal_io_error(ca); \
230 #define bch_dev_nonfatal_io_err_on(cond, ca, ...) \
232 bool _ret = (cond); \
235 bch_dev_nonfatal_io_error(ca, __VA_ARGS__); \
241 #define __bcache_io_error(c, fmt, ...) \
242 printk_ratelimited(KERN_ERR bch_fmt(c, \
243 "IO error: " fmt), ##__VA_ARGS__)
245 #define bcache_io_error(c, bio, fmt, ...) \
247 __bcache_io_error(c, fmt, ##__VA_ARGS__); \
248 (bio)->bi_error = -EIO; \
251 #endif /* _BCACHE_ERROR_H */