Skip to content

Commit 4830291

Browse files
committed
nvme: handle get-feature output format in nvme-print layer
Also the --raw-binary just selects the binary output format. Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
1 parent 48969fd commit 4830291

7 files changed

Lines changed: 35 additions & 24 deletions

File tree

nvme-print-binary.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,14 @@ static void binary_power_meas_log(struct nvme_power_meas_log *log, __u32 size)
352352
d_raw((unsigned char *)log, size);
353353
}
354354

355+
static void binary_feature_show(enum nvme_features_id fid, int sel,
356+
unsigned int result, void *buf, __u32 data_len)
357+
{
358+
if (buf) {
359+
d_raw(buf, data_len);
360+
}
361+
}
362+
355363
static struct print_ops binary_print_ops = {
356364
/* libnvme types.h print functions */
357365
.ana_log = binary_ana_log,
@@ -410,7 +418,7 @@ static struct print_ops binary_print_ops = {
410418
.zns_id_ctrl = binary_zns_id_ctrl,
411419
.zns_id_ns = binary_zns_id_ns,
412420
.zns_report_zones = binary_zns_report_zones,
413-
.show_feature = NULL,
421+
.show_feature = binary_feature_show,
414422
.show_feature_fields = NULL,
415423
.id_ctrl_rpmbs = NULL,
416424
.lba_range = NULL,

nvme-print-json.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4178,7 +4178,8 @@ static void json_feature_show_fields_power_meas(struct json_object *r,
41784178
obj_add_uint(r, "Stop Measurement Time (SMT)", smt);
41794179
}
41804180

4181-
static void json_feature_show(enum nvme_features_id fid, int sel, unsigned int result)
4181+
static void json_feature_show(enum nvme_features_id fid, int sel,
4182+
unsigned int result, void *buf, __u32 data_len)
41824183
{
41834184
struct json_object *r;
41844185
char json_str[STR_LEN];
@@ -4192,6 +4193,11 @@ static void json_feature_show(enum nvme_features_id fid, int sel, unsigned int r
41924193
obj_add_str(r, nvme_select_to_string(sel), json_str);
41934194

41944195
obj_print(r);
4196+
4197+
if (NVME_CHECK(sel, GET_FEATURES_SEL, SUPPORTED))
4198+
json_select_result(fid, result);
4199+
else
4200+
json_feature_show_fields(fid, result, buf);
41954201
}
41964202

41974203
static void json_feature_show_fields(enum nvme_features_id fid, unsigned int result,

nvme-print-stdout.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5227,10 +5227,18 @@ static void stdout_feat_host_id(unsigned int result, unsigned char *hostid)
52275227
le64_to_cpu(*(__le64 *)hostid));
52285228
}
52295229

5230-
static void stdout_feature_show(enum nvme_features_id fid, int sel, unsigned int result)
5230+
static void stdout_feature_show(enum nvme_features_id fid, int sel,
5231+
unsigned int result, void *buf, __u32 data_len)
52315232
{
52325233
printf("get-feature:%#0*x (%s), %s value:%#0*x\n", fid ? 4 : 2, fid,
52335234
nvme_feature_to_string(fid), nvme_select_to_string(sel), result ? 10 : 8, result);
5235+
5236+
if (NVME_CHECK(sel, GET_FEATURES_SEL, SUPPORTED))
5237+
stdout_select_result(fid, result);
5238+
else if (stdout_print_ops.flags & VERBOSE)
5239+
stdout_feature_show_fields(fid, result, buf);
5240+
else if (buf)
5241+
d(buf, data_len, 16, 1);
52345242
}
52355243

52365244
static void stdout_feature_show_fields(enum nvme_features_id fid,

nvme-print.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,9 +1608,10 @@ const char *nvme_ipmsr_srs_to_string(__u8 srs)
16081608
}
16091609
}
16101610

1611-
void nvme_feature_show(enum nvme_features_id fid, int sel, unsigned int result)
1611+
void nvme_show_feature(enum nvme_features_id fid, int sel, unsigned int result,
1612+
void *buf, __u32 data_len, nvme_print_flags_t flags)
16121613
{
1613-
nvme_print(show_feature, NORMAL, fid, sel, result);
1614+
nvme_print(show_feature, flags, fid, sel, result, buf, data_len);
16141615
}
16151616

16161617
void nvme_feature_show_fields(enum nvme_features_id fid, unsigned int result, unsigned char *buf)

nvme-print.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ struct print_ops {
8585
void (*zns_id_ctrl)(struct nvme_zns_id_ctrl *ctrl);
8686
void (*zns_id_ns)(struct nvme_zns_id_ns *ns, struct nvme_id_ns *id_ns);
8787
void (*zns_report_zones)(void *report, __u32 descs, __u8 ext_size, __u32 report_size, struct json_object *zone_list);
88-
void (*show_feature)(enum nvme_features_id fid, int sel, unsigned int result);
88+
void (*show_feature)(enum nvme_features_id fid, int sel,
89+
unsigned int result, void *buf, __u32 data_len);
8990
void (*show_feature_fields)(enum nvme_features_id fid, unsigned int result, unsigned char *buf);
9091
void (*id_ctrl_rpmbs)(__le32 ctrl_rpmbs);
9192
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,
263264
nvme_print_flags_t flags);
264265
void nvme_show_topology_tabular(struct libnvme_global_ctx *ctx, nvme_print_flags_t flags);
265266

266-
void nvme_feature_show(enum nvme_features_id fid, int sel, unsigned int result);
267+
void nvme_show_feature(enum nvme_features_id fid, int sel, unsigned int result,
268+
void *buf, __u32 data_len, nvme_print_flags_t flags);
267269
void nvme_feature_show_fields(enum nvme_features_id fid, unsigned int result, unsigned char *buf);
268270
void nvme_directive_show(__u8 type, __u8 oper, __u16 spec, __u32 nsid, __u64 result,
269271
void *buf, __u32 len, nvme_print_flags_t flags);

nvme.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4839,21 +4839,11 @@ static void get_feature_id_print(struct feat_cfg cfg, int err, __u64 result,
48394839
void *buf, nvme_print_flags_t flags)
48404840
{
48414841
int status = filter_out_flags(err);
4842-
int verbose = flags & VERBOSE;
48434842
enum nvme_status_type type = NVME_STATUS_TYPE_NVME;
48444843

48454844
if (!err) {
4846-
if (!cfg.raw_binary || !buf) {
4847-
nvme_feature_show(cfg.feature_id, cfg.sel, result);
4848-
if (NVME_CHECK(cfg.sel, GET_FEATURES_SEL, SUPPORTED))
4849-
nvme_show_select_result(cfg.feature_id, result);
4850-
else if (verbose || !strcmp(nvme_args.output_format, "json"))
4851-
nvme_feature_show_fields(cfg.feature_id, result, buf);
4852-
else if (buf)
4853-
d(buf, cfg.data_len, 16, 1);
4854-
} else if (buf) {
4855-
d_raw(buf, cfg.data_len);
4856-
}
4845+
nvme_show_feature(cfg.feature_id, cfg.sel, result, buf,
4846+
cfg.data_len, flags);
48574847
} else if (err > 0) {
48584848
if (!nvme_status_equals(status, type, NVME_SC_INVALID_FIELD) &&
48594849
!nvme_status_equals(status, type, NVME_SC_INVALID_NS))

plugins/feat/feat-nvme.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,7 @@ static int feat_get_nsid(struct libnvme_transport_handle *hdl, __u32 nsid,
9090

9191
nvme_show_init();
9292

93-
nvme_feature_show(fid, sel, result);
94-
if (NVME_CHECK(sel, GET_FEATURES_SEL, SUPPORTED))
95-
nvme_show_select_result(fid, result);
96-
else
97-
nvme_feature_show_fields(fid, result, buf);
93+
nvme_show_feature(fid, sel, result, buf, len, NORMAL);
9894

9995
nvme_show_finish();
10096

0 commit comments

Comments
 (0)