]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
amzn: enable amzn-nvme.c build without json-c dependencies checking
authorTokunori Ikegami <ikegami.t@gmail.com>
Wed, 18 Dec 2024 15:51:07 +0000 (00:51 +0900)
committerDaniel Wagner <wagi@monom.org>
Fri, 20 Dec 2024 08:32:28 +0000 (09:32 +0100)
Only build json print codes with CONFIG_JSONC build option instead.

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

index 54afb0dde764041b274748d0e1b8490bd8976dbf..6038171b3805b4a219f042e3a8077c0f197d43d8 100644 (file)
@@ -10,6 +10,7 @@
 #include "nvme.h"
 #include "libnvme.h"
 #include "plugin.h"
+#include "nvme-print.h"
 
 #define CREATE_CMD
 #include "amzn-nvme.h"
 #define AMZN_NVME_STATS_LOGPAGE_ID 0xD0
 #define AMZN_NVME_STATS_MAGIC 0x3C23B510
 
+#ifdef CONFIG_JSONC
 #define array_add_obj json_array_add_value_object
 #define obj_add_array json_object_add_value_array
 #define obj_add_obj json_object_add_value_object
 #define obj_add_uint json_object_add_value_uint
 #define obj_add_uint64 json_object_add_value_uint64
+#endif /* CONFIG_JSONC */
 
 struct nvme_vu_id_ctrl_field {
        __u8                    bdev[32];
@@ -112,6 +115,7 @@ static void amzn_print_latency_histogram(struct amzn_latency_histogram *hist)
        printf("=================================\n\n");
 }
 
+#ifdef CONFIG_JSONC
 static void amzn_json_add_histogram(struct json_object *root,
                                    struct amzn_latency_histogram *hist)
 {
@@ -165,6 +169,7 @@ static void amzn_print_json_stats(struct amzn_latency_log_page *log)
 
        json_free_object(root);
 }
+#endif /* CONFIG_JSONC */
 
 static void amzn_print_normal_stats(struct amzn_latency_log_page *log)
 {
@@ -205,6 +210,8 @@ static int get_stats(int argc, char **argv, struct command *cmd,
        struct nvme_dev *dev;
        struct amzn_latency_log_page log = { 0 };
        int rc;
+       nvme_print_flags_t flags;
+       int err;
 
        struct config {
                char *output_format;
@@ -253,9 +260,17 @@ static int get_stats(int argc, char **argv, struct command *cmd,
                return -ENOTSUP;
        }
 
+       err = validate_output_format(cfg.output_format, &flags);
+       if (err < 0) {
+               nvme_show_error("Invalid output format");
+               return err;
+       }
+
+#ifdef CONFIG_JSONC
        if (!strcmp(cfg.output_format, "json"))
                amzn_print_json_stats(&log);
        else
+#endif /* CONFIG_JSONC */
                amzn_print_normal_stats(&log);
 
        return 0;
index a0f26fca5adeef2551ad947d8cd1f0ec5c82fe13..174f5ba1d32d3ad17f52bd7384a9a027c57265b9 100644 (file)
@@ -2,7 +2,6 @@
 
 if json_c_dep.found()
   sources += [
-    'plugins/amzn/amzn-nvme.c',
     'plugins/dapustor/dapustor-nvme.c',
     'plugins/dell/dell-nvme.c',
     'plugins/fdp/fdp.c',
@@ -23,6 +22,7 @@ if json_c_dep.found()
 endif
 
 sources += [
+  'plugins/amzn/amzn-nvme.c',
   'plugins/dera/dera-nvme.c',
   'plugins/innogrit/innogrit-nvme.c',
   'plugins/inspur/inspur-nvme.c',