From 1c7de189e209ca20baf86506ab5d3f96992e619a Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Fri, 5 Jul 2024 11:53:10 +0200 Subject: [PATCH] Get rid of non-OCF error codes Let's put an end to random crashes and vague error messages in pyocf! Signed-off-by: Michal Mielewczyk --- src/mngt/ocf_mngt_core.c | 4 ++-- src/ocf_ctx.c | 13 +++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/mngt/ocf_mngt_core.c b/src/mngt/ocf_mngt_core.c index 1c6dc37..32dd58d 100644 --- a/src/mngt/ocf_mngt_core.c +++ b/src/mngt/ocf_mngt_core.c @@ -54,10 +54,10 @@ static int _ocf_uuid_set(const struct ocf_volume_uuid *uuid, int result; if (!uuid->data) - return -EINVAL; + return -OCF_ERR_INVAL; if (uuid->size > sizeof(muuid->data)) - return -ENOBUFS; + return -OCF_ERR_INVAL; result = env_memcpy(muuid->data, sizeof(muuid->data), uuid->data, uuid->size); diff --git a/src/ocf_ctx.c b/src/ocf_ctx.c index 008e4d7..75c4726 100644 --- a/src/ocf_ctx.c +++ b/src/ocf_ctx.c @@ -1,5 +1,6 @@ /* * Copyright(c) 2012-2022 Intel Corporation + * Copyright(c) 2024 Huawei Technologies * SPDX-License-Identifier: BSD-3-Clause */ @@ -25,19 +26,19 @@ int ocf_ctx_register_volume_type_internal(ocf_ctx_t ctx, uint8_t type_id, int result = 0; if (!ctx || !properties) - return -EINVAL; + return -OCF_ERR_INVAL; env_rmutex_lock(&ctx->lock); if (type_id >= OCF_VOLUME_TYPE_MAX || ctx->volume_type[type_id]) { env_rmutex_unlock(&ctx->lock); - result = -EINVAL; + result = -OCF_ERR_INVAL; goto err; } ocf_volume_type_init(&ctx->volume_type[type_id], properties, extended); if (!ctx->volume_type[type_id]) - result = -EINVAL; + result = -OCF_ERR_INVAL; env_rmutex_unlock(&ctx->lock); @@ -58,7 +59,7 @@ int ocf_ctx_register_volume_type(ocf_ctx_t ctx, uint8_t type_id, const struct ocf_volume_properties *properties) { if (type_id >= OCF_VOLUME_TYPE_MAX_USER) - return -EINVAL; + return -OCF_ERR_INVAL; return ocf_ctx_register_volume_type_internal(ctx, type_id, properties, NULL); @@ -150,7 +151,7 @@ int ocf_ctx_volume_create(ocf_ctx_t ctx, ocf_volume_t *volume, volume_type = ocf_ctx_get_volume_type(ctx, type_id); if (!volume_type) - return -EINVAL; + return -OCF_ERR_INVAL; return ocf_volume_create(volume, volume_type, uuid); } @@ -188,7 +189,7 @@ int ocf_ctx_create(ocf_ctx_t *ctx, const struct ocf_ctx_config *cfg) ocf_ctx = env_zalloc(sizeof(*ocf_ctx), ENV_MEM_NORMAL); if (!ocf_ctx) - return -ENOMEM; + return -OCF_ERR_NO_MEM; INIT_LIST_HEAD(&ocf_ctx->caches); env_atomic_set(&ocf_ctx->ref_count, 1);