From 3fca309e510a8626092d18fe32af52a0b7010ec3 Mon Sep 17 00:00:00 2001 From: Ostrokrzew Date: Tue, 17 Dec 2019 10:15:52 +0100 Subject: [PATCH] Change error code and add new Change 'OCF_ERR_START_CACHE_FAIL' to 'OCF_ERR_NO_MEM' while CAS fails in case of memory lack on device. Add new error code for case, when device doesn't satisfy CAS requirements - 'OCF_ERR_INVAL_CACHE_DEV'. Use 'OCF_ERR_INVAL_CACHE_DEV' in code. Update error code match in test. closes #317 issue Signed-off-by: Ostrokrzew --- inc/ocf_err.h | 5 ++++- src/mngt/ocf_mngt_cache.c | 4 ++-- tests/functional/pyocf/types/shared.py | 1 + tests/functional/tests/management/test_start_stop.py | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/inc/ocf_err.h b/inc/ocf_err.h index 2d0c966..e3e7dba 100644 --- a/inc/ocf_err.h +++ b/inc/ocf_err.h @@ -117,8 +117,11 @@ typedef enum { /** Invalid cache line size */ OCF_ERR_INVALID_CACHE_LINE_SIZE, - /** Invalid cache name loaded*/ + /** Invalid cache name loaded */ OCF_ERR_CACHE_NAME_MISMATCH, + + /** Device does not meet requirements */ + OCF_ERR_INVAL_CACHE_DEV, } ocf_error_t; #endif /* __OCF_ERR_H__ */ diff --git a/src/mngt/ocf_mngt_cache.c b/src/mngt/ocf_mngt_cache.c index 3c718fa..94625b1 100644 --- a/src/mngt/ocf_mngt_cache.c +++ b/src/mngt/ocf_mngt_cache.c @@ -635,7 +635,7 @@ static void _ocf_mngt_attach_cache_device(ocf_pipeline_t pipeline, if (context->volume_size < OCF_CACHE_SIZE_MIN) { ocf_cache_log(cache, log_err, "ERROR: Cache cache size must " "be at least %llu [MiB]\n", OCF_CACHE_SIZE_MIN / MiB); - OCF_PL_FINISH_RET(context->pipeline, -OCF_ERR_START_CACHE_FAIL); + OCF_PL_FINISH_RET(context->pipeline, -OCF_ERR_INVAL_CACHE_DEV); } ocf_pipeline_next(pipeline); @@ -1211,7 +1211,7 @@ static int _ocf_mngt_cache_start(ocf_ctx_t ctx, ocf_cache_t *cache, result = ocf_metadata_init(tmp_cache, params.metadata.line_size); if (result) { env_rmutex_unlock(&ctx->lock); - result = -OCF_ERR_START_CACHE_FAIL; + result = -OCF_ERR_NO_MEM; goto _cache_mngt_init_instance_ERROR; } params.flags.metadata_inited = true; diff --git a/tests/functional/pyocf/types/shared.py b/tests/functional/pyocf/types/shared.py index 74f97a0..70d7f49 100644 --- a/tests/functional/pyocf/types/shared.py +++ b/tests/functional/pyocf/types/shared.py @@ -47,6 +47,7 @@ class OcfErrorCode(IntEnum): OCF_ERR_INVALID_CACHE_MODE = auto() OCF_ERR_INVALID_CACHE_LINE_SIZE = auto() OCF_ERR_CACHE_NAME_MISMATCH = auto() + OCF_ERR_INVAL_CACHE_DEV = auto() class OcfCompletion: diff --git a/tests/functional/tests/management/test_start_stop.py b/tests/functional/tests/management/test_start_stop.py index d946fc3..17d9c67 100644 --- a/tests/functional/tests/management/test_start_stop.py +++ b/tests/functional/tests/management/test_start_stop.py @@ -359,7 +359,7 @@ def test_start_too_small_device(pyocf_ctx, mode, cls): cache_device = Volume(Size.from_B(20 * 1024 * 1024 - 1)) - with pytest.raises(OcfError, match="OCF_ERR_START_CACHE_FAIL"): + with pytest.raises(OcfError, match="OCF_ERR_INVAL_CACHE_DEV"): Cache.start_on_device(cache_device, cache_mode=mode, cache_line_size=cls)