Merge pull request #962 from Open-CAS/passive_api

Passive state - API changes
This commit is contained in:
Robert Baldyga 2021-11-03 10:11:08 +01:00 committed by GitHub
commit 5431f83273
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 69 additions and 57 deletions

View File

@ -1138,8 +1138,12 @@ int get_cache_mode(int ctrl_fd, unsigned int cache_id, int *mode)
cmd_info.cache_id = cache_id;
if (ioctl(ctrl_fd, KCAS_IOCTL_CACHE_INFO, &cmd_info) < 0)
return FAILURE;
{
if (cmd_info.ext_err_code == OCF_ERR_CACHE_STANDBY)
cas_printf(LOG_ERR, "Cannot get cache mode while cache %d is in standby mode.", cmd_info.cache_id);
return FAILURE;
}
*mode = cmd_info.info.cache_mode;
return SUCCESS;
}
@ -1202,6 +1206,10 @@ int set_cache_mode(unsigned int cache_mode, unsigned int cache_id, int flush)
"of cache mode. If you want to switch cache mode immediately, use\n"
"'--flush-cache no' parameter.\n");
return INTERRUPTED;
} else if (OCF_ERR_CACHE_STANDBY == cmd.ext_err_code) {
cas_printf(LOG_ERR, "Cannot change cache mode while cache %d is in standby mode\n",
cache_id);
return FAILURE;
} else {
cas_printf(LOG_ERR, "Error while setting cache state for cache %d\n",
cache_id);
@ -1261,6 +1269,9 @@ int core_params_set(unsigned int cache_id, unsigned int core_id,
if (run_ioctl(fd, KCAS_IOCTL_SET_CORE_PARAM, &cmd) < 0) {
close(fd);
if (cmd.ext_err_code == OCF_ERR_CACHE_STANDBY) {
cas_printf(LOG_ERR, "Cannot set parameters for cache %d while in standby mode.\n", cmd.cache_id);
}
return FAILURE;
}
}
@ -1359,6 +1370,9 @@ int cache_params_set(unsigned int cache_id, struct cas_param *params)
cmd.param_value = params[i].value;
if (run_ioctl(fd, KCAS_IOCTL_SET_CACHE_PARAM, &cmd) < 0) {
if (cmd.ext_err_code == OCF_ERR_CACHE_STANDBY)
cas_printf(LOG_ERR, "Cannot set cache parameters while cache %d is in standby mode\n", cmd.cache_id);
close(fd);
return FAILURE;
}
@ -1368,41 +1382,6 @@ int cache_params_set(unsigned int cache_id, struct cas_param *params)
return SUCCESS;
}
int cache_get_param(unsigned int cache_id, unsigned int param_id,
struct cas_param *param)
{
struct kcas_get_cache_param cmd = { 0 };
int fd = 0;
if (param_id >= cache_param_id_max)
return FAILURE;
fd = open_ctrl_device();
if (fd == -1)
return FAILURE;
cmd.param_id = param_id;
cmd.cache_id = cache_id;
if (run_ioctl(fd, KCAS_IOCTL_GET_CACHE_PARAM, &cmd) < 0) {
if (cmd.ext_err_code == OCF_ERR_CACHE_NOT_EXIST)
cas_printf(LOG_ERR, "Cache id %d not running\n", cache_id);
else
cas_printf(LOG_ERR, "Can't get parameters\n");
close(fd);
return FAILURE;
}
if (param->transform_value)
param->value = param->transform_value(cmd.param_value);
else
param->value = cmd.param_value;
close(fd);
return SUCCESS;
}
int cache_params_get(unsigned int cache_id, struct cas_param *params,
unsigned int output_format)
{
@ -1434,6 +1413,8 @@ int cache_params_get(unsigned int cache_id, struct cas_param *params,
if (run_ioctl(fd, KCAS_IOCTL_GET_CACHE_PARAM, &cmd) < 0) {
if (cmd.ext_err_code == OCF_ERR_CACHE_NOT_EXIST)
cas_printf(LOG_ERR, "Cache id %d not running\n", cache_id);
else if (cmd.ext_err_code == OCF_ERR_CACHE_STANDBY)
cas_printf(LOG_ERR, "Cannot get cache parameters while cache %d is in standby mode\n", cmd.cache_id);
else
cas_printf(LOG_ERR, "Can't get parameters\n");
fclose(intermediate_file[0]);
@ -1763,6 +1744,8 @@ int add_core(unsigned int cache_id, unsigned int core_id, const char *core_devic
"accessing it or unmount the device.\n",
user_core_path);
}
} else if (OCF_ERR_CACHE_STANDBY == cmd.ext_err_code) {
cas_printf(LOG_ERR, "Cannot add core to cache %d in standby mode\n", cache_id);
} else {
print_err(cmd.ext_err_code);
}
@ -1986,6 +1969,9 @@ int flush_cache(unsigned int cache_id)
if (OCF_ERR_FLUSHING_INTERRUPTED == cmd.ext_err_code) {
cas_printf(LOG_ERR, DIRTY_FLUSHING_WARNING);
return INTERRUPTED;
} else if (OCF_ERR_CACHE_STANDBY == cmd.ext_err_code) {
cas_printf(LOG_ERR, "Cannot flush cache %d in standby mode\n", cmd.cache_id);
return FAILURE;
} else {
print_err(cmd.ext_err_code);
return FAILURE;
@ -2012,9 +1998,15 @@ int purge_core(unsigned int cache_id, unsigned int core_id)
/* synchronous flag */
if (run_ioctl_interruptible(fd, KCAS_IOCTL_PURGE_CORE, &cmd, "Purging core", cache_id, core_id) < 0) {
close(fd);
print_err(cmd.ext_err_code);
if (OCF_ERR_CACHE_STANDBY == cmd.ext_err_code)
cas_printf(LOG_ERR, "Cannot purge core while cache %d is in standby mode\n", cmd.cache_id);
else
print_err(cmd.ext_err_code);
return FAILURE;
}
close(fd);
return SUCCESS;
}
@ -2430,6 +2422,9 @@ int partition_set_config(struct kcas_io_classes *cnfg)
if (result) {
if (OCF_ERR_IO_CLASS_NOT_EXIST == cnfg->ext_err_code) {
result = SUCCESS;
} else if (OCF_ERR_CACHE_STANDBY == cnfg->ext_err_code) {
cas_printf(LOG_ERR, "Cannot set IO class config for cache %d while in standby mode.\n", cnfg->cache_id);
result = FAILURE;
} else {
print_err(cnfg->ext_err_code);
result = FAILURE;
@ -2504,9 +2499,13 @@ int reset_counters(unsigned int cache_id, unsigned int core_id)
cmd.core_id = core_id;
if (ioctl(fd, KCAS_IOCTL_RESET_STATS, &cmd) < 0) {
if (OCF_ERR_CACHE_STANDBY == cmd.ext_err_code) {
cas_printf(LOG_ERR, "Cannot reset statistics for cache %d while in standby mode.\n", cmd.cache_id);
} else {
cas_printf(LOG_ERR, "Error encountered while resetting counters\n");
print_err(cmd.ext_err_code);
}
close(fd);
cas_printf(LOG_ERR, "Error encountered while reseting counters\n");
print_err(cmd.ext_err_code);
return FAILURE;
}

View File

@ -628,6 +628,10 @@ static int cache_stats(int ctrl_fd, const struct kcas_cache_info *cache_info,
if (stats_filters & STATS_FILTER_CONF)
cache_stats_conf(ctrl_fd, cache_info, cache_id, outfile, by_id_path);
/* Don't print stats for a cache in standby state */
if (cache_info->info.state & (1 << ocf_cache_state_standby))
return SUCCESS;
if (stats_filters & STATS_FILTER_USAGE)
print_usage_stats(&cache_stats.usage, outfile);

View File

@ -778,6 +778,11 @@ int cache_mngt_purge_object(const char *cache_name, size_t cache_name_len,
if (result)
return result;
if (ocf_cache_is_standby(cache)) {
ocf_mngt_cache_put(cache);
return -OCF_ERR_CACHE_STANDBY;
}
result = _cache_mngt_read_lock_sync(cache);
if (result) {
ocf_mngt_cache_put(cache);
@ -989,7 +994,7 @@ int cache_mngt_get_promotion_policy(ocf_cache_t cache, uint32_t *type)
return result;
}
*type = ocf_mngt_cache_promotion_get_policy(cache);
result = ocf_mngt_cache_promotion_get_policy(cache, type);
ocf_mngt_cache_read_unlock(cache);
return result;
@ -1156,29 +1161,34 @@ int cache_mngt_prepare_core_cfg(struct ocf_mngt_core_config *cfg,
struct kcas_insert_core *cmd_info)
{
char core_name[OCF_CORE_NAME_SIZE] = {};
ocf_cache_t cache;
ocf_cache_t cache = NULL;
uint16_t core_id;
int result;
if (strnlen(cmd_info->core_path_name, MAX_STR_LEN) >= MAX_STR_LEN)
return -OCF_ERR_INVAL;
result = mngt_get_cache_by_id(cas_ctx, cmd_info->cache_id, &cache);
if (result && result != -OCF_ERR_CACHE_NOT_EXIST) {
return result;
} else if (!result && ocf_cache_is_standby(cache)) {
ocf_mngt_cache_put(cache);
return -OCF_ERR_CACHE_STANDBY;
}
if (cmd_info->core_id == OCF_CORE_MAX) {
result = mngt_get_cache_by_id(cas_ctx, cmd_info->cache_id,
&cache);
if (result && result != -OCF_ERR_CACHE_NOT_EXIST) {
return result;
} else if (!result) {
struct cache_priv *cache_priv;
cache_priv = ocf_cache_get_priv(cache);
ocf_mngt_cache_put(cache);
struct cache_priv *cache_priv;
cache_priv = ocf_cache_get_priv(cache);
core_id = find_free_core_id(cache_priv->core_id_bitmap);
if (core_id == OCF_CORE_MAX)
return -OCF_ERR_INVAL;
core_id = find_free_core_id(cache_priv->core_id_bitmap);
if (core_id == OCF_CORE_MAX)
return -OCF_ERR_INVAL;
cmd_info->core_id = core_id;
}
cmd_info->core_id = core_id;
}
if (cache) {
ocf_mngt_cache_put(cache);
cache = NULL;
}
snprintf(core_name, sizeof(core_name), "core%d", cmd_info->core_id);
@ -1627,7 +1637,7 @@ int cache_mngt_reset_stats(const char *cache_name, size_t cache_name_len,
ocf_core_stats_initialize(core);
} else {
ocf_core_stats_initialize_all(cache);
result = ocf_core_stats_initialize_all(cache);
}
out:
@ -3194,7 +3204,6 @@ int cache_mngt_get_cache_params(struct kcas_get_cache_param *info)
result = cache_mngt_get_cleaning_policy(cache,
&info->param_value);
break;
case cache_param_cleaning_alru_wake_up_time:
result = cache_mngt_get_cleaning_param(cache,
ocf_cleaning_alru, ocf_alru_wake_up_time,

2
ocf

@ -1 +1 @@
Subproject commit 7b120162a573868221a3f66366ecbf2e1f4b90be
Subproject commit 12c8b4e333d7472f55f277195418db3df8ba6e2d