]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcache/error.h
Delete more unused shim code, update bcache code
[bcachefs-tools-debian] / libbcache / error.h
1 #ifndef _BCACHE_ERROR_H
2 #define _BCACHE_ERROR_H
3
4 #include <linux/printk.h>
5
6 struct cache;
7 struct cache_set;
8
9 /*
10  * XXX: separate out errors that indicate on disk data is inconsistent, and flag
11  * superblock as such
12  */
13
14 /* Error messages: */
15
16 #define __bch_dev_error(ca, fmt, ...)                                   \
17 do {                                                                    \
18         char _buf[BDEVNAME_SIZE];                                       \
19         bch_err((ca)->set, "%s: " fmt,                                  \
20                 bdevname((ca)->disk_sb.bdev, _buf), ##__VA_ARGS__);     \
21 } while (0)
22
23 /*
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():
27  *
28  * XXX: audit and convert to inconsistent() checks
29  */
30
31 #define bch_fs_bug(c, ...)                                              \
32 do {                                                                    \
33         bch_err(c, __VA_ARGS__);                                        \
34         BUG();                                                          \
35 } while (0)
36
37 #define bch_fs_bug_on(cond, c, ...)                                     \
38 do {                                                                    \
39         if (cond)                                                       \
40                 bch_fs_bug(c, __VA_ARGS__);                             \
41 } while (0)
42
43 /*
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.
49  *
50  * XXX: audit all inconsistent errors and make sure they're all recoverable, in
51  * BCH_ON_ERROR_CONTINUE mode
52  */
53
54 void bch_inconsistent_error(struct cache_set *);
55
56 #define bch_fs_inconsistent(c, ...)                                     \
57 do {                                                                    \
58         bch_err(c, __VA_ARGS__);                                        \
59         bch_inconsistent_error(c);                                      \
60 } while (0)
61
62 #define bch_fs_inconsistent_on(cond, c, ...)                            \
63 ({                                                                      \
64         int _ret = !!(cond);                                            \
65                                                                         \
66         if (_ret)                                                       \
67                 bch_fs_inconsistent(c, __VA_ARGS__);                    \
68         _ret;                                                           \
69 })
70
71 /*
72  * Later we might want to mark only the particular device inconsistent, not the
73  * entire cache set:
74  */
75
76 #define bch_dev_inconsistent(ca, ...)                                   \
77 do {                                                                    \
78         __bch_dev_error(ca, __VA_ARGS__);                               \
79         bch_inconsistent_error((ca)->set);                              \
80 } while (0)
81
82 #define bch_dev_inconsistent_on(cond, ca, ...)                          \
83 ({                                                                      \
84         int _ret = !!(cond);                                            \
85                                                                         \
86         if (_ret)                                                       \
87                 bch_dev_inconsistent(ca, __VA_ARGS__);                  \
88         _ret;                                                           \
89 })
90
91 /*
92  * Fsck errors: inconsistency errors we detect at mount time, and should ideally
93  * be able to repair:
94  */
95
96 enum {
97         BCH_FSCK_OK                     = 0,
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,
102 };
103
104 /* These macros return true if error should be fixed: */
105
106 /* XXX: mark in superblock that filesystem contains errors, if we ignore: */
107
108 #ifndef __fsck_err
109 #define __fsck_err(c, _can_fix, _can_ignore, _nofix_msg, msg, ...)      \
110 ({                                                                      \
111         bool _fix = false;                                              \
112                                                                         \
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); \
116                 _fix = true;                                            \
117         } else if (_can_ignore &&                                       \
118                    (c)->opts.errors == BCH_ON_ERROR_CONTINUE) {         \
119                 bch_err(c, msg " (ignoring)", ##__VA_ARGS__);           \
120         } else {                                                        \
121                 bch_err(c, msg " ("_nofix_msg")", ##__VA_ARGS__);       \
122                 ret = BCH_FSCK_ERRORS_NOT_FIXED;                        \
123                 goto fsck_err;                                          \
124         }                                                               \
125                                                                         \
126         BUG_ON(!_fix && !_can_ignore);                                  \
127         _fix;                                                           \
128 })
129 #endif
130
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)
134
135 #define unfixable_fsck_err_on(cond, c, ...)                             \
136         __fsck_err_on(cond, c, false, true, "repair unimplemented", ##__VA_ARGS__)
137
138 #define need_fsck_err_on(cond, c, ...)                                  \
139         __fsck_err_on(cond, c, false, true, "run fsck to correct", ##__VA_ARGS__)
140
141 #define mustfix_fsck_err(c, ...)                                        \
142         __fsck_err(c, true, false, "not fixing", ##__VA_ARGS__)
143
144 #define mustfix_fsck_err_on(cond, c, ...)                               \
145         __fsck_err_on(cond, c, true, false, "not fixing", ##__VA_ARGS__)
146
147 #define fsck_err_on(cond, c, ...)                                       \
148         __fsck_err_on(cond, c, true, true, "not fixing", ##__VA_ARGS__)
149
150 /*
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:
153  */
154
155 void bch_fatal_error(struct cache_set *);
156
157 #define bch_fs_fatal_error(c, ...)                                      \
158 do {                                                                    \
159         bch_err(c, __VA_ARGS__);                                        \
160         bch_fatal_error(c);                                             \
161 } while (0)
162
163 #define bch_fs_fatal_err_on(cond, c, ...)                               \
164 ({                                                                      \
165         int _ret = !!(cond);                                            \
166                                                                         \
167         if (_ret)                                                       \
168                 bch_fs_fatal_error(c, __VA_ARGS__);                     \
169         _ret;                                                           \
170 })
171
172 #define bch_dev_fatal_error(ca, ...)                                    \
173 do {                                                                    \
174         __bch_dev_error(ca, __VA_ARGS__);                               \
175         bch_fatal_error(c);                                             \
176 } while (0)
177
178 #define bch_dev_fatal_io_error(ca, fmt, ...)                            \
179 do {                                                                    \
180         char _buf[BDEVNAME_SIZE];                                       \
181                                                                         \
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);                                     \
186 } while (0)
187
188 #define bch_dev_fatal_io_err_on(cond, ca, ...)                          \
189 ({                                                                      \
190         int _ret = !!(cond);                                            \
191                                                                         \
192         if (_ret)                                                       \
193                 bch_dev_fatal_io_error(ca, __VA_ARGS__);                \
194         _ret;                                                           \
195 })
196
197 /*
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:
201  */
202
203 void bch_account_io_completion(struct cache *);
204 void bch_account_io_completion_time(struct cache *, unsigned, int);
205
206 void bch_nonfatal_io_error_work(struct work_struct *);
207
208 /* Does the error handling without logging a message */
209 void bch_nonfatal_io_error(struct cache *);
210
211 #if 0
212 #define bch_fs_nonfatal_io_error(c, ...)                                \
213 do {                                                                    \
214         bch_err(c, __VA_ARGS__);                                        \
215         bch_nonfatal_io_error(c);                                       \
216 } while (0)
217 #endif
218
219 /* Logs message and handles the error: */
220 #define bch_dev_nonfatal_io_error(ca, fmt, ...)                         \
221 do {                                                                    \
222         char _buf[BDEVNAME_SIZE];                                       \
223                                                                         \
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);                                      \
228 } while (0)
229
230 #define bch_dev_nonfatal_io_err_on(cond, ca, ...)                       \
231 ({                                                                      \
232         bool _ret = (cond);                                             \
233                                                                         \
234         if (_ret)                                                       \
235                 bch_dev_nonfatal_io_error(ca, __VA_ARGS__);             \
236         _ret;                                                           \
237 })
238
239 /* kill? */
240
241 #define __bcache_io_error(c, fmt, ...)                                  \
242         printk_ratelimited(KERN_ERR bch_fmt(c,                          \
243                         "IO error: " fmt), ##__VA_ARGS__)
244
245 #define bcache_io_error(c, bio, fmt, ...)                               \
246 do {                                                                    \
247         __bcache_io_error(c, fmt, ##__VA_ARGS__);                       \
248         (bio)->bi_error = -EIO;                                         \
249 } while (0)
250
251 #endif /* _BCACHE_ERROR_H */