From 57a3938872bf8c50b62f713096160d0a9b581953 Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Thu, 25 Nov 2021 16:26:38 +0100 Subject: [PATCH] Improve error mapping code Signed-off-by: Robert Baldyga --- modules/cas_cache/utils/cas_err.h | 37 ++++++++++++++++++++++--------- modules/include/cas_ioctl_codes.h | 8 +++++-- ocf | 2 +- 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/modules/cas_cache/utils/cas_err.h b/modules/cas_cache/utils/cas_err.h index 2f21ec6..45880c7 100644 --- a/modules/cas_cache/utils/cas_err.h +++ b/modules/cas_cache/utils/cas_err.h @@ -6,10 +6,12 @@ #include "cas_cache.h" -struct { - int cas_error; - int std_error; -} static cas_error_code_map[] = { +struct cas_error_map_entry { + int cas_err; + int errno; +}; + +static struct cas_error_map_entry cas_ocf_error_map[] = { /* OCF error mappings*/ { OCF_ERR_INVAL, EINVAL }, { OCF_ERR_AGAIN, EAGAIN }, @@ -52,7 +54,9 @@ struct { { OCF_ERR_METADATA_LAYOUT_MISMATCH, EINVAL }, { OCF_ERR_CACHE_LINE_SIZE_MISMATCH, EINVAL }, { OCF_ERR_CACHE_STANDBY, EBUSY }, +}; +static struct cas_error_map_entry cas_error_map[] = { /* CAS kernel error mappings*/ { KCAS_ERR_ROOT, EPERM }, { KCAS_ERR_SYSTEM, EINVAL }, @@ -81,19 +85,30 @@ struct { /* Helper which change cas-specific error */ /* codes to kernel generic error codes */ /*******************************************/ -static inline int map_cas_err_to_generic(int cas_error_code) +static inline int map_cas_err_to_generic(int error_code) { int i; - if (cas_error_code == 0) + if (error_code == 0) return 0; /* No Error */ - cas_error_code = abs(cas_error_code); + error_code = abs(error_code); - for (i = 0; i < ARRAY_SIZE(cas_error_code_map); i++) { - if (cas_error_code_map[i].cas_error == cas_error_code) - return -cas_error_code_map[i].std_error; + if (error_code >= OCF_ERR_MIN && error_code <= OCF_ERR_MAX) { + for (i = 0; i < ARRAY_SIZE(cas_ocf_error_map); i++) { + if (cas_ocf_error_map[i].cas_err == error_code) + return -cas_ocf_error_map[i].errno; + return -EINVAL; + } } - return -cas_error_code; + if (error_code >= KCAS_ERR_MIN && error_code <= KCAS_ERR_MAX) { + for (i = 0; i < ARRAY_SIZE(cas_error_map); i++) { + if (cas_error_map[i].cas_err == error_code) + return -cas_error_map[i].errno; + return -EINVAL; + } + } + + return -error_code; } diff --git a/modules/include/cas_ioctl_codes.h b/modules/include/cas_ioctl_codes.h index ba578bf..0800c31 100644 --- a/modules/include/cas_ioctl_codes.h +++ b/modules/include/cas_ioctl_codes.h @@ -507,8 +507,10 @@ struct kcas_failover_activate * Extended kernel CAS error codes */ enum kcas_error { + KCAS_ERR_MIN = 2000000, + /** Must be root */ - KCAS_ERR_ROOT = 2000000, + KCAS_ERR_ROOT = KCAS_ERR_MIN, /** System Error */ KCAS_ERR_SYSTEM, @@ -571,7 +573,9 @@ enum kcas_error { KCAS_ERR_CORE_IN_ACTIVE_STATE, /** Inactive core has dirty data assigned */ - KCAS_ERR_INACTIVE_CORE_IS_DIRTY + KCAS_ERR_INACTIVE_CORE_IS_DIRTY, + + KCAS_ERR_MAX = KCAS_ERR_INACTIVE_CORE_IS_DIRTY, }; #endif diff --git a/ocf b/ocf index 8669a29..e72018b 160000 --- a/ocf +++ b/ocf @@ -1 +1 @@ -Subproject commit 8669a296ccd87f5dc274920cf613143f74cb8cb3 +Subproject commit e72018bc02478f3ac73ee8984fafaf61f09c425d