Skip to content

Commit

Permalink
micron: avoid sprinkling ifdefs
Browse files Browse the repository at this point in the history
Use empty json functions instead without json.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
  • Loading branch information
ikegami-t committed Dec 21, 2024
1 parent 213bdcd commit 68a8b96
Showing 1 changed file with 4 additions and 54 deletions.
58 changes: 4 additions & 54 deletions plugins/micron/micron-nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -737,11 +737,10 @@ 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;

Expand All @@ -762,10 +761,8 @@ static int micron_temp_stats(int argc, char **argv, struct command *cmd,
return err;
}

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

err = nvme_get_log_smart(dev_fd(dev), 0xffffffff, false, &smart_log);
if (!err) {
Expand All @@ -775,7 +772,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 @@ -798,14 +795,11 @@ 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 @@ -827,9 +821,7 @@ 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 @@ -929,10 +921,8 @@ static int micron_pcie_stats(int argc, char **argv,
return err;
}

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

if (eModel == M5407) {
admin_cmd.opcode = 0xD6;
Expand Down Expand Up @@ -1013,7 +1003,6 @@ 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 @@ -1036,9 +1025,6 @@ 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 @@ -1354,90 +1340,73 @@ 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 @@ -1457,12 +1426,9 @@ 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 @@ -1552,36 +1518,28 @@ 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 Down Expand Up @@ -2015,10 +1973,8 @@ 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;
Expand Down Expand Up @@ -2052,10 +2008,8 @@ static int micron_drive_info(int argc, char **argv, struct command *cmd,
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 @@ -2080,7 +2034,6 @@ 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 @@ -2106,7 +2059,6 @@ 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 @@ -2116,9 +2068,7 @@ 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 68a8b96

Please sign in to comment.