]> www.infradead.org Git - users/sagi/libnvme.git/log
users/sagi/libnvme.git
12 months agoRevert "fabrics: retry discovery log page when DNR is not set"
Daniel Wagner [Fri, 12 Apr 2024 11:03:27 +0000 (13:03 +0200)]
Revert "fabrics: retry discovery log page when DNR is not set"

This reverts commit 2f27d849889c9a452dbe49fda31e53149b7e3f83.

The result field is undefined for many commands and thus can have random values.
Thus we can't blindly evaluate these for all commands.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
12 months agoRevert "ioctl: Update function documentation"
Daniel Wagner [Fri, 12 Apr 2024 11:03:27 +0000 (13:03 +0200)]
Revert "ioctl: Update function documentation"

This reverts commit e3d3371160eba2bd26dcffaea4eed910898dfb2d.

The result field is undefined for many commands and thus can have random values.
Thus we can't blindly evaluate these for all commands.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
12 months agoRevert "ioctl: Update stub functions to match documentation"
Daniel Wagner [Fri, 12 Apr 2024 11:03:27 +0000 (13:03 +0200)]
Revert "ioctl: Update stub functions to match documentation"

This reverts commit 4eb7c9e662751d4fb5d1837b8d700e33aef7ab9f.

The result field is undefined for many commands and thus can have random values.
Thus we can't blindly evaluate these for all commands.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
12 months agoRevert "ioctl: add nvme_set_features_timestamp2()"
Daniel Wagner [Fri, 12 Apr 2024 10:58:34 +0000 (12:58 +0200)]
Revert "ioctl: add nvme_set_features_timestamp2()"

This reverts commit 99d5e26bb4014830a4a5649bd200f9fcc199990b.

The result field is undefined for many commands and thus can have random values.
Thus we can't blindly evaluate these for all commands.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
12 months agoRevert "ioctl: add nvme_set_features_host_behavior2()"
Daniel Wagner [Fri, 12 Apr 2024 10:58:34 +0000 (12:58 +0200)]
Revert "ioctl: add nvme_set_features_host_behavior2()"

This reverts commit eff57ae736dc14a22229b9f50b68abd6001edc97.

The result field is undefined for many commands and thus can have random values.
Thus we can't blindly evaluate these for all commands.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
12 months agoRevert "ioctl: add nvme_set_features_host_id2()"
Daniel Wagner [Fri, 12 Apr 2024 10:58:34 +0000 (12:58 +0200)]
Revert "ioctl: add nvme_set_features_host_id2()"

This reverts commit 0782b381f3f1d1f1aabbc602aec1be549367b501.

The result field is undefined for many commands and thus can have random values.
Thus we can't blindly evaluate these for all commands.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
12 months agoRevert "ioctl: add nvme_set_features_iocs_profile2()"
Daniel Wagner [Fri, 12 Apr 2024 10:58:34 +0000 (12:58 +0200)]
Revert "ioctl: add nvme_set_features_iocs_profile2()"

This reverts commit cb9bdfd4f15305b5d2868aea7f642e211e5a2f36.

The result field is undefined for many commands and thus can have random values.
Thus we can't blindly evaluate these for all commands.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
12 months agoRevert "ioctl: add nvme_get_features_timestamp2()"
Daniel Wagner [Fri, 12 Apr 2024 10:58:34 +0000 (12:58 +0200)]
Revert "ioctl: add nvme_get_features_timestamp2()"

This reverts commit 5547b9350340328b2f7f37c52c8492a32554084d.

The result field is undefined for many commands and thus can have random values.
Thus we can't blindly evaluate these for all commands.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
12 months agoRevert "ioctl: add nvme_get_features_host_id2()"
Daniel Wagner [Fri, 12 Apr 2024 10:58:34 +0000 (12:58 +0200)]
Revert "ioctl: add nvme_get_features_host_id2()"

This reverts commit 3d9ab1d2217af69a0285efde2c0c0ee211bdca60.

The result field is undefined for many commands and thus can have random values.
Thus we can't blindly evaluate these for all commands.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
12 months agoRevert "ioctl: Return NVMe status in nvme_directive_send_id_endir()"
Daniel Wagner [Fri, 12 Apr 2024 10:58:34 +0000 (12:58 +0200)]
Revert "ioctl: Return NVMe status in nvme_directive_send_id_endir()"

This reverts commit 2d2d76fa08bfd0a3f82cb9db051e53992b4bded2.

The result field is undefined for many commands and thus can have random values.
Thus we can't blindly evaluate these for all commands.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
12 months agoioctl: Add nvme_ns_mgmt_delete_timeout()
Tokunori Ikegami [Wed, 10 Apr 2024 16:08:26 +0000 (01:08 +0900)]
ioctl: Add nvme_ns_mgmt_delete_timeout()

The existing nvme_ns_mgmt_delete() does not support the timeout.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
12 months agoioctl: Return NVMe status in nvme_directive_send_id_endir()
Hannes Reinecke [Fri, 5 Apr 2024 15:04:10 +0000 (17:04 +0200)]
ioctl: Return NVMe status in nvme_directive_send_id_endir()

Documentation states that the NVMe status code should be returned,
to fix up the code to actually do it.

Signed-off-by: Hannes Reinecke <hare@suse.de>
12 months agoioctl: add nvme_get_features_host_id2()
Hannes Reinecke [Fri, 5 Apr 2024 14:31:25 +0000 (16:31 +0200)]
ioctl: add nvme_get_features_host_id2()

All 'get features' commands have an 'result' field as the last
argument, so add an alternative function nvme_get_features_host_id2()
to follow the same calling convention.

Signed-off-by: Hannes Reinecke <hare@suse.de>
12 months agoioctl: add nvme_get_features_timestamp2()
Hannes Reinecke [Fri, 5 Apr 2024 14:31:25 +0000 (16:31 +0200)]
ioctl: add nvme_get_features_timestamp2()

All 'get features' commands have an 'result' field as the last
argument, so add an alternative function nvme_get_features_timestamp2()
to follow the same calling convention.

Signed-off-by: Hannes Reinecke <hare@suse.de>
12 months agoioctl: add nvme_set_features_iocs_profile2()
Hannes Reinecke [Fri, 5 Apr 2024 14:31:25 +0000 (16:31 +0200)]
ioctl: add nvme_set_features_iocs_profile2()

All 'set features' commands have an 'result' field as the last
argument, so add an alternative function nvme_set_features_iocs_profile2()
to follow the same calling convention.

Signed-off-by: Hannes Reinecke <hare@suse.de>
12 months agoioctl: add nvme_set_features_host_id2()
Hannes Reinecke [Fri, 5 Apr 2024 14:31:25 +0000 (16:31 +0200)]
ioctl: add nvme_set_features_host_id2()

All 'set features' commands have an 'result' field as the last
argument, so add an alternative function nvme_set_features_host_id2()
to follow the same calling convention.

Signed-off-by: Hannes Reinecke <hare@suse.de>
12 months agoioctl: add nvme_set_features_host_behavior2()
Hannes Reinecke [Fri, 5 Apr 2024 14:31:25 +0000 (16:31 +0200)]
ioctl: add nvme_set_features_host_behavior2()

All 'set features' commands have an 'result' field as the last
argument, so add an alternative function nvme_set_features_host_behavior2()
to follow the same calling convention.

Signed-off-by: Hannes Reinecke <hare@suse.de>
12 months agoioctl: add nvme_set_features_timestamp2()
Hannes Reinecke [Fri, 5 Apr 2024 14:31:25 +0000 (16:31 +0200)]
ioctl: add nvme_set_features_timestamp2()

All 'set features' commands have an 'result' field as the last
argument, so add an alternative function nvme_set_features_timestamp2()
to follow the same calling convention.

Signed-off-by: Hannes Reinecke <hare@suse.de>
12 months agoioctl: Update stub functions to match documentation
Hannes Reinecke [Fri, 5 Apr 2024 13:44:05 +0000 (15:44 +0200)]
ioctl: Update stub functions to match documentation

Modify stub functions to correctly update the return values if the
ioctl succeeded but an NVMe status was returned.

Signed-off-by: Hannes Reinecke <hare@suse.de>
12 months agoioctl: Update function documentation
Hannes Reinecke [Fri, 5 Apr 2024 13:44:05 +0000 (15:44 +0200)]
ioctl: Update function documentation

Update the function documentation to reflect the change in the
ioctl return values.

Signed-off-by: Hannes Reinecke <hare@suse.de>
12 months agofabrics: retry discovery log page when DNR is not set
Hannes Reinecke [Thu, 4 Apr 2024 07:35:13 +0000 (09:35 +0200)]
fabrics: retry discovery log page when DNR is not set

Reading the discovery log page might result in an NVMe status,
so we should evaluate the DNR bit to check if it's safe to retry
the command.

Signed-off-by: Hannes Reinecke <hare@suse.de>
12 months agoioctl: return EPROTO when an NVMe status occurred
Hannes Reinecke [Thu, 4 Apr 2024 07:07:33 +0000 (09:07 +0200)]
ioctl: return EPROTO when an NVMe status occurred

The ioctl might return 0, but the NVMe status might indicate an
error. In these cases we should return EPROTO to indicate that
the command did not succeed.

Signed-off-by: Hannes Reinecke <hare@suse.de>
12 months agolinux: Allocate aligned payload for nvme_get_telemetry_log
Liang Yan [Mon, 18 Mar 2024 01:46:12 +0000 (09:46 +0800)]
linux: Allocate aligned payload for nvme_get_telemetry_log

Use nvme_realloc to allocate alighed payload for
nvme_get_telemetry_log.
Fix a compilation warning in tree.c also.

Signed-off-by: Liang Yan <ckgppl_yan@sina.cn>
12 months agotest: use diff to compare sysfs output
Caleb Sander Mateos [Tue, 19 Mar 2024 18:30:53 +0000 (12:30 -0600)]
test: use diff to compare sysfs output

The sysfs tests are currently hand-rolling file comparison.
Use diff -u instead to get a rich comparison if the comparison fails.

Create a single shell script that combines extracting the sysfs files,
invoking the test program to generate the tree output,
and diffing the result against the expected output.
This reduces the C and Meson code needed for the test.

Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>
12 months agotree: fix lba_count size calculation
Daniel Wagner [Thu, 28 Mar 2024 16:20:13 +0000 (17:20 +0100)]
tree: fix lba_count size calculation

The kernel reports the size in 512 byte units, which is might not match
with lba_size.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
12 months agotree: Add NVM subsystem controller identifier
Nilay Shroff [Tue, 26 Mar 2024 06:57:23 +0000 (12:27 +0530)]
tree: Add NVM subsystem controller identifier

This commit introduces a field "cntlid" for controller,
that contains the NVM subsystem unique identifier assigned
to each controller device in an NVM subsystem.

While attaching a namespace, typically user needs to specify the
controller identifier (cntlid). The cntlid could be referenced from
sysfs (/sys/class/nvme/nvmeX/cntlid) but it would be nice to have
a direct option.

Signed-off-by: Nilay Shroff <nilay@linux.ibm.com>
Link: https://lore.kernel.org/r/20240326065752.164286-1-nilay@linux.ibm.com
Signed-off-by: Daniel Wagner <dwagner@suse.de>
12 months agotest: Add unit test for nvme_id_ns_flbas_to_lbaf_inuse()
Ben Chuang [Tue, 2 Apr 2024 07:01:40 +0000 (15:01 +0800)]
test: Add unit test for nvme_id_ns_flbas_to_lbaf_inuse()

Signed-off-by: Ben Chuang <benchuanggli@gmail.com>
12 months agotypes: Fix NVME_CSTS_SHST_MASK definition
Tokunori Ikegami [Sun, 31 Mar 2024 09:55:25 +0000 (18:55 +0900)]
types: Fix NVME_CSTS_SHST_MASK definition

Deprecate NVME_CSTS_SHN_MASK instead.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
12 months agoutil: Fixed nvme_id_ns_flbas_to_lbaf_inuse()
Ben Chuang [Mon, 1 Apr 2024 06:22:07 +0000 (14:22 +0800)]
util: Fixed nvme_id_ns_flbas_to_lbaf_inuse()

Signed-off-by: Ben Chuang <benchuanggli@gmail.com>
13 months agotypes: Add optional data present filed mask and shift definition
Tokunori Ikegami [Mon, 25 Mar 2024 13:42:43 +0000 (22:42 +0900)]
types: Add optional data present filed mask and shift definition

Also add reserved filed definition and macros to get.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
13 months agotypes: Fix EOM header optional data present fields definition
Tokunori Ikegami [Mon, 25 Mar 2024 13:25:46 +0000 (22:25 +0900)]
types: Fix EOM header optional data present fields definition

Defined eye data present as bit 0 and printable eye present as bit 1.
Fixed eye data present to bit 1 and printable eye present to bit 0.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
13 months agolibnvme : record the nvme pci adapter physical slot
Nilay Shroff [Thu, 21 Mar 2024 13:16:17 +0000 (18:46 +0530)]
libnvme : record the nvme pci adapter physical slot

There is a subtle bug in the nvme controller physical
slot lookup code due to which the readdir() prematurely
aborts the lookup and hence libnvme fails to record the
pci slot address of the nvme controller. This patch helps
to fix this issue.

Signed-off-by: Nilay Shroff <nilay@linux.ibm.com>
Signed-off-by: Daniel Wagner <dwagner@suse.de>
13 months agobuild: Switch default meson buildtype to 'debugoptimized'
Tomas Bzatek [Wed, 20 Mar 2024 14:03:21 +0000 (15:03 +0100)]
build: Switch default meson buildtype to 'debugoptimized'

The meson 'debug' buildtype defaults to '-O0 -g' which misses
some important compiler warnings (as of gcc-13). While there's
no universal solution, the 'debugoptimized' buildtype supplies
'-O2 -g' that appears to be a reasonable compromise for having
important compiler warnings by default.

Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
13 months agobuild: Add vscode directory into ignore
Liang Yan [Wed, 20 Mar 2024 00:27:54 +0000 (08:27 +0800)]
build: Add vscode directory into ignore

Signed-off-by: Liang Yan <ckgppl_yan@sina.cn>
13 months agosysfs: minimize heap allocations of sysfs paths
Caleb Sander Mateos [Tue, 19 Mar 2024 19:23:51 +0000 (13:23 -0600)]
sysfs: minimize heap allocations of sysfs paths

11a0918a9972 ("nvme: allow to overwrite base sysfs path")
added support for changing the sysfs path via an environment variable.
Unfortunately, it added a heap allocation
every time a sysfs path was requested.

Modify the callers to not free the paths, which allows a string constant
to be returned if the path isn't overridden, avoiding an allocation.
Cache the path in a static variable so that if it is overridden,
the heap-allocated string only needs to be constructed once
and afterwards can be reused.

Create a file sysfs.c to consolidate this logic
instead of spreading them across 3 files.
Also introduce a helper to factor out the duplicated code.

Fixes: 11a0918a9972 ("nvme: allow to overwrite base sysfs path")
Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>
13 months agojson: Fix uninitialized variables
Tomas Bzatek [Tue, 19 Mar 2024 15:33:05 +0000 (16:33 +0100)]
json: Fix uninitialized variables

In file included from ../src/nvme/json.c:17:
In function ‘freep’,
    inlined from ‘json_export_nvme_tls_key’ at ../src/nvme/json.c:70:24:
../src/nvme/cleanup.h:24:9: warning: ‘tls_str’ may be used uninitialized [-Wmaybe-uninitialized]
   24 |         free(*(void **)p);
      |         ^~~~~~~~~~~~~~~~~
../src/nvme/json.c: In function ‘json_export_nvme_tls_key’:
../src/nvme/json.c:70:38: note: ‘tls_str’ was declared here
   70 |                 _cleanup_free_ char *tls_str;
      |                                      ^~~~~~~

In function ‘freep’,
    inlined from ‘json_export_nvme_tls_key’ at ../src/nvme/json.c:66:32:
../src/nvme/cleanup.h:24:9: warning: ‘key_data’ may be used uninitialized [-Wmaybe-uninitialized]
   24 |         free(*(void **)p);
      |         ^~~~~~~~~~~~~~~~~
../src/nvme/json.c: In function ‘json_export_nvme_tls_key’:
../src/nvme/json.c:66:39: note: ‘key_data’ was declared here
   66 |         _cleanup_free_ unsigned char *key_data;
      |                                       ^~~~~~~~

In function ‘freep’,
    inlined from ‘json_import_nvme_tls_key’ at ../src/nvme/json.c:37:32,
    inlined from ‘json_update_attributes’ at ../src/nvme/json.c:147:3,
    inlined from ‘json_parse_port’ at ../src/nvme/json.c:177:2,
    inlined from ‘json_parse_subsys’ at ../src/nvme/json.c:212:4,
    inlined from ‘json_parse_host’ at ../src/nvme/json.c:246:4,
    inlined from ‘json_read_config’ at ../src/nvme/json.c:316:4:
../src/nvme/cleanup.h:24:9: warning: ‘key_data’ may be used uninitialized [-Wmaybe-uninitialized]
   24 |         free(*(void **)p);
      |         ^~~~~~~~~~~~~~~~~
../src/nvme/json.c: In function ‘json_read_config’:
../src/nvme/json.c:37:39: note: ‘key_data’ was declared here
   37 |         _cleanup_free_ unsigned char *key_data;
      |                                       ^~~~~~~~

Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
13 months agolibnvme: add missing symbol nvme_scan_tls_keys
Hannes Reinecke [Tue, 19 Mar 2024 13:57:03 +0000 (14:57 +0100)]
libnvme: add missing symbol nvme_scan_tls_keys

Missing from the list of exports.

Signed-off-by: Hannes Reinecke <hare@suse.de.
13 months agonbft: Whitespace fixes
Tomas Bzatek [Mon, 18 Mar 2024 14:05:26 +0000 (15:05 +0100)]
nbft: Whitespace fixes

Code style fixes to satisfy the checkpatch
"please, no space before tabs" warnings.

Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
13 months agotests: Add complex NBFT table from Dell R660
Tomas Bzatek [Mon, 19 Feb 2024 15:19:57 +0000 (10:19 -0500)]
tests: Add complex NBFT table from Dell R660

Two HFIs, four discovery records (only two visible in the
table) and some form of multipath. Two SSNS records marked
as unavailable due to subnet mismatch.

Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
13 months agotests: Adapt to added NBFT SSNS flags
Tomas Bzatek [Fri, 9 Feb 2024 17:19:29 +0000 (18:19 +0100)]
tests: Adapt to added NBFT SSNS flags

+ regenerate the sample table outputs.

Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
13 months agonbft: Add SSNS 'discovered' flag
Tomas Bzatek [Mon, 19 Feb 2024 13:50:09 +0000 (08:50 -0500)]
nbft: Add SSNS 'discovered' flag

Indicates that the SSNS record was obtained through discovery.

Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
13 months agonbft: Add SSNS 'unavailable' flag
Tomas Bzatek [Fri, 9 Feb 2024 17:11:35 +0000 (18:11 +0100)]
nbft: Add SSNS 'unavailable' flag

Certain pre-OS driver implementations (i.e. UEFI) may opt
to include SSNS records that failed to connect, caused either
by a temporary target inaccessibility or an invalid
configuration. Such reason is further indicated by TP8029
extended information.

This commit adds a flag indicating namespace availability
so that clients (nvme-cli) may either decide to skip such
record or make another connection attempt.

Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
13 months agodoc: Document the NBFT API
Tomas Bzatek [Thu, 15 Feb 2024 15:33:20 +0000 (10:33 -0500)]
doc: Document the NBFT API

Added an explicit note about unstable API, that is in fact
semi-unstable whereas existing structures are stable and
new API will possibly be added at the end of the structs.

Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
13 months agoioctl: Move nvme_cmd_dword_fields definitions into header file
Tokunori Ikegami [Sun, 17 Mar 2024 10:19:38 +0000 (19:19 +0900)]
ioctl: Move nvme_cmd_dword_fields definitions into header file

This is to be used the definitions by nvme-cli.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
13 months agotypes: Add PEL set feature event layout definitions
Tokunori Ikegami [Sun, 17 Mar 2024 06:39:35 +0000 (15:39 +0900)]
types: Add PEL set feature event layout definitions

The changes for PEL set feature event print function.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
13 months agotypes: Fix enum nvme_pel_rci documentation error
Tokunori Ikegami [Sun, 17 Mar 2024 06:37:09 +0000 (15:37 +0900)]
types: Fix enum nvme_pel_rci documentation error

Correct to nvme_persistent_event_log.rci from nvme_st_result.dsts.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
13 months agotypes: Add boot partition information definitions
Tokunori Ikegami [Sun, 17 Mar 2024 11:54:43 +0000 (20:54 +0900)]
types: Add boot partition information definitions

The changes for boot partition log print function.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
13 months agotypes: Add PEL header additional information definitions
Tokunori Ikegami [Fri, 15 Mar 2024 14:31:28 +0000 (23:31 +0900)]
types: Add PEL header additional information definitions

The changes for persistent event entry ehai print function.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
13 months agofabrics: keyring is a long
Hannes Reinecke [Wed, 21 Feb 2024 14:34:19 +0000 (15:34 +0100)]
fabrics: keyring is a long

The keyring identifier is a 'long', not an integer.

Signed-off-by: Hannes Reinecke <hare@suse.de>
13 months agoconfig-schema.json.in: tls keys and keyrings are strings
Hannes Reinecke [Wed, 21 Feb 2024 14:33:14 +0000 (15:33 +0100)]
config-schema.json.in: tls keys and keyrings are strings

TLS keys and keyrings are stored as strings, not as integers.

Signed-off-by: Hannes Reinecke <hare@suse.de>
13 months agolinux: Add nvme_scan_tls_keys()
Hannes Reinecke [Tue, 27 Feb 2024 07:28:05 +0000 (08:28 +0100)]
linux: Add nvme_scan_tls_keys()

Add a function to iterate existing TLS keys in a given keyring.

Signed-off-by: Hannes Reinecke <hare@suse.de>
13 months agojson: dump TLS key data in PSK interchange format
Hannes Reinecke [Wed, 28 Feb 2024 07:43:45 +0000 (08:43 +0100)]
json: dump TLS key data in PSK interchange format

Dump the TLS key data in PSK interchange format, too, to be consistent
with all other functions.

Signed-off-by: Hannes Reinecke <hare@suse.de>
13 months agojson: import TLS key from PSK interchange format
Hannes Reinecke [Wed, 21 Feb 2024 14:31:00 +0000 (15:31 +0100)]
json: import TLS key from PSK interchange format

As now the JSON configuration file holds the TLS key in PSK interchange
format we should be parsing that key and inserting it into the kernel
keystore to make it available for TLS.

Signed-off-by: Hannes Reinecke <hare@suse.de>
13 months agojson: export TLS key in PSK interchange format
Hannes Reinecke [Wed, 21 Feb 2024 14:25:45 +0000 (15:25 +0100)]
json: export TLS key in PSK interchange format

Rather than printing the key serial number (which will only be valid
for this session) we should be exporting the actual key in PSK
interchange format to make it persistent across reboots.

Signed-off-by: Hannes Reinecke <hare@suse.de>
13 months agotree: read TLS key in nvme_configure_ctrl()
Hannes Reinecke [Wed, 21 Feb 2024 14:15:27 +0000 (15:15 +0100)]
tree: read TLS key in nvme_configure_ctrl()

nvme_configure_ctrl() is reading the values from sysfs, so we
should be reading the TLS key, too, if present.

Signed-off-by: Hannes Reinecke <hare@suse.de>
13 months agolinux: rework nvme_insert_tls_key_versioned()
Hannes Reinecke [Wed, 21 Feb 2024 14:04:06 +0000 (15:04 +0100)]
linux: rework nvme_insert_tls_key_versioned()

We really should not update existing keys as this will confuse
existing users of that key. Rather we should revoke the old key
and insert a new one.

Signed-off-by: Hannes Reinecke <hare@suse.de>
13 months agolinux: add nvme_import_tls_key()
Hannes Reinecke [Wed, 21 Feb 2024 06:57:16 +0000 (07:57 +0100)]
linux: add nvme_import_tls_key()

Add a function to import a TLS key in the PSK interchange format
as defined in the NVMe TCP transport specification.

Signed-off-by: Hannes Reinecke <hare@suse.de>
13 months agolinux: add nvme_export_tls_key()
Hannes Reinecke [Wed, 21 Feb 2024 06:57:16 +0000 (07:57 +0100)]
linux: add nvme_export_tls_key()

Add a function to export a TLS key in the PSK interchange format
as defined in the NVMe TCP transport specification.

Signed-off-by: Hannes Reinecke <hare@suse.de>
13 months agocrc32: Add CRC32 algorithm
Hannes Reinecke [Sun, 25 Feb 2024 13:38:46 +0000 (14:38 +0100)]
crc32: Add CRC32 algorithm

Free implementation based on FreeBSD sources.

Signed-off-by: Hannes Reinecke <hare@suse.de>
13 months agolinux: add nvme_update_key()
Hannes Reinecke [Tue, 27 Feb 2024 13:52:00 +0000 (14:52 +0100)]
linux: add nvme_update_key()

Add function to update a key by identity string.

Signed-off-by: Hannes Reinecke <hare@suse.de>
13 months agolinux: add nvme_read_key()
Hannes Reinecke [Wed, 21 Feb 2024 06:32:16 +0000 (07:32 +0100)]
linux: add nvme_read_key()

Add a function to return the payload of a key.

Signed-off-by: Hannes Reinecke <hare@suse.de>
13 months agolinux: allow for NULL argument in nvme_lookup_keyring()
Hannes Reinecke [Wed, 21 Feb 2024 14:07:28 +0000 (15:07 +0100)]
linux: allow for NULL argument in nvme_lookup_keyring()

Use the default '.nvme' keyring when nvme_lookup_keyring() is called
with a NULL argument.

Signed-off-by: Hannes Reinecke <hare@suse.de>
13 months agolog: Respect DEFAULT_LOGLEVEL on uninitialized logging
Tomas Bzatek [Thu, 15 Feb 2024 14:21:20 +0000 (09:21 -0500)]
log: Respect DEFAULT_LOGLEVEL on uninitialized logging

When logging has not been initialized and no root available,
logging via nvme_msg() would just print everything. Better
to check against DEFAULT_LOGLEVEL in such cases.

Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
13 months agolog: Introduce nvme_get_logging_level()
Tomas Bzatek [Wed, 14 Feb 2024 16:25:01 +0000 (11:25 -0500)]
log: Introduce nvme_get_logging_level()

This is essentially a getter for nvme_init_logging() since
nvme_root_t is an opaque struct. Takes optional pointer
to bool args to retrieve PID and timestamp logging values.

Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
13 months agoioctl: remove incomplete debug logging infrastructure
Daniel Wagner [Wed, 6 Mar 2024 09:18:10 +0000 (10:18 +0100)]
ioctl: remove incomplete debug logging infrastructure

Do not clutter the code base with debugging code. Because
the low level passthru functions are now exposed as weak symbol, the
user application can do it by itself.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
13 months agoioctl: export nvme_submit_passthru{64} as weak symbol
Daniel Wagner [Tue, 5 Mar 2024 14:32:59 +0000 (15:32 +0100)]
ioctl: export nvme_submit_passthru{64} as weak symbol

Export the two low level ioctl function as weak symbol. This allows the
user application to provide their own version of this function, e.g. in
order to allow meassuring the time spend in the function or printing the
struct nvme_passthru_cmd{64}.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
13 months agolog: move nvme_{set|get}_debug to log.c
Daniel Wagner [Tue, 5 Mar 2024 14:18:01 +0000 (15:18 +0100)]
log: move nvme_{set|get}_debug to log.c

Let's group all logging related function into one location.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
13 months agofabrics: check the read() return value
Maurizio Lombardi [Mon, 4 Mar 2024 14:05:15 +0000 (15:05 +0100)]
fabrics: check the read() return value

Do not pass to the is_dmi_uuid_valid() function an invalid len value
if read() fails.

Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
13 months agotypes: Add PEL reporting context port identifier type definitions
Tokunori Ikegami [Mon, 26 Feb 2024 15:46:52 +0000 (00:46 +0900)]
types: Add PEL reporting context port identifier type definitions

The changes for PEL rci port identifier type print function.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
13 months agotypes: Add persistent event log reporting context definitions
Tokunori Ikegami [Sun, 25 Feb 2024 15:22:35 +0000 (00:22 +0900)]
types: Add persistent event log reporting context definitions

The changes for persistent event log rci print function.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
14 months agodoc: Regenerate all docs for v1.8
Daniel Wagner [Wed, 14 Feb 2024 09:40:43 +0000 (10:40 +0100)]
doc: Regenerate all docs for v1.8

Signed-off-by: Daniel Wagner <dwagner@suse.de>
14 months agobuild: Update version to v1.8
Daniel Wagner [Wed, 14 Feb 2024 09:40:15 +0000 (10:40 +0100)]
build: Update version to v1.8

Signed-off-by: Daniel Wagner <dwagner@suse.de>
14 months agolinux: Explicitly initialize auto-cleanup variables
Tomas Bzatek [Fri, 9 Feb 2024 16:38:45 +0000 (17:38 +0100)]
linux: Explicitly initialize auto-cleanup variables

gcc complains about potentially uninitialized variables.

Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
14 months agoexample: fix mi identify failed with error cntid
Jian Zhang [Wed, 7 Feb 2024 11:06:17 +0000 (19:06 +0800)]
example: fix mi identify failed with error cntid

This command failed when we try to identify a controller that the
controller id is 1.

Refer to the `Figure 273: Identify - CNS Values`:
+-----------+-------+
| CNS Value | CNTID |
+-----------+-------+
| 01h       | N     |
+-----------+-------+
When CNS is 01h, the CNTID field is ignored.

See `Figure 270: Identify - Command Dword 10`:
If this field is not used as part of the Identify operation, then
* host software shall clear this field to 0h for backwards compatibility
(0h is a valid controller identifier);
* and the controller shall ignore this field.

This filed is set to controller id in the example code, but it should be
0 when CNS is 1.

PS: The NVMe that we are testing does not ignore the CNTID field and
returns an error when the CNTID field is not 0.

Signed-off-by: Jian Zhang <zhangjian.3032@bytedance.com>
14 months agotree: do not issue an error when subsys lookup fails during scanning
Daniel Wagner [Tue, 6 Feb 2024 13:06:10 +0000 (14:06 +0100)]
tree: do not issue an error when subsys lookup fails during scanning

The scan operation is not atomically done and the sysfs might change
while we are iterating over it. Thus, it's possible that we find a
controller but when we try to lookup the corresponding subsystem it might
already destroyed and removed.

This error makes blktests fail because it finds controllers controller
which are not under control of blktests, instead they are created and
destroyed by the udev auto connect rules.

These resources appear and disappear while the test runs but when we
scan sysfs we issue errors for unrelated resources. Thus just do not
issue a error, turn this into debug log message.

Anyway, we already do just return error codes for other reason in this
function anyway without logging.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
14 months agotypes: Add controller properties CMBEBS, CMBSWTP and NSSD
Tokunori Ikegami [Sat, 3 Feb 2024 16:59:26 +0000 (01:59 +0900)]
types: Add controller properties CMBEBS, CMBSWTP and NSSD

Described by the NVM express base specification revision 2.0c.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
14 months agotests: Add sample NBFT table from Dell PowerEdge R660
Tomas Bzatek [Tue, 23 Jan 2024 16:42:38 +0000 (17:42 +0100)]
tests: Add sample NBFT table from Dell PowerEdge R660

What's special on this table is the second SSNS record that
is roughly equal to the first one except of the 'nsid' and
'nid' values, although only a single subsystem has been
configured and enabled in the EFI Setup.

Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
14 months agotests: Add sample NBFT table from Dell PowerEdge R760
Tomas Bzatek [Fri, 5 Jan 2024 13:53:28 +0000 (14:53 +0100)]
tests: Add sample NBFT table from Dell PowerEdge R760

Covered by the Python tests already, let's include this
table in the other NBFT parser tests (which are all
QEMU dumps).

Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
14 months agotests: Fix diffs output for duplicate HFI entries
Tomas Bzatek [Fri, 5 Jan 2024 13:49:15 +0000 (14:49 +0100)]
tests: Fix diffs output for duplicate HFI entries

With commit "nbft: avoid duplicate entries in ssns->hfis" applied,
nbft-dump will not see any duplicate HFI indices any more.
Fix the reference output for generating the diffs.

Signed-off-by: Martin Wilck <mwilck@suse.com>
Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
14 months agonbft: avoid duplicate entries in ssns->hfis
Martin Wilck [Thu, 11 Jan 2024 10:02:11 +0000 (11:02 +0100)]
nbft: avoid duplicate entries in ssns->hfis

The NVMe boot specification does not disallow listing the primary
HFI index again in the secondary HFI list, or listing the same
index multiple times in the secondary HFI list. But such duplicate
entries aren't helpful for consumers of this data. In the worst
case, they might lead to confusion and misconfiguration.
Suppress them.

Signed-off-by: Martin Wilck <mwilck@suse.com>
14 months agonbft: Fix (struct nbft_info_subsystem_ns).num_hfis off-by-one
Tomas Bzatek [Fri, 5 Jan 2024 13:42:11 +0000 (14:42 +0100)]
nbft: Fix (struct nbft_info_subsystem_ns).num_hfis off-by-one

The num_hfis field only reflected the number of Secondary HFI
Associations, resulting in the last parsed HFI being ignored
by users (nvme-cli).

According to the NVM Express Boot Specification, Revision 1.0,
the Primary HFI Descriptor Index in the Subsystem Namespace
(SSNS) Descriptor contains this note:

  "If multiple HFIs are associated with this record, subsequent
   interfaces should be populated in the Secondary HFI
   Associations field."

As both the primary and secondary HFIs are parsed into a single
array, it makes sense to reflect the proper number of elements.

Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
14 months agobuild(deps): bump codecov/codecov-action from 3 to 4
dependabot[bot] [Mon, 5 Feb 2024 02:07:58 +0000 (02:07 +0000)]
build(deps): bump codecov/codecov-action from 3 to 4

Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 3 to 4.
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/codecov/codecov-action/compare/v3...v4)

---
updated-dependencies:
- dependency-name: codecov/codecov-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
14 months agotest: read and dump sysfs tar file
Daniel Wagner [Tue, 30 Jan 2024 17:25:08 +0000 (18:25 +0100)]
test: read and dump sysfs tar file

The library is able to scan the topology from a simple copy of
sysfs. There is no need to do any IOCTL, thus we can start test to
tree code.

This provides just the basic building blocks.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
14 months agonvme: allow to overwrite hostnqn and hostid
Daniel Wagner [Wed, 31 Jan 2024 11:37:10 +0000 (12:37 +0100)]
nvme: allow to overwrite hostnqn and hostid

In order to be able to test the topology scan code, allow
hostnqn and hostid to be controlled via an environment variable.

This is just for testing purposes, thus don't mention it.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
14 months agonvme: allow to overwrite base sysfs path
Daniel Wagner [Tue, 30 Jan 2024 17:28:40 +0000 (18:28 +0100)]
nvme: allow to overwrite base sysfs path

In order to be able to test the topology scan code, make the
lookup paths flexible. Check if the LIBNVME_SYSFS_PATH environment
variable is set and if so use this as base path.

We could also introduce a setter for this, but this is really
a debugging interface and thus I don't really want it to be
visible in the public API.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
14 months agojson: dump the output to the user selected filedescriptor
Daniel Wagner [Wed, 31 Jan 2024 11:39:08 +0000 (12:39 +0100)]
json: dump the output to the user selected filedescriptor

Allow the user to select the output filedescriptor instead always
dumping it to stdout.

This allows to write the output to a file.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
14 months agolibnvme: export nvme_dump_tree
Daniel Wagner [Tue, 30 Jan 2024 17:26:04 +0000 (18:26 +0100)]
libnvme: export nvme_dump_tree

This function is available since the 1.0 release. Export it.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
15 months agofabrics: add 'concat' option
Hannes Reinecke [Thu, 18 Jan 2024 11:34:25 +0000 (12:34 +0100)]
fabrics: add 'concat' option

Add an option 'concat' to enable secure concatenation for TCP.

Signed-off-by: Hannes Reinecke <hare@suse.de>
15 months agomi: set correct rc and errno when crc mismatch
Jinliang Wang [Fri, 19 Jan 2024 07:47:04 +0000 (23:47 -0800)]
mi: set correct rc and errno when crc mismatch

Before the fix, when we meet crc mismatch response, the errno is 0
and rc is 1. This combination will be mistaken as Admin Generic Command
Status code value 0x1 (Invalid Command Opcode):
  $ nvme id-ctrl mctp:1,20
  crc mismatch
  NVMe status: Invalid Command Opcode: A reserved coded value or an
    unsupported value in the command opcode field(0x1

After the fix, the rc is -1, and errno is set to Bad message.
  $ nvme id-ctrl mctp:1,20
  crc mismatch
  identify controller: Bad message

Signed-off-by: Jinliang Wang <jinliangw@google.com>
15 months agotree: use logical block size for lba
Daniel Wagner [Fri, 19 Jan 2024 12:07:42 +0000 (13:07 +0100)]
tree: use logical block size for lba

The kernel export the LBA size via the logical_block_size sysfs entry
not the physical_block_size.

Fixes: 7959f52960fd ("tree: read all attributes from sysfs when available")
Signed-off-by: Daniel Wagner <dwagner@suse.de>
15 months agojson-schema: add keyring and tls_key details
Daniel Wagner [Thu, 18 Jan 2024 13:40:40 +0000 (14:40 +0100)]
json-schema: add keyring and tls_key details

Update the JSON schema with the keyring and tls_key details.

Fixes: 7d1a68f13155 ("json-schema: add keyring and tls_key details")
Signed-off-by: Daniel Wagner <dwagner@suse.de>
15 months agobuild: checkout full repo for checkpatch
Daniel Wagner [Thu, 18 Jan 2024 14:20:59 +0000 (15:20 +0100)]
build: checkout full repo for checkpatch

checkpatch likes to verify git references. Thus we need to checkout the
full repo to get this working.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
15 months agolinux: avoid segfault in check-tls-key due to null hostnqn/subsysnqn
Martin George [Thu, 11 Jan 2024 09:31:22 +0000 (15:01 +0530)]
linux: avoid segfault in check-tls-key due to null hostnqn/subsysnqn

Running nvme check-tls-key hits a segfault as seen below:

nvme check-tls-key
-d NVMeTLSkey-1:01:bB7soUnpHfxVg53sCY21KY3nLbqLit2RcIO8Rbdf3mKhcKaM:

Segmentation fault (core dumped)

This is because the strlen check on subsysnqn or hostnqn crashes at
src/nvme/linux.c due to either of them being null. Avoid this segfault
by checking these strings before running a strlen on them.

Signed-off-by: Martin George <marting@netapp.com>
15 months agoMerge pull request #770 from hreinecke/fix-join.v2 origin/HEAD origin/master
Hannes Reinecke [Thu, 18 Jan 2024 12:56:39 +0000 (13:56 +0100)]
Merge pull request #770 from hreinecke/fix-join.v2

meson.build: fixup 'join' syntax

15 months agomeson.build: fixup 'join' syntax
Hannes Reinecke [Thu, 18 Jan 2024 11:31:28 +0000 (12:31 +0100)]
meson.build: fixup 'join' syntax

The 'join' function only takes one argument, so use the correct
syntax here.

Signed-off-by: Hannes Reinecke <hare@suse.de>
15 months agoutil: Explicitly initialize auto-cleanup variables
Tomas Bzatek [Fri, 29 Dec 2023 17:49:44 +0000 (18:49 +0100)]
util: Explicitly initialize auto-cleanup variables

gcc complains about potentially uninitialized variables.

Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
15 months agotree: Explicitly initialize auto-cleanup variables
Tomas Bzatek [Fri, 29 Dec 2023 17:49:36 +0000 (18:49 +0100)]
tree: Explicitly initialize auto-cleanup variables

gcc complains about potentially uninitialized variables.

Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
15 months agolinux: Explicitly initialize auto-cleanup variables
Tomas Bzatek [Fri, 29 Dec 2023 17:49:25 +0000 (18:49 +0100)]
linux: Explicitly initialize auto-cleanup variables

gcc complains about potentially uninitialized variables.

Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
15 months agofabrics: Explicitly initialize auto-cleanup variables
Tomas Bzatek [Fri, 29 Dec 2023 17:37:41 +0000 (18:37 +0100)]
fabrics: Explicitly initialize auto-cleanup variables

gcc complains about potentially uninitialized variables used
in the cleanup function even though such scenario is unlikely
to happen. Still, an explicit initializer makes the warnings
go away.

E.g.

../src/nvme/fabrics.c: In function ‘nvmf_hostnqn_generate’:
../src/nvme/fabrics.c:1297:30: note: ‘stream’ was declared here
 1297 |         _cleanup_file_ FILE *stream;
      |                              ^~~~~~
In function ‘cleanup_fd’,
    inlined from ‘uuid_from_device_tree’ at ../src/nvme/fabrics.c:1189:19,
    inlined from ‘nvmf_hostnqn_generate’ at ../src/nvme/fabrics.c:1350:9:
../src/nvme/cleanup.h:37:17: warning: ‘f’ may be used uninitialized [-Wmaybe-uninitialized]
   37 |                 close(*fd);
      |                 ^~~~~~~~~~

Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
15 months agoutil: Added function to find specific UUID in UUID list.
Leonardo da Cunha [Fri, 15 Dec 2023 15:53:28 +0000 (07:53 -0800)]
util: Added function to find specific UUID in UUID list.

Finds a given UUID in the UUID list returned by identify UUID.

Signed-off-by: Leonardo da Cunha <leonardo.da.cunha@solidigm.com>