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 <robert.baldyga@huawei.com>
This commit is contained in:
Robert Baldyga 2024-11-21 21:26:00 +01:00
parent 2c28f33e37
commit 0d06b3a597
3 changed files with 27 additions and 3 deletions

View File

@ -162,6 +162,11 @@ void ocf_resolve_effective_cache_mode(ocf_cache_t cache,
return; return;
} }
if (env_atomic_read(&cache->attach_pt)) {
req->cache_mode = ocf_req_cache_mode_pt;
return;
}
if (cache->pt_unaligned_io && !ocf_req_is_4k(req->addr, req->bytes)) { if (cache->pt_unaligned_io && !ocf_req_is_4k(req->addr, req->bytes)) {
req->cache_mode = ocf_req_cache_mode_pt; req->cache_mode = ocf_req_cache_mode_pt;
return; return;

View File

@ -1901,18 +1901,35 @@ static void _ocf_mngt_attach_shutdown_status(ocf_pipeline_t pipeline,
_ocf_mngt_attach_shutdown_status_complete, context); _ocf_mngt_attach_shutdown_status_complete, context);
} }
static void _ocf_mngt_attach_post_init_finish(void *priv)
{
struct ocf_cache_attach_context *context = priv;
ocf_cache_t cache = context->cache;
ocf_refcnt_unfreeze(&cache->refcnt.d2c);
env_atomic_set(&cache->attach_pt, 0);
ocf_cache_log(cache, log_debug, "Cache attached\n");
ocf_pipeline_next(context->pipeline);
}
static void _ocf_mngt_attach_post_init(ocf_pipeline_t pipeline, static void _ocf_mngt_attach_post_init(ocf_pipeline_t pipeline,
void *priv, ocf_pipeline_arg_t arg) void *priv, ocf_pipeline_arg_t arg)
{ {
struct ocf_cache_attach_context *context = priv; struct ocf_cache_attach_context *context = priv;
ocf_cache_t cache = context->cache; ocf_cache_t cache = context->cache;
env_atomic_set(&cache->attach_pt, 1);
ocf_cleaner_refcnt_unfreeze(cache); ocf_cleaner_refcnt_unfreeze(cache);
ocf_refcnt_unfreeze(&cache->refcnt.metadata); ocf_refcnt_unfreeze(&cache->refcnt.metadata);
ocf_cache_log(cache, log_debug, "Cache attached\n"); ocf_refcnt_freeze(&cache->refcnt.d2c);
ocf_refcnt_register_zero_cb(&cache->refcnt.d2c,
ocf_pipeline_next(pipeline); _ocf_mngt_attach_post_init_finish, context);
} }
static void _ocf_mngt_attach_handle_error( static void _ocf_mngt_attach_handle_error(

View File

@ -106,6 +106,8 @@ struct ocf_cache {
env_atomic flush_in_progress; env_atomic flush_in_progress;
env_mutex flush_mutex; env_mutex flush_mutex;
env_atomic attach_pt;
struct ocf_cleaner cleaner; struct ocf_cleaner cleaner;
struct list_head io_queues; struct list_head io_queues;