Use ref counter to track attach state

Signed-off-by: Adam Rutkowski <adam.j.rutkowski@intel.com>
This commit is contained in:
Adam Rutkowski
2019-04-09 14:22:33 -04:00
parent 979f51612f
commit dc716d6a08
7 changed files with 29 additions and 44 deletions

View File

@@ -562,6 +562,9 @@ static int _ocf_mngt_init_new_cache(struct ocf_cachemng_init_params *params)
env_atomic_set(&cache->ref_count, 1);
cache->owner = params->ctx;
/* start with freezed metadata ref counter to indicate detached device*/
ocf_refcnt_freeze(&cache->refcnt.metadata);
/* Copy all required initialization parameters */
cache->cache_id = params->id;
@@ -1511,9 +1514,7 @@ static void _ocf_mngt_attach_post_init(ocf_pipeline_t pipeline,
context->flags.cleaner_started = true;
}
env_waitqueue_init(&cache->pending_cache_wq);
env_atomic_set(&cache->attached, 1);
ocf_refcnt_unfreeze(&cache->refcnt.metadata);
ocf_pipeline_next(context->pipeline);
}
@@ -1769,7 +1770,6 @@ static void _ocf_mngt_cache_unplug_complete(void *priv, int error)
env_vfree(cache->device);
cache->device = NULL;
env_atomic_set(&cache->attached, 0);
/* TODO: this should be removed from detach after 'attached' stats
are better separated in statistics */
@@ -1960,7 +1960,7 @@ static void ocf_mngt_cache_stop_unplug(ocf_pipeline_t pipeline,
struct ocf_mngt_cache_stop_context *context = priv;
ocf_cache_t cache = context->cache;
if (!env_atomic_read(&cache->attached))
if (!ocf_cache_is_device_attached(cache))
OCF_PL_NEXT_RET(pipeline);
_ocf_mngt_cache_unplug(cache, true, &context->unplug_context,
@@ -2295,19 +2295,21 @@ static void ocf_mngt_cache_detach_flush(ocf_pipeline_t pipeline,
context);
}
static void ocf_mngt_cache_detach_wait_pending_finish(void *priv)
{
struct ocf_mngt_cache_detach_context *context = priv;
ocf_pipeline_next(context->pipeline);
}
static void ocf_mngt_cache_detach_wait_pending(ocf_pipeline_t pipeline,
void *priv, ocf_pipeline_arg_t arg)
{
struct ocf_mngt_cache_detach_context *context = priv;
ocf_cache_t cache = context->cache;
env_atomic_set(&cache->attached, 0);
/* FIXME: This should be asynchronous! */
env_waitqueue_wait(cache->pending_cache_wq,
!env_atomic_read(&cache->pending_cache_requests));
ocf_pipeline_next(context->pipeline);
ocf_refcnt_freeze(&cache->refcnt.metadata);
ocf_refcnt_register_zero_cb(&cache->refcnt.metadata,
ocf_mngt_cache_detach_wait_pending_finish, context);
}
static void ocf_mngt_cache_detach_update_metadata(ocf_pipeline_t pipeline,
@@ -2406,7 +2408,7 @@ void ocf_mngt_cache_detach(ocf_cache_t cache,
if (!cache->mngt_queue)
OCF_CMPL_RET(cache, priv, -OCF_ERR_INVAL);
if (!env_atomic_read(&cache->attached))
if (!ocf_cache_is_device_attached(cache))
OCF_CMPL_RET(cache, priv, -OCF_ERR_INVAL);
result = ocf_pipeline_create(&pipeline, cache,