Combine cache ref counter and valid flag into ocf_refcnt

Signed-off-by: Adam Rutkowski <adam.j.rutkowski@intel.com>
This commit is contained in:
Adam Rutkowski 2019-04-10 15:59:21 -04:00
parent 4251cc63e7
commit aafc067fa5
3 changed files with 15 additions and 21 deletions

View File

@ -561,7 +561,7 @@ static int _ocf_mngt_init_new_cache(struct ocf_cachemng_init_params *params)
INIT_LIST_HEAD(&cache->list);
list_add_tail(&cache->list, &params->ctx->caches);
env_atomic_set(&cache->ref_count, 1);
ocf_refcnt_inc(&cache->refcnt.cache);
cache->owner = params->ctx;
/* start with freezed metadata ref counter to indicate detached device*/
@ -1221,7 +1221,7 @@ static int _ocf_mngt_cache_start(ocf_ctx_t ctx, ocf_cache_t *cache,
cache_unlock convention. User is expected to call
ocf_mngt_cache_unlock in future which would up the
semaphore as well as decrement ref_count. */
env_atomic_inc(&(*cache)->ref_count);
ocf_refcnt_inc(&(*cache)->refcnt.cache);
} else {
/* User did not request to lock cache instance after creation -
up the semaphore here since we have acquired the lock to
@ -1244,7 +1244,6 @@ static void _ocf_mng_cache_set_valid(ocf_cache_t cache)
* Clear initialization state and set the valid bit so we know
* its in use.
*/
cache->valid_ocf_cache_device_t = 1;
env_bit_clear(ocf_cache_state_initializing, &cache->cache_state);
env_bit_set(ocf_cache_state_running, &cache->cache_state);
}
@ -2000,7 +1999,7 @@ static void ocf_mngt_cache_stop_finish(ocf_pipeline_t pipeline,
if (!error) {
env_mutex_lock(&ctx->lock);
/* Mark device uninitialized */
cache->valid_ocf_cache_device_t = 0;
ocf_refcnt_freeze(&cache->refcnt.cache);
/* Remove cache from the list */
list_del(&cache->list);
env_mutex_unlock(&ctx->lock);

View File

@ -121,7 +121,7 @@ void ocf_mngt_cache_put(ocf_cache_t cache)
{
OCF_CHECK_NULL(cache);
if (env_atomic_dec_return(&cache->ref_count) == 0) {
if (ocf_refcnt_dec(&cache->refcnt.cache) == 0) {
ocf_metadata_deinit(cache);
env_vfree(cache);
}
@ -155,10 +155,7 @@ int ocf_mngt_cache_get_by_id(ocf_ctx_t ocf_ctx, ocf_cache_id_t id, ocf_cache_t *
if (instance) {
/* if cache is either fully initialized or during recovery */
if (instance->valid_ocf_cache_device_t) {
/* Increase reference counter */
env_atomic_inc(&instance->ref_count);
} else {
if (!ocf_refcnt_inc(&instance->refcnt.cache)) {
/* Cache not initialized yet */
instance = NULL;
}
@ -210,7 +207,8 @@ static int _ocf_mngt_cache_lock(ocf_cache_t cache, int (*lock_fn)(env_rwsem *s),
int ret;
/* Increment reference counter */
env_atomic_inc(&cache->ref_count);
if (!ocf_refcnt_inc(&cache->refcnt.cache))
return -OCF_ERR_CACHE_NOT_EXIST;
env_atomic_inc(&cache->lock_waiter);
ret = lock_fn(&cache->lock);
@ -266,13 +264,7 @@ int ocf_mngt_cache_read_trylock(ocf_cache_t cache)
/* if cache is either fully initialized or during recovery */
static bool _ocf_mngt_cache_try_get(ocf_cache_t cache)
{
if (!!cache->valid_ocf_cache_device_t) {
/* Increase reference counter */
env_atomic_inc(&cache->ref_count);
return true;
}
return false;
return !!ocf_refcnt_inc(&cache->refcnt.cache);
}
int ocf_mngt_cache_get(ocf_cache_t cache)

View File

@ -146,13 +146,10 @@ struct ocf_cache {
ocf_ctx_t owner;
struct list_head list;
/* set to make valid */
uint8_t valid_ocf_cache_device_t;
/* unset running to not serve any more I/O requests */
unsigned long cache_state;
env_atomic ref_count;
struct ocf_superblock_config *conf_meta;
struct ocf_cache_device *device;
@ -169,8 +166,14 @@ struct ocf_cache {
char name[OCF_CACHE_NAME_SIZE];
struct {
/* cache get/put counter */
struct ocf_refcnt cache;
/* # of requests potentially dirtying cachelines */
struct ocf_refcnt dirty;
/* # of requests accessing attached metadata, excluding
* management reqs */
struct ocf_refcnt metadata;
/* # of forced cleaning requests (eviction path) */
struct ocf_refcnt cleaning[OCF_IO_CLASS_MAX];
} refcnt;