]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme-print-json: Add select_result print function
authorTokunori Ikegami <ikegami.t@gmail.com>
Mon, 9 Oct 2023 12:24:56 +0000 (21:24 +0900)
committerDaniel Wagner <wagi@monom.org>
Thu, 12 Oct 2023 06:27:15 +0000 (08:27 +0200)
Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
nvme-print-json.c
nvme-print.c

index 20900f675a360ed2719c33ad50dad6dba45c6e53..f88093fdc5f8f40317d47c0b27b53f169ca79dcb 100644 (file)
@@ -621,6 +621,23 @@ static void json_ana_log(struct nvme_ana_log *ana_log, const char *devname,
        json_print(root);
 }
 
+static void json_select_result(__u32 result)
+{
+       struct json_object *root = json_create_object();
+       struct json_object *feature = json_create_array();
+
+       if (result & 0x1)
+               json_array_add_value_string(feature, "saveable");
+       if (result & 0x2)
+               json_array_add_value_string(feature, "per-namespace");
+       if (result & 0x4)
+               json_array_add_value_string(feature, "changeable");
+
+       json_object_add_value_array(root, "Feature", feature);
+
+       json_print(root);
+}
+
 static void json_self_test_log(struct nvme_self_test_log *self_test, __u8 dst_entries,
                               __u32 size, const char *devname)
 {
@@ -3030,7 +3047,7 @@ static struct print_ops json_print_ops = {
        .resv_report                    = json_nvme_resv_report,
        .sanitize_log_page              = json_sanitize_log,
        .secondary_ctrl_list            = json_nvme_list_secondary_ctrl,
-       .select_result                  = NULL,
+       .select_result                  = json_select_result,
        .self_test_log                  = json_self_test_log,
        .single_property                = NULL,
        .smart_log                      = json_smart_log,
index 89d02c1ceeb485a2f615ed0e6a5a1e7daccbf2e2..41bfec0c9669357de7fcdbc88ec118193b342955 100644 (file)
@@ -29,7 +29,7 @@ static struct print_ops *nvme_print_ops(enum nvme_print_flags flags)
 {
        struct print_ops *ops = NULL;
 
-       if (flags & JSON)
+       if (flags & JSON || nvme_is_output_format_json())
                ops = nvme_get_json_print_ops(flags);
        else if (flags & BINARY)
                ops = nvme_get_binary_print_ops(flags);