Allocate stop context on during start

To make cache stop as simple as possibe and to reduce number of errors, stop
context should be allocated during cache initialize.

Signed-off-by: Michal Mielewczyk <michal.mielewczyk@intel.com>
This commit is contained in:
Michal Mielewczyk 2020-03-20 10:01:10 -04:00
parent f93019165f
commit 9e692435f6
2 changed files with 32 additions and 17 deletions

View File

@ -58,6 +58,7 @@ struct cas_classifier;
struct cache_priv { struct cache_priv {
uint64_t core_id_bitmap[DIV_ROUND_UP(OCF_CORE_MAX, 8*sizeof(uint64_t))]; uint64_t core_id_bitmap[DIV_ROUND_UP(OCF_CORE_MAX, 8*sizeof(uint64_t))];
struct cas_classifier *classifier; struct cas_classifier *classifier;
struct _cache_mngt_stop_context *stop_context;
atomic_t flush_interrupt_enabled; atomic_t flush_interrupt_enabled;
ocf_queue_t mngt_queue; ocf_queue_t mngt_queue;
ocf_queue_t io_queues[]; ocf_queue_t io_queues[];

View File

@ -355,13 +355,6 @@ static int _cache_mngt_core_flush_uninterruptible(ocf_core_t core)
return result; return result;
} }
static void _cache_mngt_cache_priv_deinit(ocf_cache_t cache)
{
struct cache_priv *cache_priv = ocf_cache_get_priv(cache);
vfree(cache_priv);
}
struct _cache_mngt_stop_context { struct _cache_mngt_stop_context {
struct _cache_mngt_async_context async; struct _cache_mngt_async_context async;
int error; int error;
@ -369,6 +362,16 @@ struct _cache_mngt_stop_context {
struct task_struct *finish_thread; struct task_struct *finish_thread;
}; };
static void _cache_mngt_cache_priv_deinit(ocf_cache_t cache)
{
struct cache_priv *cache_priv = ocf_cache_get_priv(cache);
kthread_stop(cache_priv->stop_context->finish_thread);
kfree(cache_priv->stop_context);
vfree(cache_priv);
}
static int exit_instance_finish(void *data) static int exit_instance_finish(void *data)
{ {
struct cache_priv *cache_priv; struct cache_priv *cache_priv;
@ -377,6 +380,9 @@ static int exit_instance_finish(void *data)
bool flush_status; bool flush_status;
int result = 0; int result = 0;
if (kthread_should_stop())
return 0;
flush_status = ocf_mngt_cache_is_dirty(ctx->cache); flush_status = ocf_mngt_cache_is_dirty(ctx->cache);
cache_priv = ocf_cache_get_priv(ctx->cache); cache_priv = ocf_cache_get_priv(ctx->cache);
mngt_queue = cache_priv->mngt_queue; mngt_queue = cache_priv->mngt_queue;
@ -479,19 +485,12 @@ static void _cache_mngt_cache_stop_complete(ocf_cache_t cache, void *priv,
static int _cache_mngt_cache_stop_sync(ocf_cache_t cache) static int _cache_mngt_cache_stop_sync(ocf_cache_t cache)
{ {
struct cache_priv *cache_priv;
struct _cache_mngt_stop_context *context; struct _cache_mngt_stop_context *context;
int result = 0; int result = 0;
context = env_malloc(sizeof(*context), GFP_KERNEL); cache_priv = ocf_cache_get_priv(cache);
if (!context) context = cache_priv->stop_context;
return -ENOMEM;
context->finish_thread = kthread_create(exit_instance_finish, context,
"cas_cache_stop_complete");
if (!context->finish_thread) {
kfree(context);
return -ENOMEM;
}
_cache_mngt_async_context_init(&context->async); _cache_mngt_async_context_init(&context->async);
context->error = 0; context->error = 0;
@ -1737,6 +1736,21 @@ static int _cache_mngt_cache_priv_init(ocf_cache_t cache)
if (!cache_priv) if (!cache_priv)
return -ENOMEM; return -ENOMEM;
cache_priv->stop_context =
env_malloc(sizeof(*cache_priv->stop_context), GFP_KERNEL);
if (!cache_priv->stop_context) {
kfree(cache_priv);
return -ENOMEM;
}
cache_priv->stop_context->finish_thread = kthread_create(
exit_instance_finish, cache_priv->stop_context, "cas_cache_stop_complete");
if (!cache_priv->stop_context->finish_thread) {
kfree(cache_priv->stop_context);
kfree(cache_priv);
return -ENOMEM;
}
atomic_set(&cache_priv->flush_interrupt_enabled, 1); atomic_set(&cache_priv->flush_interrupt_enabled, 1);
ocf_cache_set_priv(cache, cache_priv); ocf_cache_set_priv(cache, cache_priv);