From c93d1f73ef5162290f848057856d21d1f99a183b Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Tue, 17 Nov 2020 09:47:55 -0500 Subject: [PATCH] casadm: occupancy per ioclass Enable new ioclass config format with float allocation values Signed-off-by: Michal Mielewczyk --- casadm/cas_lib.c | 58 +++++++++++++++++++++++++-------------- casadm/statistics_model.c | 4 +-- 2 files changed, 39 insertions(+), 23 deletions(-) diff --git a/casadm/cas_lib.c b/casadm/cas_lib.c index f4d0146..86fa5bb 100644 --- a/casadm/cas_lib.c +++ b/casadm/cas_lib.c @@ -2031,11 +2031,10 @@ void partition_list_line(FILE *out, struct kcas_io_class *cls, bool csv) { char buffer[128]; const char *prio; - const char *allocation; - if (cls->info.cache_mode != ocf_cache_mode_pt) - allocation = csv ? "1" : "YES"; - else - allocation = csv ? "0" : "NO"; + char allocation_str[MAX_STR_LEN]; + + snprintf(allocation_str, sizeof(allocation_str), "%d.%02d", + cls->info.max_size/100, cls->info.max_size%100); if (OCF_IO_CLASS_PRIO_PINNED == cls->info.priority) { prio = csv ? "" : "Pinned"; @@ -2045,7 +2044,7 @@ void partition_list_line(FILE *out, struct kcas_io_class *cls, bool csv) } fprintf(out, TAG(TABLE_ROW)"%u,%s,%s,%s\n", - cls->class_id, cls->info.name, prio, allocation); + cls->class_id, cls->info.name, prio, allocation_str); } @@ -2061,6 +2060,7 @@ int partition_list(unsigned int cache_id, unsigned int output_format) if (fd == -1 ) return FAILURE; + if (create_pipe_pair(intermediate_file)) { cas_printf(LOG_ERR,"Failed to create unidirectional pipe.\n"); close(fd); @@ -2118,8 +2118,11 @@ int partition_list(unsigned int cache_id, unsigned int output_format) } enum { - part_csv_coll_id = 0, part_csv_coll_name, part_csv_coll_prio, - part_csv_coll_alloc, part_csv_coll_max + part_csv_coll_id = 0, + part_csv_coll_name, + part_csv_coll_prio, + part_csv_coll_alloc, + part_csv_coll_max }; int partition_is_name_valid(const char *name) @@ -2157,6 +2160,28 @@ static inline const char *partition_get_csv_col(CSVFILE *csv, int col, return val; } +static int calculate_max_allocation(uint16_t cache_id, const char *allocation, + uint32_t *part_size) +{ + float alloc = 0; + char *end; + + if (strnlen(allocation, MAX_STR_LEN) > 4) + return FAILURE; + + alloc = strtof(allocation, &end); + if (alloc > 1 || alloc < 0) + return FAILURE; + + if (allocation + strnlen(allocation, MAX_STR_LEN) != end) + return FAILURE; + + *part_size = (uint32_t)(alloc * 100); + + return SUCCESS; +} + + static inline int partition_get_line(CSVFILE *csv, struct kcas_io_classes *cnfg, int *error_col) @@ -2227,20 +2252,13 @@ static inline int partition_get_line(CSVFILE *csv, if (strempty(alloc)) { return FAILURE; } - if (validate_str_num(alloc, "alloc", 0, 1)) { - return FAILURE; - } - value = strtoul(alloc, NULL, 10); - if (0 == value) { - cnfg->info[part_id].cache_mode = ocf_cache_mode_pt; - } else if (1 == value) { - cnfg->info[part_id].cache_mode = ocf_cache_mode_max; - } else { - return FAILURE; - } + if (calculate_max_allocation(cnfg->cache_id, alloc, &value) == FAILURE) + return FAILURE; + + cnfg->info[part_id].cache_mode = ocf_cache_mode_max; cnfg->info[part_id].min_size = 0; - cnfg->info[part_id].max_size = UINT32_MAX; + cnfg->info[part_id].max_size = value; return 0; } diff --git a/casadm/statistics_model.c b/casadm/statistics_model.c index 4a4438e..9f48279 100644 --- a/casadm/statistics_model.c +++ b/casadm/statistics_model.c @@ -403,9 +403,7 @@ static void print_stats_ioclass_conf(const struct kcas_io_class* io_class, print_kv_pair(outfile, "Eviction priority", "%d", io_class->info.priority); } - print_kv_pair(outfile, "Selective allocation", "%s", - io_class->info.cache_mode != ocf_cache_mode_pt ? - "Yes" : "No"); + print_kv_pair(outfile, "Max size", "%u%%", io_class->info.max_size); }