From: da Cunha, Leonardo Date: Wed, 14 Jun 2023 18:39:02 +0000 (-0700) Subject: plugins/solidigm: Formated log page directory table consistently with "nvme list... X-Git-Tag: v2.5~19 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=7e2a5f24ae601279c5d5418c29a88101e4d82b1c;p=users%2Fsagi%2Fnvme-cli.git plugins/solidigm: Formated log page directory table consistently with "nvme list" format. Signed-off-by: leonardo.da.cunha --- diff --git a/plugins/solidigm/solidigm-log-page-dir.c b/plugins/solidigm/solidigm-log-page-dir.c index 4972b888..111a4337 100644 --- a/plugins/solidigm/solidigm-log-page-dir.c +++ b/plugins/solidigm/solidigm-log-page-dir.c @@ -9,6 +9,7 @@ #include #include +#include #include "common.h" #include "nvme-print.h" @@ -18,6 +19,8 @@ #define MIN_VENDOR_LID 0xC0 #define SOLIDIGM_MAX_UUID 2 +static const char dash[100] = {[0 ... 99] = '-'}; + struct lid_dir { struct __packed { bool supported; @@ -180,10 +183,8 @@ static struct lid_dir *get_ocp_lids(struct nvme_supported_log_pages *supported) static void supported_log_pages_normal(struct lid_dir *lid_dir[SOLIDIGM_MAX_UUID + 1]) { - printf("Log Page Directory:\n"); - printf("-----------------------------------------------------------------\n"); - printf("| %-5s| %-42s| %-11s|\n", "LID", "Description", "UUID Index"); - printf("-----------------------------------------------------------------\n"); + printf("%-5s %-4s %-42s\n", "uuidx", "LID", "Description"); + printf("%-.5s %-.4s %-.42s\n", dash, dash, dash); for (int uuid_index = 0; uuid_index <= SOLIDIGM_MAX_UUID; uuid_index++) { if (!lid_dir[uuid_index]) @@ -193,19 +194,15 @@ static void supported_log_pages_normal(struct lid_dir *lid_dir[SOLIDIGM_MAX_UUID if (!lid_dir[uuid_index]->lid[lid].supported) continue; - printf("| 0x%-3.02x", le32_to_cpu(lid)); - printf("| %-42s", lid_dir[uuid_index]->lid[lid].str); - printf("| %-11d|\n", le32_to_cpu(uuid_index)); + printf("%-5d 0x%02x %s\n", le32_to_cpu(uuid_index), le32_to_cpu(lid), + lid_dir[uuid_index]->lid[lid].str); } } - - printf("-----------------------------------------------------------------\n"); } static void supported_log_pages_json(struct lid_dir *lid_dir[SOLIDIGM_MAX_UUID + 1]) { - struct json_object *root = json_create_object(); - struct json_object *supported_arry = json_create_array(); + struct json_object *root = json_create_array(); for (int uuid_index = 0; uuid_index <= SOLIDIGM_MAX_UUID; uuid_index++) { if (!lid_dir[uuid_index]) @@ -217,16 +214,14 @@ static void supported_log_pages_json(struct lid_dir *lid_dir[SOLIDIGM_MAX_UUID + struct json_object *lid_obj = json_create_object(); + json_object_add_value_uint(lid_obj, "uuidx", le32_to_cpu(uuid_index)); json_object_add_value_uint(lid_obj, "lid", le32_to_cpu(lid)); json_object_add_value_string(lid_obj, "description", lid_dir[uuid_index]->lid[lid].str); - json_object_add_value_uint(lid_obj, "uuid index", le32_to_cpu(uuid_index)); - json_array_add_value_object(supported_arry, lid_obj); + json_array_add_value_object(root, lid_obj); } } - json_object_add_value_array(root, "supported", supported_arry); - json_print_object(root, NULL); json_free_object(root); printf("\n"); @@ -236,7 +231,7 @@ int solidigm_get_log_page_directory_log(int argc, char **argv, struct command *c struct plugin *plugin) { const int NO_UUID_INDEX = 0; - const char *description = "Retrieves the list of supported log pages."; + const char *description = "Retrieves list of supported log pages for each UUID index."; char *format = "normal"; OPT_ARGS(options) = { @@ -294,10 +289,12 @@ int solidigm_get_log_page_directory_log(int argc, char **argv, struct command *c supported_log_pages_json(lid_dirs); } else { fprintf(stderr, "Error: Invalid output format specified: %s.\n", format); - return -EINVAL; + err = -EINVAL; } } + /* Redundant close() to make static code analysis happy */ + close(dev->direct.fd); dev_close(dev); return err; }