diff --git a/modules/cas_cache/layer_cache_management.c b/modules/cas_cache/layer_cache_management.c index 0d062bd..9181eb1 100644 --- a/modules/cas_cache/layer_cache_management.c +++ b/modules/cas_cache/layer_cache_management.c @@ -1753,6 +1753,58 @@ int cache_mngt_interrupt_flushing(const char *cache_name) } +int cache_mngt_get_stats(struct kcas_get_stats *stats) +{ + int result; + ocf_cache_t cache; + ocf_core_t core = NULL; + + result = mngt_get_cache_by_id(cas_ctx, stats->cache_id, &cache); + if (result) + return result; + + result = _cache_mngt_read_lock_sync(cache); + if (result) + goto put; + + if (stats->core_id == OCF_CORE_ID_INVALID && + stats->part_id == OCF_IO_CLASS_INVALID) { + result = ocf_stats_collect_cache(cache, &stats->usage, &stats->req, + &stats->blocks, &stats->errors); + if (result) + goto unlock; + + } else if (stats->part_id == OCF_IO_CLASS_INVALID) { + result = get_core_by_id(cache, stats->core_id, &core); + if (result) + goto unlock; + + result = ocf_stats_collect_core(core, &stats->usage, &stats->req, + &stats->blocks, &stats->errors); + if (result) + goto unlock; + + } else { + if (stats->core_id == OCF_CORE_ID_INVALID) { + result = ocf_stats_collect_part_cache(cache, stats->part_id, + &stats->usage, &stats->req, &stats->blocks); + } else { + result = get_core_by_id(cache, stats->core_id, &core); + if (result) + goto unlock; + + result = ocf_stats_collect_part_core(core, stats->part_id, + &stats->usage, &stats->req, &stats->blocks); + } + } + +unlock: + ocf_mngt_cache_read_unlock(cache); +put: + ocf_mngt_cache_put(cache); + return result; +} + int cache_mngt_get_info(struct kcas_cache_info *info) { uint32_t i, j; diff --git a/modules/cas_cache/layer_cache_management.h b/modules/cas_cache/layer_cache_management.h index 6ac0e8a..bd1babd 100644 --- a/modules/cas_cache/layer_cache_management.h +++ b/modules/cas_cache/layer_cache_management.h @@ -73,6 +73,8 @@ int cache_mngt_list_caches(struct kcas_cache_list *list); int cache_mngt_interrupt_flushing(const char *cache_name); +int cache_mngt_get_stats(struct kcas_get_stats *stats); + int cache_mngt_get_info(struct kcas_cache_info *info); int cache_mngt_get_io_class_info(struct kcas_io_class *part); diff --git a/modules/cas_cache/service_ui_ioctl.c b/modules/cas_cache/service_ui_ioctl.c index 62a4ac0..a3cb6df 100644 --- a/modules/cas_cache/service_ui_ioctl.c +++ b/modules/cas_cache/service_ui_ioctl.c @@ -193,6 +193,16 @@ long cas_service_ioctl_ctrl(struct file *filp, unsigned int cmd, RETURN_CMD_RESULT(cmd_info, arg, retval); } + case KCAS_IOCTL_GET_STATS: { + struct kcas_get_stats *cmd_info; + + GET_CMD_INFO(cmd_info, arg); + + retval = cache_mngt_get_stats(cmd_info); + + RETURN_CMD_RESULT(cmd_info, arg, retval); + } + case KCAS_IOCTL_CACHE_INFO: { struct kcas_cache_info *cmd_info; diff --git a/modules/include/cas_ioctl_codes.h b/modules/include/cas_ioctl_codes.h index 451a26e..6e60adc 100644 --- a/modules/include/cas_ioctl_codes.h +++ b/modules/include/cas_ioctl_codes.h @@ -157,6 +157,28 @@ struct kcas_flush_core { int ext_err_code; }; +struct kcas_get_stats { + /** id of a cache */ + uint16_t cache_id; + + /** id of a core */ + uint16_t core_id; + + /** id of an ioclass */ + uint16_t part_id; + + /** fields to be filled with statistics */ + struct ocf_stats_usage usage; + + struct ocf_stats_requests req; + + struct ocf_stats_blocks blocks; + + struct ocf_stats_errors errors; + + int ext_err_code; +}; + struct kcas_cache_info { /** id of a cache */ uint16_t cache_id; @@ -405,6 +427,7 @@ struct kcas_get_cache_param { * 31 * KCAS_IOCTL_GET_CORE_PARAM * OK * * 32 * KCAS_IOCTL_SET_CACHE_PARAM * OK * * 33 * KCAS_IOCTL_GET_CACHE_PARAM * OK * + * 34 * KCAS_IOCTL_GET_STATS * OK * ******************************************************************************* */ @@ -492,6 +515,9 @@ struct kcas_get_cache_param { /** Get various cache runtime parameters */ #define KCAS_IOCTL_GET_CACHE_PARAM _IOW(KCAS_IOCTL_MAGIC, 33, struct kcas_get_cache_param) +/** Get stats of particular OCF object */ +#define KCAS_IOCTL_GET_STATS _IOR(KCAS_IOCTL_MAGIC, 34, struct kcas_get_stats) + /** * Extended kernel CAS error codes */ diff --git a/ocf b/ocf index 9a46c40..c2da038 160000 --- a/ocf +++ b/ocf @@ -1 +1 @@ -Subproject commit 9a46c402b2e8398da7a3ee212faf041b3f01f958 +Subproject commit c2da038c03693a9105bee67952614db1a5cf1a37