]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme-print-json: Change to report feature select in array
authorTokunori Ikegami <ikegami.t@gmail.com>
Fri, 3 Nov 2023 14:33:20 +0000 (23:33 +0900)
committerDaniel Wagner <wagi@monom.org>
Thu, 16 Nov 2023 10:05:54 +0000 (11:05 +0100)
Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
nvme-print-json.c
nvme-print-stdout.c
nvme-print.c
nvme-print.h
nvme.c
plugins/ocp/ocp-nvme.c

index 95c89aae0a3a9389c7785bcbccd055f4d44134ec..dae6ec3756fcd6447e55f7a4bb1721b526044c84 100644 (file)
@@ -724,9 +724,10 @@ static void json_ana_log(struct nvme_ana_log *ana_log, const char *devname,
        json_print(r);
 }
 
-static void json_select_result(__u32 result)
+static void json_select_result(enum nvme_features_id fid, __u32 result)
 {
-       struct json_object *r = json_create_object();
+       struct json_object *r = json_r ? json_r : json_create_object();
+       char json_str[STR_LEN];
        struct json_object *feature = json_create_array();
 
        if (result & 0x1)
@@ -736,9 +737,10 @@ static void json_select_result(__u32 result)
        if (result & 0x4)
                array_add_str(feature, "changeable");
 
-       obj_add_array(r, "Feature", feature);
+       sprintf(json_str, "Feature: %#0*x: select", fid ? 4 : 2, fid);
+       obj_add_array(r, json_str, feature);
 
-       json_print(r);
+       obj_print(r);
 }
 
 static void json_self_test_log(struct nvme_self_test_log *self_test, __u8 dst_entries,
index 1b51edb4d642644b9d8ddb2950f656cedc80deac..a6a49f37e8442bc8c91c0dec711fa15f3f9a2722 100644 (file)
@@ -4113,7 +4113,7 @@ static void stdout_sanitize_log(struct nvme_sanitize_log_page *sanitize,
                le32_to_cpu(sanitize->etcend));
 }
 
-static void stdout_select_result(__u32 result)
+static void stdout_select_result(enum nvme_features_id fid, __u32 result)
 {
        if (result & 0x1)
                printf("  Feature is saveable\n");
index e1efe496f04eccf2c6b5e59a6908c6c531896d17..1086aad2a9bae40726533a3831585c92a9304f5c 100644 (file)
@@ -379,7 +379,7 @@ void nvme_show_relatives(const char *name)
 
 void d(unsigned char *buf, int len, int width, int group)
 {
-       nvme_print(d, 0, buf, len, width, group);
+       nvme_print(d, NORMAL, buf, len, width, group);
 }
 
 void d_raw(unsigned char *buf, unsigned len)
@@ -789,9 +789,9 @@ const char *nvme_select_to_string(int sel)
        }
 }
 
-void nvme_show_select_result(__u32 result)
+void nvme_show_select_result(enum nvme_features_id fid, __u32 result)
 {
-       nvme_print(select_result, 0, result);
+       nvme_print(select_result, NORMAL, fid, result);
 }
 
 const char *nvme_feature_lba_type_to_string(__u8 type)
@@ -887,7 +887,7 @@ const char *nvme_plm_window_to_string(__u32 plm)
 
 void nvme_show_lba_status_info(__u32 result)
 {
-       nvme_print(lba_status_info, 0, result);
+       nvme_print(lba_status_info, NORMAL, result);
 }
 
 const char *nvme_host_metadata_type_to_string(enum nvme_features_id fid,
@@ -952,12 +952,12 @@ const char *nvme_host_metadata_type_to_string(enum nvme_features_id fid,
 
 void nvme_feature_show(enum nvme_features_id fid, int sel, unsigned int result)
 {
-       nvme_print(show_feature, 0, fid, sel, result);
+       nvme_print(show_feature, NORMAL, fid, sel, result);
 }
 
 void nvme_feature_show_fields(enum nvme_features_id fid, unsigned int result, unsigned char *buf)
 {
-       nvme_print(show_feature_fields, 0, fid, result, buf);
+       nvme_print(show_feature_fields, NORMAL, fid, result, buf);
 }
 
 void nvme_show_lba_status(struct nvme_lba_status *list, unsigned long len,
@@ -1009,7 +1009,7 @@ void nvme_generic_full_path(nvme_ns_t n, char *path, size_t len)
 
 void nvme_show_list_item(nvme_ns_t n)
 {
-       nvme_print(list_item, 0, n);
+       nvme_print(list_item, NORMAL, n);
 }
 
 void nvme_show_list_items(nvme_root_t r, enum nvme_print_flags flags)
index 73bd07d327d5223500e68a561cac3ab1c3f68a7b..4533474eb304b03d0f21245bc518a50e99ac0a80 100644 (file)
@@ -65,7 +65,7 @@ struct print_ops {
        void (*resv_report)(struct nvme_resv_status *status, int bytes, bool eds);
        void (*sanitize_log_page)(struct nvme_sanitize_log_page *sanitize_log, const char *devname);
        void (*secondary_ctrl_list)(const struct nvme_secondary_ctrl_list *sc_list, __u32 count);
-       void (*select_result)(__u32 result);
+       void (*select_result)(enum nvme_features_id fid, __u32 result);
        void (*self_test_log)(struct nvme_self_test_log *self_test, __u8 dst_entries, __u32 size, const char *devname);
        void (*single_property)(int offset, uint64_t value64);
        void (*smart_log)(struct nvme_smart_log *smart, unsigned int nsid, const char *devname);
@@ -77,8 +77,8 @@ struct print_ops {
        void (*zns_id_ctrl)(struct nvme_zns_id_ctrl *ctrl);
        void (*zns_id_ns)(struct nvme_zns_id_ns *ns, struct nvme_id_ns *id_ns);
        void (*zns_report_zones)(void *report, __u32 descs, __u8 ext_size, __u32 report_size, struct json_object *zone_list);
-       void (*show_feature)(enum nvme_features_id id, int sel, unsigned int result);
-       void (*show_feature_fields)(enum nvme_features_id id, unsigned int result, unsigned char *buf);
+       void (*show_feature)(enum nvme_features_id fid, int sel, unsigned int result);
+       void (*show_feature_fields)(enum nvme_features_id fid, unsigned int result, unsigned char *buf);
        void (*id_ctrl_rpmbs)(__le32 ctrl_rpmbs);
        void (*lba_range)(struct nvme_lba_range_type *lbrt, int nr_ranges);
        void (*lba_status_info)(__u32 result);
@@ -238,7 +238,7 @@ void nvme_feature_show(enum nvme_features_id fid, int sel, unsigned int result);
 void nvme_feature_show_fields(enum nvme_features_id fid, unsigned int result, unsigned char *buf);
 void nvme_directive_show(__u8 type, __u8 oper, __u16 spec, __u32 nsid, __u32 result,
        void *buf, __u32 len, enum nvme_print_flags flags);
-void nvme_show_select_result(__u32 result);
+void nvme_show_select_result(enum nvme_features_id fid, __u32 result);
 
 void nvme_show_zns_id_ctrl(struct nvme_zns_id_ctrl *ctrl,
                           enum nvme_print_flags flags);
diff --git a/nvme.c b/nvme.c
index cfc701bbb102a4ad340d7d21b4aabe72000657a8..fb0afca1d3d85a2135079536fcdda8a2c4accdaf 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -4572,7 +4572,7 @@ static void get_feature_id_print(struct feat_cfg cfg, int err, __u32 result,
                if (!cfg.raw_binary || !buf) {
                        nvme_feature_show(cfg.feature_id, cfg.sel, result);
                        if (cfg.sel == 3)
-                               nvme_show_select_result(result);
+                               nvme_show_select_result(cfg.feature_id, result);
                        else if (cfg.human_readable)
                                nvme_feature_show_fields(cfg.feature_id, result,
                                                         buf);
index 34c395e3c8752d8bea72f7a62bd091c9c20189ed..fcb8819cfe17e92ac62f8cc98d4638774992af06 100644 (file)
@@ -707,7 +707,7 @@ static int eol_plp_failure_mode_get(struct nvme_dev *dev, const __u32 nsid,
                                 nvme_select_to_string(sel),
                                 eol_plp_failure_mode_to_string(result));
                if (sel == NVME_GET_FEATURES_SEL_SUPPORTED)
-                       nvme_show_select_result(result);
+                       nvme_show_select_result(fid, result);
        } else {
                nvme_show_error("Could not get feature: %#0*x.", fid ? 4 : 2, fid);
        }