diff --git a/nvme-print-binary.c b/nvme-print-binary.c index 75592f6d24..71ec53127a 100644 --- a/nvme-print-binary.c +++ b/nvme-print-binary.c @@ -352,6 +352,14 @@ static void binary_power_meas_log(struct nvme_power_meas_log *log, __u32 size) d_raw((unsigned char *)log, size); } +static void binary_feature_show(enum nvme_features_id fid, int sel, + unsigned int result, void *buf, __u32 data_len) +{ + if (buf) { + d_raw(buf, data_len); + } +} + static struct print_ops binary_print_ops = { /* libnvme types.h print functions */ .ana_log = binary_ana_log, @@ -410,7 +418,7 @@ static struct print_ops binary_print_ops = { .zns_id_ctrl = binary_zns_id_ctrl, .zns_id_ns = binary_zns_id_ns, .zns_report_zones = binary_zns_report_zones, - .show_feature = NULL, + .show_feature = binary_feature_show, .show_feature_fields = NULL, .id_ctrl_rpmbs = NULL, .lba_range = NULL, diff --git a/nvme-print-json.c b/nvme-print-json.c index 51a8c4dd1c..717709a58b 100644 --- a/nvme-print-json.c +++ b/nvme-print-json.c @@ -4178,7 +4178,8 @@ static void json_feature_show_fields_power_meas(struct json_object *r, obj_add_uint(r, "Stop Measurement Time (SMT)", smt); } -static void json_feature_show(enum nvme_features_id fid, int sel, unsigned int result) +static void json_feature_show(enum nvme_features_id fid, int sel, + unsigned int result, void *buf, __u32 data_len) { struct json_object *r; char json_str[STR_LEN]; @@ -4192,6 +4193,11 @@ static void json_feature_show(enum nvme_features_id fid, int sel, unsigned int r obj_add_str(r, nvme_select_to_string(sel), json_str); obj_print(r); + + if (NVME_CHECK(sel, GET_FEATURES_SEL, SUPPORTED)) + json_select_result(fid, result); + else + json_feature_show_fields(fid, result, buf); } static void json_feature_show_fields(enum nvme_features_id fid, unsigned int result, diff --git a/nvme-print-stdout.c b/nvme-print-stdout.c index 58aad2c233..b48d929472 100644 --- a/nvme-print-stdout.c +++ b/nvme-print-stdout.c @@ -5227,10 +5227,18 @@ static void stdout_feat_host_id(unsigned int result, unsigned char *hostid) le64_to_cpu(*(__le64 *)hostid)); } -static void stdout_feature_show(enum nvme_features_id fid, int sel, unsigned int result) +static void stdout_feature_show(enum nvme_features_id fid, int sel, + unsigned int result, void *buf, __u32 data_len) { printf("get-feature:%#0*x (%s), %s value:%#0*x\n", fid ? 4 : 2, fid, nvme_feature_to_string(fid), nvme_select_to_string(sel), result ? 10 : 8, result); + + if (NVME_CHECK(sel, GET_FEATURES_SEL, SUPPORTED)) + stdout_select_result(fid, result); + else if (stdout_print_ops.flags & VERBOSE) + stdout_feature_show_fields(fid, result, buf); + else if (buf) + d(buf, data_len, 16, 1); } static void stdout_feature_show_fields(enum nvme_features_id fid, diff --git a/nvme-print.c b/nvme-print.c index caa3d8e14b..545854f308 100644 --- a/nvme-print.c +++ b/nvme-print.c @@ -1608,9 +1608,10 @@ const char *nvme_ipmsr_srs_to_string(__u8 srs) } } -void nvme_feature_show(enum nvme_features_id fid, int sel, unsigned int result) +void nvme_show_feature(enum nvme_features_id fid, int sel, unsigned int result, + void *buf, __u32 data_len, nvme_print_flags_t flags) { - nvme_print(show_feature, NORMAL, fid, sel, result); + nvme_print(show_feature, flags, fid, sel, result, buf, data_len); } void nvme_feature_show_fields(enum nvme_features_id fid, unsigned int result, unsigned char *buf) diff --git a/nvme-print.h b/nvme-print.h index 289f2e2d7e..bd88410d1f 100644 --- a/nvme-print.h +++ b/nvme-print.h @@ -85,7 +85,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 fid, int sel, unsigned int result); + void (*show_feature)(enum nvme_features_id fid, int sel, + unsigned int result, void *buf, __u32 data_len); 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); @@ -263,7 +264,8 @@ void nvme_show_topology(struct libnvme_global_ctx *ctx, nvme_print_flags_t flags); void nvme_show_topology_tabular(struct libnvme_global_ctx *ctx, nvme_print_flags_t flags); -void nvme_feature_show(enum nvme_features_id fid, int sel, unsigned int result); +void nvme_show_feature(enum nvme_features_id fid, int sel, unsigned int result, + void *buf, __u32 data_len, nvme_print_flags_t flags); 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, __u64 result, void *buf, __u32 len, nvme_print_flags_t flags); diff --git a/nvme.c b/nvme.c index c074b4f962..4e44aba838 100644 --- a/nvme.c +++ b/nvme.c @@ -4838,29 +4838,19 @@ static int filter_out_flags(int status) static void get_feature_id_print(struct feat_cfg cfg, int err, __u64 result, void *buf, nvme_print_flags_t flags) { - int status = filter_out_flags(err); - int verbose = flags & VERBOSE; + int status = err > 0 ? filter_out_flags(err) : err; enum nvme_status_type type = NVME_STATUS_TYPE_NVME; - if (!err) { - if (!cfg.raw_binary || !buf) { - nvme_feature_show(cfg.feature_id, cfg.sel, result); - if (NVME_CHECK(cfg.sel, GET_FEATURES_SEL, SUPPORTED)) - nvme_show_select_result(cfg.feature_id, result); - else if (verbose || !strcmp(nvme_args.output_format, "json")) - nvme_feature_show_fields(cfg.feature_id, result, buf); - else if (buf) - d(buf, cfg.data_len, 16, 1); - } else if (buf) { - d_raw(buf, cfg.data_len); - } - } else if (err > 0) { - if (!nvme_status_equals(status, type, NVME_SC_INVALID_FIELD) && - !nvme_status_equals(status, type, NVME_SC_INVALID_NS)) - nvme_show_status(err); - } else { - nvme_show_error("get-feature: %s", libnvme_strerror(err)); + if (err) { + if (nvme_status_equals(status, type, NVME_SC_INVALID_FIELD) || + nvme_status_equals(status, type, NVME_SC_INVALID_NS)) + return; + nvme_show_err(err, "get-feature"); + return; } + + nvme_show_feature(cfg.feature_id, cfg.sel, result, buf, cfg.data_len, + flags); } static bool is_get_feature_result_set(enum nvme_features_id feature_id) diff --git a/plugins/feat/feat-nvme.c b/plugins/feat/feat-nvme.c index 7f0f165b65..61b23adfa4 100644 --- a/plugins/feat/feat-nvme.c +++ b/plugins/feat/feat-nvme.c @@ -90,11 +90,7 @@ static int feat_get_nsid(struct libnvme_transport_handle *hdl, __u32 nsid, nvme_show_init(); - nvme_feature_show(fid, sel, result); - if (NVME_CHECK(sel, GET_FEATURES_SEL, SUPPORTED)) - nvme_show_select_result(fid, result); - else - nvme_feature_show_fields(fid, result, buf); + nvme_show_feature(fid, sel, result, buf, len, NORMAL); nvme_show_finish();