From 2bf6e42dea7264a30bebb4e0a98f4367d313f229 Mon Sep 17 00:00:00 2001 From: Slawomir Jankowski Date: Wed, 17 Feb 2021 15:35:57 +0100 Subject: [PATCH] Print separate messages for different "remove core" return codes Change extended error message for `KCAS_ERR_REMOVED_DIRTY`. Print informative messages when `remove core` command fails. Make separate error messages for detaching. Update help printouts. Update documentation comments. Signed-off-by: Slawomir Jankowski --- casadm/cas_lib.c | 20 ++++++++++++++++---- casadm/cas_main.c | 4 ++-- casadm/extended_err_msg.c | 4 ++-- modules/include/cas_ioctl_codes.h | 8 ++++---- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/casadm/cas_lib.c b/casadm/cas_lib.c index 6d8d397..043fedc 100644 --- a/casadm/cas_lib.c +++ b/casadm/cas_lib.c @@ -1904,12 +1904,24 @@ int remove_core(unsigned int cache_id, unsigned int core_id, if (run_ioctl_interruptible(fd, KCAS_IOCTL_REMOVE_CORE, &cmd, "Removing core", cache_id, core_id) < 0) { close(fd); - if (OCF_ERR_FLUSHING_INTERRUPTED == cmd.ext_err_code) { - cas_printf(LOG_ERR, "You have interrupted removal of core. CAS continues to operate normally.\n"); + if (cmd.ext_err_code == OCF_ERR_FLUSHING_INTERRUPTED) { + cas_printf(LOG_ERR, "You have interrupted %s of core. " + "CAS continues to operate normally.\n", + detach ? "detaching" : "removal"); return INTERRUPTED; + } else if (cmd.ext_err_code == OCF_ERR_CORE_IN_INACTIVE_STATE) { + cas_printf(LOG_ERR, "Core is inactive. To manage the " + "inactive core use '--remove-inactive' " + "command.\n"); + return FAILURE; + } else if (cmd.ext_err_code == KCAS_ERR_REMOVED_DIRTY) { + print_err(cmd.ext_err_code); + return SUCCESS; } else { - cas_printf(LOG_ERR, "Error while removing core device %d from cache instance %d\n", - core_id, cache_id); + cas_printf(LOG_ERR, "Error while %s core device %d " + "from cache instance %d\n", + detach ? "detaching" : "removing", + core_id, cache_id); print_err(cmd.ext_err_code); return FAILURE; } diff --git a/casadm/cas_main.c b/casadm/cas_main.c index bba3b58..6093906 100644 --- a/casadm/cas_main.c +++ b/casadm/cas_main.c @@ -1109,7 +1109,7 @@ int handle_add() static cli_option remove_options[] = { {'i', "cache-id", CACHE_ID_DESC, 1, "ID", CLI_OPTION_REQUIRED}, {'j', "core-id", CORE_ID_DESC, 1, "ID", CLI_OPTION_REQUIRED}, - {'f', "force", "Force remove inactive core"}, + {'f', "force", "Force active core removal without data flush"}, {0} }; @@ -1961,7 +1961,7 @@ static cli_command cas_commands[] = { { .name = "remove-core", .short_name = 'R', - .desc = "Remove core device from cache instance", + .desc = "Remove active core device from cache instance", .long_desc = NULL, .options = remove_options, .command_handle_opts = remove_core_command_handle_option, diff --git a/casadm/extended_err_msg.c b/casadm/extended_err_msg.c index e70ea2c..6b4b842 100644 --- a/casadm/extended_err_msg.c +++ b/casadm/extended_err_msg.c @@ -222,8 +222,8 @@ struct { }, { KCAS_ERR_REMOVED_DIRTY, - "Flush error occured. Core has been set to detached state.\n" - "Warning: Core device may contain inconsistent data.\n" + "Warning: Core has been removed or detached without flush.\n" + "Core device may contain inconsistent data.\n" "To access your data please add core back to the cache." }, { diff --git a/modules/include/cas_ioctl_codes.h b/modules/include/cas_ioctl_codes.h index 32520fe..ff5c582 100644 --- a/modules/include/cas_ioctl_codes.h +++ b/modules/include/cas_ioctl_codes.h @@ -117,7 +117,7 @@ struct kcas_insert_core { struct kcas_remove_core { uint16_t cache_id; /**< id of an running cache */ uint16_t core_id; /**< id core object to be removed */ - bool force_no_flush; /**< remove core without flushing */ + bool force_no_flush; /**< remove active core without flushing */ bool detach; /**< detach core without removing it from cache metadata */ int ext_err_code; @@ -473,7 +473,7 @@ struct kcas_get_cache_param { /** Add core object to an running cache instance */ #define KCAS_IOCTL_INSERT_CORE _IOWR(KCAS_IOCTL_MAGIC, 22, struct kcas_insert_core) -/** Remove core object from an running cache instance */ +/** Remove active core object from an running cache instance */ #define KCAS_IOCTL_REMOVE_CORE _IOR(KCAS_IOCTL_MAGIC, 23, struct kcas_remove_core) /** Retrieve properties of a running cache instance (incl. mode etc.) */ @@ -566,7 +566,7 @@ enum kcas_error { /** Given device is a partition */ KCAS_ERR_A_PART, - /** Core has been removed with flush error */ + /** Core has been removed, but it may contain dirty data */ KCAS_ERR_REMOVED_DIRTY, /** Cache has been stopped, but it may contain dirty data */ @@ -584,7 +584,7 @@ enum kcas_error { /** Condition token does not identify any known condition */ KCAS_ERR_CLS_RULE_UNKNOWN_CONDITION, - /** Waiting for async operation was interrupted*/ + /** Waiting for async operation was interrupted */ KCAS_ERR_WAITING_INTERRUPTED, /** Cache already being stopped*/