summaryrefslogtreecommitdiff
path: root/fs/bcachefs/errcode.h
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2022-07-18 05:31:21 +0300
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-23 00:09:36 +0300
commit615f867c14b2d70efb02dafb8e668d984e74d0e3 (patch)
tree266f977a35d430198ba942f24e4dcbb73664f9fa /fs/bcachefs/errcode.h
parent3ab25c1b4ef2a57b8bc55e786e90af63f7d06663 (diff)
downloadlinux-615f867c14b2d70efb02dafb8e668d984e74d0e3.tar.xz
bcachefs: Improved errcodes
Instead of overloading standard error codes (EINTR/EAGAIN), and defining short lists of error codes in multiple places that potentially end up overlapping & conflicting, we're now going to have one master list of error codes. Error codes are defined with an x-macro: thus we also have bch2_err_str() now. Also, error codes have a class field. Now, instead of checking for errors with ==, code should use bch2_err_matches(), which returns true if the error is equal to or a sub-error of the error class. This means we can define unique errors for every source location where an error is generated, which will help improve our error messages. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/errcode.h')
-rw-r--r--fs/bcachefs/errcode.h33
1 files changed, 27 insertions, 6 deletions
diff --git a/fs/bcachefs/errcode.h b/fs/bcachefs/errcode.h
index 0581f3c7a0d8..69cc7cdd1c06 100644
--- a/fs/bcachefs/errcode.h
+++ b/fs/bcachefs/errcode.h
@@ -2,12 +2,33 @@
#ifndef _BCACHEFS_ERRCODE_H
#define _BCACHEFS_ERRCODE_H
-enum {
- /* Bucket allocator: */
- OPEN_BUCKETS_EMPTY = 2048,
- FREELIST_EMPTY, /* Allocator thread not keeping up */
- INSUFFICIENT_DEVICES,
- NEED_SNAPSHOT_CLEANUP,
+#define BCH_ERRCODES() \
+ x(0, open_buckets_empty) \
+ x(0, freelist_empty) \
+ x(freelist_empty, no_buckets_found) \
+ x(0, insufficient_devices) \
+ x(0, need_snapshot_cleanup)
+
+enum bch_errcode {
+ BCH_ERR_START = 2048,
+#define x(class, err) BCH_ERR_##err,
+ BCH_ERRCODES()
+#undef x
+ BCH_ERR_MAX
};
+const char *bch2_err_str(int);
+bool __bch2_err_matches(int, int);
+
+static inline bool _bch2_err_matches(int err, int class)
+{
+ return err && __bch2_err_matches(err, class);
+}
+
+#define bch2_err_matches(_err, _class) \
+({ \
+ BUILD_BUG_ON(!__builtin_constant_p(_class)); \
+ _bch2_err_matches(_err, _class); \
+})
+
#endif /* _BCACHFES_ERRCODE_H */