Skip to content

Commit 8b1b046

Browse files
ikegami-tigaw
authored andcommitted
nvme: add NVMe 2.1 changed-alloc-ns-list-log command
The command functions combined with the changed-ns-list-log command. The output almost same but different as lists attached or allocated NSs. Signed-off-by: Tokunori Ikegami <[email protected]>
1 parent 3065588 commit 8b1b046

9 files changed

Lines changed: 52 additions & 23 deletions

nvme-builtin.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ COMMAND_LIST(
3636
ENTRY("get-log", "Generic NVMe get log, returns log in raw format", get_log)
3737
ENTRY("telemetry-log", "Retrieve FW Telemetry log write to file", get_telemetry_log)
3838
ENTRY("fw-log", "Retrieve FW Log, show it", get_fw_log)
39-
ENTRY("changed-ns-list-log", "Retrieve Changed Namespace List, show it", get_changed_ns_list_log)
39+
ENTRY("changed-ns-list-log", "Retrieve Changed Attached Namespace List, show it", get_changed_attach_ns_list_log)
4040
ENTRY("smart-log", "Retrieve SMART Log, show it", get_smart_log)
4141
ENTRY("ana-log", "Retrieve ANA Log, show it", get_ana_log)
4242
ENTRY("error-log", "Retrieve Error Log, show it", get_error_log)
@@ -60,6 +60,7 @@ COMMAND_LIST(
6060
ENTRY("supported-cap-config-log", "Retrieve the list of Supported Capacity Configuration Descriptors", get_supp_cap_config_log)
6161
ENTRY("mgmt-addr-list-log", "Retrieve Management Address List Log, show it", get_mgmt_addr_list_log)
6262
ENTRY("rotational-media-info-log", "Retrieve Rotational Media Information Log, show it", get_rotational_media_info_log)
63+
ENTRY("changed-alloc-ns-list-log", "Retrieve Changed Allocated Namespace List, show it", get_changed_alloc_ns_list_log)
6364
ENTRY("set-feature", "Set a feature and show the resulting value", set_feature)
6465
ENTRY("set-property", "Set a property and show the resulting value", set_property)
6566
ENTRY("get-property", "Get a property and show the resulting value", get_property)

nvme-print-binary.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,7 @@ static void binary_fw_log(struct nvme_firmware_slot *fw_log,
233233
d_raw((unsigned char *)fw_log, sizeof(*fw_log));
234234
}
235235

236-
static void binary_changed_ns_list_log(struct nvme_ns_list *log,
237-
const char *devname)
236+
static void binary_changed_ns_list_log(struct nvme_ns_list *log, const char *devname, bool alloc)
238237
{
239238
d_raw((unsigned char *)log, sizeof(*log));
240239
}

nvme-print-json.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -583,8 +583,7 @@ void json_fw_log(struct nvme_firmware_slot *fw_log, const char *devname)
583583
json_print(r);
584584
}
585585

586-
void json_changed_ns_list_log(struct nvme_ns_list *log,
587-
const char *devname)
586+
void json_changed_ns_list_log(struct nvme_ns_list *log, const char *devname, bool alloc)
588587
{
589588
struct json_object *r = json_create_object();
590589
struct json_object *nsi = json_create_object();
@@ -593,10 +592,13 @@ void json_changed_ns_list_log(struct nvme_ns_list *log,
593592
__u32 nsid;
594593
int i;
595594

595+
_cleanup_free_ char *k = NULL;
596+
596597
if (log->ns[0] == cpu_to_le32(0xffffffff))
597598
return;
598599

599-
obj_add_str(r, "Changed Namespace List Log", devname);
600+
if (asprintf(&k, "Changed %s Namespace List Log", alloc ? "Allocated" : "Attached") > 0)
601+
obj_add_str(r, k, devname);
600602

601603
for (i = 0; i < NVME_ID_NS_LIST_MAX; i++) {
602604
nsid = le32_to_cpu(log->ns[i]);

nvme-print-stdout.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4034,8 +4034,7 @@ static void stdout_fw_log(struct nvme_firmware_slot *fw_log,
40344034
}
40354035
}
40364036

4037-
static void stdout_changed_ns_list_log(struct nvme_ns_list *log,
4038-
const char *devname)
4037+
static void stdout_changed_ns_list_log(struct nvme_ns_list *log, const char *devname, bool alloc)
40394038
{
40404039
__u32 nsid;
40414040
int i;

nvme-print.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -740,11 +740,10 @@ void nvme_show_fw_log(struct nvme_firmware_slot *fw_log,
740740
nvme_print(fw_log, flags, fw_log, devname);
741741
}
742742

743-
void nvme_show_changed_ns_list_log(struct nvme_ns_list *log,
744-
const char *devname,
745-
nvme_print_flags_t flags)
743+
void nvme_show_changed_ns_list_log(struct nvme_ns_list *log, const char *devname,
744+
nvme_print_flags_t flags, bool alloc)
746745
{
747-
nvme_print(ns_list_log, flags, log, devname);
746+
nvme_print(ns_list_log, flags, log, devname, alloc);
748747
}
749748

750749
void nvme_print_effects_log_pages(struct list_head *list,

nvme-print.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ struct print_ops {
5858
void (*media_unit_stat_log)(struct nvme_media_unit_stat_log *mus);
5959
void (*mi_cmd_support_effects_log)(struct nvme_mi_cmd_supported_effects_log *mi_cmd_log, const char *devname);
6060
void (*ns_list)(struct nvme_ns_list *ns_list);
61-
void (*ns_list_log)(struct nvme_ns_list *log, const char *devname);
61+
void (*ns_list_log)(struct nvme_ns_list *log, const char *devname, bool alloc);
6262
void (*nvm_id_ns)(struct nvme_nvm_id_ns *nvm_ns, unsigned int nsid, struct nvme_id_ns *ns, unsigned int lba_index, bool cap_only);
6363
void (*persistent_event_log)(void *pevent_log_info, __u8 action, __u32 size, const char *devname);
6464
void (*predictable_latency_event_agg_log)(struct nvme_aggregate_predictable_lat_event *pea_log, __u64 log_entries, __u32 size, const char *devname);
@@ -174,8 +174,8 @@ void nvme_show_fw_log(struct nvme_firmware_slot *fw_log, const char *devname,
174174
nvme_print_flags_t flags);
175175
void nvme_print_effects_log_pages(struct list_head *list,
176176
nvme_print_flags_t flags);
177-
void nvme_show_changed_ns_list_log(struct nvme_ns_list *log,
178-
const char *devname, nvme_print_flags_t flags);
177+
void nvme_show_changed_ns_list_log(struct nvme_ns_list *log, const char *devname,
178+
nvme_print_flags_t flags, bool alloc);
179179
void nvme_show_endurance_log(struct nvme_endurance_group_log *endurance_log,
180180
__u16 group_id, const char *devname, nvme_print_flags_t flags);
181181
void nvme_show_sanitize_log(struct nvme_sanitize_log_page *sanitize,

nvme-wrap.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,12 @@ int nvme_cli_get_log_changed_ns_list(struct nvme_dev *dev, bool rae,
214214
return do_admin_op(get_log_changed_ns_list, dev, rae, ns_log);
215215
}
216216

217+
int nvme_cli_get_log_changed_alloc_ns_list(struct nvme_dev *dev, bool rae, __u32 len,
218+
struct nvme_ns_list *ns_log)
219+
{
220+
return do_admin_op(get_log_changed_alloc_ns_list, dev, rae, len, ns_log);
221+
}
222+
217223
int nvme_cli_get_log_cmd_effects(struct nvme_dev *dev, enum nvme_csi csi,
218224
struct nvme_cmd_effects_log *effects_log)
219225
{

nvme-wrap.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ int nvme_cli_get_log_fw_slot(struct nvme_dev *dev, bool rae,
7272
struct nvme_firmware_slot *fw_log);
7373
int nvme_cli_get_log_changed_ns_list(struct nvme_dev *dev, bool rae,
7474
struct nvme_ns_list *ns_log);
75+
int nvme_cli_get_log_changed_alloc_ns_list(struct nvme_dev *dev, bool rae, __u32 len,
76+
struct nvme_ns_list *ns_log);
7577
int nvme_cli_get_log_cmd_effects(struct nvme_dev *dev, enum nvme_csi csi,
7678
struct nvme_cmd_effects_log *effects_log);
7779
int nvme_cli_get_log_device_self_test(struct nvme_dev *dev,

nvme.c

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,10 +1354,9 @@ static int get_fw_log(int argc, char **argv, struct command *cmd, struct plugin
13541354
return err;
13551355
}
13561356

1357-
static int get_changed_ns_list_log(int argc, char **argv, struct command *cmd, struct plugin *plugin)
1357+
static int get_changed_ns_list_log(int argc, char **argv, bool alloc)
13581358
{
1359-
const char *desc = "Retrieve Changed Namespaces log for the given device "
1360-
"in either decoded format (default) or binary.";
1359+
_cleanup_free_ char *desc = NULL;
13611360

13621361
_cleanup_free_ struct nvme_ns_list *changed_ns_list_log = NULL;
13631362
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
@@ -1375,6 +1374,11 @@ static int get_changed_ns_list_log(int argc, char **argv, struct command *cmd, s
13751374
NVME_ARGS(opts,
13761375
OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw_output));
13771376

1377+
if (asprintf(&desc, "Retrieve Changed %s Namespaces log for the given device %s",
1378+
alloc ? "Allocated" : "Attached",
1379+
"in either decoded format (default) or binary.") < 0)
1380+
desc = NULL;
1381+
13781382
err = parse_and_open(&dev, argc, argv, desc, opts);
13791383
if (err)
13801384
return err;
@@ -1392,19 +1396,36 @@ static int get_changed_ns_list_log(int argc, char **argv, struct command *cmd, s
13921396
if (!changed_ns_list_log)
13931397
return -ENOMEM;
13941398

1395-
err = nvme_cli_get_log_changed_ns_list(dev, true,
1396-
changed_ns_list_log);
1399+
if (alloc)
1400+
err = nvme_cli_get_log_changed_alloc_ns_list(dev, true,
1401+
sizeof(*changed_ns_list_log),
1402+
changed_ns_list_log);
1403+
else
1404+
err = nvme_cli_get_log_changed_ns_list(dev, true,
1405+
changed_ns_list_log);
13971406
if (!err)
1398-
nvme_show_changed_ns_list_log(changed_ns_list_log,
1399-
dev->name, flags);
1407+
nvme_show_changed_ns_list_log(changed_ns_list_log, dev->name, flags, alloc);
14001408
else if (err > 0)
14011409
nvme_show_status(err);
14021410
else
1403-
nvme_show_error("changed ns list log: %s", nvme_strerror(errno));
1411+
nvme_show_error("changed %s ns list log: %s", alloc ? "allocated" : "attached",
1412+
nvme_strerror(errno));
14041413

14051414
return err;
14061415
}
14071416

1417+
static int get_changed_attach_ns_list_log(int argc, char **argv, struct command *cmd,
1418+
struct plugin *plugin)
1419+
{
1420+
return get_changed_ns_list_log(argc, argv, false);
1421+
}
1422+
1423+
static int get_changed_alloc_ns_list_log(int argc, char **argv, struct command *cmd,
1424+
struct plugin *plugin)
1425+
{
1426+
return get_changed_ns_list_log(argc, argv, true);
1427+
}
1428+
14081429
static int get_pred_lat_per_nvmset_log(int argc, char **argv,
14091430
struct command *cmd, struct plugin *plugin)
14101431
{

0 commit comments

Comments
 (0)