Make management API asynchronous

NOTE: This patch only changes API that pretends to be asynchronous.
Most of management operations are still performed synchronously.
The real asynchronism will be introduced in the next patches.

Signed-off-by: Robert Baldyga <robert.baldyga@intel.com>
This commit is contained in:
Robert Baldyga
2019-03-01 15:52:59 +01:00
parent e21b617841
commit c5df82f2cb
11 changed files with 566 additions and 547 deletions

View File

@@ -1476,19 +1476,22 @@ int ocf_mngt_cache_start(ocf_ctx_t ctx, ocf_cache_t *cache,
return result;
}
int ocf_mngt_cache_attach(ocf_cache_t cache,
struct ocf_mngt_cache_device_config *device_cfg)
void ocf_mngt_cache_attach(ocf_cache_t cache,
struct ocf_mngt_cache_device_config *cfg,
ocf_mngt_cache_attach_end_t cmpl, void *priv)
{
int result;
if (!cache || !device_cfg)
return -OCF_ERR_INVAL;
OCF_CHECK_NULL(cache);
OCF_CHECK_NULL(cfg);
result = _ocf_mngt_cache_validate_device_cfg(device_cfg);
if (result)
return result;
result = _ocf_mngt_cache_validate_device_cfg(cfg);
if (result) {
cmpl(cache, priv, result);
return;
}
result = _ocf_mngt_cache_attach(cache, device_cfg, false);
result = _ocf_mngt_cache_attach(cache, cfg, false);
if (!result) {
ocf_cache_log(cache, log_info, "Successfully attached\n");
} else {
@@ -1496,7 +1499,7 @@ int ocf_mngt_cache_attach(ocf_cache_t cache,
"failed\n");
}
return result;
cmpl(cache, priv, result);
}
/**
@@ -1636,32 +1639,36 @@ static void _ocf_mngt_cache_load_log(ocf_cache_t cache)
cache, false);
}
int ocf_mngt_cache_load(ocf_ctx_t ctx, ocf_cache_t *cache,
struct ocf_mngt_cache_device_config *device_cfg)
void ocf_mngt_cache_load(ocf_cache_t cache,
struct ocf_mngt_cache_device_config *cfg,
ocf_mngt_cache_load_end_t cmpl, void *priv)
{
int result;
if (!ctx || !cache || !device_cfg)
return -OCF_ERR_INVAL;
OCF_CHECK_NULL(cache);
OCF_CHECK_NULL(cfg);
result = _ocf_mngt_cache_validate_device_cfg(device_cfg);
if (result)
return result;
result = _ocf_mngt_cache_attach(*cache, device_cfg, true);
result = _ocf_mngt_cache_validate_device_cfg(cfg);
if (result) {
_ocf_mngt_init_handle_error(*cache, ctx, NULL);
return result;
cmpl(cache, priv, result);
return;
}
_ocf_mng_cache_set_valid(*cache);
result = _ocf_mngt_cache_attach(cache, cfg, true);
if (result) {
cmpl(cache, priv, result);
return;
}
_ocf_mngt_cache_load_log(*cache);
_ocf_mng_cache_set_valid(cache);
return 0;
_ocf_mngt_cache_load_log(cache);
cmpl(cache, priv, 0);
}
int ocf_mngt_cache_stop(ocf_cache_t cache)
void ocf_mngt_cache_stop(ocf_cache_t cache,
ocf_mngt_cache_stop_end_t cmpl, void *priv)
{
int result;
char cache_name[OCF_CACHE_NAME_SIZE];
@@ -1671,8 +1678,10 @@ int ocf_mngt_cache_stop(ocf_cache_t cache)
result = env_strncpy(cache_name, sizeof(cache_name),
ocf_cache_get_name(cache), sizeof(cache_name));
if (result)
return result;
if (result) {
cmpl(cache, priv, result);
return;
}
ctx = ocf_cache_get_ctx(cache);
@@ -1691,38 +1700,41 @@ int ocf_mngt_cache_stop(ocf_cache_t cache)
cache_name);
}
return result;
cmpl(cache, priv, result);
}
static int _cache_mng_set_cache_mode(ocf_cache_t cache, ocf_cache_mode_t mode,
uint8_t flush)
void ocf_mngt_cache_save(ocf_cache_t cache,
ocf_mngt_cache_save_end_t cmpl, void *priv)
{
int result;
result = ocf_metadata_flush_superblock(cache);
if (result) {
ocf_cache_log(cache, log_err,
"Failed to flush superblock! Changes "
"in cache config are not persistent!\n");
}
cmpl(cache, priv, result ? -OCF_ERR_WRITE_CACHE : 0);
}
static int _cache_mng_set_cache_mode(ocf_cache_t cache, ocf_cache_mode_t mode)
{
ocf_cache_mode_t mode_new = mode;
ocf_cache_mode_t mode_old = cache->conf_meta->cache_mode;
int result = 0;
/* Check if IO interface type is valid */
if (!ocf_cache_mode_is_valid(mode))
return -OCF_ERR_INVAL;
if (mode_new == mode_old) {
if (mode == mode_old) {
ocf_cache_log(cache, log_info, "Cache mode '%s' is already set\n",
ocf_get_io_iface_name(mode_new));
ocf_get_io_iface_name(mode));
return 0;
}
cache->conf_meta->cache_mode = mode_new;
cache->conf_meta->cache_mode = mode;
if (flush) {
/* Flush required, do it, do it, do it... */
result = ocf_mngt_cache_flush(cache, true);
if (result) {
cache->conf_meta->cache_mode = mode_old;
return result;
}
} else if (ocf_cache_mode_wb == mode_old) {
if (ocf_cache_mode_wb == mode_old) {
int i;
for (i = 0; i != OCF_CORE_MAX; ++i) {
@@ -1735,33 +1747,26 @@ static int _cache_mng_set_cache_mode(ocf_cache_t cache, ocf_cache_mode_t mode,
}
}
if (ocf_metadata_flush_superblock(cache)) {
ocf_cache_log(cache, log_err, "Failed to store cache mode "
"change. Reverting\n");
cache->conf_meta->cache_mode = mode_old;
return -OCF_ERR_WRITE_CACHE;
}
ocf_cache_log(cache, log_info, "Changing cache mode from '%s' to '%s' "
"successful\n", ocf_get_io_iface_name(mode_old),
ocf_get_io_iface_name(mode_new));
ocf_get_io_iface_name(mode));
return 0;
}
int ocf_mngt_cache_set_mode(ocf_cache_t cache, ocf_cache_mode_t mode,
uint8_t flush)
int ocf_mngt_cache_set_mode(ocf_cache_t cache, ocf_cache_mode_t mode)
{
int result;
OCF_CHECK_NULL(cache);
if (!ocf_cache_mode_is_valid(mode)) {
ocf_cache_log(cache, log_err, "Cache mode %u is invalid\n", mode);
ocf_cache_log(cache, log_err, "Cache mode %u is invalid\n",
mode);
return -OCF_ERR_INVAL;
}
result = _cache_mng_set_cache_mode(cache, mode, flush);
result = _cache_mng_set_cache_mode(cache, mode);
if (result) {
const char *name = ocf_get_io_iface_name(mode);
@@ -1827,32 +1832,36 @@ int ocf_mngt_cache_get_fallback_pt_error_threshold(ocf_cache_t cache,
return 0;
}
int ocf_mngt_cache_detach(ocf_cache_t cache)
struct ocf_mngt_cache_detach_context {
ocf_mngt_cache_detach_end_t cmpl;
void *priv;
};
static void ocf_mngt_cache_detach_flush_cmpl(ocf_cache_t cache,
void *priv, int error)
{
struct ocf_mngt_cache_detach_context *context = priv;
int i, j, no;
int result;
OCF_CHECK_NULL(cache);
no = cache->conf_meta->core_count;
if (!env_atomic_read(&cache->attached))
return -EINVAL;
/* prevent dirty io */
env_atomic_inc(&cache->flush_started);
result = ocf_mngt_cache_flush(cache, true);
if (result)
return result;
if (error) {
ENV_BUG_ON(env_atomic_dec_return(&cache->flush_started) < 0);
context->cmpl(cache, context->priv, error);
env_vfree(context);
return;
}
/* wait for all requests referencing cacheline metadata to finish */
env_atomic_set(&cache->attached, 0);
/* FIXME: This should be asynchronous! */
env_waitqueue_wait(cache->pending_cache_wq,
!env_atomic_read(&cache->pending_cache_requests));
ENV_BUG_ON(env_atomic_dec_return(&cache->flush_started) < 0);
no = cache->conf_meta->core_count;
/* remove cacheline metadata and cleaning policy meta for all cores */
for (i = 0, j = 0; j < no && i < OCF_CORE_MAX; i++) {
if (!env_bit_test(i, cache->conf_meta->valid_core_bitmap))
@@ -1878,5 +1887,33 @@ int ocf_mngt_cache_detach(ocf_cache_t cache)
}
}
return result;
context->cmpl(cache, context->priv, result);
env_vfree(context);
}
void ocf_mngt_cache_detach(ocf_cache_t cache,
ocf_mngt_cache_detach_end_t cmpl, void *priv)
{
struct ocf_mngt_cache_detach_context *context;
OCF_CHECK_NULL(cache);
if (!env_atomic_read(&cache->attached)) {
cmpl(cache, priv, -OCF_ERR_INVAL);
return;
}
context = env_vmalloc(sizeof(*context));
if (!context) {
cmpl(cache, priv, -OCF_ERR_NO_MEM);
return;
}
context->cmpl = cmpl;
context->priv = priv;
/* prevent dirty io */
env_atomic_inc(&cache->flush_started);
ocf_mngt_cache_flush(cache, true, ocf_mngt_cache_detach_flush_cmpl,
context);
}

View File

@@ -94,7 +94,7 @@ static int _ocf_mngt_cache_add_core(ocf_cache_t cache, ocf_core_t *core,
goto error_out;
if (cfg->user_metadata.data && cfg->user_metadata.size > 0) {
result = ocf_core_set_user_metadata_raw(tmp_core,
result = ocf_mngt_core_set_user_metadata(tmp_core,
cfg->user_metadata.data,
cfg->user_metadata.size);
if (result)
@@ -362,51 +362,60 @@ int ocf_mngt_core_init_front_volume(ocf_core_t core)
return ocf_volume_open(&core->front_volume);
}
int ocf_mngt_cache_add_core(ocf_cache_t cache, ocf_core_t *core,
struct ocf_mngt_core_config *cfg)
void ocf_mngt_cache_add_core(ocf_cache_t cache,
struct ocf_mngt_core_config *cfg,
ocf_mngt_cache_add_core_end_t cmpl, void *priv)
{
int result;
char core_name[OCF_CORE_NAME_SIZE];
ocf_core_t core = NULL;
int result;
OCF_CHECK_NULL(cache);
OCF_CHECK_NULL(core);
result = _ocf_mngt_find_core_id(cache, cfg);
if (result)
return result;
if (result) {
cmpl(cache, NULL, priv, result);
return;
}
if (cfg->name) {
result = env_strncpy(core_name, sizeof(core_name), cfg->name,
sizeof(core_name));
if (result)
return result;
if (result) {
cmpl(cache, NULL, priv, result);
return;
}
} else {
result = snprintf(core_name, sizeof(core_name), "core%hu",
cfg->core_id);
if (result < 0)
return result;
if (result < 0) {
cmpl(cache, NULL, priv, result);
return;
}
}
result = ocf_core_set_name(&cache->core[cfg->core_id], core_name,
sizeof(core_name));
if (result)
return result;
if (result) {
cmpl(cache, NULL, priv, result);
return;
}
ocf_cache_log(cache, log_debug, "Inserting core %s\n", core_name);
if (cfg->try_add)
result = _ocf_mngt_cache_try_add_core(cache, core, cfg);
result = _ocf_mngt_cache_try_add_core(cache, &core, cfg);
else
result = _ocf_mngt_cache_add_core(cache, core, cfg);
result = _ocf_mngt_cache_add_core(cache, &core, cfg);
if (result)
goto out;
result = ocf_mngt_core_init_front_volume(*core);
result = ocf_mngt_core_init_front_volume(core);
out:
if (!result) {
ocf_core_log(*core, log_info, "Successfully added\n");
ocf_core_log(core, log_info, "Successfully added\n");
} else {
if (result == -OCF_ERR_CORE_NOT_AVAIL) {
ocf_cache_log(cache, log_err, "Core %s is zero size\n",
@@ -416,24 +425,13 @@ out:
core_name);
}
return result;
cmpl(cache, core, priv, result);
}
static int _ocf_mngt_cache_remove_core(ocf_core_t core, bool detach)
static int _ocf_mngt_cache_remove_core(ocf_core_t core)
{
struct ocf_cache *cache = core->volume.cache;
ocf_core_id_t core_id = ocf_core_get_id(core);
int status;
if (detach) {
status = cache_mng_core_close(cache, core_id);
if (!status) {
cache->ocf_core_inactive_count++;
env_bit_set(ocf_cache_state_incomplete,
&cache->cache_state);
}
return status;
}
ocf_volume_close(&core->front_volume);
@@ -452,7 +450,8 @@ static int _ocf_mngt_cache_remove_core(ocf_core_t core, bool detach)
return 0;
}
int ocf_mngt_cache_remove_core(ocf_core_t core)
void ocf_mngt_cache_remove_core(ocf_core_t core,
ocf_mngt_cache_remove_core_end_t cmpl, void *priv)
{
ocf_cache_t cache = ocf_core_get_cache(core);
const char *core_name = ocf_core_get_name(core);
@@ -462,7 +461,7 @@ int ocf_mngt_cache_remove_core(ocf_core_t core)
core_name = ocf_core_get_name(core);
result = _ocf_mngt_cache_remove_core(core, false);
result = _ocf_mngt_cache_remove_core(core);
if (!result) {
ocf_cache_log(cache, log_info, "Core %s successfully removed\n",
core_name);
@@ -471,10 +470,27 @@ int ocf_mngt_cache_remove_core(ocf_core_t core)
core_name);
}
return result;
cmpl(priv, result);
}
int ocf_mngt_cache_detach_core(ocf_core_t core)
static int _ocf_mngt_cache_detach_core(ocf_core_t core)
{
struct ocf_cache *cache = core->volume.cache;
ocf_core_id_t core_id = ocf_core_get_id(core);
int status;
status = cache_mng_core_close(cache, core_id);
if (!status) {
cache->ocf_core_inactive_count++;
env_bit_set(ocf_cache_state_incomplete,
&cache->cache_state);
}
return status;
}
void ocf_mngt_cache_detach_core(ocf_core_t core,
ocf_mngt_cache_detach_core_end_t cmpl, void *priv)
{
ocf_cache_t cache = ocf_core_get_cache(core);
const char *core_name = ocf_core_get_name(core);
@@ -482,7 +498,7 @@ int ocf_mngt_cache_detach_core(ocf_core_t core)
ocf_core_log(core, log_debug, "Detaching core\n");
result = _ocf_mngt_cache_remove_core(core, true);
result = _ocf_mngt_cache_detach_core(core);
if (!result) {
ocf_cache_log(cache, log_info, "Core %s successfully detached\n",
core_name);
@@ -491,9 +507,79 @@ int ocf_mngt_cache_detach_core(ocf_core_t core)
core_name);
}
cmpl(priv, result);
}
int ocf_mngt_core_set_uuid(ocf_core_t core, const struct ocf_volume_uuid *uuid)
{
struct ocf_volume_uuid *current_uuid;
int result;
int diff;
OCF_CHECK_NULL(core);
OCF_CHECK_NULL(uuid);
OCF_CHECK_NULL(uuid->data);
current_uuid = &ocf_core_get_volume(core)->uuid;
result = env_memcmp(current_uuid->data, current_uuid->size,
uuid->data, uuid->size, &diff);
if (result)
return result;
if (!diff) {
/* UUIDs are identical */
return 0;
}
result = ocf_metadata_set_core_uuid(core, uuid, NULL);
if (result)
return result;
ocf_volume_set_uuid(&core->volume, uuid);
return result;
}
int ocf_mngt_core_set_user_metadata(ocf_core_t core, void *data, size_t size)
{
ocf_cache_t cache;
uint32_t core_id;
OCF_CHECK_NULL(core);
OCF_CHECK_NULL(data);
cache = ocf_core_get_cache(core);
core_id = ocf_core_get_id(core);
if (size > OCF_CORE_USER_DATA_SIZE)
return -EINVAL;
env_memcpy(cache->core_conf_meta[core_id].user_data,
OCF_CORE_USER_DATA_SIZE, data, size);
return 0;
}
int ocf_mngt_core_get_user_metadata(ocf_core_t core, void *data, size_t size)
{
uint32_t core_id;
ocf_cache_t cache;
OCF_CHECK_NULL(core);
core_id = ocf_core_get_id(core);
cache = ocf_core_get_cache(core);
if (size > sizeof(cache->core_conf_meta[core_id].user_data))
return -EINVAL;
env_memcpy(data, size, cache->core_conf_meta[core_id].user_data,
OCF_CORE_USER_DATA_SIZE);
return 0;
}
static int _cache_mng_set_core_seq_cutoff_threshold(ocf_core_t core, void *cntx)
{
uint32_t threshold = *(uint32_t*) cntx;
@@ -510,14 +596,6 @@ static int _cache_mng_set_core_seq_cutoff_threshold(ocf_core_t core, void *cntx)
}
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);
@@ -582,13 +660,6 @@ static int _cache_mng_set_core_seq_cutoff_policy(ocf_core_t core, void *cntx)
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),

View File

@@ -461,7 +461,8 @@ static int _ocf_mng_cache_flush(ocf_cache_t cache, bool interruption)
return result;
}
int ocf_mngt_cache_flush(ocf_cache_t cache, bool interruption)
void ocf_mngt_cache_flush(ocf_cache_t cache, bool interruption,
ocf_mngt_cache_flush_end_t cmpl, void *priv)
{
int result = 0;
@@ -470,19 +471,22 @@ int ocf_mngt_cache_flush(ocf_cache_t cache, bool interruption)
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;
cmpl(cache, priv, -OCF_ERR_INVAL);
return;
}
if (ocf_cache_is_incomplete(cache)) {
ocf_cache_log(cache, log_err, "Cannot flush cache - "
"cache is in incomplete state\n");
return -OCF_ERR_CACHE_IN_INCOMPLETE_STATE;
cmpl(cache, priv, -OCF_ERR_CACHE_IN_INCOMPLETE_STATE);
return;
}
if (!cache->flush_queue) {
ocf_cache_log(cache, log_err,
"Cannot flush cache - no flush queue set\n");
return -OCF_ERR_INVAL;
cmpl(cache, priv, -OCF_ERR_INVAL);
return;
}
ocf_cache_log(cache, log_info, "Flushing cache\n");
@@ -496,7 +500,7 @@ int ocf_mngt_cache_flush(ocf_cache_t cache, bool interruption)
if (!result)
ocf_cache_log(cache, log_info, "Flushing cache completed\n");
return result;
cmpl(cache, priv, result);
}
static int _ocf_mng_core_flush(ocf_core_t core, bool interruption)
@@ -521,7 +525,8 @@ static int _ocf_mng_core_flush(ocf_core_t core, bool interruption)
return ret;
}
int ocf_mngt_core_flush(ocf_core_t core, bool interruption)
void ocf_mngt_core_flush(ocf_core_t core, bool interruption,
ocf_mngt_core_flush_end_t cmpl, void *priv)
{
ocf_cache_t cache;
int ret = 0;
@@ -533,19 +538,22 @@ int ocf_mngt_core_flush(ocf_core_t core, bool interruption)
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;
cmpl(core, priv, -OCF_ERR_INVAL);
return;
}
if (!core->opened) {
ocf_core_log(core, log_err, "Cannot flush - core is in "
"inactive state\n");
return -OCF_ERR_CORE_IN_INACTIVE_STATE;
cmpl(core, priv, -OCF_ERR_CORE_IN_INACTIVE_STATE);
return;
}
if (!cache->flush_queue) {
ocf_core_log(core, log_err,
"Cannot flush core - no flush queue set\n");
return -OCF_ERR_INVAL;
cmpl(core, priv, -OCF_ERR_INVAL);
return;
}
ocf_core_log(core, log_info, "Flushing\n");
@@ -559,10 +567,46 @@ int ocf_mngt_core_flush(ocf_core_t core, bool interruption)
if (!ret)
ocf_cache_log(cache, log_info, "Flushing completed\n");
return ret;
cmpl(core, priv, ret);
}
int ocf_mngt_core_purge(ocf_core_t core, bool interruption)
void ocf_mngt_cache_purge(ocf_cache_t cache,
ocf_mngt_cache_purge_end_t cmpl, void *priv)
{
int result = 0;
OCF_CHECK_NULL(cache);
if (!cache->flush_queue) {
ocf_cache_log(cache, log_err,
"Cannot purge cache - no flush queue set\n");
cmpl(cache, priv, -OCF_ERR_INVAL);
return;
}
_ocf_mngt_begin_flush(cache);
ocf_cache_log(cache, log_info, "Purging\n");
result = _ocf_mng_cache_flush(cache, true);
if (result)
goto out;
OCF_METADATA_LOCK_WR();
result = ocf_metadata_sparse_range(cache, OCF_CORE_ID_INVALID, 0,
~0ULL);
OCF_METADATA_UNLOCK_WR();
out:
_ocf_mngt_end_flush(cache);
cmpl(cache, priv, result);
}
void ocf_mngt_core_purge(ocf_core_t core,
ocf_mngt_core_purge_end_t cmpl, void *priv)
{
ocf_cache_t cache;
ocf_core_id_t core_id;
@@ -577,7 +621,8 @@ int ocf_mngt_core_purge(ocf_core_t core, bool interruption)
if (!cache->flush_queue) {
ocf_core_log(core, log_err,
"Cannot purge core - no flush queue set\n");
return -OCF_ERR_INVAL;
cmpl(core, priv, -OCF_ERR_INVAL);
return;
}
core_size = ocf_volume_get_length(&cache->core[core_id].volume);
@@ -587,7 +632,7 @@ int ocf_mngt_core_purge(ocf_core_t core, bool interruption)
ocf_core_log(core, log_info, "Purging\n");
result = _ocf_mng_core_flush(core, interruption);
result = _ocf_mng_core_flush(core, true);
if (result)
goto out;
@@ -600,48 +645,15 @@ int ocf_mngt_core_purge(ocf_core_t core, bool interruption)
out:
_ocf_mngt_end_flush(cache);
return result;
cmpl(core, priv, result);
}
int ocf_mngt_cache_purge(ocf_cache_t cache, bool interruption)
{
int result = 0;
OCF_CHECK_NULL(cache);
if (!cache->flush_queue) {
ocf_cache_log(cache, log_err,
"Cannot purge cache - no flush queue set\n");
return -OCF_ERR_INVAL;
}
_ocf_mngt_begin_flush(cache);
ocf_cache_log(cache, log_info, "Purging\n");
result = _ocf_mng_cache_flush(cache, interruption);
if (result)
goto out;
OCF_METADATA_LOCK_WR();
result = ocf_metadata_sparse_range(cache, OCF_CORE_ID_INVALID, 0,
~0ULL);
OCF_METADATA_UNLOCK_WR();
out:
_ocf_mngt_end_flush(cache);
return result;
}
int ocf_mngt_cache_flush_interrupt(ocf_cache_t cache)
void 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;
}
int ocf_mngt_cache_cleaning_set_policy(ocf_cache_t cache, ocf_cleaning_t type)
@@ -681,24 +693,12 @@ int ocf_mngt_cache_cleaning_set_policy(ocf_cache_t cache, ocf_cleaning_t type)
cache->conf_meta->cleaning_policy_type = type;
if (type != old_type) {
/*
* If operation was successfull or cleaning policy changed,
* we need to flush superblock.
*/
if (ocf_metadata_flush_superblock(cache)) {
ocf_cache_log(cache, log_err,
"Failed to flush superblock! Changes "
"in cache config are not persistent!\n");
}
}
ocf_metadata_unlock(cache, OCF_METADATA_WR);
ocf_cache_log(cache, log_info, "Changing cleaning policy from "
"%s to %s\n", cleaning_policy_ops[old_type].name,
cleaning_policy_ops[type].name);
ocf_metadata_unlock(cache, OCF_METADATA_WR);
return ret;
}
@@ -730,18 +730,6 @@ int ocf_mngt_cache_cleaning_set_param(ocf_cache_t cache, ocf_cleaning_t type,
ret = cleaning_policy_ops[type].set_cleaning_param(cache,
param_id, param_value);
if (ret == 0) {
/*
* If operation was successfull or cleaning policy changed,
* we need to flush superblock.
*/
if (ocf_metadata_flush_superblock(cache)) {
ocf_cache_log(cache, log_err,
"Failed to flush superblock! Changes "
"in cache config are not persistent!\n");
}
}
ocf_metadata_unlock(cache, OCF_METADATA_WR);
return ret;

View File

@@ -283,36 +283,29 @@ int ocf_mngt_cache_io_classes_configure(ocf_cache_t cache,
result = env_memcpy(old_config, sizeof(&cache->user_parts),
cache->user_parts, sizeof(&cache->user_parts));
if (result) {
env_free(old_config);
return result;
}
if (result)
goto out_cpy;
for (i = 0; i < OCF_IO_CLASS_MAX; i++) {
result = _ocf_mngt_io_class_edit(cache, &cfg->config[i]);
if (result && result != -OCF_ERR_IO_CLASS_NOT_EXIST) {
ocf_cache_log(cache, log_err,
"Failed to set new io class config\n");
goto err;
goto out_edit;
}
result = 0;
}
ocf_part_sort(cache);
if (ocf_metadata_flush_superblock(cache)) {
ocf_cache_log(cache, log_err, "Failed to store new io class config\n");
result = -OCF_ERR_WRITE_CACHE;
}
err:
out_edit:
if (result) {
ENV_BUG_ON(env_memcpy(cache->user_parts, sizeof(&cache->user_parts),
old_config, sizeof(&cache->user_parts)));
}
out_cpy:
OCF_METADATA_UNLOCK_WR();
env_free(old_config);
return result;
}