Use name based OCF management API

Signed-off-by: Robert Baldyga <robert.baldyga@intel.com>
This commit is contained in:
Robert Baldyga 2019-08-12 09:48:30 +02:00
parent c9fdcd9f76
commit f038223979
11 changed files with 509 additions and 328 deletions

View File

@ -868,7 +868,7 @@ static void check_cache_scheduler(const char *cache_device, const char *elv_name
} }
} }
int start_cache(ocf_cache_id_t cache_id, unsigned int cache_init, int start_cache(uint16_t cache_id, unsigned int cache_init,
const char *cache_device, ocf_cache_mode_t cache_mode, const char *cache_device, ocf_cache_mode_t cache_mode,
ocf_eviction_t eviction_policy_type, ocf_eviction_t eviction_policy_type,
ocf_cache_line_size_t line_size, int force) ocf_cache_line_size_t line_size, int force)
@ -1001,7 +1001,7 @@ int start_cache(ocf_cache_id_t cache_id, unsigned int cache_init,
return SUCCESS; return SUCCESS;
} }
int stop_cache(ocf_cache_id_t cache_id, int flush) int stop_cache(uint16_t cache_id, int flush)
{ {
int fd = 0; int fd = 0;
struct kcas_stop_cache cmd; struct kcas_stop_cache cmd;

View File

@ -118,11 +118,11 @@ int caslog(int log_level, const char *template, ...);
#define UNDEFINED -1 #define UNDEFINED -1
void metadata_memory_footprint(uint64_t size, float *footprint, const char **units); void metadata_memory_footprint(uint64_t size, float *footprint, const char **units);
int start_cache(ocf_cache_id_t cache_id, unsigned int cache_init, int start_cache(uint16_t cache_id, unsigned int cache_init,
const char *cache_device, ocf_cache_mode_t cache_mode, const char *cache_device, ocf_cache_mode_t cache_mode,
ocf_eviction_t eviction_policy_type, ocf_eviction_t eviction_policy_type,
ocf_cache_line_size_t line_size, int force); ocf_cache_line_size_t line_size, int force);
int stop_cache(ocf_cache_id_t cache_id, int flush); int stop_cache(uint16_t cache_id, int flush);
#ifdef WI_AVAILABLE #ifdef WI_AVAILABLE
#define CAS_CLI_HELP_START_CACHE_MODES "wt|wb|wa|pt|wi|wo" #define CAS_CLI_HELP_START_CACHE_MODES "wt|wb|wa|pt|wi|wo"

View File

@ -57,6 +57,7 @@ enum {
struct cas_classifier; struct cas_classifier;
struct cache_priv { struct cache_priv {
uint64_t core_id_bitmap[DIV_ROUND_UP(OCF_CORE_MAX, 8*sizeof(uint64_t))];
struct cas_classifier *classifier; struct cas_classifier *classifier;
atomic_t flush_interrupt_enabled; atomic_t flush_interrupt_enabled;
ocf_queue_t mngt_queue; ocf_queue_t mngt_queue;
@ -96,4 +97,60 @@ struct casdsk_functions_mapper {
struct gendisk *(*casdsk_exp_obj_get_gendisk)(struct casdsk_disk *dsk); struct gendisk *(*casdsk_exp_obj_get_gendisk)(struct casdsk_disk *dsk);
}; };
static inline void cache_name_from_id(char *name, uint16_t id)
{
int result;
result = snprintf(name, OCF_CACHE_NAME_SIZE, "cache%d", id);
ENV_BUG_ON(result >= OCF_CACHE_NAME_SIZE);
}
static inline void core_name_from_id(char *name, uint16_t id)
{
int result;
result = snprintf(name, OCF_CORE_NAME_SIZE, "core%d", id);
ENV_BUG_ON(result >= OCF_CORE_NAME_SIZE);
}
static inline int cache_id_from_name(uint16_t *cache_id, const char *name)
{
const char *id_str;
long res;
int result;
if (strnlen(name, OCF_CACHE_NAME_SIZE) < sizeof("cache") - 1)
return -EINVAL;
id_str = name + sizeof("cache") - 1;
result = kstrtol(id_str, 10, &res);
if (!result)
*cache_id = res;
return result;
}
static inline int mngt_get_cache_by_id(ocf_ctx_t ctx, uint16_t id,
ocf_cache_t *cache)
{
char cache_name[OCF_CACHE_NAME_SIZE];
cache_name_from_id(cache_name, id);
return ocf_mngt_cache_get_by_name(ctx, cache_name, cache);
}
static inline int get_core_by_id(ocf_cache_t cache, uint16_t id,
ocf_core_t *core)
{
char core_name[OCF_CORE_NAME_SIZE];
core_name_from_id(core_name, id);
return ocf_core_get_by_name(cache, core_name, core);
}
#endif #endif

View File

@ -154,13 +154,75 @@ static int _cache_mngt_cache_stop_sync(ocf_cache_t cache)
return result; return result;
} }
int cache_mngt_flush_object(ocf_cache_id_t cache_id, ocf_core_id_t core_id) static uint16_t find_free_cache_id(ocf_ctx_t ctx)
{
ocf_cache_t cache;
uint16_t id;
int result;
for (id = OCF_CACHE_ID_MIN; id < OCF_CACHE_ID_MAX; id++) {
result = mngt_get_cache_by_id(ctx, id, &cache);
if (!result)
ocf_mngt_cache_put(cache);
else if (result == -OCF_ERR_CACHE_NOT_EXIST)
break;
else
return OCF_CACHE_ID_MAX;
}
return id;
}
static uint64_t _ffz(uint64_t word)
{
int i;
for (i = 0; i < sizeof(word)*8 && (word & 1); i++)
word >>= 1;
return i;
}
static uint16_t find_free_core_id(uint64_t *bitmap)
{
uint16_t i, ret = OCF_CORE_MAX;
bool zero_core_free = !(*bitmap & 0x1UL);
/* check if any core id is free except 0 */
for (i = 0; i * sizeof(uint64_t) * 8 < OCF_CORE_MAX; i++) {
uint64_t ignore_mask = (i == 0) ? 1UL : 0UL;
if (~(bitmap[i] | ignore_mask)) {
ret = min((uint64_t)OCF_CORE_MAX,
(uint64_t)(i * sizeof(uint64_t) * 8
+ _ffz(bitmap[i] | ignore_mask)));
break;
}
}
/* return 0 only if no other core is free */
if (ret == OCF_CORE_MAX && zero_core_free)
return 0;
return ret;
}
static void mark_core_id_used(uint64_t *bitmap, uint16_t core_id)
{
set_bit(core_id, (unsigned long *)bitmap);
}
static void mark_core_id_free(uint64_t *bitmap, uint16_t core_id)
{
clear_bit(core_id, (unsigned long *)bitmap);
}
int cache_mngt_flush_object(const char *cache_name, const char *core_name)
{ {
ocf_cache_t cache; ocf_cache_t cache;
ocf_core_t core; ocf_core_t core;
int result; int result;
result = ocf_mngt_cache_get_by_id(cas_ctx, cache_id, &cache); result = ocf_mngt_cache_get_by_name(cas_ctx, cache_name, &cache);
if (result) if (result)
return result; return result;
@ -170,7 +232,7 @@ int cache_mngt_flush_object(ocf_cache_id_t cache_id, ocf_core_id_t core_id)
return result; return result;
} }
result = ocf_core_get(cache, core_id, &core); result = ocf_core_get_by_name(cache, core_name, &core);
if (result) if (result)
goto out; goto out;
@ -182,12 +244,12 @@ out:
return result; return result;
} }
int cache_mngt_flush_device(ocf_cache_id_t id) int cache_mngt_flush_device(const char *cache_name)
{ {
int result; int result;
ocf_cache_t cache; ocf_cache_t cache;
result = ocf_mngt_cache_get_by_id(cas_ctx, id, &cache); result = ocf_mngt_cache_get_by_name(cas_ctx, cache_name, &cache);
if (result) if (result)
return result; return result;
@ -204,15 +266,10 @@ int cache_mngt_flush_device(ocf_cache_id_t id)
return result; return result;
} }
int cache_mngt_set_cleaning_policy(ocf_cache_id_t cache_id, uint32_t type) int cache_mngt_set_cleaning_policy(ocf_cache_t cache, uint32_t type)
{ {
ocf_cache_t cache;
int result; int result;
result = ocf_mngt_cache_get_by_id(cas_ctx, cache_id, &cache);
if (result)
return result;
result = _cache_mngt_lock_sync(cache); result = _cache_mngt_lock_sync(cache);
if (result) { if (result) {
ocf_mngt_cache_put(cache); ocf_mngt_cache_put(cache);
@ -227,20 +284,14 @@ int cache_mngt_set_cleaning_policy(ocf_cache_id_t cache_id, uint32_t type)
out: out:
ocf_mngt_cache_unlock(cache); ocf_mngt_cache_unlock(cache);
ocf_mngt_cache_put(cache);
return result; return result;
} }
int cache_mngt_get_cleaning_policy(ocf_cache_id_t cache_id, uint32_t *type) int cache_mngt_get_cleaning_policy(ocf_cache_t cache, uint32_t *type)
{ {
ocf_cleaning_t tmp_type; ocf_cleaning_t tmp_type;
ocf_cache_t cache;
int result; int result;
result = ocf_mngt_cache_get_by_id(cas_ctx, cache_id, &cache);
if (result)
return result;
result = _cache_mngt_read_lock_sync(cache); result = _cache_mngt_read_lock_sync(cache);
if (result) { if (result) {
ocf_mngt_cache_put(cache); ocf_mngt_cache_put(cache);
@ -253,20 +304,14 @@ int cache_mngt_get_cleaning_policy(ocf_cache_id_t cache_id, uint32_t *type)
*type = tmp_type; *type = tmp_type;
ocf_mngt_cache_read_unlock(cache); ocf_mngt_cache_read_unlock(cache);
ocf_mngt_cache_put(cache);
return result; return result;
} }
int cache_mngt_set_cleaning_param(ocf_cache_id_t cache_id, ocf_cleaning_t type, int cache_mngt_set_cleaning_param(ocf_cache_t cache, ocf_cleaning_t type,
uint32_t param_id, uint32_t param_value) uint32_t param_id, uint32_t param_value)
{ {
ocf_cache_t cache;
int result; int result;
result = ocf_mngt_cache_get_by_id(cas_ctx, cache_id, &cache);
if (result)
return result;
result = _cache_mngt_lock_sync(cache); result = _cache_mngt_lock_sync(cache);
if (result) { if (result) {
ocf_mngt_cache_put(cache); ocf_mngt_cache_put(cache);
@ -282,20 +327,14 @@ int cache_mngt_set_cleaning_param(ocf_cache_id_t cache_id, ocf_cleaning_t type,
out: out:
ocf_mngt_cache_unlock(cache); ocf_mngt_cache_unlock(cache);
ocf_mngt_cache_put(cache);
return result; return result;
} }
int cache_mngt_get_cleaning_param(ocf_cache_id_t cache_id, ocf_cleaning_t type, int cache_mngt_get_cleaning_param(ocf_cache_t cache, ocf_cleaning_t type,
uint32_t param_id, uint32_t *param_value) uint32_t param_id, uint32_t *param_value)
{ {
ocf_cache_t cache;
int result; int result;
result = ocf_mngt_cache_get_by_id(cas_ctx, cache_id, &cache);
if (result)
return result;
result = _cache_mngt_read_lock_sync(cache); result = _cache_mngt_read_lock_sync(cache);
if (result) { if (result) {
ocf_mngt_cache_put(cache); ocf_mngt_cache_put(cache);
@ -306,7 +345,6 @@ int cache_mngt_get_cleaning_param(ocf_cache_id_t cache_id, ocf_cleaning_t type,
param_id, param_value); param_id, param_value);
ocf_mngt_cache_read_unlock(cache); ocf_mngt_cache_read_unlock(cache);
ocf_mngt_cache_put(cache);
return result; return result;
} }
@ -437,15 +475,37 @@ int cache_mngt_prepare_core_cfg(struct ocf_mngt_core_config *cfg,
struct kcas_insert_core *cmd_info) struct kcas_insert_core *cmd_info)
{ {
struct block_device *bdev; struct block_device *bdev;
static char core_name[OCF_CORE_NAME_SIZE];
struct cache_priv *cache_priv;
ocf_cache_t cache;
uint16_t core_id;
int result; int result;
if (strnlen(cmd_info->core_path_name, MAX_STR_LEN) >= MAX_STR_LEN) if (strnlen(cmd_info->core_path_name, MAX_STR_LEN) >= MAX_STR_LEN)
return -OCF_ERR_INVAL; return -OCF_ERR_INVAL;
if (cmd_info->core_id == OCF_CORE_MAX) {
result = mngt_get_cache_by_id(cas_ctx, cmd_info->cache_id,
&cache);
if (result)
return result;
cache_priv = ocf_cache_get_priv(cache);
ocf_mngt_cache_put(cache);
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;
}
snprintf(core_name, sizeof(core_name), "core%d", cmd_info->core_id);
memset(cfg, 0, sizeof(*cfg)); memset(cfg, 0, sizeof(*cfg));
cfg->name = core_name;
cfg->uuid.data = cmd_info->core_path_name; cfg->uuid.data = cmd_info->core_path_name;
cfg->uuid.size = strnlen(cmd_info->core_path_name, MAX_STR_LEN) + 1; cfg->uuid.size = strnlen(cmd_info->core_path_name, MAX_STR_LEN) + 1;
cfg->core_id = cmd_info->core_id;
cfg->try_add = cmd_info->try_add; cfg->try_add = cmd_info->try_add;
if (cas_upgrade_is_in_upgrade()) { if (cas_upgrade_is_in_upgrade()) {
@ -474,7 +534,8 @@ int cache_mngt_prepare_core_cfg(struct ocf_mngt_core_config *cfg,
return result; return result;
} }
int cache_mngt_update_core_uuid(ocf_cache_t cache, ocf_core_id_t id, ocf_uuid_t uuid) static int cache_mngt_update_core_uuid(ocf_cache_t cache, const char *core_name,
ocf_uuid_t uuid)
{ {
ocf_core_t core; ocf_core_t core;
ocf_volume_t vol; ocf_volume_t vol;
@ -483,7 +544,7 @@ int cache_mngt_update_core_uuid(ocf_cache_t cache, ocf_core_id_t id, ocf_uuid_t
bool match; bool match;
int result; int result;
if (ocf_core_get(cache, id, &core)) { if (ocf_core_get_by_name(cache, core_name, &core)) {
/* no such core */ /* no such core */
return -ENODEV; return -ENODEV;
} }
@ -560,17 +621,18 @@ static void _cache_mngt_add_core_complete(ocf_cache_t cache,
static void _cache_mngt_remove_core_complete(void *priv, int error); static void _cache_mngt_remove_core_complete(void *priv, int error);
int cache_mngt_add_core_to_cache(struct ocf_mngt_core_config *cfg, int cache_mngt_add_core_to_cache(const char *cache_name,
ocf_cache_id_t cache_id, struct kcas_insert_core *cmd_info) struct ocf_mngt_core_config *cfg,
struct kcas_insert_core *cmd_info)
{ {
struct _cache_mngt_add_core_context add_context; struct _cache_mngt_add_core_context add_context;
struct _cache_mngt_sync_context remove_context; struct _cache_mngt_sync_context remove_context;
ocf_cache_t cache; ocf_cache_t cache;
ocf_core_t core; ocf_core_t core;
ocf_core_id_t core_id;
int result, remove_core_result; int result, remove_core_result;
struct cache_priv *cache_priv;
result = ocf_mngt_cache_get_by_id(cas_ctx, cache_id, &cache); result = ocf_mngt_cache_get_by_name(cas_ctx, cache_name, &cache);
if (cfg->try_add && (result == -OCF_ERR_CACHE_NOT_EXIST)) { if (cfg->try_add && (result == -OCF_ERR_CACHE_NOT_EXIST)) {
result = ocf_mngt_core_pool_add(cas_ctx, &cfg->uuid, result = ocf_mngt_core_pool_add(cas_ctx, &cfg->uuid,
cfg->volume_type); cfg->volume_type);
@ -597,7 +659,7 @@ int cache_mngt_add_core_to_cache(struct ocf_mngt_core_config *cfg,
} }
if (cmd_info && cmd_info->update_path) { if (cmd_info && cmd_info->update_path) {
result = cache_mngt_update_core_uuid(cache, cfg->core_id, &cfg->uuid); result = cache_mngt_update_core_uuid(cache, cfg->name, &cfg->uuid);
ocf_mngt_cache_unlock(cache); ocf_mngt_cache_unlock(cache);
ocf_mngt_cache_put(cache); ocf_mngt_cache_put(cache);
return result; return result;
@ -615,8 +677,6 @@ int cache_mngt_add_core_to_cache(struct ocf_mngt_core_config *cfg,
if (result) if (result)
goto error_affter_lock; goto error_affter_lock;
core_id = ocf_core_get_id(core);
result = block_dev_create_exported_object(core); result = block_dev_create_exported_object(core);
if (result) if (result)
goto error_after_add_core; goto error_after_add_core;
@ -625,12 +685,13 @@ int cache_mngt_add_core_to_cache(struct ocf_mngt_core_config *cfg,
if (result) if (result)
goto error_after_create_exported_object; goto error_after_create_exported_object;
cache_priv = ocf_cache_get_priv(cache);
mark_core_id_used(cache_priv->core_id_bitmap, cmd_info->core_id);
ocf_mngt_cache_unlock(cache); ocf_mngt_cache_unlock(cache);
ocf_mngt_cache_put(cache); ocf_mngt_cache_put(cache);
if (cmd_info)
cmd_info->core_id = core_id;
_cache_mngt_log_core_device_path(core); _cache_mngt_log_core_device_path(core);
return 0; return 0;
@ -713,8 +774,9 @@ int cache_mngt_remove_core_from_cache(struct kcas_remove_core *cmd)
int result, flush_result = 0; int result, flush_result = 0;
ocf_cache_t cache; ocf_cache_t cache;
ocf_core_t core; ocf_core_t core;
struct cache_priv *cache_priv;
result = ocf_mngt_cache_get_by_id(cas_ctx, cmd->cache_id, &cache); result = mngt_get_cache_by_id(cas_ctx, cmd->cache_id, &cache);
if (result) if (result)
return result; return result;
@ -725,7 +787,7 @@ int cache_mngt_remove_core_from_cache(struct kcas_remove_core *cmd)
if (result) if (result)
goto put; goto put;
result = ocf_core_get(cache, cmd->core_id, &core); result = get_core_by_id(cache, cmd->core_id, &core);
if (result < 0) if (result < 0)
goto rd_unlock; goto rd_unlock;
@ -742,7 +804,7 @@ int cache_mngt_remove_core_from_cache(struct kcas_remove_core *cmd)
if (result) if (result)
goto put; goto put;
result = ocf_core_get(cache, cmd->core_id, &core); result = get_core_by_id(cache, cmd->core_id, &core);
if (result < 0) { if (result < 0) {
goto unlock; goto unlock;
} }
@ -777,6 +839,11 @@ int cache_mngt_remove_core_from_cache(struct kcas_remove_core *cmd)
wait_for_completion(&context.compl); wait_for_completion(&context.compl);
if (!result && cmd->detach) {
cache_priv = ocf_cache_get_priv(cache);
mark_core_id_free(cache_priv->core_id_bitmap, cmd->core_id);
}
if (!result && flush_result) if (!result && flush_result)
result = flush_result; result = flush_result;
@ -792,14 +859,13 @@ rd_unlock:
return result; return result;
} }
int cache_mngt_reset_stats(ocf_cache_id_t cache_id, int cache_mngt_reset_stats(const char *cache_name, const char *core_name)
ocf_core_id_t core_id)
{ {
ocf_cache_t cache; ocf_cache_t cache;
ocf_core_t core; ocf_core_t core;
int result = 0; int result = 0;
result = ocf_mngt_cache_get_by_id(cas_ctx, cache_id, &cache); result = ocf_mngt_cache_get_by_name(cas_ctx, cache_name, &cache);
if (result) if (result)
return result; return result;
@ -809,8 +875,8 @@ int cache_mngt_reset_stats(ocf_cache_id_t cache_id,
return result; return result;
} }
if (core_id != OCF_CORE_ID_INVALID) { if (!core_name) {
result = ocf_core_get(cache, core_id, &core); result = ocf_core_get_by_name(cache, core_name, &core);
if (result) if (result)
goto out; goto out;
@ -836,7 +902,8 @@ static inline void io_class_info2cfg(ocf_part_id_t part_id,
cfg->max_size = info->max_size; cfg->max_size = info->max_size;
} }
int cache_mngt_set_partitions(struct kcas_io_classes *cfg) int cache_mngt_set_partitions(const char *cache_name,
struct kcas_io_classes *cfg)
{ {
ocf_cache_t cache; ocf_cache_t cache;
struct ocf_mngt_io_classes_config *io_class_cfg; struct ocf_mngt_io_classes_config *io_class_cfg;
@ -861,7 +928,7 @@ int cache_mngt_set_partitions(struct kcas_io_classes *cfg)
&io_class_cfg->config[class_id]); &io_class_cfg->config[class_id]);
} }
result = ocf_mngt_cache_get_by_id(cas_ctx, cfg->cache_id, &cache); result = ocf_mngt_cache_get_by_name(cas_ctx, cache_name, &cache);
if (result) if (result)
goto out_get; goto out_get;
@ -910,19 +977,17 @@ static int _cache_mngt_create_exported_object(ocf_core_t core, void *cntx)
result = block_dev_create_exported_object(core); result = block_dev_create_exported_object(core);
if (result) { if (result) {
printk(KERN_ERR "Cannot to create exported object, " printk(KERN_ERR "Cannot to create exported object, %s.%s\n",
"cache id = %u, core id = %u\n", ocf_cache_get_name(cache),
ocf_cache_get_id(cache), ocf_core_get_name(core));
ocf_core_get_id(core));
return result; return result;
} }
result = block_dev_activate_exported_object(core); result = block_dev_activate_exported_object(core);
if (result) { if (result) {
printk(KERN_ERR "Cannot to activate exported object, " printk(KERN_ERR "Cannot to activate exported object, %s.%s\n",
"cache id = %u, core id = %u\n", ocf_cache_get_name(cache),
ocf_cache_get_id(cache), ocf_core_get_name(core));
ocf_core_get_id(core));
} }
return result; return result;
@ -933,10 +998,9 @@ static int _cache_mngt_destroy_exported_object(ocf_core_t core, void *cntx)
if (block_dev_destroy_exported_object(core)) { if (block_dev_destroy_exported_object(core)) {
ocf_cache_t cache = ocf_core_get_cache(core); ocf_cache_t cache = ocf_core_get_cache(core);
printk(KERN_ERR "Cannot to destroy exported object, " printk(KERN_ERR "Cannot to destroy exported object, %s.%s\n",
"cache id = %u, core id = %u\n", ocf_cache_get_name(cache),
ocf_cache_get_id(cache), ocf_core_get_name(core));
ocf_core_get_id(core));
} }
return 0; return 0;
@ -966,16 +1030,28 @@ int cache_mngt_prepare_cache_cfg(struct ocf_mngt_cache_config *cfg,
struct block_device *bdev; struct block_device *bdev;
int part_count; int part_count;
char holder[] = "CAS START\n"; char holder[] = "CAS START\n";
char cache_name[OCF_CACHE_NAME_SIZE];
uint16_t cache_id;
bool is_part; bool is_part;
if (strnlen(cmd->cache_path_name, MAX_STR_LEN) >= MAX_STR_LEN) if (strnlen(cmd->cache_path_name, MAX_STR_LEN) >= MAX_STR_LEN)
return -OCF_ERR_INVAL; return -OCF_ERR_INVAL;
if (cmd->cache_id == OCF_CACHE_ID_MAX) {
cache_id = find_free_cache_id(cas_ctx);
if (cache_id == OCF_CACHE_ID_MAX)
return -OCF_ERR_INVAL;
cmd->cache_id = cache_id;
}
cache_name_from_id(cache_name, cmd->cache_id);
memset(cfg, 0, sizeof(*cfg)); memset(cfg, 0, sizeof(*cfg));
memset(device_cfg, 0, sizeof(*device_cfg)); memset(device_cfg, 0, sizeof(*device_cfg));
memset(atomic_params, 0, sizeof(*atomic_params)); memset(atomic_params, 0, sizeof(*atomic_params));
cfg->id = cmd->cache_id; cfg->name = cache_name;
cfg->cache_mode = cmd->caching_mode; cfg->cache_mode = cmd->caching_mode;
cfg->cache_line_size = cmd->line_size; cfg->cache_line_size = cmd->line_size;
cfg->eviction_policy = cmd->eviction_policy; cfg->eviction_policy = cmd->eviction_policy;
@ -1120,7 +1196,7 @@ static int _cache_mngt_cache_priv_init(ocf_cache_t cache)
struct cache_priv *cache_priv; struct cache_priv *cache_priv;
uint32_t cpus_no = num_online_cpus(); uint32_t cpus_no = num_online_cpus();
cache_priv = vmalloc(sizeof(*cache_priv) + cache_priv = vzalloc(sizeof(*cache_priv) +
cpus_no * sizeof(*cache_priv->io_queues)); cpus_no * sizeof(*cache_priv->io_queues));
if (!cache_priv) if (!cache_priv)
return -OCF_ERR_NO_MEM; return -OCF_ERR_NO_MEM;
@ -1340,36 +1416,24 @@ int cache_mngt_init_instance(struct ocf_mngt_cache_config *cfg,
/** /**
* @brief routine implementing dynamic sequential cutoff parameter switching * @brief routine implementing dynamic sequential cutoff parameter switching
* @param[in] cache_id cache id to which the change pertains * @param[in] cache cache to which the change pertains
* @param[in] core_id core id to which the change pertains * @param[in] core core to which the change pertains
* or OCF_CORE_ID_INVALID for setting value for all cores * or NULL for setting value for all cores attached to specified cache
* attached to specified cache
* @param[in] thresh new sequential cutoff threshold value * @param[in] thresh new sequential cutoff threshold value
* @return exit code of successful completion is 0; * @return exit code of successful completion is 0;
* nonzero exit code means failure * nonzero exit code means failure
*/ */
int cache_mngt_set_seq_cutoff_threshold(ocf_cache_id_t cache_id, ocf_core_id_t core_id, int cache_mngt_set_seq_cutoff_threshold(ocf_cache_t cache, ocf_core_t core,
uint32_t thresh) uint32_t thresh)
{ {
ocf_cache_t cache;
ocf_core_t core;
int result; int result;
result = ocf_mngt_cache_get_by_id(cas_ctx, cache_id, &cache);
if (result)
return result;
result = _cache_mngt_lock_sync(cache); result = _cache_mngt_lock_sync(cache);
if (result) {
ocf_mngt_cache_put(cache);
return result;
}
if (core_id != OCF_CORE_ID_INVALID) {
result = ocf_core_get(cache, core_id, &core);
if (result) if (result)
goto out; return result;
if (core) {
result = ocf_mngt_core_set_seq_cutoff_threshold(core, thresh); result = ocf_mngt_core_set_seq_cutoff_threshold(core, thresh);
} else { } else {
result = ocf_mngt_core_set_seq_cutoff_threshold_all(cache, result = ocf_mngt_core_set_seq_cutoff_threshold_all(cache,
@ -1383,46 +1447,32 @@ int cache_mngt_set_seq_cutoff_threshold(ocf_cache_id_t cache_id, ocf_core_id_t c
out: out:
ocf_mngt_cache_unlock(cache); ocf_mngt_cache_unlock(cache);
ocf_mngt_cache_put(cache);
return result; return result;
} }
/** /**
* @brief routine implementing dynamic sequential cutoff parameter switching * @brief routine implementing dynamic sequential cutoff parameter switching
* @param[in] id cache id to which the change pertains * @param[in] cache cache to which the change pertains
* @param[in] core_id core id to which the change pertains * @param[in] core core to which the change pertains
* or OCF_CORE_ID_INVALID for setting value for all cores * or NULL for setting value for all cores attached to specified cache
* attached to specified cache
* @param[in] policy new sequential cutoff policy value * @param[in] policy new sequential cutoff policy value
* @return exit code of successful completion is 0; * @return exit code of successful completion is 0;
* nonzero exit code means failure * nonzero exit code means failure
*/ */
int cache_mngt_set_seq_cutoff_policy(ocf_cache_id_t id, ocf_core_id_t core_id, int cache_mngt_set_seq_cutoff_policy(ocf_cache_t cache, ocf_core_t core,
ocf_seq_cutoff_policy policy) ocf_seq_cutoff_policy policy)
{ {
ocf_cache_t cache;
ocf_core_t core;
int result; int result;
result = ocf_mngt_cache_get_by_id(cas_ctx, id, &cache);
if (result)
return result;
result = _cache_mngt_lock_sync(cache); result = _cache_mngt_lock_sync(cache);
if (result) {
ocf_mngt_cache_put(cache);
return result;
}
if (core_id != OCF_CORE_ID_INVALID) {
result = ocf_core_get(cache, core_id, &core);
if (result) if (result)
goto out; return result;
if (core)
result = ocf_mngt_core_set_seq_cutoff_policy(core, policy); result = ocf_mngt_core_set_seq_cutoff_policy(core, policy);
} else { else
result = ocf_mngt_core_set_seq_cutoff_policy_all(cache, policy); result = ocf_mngt_core_set_seq_cutoff_policy_all(cache, policy);
}
if (result) if (result)
goto out; goto out;
@ -1431,106 +1481,71 @@ int cache_mngt_set_seq_cutoff_policy(ocf_cache_id_t id, ocf_core_id_t core_id,
out: out:
ocf_mngt_cache_unlock(cache); ocf_mngt_cache_unlock(cache);
ocf_mngt_cache_put(cache);
return result; return result;
} }
/** /**
* @brief routine implementing dynamic sequential cutoff parameter switching * @brief Get sequential cutoff threshold value
* @param[in] cache_id cache id to which the change pertains * @param[in] core OCF core
* @param[in] core_id core id to which the change pertains * @param[out] thresh sequential cutoff threshold value
* or OCF_CORE_ID_INVALID for setting value for all cores
* attached to specified cache
* @param[out] thresh new sequential cutoff threshold value
* @return exit code of successful completion is 0; * @return exit code of successful completion is 0;
* nonzero exit code means failure * nonzero exit code means failure
*/ */
int cache_mngt_get_seq_cutoff_threshold(ocf_cache_id_t cache_id, int cache_mngt_get_seq_cutoff_threshold(ocf_core_t core, uint32_t *thresh)
ocf_core_id_t core_id, uint32_t *thresh)
{ {
ocf_cache_t cache; ocf_cache_t cache = ocf_core_get_cache(core);
ocf_core_t core;
int result; int result;
result = ocf_mngt_cache_get_by_id(cas_ctx, cache_id, &cache);
if (result)
return result;
result = _cache_mngt_read_lock_sync(cache); result = _cache_mngt_read_lock_sync(cache);
if (result) {
ocf_mngt_cache_put(cache);
return result;
}
result = ocf_core_get(cache, core_id, &core);
if (result) if (result)
goto out; return result;
result = ocf_mngt_core_get_seq_cutoff_threshold(core, thresh); result = ocf_mngt_core_get_seq_cutoff_threshold(core, thresh);
out:
ocf_mngt_cache_read_unlock(cache); ocf_mngt_cache_read_unlock(cache);
ocf_mngt_cache_put(cache);
return result; return result;
} }
/** /**
* @brief routine implementing dynamic sequential cutoff parameter switching * @brief Get sequential cutoff policy
* @param[in] id cache id to which the change pertains * @param[in] core OCF core
* @param[in] core_id core id to which the change pertains * @param[out] thresh sequential cutoff policy
* or OCF_CORE_ID_INVALID for setting value for all cores
* attached to specified cache
* @param[out] policy new sequential cutoff policy value
* @return exit code of successful completion is 0; * @return exit code of successful completion is 0;
* nonzero exit code means failure * nonzero exit code means failure
*/ */
int cache_mngt_get_seq_cutoff_policy(ocf_cache_id_t id, ocf_core_id_t core_id, int cache_mngt_get_seq_cutoff_policy(ocf_core_t core,
ocf_seq_cutoff_policy *policy) ocf_seq_cutoff_policy *policy)
{ {
ocf_cache_t cache; ocf_cache_t cache = ocf_core_get_cache(core);
ocf_core_t core;
int result; int result;
result = ocf_mngt_cache_get_by_id(cas_ctx, id, &cache);
if (result)
return result;
result = _cache_mngt_read_lock_sync(cache); result = _cache_mngt_read_lock_sync(cache);
if (result) {
ocf_mngt_cache_put(cache);
return result;
}
result = ocf_core_get(cache, core_id, &core);
if (result) if (result)
goto out; return result;
result = ocf_mngt_core_get_seq_cutoff_policy(core, policy); result = ocf_mngt_core_get_seq_cutoff_policy(core, policy);
out:
ocf_mngt_cache_read_unlock(cache); ocf_mngt_cache_read_unlock(cache);
ocf_mngt_cache_put(cache);
return result; return result;
} }
/** /**
* @brief routine implementing dynamic cache mode switching * @brief routine implementing dynamic cache mode switching
* @param device caching device to which operation applies * @param cache_name name of cache to which operation applies
* @param mode target mode (WRITE_THROUGH, WRITE_BACK, WRITE_AROUND etc.) * @param mode target mode (WRITE_THROUGH, WRITE_BACK, WRITE_AROUND etc.)
* @param flush shall we flush dirty data during switch, or shall we flush * @param flush shall we flush dirty data during switch, or shall we flush
* all remaining dirty data before entering new mode? * all remaining dirty data before entering new mode?
*/ */
int cache_mngt_set_cache_mode(const char *cache_name, ocf_cache_mode_t mode,
int cache_mngt_set_cache_mode(ocf_cache_id_t id, ocf_cache_mode_t mode,
uint8_t flush) uint8_t flush)
{ {
ocf_cache_mode_t old_mode; ocf_cache_mode_t old_mode;
ocf_cache_t cache; ocf_cache_t cache;
int result; int result;
result = ocf_mngt_cache_get_by_id(cas_ctx, id, &cache); result = ocf_mngt_cache_get_by_name(cas_ctx, cache_name, &cache);
if (result) if (result)
return result; return result;
@ -1566,19 +1581,19 @@ out:
/** /**
* @brief routine implements --stop-cache command. * @brief routine implements --stop-cache command.
* @param[in] cache_id caching device id to be removed * @param[in] cache_name caching device name to be removed
* @param[in] flush Boolean: shall we flush dirty data before removing cache. * @param[in] flush Boolean: shall we flush dirty data before removing cache.
* if yes, flushing may still be interrupted by user (in which case * if yes, flushing may still be interrupted by user (in which case
* device won't be actually removed and error will be returned) * device won't be actually removed and error will be returned)
*/ */
int cache_mngt_exit_instance(ocf_cache_id_t id, int flush) int cache_mngt_exit_instance(const char *cache_name, int flush)
{ {
ocf_cache_t cache; ocf_cache_t cache;
struct cache_priv *cache_priv; struct cache_priv *cache_priv;
int status, flush_status = 0; int status, flush_status = 0;
/* Get cache */ /* Get cache */
status = ocf_mngt_cache_get_by_id(cas_ctx, id, &cache); status = ocf_mngt_cache_get_by_name(cas_ctx, cache_name, &cache);
if (status) if (status)
return status; return status;
@ -1685,8 +1700,10 @@ put:
static int cache_mngt_list_caches_visitor(ocf_cache_t cache, void *cntx) static int cache_mngt_list_caches_visitor(ocf_cache_t cache, void *cntx)
{ {
ocf_cache_id_t id = ocf_cache_get_id(cache);
struct kcas_cache_list *list = cntx; struct kcas_cache_list *list = cntx;
uint16_t id;
BUG_ON(cache_id_from_name(&id, ocf_cache_get_name(cache)));
if (list->id_position >= id) if (list->id_position >= id)
return 0; return 0;
@ -1706,13 +1723,13 @@ int cache_mngt_list_caches(struct kcas_cache_list *list)
return ocf_mngt_cache_visit(cas_ctx, cache_mngt_list_caches_visitor, list); return ocf_mngt_cache_visit(cas_ctx, cache_mngt_list_caches_visitor, list);
} }
int cache_mngt_interrupt_flushing(ocf_cache_id_t id) int cache_mngt_interrupt_flushing(const char *cache_name)
{ {
ocf_cache_t cache; ocf_cache_t cache;
struct cache_priv *cache_priv; struct cache_priv *cache_priv;
int result; int result;
result = ocf_mngt_cache_get_by_id(cas_ctx, id, &cache); result = ocf_mngt_cache_get_by_name(cas_ctx, cache_name, &cache);
if (result) if (result)
return result; return result;
@ -1735,7 +1752,7 @@ int cache_mngt_get_info(struct kcas_cache_info *info)
ocf_core_t core; ocf_core_t core;
const struct ocf_volume_uuid *uuid; const struct ocf_volume_uuid *uuid;
result = ocf_mngt_cache_get_by_id(cas_ctx, info->cache_id, &cache); result = mngt_get_cache_by_id(cas_ctx, info->cache_id, &cache);
if (result) if (result)
return result; return result;
@ -1769,7 +1786,7 @@ int cache_mngt_get_info(struct kcas_cache_info *info)
/* Collect cores IDs */ /* Collect cores IDs */
for (i = 0, j = 0; j < info->info.core_count && for (i = 0, j = 0; j < info->info.core_count &&
i < OCF_CORE_MAX; i++) { i < OCF_CORE_MAX; i++) {
if (ocf_core_get(cache, i, &core)) if (get_core_by_id(cache, i, &core))
continue; continue;
info->core_id[j] = i; info->core_id[j] = i;
@ -1786,13 +1803,13 @@ put:
int cache_mngt_get_io_class_info(struct kcas_io_class *part) int cache_mngt_get_io_class_info(struct kcas_io_class *part)
{ {
int result; int result;
ocf_cache_id_t cache_id = part->cache_id; uint16_t cache_id = part->cache_id;
ocf_core_id_t core_id = part->core_id; uint16_t core_id = part->core_id;
uint32_t io_class_id = part->class_id; uint32_t io_class_id = part->class_id;
ocf_cache_t cache; ocf_cache_t cache;
ocf_core_t core; ocf_core_t core;
result = ocf_mngt_cache_get_by_id(cas_ctx, cache_id, &cache); result = mngt_get_cache_by_id(cas_ctx, cache_id, &cache);
if (result) if (result)
return result; return result;
@ -1807,7 +1824,7 @@ int cache_mngt_get_io_class_info(struct kcas_io_class *part)
goto end; goto end;
if (part->get_stats) { if (part->get_stats) {
result = ocf_core_get(cache, core_id, &core); result = get_core_by_id(cache, core_id, &core);
if (result < 0) { if (result < 0) {
result = OCF_ERR_CORE_NOT_AVAIL; result = OCF_ERR_CORE_NOT_AVAIL;
goto end; goto end;
@ -1830,7 +1847,7 @@ int cache_mngt_get_core_info(struct kcas_core_info *info)
const struct ocf_volume_uuid *uuid; const struct ocf_volume_uuid *uuid;
int result; int result;
result = ocf_mngt_cache_get_by_id(cas_ctx, info->cache_id, &cache); result = mngt_get_cache_by_id(cas_ctx, info->cache_id, &cache);
if (result) if (result)
return result; return result;
@ -1838,7 +1855,7 @@ int cache_mngt_get_core_info(struct kcas_core_info *info)
if(result) if(result)
goto put; goto put;
result = ocf_core_get(cache, info->core_id, &core); result = get_core_by_id(cache, info->core_id, &core);
if (result < 0) { if (result < 0) {
result = OCF_ERR_CORE_NOT_AVAIL; result = OCF_ERR_CORE_NOT_AVAIL;
goto unlock; goto unlock;
@ -1882,102 +1899,172 @@ void cache_mngt_wait_for_rq_finish(ocf_cache_t cache)
int cache_mngt_set_core_params(struct kcas_set_core_param *info) int cache_mngt_set_core_params(struct kcas_set_core_param *info)
{ {
ocf_cache_t cache;
ocf_core_t core;
int result;
result = mngt_get_cache_by_id(cas_ctx, info->cache_id, &cache);
if (result)
return result;
result = get_core_by_id(cache, info->core_id, &core);
if (result)
goto out;
switch (info->param_id) { switch (info->param_id) {
case core_param_seq_cutoff_threshold: case core_param_seq_cutoff_threshold:
return cache_mngt_set_seq_cutoff_threshold(info->cache_id, result = cache_mngt_set_seq_cutoff_threshold(cache, core,
info->core_id, info->param_value); info->param_value);
break;
case core_param_seq_cutoff_policy: case core_param_seq_cutoff_policy:
return cache_mngt_set_seq_cutoff_policy(info->cache_id, result = cache_mngt_set_seq_cutoff_policy(cache, core,
info->core_id, info->param_value); info->param_value);
break;
default: default:
return -EINVAL; result = -EINVAL;
} }
out:
ocf_mngt_cache_put(cache);
return result;
} }
int cache_mngt_get_core_params(struct kcas_get_core_param *info) int cache_mngt_get_core_params(struct kcas_get_core_param *info)
{ {
ocf_cache_t cache;
ocf_core_t core;
int result;
result = mngt_get_cache_by_id(cas_ctx, info->cache_id, &cache);
if (result)
return result;
result = get_core_by_id(cache, info->core_id, &core);
if (result)
goto out;
switch (info->param_id) { switch (info->param_id) {
case core_param_seq_cutoff_threshold: case core_param_seq_cutoff_threshold:
return cache_mngt_get_seq_cutoff_threshold(info->cache_id, result = cache_mngt_get_seq_cutoff_threshold(core,
info->core_id, &info->param_value); &info->param_value);
break;
case core_param_seq_cutoff_policy: case core_param_seq_cutoff_policy:
return cache_mngt_get_seq_cutoff_policy(info->cache_id, result = cache_mngt_get_seq_cutoff_policy(core,
info->core_id, &info->param_value); &info->param_value);
break;
default: default:
return -EINVAL; result = -EINVAL;
} }
out:
ocf_mngt_cache_put(cache);
return result;
} }
int cache_mngt_set_cache_params(struct kcas_set_cache_param *info) int cache_mngt_set_cache_params(struct kcas_set_cache_param *info)
{ {
ocf_cache_t cache;
int result;
result = mngt_get_cache_by_id(cas_ctx, info->cache_id, &cache);
if (result)
return result;
switch (info->param_id) { switch (info->param_id) {
case cache_param_cleaning_policy_type: case cache_param_cleaning_policy_type:
return cache_mngt_set_cleaning_policy(info->cache_id, result = cache_mngt_set_cleaning_policy(cache,
info->param_value); info->param_value);
break;
case cache_param_cleaning_alru_wake_up_time: case cache_param_cleaning_alru_wake_up_time:
return cache_mngt_set_cleaning_param(info->cache_id, result = cache_mngt_set_cleaning_param(cache,
ocf_cleaning_alru, ocf_alru_wake_up_time, ocf_cleaning_alru, ocf_alru_wake_up_time,
info->param_value); info->param_value);
break;
case cache_param_cleaning_alru_stale_buffer_time: case cache_param_cleaning_alru_stale_buffer_time:
return cache_mngt_set_cleaning_param(info->cache_id, result = cache_mngt_set_cleaning_param(cache,
ocf_cleaning_alru, ocf_alru_stale_buffer_time, ocf_cleaning_alru, ocf_alru_stale_buffer_time,
info->param_value); info->param_value);
break;
case cache_param_cleaning_alru_flush_max_buffers: case cache_param_cleaning_alru_flush_max_buffers:
return cache_mngt_set_cleaning_param(info->cache_id, result = cache_mngt_set_cleaning_param(cache,
ocf_cleaning_alru, ocf_alru_flush_max_buffers, ocf_cleaning_alru, ocf_alru_flush_max_buffers,
info->param_value); info->param_value);
break;
case cache_param_cleaning_alru_activity_threshold: case cache_param_cleaning_alru_activity_threshold:
return cache_mngt_set_cleaning_param(info->cache_id, result = cache_mngt_set_cleaning_param(cache,
ocf_cleaning_alru, ocf_alru_activity_threshold, ocf_cleaning_alru, ocf_alru_activity_threshold,
info->param_value); info->param_value);
break;
case cache_param_cleaning_acp_wake_up_time: case cache_param_cleaning_acp_wake_up_time:
return cache_mngt_set_cleaning_param(info->cache_id, result = cache_mngt_set_cleaning_param(cache,
ocf_cleaning_acp, ocf_acp_wake_up_time, ocf_cleaning_acp, ocf_acp_wake_up_time,
info->param_value); info->param_value);
break;
case cache_param_cleaning_acp_flush_max_buffers: case cache_param_cleaning_acp_flush_max_buffers:
return cache_mngt_set_cleaning_param(info->cache_id, result = cache_mngt_set_cleaning_param(cache,
ocf_cleaning_acp, ocf_acp_flush_max_buffers, ocf_cleaning_acp, ocf_acp_flush_max_buffers,
info->param_value); info->param_value);
break;
default: default:
return -EINVAL; result = -EINVAL;
} }
ocf_mngt_cache_put(cache);
return result;
} }
int cache_mngt_get_cache_params(struct kcas_get_cache_param *info) int cache_mngt_get_cache_params(struct kcas_get_cache_param *info)
{ {
ocf_cache_t cache;
int result;
result = mngt_get_cache_by_id(cas_ctx, info->cache_id, &cache);
if (result)
return result;
switch (info->param_id) { switch (info->param_id) {
case cache_param_cleaning_policy_type: case cache_param_cleaning_policy_type:
return cache_mngt_get_cleaning_policy(info->cache_id, result = cache_mngt_get_cleaning_policy(cache,
&info->param_value); &info->param_value);
break;
case cache_param_cleaning_alru_wake_up_time: case cache_param_cleaning_alru_wake_up_time:
return cache_mngt_get_cleaning_param(info->cache_id, result = cache_mngt_get_cleaning_param(cache,
ocf_cleaning_alru, ocf_alru_wake_up_time, ocf_cleaning_alru, ocf_alru_wake_up_time,
&info->param_value); &info->param_value);
break;
case cache_param_cleaning_alru_stale_buffer_time: case cache_param_cleaning_alru_stale_buffer_time:
return cache_mngt_get_cleaning_param(info->cache_id, result = cache_mngt_get_cleaning_param(cache,
ocf_cleaning_alru, ocf_alru_stale_buffer_time, ocf_cleaning_alru, ocf_alru_stale_buffer_time,
&info->param_value); &info->param_value);
break;
case cache_param_cleaning_alru_flush_max_buffers: case cache_param_cleaning_alru_flush_max_buffers:
return cache_mngt_get_cleaning_param(info->cache_id, result = cache_mngt_get_cleaning_param(cache,
ocf_cleaning_alru, ocf_alru_flush_max_buffers, ocf_cleaning_alru, ocf_alru_flush_max_buffers,
&info->param_value); &info->param_value);
break;
case cache_param_cleaning_alru_activity_threshold: case cache_param_cleaning_alru_activity_threshold:
return cache_mngt_get_cleaning_param(info->cache_id, result = cache_mngt_get_cleaning_param(cache,
ocf_cleaning_alru, ocf_alru_activity_threshold, ocf_cleaning_alru, ocf_alru_activity_threshold,
&info->param_value); &info->param_value);
break;
case cache_param_cleaning_acp_wake_up_time: case cache_param_cleaning_acp_wake_up_time:
return cache_mngt_get_cleaning_param(info->cache_id, result = cache_mngt_get_cleaning_param(cache,
ocf_cleaning_acp, ocf_acp_wake_up_time, ocf_cleaning_acp, ocf_acp_wake_up_time,
&info->param_value); &info->param_value);
break;
case cache_param_cleaning_acp_flush_max_buffers: case cache_param_cleaning_acp_flush_max_buffers:
return cache_mngt_get_cleaning_param(info->cache_id, result = cache_mngt_get_cleaning_param(cache,
ocf_cleaning_acp, ocf_acp_flush_max_buffers, ocf_cleaning_acp, ocf_acp_flush_max_buffers,
&info->param_value); &info->param_value);
break;
default: default:
return -EINVAL; result = -EINVAL;
} }
ocf_mngt_cache_put(cache);
return result;
} }

View File

@ -10,27 +10,28 @@
struct atomic_dev_params; struct atomic_dev_params;
int cache_mngt_set_cleaning_policy(ocf_cache_id_t cache_id, uint32_t type); int cache_mngt_set_cleaning_policy(ocf_cache_t cache, uint32_t type);
int cache_mngt_get_cleaning_policy(ocf_cache_id_t cache_id, uint32_t *type); int cache_mngt_get_cleaning_policy(ocf_cache_t cache, uint32_t *type);
int cache_mngt_set_cleaning_param(ocf_cache_id_t cache_id, ocf_cleaning_t type, int cache_mngt_set_cleaning_param(ocf_cache_t cache, ocf_cleaning_t type,
uint32_t param_id, uint32_t param_value); uint32_t param_id, uint32_t param_value);
int cache_mngt_get_cleaning_param(ocf_cache_id_t cache_id, ocf_cleaning_t type, int cache_mngt_get_cleaning_param(ocf_cache_t cache, ocf_cleaning_t type,
uint32_t param_id, uint32_t *param_value); uint32_t param_id, uint32_t *param_value);
int cache_mngt_add_core_to_cache(struct ocf_mngt_core_config *cfg, int cache_mngt_add_core_to_cache(const char *cache_name,
ocf_cache_id_t cache_id, struct kcas_insert_core *cmd_info); struct ocf_mngt_core_config *cfg,
struct kcas_insert_core *cmd_info);
int cache_mngt_remove_core_from_cache(struct kcas_remove_core *cmd); int cache_mngt_remove_core_from_cache(struct kcas_remove_core *cmd);
int cache_mngt_reset_stats(ocf_cache_id_t cache_id, int cache_mngt_reset_stats(const char *cache_name, const char *core_name);
ocf_core_id_t core_id);
int cache_mngt_set_partitions(struct kcas_io_classes *cfg); int cache_mngt_set_partitions(const char *cache_name,
struct kcas_io_classes *cfg);
int cache_mngt_exit_instance(ocf_cache_id_t id, int flush); int cache_mngt_exit_instance(const char *cache_name, int flush);
int cache_mngt_prepare_cache_cfg(struct ocf_mngt_cache_config *cfg, int cache_mngt_prepare_cache_cfg(struct ocf_mngt_cache_config *cfg,
struct ocf_mngt_cache_device_config *device_cfg, struct ocf_mngt_cache_device_config *device_cfg,
@ -50,31 +51,27 @@ int cache_mngt_init_instance(struct ocf_mngt_cache_config *cfg,
struct ocf_mngt_cache_device_config *device_cfg, struct ocf_mngt_cache_device_config *device_cfg,
struct kcas_start_cache *cmd); struct kcas_start_cache *cmd);
int cache_mngt_set_seq_cutoff_threshold(ocf_cache_id_t id, ocf_core_id_t core_id, int cache_mngt_set_seq_cutoff_threshold(ocf_cache_t cache, ocf_core_t core,
uint32_t thresh); uint32_t thresh);
int cache_mngt_set_seq_cutoff_policy(ocf_cache_id_t id, ocf_core_id_t core_id, int cache_mngt_set_seq_cutoff_policy(ocf_cache_t cache, ocf_core_t core,
ocf_seq_cutoff_policy policy); ocf_seq_cutoff_policy policy);
int cache_mngt_get_seq_cutoff_threshold(ocf_cache_id_t id, ocf_core_id_t core_id, int cache_mngt_get_seq_cutoff_threshold(ocf_core_t core, uint32_t *thresh);
uint32_t *thresh);
int cache_mngt_get_seq_cutoff_policy(ocf_cache_id_t id, ocf_core_id_t core_id, int cache_mngt_get_seq_cutoff_policy(ocf_core_t core,
ocf_seq_cutoff_policy *policy); ocf_seq_cutoff_policy *policy);
int cache_mngt_set_cache_mode(ocf_cache_id_t id, ocf_cache_mode_t mode, int cache_mngt_set_cache_mode(const char *cache_name, ocf_cache_mode_t mode,
uint8_t flush); uint8_t flush);
int cache_mngt_flush_object(ocf_cache_id_t cache_id, ocf_core_id_t core_id); int cache_mngt_flush_object(const char *cache_name, const char *core_name);
int cache_mngt_flush_device(ocf_cache_id_t id); int cache_mngt_flush_device(const char *cache_name);
ocf_cache_line_t cache_mngt_lookup(ocf_cache_t cache,
ocf_core_id_t core_id, uint64_t core_cacheline);
int cache_mngt_list_caches(struct kcas_cache_list *list); int cache_mngt_list_caches(struct kcas_cache_list *list);
int cache_mngt_interrupt_flushing(ocf_cache_id_t id); int cache_mngt_interrupt_flushing(const char *cache_name);
int cache_mngt_get_info(struct kcas_cache_info *info); int cache_mngt_get_info(struct kcas_cache_info *info);

View File

@ -52,7 +52,7 @@ bool cas_upgrade_is_in_upgrade(void)
* +------------+-------------------------------+---------------+ * +------------+-------------------------------+---------------+
* |Group | Key | Type | * |Group | Key | Type |
* |------------|-------------------------------|---------------| * |------------|-------------------------------|---------------|
* |cache | cache_id | uint | * |cache | cache_name | string |
* |cache | cache_path | string | * |cache | cache_path | string |
* |cache | cache_type | uint | * |cache | cache_type | uint |
* |cache | cache_line_size | uint | * |cache | cache_line_size | uint |
@ -62,7 +62,7 @@ bool cas_upgrade_is_in_upgrade(void)
* |cache | cache_seq_cutoff_policy | uint | * |cache | cache_seq_cutoff_policy | uint |
* |------------|-------------------------------|---------------| * |------------|-------------------------------|---------------|
* |core | core_no | uint | * |core | core_no | uint |
* |core | core_X_id | uint | * |core | core_X_name | string |
* |core | core_X_path | string | * |core | core_X_path | string |
* |core | core_X_type | uint | * |core | core_X_type | uint |
* |------------|-------------------------------|---------------| * |------------|-------------------------------|---------------|
@ -87,14 +87,14 @@ bool cas_upgrade_is_in_upgrade(void)
#define UPGRADE_IFACE_VERSION_STR "upgrade_iface_version" #define UPGRADE_IFACE_VERSION_STR "upgrade_iface_version"
#define CACHE_ID_STR "cache_id" #define CACHE_NAME_STR "cache_name"
#define CACHE_PATH_STR "cache_path" #define CACHE_PATH_STR "cache_path"
#define CACHE_LINE_SIZE_STR "cache_line_size" #define CACHE_LINE_SIZE_STR "cache_line_size"
#define CACHE_TYPE_STR "cache_type" #define CACHE_TYPE_STR "cache_type"
#define CACHE_MODE_STR "cache_mode" #define CACHE_MODE_STR "cache_mode"
#define CORE_NO_STR "core_no" #define CORE_NO_STR "core_no"
#define CORE_ID_STR "core_%lu_id" #define CORE_NAME_STR "core_%lu_name"
#define CORE_PATH_STR "core_%lu_path" #define CORE_PATH_STR "core_%lu_path"
#define CORE_SEQ_CUTOFF_THRESHOLD_STR "core_%lu_seq_cutoff_thresh" #define CORE_SEQ_CUTOFF_THRESHOLD_STR "core_%lu_seq_cutoff_thresh"
#define CORE_SEQ_CUTOFF_POLICY_STR "core_%lu_seq_cutoff_policy" #define CORE_SEQ_CUTOFF_POLICY_STR "core_%lu_seq_cutoff_policy"
@ -134,12 +134,12 @@ static int _cas_upgrade_dump_cache_conf_main(ocf_cache_t cache,
return result; return result;
} }
result = cas_properties_add_uint(cache_props, CACHE_ID_STR, result = cas_properties_add_string(cache_props, CACHE_NAME_STR,
(uint64_t) ocf_cache_get_id(cache), ocf_cache_get_name(cache),
CAS_PROPERTIES_CONST); CAS_PROPERTIES_CONST);
if (result) { if (result) {
printk(KERN_ERR OCF_PREFIX_SHORT printk(KERN_ERR OCF_PREFIX_SHORT
"Error during adding cache_id\n"); "Error during adding cache_name\n");
return result; return result;
} }
@ -192,7 +192,6 @@ int _cas_upgrade_core_visitor(ocf_core_t core, void *cntx)
{ {
int result = 0; int result = 0;
char *value = NULL; char *value = NULL;
uint32_t core_idx = ocf_core_get_id(core);
struct _ocf_core_visitor_ctx *core_visitor_ctx = struct _ocf_core_visitor_ctx *core_visitor_ctx =
(struct _ocf_core_visitor_ctx*) cntx; (struct _ocf_core_visitor_ctx*) cntx;
struct cas_properties *cache_props = core_visitor_ctx->cache_props; struct cas_properties *cache_props = core_visitor_ctx->cache_props;
@ -207,12 +206,12 @@ int _cas_upgrade_core_visitor(ocf_core_t core, void *cntx)
return result; return result;
} }
result = snprintf(value, MAX_STR_LEN, CORE_ID_STR, core_no); result = snprintf(value, MAX_STR_LEN, CORE_NAME_STR, core_no);
if (result < 0) if (result < 0)
goto err; goto err;
result = cas_properties_add_uint(cache_props, value, core_idx, result = cas_properties_add_string(cache_props, value,
CAS_PROPERTIES_CONST); ocf_core_get_name(core), CAS_PROPERTIES_CONST);
if (result) { if (result) {
printk(KERN_ERR OCF_PREFIX_SHORT OCF_PREFIX_SHORT printk(KERN_ERR OCF_PREFIX_SHORT OCF_PREFIX_SHORT
"Error during adding core id\n"); "Error during adding core id\n");
@ -309,7 +308,6 @@ err:
static int _cas_upgrade_dump_cache_conf_flush(ocf_cache_t cache, static int _cas_upgrade_dump_cache_conf_flush(ocf_cache_t cache,
struct cas_properties *cache_props) struct cas_properties *cache_props)
{ {
ocf_cache_id_t cache_id = ocf_cache_get_id(cache);
uint32_t cleaning_type; uint32_t cleaning_type;
uint32_t alru_thread_wakeup_time; uint32_t alru_thread_wakeup_time;
uint32_t alru_stale_buffer_time; uint32_t alru_stale_buffer_time;
@ -321,18 +319,18 @@ static int _cas_upgrade_dump_cache_conf_flush(ocf_cache_t cache,
CAS_DEBUG_TRACE(); CAS_DEBUG_TRACE();
result |= cache_mngt_get_cleaning_policy(cache_id, &cleaning_type); result |= cache_mngt_get_cleaning_policy(cache, &cleaning_type);
result |= cache_mngt_get_cleaning_param(cache_id, ocf_cleaning_alru, result |= cache_mngt_get_cleaning_param(cache, ocf_cleaning_alru,
ocf_alru_wake_up_time, &alru_thread_wakeup_time); ocf_alru_wake_up_time, &alru_thread_wakeup_time);
result |= cache_mngt_get_cleaning_param(cache_id, ocf_cleaning_alru, result |= cache_mngt_get_cleaning_param(cache, ocf_cleaning_alru,
ocf_alru_stale_buffer_time, &alru_stale_buffer_time); ocf_alru_stale_buffer_time, &alru_stale_buffer_time);
result |= cache_mngt_get_cleaning_param(cache_id, ocf_cleaning_alru, result |= cache_mngt_get_cleaning_param(cache, ocf_cleaning_alru,
ocf_alru_flush_max_buffers, &alru_flush_max_buffers); ocf_alru_flush_max_buffers, &alru_flush_max_buffers);
result |= cache_mngt_get_cleaning_param(cache_id, ocf_cleaning_alru, result |= cache_mngt_get_cleaning_param(cache, ocf_cleaning_alru,
ocf_alru_activity_threshold, &alru_activity_threshold); ocf_alru_activity_threshold, &alru_activity_threshold);
result |= cache_mngt_get_cleaning_param(cache_id, ocf_cleaning_acp, result |= cache_mngt_get_cleaning_param(cache, ocf_cleaning_acp,
ocf_acp_wake_up_time, &acp_thread_wakeup_time); ocf_acp_wake_up_time, &acp_thread_wakeup_time);
result |= cache_mngt_get_cleaning_param(cache_id, ocf_cleaning_acp, result |= cache_mngt_get_cleaning_param(cache, ocf_cleaning_acp,
ocf_acp_flush_max_buffers, &acp_flush_max_buffers); ocf_acp_flush_max_buffers, &acp_flush_max_buffers);
if (result) { if (result) {
printk(KERN_ERR OCF_PREFIX_SHORT printk(KERN_ERR OCF_PREFIX_SHORT
@ -747,13 +745,14 @@ int cas_upgrade_set_pt_and_flush_visitor_core(ocf_core_t core, void *cntx)
int _cas_upgrade_set_pt_and_flush_visitor_cache(ocf_cache_t cache, void *cntx) int _cas_upgrade_set_pt_and_flush_visitor_cache(ocf_cache_t cache, void *cntx)
{ {
int *result = (int*) cntx; int *result = (int*) cntx;
int cache_id = ocf_cache_get_id(cache); const char *cache_name = ocf_cache_get_name(cache);
*result = cache_mngt_set_cache_mode(cache_id, ocf_cache_mode_pt, false); *result = cache_mngt_set_cache_mode(cache_name,
ocf_cache_mode_pt, false);
if (*result) if (*result)
return *result; return *result;
*result = cache_mngt_flush_device(cache_id); *result = cache_mngt_flush_device(cache_name);
if (*result) if (*result)
return *result; return *result;
@ -787,7 +786,7 @@ int _cas_upgrade_stop_devices_visitor_exit(ocf_cache_t cache, void *cntx)
{ {
int *result = (int*) cntx; int *result = (int*) cntx;
*result = cache_mngt_exit_instance(ocf_cache_get_id(cache), true); *result = cache_mngt_exit_instance(ocf_cache_get_name(cache), true);
return *result; return *result;
} }
@ -811,7 +810,7 @@ static int _cas_upgrade_stop_devices(void)
} }
static int _cas_upgrade_restore_conf_main(struct cas_properties *cache_props, static int _cas_upgrade_restore_conf_main(struct cas_properties *cache_props,
uint64_t *cache_id) char *cache_name)
{ {
int result = 0; int result = 0;
uint64_t cache_mode, cache_line_size; uint64_t cache_mode, cache_line_size;
@ -834,7 +833,8 @@ static int _cas_upgrade_restore_conf_main(struct cas_properties *cache_props,
if (result) if (result)
goto error; goto error;
result = cas_properties_get_uint(cache_props, CACHE_ID_STR, cache_id); result = cas_properties_get_string(cache_props, CACHE_NAME_STR,
cache_name, OCF_CACHE_NAME_SIZE);
if (result) if (result)
goto error; goto error;
@ -861,7 +861,7 @@ static int _cas_upgrade_restore_conf_main(struct cas_properties *cache_props,
if (cache_mode >= ocf_cache_mode_max) if (cache_mode >= ocf_cache_mode_max)
cache_mode = ocf_cache_mode_default; cache_mode = ocf_cache_mode_default;
cfg.id = *cache_id; cfg.name = cache_name;
cfg.cache_mode = cache_mode; cfg.cache_mode = cache_mode;
/* cfg.eviction_policy = TODO */ /* cfg.eviction_policy = TODO */
cfg.cache_line_size = cache_line_size; cfg.cache_line_size = cache_line_size;
@ -905,8 +905,8 @@ static int _cas_upgrade_restore_conf_core(struct cas_properties *cache_props,
{ {
int result = 0; int result = 0;
unsigned long i = 0; unsigned long i = 0;
uint64_t core_id, core_no, version; uint64_t core_no, version;
ocf_core_id_t core_id_int; char core_name[OCF_CORE_NAME_SIZE];
char *core_path = NULL; char *core_path = NULL;
char *key = NULL; char *key = NULL;
@ -946,24 +946,23 @@ static int _cas_upgrade_restore_conf_core(struct cas_properties *cache_props,
if (result) if (result)
goto error; goto error;
result = snprintf(key, MAX_STR_LEN, CORE_ID_STR, i); result = snprintf(key, MAX_STR_LEN, CORE_NAME_STR, i);
if (result < 0) if (result < 0)
goto error; goto error;
result = cas_properties_get_uint(cache_props, key, &core_id); result = cas_properties_get_string(cache_props, key,
core_name, OCF_CORE_NAME_SIZE);
if (result) if (result)
goto error; goto error;
core_id_int = core_id; cfg.name = core_name;
cfg.try_add = 0; cfg.try_add = 0;
cfg.volume_type = BLOCK_DEVICE_VOLUME; cfg.volume_type = BLOCK_DEVICE_VOLUME;
cfg.core_id = core_id_int;
cfg.uuid.data = core_path; cfg.uuid.data = core_path;
cfg.uuid.size = strnlen(core_path, MAX_STR_LEN) + 1; cfg.uuid.size = strnlen(core_path, MAX_STR_LEN) + 1;
result = cache_mngt_add_core_to_cache(&cfg, result = cache_mngt_add_core_to_cache(ocf_cache_get_name(cache),
ocf_cache_get_id(cache), NULL); &cfg, NULL);
if (result) if (result)
goto error; goto error;
} }
@ -977,7 +976,6 @@ error:
static int _cas_upgrade_restore_conf_flush(struct cas_properties *cache_props, static int _cas_upgrade_restore_conf_flush(struct cas_properties *cache_props,
ocf_cache_t cache) ocf_cache_t cache)
{ {
ocf_cache_id_t cache_id = ocf_cache_get_id(cache);
uint64_t cleaning_type; uint64_t cleaning_type;
uint64_t alru_thread_wakeup_time = OCF_ALRU_DEFAULT_WAKE_UP; uint64_t alru_thread_wakeup_time = OCF_ALRU_DEFAULT_WAKE_UP;
uint64_t alru_stale_buffer_time = OCF_ALRU_DEFAULT_STALENESS_TIME; uint64_t alru_stale_buffer_time = OCF_ALRU_DEFAULT_STALENESS_TIME;
@ -1063,18 +1061,18 @@ static int _cas_upgrade_restore_conf_flush(struct cas_properties *cache_props,
if (result) if (result)
return result; return result;
result |= cache_mngt_set_cleaning_policy(cache_id, cleaning_type); result |= cache_mngt_set_cleaning_policy(cache, cleaning_type);
result |= cache_mngt_set_cleaning_param(cache_id, ocf_cleaning_alru, result |= cache_mngt_set_cleaning_param(cache, ocf_cleaning_alru,
ocf_alru_wake_up_time, alru_thread_wakeup_time); ocf_alru_wake_up_time, alru_thread_wakeup_time);
result |= cache_mngt_set_cleaning_param(cache_id, ocf_cleaning_alru, result |= cache_mngt_set_cleaning_param(cache, ocf_cleaning_alru,
ocf_alru_stale_buffer_time, alru_stale_buffer_time); ocf_alru_stale_buffer_time, alru_stale_buffer_time);
result |= cache_mngt_set_cleaning_param(cache_id, ocf_cleaning_alru, result |= cache_mngt_set_cleaning_param(cache, ocf_cleaning_alru,
ocf_alru_flush_max_buffers, alru_flush_max_buffers); ocf_alru_flush_max_buffers, alru_flush_max_buffers);
result |= cache_mngt_set_cleaning_param(cache_id, ocf_cleaning_alru, result |= cache_mngt_set_cleaning_param(cache, ocf_cleaning_alru,
ocf_alru_activity_threshold, alru_activity_threshold); ocf_alru_activity_threshold, alru_activity_threshold);
result |= cache_mngt_set_cleaning_param(cache_id, ocf_cleaning_acp, result |= cache_mngt_set_cleaning_param(cache, ocf_cleaning_acp,
ocf_acp_wake_up_time, acp_thread_wakeup_time); ocf_acp_wake_up_time, acp_thread_wakeup_time);
result |= cache_mngt_set_cleaning_param(cache_id, ocf_cleaning_acp, result |= cache_mngt_set_cleaning_param(cache, ocf_cleaning_acp,
ocf_acp_flush_max_buffers, acp_flush_max_buffers); ocf_acp_flush_max_buffers, acp_flush_max_buffers);
return result; return result;
@ -1113,8 +1111,6 @@ static int _cas_upgrade_restore_conf_io_class(
return result; return result;
} }
cfg->cache_id = ocf_cache_get_id(cache);
result = cas_properties_get_uint(cache_props, IO_CLASS_NO_STR, result = cas_properties_get_uint(cache_props, IO_CLASS_NO_STR,
&io_class_no); &io_class_no);
if (result) if (result)
@ -1181,7 +1177,7 @@ static int _cas_upgrade_restore_conf_io_class(
cfg->info[part_id].min_size = (uint32_t)min_size; cfg->info[part_id].min_size = (uint32_t)min_size;
} }
result = cache_mngt_set_partitions(cfg); result = cache_mngt_set_partitions(ocf_cache_get_name(cache), cfg);
error_after_alloc_buffers: error_after_alloc_buffers:
kfree(key); kfree(key);
@ -1193,16 +1189,16 @@ error_after_alloc_buffers:
static int _cas_upgrade_restore_cache(struct cas_properties *cache_props) static int _cas_upgrade_restore_cache(struct cas_properties *cache_props)
{ {
int result = 0; int result = 0;
uint64_t cache_id; char cache_name[OCF_CACHE_NAME_SIZE];
ocf_cache_t cache; ocf_cache_t cache;
CAS_DEBUG_TRACE(); CAS_DEBUG_TRACE();
result = _cas_upgrade_restore_conf_main(cache_props, &cache_id); result = _cas_upgrade_restore_conf_main(cache_props, cache_name);
if (result) if (result)
return result; return result;
result = ocf_mngt_cache_get_by_id(cas_ctx, cache_id, &cache); result = ocf_mngt_cache_get_by_name(cas_ctx, cache_name, &cache);
if (result) if (result)
return result; return result;
@ -1237,16 +1233,18 @@ int _cas_upgrade_restore_cache_mode_visitor(ocf_core_t core, void *cntx)
static int _cas_upgrade_restore_cache_mode(struct cas_properties *cache_props) static int _cas_upgrade_restore_cache_mode(struct cas_properties *cache_props)
{ {
int result = 0; int result = 0;
uint64_t cache_id, cache_mode; uint64_t cache_mode;
char cache_name[OCF_CACHE_NAME_SIZE];
ocf_cache_t cache; ocf_cache_t cache;
CAS_DEBUG_TRACE(); CAS_DEBUG_TRACE();
result = cas_properties_get_uint(cache_props, CACHE_ID_STR, &cache_id); result = cas_properties_get_string(cache_props, CACHE_NAME_STR,
cache_name, OCF_CACHE_NAME_SIZE);
if (result) if (result)
return result; return result;
result = ocf_mngt_cache_get_by_id(cas_ctx, cache_id, &cache); result = ocf_mngt_cache_get_by_name(cas_ctx, cache_name, &cache);
if (result) if (result)
return result; return result;
@ -1256,7 +1254,7 @@ static int _cas_upgrade_restore_cache_mode(struct cas_properties *cache_props)
goto error; goto error;
if (ocf_cache_get_mode(cache) != cache_mode) { if (ocf_cache_get_mode(cache) != cache_mode) {
result = cache_mngt_set_cache_mode(ocf_cache_get_id(cache), result = cache_mngt_set_cache_mode(ocf_cache_get_name(cache),
cache_mode, false); cache_mode, false);
if (result) if (result)
goto error; goto error;
@ -1274,16 +1272,17 @@ static int _cas_upgrade_restore_cache_after_error(
struct cas_properties *cache_props) struct cas_properties *cache_props)
{ {
int result = 0; int result = 0;
uint64_t cache_id; char cache_name[OCF_CACHE_NAME_SIZE];
ocf_cache_t cache = NULL; ocf_cache_t cache = NULL;
CAS_DEBUG_TRACE(); CAS_DEBUG_TRACE();
result = cas_properties_get_uint(cache_props, CACHE_ID_STR, &cache_id); result = cas_properties_get_string(cache_props, CACHE_NAME_STR,
cache_name, OCF_CACHE_NAME_SIZE);
if (result) if (result)
return result; return result;
result = ocf_mngt_cache_get_by_id(cas_ctx, cache_id, &cache); result = ocf_mngt_cache_get_by_name(cas_ctx, cache_name, &cache);
if (result == -OCF_ERR_CACHE_NOT_EXIST) { if (result == -OCF_ERR_CACHE_NOT_EXIST) {
result = _cas_upgrade_restore_cache(cache_props); result = _cas_upgrade_restore_cache(cache_props);
} else if (result == 0) { } else if (result == 0) {
@ -1363,8 +1362,8 @@ int cas_upgrade_check_ctx_visitor(ocf_cache_t cache, void *cntx)
if (result) { if (result) {
printk(KERN_ERR OCF_PREFIX_SHORT printk(KERN_ERR OCF_PREFIX_SHORT
"Upgrade error. Cannot start upgrade in flight" "Upgrade error. Cannot start upgrade in flight"
" cache %d is in incomplete state\n", " %s is in incomplete state\n",
ocf_cache_get_id(cache)); ocf_cache_get_name(cache));
} }
return result; return result;

View File

@ -77,10 +77,13 @@ long cas_service_ioctl_ctrl(struct file *filp, unsigned int cmd,
case KCAS_IOCTL_STOP_CACHE: { case KCAS_IOCTL_STOP_CACHE: {
struct kcas_stop_cache *cmd_info; struct kcas_stop_cache *cmd_info;
char cache_name[OCF_CACHE_NAME_SIZE];
GET_CMD_INFO(cmd_info, arg); GET_CMD_INFO(cmd_info, arg);
retval = cache_mngt_exit_instance(cmd_info->cache_id, cache_name_from_id(cache_name, cmd_info->cache_id);
retval = cache_mngt_exit_instance(cache_name,
cmd_info->flush_data); cmd_info->flush_data);
RETURN_CMD_RESULT(cmd_info, arg, retval); RETURN_CMD_RESULT(cmd_info, arg, retval);
@ -88,10 +91,13 @@ long cas_service_ioctl_ctrl(struct file *filp, unsigned int cmd,
case KCAS_IOCTL_SET_CACHE_STATE: { case KCAS_IOCTL_SET_CACHE_STATE: {
struct kcas_set_cache_state *cmd_info; struct kcas_set_cache_state *cmd_info;
char cache_name[OCF_CACHE_NAME_SIZE];
GET_CMD_INFO(cmd_info, arg); GET_CMD_INFO(cmd_info, arg);
retval = cache_mngt_set_cache_mode(cmd_info->cache_id, cache_name_from_id(cache_name, cmd_info->cache_id);
retval = cache_mngt_set_cache_mode(cache_name,
cmd_info->caching_mode, cmd_info->flush_data); cmd_info->caching_mode, cmd_info->flush_data);
RETURN_CMD_RESULT(cmd_info, arg, retval); RETURN_CMD_RESULT(cmd_info, arg, retval);
@ -100,14 +106,17 @@ long cas_service_ioctl_ctrl(struct file *filp, unsigned int cmd,
case KCAS_IOCTL_INSERT_CORE: { case KCAS_IOCTL_INSERT_CORE: {
struct kcas_insert_core *cmd_info; struct kcas_insert_core *cmd_info;
struct ocf_mngt_core_config cfg; struct ocf_mngt_core_config cfg;
char cache_name[OCF_CACHE_NAME_SIZE];
GET_CMD_INFO(cmd_info, arg); GET_CMD_INFO(cmd_info, arg);
cache_name_from_id(cache_name, cmd_info->cache_id);
retval = cache_mngt_prepare_core_cfg(&cfg, cmd_info); retval = cache_mngt_prepare_core_cfg(&cfg, cmd_info);
if (retval) if (retval)
RETURN_CMD_RESULT(cmd_info, arg, retval); RETURN_CMD_RESULT(cmd_info, arg, retval);
retval = cache_mngt_add_core_to_cache(&cfg, cmd_info->cache_id, retval = cache_mngt_add_core_to_cache(cache_name, &cfg,
cmd_info); cmd_info);
RETURN_CMD_RESULT(cmd_info, arg, retval); RETURN_CMD_RESULT(cmd_info, arg, retval);
@ -125,42 +134,61 @@ long cas_service_ioctl_ctrl(struct file *filp, unsigned int cmd,
case KCAS_IOCTL_RESET_STATS: { case KCAS_IOCTL_RESET_STATS: {
struct kcas_reset_stats *cmd_info; struct kcas_reset_stats *cmd_info;
char cache_name[OCF_CACHE_NAME_SIZE];
char core_name[OCF_CORE_NAME_SIZE];
GET_CMD_INFO(cmd_info, arg); GET_CMD_INFO(cmd_info, arg);
retval = cache_mngt_reset_stats(cmd_info->cache_id, cache_name_from_id(cache_name, cmd_info->cache_id);
cmd_info->core_id);
if (cmd_info->core_id != OCF_CORE_ID_INVALID)
core_name_from_id(core_name, cmd_info->core_id);
retval = cache_mngt_reset_stats(cache_name,
cmd_info->core_id != OCF_CORE_ID_INVALID ?
core_name : NULL);
RETURN_CMD_RESULT(cmd_info, arg, retval); RETURN_CMD_RESULT(cmd_info, arg, retval);
} }
case KCAS_IOCTL_FLUSH_CACHE: { case KCAS_IOCTL_FLUSH_CACHE: {
struct kcas_flush_cache *cmd_info; struct kcas_flush_cache *cmd_info;
char cache_name[OCF_CACHE_NAME_SIZE];
GET_CMD_INFO(cmd_info, arg); GET_CMD_INFO(cmd_info, arg);
retval = cache_mngt_flush_device(cmd_info->cache_id); cache_name_from_id(cache_name, cmd_info->cache_id);
retval = cache_mngt_flush_device(cache_name);
RETURN_CMD_RESULT(cmd_info, arg, retval); RETURN_CMD_RESULT(cmd_info, arg, retval);
} }
case KCAS_IOCTL_INTERRUPT_FLUSHING: { case KCAS_IOCTL_INTERRUPT_FLUSHING: {
struct kcas_interrupt_flushing *cmd_info; struct kcas_interrupt_flushing *cmd_info;
char cache_name[OCF_CACHE_NAME_SIZE];
GET_CMD_INFO(cmd_info, arg); GET_CMD_INFO(cmd_info, arg);
retval = cache_mngt_interrupt_flushing(cmd_info->cache_id); cache_name_from_id(cache_name, cmd_info->cache_id);
retval = cache_mngt_interrupt_flushing(cache_name);
RETURN_CMD_RESULT(cmd_info, arg, retval); RETURN_CMD_RESULT(cmd_info, arg, retval);
} }
case KCAS_IOCTL_FLUSH_CORE: { case KCAS_IOCTL_FLUSH_CORE: {
struct kcas_flush_core *cmd_info; struct kcas_flush_core *cmd_info;
char cache_name[OCF_CACHE_NAME_SIZE];
char core_name[OCF_CORE_NAME_SIZE];
GET_CMD_INFO(cmd_info, arg); GET_CMD_INFO(cmd_info, arg);
retval = cache_mngt_flush_object(cmd_info->cache_id, cache_name_from_id(cache_name, cmd_info->cache_id);
cmd_info->core_id);
core_name_from_id(core_name, cmd_info->core_id);
retval = cache_mngt_flush_object(cache_name, core_name);
RETURN_CMD_RESULT(cmd_info, arg, retval); RETURN_CMD_RESULT(cmd_info, arg, retval);
} }
@ -198,12 +226,15 @@ long cas_service_ioctl_ctrl(struct file *filp, unsigned int cmd,
case KCAS_IOCTL_PARTITION_SET: { case KCAS_IOCTL_PARTITION_SET: {
struct kcas_io_classes *cmd_info; struct kcas_io_classes *cmd_info;
char cache_name[OCF_CACHE_NAME_SIZE];
/* copy entire memory from user, including array of /* copy entire memory from user, including array of
* ocf_io_class_info structs past the end of kcas_io_classes */ * ocf_io_class_info structs past the end of kcas_io_classes */
_GET_CMD_INFO(cmd_info, arg, KCAS_IO_CLASSES_SIZE); _GET_CMD_INFO(cmd_info, arg, KCAS_IO_CLASSES_SIZE);
retval = cache_mngt_set_partitions(cmd_info); cache_name_from_id(cache_name, cmd_info->cache_id);
retval = cache_mngt_set_partitions(cache_name, cmd_info);
/* return just sizeof(struct kcas_io_classes) bytes of data */ /* return just sizeof(struct kcas_io_classes) bytes of data */
RETURN_CMD_RESULT(cmd_info, arg, retval); RETURN_CMD_RESULT(cmd_info, arg, retval);

View File

@ -247,8 +247,8 @@ int cas_create_cleaner_thread(ocf_cleaner_t c)
int result; int result;
result = _cas_create_thread(&info, _cas_cleaner_thread, c, result = _cas_create_thread(&info, _cas_cleaner_thread, c,
CAS_CPUS_ALL, "cas_clean_%d", CAS_CPUS_ALL, "cas_clean_%s",
ocf_cache_get_id(cache)); ocf_cache_get_name(cache));
if (!result) { if (!result) {
ocf_cleaner_set_priv(c, info); ocf_cleaner_set_priv(c, info);
_cas_start_thread(info); _cas_start_thread(info);
@ -277,8 +277,8 @@ int cas_create_metadata_updater_thread(ocf_metadata_updater_t mu)
int result; int result;
result = _cas_create_thread(&info, _cas_metadata_updater_thread, result = _cas_create_thread(&info, _cas_metadata_updater_thread,
mu, CAS_CPUS_ALL, "ocf_metadata_updater_%d", mu, CAS_CPUS_ALL, "ocf_metadata_updater_%s",
ocf_cache_get_id(ocf_metadata_updater_get_cache(mu))); ocf_cache_get_name(ocf_metadata_updater_get_cache(mu)));
if (!result) { if (!result) {
ocf_metadata_updater_set_priv(mu, info); ocf_metadata_updater_set_priv(mu, info);
_cas_start_thread(info); _cas_start_thread(info);

View File

@ -891,6 +891,16 @@ int block_dev_activate_all_exported_objects(ocf_cache_t cache)
true); true);
} }
static const char *get_cache_id_string(ocf_cache_t cache)
{
return ocf_cache_get_name(cache) + sizeof("cache") - 1;
}
static const char *get_core_id_string(ocf_core_t core)
{
return ocf_core_get_name(core) + sizeof("core") - 1;
}
int block_dev_create_exported_object(ocf_core_t core) int block_dev_create_exported_object(ocf_core_t core)
{ {
ocf_volume_t obj = ocf_core_get_volume(core); ocf_volume_t obj = ocf_core_get_volume(core);
@ -901,9 +911,9 @@ int block_dev_create_exported_object(ocf_core_t core)
struct casdsk_disk *dsk; struct casdsk_disk *dsk;
int result; int result;
snprintf(dev_name, DISK_NAME_LEN, "cas%d-%d", snprintf(dev_name, DISK_NAME_LEN, "cas%s-%s",
ocf_cache_get_id(cache), get_cache_id_string(cache),
ocf_core_get_id(core)); get_core_id_string(core));
dsk = casdisk_functions.casdsk_disk_claim(uuid->data, core); dsk = casdisk_functions.casdsk_disk_claim(uuid->data, core);
if (dsk != bvol->dsk) if (dsk != bvol->dsk)

View File

@ -40,7 +40,7 @@ struct kcas_start_cache {
/** /**
* id of newely inserted cache (in range 1-OCF_CACHE_ID_MAX). * id of newely inserted cache (in range 1-OCF_CACHE_ID_MAX).
*/ */
ocf_cache_id_t cache_id; uint16_t cache_id;
/** /**
* cache initialization mode * cache initialization mode
@ -86,7 +86,7 @@ struct kcas_start_cache {
}; };
struct kcas_stop_cache { struct kcas_stop_cache {
ocf_cache_id_t cache_id; /**< id of cache to be stopped */ uint16_t cache_id; /**< id of cache to be stopped */
uint8_t flush_data; /**< should data be flushed? */ uint8_t flush_data; /**< should data be flushed? */
@ -94,7 +94,7 @@ struct kcas_stop_cache {
}; };
struct kcas_set_cache_state { struct kcas_set_cache_state {
ocf_cache_id_t cache_id; /**< id of cache for which state should be set */ uint16_t cache_id; /**< id of cache for which state should be set */
/** /**
* caching mode for new cache instance * caching mode for new cache instance
@ -113,8 +113,8 @@ struct kcas_set_cache_state {
}; };
struct kcas_insert_core { struct kcas_insert_core {
ocf_cache_id_t cache_id; /**< id of an running cache */ uint16_t cache_id; /**< id of an running cache */
ocf_core_id_t core_id; /**< id of newely inserted core object */ uint16_t core_id; /**< id of newely inserted core object */
char core_path_name[MAX_STR_LEN]; /**< path to a core object */ char core_path_name[MAX_STR_LEN]; /**< path to a core object */
bool try_add; /**< add core to pool if cache isn't present */ bool try_add; /**< add core to pool if cache isn't present */
bool update_path; /**< provide alternative path for core device */ bool update_path; /**< provide alternative path for core device */
@ -123,8 +123,8 @@ struct kcas_insert_core {
}; };
struct kcas_remove_core { struct kcas_remove_core {
ocf_cache_id_t cache_id; /**< id of an running cache */ uint16_t cache_id; /**< id of an running cache */
ocf_core_id_t core_id; /**< id core object to be removed */ uint16_t core_id; /**< id core object to be removed */
bool force_no_flush; /**< remove core without flushing */ bool force_no_flush; /**< remove core without flushing */
bool detach; /**< detach core without removing it from cache metadata */ bool detach; /**< detach core without removing it from cache metadata */
@ -132,34 +132,34 @@ struct kcas_remove_core {
}; };
struct kcas_reset_stats { struct kcas_reset_stats {
ocf_cache_id_t cache_id; /**< id of an running cache */ uint16_t cache_id; /**< id of an running cache */
ocf_core_id_t core_id; /**< id core object to be removed */ uint16_t core_id; /**< id core object to be removed */
int ext_err_code; int ext_err_code;
}; };
struct kcas_flush_cache { struct kcas_flush_cache {
ocf_cache_id_t cache_id; /**< id of an running cache */ uint16_t cache_id; /**< id of an running cache */
int ext_err_code; int ext_err_code;
}; };
struct kcas_interrupt_flushing { struct kcas_interrupt_flushing {
ocf_cache_id_t cache_id; /**< id of an running cache */ uint16_t cache_id; /**< id of an running cache */
int ext_err_code; int ext_err_code;
}; };
struct kcas_flush_core { struct kcas_flush_core {
ocf_cache_id_t cache_id; /**< id of an running cache */ uint16_t cache_id; /**< id of an running cache */
ocf_core_id_t core_id; /**< id core object to be removed */ uint16_t core_id; /**< id core object to be removed */
int ext_err_code; int ext_err_code;
}; };
struct kcas_cache_info { struct kcas_cache_info {
/** id of a cache */ /** id of a cache */
ocf_cache_id_t cache_id; uint16_t cache_id;
/** path to caching device */ /** path to caching device */
char cache_path_name[MAX_STR_LEN]; char cache_path_name[MAX_STR_LEN];
@ -167,7 +167,7 @@ struct kcas_cache_info {
/** /**
* IDs of cores associated with this cache. * IDs of cores associated with this cache.
*/ */
ocf_core_id_t core_id[OCF_CORE_MAX]; uint16_t core_id[OCF_CORE_MAX];
struct ocf_cache_info info; struct ocf_cache_info info;
@ -181,10 +181,10 @@ struct kcas_core_info {
char core_path_name[MAX_STR_LEN]; char core_path_name[MAX_STR_LEN];
/** Cache id */ /** Cache id */
ocf_cache_id_t cache_id; uint16_t cache_id;
/** Core id */ /** Core id */
ocf_core_id_t core_id; uint16_t core_id;
/** CAS statistics of core */ /** CAS statistics of core */
struct ocf_stats_core stats; struct ocf_stats_core stats;
@ -223,10 +223,10 @@ struct kcas_core_pool_count {
*/ */
struct kcas_io_class { struct kcas_io_class {
/** Cache ID */ /** Cache ID */
ocf_cache_id_t cache_id; uint16_t cache_id;
/** Core ID */ /** Core ID */
ocf_core_id_t core_id; uint16_t core_id;
/** IO class id for which info will be retrieved */ /** IO class id for which info will be retrieved */
uint32_t class_id; uint32_t class_id;
@ -248,7 +248,7 @@ struct kcas_io_class {
*/ */
struct kcas_io_classes { struct kcas_io_classes {
/** Cache ID */ /** Cache ID */
ocf_cache_id_t cache_id; uint16_t cache_id;
int ext_err_code; int ext_err_code;
@ -268,7 +268,7 @@ struct kcas_cache_list {
/** requested number of ids and returned in response cmd */ /** requested number of ids and returned in response cmd */
uint32_t in_out_num; uint32_t in_out_num;
/** array with cache list and its properties */ /** array with cache list and its properties */
ocf_cache_id_t cache_id_tab[CACHE_LIST_ID_LIMIT]; uint16_t cache_id_tab[CACHE_LIST_ID_LIMIT];
int ext_err_code; int ext_err_code;
}; };
@ -325,8 +325,8 @@ enum kcas_core_param_id {
}; };
struct kcas_set_core_param { struct kcas_set_core_param {
ocf_cache_id_t cache_id; uint16_t cache_id;
ocf_core_id_t core_id; uint16_t core_id;
enum kcas_core_param_id param_id; enum kcas_core_param_id param_id;
uint32_t param_value; uint32_t param_value;
@ -334,8 +334,8 @@ struct kcas_set_core_param {
}; };
struct kcas_get_core_param { struct kcas_get_core_param {
ocf_cache_id_t cache_id; uint16_t cache_id;
ocf_core_id_t core_id; uint16_t core_id;
enum kcas_core_param_id param_id; enum kcas_core_param_id param_id;
uint32_t param_value; uint32_t param_value;
@ -354,7 +354,7 @@ enum kcas_cache_param_id {
}; };
struct kcas_set_cache_param { struct kcas_set_cache_param {
ocf_cache_id_t cache_id; uint16_t cache_id;
enum kcas_cache_param_id param_id; enum kcas_cache_param_id param_id;
uint32_t param_value; uint32_t param_value;
@ -362,7 +362,7 @@ struct kcas_set_cache_param {
}; };
struct kcas_get_cache_param { struct kcas_get_cache_param {
ocf_cache_id_t cache_id; uint16_t cache_id;
enum kcas_cache_param_id param_id; enum kcas_cache_param_id param_id;
uint32_t param_value; uint32_t param_value;

2
ocf

@ -1 +1 @@
Subproject commit aa02f56b052a636e30c282a4b0efef4b3bb9808e Subproject commit bc2084567330a16db660feb0f579210f525dfc2b