Skip to content

Commit

Permalink
nvme: add mgmt-addr-list-log command
Browse files Browse the repository at this point in the history
Since added the NVMe 2.1 log page.

Signed-off-by: Tokunori Ikegami <[email protected]>
  • Loading branch information
ikegami-t committed Jan 13, 2025
1 parent 37c8e05 commit efdb01c
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 0 deletions.
1 change: 1 addition & 0 deletions nvme-builtin.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ COMMAND_LIST(
ENTRY("mi-cmd-support-effects-log", "Retrieve MI Command Support and Effects log and show it", get_mi_cmd_support_effects_log)
ENTRY("media-unit-stat-log", "Retrieve the configuration and wear of media units, show it", get_media_unit_stat_log)
ENTRY("supported-cap-config-log", "Retrieve the list of Supported Capacity Configuration Descriptors", get_supp_cap_config_log)
ENTRY("mgmt-addr-list-log", "Retrieve Management Address List Log, show it", get_mgmt_addr_list_log)

Check failure on line 61 in nvme-builtin.h

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: line length of 108 exceeds 100 columns
ENTRY("set-feature", "Set a feature and show the resulting value", set_feature)
ENTRY("set-property", "Set a property and show the resulting value", set_property)
ENTRY("get-property", "Get a property and show the resulting value", get_property)
Expand Down
28 changes: 28 additions & 0 deletions nvme-print-stdout.c
Original file line number Diff line number Diff line change
Expand Up @@ -5509,6 +5509,33 @@ static void stdout_connect_msg(nvme_ctrl_t c)
printf("connecting to device: %s\n", nvme_ctrl_get_name(c));
}

static void stdout_mgmt_addr_list_log(struct nvme_mgmt_addr_list_log *ma_list)
{
int i;
bool reserved = true;

printf("Management Address List:\n");
for (i = 0; i < ARRAY_SIZE(ma_list->mad); i++) {
switch (ma_list->mad[i].mat) {
case 1:
case 2:
printf("Descriptor: %d, Type: %d (%s), Address: %s\n", i,
ma_list->mad[i].mat,
ma_list->mad[i].mat == 1 ? "NVM subsystem management agent" :
"fabric interface manager", ma_list->mad[i].madrs);
reserved = false;
break;
case 0xff:
goto out;
default:
break;
}
}
out:
if (reserved)
printf("All management address descriptors reserved\n");
}

static struct print_ops stdout_print_ops = {
/* libnvme types.h print functions */
.ana_log = stdout_ana_log,
Expand Down Expand Up @@ -5576,6 +5603,7 @@ static struct print_ops stdout_print_ops = {
.d = stdout_d,
.show_init = NULL,
.show_finish = NULL,
.mgmt_addr_list_log = stdout_mgmt_addr_list_log,

/* libnvme tree print functions */
.list_item = stdout_list_item,
Expand Down
5 changes: 5 additions & 0 deletions nvme-print.c
Original file line number Diff line number Diff line change
Expand Up @@ -1440,3 +1440,8 @@ void nvme_show_finish(void)
{
nvme_print_output_format(show_finish);
}

void nvme_show_mgmt_addr_list_log(struct nvme_mgmt_addr_list_log *ma_list, nvme_print_flags_t flags)
{
nvme_print(mgmt_addr_list_log, flags, ma_list);
}
3 changes: 3 additions & 0 deletions nvme-print.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ struct print_ops {
void (*d)(unsigned char *buf, int len, int width, int group);
void (*show_init)(void);
void (*show_finish)(void);
void (*mgmt_addr_list_log)(struct nvme_mgmt_addr_list_log *ma_log);

/* libnvme tree print functions */
void (*list_item)(nvme_ns_t n);
Expand Down Expand Up @@ -327,4 +328,6 @@ const char *nvme_degrees_string(long t);
void print_array(char *name, __u8 *data, int size);
void json_print(struct json_object *r);
struct json_object *obj_create_array_obj(struct json_object *o, const char *k);
void nvme_show_mgmt_addr_list_log(struct nvme_mgmt_addr_list_log *ma_list,
nvme_print_flags_t flags);
#endif /* NVME_PRINT_H */
6 changes: 6 additions & 0 deletions nvme-wrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,3 +430,9 @@ int nvme_cli_security_receive(struct nvme_dev *dev,

return -ENODEV;
}

int nvme_cli_get_log_mgmt_addr_list(struct nvme_dev *dev, __u32 len,
struct nvme_mgmt_addr_list_log *ma_list)
{
return do_admin_op(get_log_mgmt_addr_list, dev, len, ma_list);
}
3 changes: 3 additions & 0 deletions nvme-wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,7 @@ int nvme_cli_security_send(struct nvme_dev *dev,
int nvme_cli_security_receive(struct nvme_dev *dev,
struct nvme_security_receive_args* args);

int nvme_cli_get_log_mgmt_addr_list(struct nvme_dev *dev, __u32 len,
struct nvme_mgmt_addr_list_log *ma_list);

#endif /* _NVME_WRAP_H */
37 changes: 37 additions & 0 deletions nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -9962,6 +9962,43 @@ static int nmi_send(int argc, char **argv, struct command *cmd, struct plugin *p
return nvme_mi(argc, argv, nvme_admin_nvme_mi_send, desc);
}

static int get_mgmt_addr_list_log(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Retrieve Management Address List Log, show it";
nvme_print_flags_t flags;
int err = -1;

_cleanup_free_ struct nvme_mgmt_addr_list_log *ma_log = NULL;

_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;

NVME_ARGS(opts);

err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;

err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}

ma_log = nvme_alloc(sizeof(*ma_log));
if (!ma_log)
return -ENOMEM;

err = nvme_cli_get_log_mgmt_addr_list(dev, sizeof(struct nvme_mgmt_addr_list_log), ma_log);
if (!err)
nvme_show_mgmt_addr_list_log(ma_log, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_perror("management address list log");

return err;
}

void register_extension(struct plugin *plugin)
{
plugin->parent = &nvme;
Expand Down

0 comments on commit efdb01c

Please sign in to comment.