Skip to content

Commit 0d06b3a

Browse files
committed
Fix race condition during cache attach
After attaching new cache device handle all the IOs in Pass-Through mode until all the d2c requests are completed. Signed-off-by: Robert Baldyga <[email protected]>
1 parent 2c28f33 commit 0d06b3a

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

src/engine/cache_engine.c

+5
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ void ocf_resolve_effective_cache_mode(ocf_cache_t cache,
162162
return;
163163
}
164164

165+
if (env_atomic_read(&cache->attach_pt)) {
166+
req->cache_mode = ocf_req_cache_mode_pt;
167+
return;
168+
}
169+
165170
if (cache->pt_unaligned_io && !ocf_req_is_4k(req->addr, req->bytes)) {
166171
req->cache_mode = ocf_req_cache_mode_pt;
167172
return;

src/mngt/ocf_mngt_cache.c

+20-3
Original file line numberDiff line numberDiff line change
@@ -1901,18 +1901,35 @@ static void _ocf_mngt_attach_shutdown_status(ocf_pipeline_t pipeline,
19011901
_ocf_mngt_attach_shutdown_status_complete, context);
19021902
}
19031903

1904+
1905+
static void _ocf_mngt_attach_post_init_finish(void *priv)
1906+
{
1907+
struct ocf_cache_attach_context *context = priv;
1908+
ocf_cache_t cache = context->cache;
1909+
1910+
ocf_refcnt_unfreeze(&cache->refcnt.d2c);
1911+
1912+
env_atomic_set(&cache->attach_pt, 0);
1913+
1914+
ocf_cache_log(cache, log_debug, "Cache attached\n");
1915+
1916+
ocf_pipeline_next(context->pipeline);
1917+
}
1918+
19041919
static void _ocf_mngt_attach_post_init(ocf_pipeline_t pipeline,
19051920
void *priv, ocf_pipeline_arg_t arg)
19061921
{
19071922
struct ocf_cache_attach_context *context = priv;
19081923
ocf_cache_t cache = context->cache;
19091924

1925+
env_atomic_set(&cache->attach_pt, 1);
1926+
19101927
ocf_cleaner_refcnt_unfreeze(cache);
19111928
ocf_refcnt_unfreeze(&cache->refcnt.metadata);
19121929

1913-
ocf_cache_log(cache, log_debug, "Cache attached\n");
1914-
1915-
ocf_pipeline_next(pipeline);
1930+
ocf_refcnt_freeze(&cache->refcnt.d2c);
1931+
ocf_refcnt_register_zero_cb(&cache->refcnt.d2c,
1932+
_ocf_mngt_attach_post_init_finish, context);
19161933
}
19171934

19181935
static void _ocf_mngt_attach_handle_error(

src/ocf_cache_priv.h

+2
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ struct ocf_cache {
106106
env_atomic flush_in_progress;
107107
env_mutex flush_mutex;
108108

109+
env_atomic attach_pt;
110+
109111
struct ocf_cleaner cleaner;
110112

111113
struct list_head io_queues;

0 commit comments

Comments
 (0)