Skip to content

Commit

Permalink
nvme: add pull-model-ddc-req-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 Feb 28, 2025
1 parent 703daad commit f61f090
Show file tree
Hide file tree
Showing 9 changed files with 128 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 @@ -66,6 +66,7 @@ COMMAND_LIST(
ENTRY("reachability-associations-log", "Retrieve Reachability Associations Log, show it", get_reachability_associations_log)
ENTRY("host-discovery-log", "Retrieve Host Discovery Log, show it", get_host_discovery_log)
ENTRY("ave-discovery-log", "Retrieve AVE Discovery Log, show it", get_ave_discovery_log)
ENTRY("pull-model-ddc-req-log", "Retrieve Pull Model DDC Request Log, show it", get_pull_model_ddc_req_log)

Check failure on line 69 in nvme-builtin.h

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: line length of 115 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
6 changes: 6 additions & 0 deletions nvme-print-binary.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,11 @@ static void binary_ave_discovery_log(struct nvme_ave_discover_log *log)
d_raw((unsigned char *)log, le32_to_cpu(log->tadlpl));
}

static void binary_pull_model_ddc_req_log(struct nvme_pull_model_ddc_req_log *log)
{
d_raw((unsigned char *)log, le32_to_cpu(log->tpdrpl));
}

static struct print_ops binary_print_ops = {
/* libnvme types.h print functions */
.ana_log = binary_ana_log,
Expand Down Expand Up @@ -415,6 +420,7 @@ static struct print_ops binary_print_ops = {
.reachability_associations_log = binary_reachability_associations_log,
.host_discovery_log = binary_host_discovery_log,
.ave_discovery_log = binary_ave_discovery_log,
.pull_model_ddc_req_log = binary_pull_model_ddc_req_log,

/* libnvme tree print functions */
.list_item = NULL,
Expand Down
12 changes: 12 additions & 0 deletions nvme-print-json.c
Original file line number Diff line number Diff line change
Expand Up @@ -4904,6 +4904,17 @@ static void json_ave_discovery_log(struct nvme_ave_discover_log *log)
}
}

static void json_pull_model_ddc_req_log(struct nvme_pull_model_ddc_req_log *log)
{
struct json_object *r = json_create_object();
__u32 tpdrpl = le32_to_cpu(log->tpdrpl);
__u32 osp_len = tpdrpl - offsetof(struct nvme_pull_model_ddc_req_log, osp);

obj_add_uint(r, "ori", log->ori);
printf("tpdrpl: %u\n", tpdrpl);
obj_d(r, "osp", (unsigned char *)log->osp, osp_len, 16, 1);
}

static struct print_ops json_print_ops = {
/* libnvme types.h print functions */
.ana_log = json_ana_log,
Expand Down Expand Up @@ -4978,6 +4989,7 @@ static struct print_ops json_print_ops = {
.reachability_associations_log = json_reachability_associations_log,
.host_discovery_log = json_host_discovery_log,
.ave_discovery_log = json_ave_discovery_log,
.pull_model_ddc_req_log = json_pull_model_ddc_req_log,

/* libnvme tree print functions */
.list_item = json_list_item,
Expand Down
12 changes: 12 additions & 0 deletions nvme-print-stdout.c
Original file line number Diff line number Diff line change
Expand Up @@ -5836,6 +5836,17 @@ static void stdout_ave_discovery_log(struct nvme_ave_discover_log *log)
}
}

static void stdout_pull_model_ddc_req_log(struct nvme_pull_model_ddc_req_log *log)
{
__u32 tpdrpl = le32_to_cpu(log->tpdrpl);
__u32 osp_len = tpdrpl - offsetof(struct nvme_pull_model_ddc_req_log, osp);

printf("ori: %u\n", log->ori);
printf("tpdrpl: %u\n", tpdrpl);
printf("osp:\n");
d((unsigned char *)log->osp, osp_len, 16, 1);
}

static struct print_ops stdout_print_ops = {
/* libnvme types.h print functions */
.ana_log = stdout_ana_log,
Expand Down Expand Up @@ -5910,6 +5921,7 @@ static struct print_ops stdout_print_ops = {
.reachability_associations_log = stdout_reachability_associations_log,
.host_discovery_log = stdout_host_discovery_log,
.ave_discovery_log = stdout_ave_discovery_log,
.pull_model_ddc_req_log = stdout_pull_model_ddc_req_log,

/* libnvme tree print functions */
.list_item = stdout_list_item,
Expand Down
6 changes: 6 additions & 0 deletions nvme-print.c
Original file line number Diff line number Diff line change
Expand Up @@ -1530,3 +1530,9 @@ void nvme_show_ave_discovery_log(struct nvme_ave_discover_log *log, nvme_print_f
{
nvme_print(ave_discovery_log, flags, log);
}

void nvme_show_pull_model_ddc_req_log(struct nvme_pull_model_ddc_req_log *log,
nvme_print_flags_t flags)
{
nvme_print(pull_model_ddc_req_log, flags, log);
}
3 changes: 3 additions & 0 deletions nvme-print.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ struct print_ops {
__u64 len);
void (*host_discovery_log)(struct nvme_host_discover_log *log);
void (*ave_discovery_log)(struct nvme_ave_discover_log *log);
void (*pull_model_ddc_req_log)(struct nvme_pull_model_ddc_req_log *log);

/* libnvme tree print functions */
void (*list_item)(nvme_ns_t n);
Expand Down Expand Up @@ -349,4 +350,6 @@ void nvme_show_reachability_associations_log(struct nvme_reachability_associatio
__u64 len, nvme_print_flags_t flags);
void nvme_show_host_discovery_log(struct nvme_host_discover_log *log, nvme_print_flags_t flags);
void nvme_show_ave_discovery_log(struct nvme_ave_discover_log *log, nvme_print_flags_t flags);
void nvme_show_pull_model_ddc_req_log(struct nvme_pull_model_ddc_req_log *log,
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 @@ -481,3 +481,9 @@ int nvme_cli_get_log_ave_discovery(struct nvme_dev *dev, bool rae, __u32 len,
{
return do_admin_op(get_log_ave_discover, dev, rae, len, log);
}

int nvme_cli_get_log_pull_model_ddc_req(struct nvme_dev *dev, bool rae, __u32 len,
struct nvme_pull_model_ddc_req_log *log)
{
return do_admin_op(get_log_pull_model_ddc_req, dev, rae, len, log);
}
3 changes: 3 additions & 0 deletions nvme-wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,7 @@ int nvme_cli_get_log_host_discovery(struct nvme_dev *dev, bool allhoste, bool ra

int nvme_cli_get_log_ave_discovery(struct nvme_dev *dev, bool rae, __u32 len,
struct nvme_ave_discover_log *log);

int nvme_cli_get_log_pull_model_ddc_req(struct nvme_dev *dev, bool rae, __u32 len,
struct nvme_pull_model_ddc_req_log *log);
#endif /* _NVME_WRAP_H */
79 changes: 79 additions & 0 deletions nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -10790,6 +10790,85 @@ static int get_ave_discovery_log(int argc, char **argv, struct command *cmd, str
return err;
}

static int get_pull_model_ddc_req(struct nvme_dev *dev,
bool rae, struct nvme_pull_model_ddc_req_log **logp)
{
int err;
struct nvme_pull_model_ddc_req_log *log;
__u64 log_len = sizeof(*log);
struct nvme_get_log_args args = {
.args_size = sizeof(args),
.fd = dev_fd(dev),
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
.lid = NVME_LOG_LID_PULL_MODEL_DDC_REQ,
.nsid = NVME_NSID_ALL,
.rae = rae,
};

log = nvme_alloc(log_len);
if (!log)
return -ENOMEM;

err = nvme_cli_get_log_pull_model_ddc_req(dev, rae, log_len, log);
if (err)
goto err_free;

log_len = le32_to_cpu(log->tpdrpl);
err = get_log_offset(dev, &args, &log_len, le32_to_cpu(log->tpdrpl) - log_len,
(void **)&log);
if (err)
goto err_free;

*logp = log;
return 0;

err_free:
free(log);
return err;
}

static int get_pull_model_ddc_req_log(int argc, char **argv, struct command *cmd,
struct plugin *plugin)
{
const char *desc = "Retrieve Pull Model DDC Request Log, show it";
nvme_print_flags_t flags;
int err;

_cleanup_free_ struct nvme_pull_model_ddc_req_log *log = NULL;

_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;

struct config {
bool rae;
};

struct config cfg = {
.rae = false,
};

NVME_ARGS(opts, OPT_FLAG("rae", 'r', &cfg.rae, rae));

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;
}

err = get_pull_model_ddc_req(dev, cfg.rae, &log);
if (!err)
nvme_show_pull_model_ddc_req_log(log, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_perror("pull model ddc req log");

return err;
}

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

0 comments on commit f61f090

Please sign in to comment.