|
1 | 1 | /* |
2 | 2 | * Copyright(c) 2012-2022 Intel Corporation |
3 | | - * Copyright(c) 2023-2024 Huawei Technologies |
| 3 | + * Copyright(c) 2023-2025 Huawei Technologies |
4 | 4 | * SPDX-License-Identifier: BSD-3-Clause |
5 | 5 | */ |
6 | 6 |
|
@@ -176,6 +176,7 @@ struct ocf_cache_attach_context { |
176 | 176 | }; |
177 | 177 |
|
178 | 178 | static void _ocf_mngt_cache_set_detached(ocf_cache_t cache); |
| 179 | +static void _ocf_mngt_cache_set_initializing(ocf_cache_t cache); |
179 | 180 |
|
180 | 181 | static void __init_partitions(ocf_cache_t cache) |
181 | 182 | { |
@@ -885,7 +886,7 @@ static int _ocf_mngt_init_new_cache(struct ocf_cache_mngt_init_params *params, |
885 | 886 | env_atomic_set(&(cache->last_access_ms), |
886 | 887 | env_ticks_to_msecs(env_get_tick_count())); |
887 | 888 |
|
888 | | - _ocf_mngt_cache_set_detached(cache); |
| 889 | + _ocf_mngt_cache_set_initializing(cache); |
889 | 890 |
|
890 | 891 | params->cache = cache; |
891 | 892 | params->flags.cache_alloc = true; |
@@ -1200,14 +1201,17 @@ static void _ocf_mngt_attach_read_properties_end(void *priv, int error, |
1200 | 1201 | struct ocf_metadata_load_properties *properties) |
1201 | 1202 | { |
1202 | 1203 | struct ocf_cache_attach_context *context = priv; |
| 1204 | + ocf_cache_t cache = context->cache; |
1203 | 1205 |
|
1204 | 1206 | if (error != -OCF_ERR_NO_METADATA) { |
1205 | 1207 | if (!error) { |
1206 | 1208 | /* |
1207 | 1209 | * To prevent silent metadata overriding, return error if old |
1208 | 1210 | * metadata was detected when attempting to attach cache. |
1209 | 1211 | */ |
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); |
1211 | 1215 | } |
1212 | 1216 | OCF_PL_FINISH_RET(context->pipeline, error); |
1213 | 1217 | } |
@@ -1586,6 +1590,7 @@ static void _ocf_mngt_cache_set_valid(ocf_cache_t cache) |
1586 | 1590 | * Clear initialization state and set the valid bit so we know |
1587 | 1591 | * its in use. |
1588 | 1592 | */ |
| 1593 | + env_bit_clear(ocf_cache_state_initializing, &cache->cache_state); |
1589 | 1594 | env_bit_clear(ocf_cache_state_detached, &cache->cache_state); |
1590 | 1595 | env_bit_set(ocf_cache_state_running, &cache->cache_state); |
1591 | 1596 | } |
@@ -1614,6 +1619,13 @@ static void _ocf_mngt_cache_set_detached(ocf_cache_t cache) |
1614 | 1619 | env_bit_set(ocf_cache_state_detached, &cache->cache_state); |
1615 | 1620 | } |
1616 | 1621 |
|
| 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 | + |
1617 | 1629 | static void _ocf_mngt_init_attached_nonpersistent(ocf_pipeline_t pipeline, |
1618 | 1630 | void *priv, ocf_pipeline_arg_t arg) |
1619 | 1631 | { |
|
0 commit comments