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

@@ -59,3 +59,8 @@ void ocf_refcnt_unfreeze(struct ocf_refcnt *rc)
int val = env_atomic_dec_return(&rc->freeze);
ENV_BUG_ON(val < 0);
}
bool ocf_refcnt_frozen(struct ocf_refcnt *rc)
{
return !!env_atomic_read(&rc->freeze);
}

View File

@@ -37,6 +37,8 @@ void ocf_refcnt_freeze(struct ocf_refcnt *rc);
/* Cancel the effect of single ocf_refcnt_freeze call */
void ocf_refcnt_unfreeze(struct ocf_refcnt *rc);
bool ocf_refcnt_frozen(struct ocf_refcnt *rc);
/* Register callback to be called when reference counter drops to 0.
* Must be called after counter is freezed.
* Cannot be called until previously regsitered callback had fired. */

View File

@@ -151,24 +151,6 @@ static env_allocator *_ocf_req_get_allocator(
return ocf_ctx->resources.req->allocator[idx];
}
static void start_cache_req(struct ocf_request *req)
{
ocf_cache_t cache = req->cache;
if (req->queue == req->cache->mngt_queue)
return;
req->d2c = 1;
if (env_atomic_read(&cache->attached)) {
req->d2c = 0;
env_atomic_inc(&cache->pending_cache_requests);
if (!env_atomic_read(&cache->attached)) {
req->d2c = 1;
env_atomic_dec(&cache->pending_cache_requests);
}
}
}
struct ocf_request *ocf_req_new(ocf_queue_t queue, ocf_core_t core,
uint64_t addr, uint32_t bytes, int rw)
{
@@ -212,7 +194,8 @@ struct ocf_request *ocf_req_new(ocf_queue_t queue, ocf_core_t core,
if (queue != cache->mngt_queue)
env_atomic_inc(&cache->pending_requests);
start_cache_req(req);
req->d2c = (queue != cache->mngt_queue) && !ocf_refcnt_inc(
&cache->refcnt.metadata);
env_atomic_set(&req->ref_count, 1);
@@ -292,10 +275,8 @@ void ocf_req_put(struct ocf_request *req)
OCF_DEBUG_TRACE(req->cache);
if (!req->d2c && !env_atomic_dec_return(
&req->cache->pending_cache_requests)) {
env_waitqueue_wake_up(&req->cache->pending_cache_wq);
}
if (!req->d2c && req->io_queue != req->cache->mngt_queue)
ocf_refcnt_dec(&req->cache->refcnt.metadata);
if (req->io_queue != req->cache->mngt_queue)
env_atomic_dec(&req->cache->pending_requests);