From 015508b831827d27b03f1dfa608a62ecdac5b47d Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Mon, 9 Oct 2023 21:24:56 +0900 Subject: [PATCH] nvme-print-json: Add select_result print function Signed-off-by: Tokunori Ikegami --- nvme-print-json.c | 19 ++++++++++++++++++- nvme-print.c | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/nvme-print-json.c b/nvme-print-json.c index 20900f67..f88093fd 100644 --- a/nvme-print-json.c +++ b/nvme-print-json.c @@ -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, diff --git a/nvme-print.c b/nvme-print.c index 89d02c1c..41bfec0c 100644 --- a/nvme-print.c +++ b/nvme-print.c @@ -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); -- 2.50.1