Reorganize remove-inacitve command

Don't remove inactive core if it has dirt cache lines assigned unless `force`
flag is specified.

Signed-off-by: Michal Mielewczyk <michal.mielewczyk@intel.com>
This commit is contained in:
Michal Mielewczyk 2021-04-12 13:46:57 +02:00
parent 8a8572d8bb
commit 4e680bb50a
6 changed files with 24 additions and 24 deletions

View File

@ -1937,7 +1937,8 @@ int remove_core(unsigned int cache_id, unsigned int core_id,
return SUCCESS; return SUCCESS;
} }
int remove_inactive_core(unsigned int cache_id, unsigned int core_id) int remove_inactive_core(unsigned int cache_id, unsigned int core_id,
bool force)
{ {
int fd = 0; int fd = 0;
struct kcas_remove_inactive cmd; struct kcas_remove_inactive cmd;
@ -1954,6 +1955,7 @@ int remove_inactive_core(unsigned int cache_id, unsigned int core_id)
memset(&cmd, 0, sizeof(cmd)); memset(&cmd, 0, sizeof(cmd));
cmd.cache_id = cache_id; cmd.cache_id = cache_id;
cmd.core_id = core_id; cmd.core_id = core_id;
cmd.force = force;
if (run_ioctl(fd, KCAS_IOCTL_REMOVE_INACTIVE, &cmd) < 0) { if (run_ioctl(fd, KCAS_IOCTL_REMOVE_INACTIVE, &cmd) < 0) {
close(fd); close(fd);

View File

@ -220,9 +220,10 @@ int remove_core(unsigned int cache_id, unsigned int core_id,
* *
* @param cache_id cache from which inactive core is being removed * @param cache_id cache from which inactive core is being removed
* @param cache_id inactive core which is being removed * @param cache_id inactive core which is being removed
* @param force remove inactive force even if it has dirty cache lines assigned
* @return 0 upon successful core removal, 1 upon failure * @return 0 upon successful core removal, 1 upon failure
*/ */
int remove_inactive_core(unsigned int cache_id, unsigned int core_id); int remove_inactive_core(unsigned int cache_id, unsigned int core_id, bool force);
int core_pool_remove(const char *core_device); int core_pool_remove(const char *core_device);
int get_core_pool_count(int fd); int get_core_pool_count(int fd);

View File

@ -180,23 +180,6 @@ int remove_core_command_handle_option(char *opt, const char **arg)
return 0; return 0;
} }
int remove_inactive_core_command_handle_option(char *opt, const char **arg)
{
if (!strcmp(opt, "cache-id")){
if (validate_str_num(arg[0], "cache id", OCF_CACHE_ID_MIN, OCF_CACHE_ID_MAX) == FAILURE)
return FAILURE;
command_args_values.cache_id = atoi(arg[0]);
} else if (!strcmp(opt, "core-id")){
if (validate_str_num(arg[0], "core id", 0, OCF_CORE_ID_MAX) == FAILURE)
return FAILURE;
command_args_values.core_id = atoi(arg[0]);
}
return 0;
}
int core_pool_remove_command_handle_option(char *opt, const char **arg) int core_pool_remove_command_handle_option(char *opt, const char **arg)
{ {
if (!strcmp(opt, "device")) { if (!strcmp(opt, "device")) {
@ -1143,13 +1126,14 @@ int handle_remove()
static cli_option remove_inactive_options[] = { static cli_option remove_inactive_options[] = {
{'i', "cache-id", CACHE_ID_DESC, 1, "ID", CLI_OPTION_REQUIRED}, {'i', "cache-id", CACHE_ID_DESC, 1, "ID", CLI_OPTION_REQUIRED},
{'j', "core-id", CORE_ID_DESC, 1, "ID", CLI_OPTION_REQUIRED}, {'j', "core-id", CORE_ID_DESC, 1, "ID", CLI_OPTION_REQUIRED},
{'f', "force", "Force dirty inactive core removal"},
{0} {0}
}; };
int handle_remove_inactive() int handle_remove_inactive()
{ {
return remove_inactive_core(command_args_values.cache_id, return remove_inactive_core(command_args_values.cache_id,
command_args_values.core_id); command_args_values.core_id, command_args_values.force);
} }
static cli_option core_pool_remove_options[] = { static cli_option core_pool_remove_options[] = {
@ -2005,7 +1989,7 @@ static cli_command cas_commands[] = {
.desc = "Remove inactive core device from cache instance", .desc = "Remove inactive core device from cache instance",
.long_desc = NULL, .long_desc = NULL,
.options = remove_inactive_options, .options = remove_inactive_options,
.command_handle_opts = remove_inactive_core_command_handle_option, .command_handle_opts = remove_core_command_handle_option,
.handle = handle_remove_inactive, .handle = handle_remove_inactive,
.flags = CLI_SU_REQUIRED, .flags = CLI_SU_REQUIRED,
.help = NULL, .help = NULL,

View File

@ -258,7 +258,11 @@ struct {
KCAS_ERR_CORE_IN_ACTIVE_STATE, KCAS_ERR_CORE_IN_ACTIVE_STATE,
"Core device is in active state" "Core device is in active state"
}, },
{
KCAS_ERR_INACTIVE_CORE_IS_DIRTY,
"The cache contains dirty data assigned to the core. If you want to "
"continue, please use --force option.\nWarning: the data will be lost"
},
}; };
const char *cas_strerr(int cas_error_code) const char *cas_strerr(int cas_error_code)

View File

@ -1517,6 +1517,11 @@ int cache_mngt_remove_inactive_core(struct kcas_remove_inactive *cmd)
goto unlock; goto unlock;
} }
if (ocf_mngt_core_is_dirty(core) && !cmd->force) {
result = -KCAS_ERR_INACTIVE_CORE_IS_DIRTY;
goto unlock;
}
/* /*
* Destroy exported object - in case of error during destruction of * Destroy exported object - in case of error during destruction of
* exported object, instead of trying rolling this back we rather * exported object, instead of trying rolling this back we rather

View File

@ -126,6 +126,7 @@ struct kcas_remove_core {
struct kcas_remove_inactive { struct kcas_remove_inactive {
uint16_t cache_id; /**< id of an running cache */ uint16_t cache_id; /**< id of an running cache */
uint16_t core_id; /**< id core object to be removed */ uint16_t core_id; /**< id core object to be removed */
bool force; /**< remove inactive core without flushing */
int ext_err_code; int ext_err_code;
}; };
@ -599,7 +600,10 @@ enum kcas_error {
KCAS_ERR_WAITING_INTERRUPTED, KCAS_ERR_WAITING_INTERRUPTED,
/** Core device is in active state */ /** Core device is in active state */
KCAS_ERR_CORE_IN_ACTIVE_STATE KCAS_ERR_CORE_IN_ACTIVE_STATE,
/** Inactive core has dirty data assigned */
KCAS_ERR_INACTIVE_CORE_IS_DIRTY
}; };
#endif #endif