casadm: Add option to print full /dev/by-id link

User can check path in runtime to use the same in config.

Signed-off-by: Slawomir Jankowski <slawomir.jankowski@intel.com>
This commit is contained in:
Slawomir Jankowski 2020-12-07 16:48:20 +01:00 committed by Robert Baldyga
parent 7b4837e240
commit 0f331cb650
4 changed files with 71 additions and 47 deletions

View File

@ -662,6 +662,9 @@ int set_device_path(char *dest_path, size_t dest_len, const char *src_path, size
return FAILURE; return FAILURE;
} }
int get_core_info(int fd, int cache_id, int core_id,
struct kcas_core_info *info, bool by_id_path)
{
memset(info, 0, sizeof(*info)); memset(info, 0, sizeof(*info));
info->cache_id = cache_id; info->cache_id = cache_id;
info->core_id = core_id; info->core_id = core_id;
@ -670,19 +673,20 @@ int set_device_path(char *dest_path, size_t dest_len, const char *src_path, size
return FAILURE; return FAILURE;
} }
/* internally use device special file path to describe core */ if (!by_id_path) {
if (get_dev_path(info->core_path_name, if (get_dev_path(info->core_path_name, info->core_path_name,
info->core_path_name,
sizeof(info->core_path_name))) { sizeof(info->core_path_name))) {
cas_printf(LOG_WARNING, "WARNING: Can not resolve path to core " cas_printf(LOG_WARNING, "WARNING: Can not resolve path to core %d "
"%d from cache %d. By-id path will be shown for that core.\n", "from cache %d. By-id path will be shown for that core.\n",
core_id, cache_id); core_id, cache_id);
} }
}
return SUCCESS; return SUCCESS;
} }
static int get_core_device(int cache_id, int core_id, struct core_device *core) static int get_core_device(int cache_id, int core_id,
struct core_device *core, bool by_id_path)
{ {
int fd; int fd;
struct kcas_core_info cmd_info; struct kcas_core_info cmd_info;
@ -694,7 +698,7 @@ static int get_core_device(int cache_id, int core_id, struct core_device *core)
if (fd == -1) if (fd == -1)
return FAILURE; return FAILURE;
if (get_core_info(fd, cache_id, core_id, &cmd_info)) { if (get_core_info(fd, cache_id, core_id, &cmd_info, by_id_path)) {
cas_printf(LOG_ERR, "Error while retrieving stats\n"); cas_printf(LOG_ERR, "Error while retrieving stats\n");
print_err(cmd_info.ext_err_code); print_err(cmd_info.ext_err_code);
close(fd); close(fd);
@ -788,7 +792,7 @@ error_out:
* *
* @return valid pointer to a structure or NULL if error happened * @return valid pointer to a structure or NULL if error happened
*/ */
struct cache_device *get_cache_device(const struct kcas_cache_info *info) struct cache_device *get_cache_device(const struct kcas_cache_info *info, bool by_id_path)
{ {
int core_id, cache_id, ret; int core_id, cache_id, ret;
struct cache_device *cache; struct cache_device *cache;
@ -828,7 +832,7 @@ struct cache_device *get_cache_device(const struct kcas_cache_info *info)
for (cache->core_count = 0; cache->core_count < info->info.core_count; ++cache->core_count) { for (cache->core_count = 0; cache->core_count < info->info.core_count; ++cache->core_count) {
core_id = info->core_id[cache->core_count]; core_id = info->core_id[cache->core_count];
ret = get_core_device(cache_id, core_id, &core); ret = get_core_device(cache_id, core_id, &core, by_id_path);
if (0 != ret) { if (0 != ret) {
break; break;
} else { } else {
@ -850,7 +854,7 @@ struct cache_device *get_cache_device(const struct kcas_cache_info *info)
* @param cache_id cache id (1...) * @param cache_id cache id (1...)
* @return valid pointer to a structure or NULL if error happened * @return valid pointer to a structure or NULL if error happened
*/ */
struct cache_device *get_cache_device_by_id_fd(int cache_id, int fd) struct cache_device *get_cache_device_by_id_fd(int cache_id, int fd, bool by_id_path)
{ {
struct kcas_cache_info cmd_info; struct kcas_cache_info cmd_info;
@ -862,7 +866,7 @@ struct cache_device *get_cache_device_by_id_fd(int cache_id, int fd)
return NULL; return NULL;
} }
return get_cache_device(&cmd_info); return get_cache_device(&cmd_info, by_id_path);
} }
void free_cache_devices_list(struct cache_device **caches, int caches_count) void free_cache_devices_list(struct cache_device **caches, int caches_count)
@ -875,7 +879,7 @@ void free_cache_devices_list(struct cache_device **caches, int caches_count)
free(caches); free(caches);
} }
struct cache_device **get_cache_devices(int *caches_count) struct cache_device **get_cache_devices(int *caches_count, bool by_id_path)
{ {
int i, fd, status, chunk_size, count; int i, fd, status, chunk_size, count;
struct kcas_cache_list cache_list; struct kcas_cache_list cache_list;
@ -921,7 +925,8 @@ struct cache_device **get_cache_devices(int *caches_count)
/* iterate through id table and get status */ /* iterate through id table and get status */
for (i = 0; i < cache_list.in_out_num; i++) { for (i = 0; i < cache_list.in_out_num; i++) {
if ((tmp_cache = get_cache_device_by_id_fd(cache_list.cache_id_tab[i], fd)) == NULL) { if ((tmp_cache = get_cache_device_by_id_fd(cache_list.cache_id_tab[i],
fd, by_id_path)) == NULL) {
cas_printf(LOG_ERR, "Failed to retrieve cache information!\n"); cas_printf(LOG_ERR, "Failed to retrieve cache information!\n");
continue; continue;
} }
@ -950,7 +955,7 @@ int check_cache_already_added(const char *cache_device) {
struct cache_device **caches, *curr_cache; struct cache_device **caches, *curr_cache;
int caches_count, i; int caches_count, i;
caches = get_cache_devices(&caches_count); caches = get_cache_devices(&caches_count, false);
if (NULL == caches) { if (NULL == caches) {
return SUCCESS; return SUCCESS;
@ -1009,7 +1014,7 @@ int start_cache(uint16_t cache_id, unsigned int cache_init,
if (cache_id == 0) { if (cache_id == 0) {
cache_id = 1; cache_id = 1;
caches = get_cache_devices(&caches_count); caches = get_cache_devices(&caches_count, false);
if (caches != NULL) { if (caches != NULL) {
psort(caches, caches_count, sizeof(struct cache_device*), caches_compare); psort(caches, caches_count, sizeof(struct cache_device*), caches_compare);
for (i = 0; i < caches_count; ++i) { for (i = 0; i < caches_count; ++i) {
@ -1078,7 +1083,7 @@ int start_cache(uint16_t cache_id, unsigned int cache_init,
status = SUCCESS; status = SUCCESS;
for (i = 0; i < CORE_ADD_MAX_TIMEOUT; ++i) { for (i = 0; i < CORE_ADD_MAX_TIMEOUT; ++i) {
cache = get_cache_device_by_id_fd(cache_id, fd); cache = get_cache_device_by_id_fd(cache_id, fd, false);
status = FAILURE; status = FAILURE;
if (cache == NULL) { if (cache == NULL) {
@ -1494,7 +1499,7 @@ int check_core_already_cached(const char *core_device) {
if (get_dev_path(core_device, core_device_path, sizeof(core_device_path))) if (get_dev_path(core_device, core_device_path, sizeof(core_device_path)))
return SUCCESS; return SUCCESS;
caches = get_cache_devices(&caches_count); caches = get_cache_devices(&caches_count, false);
if (NULL == caches) { if (NULL == caches) {
return SUCCESS; return SUCCESS;
@ -1583,7 +1588,7 @@ int get_inactive_core_count(const struct kcas_cache_info *cache_info)
int inactive_cores = 0; int inactive_cores = 0;
int i; int i;
cache = get_cache_device(cache_info); cache = get_cache_device(cache_info, false);
if (!cache) if (!cache)
return -1; return -1;
@ -1686,7 +1691,7 @@ int illegal_recursive_core(unsigned int cache_id, const char *core_device, int c
* iteration of this loop*/ * iteration of this loop*/
/* get underlying core device of dev_cache_id-dev_core_id */ /* get underlying core device of dev_cache_id-dev_core_id */
cache = get_cache_device_by_id_fd(dev_cache_id, fd); cache = get_cache_device_by_id_fd(dev_cache_id, fd, false);
if (!cache) { if (!cache) {
cas_printf(LOG_ERR, "Failed to extract statistics for " cas_printf(LOG_ERR, "Failed to extract statistics for "
@ -2624,7 +2629,7 @@ error_out:
return result; return result;
} }
int list_caches(unsigned int list_format) int list_caches(unsigned int list_format, bool by_id_path)
{ {
struct cache_device **caches, *curr_cache; struct cache_device **caches, *curr_cache;
struct kcas_core_pool_path core_pool_path_cmd = {0}; struct kcas_core_pool_path core_pool_path_cmd = {0};
@ -2636,7 +2641,7 @@ int list_caches(unsigned int list_format)
pthread_t thread; pthread_t thread;
struct list_printout_ctx printout_ctx; struct list_printout_ctx printout_ctx;
caches = get_cache_devices(&caches_count); caches = get_cache_devices(&caches_count, by_id_path);
if (caches_count < 0) { if (caches_count < 0) {
cas_printf(LOG_INFO, "Error getting caches list\n"); cas_printf(LOG_INFO, "Error getting caches list\n");
return FAILURE; return FAILURE;
@ -2691,9 +2696,12 @@ int list_caches(unsigned int list_format)
"-" /* device */); "-" /* device */);
for (i = 0; i < core_pool_path_cmd.core_pool_count; i++) { for (i = 0; i < core_pool_path_cmd.core_pool_count; i++) {
char *core_path = core_pool_path_cmd.core_path_tab + (MAX_STR_LEN * i); char *core_path = core_pool_path_cmd.core_path_tab + (MAX_STR_LEN * i);
if (!by_id_path) {
if (get_dev_path(core_path, core_path, MAX_STR_LEN)) { if (get_dev_path(core_path, core_path, MAX_STR_LEN)) {
cas_printf(LOG_WARNING, "WARNING: Can not resolve path to core. " cas_printf(LOG_WARNING, "WARNING: Can not resolve path "
"By-id path will be shown for that core.\n"); "to core. By-id path will be shown for that "
"core.\n");
}
} }
fprintf(intermediate_file[1], TAG(TREE_LEAF) fprintf(intermediate_file[1], TAG(TREE_LEAF)
"%s,%s,%s,%s,%s,%s\n", "%s,%s,%s,%s,%s,%s\n",
@ -2715,7 +2723,10 @@ int list_caches(unsigned int list_format)
float cache_flush_prog; float cache_flush_prog;
float core_flush_prog; float core_flush_prog;
get_dev_path(curr_cache->device, curr_cache->device, sizeof(curr_cache->device)); if (!by_id_path) {
get_dev_path(curr_cache->device, curr_cache->device,
sizeof(curr_cache->device));
}
cache_flush_prog = calculate_flush_progress(curr_cache->dirty, curr_cache->flushed); cache_flush_prog = calculate_flush_progress(curr_cache->dirty, curr_cache->flushed);
if (cache_flush_prog) { if (cache_flush_prog) {

View File

@ -26,7 +26,7 @@
#define FAILURE 1 /**< default non-zero exit code. */ #define FAILURE 1 /**< default non-zero exit code. */
#define INTERRUPTED 2 /**< if command is interrupted */ #define INTERRUPTED 2 /**< if command is interrupted */
#define SUCCESS 0 /**< 0 exit code from majority of our functions #define SUCCESS 0 /**< 0 exit code from majority of our functions \
stands for success */ stands for success */
struct core_device { struct core_device {
@ -210,7 +210,7 @@ int set_cache_mode(unsigned int cache_state, unsigned int cache_id, int flush);
*/ */
int add_core(unsigned int cache_id, unsigned int core_id, const char *core_device, int try_add, int update_path); int add_core(unsigned int cache_id, unsigned int core_id, const char *core_device, int try_add, int update_path);
int get_core_info(int fd, int cache_id, int core_id, struct kcas_core_info *info); int get_core_info(int fd, int cache_id, int core_id, struct kcas_core_info *info, bool by_id_path);
int remove_core(unsigned int cache_id, unsigned int core_id, int remove_core(unsigned int cache_id, unsigned int core_id,
bool detach, bool force_no_flush); bool detach, bool force_no_flush);
@ -234,16 +234,16 @@ int partition_is_name_valid(const char *name);
int cas_module_version(char *buff, int size); int cas_module_version(char *buff, int size);
int disk_module_version(char *buff, int size); int disk_module_version(char *buff, int size);
int list_caches(unsigned int list_format); int list_caches(unsigned int list_format, bool by_id_path);
int cache_status(unsigned int cache_id, unsigned int core_id, int io_class_id, int cache_status(unsigned int cache_id, unsigned int core_id, int io_class_id,
unsigned int stats_filters, unsigned int stats_format); unsigned int stats_filters, unsigned int stats_format, bool by_id_path);
int get_inactive_core_count(const struct kcas_cache_info *cache_info); int get_inactive_core_count(const struct kcas_cache_info *cache_info);
int open_ctrl_device_quiet(); int open_ctrl_device_quiet();
int open_ctrl_device(); int open_ctrl_device();
int *get_cache_ids(int *cache_count); int *get_cache_ids(int *cache_count);
struct cache_device *get_cache_device_by_id_fd(int cache_id, int fd); struct cache_device *get_cache_device_by_id_fd(int cache_id, int fd, bool by_id_path);
struct cache_device **get_cache_devices(int *caches_count); struct cache_device **get_cache_devices(int *caches_count, bool by_id_path);
void free_cache_devices_list(struct cache_device **caches, int caches_count); void free_cache_devices_list(struct cache_device **caches, int caches_count);
int validate_dev(const char *dev_path); int validate_dev(const char *dev_path);

View File

@ -60,6 +60,7 @@ struct command_args{
uint32_t params_type; uint32_t params_type;
uint32_t params_count; uint32_t params_count;
bool verbose; bool verbose;
bool by_id_path;
}; };
static struct command_args command_args_values = { static struct command_args command_args_values = {
@ -83,6 +84,7 @@ static struct command_args command_args_values = {
.no_flush = false, .no_flush = false,
.cache_device = NULL, .cache_device = NULL,
.core_device = NULL, .core_device = NULL,
.by_id_path = false,
.params_type = 0, .params_type = 0,
.params_count = 0, .params_count = 0,
@ -153,6 +155,8 @@ int command_handle_option(char *opt, const char **arg)
command_args_values.detach = true; command_args_values.detach = true;
} else if (!strcmp(opt, "no-flush")) { } else if (!strcmp(opt, "no-flush")) {
command_args_values.no_flush = true; command_args_values.no_flush = true;
} else if (!strcmp(opt, "by-id-path")) {
command_args_values.by_id_path = true;
} else { } else {
return FAILURE; return FAILURE;
} }
@ -344,12 +348,13 @@ int handle_start()
static cli_option list_options[] = { static cli_option list_options[] = {
{'o', "output-format", "Output format: {table|csv}", 1, "FORMAT", 0}, {'o', "output-format", "Output format: {table|csv}", 1, "FORMAT", 0},
{'b', "by-id-path", "Display by-id path to disks instead of short form /dev/sdx"},
{0} {0}
}; };
int handle_list() int handle_list()
{ {
return list_caches(command_args_values.output_format); return list_caches(command_args_values.output_format, command_args_values.by_id_path);
} }
static cli_option stats_options[] = { static cli_option stats_options[] = {
@ -358,6 +363,7 @@ static cli_option stats_options[] = {
{'d', "io-class-id", "Display per IO class statistics", 1, "ID", CLI_OPTION_OPTIONAL_ARG}, {'d', "io-class-id", "Display per IO class statistics", 1, "ID", CLI_OPTION_OPTIONAL_ARG},
{'f', "filter", "Apply filters from the following set: {all, conf, usage, req, blk, err}", 1, "FILTER-SPEC"}, {'f', "filter", "Apply filters from the following set: {all, conf, usage, req, blk, err}", 1, "FILTER-SPEC"},
{'o', "output-format", "Output format: {table|csv}", 1, "FORMAT"}, {'o', "output-format", "Output format: {table|csv}", 1, "FORMAT"},
{'b', "by-id-path", "Display by-id path to disks instead of short form /dev/sdx"},
{0} {0}
}; };
@ -396,6 +402,10 @@ int stats_command_handle_option(char *opt, const char **arg)
command_args_values.output_format = validate_str_output_format(arg[0]); command_args_values.output_format = validate_str_output_format(arg[0]);
if (OUTPUT_FORMAT_INVALID == command_args_values.output_format) if (OUTPUT_FORMAT_INVALID == command_args_values.output_format)
return FAILURE; return FAILURE;
} else if (!strcmp(opt, "by-id-path")) {
command_args_values.by_id_path = true;
if (command_args_values.by_id_path == false)
return FAILURE;
} else { } else {
return FAILURE; return FAILURE;
} }
@ -409,7 +419,8 @@ int handle_stats()
command_args_values.core_id, command_args_values.core_id,
command_args_values.io_class_id, command_args_values.io_class_id,
command_args_values.stats_filters, command_args_values.stats_filters,
command_args_values.output_format); command_args_values.output_format,
command_args_values.by_id_path);
} }
static cli_option stop_options[] = { static cli_option stop_options[] = {

View File

@ -518,7 +518,7 @@ int cache_stats_ioclasses(int ctrl_fd, const struct kcas_cache_info *cache_info,
} }
int cache_stats_conf(int ctrl_fd, const struct kcas_cache_info *cache_info, int cache_stats_conf(int ctrl_fd, const struct kcas_cache_info *cache_info,
unsigned int cache_id, FILE *outfile) unsigned int cache_id, FILE *outfile, bool by_id_path)
{ {
float flush_progress = 0; float flush_progress = 0;
float value; float value;
@ -528,10 +528,10 @@ int cache_stats_conf(int ctrl_fd, const struct kcas_cache_info *cache_info,
char dev_path[MAX_STR_LEN]; char dev_path[MAX_STR_LEN];
int inactive_cores; int inactive_cores;
if (get_dev_path(cache_info->cache_path_name, dev_path, sizeof(dev_path)) != SUCCESS) if (!by_id_path && get_dev_path(cache_info->cache_path_name, dev_path, sizeof(dev_path)) == SUCCESS)
cache_path = cache_info->cache_path_name;
else
cache_path = dev_path; cache_path = dev_path;
else
cache_path = cache_info->cache_path_name;
flush_progress = calculate_flush_progress(cache_info->info.dirty, flush_progress = calculate_flush_progress(cache_info->info.dirty,
cache_info->info.flushed); cache_info->info.flushed);
@ -604,7 +604,8 @@ void cache_stats_counters(struct kcas_get_stats *cache_stats, FILE *outfile,
} }
static int cache_stats(int ctrl_fd, const struct kcas_cache_info *cache_info, static int cache_stats(int ctrl_fd, const struct kcas_cache_info *cache_info,
unsigned int cache_id, FILE *outfile, unsigned int stats_filters) unsigned int cache_id, FILE *outfile, unsigned int stats_filters,
bool by_id_path)
{ {
struct kcas_get_stats cache_stats = {}; struct kcas_get_stats cache_stats = {};
cache_stats.cache_id = cache_id; cache_stats.cache_id = cache_id;
@ -617,7 +618,7 @@ static int cache_stats(int ctrl_fd, const struct kcas_cache_info *cache_info,
begin_record(outfile); begin_record(outfile);
if (stats_filters & STATS_FILTER_CONF) if (stats_filters & STATS_FILTER_CONF)
cache_stats_conf(ctrl_fd, cache_info, cache_id, outfile); cache_stats_conf(ctrl_fd, cache_info, cache_id, outfile, by_id_path);
if (stats_filters & STATS_FILTER_USAGE) if (stats_filters & STATS_FILTER_USAGE)
print_usage_stats(&cache_stats.usage, outfile); print_usage_stats(&cache_stats.usage, outfile);
@ -635,12 +636,12 @@ static int cache_stats(int ctrl_fd, const struct kcas_cache_info *cache_info,
int cache_stats_cores(int ctrl_fd, const struct kcas_cache_info *cache_info, int cache_stats_cores(int ctrl_fd, const struct kcas_cache_info *cache_info,
unsigned int cache_id, unsigned int core_id, int io_class_id, unsigned int cache_id, unsigned int core_id, int io_class_id,
FILE *outfile, unsigned int stats_filters) FILE *outfile, unsigned int stats_filters, bool by_id_path)
{ {
struct kcas_core_info core_info; struct kcas_core_info core_info;
struct kcas_get_stats stats; struct kcas_get_stats stats;
if (get_core_info(ctrl_fd, cache_id, core_id, &core_info)) { if (get_core_info(ctrl_fd, cache_id, core_id, &core_info, by_id_path)) {
cas_printf(LOG_ERR, "Error while retrieving stats for core %d\n", core_id); cas_printf(LOG_ERR, "Error while retrieving stats for core %d\n", core_id);
print_err(core_info.ext_err_code); print_err(core_info.ext_err_code);
return FAILURE; return FAILURE;
@ -697,7 +698,7 @@ void *stats_printout(void *ctx)
* @return SUCCESS upon successful printing of statistic. FAILURE if any error happens * @return SUCCESS upon successful printing of statistic. FAILURE if any error happens
*/ */
int cache_status(unsigned int cache_id, unsigned int core_id, int io_class_id, int cache_status(unsigned int cache_id, unsigned int core_id, int io_class_id,
unsigned int stats_filters, unsigned int output_format) unsigned int stats_filters, unsigned int output_format, bool by_id_path)
{ {
int ctrl_fd, i; int ctrl_fd, i;
int ret = SUCCESS; int ret = SUCCESS;
@ -765,13 +766,14 @@ int cache_status(unsigned int cache_id, unsigned int core_id, int io_class_id,
} }
} else if (core_id == OCF_CORE_ID_INVALID) { } else if (core_id == OCF_CORE_ID_INVALID) {
if (cache_stats(ctrl_fd, &cache_info, cache_id, intermediate_file[1], if (cache_stats(ctrl_fd, &cache_info, cache_id, intermediate_file[1],
stats_filters)) { stats_filters, by_id_path)) {
ret = FAILURE; ret = FAILURE;
goto cleanup; goto cleanup;
} }
} else { } else {
if (cache_stats_cores(ctrl_fd, &cache_info, cache_id, core_id, if (cache_stats_cores(ctrl_fd, &cache_info, cache_id, core_id,
io_class_id, intermediate_file[1], stats_filters)) { io_class_id, intermediate_file[1],
stats_filters, by_id_path)) {
ret = FAILURE; ret = FAILURE;
goto cleanup; goto cleanup;
} }