Skip to content

Commit

Permalink
micron: enable micron-nvme.c build without json-c dependencies checking
Browse files Browse the repository at this point in the history
Only build json print codes with CONFIG_JSONC build option instead.

Signed-off-by: Tokunori Ikegami <[email protected]>
  • Loading branch information
ikegami-t authored and igaw committed Dec 20, 2024
1 parent b368e36 commit b7a7cd0
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
2 changes: 1 addition & 1 deletion plugins/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

if json_c_dep.found()
sources += [
'plugins/micron/micron-nvme.c',
'plugins/nbft/nbft-plugin.c',
'plugins/netapp/netapp-nvme.c',
'plugins/nvidia/nvidia-nvme.c',
Expand All @@ -27,6 +26,7 @@ sources += [
'plugins/inspur/inspur-nvme.c',
'plugins/intel/intel-nvme.c',
'plugins/memblaze/memblaze-nvme.c',
'plugins/micron/micron-nvme.c',
'plugins/shannon/shannon-nvme.c',
'plugins/toshiba/toshiba-nvme.c',
'plugins/transcend/transcend-nvme.c',
Expand Down
81 changes: 81 additions & 0 deletions plugins/micron/micron-nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -737,10 +737,13 @@ static int micron_temp_stats(int argc, char **argv, struct command *cmd,
struct format cfg = {
.fmt = "normal",
};
#ifdef CONFIG_JSONC
bool is_json = false;
struct json_object *root;
struct json_object *logPages;
#endif /* CONFIG_JSONC */
struct nvme_dev *dev;
nvme_print_flags_t flags;

OPT_ARGS(opts) = {
OPT_FMT("format", 'f', &cfg.fmt, fmt),
Expand All @@ -753,8 +756,16 @@ static int micron_temp_stats(int argc, char **argv, struct command *cmd,
return -1;
}

err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}

#ifdef CONFIG_JSONC
if (!strcmp(cfg.fmt, "json"))
is_json = true;
#endif /* CONFIG_JSONC */

err = nvme_get_log_smart(dev_fd(dev), 0xffffffff, false, &smart_log);
if (!err) {
Expand All @@ -764,6 +775,7 @@ static int micron_temp_stats(int argc, char **argv, struct command *cmd,
tempSensors[i] = le16_to_cpu(smart_log.temp_sensor[i]);
tempSensors[i] = tempSensors[i] ? tempSensors[i] - 273 : 0;
}
#ifdef CONFIG_JSONC
if (is_json) {
struct json_object *stats = json_create_object();
char tempstr[64] = { 0 };
Expand All @@ -786,11 +798,14 @@ static int micron_temp_stats(int argc, char **argv, struct command *cmd,
printf("\n");
json_free_object(root);
} else {
#endif /* CONFIG_JSONC */
printf("Micron temperature information:\n");
printf("%-10s : %u C\n", "Current Composite Temperature", temperature);
for (i = 0; i < SensorCount && tempSensors[i]; i++)
printf("%-10s%d : %u C\n", "Temperature Sensor #", i + 1, tempSensors[i]);
#ifdef CONFIG_JSONC
}
#endif /* CONFIG_JSONC */
}
dev_close(dev);
return err;
Expand All @@ -812,7 +827,9 @@ static int micron_pcie_stats(int argc, char **argv,
struct nvme_passthru_cmd admin_cmd = { 0 };
enum eDriveModel eModel = UNKNOWN_MODEL;
char *res;
#ifdef CONFIG_JSONC
bool is_json = true;
#endif /* CONFIG_JSONC */
bool counters = false;
struct format {
char *fmt;
Expand Down Expand Up @@ -840,6 +857,7 @@ static int micron_pcie_stats(int argc, char **argv,
__u16 ecrc_error;
__u16 unsupported_request_error;
} pcie_error_counters = { 0 };
nvme_print_flags_t flags;

struct {
char *err;
Expand Down Expand Up @@ -905,8 +923,16 @@ static int micron_pcie_stats(int argc, char **argv,
goto out;
}

err = validate_output_format(cfg.fmt, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}

#ifdef CONFIG_JSONC
if (!strcmp(cfg.fmt, "normal"))
is_json = false;
#endif /* CONFIG_JSONC */

if (eModel == M5407) {
admin_cmd.opcode = 0xD6;
Expand Down Expand Up @@ -987,6 +1013,7 @@ static int micron_pcie_stats(int argc, char **argv,
uncorrectable_errors = (__u32)strtol(uncorrectable, NULL, 16);

print_stats:
#ifdef CONFIG_JSONC
if (is_json) {
struct json_object *root = json_create_object();
struct json_object *pcieErrors = json_create_array();
Expand All @@ -1009,6 +1036,9 @@ static int micron_pcie_stats(int argc, char **argv,
printf("\n");
json_free_object(root);
} else if (counters == true) {
#else /* CONFIG_JSONC */
if (counters == true) {
#endif /* CONFIG_JSONC */
__u8 *pcounter = (__u8 *)&pcie_error_counters;

for (i = 0; i < ARRAY_SIZE(pcie_correctable_errors); i++)
Expand Down Expand Up @@ -1324,73 +1354,90 @@ fb_log_page[] = {

static void print_smart_cloud_health_log(__u8 *buf, bool is_json)
{
#ifdef CONFIG_JSONC
struct json_object *root;
struct json_object *logPages;
#endif /* CONFIG_JSONC */
struct json_object *stats = NULL;
int field_count = ARRAY_SIZE(ocp_c0_log_page);

#ifdef CONFIG_JSONC
if (is_json) {
root = json_create_object();
stats = json_create_object();
logPages = json_create_array();
json_object_add_value_array(root, "OCP SMART Cloud Health Log: 0xC0",
logPages);
}
#endif /* CONFIG_JSONC */

generic_structure_parser(buf, ocp_c0_log_page, field_count, stats, 0, NULL);

#ifdef CONFIG_JSONC
if (is_json) {
json_array_add_value_object(logPages, stats);
json_print_object(root, NULL);
printf("\n");
json_free_object(root);
}
#endif /* CONFIG_JSONC */
}

static void print_nand_stats_fb(__u8 *buf, __u8 *buf2, __u8 nsze, bool is_json, __u8 spec)
{
#ifdef CONFIG_JSONC
struct json_object *root;
struct json_object *logPages;
#endif /* CONFIG_JSONC */
struct json_object *stats = NULL;
int field_count = ARRAY_SIZE(fb_log_page);

#ifdef CONFIG_JSONC
if (is_json) {
root = json_create_object();
stats = json_create_object();
logPages = json_create_array();
json_object_add_value_array(root, "Extended Smart Log Page : 0xFB",
logPages);
}
#endif /* CONFIG_JSONC */

generic_structure_parser(buf, fb_log_page, field_count, stats, spec, NULL);

/* print last three entries from D0 log page */
if (buf2) {
init_d0_log_page(buf2, nsze);

#ifdef CONFIG_JSONC
if (is_json) {
for (int i = 0; i < 7; i++)
json_object_add_value_string(stats,
d0_log_page[i].field,
d0_log_page[i].datastr);
} else {
#endif /* CONFIG_JSONC */
for (int i = 0; i < 7; i++)
printf("%-40s : %s\n", d0_log_page[i].field, d0_log_page[i].datastr);
#ifdef CONFIG_JSONC
}
#endif /* CONFIG_JSONC */
}

#ifdef CONFIG_JSONC
if (is_json) {
json_array_add_value_object(logPages, stats);
json_print_object(root, NULL);
printf("\n");
json_free_object(root);
}
#endif /* CONFIG_JSONC */
}

static void print_nand_stats_d0(__u8 *buf, __u8 oacs, bool is_json)
{
init_d0_log_page(buf, oacs);

#ifdef CONFIG_JSONC
if (is_json) {
struct json_object *root = json_create_object();
struct json_object *stats = json_create_object();
Expand All @@ -1410,9 +1457,12 @@ static void print_nand_stats_d0(__u8 *buf, __u8 oacs, bool is_json)
printf("\n");
json_free_object(root);
} else {
#endif /* CONFIG_JSONC */
for (int i = 0; i < 7; i++)
printf("%-40s : %s\n", d0_log_page[i].field, d0_log_page[i].datastr);
#ifdef CONFIG_JSONC
}
#endif /* CONFIG_JSONC */
}

static bool nsze_from_oacs; /* read nsze for now from idd[4059] */
Expand Down Expand Up @@ -1502,28 +1552,36 @@ static int micron_nand_stats(int argc, char **argv,

static void print_ext_smart_logs_e1(__u8 *buf, bool is_json)
{
#ifdef CONFIG_JSONC
struct json_object *root;
struct json_object *logPages;
#endif /* CONFIG_JSONC */
struct json_object *stats = NULL;
int field_count = ARRAY_SIZE(e1_log_page);

#ifdef CONFIG_JSONC
if (is_json) {
root = json_create_object();
stats = json_create_object();
logPages = json_create_array();
json_object_add_value_array(root, "SMART Extended Log:0xE1", logPages);
} else {
#endif /* CONFIG_JSONC */
printf("SMART Extended Log:0xE1\n");
#ifdef CONFIG_JSONC
}
#endif /* CONFIG_JSONC */

generic_structure_parser(buf, e1_log_page, field_count, stats, 0, NULL);

#ifdef CONFIG_JSONC
if (is_json) {
json_array_add_value_object(logPages, stats);
json_print_object(root, NULL);
printf("\n");
json_free_object(root);
}
#endif /* CONFIG_JSONC */
}

static int micron_smart_ext_log(int argc, char **argv,
Expand All @@ -1546,12 +1604,20 @@ static int micron_smart_ext_log(int argc, char **argv,
OPT_FMT("format", 'f', &cfg.fmt, fmt),
OPT_END()
};
nvme_print_flags_t flags;

err = parse_and_open(&dev, argc, argv, desc, opts);
if (err) {
printf("\nDevice not found\n");
return -1;
}

err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}

if (!strcmp(cfg.fmt, "normal"))
is_json = false;

Expand Down Expand Up @@ -1949,13 +2015,16 @@ static int micron_drive_info(int argc, char **argv, struct command *cmd,
unsigned char bs_ver_minor;
} dinfo = { 0 };
enum eDriveModel model = UNKNOWN_MODEL;
#ifdef CONFIG_JSONC
bool is_json = false;
struct json_object *root, *driveInfo;
#endif /* CONFIG_JSONC */
struct nvme_dev *dev;
struct format {
char *fmt;
};
int err = 0;
nvme_print_flags_t flags;

const char *fmt = "output format normal";
struct format cfg = {
Expand All @@ -1977,8 +2046,16 @@ static int micron_drive_info(int argc, char **argv, struct command *cmd,
return -1;
}

err = validate_output_format(cfg.fmt, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}

#ifdef CONFIG_JSONC
if (!strcmp(cfg.fmt, "json"))
is_json = true;
#endif /* CONFIG_JSONC */

if (model == M5407) {
admin_cmd.opcode = 0xD4,
Expand All @@ -2003,6 +2080,7 @@ static int micron_drive_info(int argc, char **argv, struct command *cmd,
dinfo.ftl_unit_size = ctrl.vs[822];
}

#ifdef CONFIG_JSONC
if (is_json) {
struct json_object *pinfo = json_create_object();
char tempstr[64] = { 0 };
Expand All @@ -2028,6 +2106,7 @@ static int micron_drive_info(int argc, char **argv, struct command *cmd,
printf("\n");
json_free_object(root);
} else {
#endif /* CONFIG_JSONC */
printf("Drive Hardware Version: %u.%u\n",
dinfo.hw_ver_major, dinfo.hw_ver_minor);

Expand All @@ -2037,7 +2116,9 @@ static int micron_drive_info(int argc, char **argv, struct command *cmd,
if (dinfo.bs_ver_major || dinfo.bs_ver_minor)
printf("Boot Spec.Version: %u.%u\n",
dinfo.bs_ver_major, dinfo.bs_ver_minor);
#ifdef CONFIG_JSONC
}
#endif /* CONFIG_JSONC */

dev_close(dev);
return 0;
Expand Down

0 comments on commit b7a7cd0

Please sign in to comment.