Skip to content

Commit 1bd4a53

Browse files
committed
nvme: add output-format-version option
The JSON outputs changed to verbose by the format version 2. Signed-off-by: Tokunori Ikegami <[email protected]>
1 parent 2b2cbf7 commit 1bd4a53

3 files changed

Lines changed: 11 additions & 8 deletions

File tree

nvme-print-json.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ static void json_id_iocs_iocsc(struct json_object *obj_iocsc, __u64 iocsc)
199199

200200
static bool human(void)
201201
{
202-
return json_print_ops.flags & VERBOSE;
202+
return json_print_ops.flags & VERBOSE || nvme_cfg.output_format_ver == 2;
203203
}
204204

205205
static void json_id_iocs(struct nvme_id_iocs *iocs)
@@ -2540,7 +2540,7 @@ static void json_print_nvme_subsystem_list(nvme_root_t r, bool show_ana)
25402540
obj_add_str(subsystem_attrs, "Name", nvme_subsystem_get_name(s));
25412541
obj_add_str(subsystem_attrs, "NQN", nvme_subsystem_get_nqn(s));
25422542

2543-
if (json_print_ops.flags & VERBOSE) {
2543+
if (human()) {
25442544
obj_add_str(subsystem_attrs, "Model",
25452545
nvme_subsystem_get_model(s));
25462546
obj_add_str(subsystem_attrs, "Firmware",
@@ -2995,14 +2995,13 @@ static void json_ctrl_register_human(int offset, uint64_t value, struct json_obj
29952995

29962996
static void json_ctrl_register(int offset, uint64_t value)
29972997
{
2998-
bool human = json_print_ops.flags & VERBOSE;
29992998
struct json_object *r;
30002999
char json_str[STR_LEN];
30013000

30023001
sprintf(json_str, "register: %#04x", offset);
30033002
r = obj_create(json_str);
30043003

3005-
if (human) {
3004+
if (human()) {
30063005
obj_add_uint64(r, nvme_register_to_string(offset), value);
30073006
json_ctrl_register_human(offset, value, r);
30083007
} else {
@@ -3130,7 +3129,7 @@ static void json_nvme_id_ctrl_nvm(struct nvme_id_ctrl_nvm *ctrl_nvm)
31303129
obj_add_uint(r, "wzdsl", ctrl_nvm->wzdsl);
31313130
obj_add_uint(r, "aocs", le16_to_cpu(ctrl_nvm->aocs));
31323131

3133-
if (json_print_ops.flags & VERBOSE) {
3132+
if (human()) {
31343133
__u16 rsvd = (ctrl_nvm->aocs & 0xfffe) >> 1;
31353134
__u8 ralbas = ctrl_nvm->aocs & 0x1;
31363135

@@ -4475,7 +4474,7 @@ static void json_list_item(nvme_ns_t n)
44754474

44764475
static void json_print_list_items(nvme_root_t t)
44774476
{
4478-
if (json_print_ops.flags & VERBOSE)
4477+
if (human())
44794478
json_detail_list(t);
44804479
else
44814480
json_simple_list(t);
@@ -4572,7 +4571,7 @@ static void json_simple_topology(nvme_root_t r)
45724571
obj_add_str(subsystem_attrs, "Name", nvme_subsystem_get_name(s));
45734572
obj_add_str(subsystem_attrs, "NQN", nvme_subsystem_get_nqn(s));
45744573

4575-
if (json_print_ops.flags & VERBOSE) {
4574+
if (human()) {
45764575
obj_add_str(subsystem_attrs, "Model",
45774576
nvme_subsystem_get_model(s));
45784577
obj_add_str(subsystem_attrs, "Firmware",
@@ -4710,7 +4709,7 @@ static void json_directive_show(__u8 type, __u8 oper, __u16 spec, __u32 nsid, __
47104709
sprintf(json_str, "%#x", result);
47114710
obj_add_result(r, json_str);
47124711

4713-
if (json_print_ops.flags & VERBOSE) {
4712+
if (human()) {
47144713
json_directive_show_fields(type, oper, result, buf, r);
47154714
} else if (buf) {
47164715
data = json_create_array();

nvme.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ static const char *pmrmscu = "PMRMSCU=0xe18 register offset";
258258

259259
struct nvme_config nvme_cfg = {
260260
.output_format = "normal",
261+
.output_format_ver = 1,
261262
};
262263

263264
static void *mmap_registers(struct nvme_dev *dev, bool writable);

nvme.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ struct nvme_config {
7979
int verbose;
8080
__u32 timeout;
8181
bool dry_run;
82+
unsigned int output_format_ver;
8283
};
8384

8485
/*
@@ -92,6 +93,8 @@ struct nvme_config {
9293
##__VA_ARGS__, \
9394
OPT_UINT("timeout", 't', &nvme_cfg.timeout, timeout), \
9495
OPT_FLAG("dry-run", 0, &nvme_cfg.dry_run, dry_run), \
96+
OPT_UINT("output-format-version", 0, &nvme_cfg.output_format_ver, \
97+
"output format version: 1|2"), \
9598
OPT_END() \
9699
}
97100

0 commit comments

Comments
 (0)