Improve error mapping code
Signed-off-by: Robert Baldyga <robert.baldyga@intel.com>
This commit is contained in:
parent
73461fc26d
commit
57a3938872
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
2
ocf
2
ocf
@ -1 +1 @@
|
||||
Subproject commit 8669a296ccd87f5dc274920cf613143f74cb8cb3
|
||||
Subproject commit e72018bc02478f3ac73ee8984fafaf61f09c425d
|
Loading…
Reference in New Issue
Block a user