From 03c2f142b335ad17dd166f49c7096017f19e5660 Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Mon, 21 Jan 2019 13:46:28 +0100 Subject: [PATCH] Cache lock cleanup and API improvements Signed-off-by: Robert Baldyga --- example/simple/src/main.c | 2 +- inc/ocf_mngt.h | 159 ++++------- inc/ocf_stats.h | 16 +- src/mngt/ocf_mngt_cache.c | 251 +----------------- src/mngt/ocf_mngt_core.c | 205 ++++++++++---- src/mngt/ocf_mngt_flush.c | 154 ++++------- src/mngt/ocf_mngt_io_class.c | 10 +- src/ocf_cache.c | 7 - src/ocf_io_class.c | 19 +- src/ocf_stats.c | 83 ++---- src/ocf_stats_priv.h | 2 - src/ocf_trace.c | 28 +- .../_cache_mng_set_cache_mode_test.c | 10 +- 13 files changed, 325 insertions(+), 621 deletions(-) diff --git a/example/simple/src/main.c b/example/simple/src/main.c index db03b07..29b7258 100644 --- a/example/simple/src/main.c +++ b/example/simple/src/main.c @@ -203,7 +203,7 @@ int main(int argc, char *argv[]) perform_workload(core1); /* Remove core from cache */ - if (ocf_mngt_cache_remove_core(cache1, ocf_core_get_id(core1), false)) + if (ocf_mngt_cache_remove_core(core1)) error("Unable to remove core\n"); /* Stop cache */ diff --git a/inc/ocf_mngt.h b/inc/ocf_mngt.h index 9ccbed7..3d1fd55 100644 --- a/inc/ocf_mngt.h +++ b/inc/ocf_mngt.h @@ -333,17 +333,6 @@ int ocf_mngt_cache_start(ocf_ctx_t ctx, ocf_cache_t *cache, */ int ocf_mngt_cache_stop(ocf_cache_t cache); -/** - * @brief Stop cache instance without acquiring cache lock - caller is - * required to hold cache write lock when calling this - * - * @param[in] cache Cache handle - * - * @retval 0 Cache successfully stopped - * @retval Non-zero Error occurred during stopping cache - */ -int ocf_mngt_cache_stop_nolock(ocf_cache_t cache); - /** * @brief Attach caching device to cache instance * @@ -356,19 +345,6 @@ int ocf_mngt_cache_stop_nolock(ocf_cache_t cache); int ocf_mngt_cache_attach(ocf_cache_t cache, struct ocf_mngt_cache_device_config *device_cfg); -/** - * @brief Attach caching device to cache instance without acquiring cache lock - * - caller is required to hold cache write lock when calling this - * - * @param[in] cache Cache handle - * @param[in] device_cfg Caching device configuration - * - * @retval 0 Cache cache successfully attached - * @retval Non-zero Error occurred during attaching cache - */ -int ocf_mngt_cache_attach_nolock(ocf_cache_t cache, - struct ocf_mngt_cache_device_config *device_cfg); - /** * @brief Detach caching cache * @@ -382,7 +358,8 @@ int ocf_mngt_cache_detach(ocf_cache_t cache); /** * @brief Load cache instance * - * @param[in] cache Cache handle + * @param[in] ctx OCF context + * @param[out] cache Cache handle * @param[in] cfg Cache configuration * @param[in] device_cfg Caching device configuration * @@ -399,7 +376,7 @@ int ocf_mngt_cache_load(ocf_ctx_t ctx, ocf_cache_t *cache, * @brief Add core to cache instance * * @param[in] cache Cache handle - * @param[in] core Core object handle + * @param[out] core Core object handle * @param[in] cfg Core configuration * * @retval 0 Core successfully added core to cache @@ -408,46 +385,25 @@ int ocf_mngt_cache_load(ocf_ctx_t ctx, ocf_cache_t *cache, int ocf_mngt_cache_add_core(ocf_cache_t cache, ocf_core_t *core, struct ocf_mngt_core_config *cfg); -/** - * @brief Add core to cache instance without acquiring cache lock - caller is - required to hold cache write lock when calling this - * - * @param[in] cache Cache handle - * @param[in] core Core object handle - * @param[in] cfg Core configuration - * - * @retval 0 Core successfully added core to cache - * @retval Non-zero Error occurred and adding core failed - */ -int ocf_mngt_cache_add_core_nolock(ocf_cache_t cache, ocf_core_t *core, - struct ocf_mngt_core_config *cfg); - /** * @brief Remove core from cache instance * - * @param[in] cache Cache handle - * @param[in] core_id Core ID - * @param[in] detach only detach core without removing it from cache metadata + * @param[in] cache Core handle * - * @retval 0 Core successfully removed core from cache - * @retval Non-zero Error occurred and removing core failed + * @retval 0 Core successfully removed from cache + * @retval Non-zero Error occurred and removing core failed */ -int ocf_mngt_cache_remove_core(ocf_cache_t cache, ocf_core_id_t core_id, - bool detach); +int ocf_mngt_cache_remove_core(ocf_core_t core); /** - * @brief Remove core from cache instance without acquiring cache lock - caller - * is required to hold cache write lock when calling this + * @brief Detach core from cache instance * - * @param[in] cache Cache handle - * @param[in] core_id Core ID - * @param[in] detach only detach core without removing it from cache metadata + * @param[in] core Core handle * - * @retval 0 Core successfully removed core from cache - * @retval Non-zero Error occurred and removing core failed + * @retval 0 Core successfully detached from cache + * @retval Non-zero Error occurred and detaching core failed */ -int ocf_mngt_cache_remove_core_nolock(ocf_cache_t cache, ocf_core_id_t core_id, - bool detach); +int ocf_mngt_cache_detach_core(ocf_core_t core); /* Flush operations */ @@ -462,45 +418,19 @@ int ocf_mngt_cache_remove_core_nolock(ocf_cache_t cache, ocf_core_id_t core_id, */ int ocf_mngt_cache_flush(ocf_cache_t cache, bool interruption); -/** - * @brief Flush data from given cache without acquiring cache lock - caller is - * required to hold cache write OR read lock when calling this - * - * @param[in] cache Cache handle - * @param[in] interruption Allow for interruption - * - * @retval 0 Successfully flushed given cache - * @retval Non-zero Error occurred and flushing cache failed - */ -int ocf_mngt_cache_flush_nolock(ocf_cache_t cache, bool interruption); - /** * @brief Flush data to given core * - * @param[in] cache Cache handle - * @param[in] id Core ID + * @param[in] core Core handle * @param[in] interruption Allow for interruption * * @retval 0 Successfully flushed data to given core * @retval Non-zero Error occurred and flushing data to core failed */ -int ocf_mngt_core_flush(ocf_cache_t cache, ocf_core_id_t id, bool interruption); +int ocf_mngt_core_flush(ocf_core_t core, bool interruption); /** - * @brief Flush data to given core without acquiring cache lock - caller is - * required to hold cache write OR read lock when calling this - * - * @param[in] cache Cache handle - * @param[in] id Core ID - * @param[in] interruption Allow for interruption - * - * @retval 0 Successfully flushed data to given core - * @retval Non-zero Error occurred and flushing data to core failed - */ -int ocf_mngt_core_flush_nolock(ocf_cache_t cache, ocf_core_id_t id, - bool interruption); -/** - * @brief Interrupt existing flushing of cache or cache + * @brief Interrupt existing flushing of cache or core * * @param[in] cache Cache instance * @@ -512,14 +442,13 @@ int ocf_mngt_cache_flush_interrupt(ocf_cache_t cache); /** * @brief Purge data to given core * - * @param[in] cache Cache handle - * @param[in] id Core ID + * @param[in] core Core handle * @param[in] interruption Allow for interruption * * @retval 0 Successfully purged data to given core * @retval Non-zero Error occurred and purging data to core failed */ -int ocf_mngt_core_purge(ocf_cache_t cache, ocf_core_id_t id, bool interruption); +int ocf_mngt_core_purge(ocf_core_t core, bool interruption); /** * @brief Purge data from given cache * @@ -629,53 +558,71 @@ int ocf_mngt_io_class_configure(ocf_cache_t cache, /** * @brief Set core sequential cutoff threshold * - * @param[in] cache Cache handle - * @param[in] core_id Core ID + * @param[in] core Core handle * @param[in] thresh threshold in bytes for sequential cutoff * * @retval 0 Sequential cutoff threshold has been set successfully * @retval Non-zero Error occured and threshold hasn't been updated */ -int ocf_mngt_set_seq_cutoff_threshold(ocf_cache_t cache, ocf_core_id_t core_id, - uint32_t thresh); +int ocf_mngt_core_set_seq_cutoff_threshold(ocf_core_t core, uint32_t thresh); /** - * @brief Set core sequential cutoff policy + * @brief Set sequential cutoff threshold for all cores in cache * * @param[in] cache Cache handle - * @param[in] core_id Core ID - * @param[in] policy sequential cutoff policy + * @param[in] thresh threshold in bytes for sequential cutoff * - * @retval 0 Sequential cutoff policy has been set successfully - * @retval Non-zero Error occured and policy hasn't been updated + * @retval 0 Sequential cutoff threshold has been set successfully + * @retval Non-zero Error occured and threshold hasn't been updated */ -int ocf_mngt_set_seq_cutoff_policy(ocf_cache_t cache, ocf_core_id_t core_id, - ocf_seq_cutoff_policy policy); +int ocf_mngt_core_set_seq_cutoff_threshold_all(ocf_cache_t cache, + uint32_t thresh); /** * @brief Get core sequential cutoff threshold * - * @param[in] cache Cache handle - * @param[in] core_id Core ID + * @param[in] core Core handle * @param[in] thresh threshold in bytes for sequential cutoff * * @retval 0 Sequential cutoff threshold has been get successfully * @retval Non-zero Error occured */ -int ocf_mngt_get_seq_cutoff_threshold(ocf_cache_t cache, ocf_core_id_t core_id, - uint32_t *thresh); +int ocf_mngt_core_get_seq_cutoff_threshold(ocf_core_t core, uint32_t *thresh); + +/** + * @brief Set core sequential cutoff policy + * + * @param[in] core Core handle + * @param[in] policy sequential cutoff policy + * + * @retval 0 Sequential cutoff policy has been set successfully + * @retval Non-zero Error occured and policy hasn't been updated + */ +int ocf_mngt_core_set_seq_cutoff_policy(ocf_core_t core, + ocf_seq_cutoff_policy policy); + +/** + * @brief Set sequential cutoff policy for all cores in cache + * + * @param[in] cache Cache handle + * @param[in] policy sequential cutoff policy + * + * @retval 0 Sequential cutoff policy has been set successfully + * @retval Non-zero Error occured and policy hasn't been updated + */ +int ocf_mngt_core_set_seq_cutoff_policy_all(ocf_cache_t cache, + ocf_seq_cutoff_policy policy); /** * @brief Get core sequential cutoff policy * - * @param[in] cache Cache handle - * @param[in] core_id Core ID + * @param[in] core Core handle * @param[in] policy sequential cutoff policy * * @retval 0 Sequential cutoff policy has been get successfully * @retval Non-zero Error occured */ -int ocf_mngt_get_seq_cutoff_policy(ocf_cache_t cache, ocf_core_id_t core_id, +int ocf_mngt_core_get_seq_cutoff_policy(ocf_core_t core, ocf_seq_cutoff_policy *policy); /** diff --git a/inc/ocf_stats.h b/inc/ocf_stats.h index bf43066..379af13 100644 --- a/inc/ocf_stats.h +++ b/inc/ocf_stats.h @@ -155,14 +155,22 @@ struct ocf_stats_core { }; /** - * @brief Initialize or reset statistics. + * @brief Initialize or reset core statistics * * Initialize or reset counters used for statistics. * - * @param[in] cache OCF cache device handle - * @param[in] core_id Id of core for which statistics should be initialized. + * @param[in] core Core handle */ -int ocf_stats_initialize(ocf_cache_t cache, ocf_core_id_t core_id); +void ocf_core_stats_initialize(ocf_core_t core); + +/** + * @brief Initialize or reset statistics of all cores in cache + * + * Initialize or reset counters used for statistics. + * + * @param[in] cache Cache handle + */ +void ocf_core_stats_initialize_all(ocf_cache_t cache); /** * @brief ocf_io_class_get_stats retrieve cache statistics diff --git a/src/mngt/ocf_mngt_cache.c b/src/mngt/ocf_mngt_cache.c index c3bea95..c34301a 100644 --- a/src/mngt/ocf_mngt_cache.c +++ b/src/mngt/ocf_mngt_cache.c @@ -1479,7 +1479,7 @@ int ocf_mngt_cache_start(ocf_ctx_t ctx, ocf_cache_t *cache, return result; } -int ocf_mngt_cache_attach_nolock(ocf_cache_t cache, +int ocf_mngt_cache_attach(ocf_cache_t cache, struct ocf_mngt_cache_device_config *device_cfg) { int result; @@ -1502,25 +1502,6 @@ int ocf_mngt_cache_attach_nolock(ocf_cache_t cache, return result; } -int ocf_mngt_cache_attach(ocf_cache_t cache, - struct ocf_mngt_cache_device_config *device_cfg) -{ - int result; - - if (!cache || !device_cfg) - return -OCF_ERR_INVAL; - - result = ocf_mngt_cache_lock(cache); - if (result) - return result; - - result = ocf_mngt_cache_attach_nolock(cache, device_cfg); - - ocf_mngt_cache_unlock(cache); - - return result; -} - /** * @brief Unplug caching device from cache instance. Variable size metadata * containers are deinitialiazed as well as other cacheline related @@ -1696,15 +1677,19 @@ int ocf_mngt_cache_load(ocf_ctx_t ctx, ocf_cache_t *cache, return 0; } -int ocf_mngt_cache_stop_nolock(ocf_cache_t cache) +int ocf_mngt_cache_stop(ocf_cache_t cache) { int result; - const char *cache_name; + char cache_name[OCF_CACHE_NAME_SIZE]; ocf_ctx_t context; OCF_CHECK_NULL(cache); - cache_name = ocf_cache_get_name(cache); + result = env_strncpy(cache_name, sizeof(cache_name), + ocf_cache_get_name(cache), sizeof(cache_name)); + if (result) + return result; + context = ocf_cache_get_ctx(cache); ocf_cache_log(cache, log_info, "Stopping cache\n"); @@ -1725,201 +1710,6 @@ int ocf_mngt_cache_stop_nolock(ocf_cache_t cache) return result; } -int ocf_mngt_cache_stop(ocf_cache_t cache) -{ - int result; - - OCF_CHECK_NULL(cache); - - result = ocf_mngt_cache_lock(cache); - if (result) - return result; - - result = ocf_mngt_cache_stop_nolock(cache); - - ocf_mngt_cache_unlock(cache); - - return result; -} - -static int _cache_mng_set_core_seq_cutoff_threshold(ocf_core_t core, void *cntx) -{ - uint32_t threshold = *(uint32_t*) cntx; - ocf_cache_t cache = ocf_core_get_cache(core); - ocf_core_id_t core_id = ocf_core_get_id(core); - uint32_t threshold_old = cache->core_conf_meta[core_id]. - seq_cutoff_threshold; - - if (threshold_old == threshold) { - ocf_core_log(core, log_info, - "Sequential cutoff threshold %u bytes is " - "already set\n", threshold); - return 0; - } - cache->core_conf_meta[core_id].seq_cutoff_threshold = threshold; - - if (ocf_metadata_flush_superblock(cache)) { - ocf_core_log(core, log_err, "Failed to store sequential " - "cutoff threshold change. Reverting\n"); - cache->core_conf_meta[core_id].seq_cutoff_threshold = - threshold_old; - return -OCF_ERR_WRITE_CACHE; - } - - ocf_core_log(core, log_info, "Changing sequential cutoff " - "threshold from %u to %u bytes successful\n", - threshold_old, threshold); - - return 0; -} - -int ocf_mngt_set_seq_cutoff_threshold(ocf_cache_t cache, - ocf_core_id_t core_id, uint32_t thresh) -{ - int result = ocf_mngt_cache_lock(cache); - if (result) - return result; - - if (core_id == OCF_CORE_ID_INVALID) { - /* Core id was not specified so threshold will be set - * for cache and all attached cores. - */ - result = ocf_core_visit(cache, - _cache_mng_set_core_seq_cutoff_threshold, - &thresh, - true); - } else { - /* Setting threshold for specified core. */ - ocf_core_t core; - result = ocf_core_get(cache, core_id, &core); - if (result) - goto END; - result = _cache_mng_set_core_seq_cutoff_threshold(core, &thresh); - } -END: - ocf_mngt_cache_unlock(cache); - - return result; -} - -static const char *_ocf_seq_cutoff_policy_names[ocf_seq_cutoff_policy_max] = { - [ocf_seq_cutoff_policy_always] = "always", - [ocf_seq_cutoff_policy_full] = "full", - [ocf_seq_cutoff_policy_never] = "never", -}; - -static const char *_cache_mng_seq_cutoff_policy_get_name( - ocf_seq_cutoff_policy policy) -{ - if (policy < 0 || policy >= ocf_seq_cutoff_policy_max) - return NULL; - - return _ocf_seq_cutoff_policy_names[policy]; -} - -static int _cache_mng_set_core_seq_cutoff_policy(ocf_core_t core, void *cntx) -{ - ocf_seq_cutoff_policy policy = *(ocf_seq_cutoff_policy*) cntx; - ocf_cache_t cache = ocf_core_get_cache(core); - ocf_core_id_t core_id = ocf_core_get_id(core); - uint32_t policy_old = cache->core_conf_meta[core_id].seq_cutoff_policy; - - if (policy_old == policy) { - ocf_core_log(core, log_info, - "Sequential cutoff policy %s is already set\n", - _cache_mng_seq_cutoff_policy_get_name(policy)); - return 0; - } - - cache->core_conf_meta[core_id].seq_cutoff_policy = policy; - - if (ocf_metadata_flush_superblock(cache)) { - ocf_core_log(core, log_err, "Failed to store sequential " - "cutoff policy change. Reverting\n"); - cache->core_conf_meta[core_id].seq_cutoff_policy = policy_old; - return -OCF_ERR_WRITE_CACHE; - } - - ocf_core_log(core, log_info, - "Changing sequential cutoff policy from %s to %s\n", - _cache_mng_seq_cutoff_policy_get_name(policy_old), - _cache_mng_seq_cutoff_policy_get_name(policy)); - - return 0; -} - -int ocf_mngt_set_seq_cutoff_policy(ocf_cache_t cache, ocf_core_id_t core_id, - ocf_seq_cutoff_policy policy) -{ - ocf_core_t core; - int result = ocf_mngt_cache_lock(cache); - if (result) - return result; - - if (core_id == OCF_CORE_ID_INVALID) { - /* Core id was not specified so policy will be set - * for cache and all attached cores. - */ - result = ocf_core_visit(cache, - _cache_mng_set_core_seq_cutoff_policy, - &policy, - true); - } else { - /* Setting policy for specified core. */ - result = ocf_core_get(cache, core_id, &core); - if (result) - goto END; - result = _cache_mng_set_core_seq_cutoff_policy(core, &policy); - } -END: - ocf_mngt_cache_unlock(cache); - - return result; -} - -int ocf_mngt_get_seq_cutoff_threshold(ocf_cache_t cache, ocf_core_id_t core_id, - uint32_t *thresh) -{ - ocf_core_t core; - int result; - - result = ocf_mngt_cache_lock(cache); - if (result) - return result; - - result = ocf_core_get(cache, core_id, &core); - if (result) - goto out; - - *thresh = ocf_core_get_seq_cutoff_threshold(core); - -out: - ocf_mngt_cache_unlock(cache); - - return result; -} - -int ocf_mngt_get_seq_cutoff_policy(ocf_cache_t cache, ocf_core_id_t core_id, - ocf_seq_cutoff_policy *policy) -{ - ocf_core_t core; - int result; - - result = ocf_mngt_cache_lock(cache); - if (result) - return result; - - result = ocf_core_get(cache, core_id, &core); - if (result) - goto out; - *policy = ocf_core_get_seq_cutoff_policy(core); - -out: - ocf_mngt_cache_unlock(cache); - - return result; -} - static int _cache_mng_set_cache_mode(ocf_cache_t cache, ocf_cache_mode_t mode, uint8_t flush) { @@ -1941,7 +1731,7 @@ static int _cache_mng_set_cache_mode(ocf_cache_t cache, ocf_cache_mode_t mode, if (flush) { /* Flush required, do it, do it, do it... */ - result = ocf_mngt_cache_flush_nolock(cache, true); + result = ocf_mngt_cache_flush(cache, true); if (result) { cache->conf_meta->cache_mode = mode_old; @@ -1987,10 +1777,6 @@ int ocf_mngt_cache_set_mode(ocf_cache_t cache, ocf_cache_mode_t mode, return -OCF_ERR_INVAL; } - result = ocf_mngt_cache_lock(cache); - if (result) - return result; - result = _cache_mng_set_cache_mode(cache, mode, flush); if (result) { @@ -2000,8 +1786,6 @@ int ocf_mngt_cache_set_mode(ocf_cache_t cache, ocf_cache_mode_t mode, "failed\n", name); } - ocf_mngt_cache_unlock(cache); - return result; } @@ -2065,22 +1849,18 @@ int ocf_mngt_cache_detach(ocf_cache_t cache) int result; ocf_cache_mode_t mode; + OCF_CHECK_NULL(cache); + no = cache->conf_meta->core_count; - result = ocf_mngt_cache_lock(cache); - if (result) - return result; - - if (!env_atomic_read(&cache->attached)) { - result = -EINVAL; - goto unlock; - } + if (!env_atomic_read(&cache->attached)) + return -EINVAL; /* temporarily switch to PT */ mode = cache->conf_meta->cache_mode; result = _cache_mng_set_cache_mode(cache, ocf_cache_mode_pt, true); if (result) - goto unlock; + return result; /* wait for all requests referencing cacheline metadata to finish */ env_atomic_set(&cache->attached, 0); @@ -2117,8 +1897,5 @@ int ocf_mngt_cache_detach(ocf_cache_t cache) } } -unlock: - ocf_mngt_cache_unlock(cache); - return result; } diff --git a/src/mngt/ocf_mngt_core.c b/src/mngt/ocf_mngt_core.c index f855185..740b52d 100644 --- a/src/mngt/ocf_mngt_core.c +++ b/src/mngt/ocf_mngt_core.c @@ -32,7 +32,7 @@ static int _ocf_mngt_cache_try_add_core(ocf_cache_t cache, ocf_core_t *core, obj = &tmp_core->obj; if (ocf_ctx_get_data_obj_type_id(cache->owner, obj->type) != - cfg->data_obj_type) { + cfg->data_obj_type) { result = -OCF_ERR_INVAL_DATA_OBJ_TYPE; goto error_out; } @@ -116,7 +116,7 @@ static int _ocf_mngt_cache_add_core(ocf_cache_t cache, ocf_core_t *core, if (ocf_cache_is_device_attached(cache) && cleaning_policy_ops[clean_type].add_core) { result = cleaning_policy_ops[clean_type].add_core(cache, - cfg->core_id); + cfg->core_id); if (result) goto error_after_open; } @@ -129,7 +129,7 @@ static int _ocf_mngt_cache_add_core(ocf_cache_t cache, ocf_core_t *core, goto error_after_clean_pol; } /* When adding new core to cache, reset all core/cache statistics */ - ocf_stats_init(tmp_core); + ocf_core_stats_initialize(tmp_core); env_atomic_set(&cache->core_runtime_meta[cfg->core_id]. cached_clines, 0); env_atomic_set(&cache->core_runtime_meta[cfg->core_id]. @@ -144,9 +144,9 @@ static int _ocf_mngt_cache_add_core(ocf_cache_t cache, ocf_core_t *core, /* Set default cache parameters for sequential */ cache->core_conf_meta[cfg->core_id].seq_cutoff_policy = - ocf_seq_cutoff_policy_default; + ocf_seq_cutoff_policy_default; cache->core_conf_meta[cfg->core_id].seq_cutoff_threshold = - cfg->seq_cutoff_threshold; + cfg->seq_cutoff_threshold; /* Add core sequence number for atomic metadata matching */ core_sequence_no = _ocf_mngt_get_core_seq_no(cache); @@ -186,7 +186,7 @@ error_after_counters_allocation: tmp_core->counters = NULL; error_after_clean_pol: - if (cleaning_policy_ops[clean_type].remove_core) + if (cleaning_policy_ops[clean_type].remove_core) cleaning_policy_ops[clean_type].remove_core(cache, cfg->core_id); error_after_open: @@ -252,8 +252,8 @@ static int __ocf_mngt_lookup_core_uuid(ocf_cache_t cache, } if (!env_strncmp(core->obj.uuid.data, cfg->uuid.data, - OCF_MIN(core->obj.uuid.size, - cfg->uuid.size))) + OCF_MIN(core->obj.uuid.size, + cfg->uuid.size))) return i; } @@ -306,7 +306,7 @@ static int __ocf_mngt_find_core_id(ocf_cache_t cache, } else if (cfg->core_id < OCF_CORE_MAX) { /* check if id is not used already */ if (env_bit_test(cfg->core_id, - cache->conf_meta->valid_object_bitmap)) { + cache->conf_meta->valid_object_bitmap)) { ocf_cache_log(cache, log_debug, "Core ID already allocated: %d.\n", cfg->core_id); @@ -362,7 +362,7 @@ int ocf_mngt_core_init_front_dobj(ocf_core_t core) return ocf_dobj_open(&core->front_obj); } -int ocf_mngt_cache_add_core_nolock(ocf_cache_t cache, ocf_core_t *core, +int ocf_mngt_cache_add_core(ocf_cache_t cache, ocf_core_t *core, struct ocf_mngt_core_config *cfg) { int result; @@ -419,24 +419,6 @@ out: return result; } -int ocf_mngt_cache_add_core(ocf_cache_t cache, ocf_core_t *core, - struct ocf_mngt_core_config *cfg) -{ - int result; - - OCF_CHECK_NULL(cache); - - result = ocf_mngt_cache_lock(cache); - if (result) - return result; - - result = ocf_mngt_cache_add_core_nolock(cache, core, cfg); - - ocf_mngt_cache_unlock(cache); - - return result; -} - static int _ocf_mngt_cache_remove_core(ocf_core_t core, bool detach) { struct ocf_cache *cache = core->obj.cache; @@ -470,24 +452,17 @@ static int _ocf_mngt_cache_remove_core(ocf_core_t core, bool detach) return 0; } -int ocf_mngt_cache_remove_core_nolock(ocf_cache_t cache, ocf_core_id_t core_id, - bool detach) +int ocf_mngt_cache_remove_core(ocf_core_t core) { + ocf_cache_t cache = ocf_core_get_cache(core); + const char *core_name = ocf_core_get_name(core); int result; - ocf_core_t core; - const char *core_name; - - OCF_CHECK_NULL(cache); - - result = ocf_core_get(cache, core_id, &core); - if (result < 0) - return -OCF_ERR_CORE_NOT_AVAIL; ocf_core_log(core, log_debug, "Removing core\n"); core_name = ocf_core_get_name(core); - result = _ocf_mngt_cache_remove_core(core, detach); + result = _ocf_mngt_cache_remove_core(core, false); if (!result) { ocf_cache_log(cache, log_info, "Core %s successfully removed\n", core_name); @@ -499,20 +474,152 @@ int ocf_mngt_cache_remove_core_nolock(ocf_cache_t cache, ocf_core_id_t core_id, return result; } -int ocf_mngt_cache_remove_core(ocf_cache_t cache, ocf_core_id_t core_id, - bool detach) +int ocf_mngt_cache_detach_core(ocf_core_t core) { + ocf_cache_t cache = ocf_core_get_cache(core); + const char *core_name = ocf_core_get_name(core); int result; - OCF_CHECK_NULL(cache); + ocf_core_log(core, log_debug, "Detaching core\n"); - result = ocf_mngt_cache_lock(cache); - if (result) - return result; - - result = ocf_mngt_cache_remove_core_nolock(cache, core_id, detach); - - ocf_mngt_cache_unlock(cache); + result = _ocf_mngt_cache_remove_core(core, true); + if (!result) { + ocf_cache_log(cache, log_info, "Core %s successfully detached\n", + core_name); + } else { + ocf_cache_log(cache, log_err, "Detaching core %s failed\n", + core_name); + } return result; } + +static int _cache_mng_set_core_seq_cutoff_threshold(ocf_core_t core, void *cntx) +{ + uint32_t threshold = *(uint32_t*) cntx; + ocf_cache_t cache = ocf_core_get_cache(core); + ocf_core_id_t core_id = ocf_core_get_id(core); + uint32_t threshold_old = cache->core_conf_meta[core_id]. + seq_cutoff_threshold; + + if (threshold_old == threshold) { + ocf_core_log(core, log_info, + "Sequential cutoff threshold %u bytes is " + "already set\n", threshold); + return 0; + } + cache->core_conf_meta[core_id].seq_cutoff_threshold = threshold; + + if (ocf_metadata_flush_superblock(cache)) { + ocf_core_log(core, log_err, "Failed to store sequential " + "cutoff threshold change. Reverting\n"); + cache->core_conf_meta[core_id].seq_cutoff_threshold = + threshold_old; + return -OCF_ERR_WRITE_CACHE; + } + + ocf_core_log(core, log_info, "Changing sequential cutoff " + "threshold from %u to %u bytes successful\n", + threshold_old, threshold); + + return 0; +} + +int ocf_mngt_core_set_seq_cutoff_threshold(ocf_core_t core, uint32_t thresh) +{ + OCF_CHECK_NULL(core); + + return _cache_mng_set_core_seq_cutoff_threshold(core, &thresh); +} + +int ocf_mngt_core_set_seq_cutoff_threshold_all(ocf_cache_t cache, + uint32_t thresh) +{ + OCF_CHECK_NULL(cache); + + return ocf_core_visit(cache, _cache_mng_set_core_seq_cutoff_threshold, + &thresh, true); +} + +int ocf_mngt_core_get_seq_cutoff_threshold(ocf_core_t core, uint32_t *thresh) +{ + OCF_CHECK_NULL(core); + OCF_CHECK_NULL(thresh); + + *thresh = ocf_core_get_seq_cutoff_threshold(core); + + return 0; +} + +static const char *_ocf_seq_cutoff_policy_names[ocf_seq_cutoff_policy_max] = { + [ocf_seq_cutoff_policy_always] = "always", + [ocf_seq_cutoff_policy_full] = "full", + [ocf_seq_cutoff_policy_never] = "never", +}; + +static const char *_cache_mng_seq_cutoff_policy_get_name( + ocf_seq_cutoff_policy policy) +{ + if (policy < 0 || policy >= ocf_seq_cutoff_policy_max) + return NULL; + + return _ocf_seq_cutoff_policy_names[policy]; +} + +static int _cache_mng_set_core_seq_cutoff_policy(ocf_core_t core, void *cntx) +{ + ocf_seq_cutoff_policy policy = *(ocf_seq_cutoff_policy*) cntx; + ocf_cache_t cache = ocf_core_get_cache(core); + ocf_core_id_t core_id = ocf_core_get_id(core); + uint32_t policy_old = cache->core_conf_meta[core_id].seq_cutoff_policy; + + if (policy_old == policy) { + ocf_core_log(core, log_info, + "Sequential cutoff policy %s is already set\n", + _cache_mng_seq_cutoff_policy_get_name(policy)); + return 0; + } + + cache->core_conf_meta[core_id].seq_cutoff_policy = policy; + + if (ocf_metadata_flush_superblock(cache)) { + ocf_core_log(core, log_err, "Failed to store sequential " + "cutoff policy change. Reverting\n"); + cache->core_conf_meta[core_id].seq_cutoff_policy = policy_old; + return -OCF_ERR_WRITE_CACHE; + } + + ocf_core_log(core, log_info, + "Changing sequential cutoff policy from %s to %s\n", + _cache_mng_seq_cutoff_policy_get_name(policy_old), + _cache_mng_seq_cutoff_policy_get_name(policy)); + + return 0; +} + +int ocf_mngt_core_set_seq_cutoff_policy(ocf_core_t core, + ocf_seq_cutoff_policy policy) +{ + OCF_CHECK_NULL(core); + + return _cache_mng_set_core_seq_cutoff_policy(core, &policy); +} +int ocf_mngt_core_set_seq_cutoff_policy_all(ocf_cache_t cache, + ocf_seq_cutoff_policy policy) +{ + OCF_CHECK_NULL(cache); + + return ocf_core_visit(cache, _cache_mng_set_core_seq_cutoff_policy, + &policy, true); +} + +int ocf_mngt_core_get_seq_cutoff_policy(ocf_core_t core, + ocf_seq_cutoff_policy *policy) +{ + OCF_CHECK_NULL(core); + OCF_CHECK_NULL(policy); + + *policy = ocf_core_get_seq_cutoff_policy(core); + + return 0; +} diff --git a/src/mngt/ocf_mngt_flush.c b/src/mngt/ocf_mngt_flush.c index a6163c4..8aebe27 100644 --- a/src/mngt/ocf_mngt_flush.c +++ b/src/mngt/ocf_mngt_flush.c @@ -35,6 +35,8 @@ bool ocf_mngt_cache_is_dirty(ocf_cache_t cache) { uint32_t i; + OCF_CHECK_NULL(cache); + for (i = 0; i < OCF_CORE_MAX; ++i) { if (!cache->core_conf_meta[i].added) continue; @@ -430,7 +432,7 @@ out: * @param allow_interruption whenever to allow interruption of flushing process. * if set to 0, all requests to interrupt flushing will be ignored */ -static int _ocf_mng_cache_flush_nolock(ocf_cache_t cache, bool interruption) +static int _ocf_mng_cache_flush(ocf_cache_t cache, bool interruption) { int result = 0; int i, j; @@ -460,12 +462,18 @@ static int _ocf_mng_cache_flush_nolock(ocf_cache_t cache, bool interruption) return result; } -int ocf_mngt_cache_flush_nolock(ocf_cache_t cache, bool interruption) +int ocf_mngt_cache_flush(ocf_cache_t cache, bool interruption) { int result = 0; OCF_CHECK_NULL(cache); + if (!ocf_cache_is_device_attached(cache)) { + ocf_cache_log(cache, log_err, "Cannot flush cache - " + "cache device is detached\n"); + return -OCF_ERR_INVAL; + } + if (ocf_cache_is_incomplete(cache)) { ocf_cache_log(cache, log_err, "Cannot flush cache - " "cache is in incomplete state\n"); @@ -476,7 +484,7 @@ int ocf_mngt_cache_flush_nolock(ocf_cache_t cache, bool interruption) _ocf_mngt_begin_flush(cache); - result = _ocf_mng_cache_flush_nolock(cache, interruption); + result = _ocf_mng_cache_flush(cache, interruption); _ocf_mngt_end_flush(cache); @@ -486,9 +494,9 @@ int ocf_mngt_cache_flush_nolock(ocf_cache_t cache, bool interruption) return result; } -static int _ocf_mng_core_flush_nolock(ocf_core_t core, bool interruption) +static int _ocf_mng_core_flush(ocf_core_t core, bool interruption) { - struct ocf_cache *cache = core->obj.cache; + ocf_cache_t cache = ocf_core_get_cache(core); ocf_core_id_t core_id = ocf_core_get_id(core); int ret; @@ -508,17 +516,20 @@ static int _ocf_mng_core_flush_nolock(ocf_core_t core, bool interruption) return ret; } -int ocf_mngt_core_flush_nolock(ocf_cache_t cache, ocf_core_id_t id, - bool interruption) +int ocf_mngt_core_flush(ocf_core_t core, bool interruption) { - ocf_core_t core; + ocf_cache_t cache; int ret = 0; - OCF_CHECK_NULL(cache); + OCF_CHECK_NULL(core); - ret = ocf_core_get(cache, id, &core); - if (ret < 0) - return -OCF_ERR_CORE_NOT_AVAIL; + cache = ocf_core_get_cache(core); + + if (!ocf_cache_is_device_attached(cache)) { + ocf_cache_log(cache, log_err, "Cannot flush core - " + "cache device is detached\n"); + return -OCF_ERR_INVAL; + } if (!core->opened) { ocf_core_log(core, log_err, "Cannot flush - core is in " @@ -530,7 +541,7 @@ int ocf_mngt_core_flush_nolock(ocf_cache_t cache, ocf_core_id_t id, _ocf_mngt_begin_flush(cache); - ret = _ocf_mng_core_flush_nolock(core, interruption); + ret = _ocf_mng_core_flush(core, interruption); _ocf_mngt_end_flush(cache); @@ -540,63 +551,17 @@ int ocf_mngt_core_flush_nolock(ocf_cache_t cache, ocf_core_id_t id, return ret; } -int ocf_mngt_cache_flush(ocf_cache_t cache, bool interruption) -{ - int result = ocf_mngt_cache_read_lock(cache); - - if (result) - return result; - - if (!ocf_cache_is_device_attached(cache)) { - result = -OCF_ERR_INVAL; - goto unlock; - } - - result = ocf_mngt_cache_flush_nolock(cache, interruption); - -unlock: - ocf_mngt_cache_read_unlock(cache); - return result; -} - -int ocf_mngt_core_flush(ocf_cache_t cache, ocf_core_id_t id, bool interruption) -{ - int result; - - /* lock read only */ - result = ocf_mngt_cache_read_lock(cache); - if (result) - return result; - - if (!ocf_cache_is_device_attached(cache)) { - result = -OCF_ERR_INVAL; - goto unlock; - } - - result = ocf_mngt_core_flush_nolock(cache, id, interruption); - -unlock: - ocf_mngt_cache_read_unlock(cache); - return result; -} - -int ocf_mngt_core_purge(ocf_cache_t cache, ocf_core_id_t core_id, bool interruption) +int ocf_mngt_core_purge(ocf_core_t core, bool interruption) { + ocf_cache_t cache; + ocf_core_id_t core_id; int result = 0; uint64_t core_size = ~0ULL; - ocf_core_t core; - OCF_CHECK_NULL(cache); + OCF_CHECK_NULL(core); - result = ocf_mngt_cache_read_lock(cache); - if (result) - return result; - - result = ocf_core_get(cache, core_id, &core); - if (result < 0) { - ocf_mngt_cache_unlock(cache); - return -OCF_ERR_CORE_NOT_AVAIL; - } + cache = ocf_core_get_cache(core); + core_id = ocf_core_get_id(core); core_size = ocf_dobj_get_length(&cache->core[core_id].obj); core_size = core_size ?: ~0ULL; @@ -605,21 +570,19 @@ int ocf_mngt_core_purge(ocf_cache_t cache, ocf_core_id_t core_id, bool interrupt ocf_core_log(core, log_info, "Purging\n"); - result = _ocf_mng_core_flush_nolock(core, interruption); + result = _ocf_mng_core_flush(core, interruption); if (result) - goto err; + goto out; OCF_METADATA_LOCK_WR(); result = ocf_metadata_sparse_range(cache, core_id, 0, core_size); OCF_METADATA_UNLOCK_WR(); -err: +out: _ocf_mngt_end_flush(cache); - ocf_mngt_cache_read_unlock(cache); - return result; } @@ -627,35 +590,32 @@ int ocf_mngt_cache_purge(ocf_cache_t cache, bool interruption) { int result = 0; - result = ocf_mngt_cache_read_lock(cache); - if (result) - return result; + OCF_CHECK_NULL(cache); _ocf_mngt_begin_flush(cache); ocf_cache_log(cache, log_info, "Purging\n"); - result = _ocf_mng_cache_flush_nolock(cache, interruption); + result = _ocf_mng_cache_flush(cache, interruption); if (result) - goto err; + goto out; OCF_METADATA_LOCK_WR(); result = ocf_metadata_sparse_range(cache, OCF_CORE_ID_INVALID, 0, ~0ULL); OCF_METADATA_UNLOCK_WR(); -err: +out: _ocf_mngt_end_flush(cache); - ocf_mngt_cache_read_unlock(cache); - return result; } int ocf_mngt_cache_flush_interrupt(ocf_cache_t cache) { OCF_CHECK_NULL(cache); + ocf_cache_log(cache, log_alert, "Flushing interrupt\n"); cache->flushing_interrupted = 1; return 0; @@ -667,20 +627,17 @@ int ocf_mngt_cache_cleaning_set_policy(ocf_cache_t cache, ocf_cleaning_t type) ocf_cleaning_t old_type; int ret; + OCF_CHECK_NULL(cache); + if (type < 0 || type >= ocf_cleaning_max) return -OCF_ERR_INVAL; - - ret = ocf_mngt_cache_lock(cache); - if (ret) - return ret; - old_type = cache->conf_meta->cleaning_policy_type; if (type == old_type) { ocf_cache_log(cache, log_info, "Cleaning policy %s is already " "set\n", cleaning_policy_ops[old_type].name); - goto out; + return 0; } ocf_metadata_lock(cache, OCF_METADATA_WR); @@ -719,24 +676,16 @@ int ocf_mngt_cache_cleaning_set_policy(ocf_cache_t cache, ocf_cleaning_t type) ocf_metadata_unlock(cache, OCF_METADATA_WR); -out: - ocf_mngt_cache_unlock(cache); - return ret; } int ocf_mngt_cache_cleaning_get_policy(ocf_cache_t cache, ocf_cleaning_t *type) { - int ret; - - ret = ocf_mngt_cache_read_lock(cache); - if (ret) - return ret; + OCF_CHECK_NULL(cache); + OCF_CHECK_NULL(type); *type = cache->conf_meta->cleaning_policy_type; - ocf_mngt_cache_read_unlock(cache); - return 0; } @@ -745,16 +694,14 @@ int ocf_mngt_cache_cleaning_set_param(ocf_cache_t cache, ocf_cleaning_t type, { int ret; + OCF_CHECK_NULL(cache); + if (type < 0 || type >= ocf_cleaning_max) return -OCF_ERR_INVAL; if (!cleaning_policy_ops[type].set_cleaning_param) return -OCF_ERR_INVAL; - ret = ocf_mngt_cache_lock(cache); - if (ret) - return ret; - ocf_metadata_lock(cache, OCF_METADATA_WR); ret = cleaning_policy_ops[type].set_cleaning_param(cache, @@ -774,8 +721,6 @@ int ocf_mngt_cache_cleaning_set_param(ocf_cache_t cache, ocf_cleaning_t type, ocf_metadata_unlock(cache, OCF_METADATA_WR); - ocf_mngt_cache_unlock(cache); - return ret; } @@ -784,20 +729,17 @@ int ocf_mngt_cache_cleaning_get_param(ocf_cache_t cache, ocf_cleaning_t type, { int ret; + OCF_CHECK_NULL(cache); + OCF_CHECK_NULL(param_value); + if (type < 0 || type >= ocf_cleaning_max) return -OCF_ERR_INVAL; if (!cleaning_policy_ops[type].get_cleaning_param) return -OCF_ERR_INVAL; - ret = ocf_mngt_cache_read_lock(cache); - if (ret) - return ret; - ret = cleaning_policy_ops[type].get_cleaning_param(cache, param_id, param_value); - ocf_mngt_cache_read_unlock(cache); - return ret; } diff --git a/src/mngt/ocf_mngt_io_class.c b/src/mngt/ocf_mngt_io_class.c index 847e47b..259630b 100644 --- a/src/mngt/ocf_mngt_io_class.c +++ b/src/mngt/ocf_mngt_io_class.c @@ -261,14 +261,6 @@ int ocf_mngt_io_class_configure(ocf_cache_t cache, if (result) return result; - result = ocf_mngt_cache_lock(cache); - if (result) - return result; - - result = _ocf_mngt_io_class_configure(cache, cfg); - - ocf_mngt_cache_unlock(cache); - - return result; + return _ocf_mngt_io_class_configure(cache, cfg); } diff --git a/src/ocf_cache.c b/src/ocf_cache.c index a56cc3c..e6f0ea7 100644 --- a/src/ocf_cache.c +++ b/src/ocf_cache.c @@ -77,17 +77,12 @@ int ocf_cache_get_info(ocf_cache_t cache, struct ocf_cache_info *info) uint64_t core_dirty_since; uint32_t dirty_blocks_inactive = 0; uint32_t cache_occupancy_inactive = 0; - int result; OCF_CHECK_NULL(cache); if (!info) return -OCF_ERR_INVAL; - result = ocf_mngt_cache_read_lock(cache); - if (result) - return result; - ENV_BUG_ON(env_memset(info, sizeof(*info), 0)); info->attached = ocf_cache_is_device_attached(cache); @@ -172,8 +167,6 @@ int ocf_cache_get_info(ocf_cache_t cache, struct ocf_cache_info *info) ocf_metadata_size_of(cache) : 0; info->cache_line_size = ocf_line_size(cache); - ocf_mngt_cache_read_unlock(cache); - return 0; } diff --git a/src/ocf_io_class.c b/src/ocf_io_class.c index d67a61b..b3677ef 100644 --- a/src/ocf_io_class.c +++ b/src/ocf_io_class.c @@ -12,8 +12,7 @@ int ocf_io_class_get_info(ocf_cache_t cache, uint32_t io_class, struct ocf_io_class_info *info) { - ocf_part_id_t part_id; - int result; + ocf_part_id_t part_id = io_class; OCF_CHECK_NULL(cache); @@ -22,23 +21,16 @@ int ocf_io_class_get_info(ocf_cache_t cache, uint32_t io_class, if (io_class >= OCF_IO_CLASS_MAX) return -OCF_ERR_INVAL; - part_id = io_class; - - result = ocf_mngt_cache_read_lock(cache); - if (result) - return result; if (!ocf_part_is_valid(&cache->user_parts[part_id])) { /* Partition does not exist */ - result = -OCF_ERR_IO_CLASS_NOT_EXIST; - goto unlock; + return -OCF_ERR_IO_CLASS_NOT_EXIST; } if (env_strncpy(info->name, sizeof(info->name), cache->user_parts[part_id].config->name, sizeof(cache->user_parts[part_id].config->name))) { - result = -OCF_ERR_INVAL; - goto unlock; + return -OCF_ERR_INVAL; } info->priority = cache->user_parts[part_id].config->priority; @@ -52,10 +44,7 @@ int ocf_io_class_get_info(ocf_cache_t cache, uint32_t io_class, info->cache_mode = cache->user_parts[part_id].config->cache_mode; -unlock: - ocf_mngt_cache_read_unlock(cache); - - return result; + return 0; } int ocf_io_class_visit(ocf_cache_t cache, ocf_io_class_visitor_t visitor, diff --git a/src/ocf_stats.c b/src/ocf_stats.c index 8d489ef..2627a3f 100644 --- a/src/ocf_stats.c +++ b/src/ocf_stats.c @@ -55,10 +55,25 @@ static void ocf_stats_error_init(struct ocf_counters_error *stats) env_atomic_set(&stats->write, 0); } -void ocf_stats_init(ocf_core_t core) + +/******************************************************************** + * Function that resets stats, debug and breakdown counters. + * If reset is set the following stats won't be reset: + * - cache_occupancy + * - queue_length + * - debug_counters_read_reqs_issued_seq_hits + * - debug_counters_read_reqs_issued_not_seq_hits + * - debug_counters_read_reqs_issued_read_miss_schedule + * - debug_counters_write_reqs_thread + * - debug_counters_write_reqs_issued_only_hdd + * - debug_counters_write_reqs_issued_both_devs + *********************************************************************/ +void ocf_core_stats_initialize(ocf_core_t core) { - int i; struct ocf_counters_core *exp_obj_stats; + int i; + + OCF_CHECK_NULL(core); exp_obj_stats = core->counters; @@ -76,47 +91,16 @@ void ocf_stats_init(ocf_core_t core) #endif } -/******************************************************************** - * Function that resets stats, debug and breakdown counters. - * If reset is set the following stats won't be reset: - * - cache_occupancy - * - queue_length - * - debug_counters_read_reqs_issued_seq_hits - * - debug_counters_read_reqs_issued_not_seq_hits - * - debug_counters_read_reqs_issued_read_miss_schedule - * - debug_counters_write_reqs_thread - * - debug_counters_write_reqs_issued_only_hdd - * - debug_counters_write_reqs_issued_both_devs - *********************************************************************/ -int ocf_stats_initialize(ocf_cache_t cache, ocf_core_id_t core_id) +void ocf_core_stats_initialize_all(ocf_cache_t cache) { - ocf_core_t core; ocf_core_id_t id; - int result; - - result = ocf_mngt_cache_lock(cache); - if (result) - return result; - - if (core_id != OCF_CORE_ID_INVALID) { - result = ocf_core_get(cache, core_id, &core); - if (!result) - ocf_stats_init(core); - - ocf_mngt_cache_unlock(cache); - return result; - } for (id = 0; id < OCF_CORE_MAX; id++) { if (!env_bit_test(id, cache->conf_meta->valid_object_bitmap)) continue; - ocf_stats_init(&cache->core[id]); + ocf_core_stats_initialize(&cache->core[id]); } - - ocf_mngt_cache_unlock(cache); - - return 0; } static void copy_req_stats(struct ocf_stats_req *dest, @@ -179,8 +163,7 @@ static void copy_debug_stats(struct ocf_stats_core_debug *dest, int ocf_io_class_get_stats(ocf_core_t core, uint32_t io_class, struct ocf_stats_io_class *stats) { - int result; - uint32_t part_id; + ocf_part_id_t part_id = io_class; uint32_t i; uint32_t cache_occupancy_total = 0; struct ocf_counters_part *part_stat; @@ -195,21 +178,12 @@ int ocf_io_class_get_stats(ocf_core_t core, uint32_t io_class, if (!stats) return -OCF_ERR_INVAL; - result = ocf_mngt_cache_read_lock(cache); - if (result) - return result; - - if (io_class >= OCF_IO_CLASS_MAX) { - result = -OCF_ERR_INVAL; - goto unlock; - } - - part_id = io_class; + if (io_class >= OCF_IO_CLASS_MAX) + return -OCF_ERR_INVAL; if (!ocf_part_is_valid(&cache->user_parts[part_id])) { /* Partition does not exist */ - result = -OCF_ERR_IO_CLASS_NOT_EXIST; - goto unlock; + return -OCF_ERR_IO_CLASS_NOT_EXIST; } for (i = 0; i != OCF_CORE_MAX; ++i) { @@ -238,9 +212,7 @@ int ocf_io_class_get_stats(ocf_core_t core, uint32_t io_class, copy_block_stats(&stats->blocks, &part_stat->blocks); -unlock: - ocf_mngt_cache_read_unlock(cache); - return result; + return 0; } static uint32_t _calc_dirty_for(uint64_t dirty_since) @@ -252,7 +224,6 @@ static uint32_t _calc_dirty_for(uint64_t dirty_since) int ocf_core_get_stats(ocf_core_t core, struct ocf_stats_core *stats) { - int result; uint32_t i; ocf_core_id_t core_id; ocf_cache_t cache; @@ -267,10 +238,6 @@ int ocf_core_get_stats(ocf_core_t core, struct ocf_stats_core *stats) if (!stats) return -OCF_ERR_INVAL; - result = ocf_mngt_cache_read_lock(cache); - if (result) - return result; - core_stats = core->counters; ENV_BUG_ON(env_memset(stats, sizeof(*stats), 0)); @@ -321,8 +288,6 @@ int ocf_core_get_stats(ocf_core_t core, struct ocf_stats_core *stats) stats->dirty_for = _calc_dirty_for( env_atomic64_read(&cache->core_runtime_meta[core_id].dirty_since)); - ocf_mngt_cache_read_unlock(cache); - return 0; } diff --git a/src/ocf_stats_priv.h b/src/ocf_stats_priv.h index 446173b..71c3982 100644 --- a/src/ocf_stats_priv.h +++ b/src/ocf_stats_priv.h @@ -56,6 +56,4 @@ struct ocf_counters_core { #endif }; -void ocf_stats_init(ocf_core_t core); - #endif diff --git a/src/ocf_trace.c b/src/ocf_trace.c index ba1d764..3cb4574 100644 --- a/src/ocf_trace.c +++ b/src/ocf_trace.c @@ -85,15 +85,10 @@ int ocf_mngt_start_trace(ocf_cache_t cache, void *trace_ctx, if (!trace_callback) return -EINVAL; - result = ocf_mngt_cache_lock(cache); - if (result) - return result; - if (cache->trace.trace_callback) { ocf_cache_log(cache, log_err, "Tracing already started for cache %u\n", ocf_cache_get_id(cache)); - ocf_mngt_cache_unlock(cache); return -EINVAL; } @@ -106,36 +101,28 @@ int ocf_mngt_start_trace(ocf_cache_t cache, void *trace_ctx, for (i = 0; i < cache->io_queues_no; i++) { result = _ocf_trace_cache_info(cache, i); - if (result) - goto trace_deinit; + if (result) { + cache->trace.trace_callback = NULL; + return result; + } } ocf_cache_log(cache, log_info, "Tracing started for cache %u\n", ocf_cache_get_id(cache)); - ocf_mngt_cache_unlock(cache); - return result; - -trace_deinit: - cache->trace.trace_callback = NULL; - ocf_mngt_cache_unlock(cache); - return result; } int ocf_mngt_stop_trace(ocf_cache_t cache) { - int queue, result; + int queue; - result = ocf_mngt_cache_lock(cache); - if (result) - return result; + OCF_CHECK_NULL(cache); if (!cache->trace.trace_callback) { ocf_cache_log(cache, log_err, "Tracing not started for cache %u\n", ocf_cache_get_id(cache)); - ocf_mngt_cache_unlock(cache); return -EINVAL; } @@ -151,7 +138,6 @@ int ocf_mngt_stop_trace(ocf_cache_t cache) // Poll for all ongoing traces completion while (ocf_is_trace_ongoing(cache)) env_msleep(20); - ocf_mngt_cache_unlock(cache); - return result; + return 0; } diff --git a/tests/unit/tests/mngt/ocf_mngt_cache.c/_cache_mng_set_cache_mode_test.c b/tests/unit/tests/mngt/ocf_mngt_cache.c/_cache_mng_set_cache_mode_test.c index ee2d422..109569f 100644 --- a/tests/unit/tests/mngt/ocf_mngt_cache.c/_cache_mng_set_cache_mode_test.c +++ b/tests/unit/tests/mngt/ocf_mngt_cache.c/_cache_mng_set_cache_mode_test.c @@ -65,7 +65,7 @@ int __wrap_ocf_log_raw(const struct ocf_logger *logger, ocf_logger_lvl_t lvl, return mock(); } -int __wrap_ocf_mngt_cache_flush_nolock(ocf_cache_t cache, bool interruption) +int __wrap_ocf_mngt_cache_flush(ocf_cache_t cache, bool interruption) { function_called(); return mock(); @@ -186,8 +186,8 @@ static void _cache_mng_set_cache_mode_test03(void **state) expect_function_call(__wrap_ocf_cache_mode_is_valid); will_return(__wrap_ocf_cache_mode_is_valid, 1); - expect_function_call(__wrap_ocf_mngt_cache_flush_nolock); - will_return(__wrap_ocf_mngt_cache_flush_nolock, -OCF_ERR_NO_MEM); + expect_function_call(__wrap_ocf_mngt_cache_flush); + will_return(__wrap_ocf_mngt_cache_flush, -OCF_ERR_NO_MEM); result = _cache_mng_set_cache_mode(&cache, mode_new, flush); @@ -334,8 +334,8 @@ static void _cache_mng_set_cache_mode_test07(void **state) expect_function_call(__wrap_ocf_cache_mode_is_valid); will_return(__wrap_ocf_cache_mode_is_valid, 1); - expect_function_call(__wrap_ocf_mngt_cache_flush_nolock); - will_return(__wrap_ocf_mngt_cache_flush_nolock, 0); + expect_function_call(__wrap_ocf_mngt_cache_flush); + will_return(__wrap_ocf_mngt_cache_flush, 0); expect_function_call(__wrap_ocf_metadata_flush_superblock); will_return(__wrap_ocf_metadata_flush_superblock, 0);