Skip to content

Commit c03cda1

Browse files
committed
Return different errors for metadata found during start and attach
Signed-off-by: Daniel Madej <daniel.madej@huawei.com>
1 parent de05e85 commit c03cda1

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

inc/ocf_def.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright(c) 2012-2022 Intel Corporation
3-
* Copyright(c) 2024 Huawei Technologies
3+
* Copyright(c) 2024-2025 Huawei Technologies
44
* SPDX-License-Identifier: BSD-3-Clause
55
*/
66

@@ -128,6 +128,9 @@ typedef enum {
128128
ocf_cache_state_standby = 4, //!< ocf_cache_state_standby
129129
/*!< OCF cache is currently in standby mode */
130130

131+
ocf_cache_state_initializing = 5, //!< ocf_cache_state_initializing
132+
/*!< OCF cache is being initialized */
133+
131134
ocf_cache_state_max //!< ocf_cache_state_max
132135
/*!< Stopper of cache state enumerator */
133136
} ocf_cache_state_t;

inc/ocf_err.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright(c) 2012-2021 Intel Corporation
3-
* Copyright(c) 2024 Huawei Technologies
3+
* Copyright(c) 2024-2025 Huawei Technologies
44
* SPDX-License-Identifier: BSD-3-Clause
55
*/
66

@@ -42,9 +42,12 @@ typedef enum {
4242
/** No metadata found on device */
4343
OCF_ERR_NO_METADATA,
4444

45-
/** Cache metadata found on device */
45+
/** Cache metadata found on device on cache start */
4646
OCF_ERR_METADATA_FOUND,
4747

48+
/** Cache metadata found on device on cache attach */
49+
OCF_ERR_METADATA_FOUND_ATTACH,
50+
4851
/** Metadata on the device doesn't match with metadata in DRAM */
4952
OCF_ERR_SUPERBLOCK_MISMATCH,
5053

src/mngt/ocf_mngt_cache.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright(c) 2012-2022 Intel Corporation
3-
* Copyright(c) 2023-2024 Huawei Technologies
3+
* Copyright(c) 2023-2025 Huawei Technologies
44
* SPDX-License-Identifier: BSD-3-Clause
55
*/
66

@@ -176,6 +176,7 @@ struct ocf_cache_attach_context {
176176
};
177177

178178
static void _ocf_mngt_cache_set_detached(ocf_cache_t cache);
179+
static void _ocf_mngt_cache_set_initializing(ocf_cache_t cache);
179180

180181
static void __init_partitions(ocf_cache_t cache)
181182
{
@@ -885,7 +886,7 @@ static int _ocf_mngt_init_new_cache(struct ocf_cache_mngt_init_params *params,
885886
env_atomic_set(&(cache->last_access_ms),
886887
env_ticks_to_msecs(env_get_tick_count()));
887888

888-
_ocf_mngt_cache_set_detached(cache);
889+
_ocf_mngt_cache_set_initializing(cache);
889890

890891
params->cache = cache;
891892
params->flags.cache_alloc = true;
@@ -1200,14 +1201,17 @@ static void _ocf_mngt_attach_read_properties_end(void *priv, int error,
12001201
struct ocf_metadata_load_properties *properties)
12011202
{
12021203
struct ocf_cache_attach_context *context = priv;
1204+
ocf_cache_t cache = context->cache;
12031205

12041206
if (error != -OCF_ERR_NO_METADATA) {
12051207
if (!error) {
12061208
/*
12071209
* To prevent silent metadata overriding, return error if old
12081210
* metadata was detected when attempting to attach cache.
12091211
*/
1210-
OCF_PL_FINISH_RET(context->pipeline, -OCF_ERR_METADATA_FOUND);
1212+
if (env_bit_test(ocf_cache_state_initializing, &cache->cache_state))
1213+
OCF_PL_FINISH_RET(context->pipeline, -OCF_ERR_METADATA_FOUND);
1214+
OCF_PL_FINISH_RET(context->pipeline, -OCF_ERR_METADATA_FOUND_ATTACH);
12111215
}
12121216
OCF_PL_FINISH_RET(context->pipeline, error);
12131217
}
@@ -1586,6 +1590,7 @@ static void _ocf_mngt_cache_set_valid(ocf_cache_t cache)
15861590
* Clear initialization state and set the valid bit so we know
15871591
* its in use.
15881592
*/
1593+
env_bit_clear(ocf_cache_state_initializing, &cache->cache_state);
15891594
env_bit_clear(ocf_cache_state_detached, &cache->cache_state);
15901595
env_bit_set(ocf_cache_state_running, &cache->cache_state);
15911596
}
@@ -1614,6 +1619,13 @@ static void _ocf_mngt_cache_set_detached(ocf_cache_t cache)
16141619
env_bit_set(ocf_cache_state_detached, &cache->cache_state);
16151620
}
16161621

1622+
static void _ocf_mngt_cache_set_initializing(ocf_cache_t cache)
1623+
{
1624+
env_bit_clear(ocf_cache_state_running, &cache->cache_state);
1625+
env_bit_set(ocf_cache_state_detached, &cache->cache_state);
1626+
env_bit_set(ocf_cache_state_initializing, &cache->cache_state);
1627+
}
1628+
16171629
static void _ocf_mngt_init_attached_nonpersistent(ocf_pipeline_t pipeline,
16181630
void *priv, ocf_pipeline_arg_t arg)
16191631
{

0 commit comments

Comments
 (0)