From f955ce890cfd6073aa5aa5a2a10bacd2a0c5cf9f Mon Sep 17 00:00:00 2001 From: Slawomir Jankowski Date: Wed, 17 Feb 2021 14:42:12 +0100 Subject: [PATCH] Remove inactive core handling from "remove core" FLush only active core during core removal. During core removal with `casadm -R` there's a flush triggered. This flush shall be skipped for inactive cores. Change return code when `casadm -R` is called with `force` flag. There was no info about dirty data when core was removed without flush. Do not destroy exported object while core is inactive. Perform detach only on active cores. Skip removing inactive core with command for active cores. Signed-off-by: Slawomir Jankowski --- modules/cas_cache/layer_cache_management.c | 48 ++++++++++------------ 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/modules/cas_cache/layer_cache_management.c b/modules/cas_cache/layer_cache_management.c index 62c70f1..ce814a0 100644 --- a/modules/cas_cache/layer_cache_management.c +++ b/modules/cas_cache/layer_cache_management.c @@ -1363,27 +1363,19 @@ static int _cache_mngt_remove_core_flush(ocf_cache_t cache, core_active = (ocf_core_get_state(core) == ocf_core_state_active); - if (cmd->detach && !core_active) { - printk(KERN_WARNING OCF_PREFIX_SHORT - "Cannot detach core which " - "is already inactive!\n"); - return -OCF_ERR_CORE_IN_INACTIVE_STATE; - } - - if (core_active) { - return _cache_mngt_core_flush_sync(core, - true, _cache_read_unlock_put_cmpl); - } else if (!ocf_mngt_core_is_dirty(core)) { - result = 0; - goto unlock; - } else { - printk(KERN_WARNING OCF_PREFIX_SHORT - "Cannot remove dirty inactive core " - "without force option\n"); + if (!core_active) { result = -OCF_ERR_CORE_IN_INACTIVE_STATE; goto unlock; } + if (!ocf_mngt_core_is_dirty(core)) { + result = 0; + goto unlock; + } + + return _cache_mngt_core_flush_sync(core, true, + _cache_read_unlock_put_cmpl); + unlock: ocf_mngt_cache_read_unlock(cache); put: @@ -1399,21 +1391,23 @@ static int _cache_mngt_remove_core_prepare(ocf_cache_t cache, ocf_core_t core, core_active = ocf_core_get_state(core) == ocf_core_state_active; - if (cmd->detach && !core_active) { - printk(KERN_WARNING OCF_PREFIX_SHORT - "Cannot detach core which " - "is already inactive!\n"); + if (!core_active) { + if (cmd->detach) { + printk(KERN_WARNING OCF_PREFIX_SHORT + "Cannot detach core which " + "is already inactive!\n"); + } return -OCF_ERR_CORE_IN_INACTIVE_STATE; - } - - if (core_active) { + } else { result = block_dev_destroy_exported_object(core); if (result) return result; } - if (!cmd->force_no_flush) - result = _cache_mngt_core_flush_uninterruptible(core); + if (cmd->force_no_flush) + return -KCAS_ERR_REMOVED_DIRTY; + + result = _cache_mngt_core_flush_uninterruptible(core); return result ? -KCAS_ERR_REMOVED_DIRTY : 0; } @@ -1463,7 +1457,7 @@ int cache_mngt_remove_core_from_cache(struct kcas_remove_core *cmd) init_completion(&context.cmpl); context.result = &result; - if (cmd->detach || prepare_result == -KCAS_ERR_REMOVED_DIRTY) { + if (cmd->detach) { ocf_mngt_cache_detach_core(core, _cache_mngt_remove_core_complete, &context); } else {