summaryrefslogtreecommitdiff
path: root/fs/bcachefs/errcode.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2022-09-18 22:43:50 +0300
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-23 00:09:40 +0300
commit5c1ef830f6786059f85bebe7501b63dffed0b633 (patch)
tree3a6f94498dd5f0d4f9d416db36d97ed01cf31373 /fs/bcachefs/errcode.c
parent57ce827442c4e7b0f38b14b91c97413c5d779697 (diff)
downloadlinux-5c1ef830f6786059f85bebe7501b63dffed0b633.tar.xz
bcachefs: Errcodes can now subtype standard error codes
The next patch is going to be adding private error codes for all the places we return -ENOSPC. Additionally, this patch updates return paths at all module boundaries to call bch2_err_class(), to return the standard error code. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/errcode.c')
-rw-r--r--fs/bcachefs/errcode.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/fs/bcachefs/errcode.c b/fs/bcachefs/errcode.c
index 9da8a5973af0..cc9ce0be356e 100644
--- a/fs/bcachefs/errcode.c
+++ b/fs/bcachefs/errcode.c
@@ -15,7 +15,7 @@ static const char * const bch2_errcode_strs[] = {
#define BCH_ERR_0 0
static unsigned bch2_errcode_parents[] = {
-#define x(class, err) [BCH_ERR_##err - BCH_ERR_START] = BCH_ERR_##class,
+#define x(class, err) [BCH_ERR_##err - BCH_ERR_START] = class,
BCH_ERRCODES()
#undef x
};
@@ -49,3 +49,14 @@ bool __bch2_err_matches(int err, int class)
return err == class;
}
+
+int __bch2_err_class(int err)
+{
+ err = -err;
+ BUG_ON((unsigned) err >= BCH_ERR_MAX);
+
+ while (err >= BCH_ERR_START && bch2_errcode_parents[err - BCH_ERR_START])
+ err = bch2_errcode_parents[err - BCH_ERR_START];
+
+ return -err;
+}