1 // SPDX-License-Identifier: GPL-2.0
6 #include <linux/errname.h>
8 static const char * const bch2_errcode_strs[] = {
9 #define x(class, err) [BCH_ERR_##err - BCH_ERR_START] = #err,
15 static unsigned bch2_errcode_parents[] = {
16 #define x(class, err) [BCH_ERR_##err - BCH_ERR_START] = class,
21 const char *bch2_err_str(int err)
27 BUG_ON(err >= BCH_ERR_MAX);
29 if (err >= BCH_ERR_START)
30 errstr = bch2_errcode_strs[err - BCH_ERR_START];
32 errstr = errname(err);
34 errstr = "(No error)";
35 return errstr ?: "(Invalid error)";
38 bool __bch2_err_matches(int err, int class)
43 BUG_ON(err >= BCH_ERR_MAX);
44 BUG_ON(class >= BCH_ERR_MAX);
46 while (err >= BCH_ERR_START && err != class)
47 err = bch2_errcode_parents[err - BCH_ERR_START];
52 int __bch2_err_class(int err)
55 BUG_ON((unsigned) err >= BCH_ERR_MAX);
57 while (err >= BCH_ERR_START && bch2_errcode_parents[err - BCH_ERR_START])
58 err = bch2_errcode_parents[err - BCH_ERR_START];
63 const char *bch2_blk_status_to_str(blk_status_t status)
65 if (status == BLK_STS_REMOVED)
66 return "device removed";
67 return blk_status_to_str(status);