1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BCACHEFS_ERROR_H
3 #define _BCACHEFS_ERROR_H
5 #include <linux/list.h>
6 #include <linux/printk.h>
13 * XXX: separate out errors that indicate on disk data is inconsistent, and flag
20 * Inconsistency errors: The on disk data is inconsistent. If these occur during
21 * initial recovery, they don't indicate a bug in the running code - we walk all
22 * the metadata before modifying anything. If they occur at runtime, they
23 * indicate either a bug in the running code or (less likely) data is being
24 * silently corrupted under us.
26 * XXX: audit all inconsistent errors and make sure they're all recoverable, in
27 * BCH_ON_ERROR_CONTINUE mode
30 bool bch2_inconsistent_error(struct bch_fs *);
32 void bch2_topology_error(struct bch_fs *);
34 #define bch2_fs_inconsistent(c, ...) \
36 bch_err(c, __VA_ARGS__); \
37 bch2_inconsistent_error(c); \
40 #define bch2_fs_inconsistent_on(cond, c, ...) \
42 int _ret = !!(cond); \
45 bch2_fs_inconsistent(c, __VA_ARGS__); \
50 * Later we might want to mark only the particular device inconsistent, not the
54 #define bch2_dev_inconsistent(ca, ...) \
56 bch_err(ca, __VA_ARGS__); \
57 bch2_inconsistent_error((ca)->fs); \
60 #define bch2_dev_inconsistent_on(cond, ca, ...) \
62 int _ret = !!(cond); \
65 bch2_dev_inconsistent(ca, __VA_ARGS__); \
70 * Fsck errors: inconsistency errors we detect at mount time, and should ideally
76 BCH_FSCK_ERRORS_NOT_FIXED = 1,
77 BCH_FSCK_REPAIR_UNIMPLEMENTED = 2,
78 BCH_FSCK_REPAIR_IMPOSSIBLE = 3,
79 BCH_FSCK_UNKNOWN_VERSION = 4,
93 FSCK_ERR_START_TOPOLOGY_REPAIR = 3,
96 struct fsck_err_state {
97 struct list_head list;
104 #define FSCK_CAN_FIX (1 << 0)
105 #define FSCK_CAN_IGNORE (1 << 1)
106 #define FSCK_NEED_FSCK (1 << 2)
108 __printf(3, 4) __cold
109 enum fsck_err_ret bch2_fsck_err(struct bch_fs *,
110 unsigned, const char *, ...);
111 void bch2_flush_fsck_errs(struct bch_fs *);
113 #define __fsck_err(c, _flags, msg, ...) \
115 int _fix = bch2_fsck_err(c, _flags, msg, ##__VA_ARGS__);\
117 if (_fix == FSCK_ERR_EXIT) { \
118 bch_err(c, "Unable to continue, halting"); \
119 ret = BCH_FSCK_ERRORS_NOT_FIXED; \
126 /* These macros return true if error should be fixed: */
128 /* XXX: mark in superblock that filesystem contains errors, if we ignore: */
130 #define __fsck_err_on(cond, c, _flags, ...) \
131 ((cond) ? __fsck_err(c, _flags, ##__VA_ARGS__) : false)
133 #define need_fsck_err_on(cond, c, ...) \
134 __fsck_err_on(cond, c, FSCK_CAN_IGNORE|FSCK_NEED_FSCK, ##__VA_ARGS__)
136 #define need_fsck_err(c, ...) \
137 __fsck_err(c, FSCK_CAN_IGNORE|FSCK_NEED_FSCK, ##__VA_ARGS__)
139 #define mustfix_fsck_err(c, ...) \
140 __fsck_err(c, FSCK_CAN_FIX, ##__VA_ARGS__)
142 #define mustfix_fsck_err_on(cond, c, ...) \
143 __fsck_err_on(cond, c, FSCK_CAN_FIX, ##__VA_ARGS__)
145 #define fsck_err(c, ...) \
146 __fsck_err(c, FSCK_CAN_FIX|FSCK_CAN_IGNORE, ##__VA_ARGS__)
148 #define fsck_err_on(cond, c, ...) \
149 __fsck_err_on(cond, c, FSCK_CAN_FIX|FSCK_CAN_IGNORE, ##__VA_ARGS__)
152 * Fatal errors: these don't indicate a bug, but we can't continue running in RW
153 * mode - pretty much just due to metadata IO errors:
156 void bch2_fatal_error(struct bch_fs *);
158 #define bch2_fs_fatal_error(c, ...) \
160 bch_err(c, __VA_ARGS__); \
161 bch2_fatal_error(c); \
164 #define bch2_fs_fatal_err_on(cond, c, ...) \
166 int _ret = !!(cond); \
169 bch2_fs_fatal_error(c, __VA_ARGS__); \
174 * IO errors: either recoverable metadata IO (because we have replicas), or data
175 * IO - we need to log it and print out a message, but we don't (necessarily)
176 * want to shut down the fs:
179 void bch2_io_error_work(struct work_struct *);
181 /* Does the error handling without logging a message */
182 void bch2_io_error(struct bch_dev *);
184 /* Logs message and handles the error: */
185 #define bch2_dev_io_error(ca, fmt, ...) \
187 printk_ratelimited(KERN_ERR "bcachefs (%s): " fmt, \
188 (ca)->name, ##__VA_ARGS__); \
192 #define bch2_dev_inum_io_error(ca, _inum, _offset, fmt, ...) \
194 printk_ratelimited(KERN_ERR "bcachefs (%s inum %llu offset %llu): " fmt,\
195 (ca)->name, (_inum), (_offset), ##__VA_ARGS__); \
199 #define bch2_dev_io_err_on(cond, ca, ...) \
201 bool _ret = (cond); \
204 bch2_dev_io_error(ca, __VA_ARGS__); \
208 #define bch2_dev_inum_io_err_on(cond, ca, _inum, _offset, ...) \
210 bool _ret = (cond); \
213 bch2_dev_inum_io_error(ca, _inum, _offset, __VA_ARGS__);\
217 #endif /* _BCACHEFS_ERROR_H */