Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nvme: add NVMe 2.1 changed-alloc-ns-list-log command #2675

Merged
merged 5 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions Documentation/nvme-changed-alloc-ns-list-log.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
nvme-changed-alloc-ns-list-log(1)
=================================

NAME
----
nvme-changed-alloc-ns-list-log - Send NVMe Changed Allocated Namespace List
log page request, returns result and log.

SYNOPSIS
--------
[verse]
'nvme changed-alloc-ns-list-log' <device> [--raw-binary | -b]
[--output-format=<fmt> | -o <fmt>] [--verbose | -v]
[--timeout=<timeout>]

DESCRIPTION
-----------
Retrieves the NVMe Changed Allocated Namespace List log page from an NVMe
device and provides the returned structure.

The <device> parameter is mandatory and must be a NVMe character device
(ex: /dev/nvme0).

On success, the returned Changed Allocated Namespace List log structure may
be returned in one of several ways depending on the option flags; the
structure may parsed by the program and printed in a readable format or
the raw buffer may be printed to stdout for another program to parse.

OPTIONS
-------
-b::
--raw-binary::
Print the raw Changed Namespace List log buffer to stdout.

-o <fmt>::
--output-format=<fmt>::
Set the reporting format to 'normal', 'json' or 'binary'. Only one
output format can be used at a time.

-v::
--verbose::
Increase the information detail in the output.

-t <timeout>::
--timeout=<timeout>::
Override default timeout value. In milliseconds.

EXAMPLES
--------
* Print the Changed Allocated Namespace List Log page in a human readable format:
+
------------
# nvme changed-alloc-ns-list-log /dev/nvme0
------------
+

* Print the raw Changed Allocated Namespace List log to a file:
+
------------
# nvme changed-alloc-ns-list-log /dev/nvme0 --raw-binary > log.raw
------------
+
It is probably a bad idea to not redirect stdout when using this mode.

NVME
----
Part of the nvme-user suite
17 changes: 15 additions & 2 deletions completions/_nvme
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ _nvme () {
'set-reg:write and show the defined NVMe controller register'
'io-mgmt-recv:send an I/O management receive command'
'io-mgmt-send:send an I/O management send command'
'mgmt-addr-list-log:retrieve management address list log'
'changed-ns-list-log:retrieve changed allocated namespaces log'
'version:show the program version'
'ocp:OCP cloud SSD extensions'
'solidigm:Solidigm plug-in extensions'
Expand Down Expand Up @@ -2638,11 +2640,22 @@ _nvme () {
-v':alias for --verbose'
--output-format=':Output format: normal|json|binary'
-o ':alias for --output-format'
_describe -t commands "nvme rotational-media-info-log" _rmi_log
(changed-alloc-ns-list-log)
local _changed_alloc_ns_list_log
_changed_alloc_ns_list_log=(
/dev/nvme':supply a device to use (required)'
--output-format=':Output format: normal|json|binary'
-o':alias for --output-format'
--raw-binary':dump infos in binary format'
-b':alias of --raw-binary'
--verbose':Increase the information detail in the output.'
-v':alias for --verbose'
--timeout=':value for timeout'
-t ':alias for --timeout'
)
_arguments '*:: :->subcmds'
_describe -t commands "nvme rotational-media-info-log" _rmi_log
_describe -t commands "nvme changed-alloc-ns-list-log options" _changed_alloc_ns_list_log
;;
(version)
local _version
Expand Down Expand Up @@ -2756,7 +2769,7 @@ _nvme () {
subsystem-reset ns-rescan get-lba-status dsm discover connect-all connect
dim disconnect disconnect-all gen-hostnqn show-hostnqn tls-key dir-receive
dir-send virt-mgmt rpmb version ocp solidigm dapustor mgmt-addr-list-log
rotational-media-info-log
rotational-media-info-log changed-alloc-ns-list-log
)
_arguments '*:: :->subcmds'
_describe -t commands "help: infos on a specific nvme command, or provide no option to see a synopsis of all nvme commands" _h
Expand Down
6 changes: 5 additions & 1 deletion completions/bash-nvme-completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,10 @@ nvme_list_opts () {
opts+=" --endg-id= -e --verbose -v --output-format= -o \
--timeout= -t"
;;
"changed-alloc-cns-list-log")
opts+=" --output-format= -o --raw-binary -b --verbose -v \
--timeout= -t"
;;
"version")
opts+=$NO_OPTS
;;
Expand Down Expand Up @@ -1677,7 +1681,7 @@ _nvme_subcmds () {
supported-log-pages lockdown media-unit-stat-log \
supported-cap-config-log dim show-topology list-endgrp \
nvme-mi-recv nvme-mi-send get-reg set-reg mgmt-addr-list-log \
rotational-media-info-log"
rotational-media-info-log changed-alloc-ns-list-log"

# Add plugins:
for plugin in "${!_plugin_subcmds[@]}"; do
Expand Down
3 changes: 2 additions & 1 deletion nvme-builtin.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
ENTRY("get-log", "Generic NVMe get log, returns log in raw format", get_log)
ENTRY("telemetry-log", "Retrieve FW Telemetry log write to file", get_telemetry_log)
ENTRY("fw-log", "Retrieve FW Log, show it", get_fw_log)
ENTRY("changed-ns-list-log", "Retrieve Changed Namespace List, show it", get_changed_ns_list_log)
ENTRY("changed-ns-list-log", "Retrieve Changed Attached Namespace List, show it", get_changed_attach_ns_list_log)

Check failure on line 39 in nvme-builtin.h

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: line length of 121 exceeds 100 columns
ENTRY("smart-log", "Retrieve SMART Log, show it", get_smart_log)
ENTRY("ana-log", "Retrieve ANA Log, show it", get_ana_log)
ENTRY("error-log", "Retrieve Error Log, show it", get_error_log)
Expand All @@ -60,6 +60,7 @@
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)
ENTRY("rotational-media-info-log", "Retrieve Rotational Media Information Log, show it", get_rotational_media_info_log)
ENTRY("changed-alloc-ns-list-log", "Retrieve Changed Allocated Namespace List, show it", get_changed_alloc_ns_list_log)

Check failure on line 63 in nvme-builtin.h

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: line length of 127 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
3 changes: 1 addition & 2 deletions nvme-print-binary.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,7 @@ static void binary_fw_log(struct nvme_firmware_slot *fw_log,
d_raw((unsigned char *)fw_log, sizeof(*fw_log));
}

static void binary_changed_ns_list_log(struct nvme_ns_list *log,
const char *devname)
static void binary_changed_ns_list_log(struct nvme_ns_list *log, const char *devname, bool alloc)
{
d_raw((unsigned char *)log, sizeof(*log));
}
Expand Down
8 changes: 5 additions & 3 deletions nvme-print-json.c
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,7 @@ void json_fw_log(struct nvme_firmware_slot *fw_log, const char *devname)
json_print(r);
}

void json_changed_ns_list_log(struct nvme_ns_list *log,
const char *devname)
void json_changed_ns_list_log(struct nvme_ns_list *log, const char *devname, bool alloc)
{
struct json_object *r = json_create_object();
struct json_object *nsi = json_create_object();
Expand All @@ -593,10 +592,13 @@ void json_changed_ns_list_log(struct nvme_ns_list *log,
__u32 nsid;
int i;

_cleanup_free_ char *k = NULL;

if (log->ns[0] == cpu_to_le32(0xffffffff))
return;

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

for (i = 0; i < NVME_ID_NS_LIST_MAX; i++) {
nsid = le32_to_cpu(log->ns[i]);
Expand Down
3 changes: 1 addition & 2 deletions nvme-print-stdout.c
Original file line number Diff line number Diff line change
Expand Up @@ -4034,8 +4034,7 @@ static void stdout_fw_log(struct nvme_firmware_slot *fw_log,
}
}

static void stdout_changed_ns_list_log(struct nvme_ns_list *log,
const char *devname)
static void stdout_changed_ns_list_log(struct nvme_ns_list *log, const char *devname, bool alloc)
{
__u32 nsid;
int i;
Expand Down
7 changes: 3 additions & 4 deletions nvme-print.c
Original file line number Diff line number Diff line change
Expand Up @@ -740,11 +740,10 @@ void nvme_show_fw_log(struct nvme_firmware_slot *fw_log,
nvme_print(fw_log, flags, fw_log, devname);
}

void nvme_show_changed_ns_list_log(struct nvme_ns_list *log,
const char *devname,
nvme_print_flags_t flags)
void nvme_show_changed_ns_list_log(struct nvme_ns_list *log, const char *devname,
nvme_print_flags_t flags, bool alloc)
{
nvme_print(ns_list_log, flags, log, devname);
nvme_print(ns_list_log, flags, log, devname, alloc);
}

void nvme_print_effects_log_pages(struct list_head *list,
Expand Down
6 changes: 3 additions & 3 deletions nvme-print.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct print_ops {
void (*media_unit_stat_log)(struct nvme_media_unit_stat_log *mus);
void (*mi_cmd_support_effects_log)(struct nvme_mi_cmd_supported_effects_log *mi_cmd_log, const char *devname);
void (*ns_list)(struct nvme_ns_list *ns_list);
void (*ns_list_log)(struct nvme_ns_list *log, const char *devname);
void (*ns_list_log)(struct nvme_ns_list *log, const char *devname, bool alloc);
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);
void (*persistent_event_log)(void *pevent_log_info, __u8 action, __u32 size, const char *devname);
void (*predictable_latency_event_agg_log)(struct nvme_aggregate_predictable_lat_event *pea_log, __u64 log_entries, __u32 size, const char *devname);
Expand Down Expand Up @@ -174,8 +174,8 @@ void nvme_show_fw_log(struct nvme_firmware_slot *fw_log, const char *devname,
nvme_print_flags_t flags);
void nvme_print_effects_log_pages(struct list_head *list,
nvme_print_flags_t flags);
void nvme_show_changed_ns_list_log(struct nvme_ns_list *log,
const char *devname, nvme_print_flags_t flags);
void nvme_show_changed_ns_list_log(struct nvme_ns_list *log, const char *devname,
nvme_print_flags_t flags, bool alloc);
void nvme_show_endurance_log(struct nvme_endurance_group_log *endurance_log,
__u16 group_id, const char *devname, nvme_print_flags_t flags);
void nvme_show_sanitize_log(struct nvme_sanitize_log_page *sanitize,
Expand Down
11 changes: 10 additions & 1 deletion nvme-wrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@ int nvme_cli_get_log_changed_ns_list(struct nvme_dev *dev, bool rae,
return do_admin_op(get_log_changed_ns_list, dev, rae, ns_log);
}

int nvme_cli_get_log_changed_alloc_ns_list(struct nvme_dev *dev, bool rae, __u32 len,
struct nvme_ns_list *ns_log)
{
return do_admin_op(get_log_changed_alloc_ns_list, dev, rae, len, ns_log);
}

int nvme_cli_get_log_cmd_effects(struct nvme_dev *dev, enum nvme_csi csi,
struct nvme_cmd_effects_log *effects_log)
{
Expand Down Expand Up @@ -440,5 +446,8 @@ int nvme_cli_get_log_mgmt_addr_list(struct nvme_dev *dev, __u32 len,
int nvme_cli_get_log_rotational_media_info(struct nvme_dev *dev, __u16 endgid, __u32 len,
struct nvme_rotational_media_info_log *info)
{
return do_admin_op(get_log_rotational_media_info, dev, endgid, len, info);
if (dev->type == NVME_DEV_DIRECT)
return nvme_get_log_rotational_media_info(dev->direct.fd, endgid, len, info);

return -ENODEV;
}
2 changes: 2 additions & 0 deletions nvme-wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ int nvme_cli_get_log_fw_slot(struct nvme_dev *dev, bool rae,
struct nvme_firmware_slot *fw_log);
int nvme_cli_get_log_changed_ns_list(struct nvme_dev *dev, bool rae,
struct nvme_ns_list *ns_log);
int nvme_cli_get_log_changed_alloc_ns_list(struct nvme_dev *dev, bool rae, __u32 len,
struct nvme_ns_list *ns_log);
int nvme_cli_get_log_cmd_effects(struct nvme_dev *dev, enum nvme_csi csi,
struct nvme_cmd_effects_log *effects_log);
int nvme_cli_get_log_device_self_test(struct nvme_dev *dev,
Expand Down
37 changes: 29 additions & 8 deletions nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -1354,10 +1354,9 @@ static int get_fw_log(int argc, char **argv, struct command *cmd, struct plugin
return err;
}

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

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

if (asprintf(&desc, "Retrieve Changed %s Namespaces log for the given device %s",
alloc ? "Allocated" : "Attached",
"in either decoded format (default) or binary.") < 0)
desc = NULL;

err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
Expand All @@ -1392,19 +1396,36 @@ static int get_changed_ns_list_log(int argc, char **argv, struct command *cmd, s
if (!changed_ns_list_log)
return -ENOMEM;

err = nvme_cli_get_log_changed_ns_list(dev, true,
changed_ns_list_log);
if (alloc)
err = nvme_cli_get_log_changed_alloc_ns_list(dev, true,
sizeof(*changed_ns_list_log),
changed_ns_list_log);
else
err = nvme_cli_get_log_changed_ns_list(dev, true,
changed_ns_list_log);
if (!err)
nvme_show_changed_ns_list_log(changed_ns_list_log,
dev->name, flags);
nvme_show_changed_ns_list_log(changed_ns_list_log, dev->name, flags, alloc);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_error("changed ns list log: %s", nvme_strerror(errno));
nvme_show_error("changed %s ns list log: %s", alloc ? "allocated" : "attached",
nvme_strerror(errno));

return err;
}

static int get_changed_attach_ns_list_log(int argc, char **argv, struct command *cmd,
struct plugin *plugin)
{
return get_changed_ns_list_log(argc, argv, false);
}

static int get_changed_alloc_ns_list_log(int argc, char **argv, struct command *cmd,
struct plugin *plugin)
{
return get_changed_ns_list_log(argc, argv, true);
}

static int get_pred_lat_per_nvmset_log(int argc, char **argv,
struct command *cmd, struct plugin *plugin)
{
Expand Down
Loading