Cache lock cleanup and API improvements
Signed-off-by: Robert Baldyga <robert.baldyga@intel.com>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user