]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
seagate: enable seagate-nvme.c build without json-c dependencies checking
authorTokunori Ikegami <ikegami.t@gmail.com>
Sat, 21 Dec 2024 07:49:12 +0000 (16:49 +0900)
committerDaniel Wagner <wagi@monom.org>
Fri, 3 Jan 2025 09:21:08 +0000 (10:21 +0100)
Only build json print codes with CONFIG_JSONC build option instead.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
plugins/meson.build
plugins/seagate/seagate-nvme.c
util/json.h

index 3d2a56ca521cab6cdf02c81f52ebca76f94b46ea..7eaa35a794ff7dc1c96c4c6b0da0064cf3f3a3ef 100644 (file)
@@ -2,7 +2,6 @@
 
 if json_c_dep.found()
   sources += [
-    'plugins/seagate/seagate-nvme.c',
     'plugins/solidigm/solidigm-nvme.c',
     'plugins/ssstc/ssstc-nvme.c',
     'plugins/wdc/wdc-nvme.c',
@@ -27,6 +26,7 @@ sources += [
   'plugins/netapp/netapp-nvme.c',
   'plugins/nvidia/nvidia-nvme.c',
   'plugins/scaleflux/sfx-nvme.c',
+  'plugins/seagate/seagate-nvme.c',
   'plugins/shannon/shannon-nvme.c',
   'plugins/toshiba/toshiba-nvme.c',
   'plugins/transcend/transcend-nvme.c',
index 887e5bc05b8da154813f8d1c332c34729a0e49b7..96bbbb6349e79dd07806bf04155aba564019c869 100644 (file)
@@ -1078,6 +1078,7 @@ static int temp_stats(int argc, char **argv, struct command *cmd, struct plugin
        int index;
        const char *desc = "Retrieve Seagate Temperature Stats information for the given device ";
        const char *output_format = "output in binary format";
+       nvme_print_flags_t flags;
        unsigned int temperature = 0, PcbTemp = 0, SocTemp = 0, scCurrentTemp = 0, scMaxTemp = 0;
        unsigned long long maxTemperature = 0, MaxSocTemp = 0;
        struct nvme_dev *dev;
@@ -1100,7 +1101,13 @@ static int temp_stats(int argc, char **argv, struct command *cmd, struct plugin
                return -1;
        }
 
-       if (strcmp(cfg.output_format, "json"))
+       err = validate_output_format(cfg.output_format, &flags);
+       if (err < 0) {
+               nvme_show_error("Invalid output format");
+               return err;
+       }
+
+       if (flags & NORMAL)
                printf("Seagate Temperature Stats Information :\n");
        /*STEP-1 : Get Current Temperature from SMART */
        err = nvme_get_log_smart(dev_fd(dev), 0xffffffff, false, &smart_log);
@@ -1111,7 +1118,7 @@ static int temp_stats(int argc, char **argv, struct command *cmd, struct plugin
                PcbTemp = PcbTemp ? PcbTemp - 273 : 0;
                SocTemp = le16_to_cpu(smart_log.temp_sensor[1]);
                SocTemp = SocTemp ? SocTemp - 273 : 0;
-               if (strcmp(cfg.output_format, "json")) {
+               if (flags & NORMAL) {
                        printf("%-20s : %u C\n", "Current Temperature", temperature);
                        printf("%-20s : %u C\n", "Current PCB Temperature", PcbTemp);
                        printf("%-20s : %u C\n", "Current SOC Temperature", SocTemp);
@@ -1126,14 +1133,14 @@ static int temp_stats(int argc, char **argv, struct command *cmd, struct plugin
                        if (ExtdSMARTInfo.vendorData[index].AttributeNumber == VS_ATTR_ID_MAX_LIFE_TEMPERATURE) {
                                maxTemperature = smart_attribute_vs(ExtdSMARTInfo.Version, ExtdSMARTInfo.vendorData[index]);
                                maxTemperature = maxTemperature ? maxTemperature - 273 : 0;
-                               if (strcmp(cfg.output_format, "json"))
+                               if (flags & NORMAL)
                                        printf("%-20s : %d C\n", "Highest Temperature", (unsigned int)maxTemperature);
                        }
 
                        if (ExtdSMARTInfo.vendorData[index].AttributeNumber == VS_ATTR_ID_MAX_SOC_LIFE_TEMPERATURE) {
                                MaxSocTemp = smart_attribute_vs(ExtdSMARTInfo.Version, ExtdSMARTInfo.vendorData[index]);
                                MaxSocTemp = MaxSocTemp ? MaxSocTemp - 273 : 0;
-                               if (strcmp(cfg.output_format, "json"))
+                               if (flags & NORMAL)
                                        printf("%-20s : %d C\n", "Max SOC Temperature", (unsigned int)MaxSocTemp);
                        }
                }
@@ -1155,7 +1162,7 @@ static int temp_stats(int argc, char **argv, struct command *cmd, struct plugin
                printf("%-20s : %d C\n", "Super-cap Max Temperature", scMaxTemp);
        }
 
-       if (!strcmp(cfg.output_format, "json"))
+       if (flags & JSON)
                json_temp_stats(temperature, PcbTemp, SocTemp, maxTemperature, MaxSocTemp, cf_err, scCurrentTemp, scMaxTemp);
 
        dev_close(dev);
@@ -1248,6 +1255,7 @@ static int vs_pcie_error_log(int argc, char **argv, struct command *cmd, struct
        const char *desc = "Retrieve Seagate PCIe error counters for the given device ";
        const char *output_format = "output in binary format";
        int err;
+       nvme_print_flags_t flags;
        struct config {
                char *output_format;
        };
@@ -1267,13 +1275,19 @@ static int vs_pcie_error_log(int argc, char **argv, struct command *cmd, struct
                return -1;
        }
 
-       if (strcmp(cfg.output_format, "json"))
+       err = validate_output_format(cfg.output_format, &flags);
+       if (err < 0) {
+               nvme_show_error("Invalid output format");
+               return err;
+       }
+
+       if (flags & NORMAL)
                printf("Seagate PCIe error counters Information :\n");
 
        err = nvme_get_log_simple(dev_fd(dev), 0xCB,
                                  sizeof(pcieErrorLog), &pcieErrorLog);
        if (!err) {
-               if (strcmp(cfg.output_format, "json"))
+               if (flags & NORMAL)
                        print_vs_pcie_error_log(pcieErrorLog);
                else
                        json_vs_pcie_error_log(pcieErrorLog);
@@ -1386,6 +1400,7 @@ static int stx_vs_fw_activate_history(int argc, char **argv, struct command *cmd
        const char *desc = "Retrieve FW Activate History for Seagate device ";
        const char *output_format = "output in binary format";
        int err;
+       nvme_print_flags_t flags;
        struct config {
                char *output_format;
        };
@@ -1405,16 +1420,21 @@ static int stx_vs_fw_activate_history(int argc, char **argv, struct command *cmd
                return -1;
        }
 
-       if (strcmp(cfg.output_format, "json"))
+       err = validate_output_format(cfg.output_format, &flags);
+       if (err < 0) {
+               nvme_show_error("Invalid output format");
+               return err;
+       }
+
+       if (flags & NORMAL)
                printf("Seagate FW Activation History Information :\n");
 
        err = nvme_get_log_simple(dev_fd(dev), 0xC2, sizeof(fwActivHis), &fwActivHis);
        if (!err) {
-               if (strcmp(cfg.output_format, "json"))
+               if (flags & NORMAL)
                        print_stx_vs_fw_activate_history(fwActivHis);
                else
                        json_stx_vs_fw_activate_history(fwActivHis);
-
        } else if (err > 0) {
                nvme_show_status(err);
        }
index 07dbfa44d5d11214ac17090015ff1845379523dc..42f3b6baa44d6e91c4507bd68df6a9607b32eb28 100644 (file)
@@ -56,11 +56,14 @@ struct json_object;
 
 #define json_object_add_value_string(o, k, v)
 #define json_create_object(o) NULL
+#define json_create_array(a) NULL
 #define json_free_object(o) ((void)(o))
 #define json_object_add_value_uint(o, k, v)
-#define json_object_add_value_int(o, k, v)
-#define json_print_object(o, u)
+#define json_object_add_value_int(o, k, v) ((void)(v))
 #define json_object_add_value_double(o, k, v)
+#define json_object_add_value_array(o, k, v) ((void)(v))
 #define json_object_add_value_object(o, k, v) ((void)(v))
+#define json_array_add_value_object(o, k) ((void)(k))
+#define json_print_object(o, u) ((void)(o))
 #endif /* CONFIG_JSONC */
 #endif /* __JSON__H */