From be6417306690de5ffb5736cd9eef3aec0124a623 Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Wed, 5 Jun 2019 05:30:57 -0400 Subject: [PATCH] Fix order of operations in cache stop completion Prevent metadata updater being freed by pyocf before it's deinitialized by ocf. Signed-off-by: Michal Mielewczyk --- src/mngt/ocf_mngt_cache.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/mngt/ocf_mngt_cache.c b/src/mngt/ocf_mngt_cache.c index addef31..0b17207 100644 --- a/src/mngt/ocf_mngt_cache.c +++ b/src/mngt/ocf_mngt_cache.c @@ -1942,6 +1942,9 @@ static void ocf_mngt_cache_stop_finish(ocf_pipeline_t pipeline, struct ocf_mngt_cache_stop_context *context = priv; ocf_cache_t cache = context->cache; ocf_ctx_t ctx = context->ctx; + int pipeline_error; + ocf_mngt_cache_stop_end_t pipeline_cmpl; + void *completion_priv; if (!error) { env_mutex_lock(&ctx->lock); @@ -1972,11 +1975,20 @@ static void ocf_mngt_cache_stop_finish(ocf_pipeline_t pipeline, context->cache_name); } - context->cmpl(cache, context->priv, - error ?: context->cache_write_error); + /* + * FIXME: Destroying pipeline before completing management operation is a + * temporary workaround for insufficient object lifetime management in pyocf + * Context must not be referenced after destroying pipeline as this is + * typically freed upon pipeline destroy. + */ + pipeline_error = error ?: context->cache_write_error; + pipeline_cmpl = context->cmpl; + completion_priv = context->priv; ocf_pipeline_destroy(context->pipeline); + pipeline_cmpl(cache, completion_priv, pipeline_error); + if (!error) { /* Finally release cache instance */ ocf_mngt_cache_put(cache);