]> www.infradead.org Git - users/sagi/libnvme.git/log
users/sagi/libnvme.git
10 months agonvme: check for capability feat=dns_traddr dns-traddr
Sagi Grimberg [Thu, 28 Mar 2024 14:16:27 +0000 (16:16 +0200)]
nvme: check for capability feat=dns_traddr

Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
11 months agolibnvme: Introduce functions to generate host identifier and host NQN
Israel Rukshin [Thu, 18 Apr 2024 14:24:37 +0000 (14:24 +0000)]
libnvme: Introduce functions to generate host identifier and host NQN

The nvmf_hostid_generate() function generates a machine specific
host identifier. This is useful when the host ID can't be derived
from an NQN that doesn't contain a UUID.
Also, add nvmf_hostnqn_generate_from_hostid() to explicitly set UUID
when hostid is not NULL.

Signed-off-by: Israel Rukshin <israelr@nvidia.com>
Reviewed-by: Max Gurtovoy <mgurtovoy@nvidia.com>
11 months agofabrics: Unescape URI elements
Tomas Bzatek [Mon, 13 May 2024 15:38:25 +0000 (17:38 +0200)]
fabrics: Unescape URI elements

This adds support for unescaping percent-encoded URI parts.

Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
11 months agotests: Add uriparser tests
Tomas Bzatek [Wed, 17 Apr 2024 16:06:23 +0000 (18:06 +0200)]
tests: Add uriparser tests

Simple testcase both for valid and malformed URI strings.

Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
11 months agofabrics: Introduce simple URI parser
Tomas Bzatek [Wed, 17 Apr 2024 16:04:34 +0000 (18:04 +0200)]
fabrics: Introduce simple URI parser

A very simple URI parser implementing URI syntax described
in the Boot Specification, rev. 1.0.

Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
11 months agolinux: default init cleanup variable
Daniel Wagner [Fri, 10 May 2024 11:30:53 +0000 (13:30 +0200)]
linux: default init cleanup variable

gcc sometimes has troubles to figure out if a variable is used without
initialization when using the cleanup helpers.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
11 months agolinux: Fix uninitialized variables
Tomas Bzatek [Fri, 3 May 2024 15:19:39 +0000 (17:19 +0200)]
linux: Fix uninitialized variables

In file included from ../src/nvme/linux.c:40:
In function ‘freep’,
    inlined from ‘nvme_get_telemetry_log’ at ../src/nvme/linux.c:169:23:
../src/nvme/cleanup.h:24:9: warning: ‘log’ may be used uninitialized [-Wmaybe-uninitialized]
   24 |         free(*(void **)p);
      |         ^~~~~~~~~~~~~~~~~
../src/nvme/linux.c: In function ‘nvme_get_telemetry_log’:
../src/nvme/linux.c:169:30: note: ‘log’ was declared here
  169 |         _cleanup_free_ void *log;
      |                              ^~~

Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
11 months agotypes: add the nvme Cancel command opcode
Maurizio Lombardi [Thu, 9 May 2024 07:47:12 +0000 (09:47 +0200)]
types: add the nvme Cancel command opcode

Defined by TP4097

Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
11 months agolog: split log variables from root object
Daniel Wagner [Tue, 7 May 2024 14:17:59 +0000 (16:17 +0200)]
log: split log variables from root object

The original plan was to avoid any global variables in the library. Thus
the logging variables were tied to the root object which is available
via the fabric API.

The default NVME API doesn't have the root object thus we had to add a
global variable to set log level etc. But the API to set these variables
is done via the root object.

This approach enforces the caller side to create an default root object
to initialize the default logging level. This introduces unnecessary
complexity on the caller side and wastes resources.

Let's split the default logging setting from the root object.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
11 months agolog: keep log level logic in one place
Daniel Wagner [Fri, 26 Apr 2024 11:20:18 +0000 (13:20 +0200)]
log: keep log level logic in one place

Do not distribute the filtering over several places.

While at it also make it the arguments a bit more readable.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
11 months agolibnvme: sort export map
Daniel Wagner [Fri, 26 Apr 2024 11:34:00 +0000 (13:34 +0200)]
libnvme: sort export map

Sort the entries alphabetically.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
11 months agomi: restore default ep timeout during admin_passthru
Jinliang Wang [Thu, 5 Jan 2023 18:10:44 +0000 (10:10 -0800)]
mi: restore default ep timeout during admin_passthru

Before the fix, the timeout can only increase and also it will change
the default timeout setting permanently.

After the fix, the timeout can be any value provided by the timeout_ms
parameter and also we will restore the default timeout settings.

Signed-off-by: Jinliang Wang <jinliangw@google.com>
11 months agomi: fix the rc for nvme_mi_scan_ep
Hao Jiang [Wed, 7 Dec 2022 22:55:40 +0000 (14:55 -0800)]
mi: fix the rc for nvme_mi_scan_ep

nvme_mi_scan_ep should return error code of calling function.

Signed-off-by: Hao Jiang <jianghao@google.com>
Signed-off-by: Jinliang Wang <jinliangw@google.com>
11 months agoccan/endian.h: Only define __{BIG,LITTLE}_ENDIAN if undefined.
Warner Losh [Fri, 3 May 2024 17:39:42 +0000 (11:39 -0600)]
ccan/endian.h: Only define __{BIG,LITTLE}_ENDIAN if undefined.

When both endian.h and ccan/endian/endian.h are included, we can have
__{BIG,LITTLE}_ENDIAN redefined when compiling with clang on FreeBSD.
Clang and gcc have moved to a predefine for endian orders. glibc defines
these the same as they are defied here, but that's an unsafe assumption
to make. Instead, only define them when __LITTLE_ENDIAN not defined as a
fallback to when the host does not define them in the standard system
headers.

Signed-off-by: Warner Losh <imp@bsdimp.com>
11 months agoUse C99 types for uint32_t
Sam James [Sat, 4 May 2024 09:59:16 +0000 (10:59 +0100)]
Use C99 types for uint32_t

<stdint.h> provides `uint32_t`, while `u_int_32` is an unofficial/internal
typedef that glibc happens to provide. This fixes the build on musl.

Bug: https://bugs.gentoo.org/931194

Signed-off-by: Sam James <sam@gentoo.org>
11 months agomi: fix the return error code.
Hao Jiang [Tue, 6 Dec 2022 00:48:35 +0000 (16:48 -0800)]
mi: fix the return error code.

When returning a system error code (i.e. rc < 0), the function should
return -1 and set errno instead of returning the errno directly. It is
very helpful for the client to handle the rc in an unified way.

Signed-off-by: Hao Jiang <jianghao@google.com>
Signed-off-by: Jinliang Wang <jinliangw@google.com>
11 months agoexamples: Include sys/stat.h for S_I* constants
Warner Losh [Fri, 3 May 2024 16:14:29 +0000 (10:14 -0600)]
examples: Include sys/stat.h for S_I* constants

POSIX says that these constants are defined in sys/stat.h. On Linux with
glibc and musl this is also defined in fcntl.h. Other systems define it
only in sys/stat.h, so include that as well. The Linux headers ensure
that the first of sys/stat.h or fcntl.h define the constant, so it's
harmless to include both.

For the latest standard, IEEE Std 1003.1-2017, see
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/fcntl.h.html
and
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_stat.h.html
for details.

Signed-off-by: Warner Losh <imp@bsdimp.com>
11 months agodoc: Regenerate all docs for v1.9
Daniel Wagner [Fri, 3 May 2024 12:08:20 +0000 (14:08 +0200)]
doc: Regenerate all docs for v1.9

Signed-off-by: Daniel Wagner <dwagner@suse.de>
11 months agobuild: Update version to v1.9
Daniel Wagner [Fri, 3 May 2024 12:07:33 +0000 (14:07 +0200)]
build: Update version to v1.9

Signed-off-by: Daniel Wagner <dwagner@suse.de>
11 months agotypes: Added Command and Feature Lockdown LID
Leonardo da Cunha [Thu, 2 May 2024 23:08:20 +0000 (16:08 -0700)]
types: Added Command and Feature Lockdown LID

NVMe Spec 2.0 added LID 0x14.

Signed-off-by: Leonardo da Cunha <leonardo.da.cunha@solidigm.com>
11 months agotypes: add ASQ, ACQ and BPMBL controller properties definitions
Tokunori Ikegami [Wed, 1 May 2024 10:52:44 +0000 (19:52 +0900)]
types: add ASQ, ACQ and BPMBL controller properties definitions

Since the base address fields shift amount is 12 but not 0.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
11 months agotypes: add controller properties enum documentation
Tokunori Ikegami [Wed, 1 May 2024 06:43:12 +0000 (15:43 +0900)]
types: add controller properties enum documentation

All remained enum definitions missed documentation added.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
11 months agotypes: fix CRTO.CRIMT mask value definition
Tokunori Ikegami [Wed, 1 May 2024 06:45:26 +0000 (15:45 +0900)]
types: fix CRTO.CRIMT mask value definition

Fixes: 0b14eb6930fe ("types: Add new enums and defines for TP-4084")
Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
11 months agotree: use strtou32 to read lba_size
Daniel Wagner [Tue, 30 Apr 2024 14:53:49 +0000 (16:53 +0200)]
tree: use strtou32 to read lba_size

The lba_size variable is of type int, thus we should use nvme_strtou32
and avoid overwriting memory.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
11 months agotypes: Fix PMRWBM register name
Tokunori Ikegami [Mon, 29 Apr 2024 14:01:39 +0000 (23:01 +0900)]
types: Fix PMRWBM register name

Incorrectly defined as PMRWMB.
Also add enum nvme_pmrcap documentation.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
11 months agoexamples: fix mi-mctp build warning errors
Tokunori Ikegami [Sun, 28 Apr 2024 14:44:36 +0000 (23:44 +0900)]
examples: fix mi-mctp build warning errors

Initialize net and eid variables to 0.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
11 months agotest: add CSTS.ST, CAP.CPS and CAP.NSSS registers
Tokunori Ikegami [Sun, 28 Apr 2024 13:12:05 +0000 (22:12 +0900)]
test: add CSTS.ST, CAP.CPS and CAP.NSSS registers

Added by NVMe revision 2.0 changes.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
11 months agotypes: add CAP.CPS and CAP.NSSS definitions
Tokunori Ikegami [Sun, 28 Apr 2024 02:55:55 +0000 (11:55 +0900)]
types: add CAP.CPS and CAP.NSSS definitions

Added by NVMe revision 2.0 changes.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
11 months agotypes: add enum nvme_cap documentation
Tokunori Ikegami [Sun, 28 Apr 2024 02:43:49 +0000 (11:43 +0900)]
types: add enum nvme_cap documentation

Since missed to add the documentatin.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
11 months agotypes: Add enum nvme_unit/cmbebs/cmbswtp/flbas/cmic documentation
Tokunori Ikegami [Fri, 26 Apr 2024 11:38:11 +0000 (20:38 +0900)]
types: Add enum nvme_unit/cmbebs/cmbswtp/flbas/cmic documentation

Since missed to add the documentatin.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
11 months agoutil: Add string constant for ENVME_CONNECT_IGNORED
Tomas Bzatek [Thu, 25 Apr 2024 15:09:44 +0000 (17:09 +0200)]
util: Add string constant for ENVME_CONNECT_IGNORED

for use through nvme_errno_to_string().

Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
11 months agotests: Add sample NBFT table with mpath IPv4+IPv6 discovery
Tomas Bzatek [Thu, 25 Apr 2024 14:50:38 +0000 (16:50 +0200)]
tests: Add sample NBFT table with mpath IPv4+IPv6 discovery

A sample table generated by latest EDK2 snapshot:
- two HFIs: static IPv4 and static IPv6
- two boot attempts defined for each HFI (multipath)
  with the well-known discovery NQN
- second NIC link down

Result:
- the first boot attempt properly discovered
- the second boot attempt transformed in an SSNS record
  with the discovery NQN and marked as unavailable
- two Discovery Descriptor records corresponding with
  the boot attempts and linked to corresponding SSNS records

Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
12 months agotypes: add controller status shutdown type (CSTS.ST) definition
Tokunori Ikegami [Sun, 21 Apr 2024 02:43:37 +0000 (11:43 +0900)]
types: add controller status shutdown type (CSTS.ST) definition

Added by NVMe revision 2.0 multiple controller shutdown enhancement.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
12 months agotypes: Add enum nvme_csts documentation
Tokunori Ikegami [Sun, 21 Apr 2024 02:34:02 +0000 (11:34 +0900)]
types: Add enum nvme_csts documentation

Since missed to add the documentatin.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
12 months agotypes: Add NVME_CMIC definitions
Tokunori Ikegami [Wed, 17 Apr 2024 15:43:39 +0000 (00:43 +0900)]
types: Add NVME_CMIC definitions

The existing NVME_CTRL_CMIC definitions are complex values.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
12 months agotypes: Add CMBSWTP property definitions
Tokunori Ikegami [Mon, 15 Apr 2024 14:20:01 +0000 (23:20 +0900)]
types: Add CMBSWTP property definitions

Also change PMRSWTU to use NVME_UNIT definitions.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
12 months agotypes: Add NVME_CMBEBS property definitions
Tokunori Ikegami [Mon, 15 Apr 2024 13:59:43 +0000 (22:59 +0900)]
types: Add NVME_CMBEBS property definitions

Also add NVME_UNIT definitions for CMBSZU and PMRSZU.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
12 months agotypes: Fix boot partition read offset (BPROF) mask value
Tokunori Ikegami [Sun, 14 Apr 2024 07:52:50 +0000 (16:52 +0900)]
types: Fix boot partition read offset (BPROF) mask value

The register bits defined 29:10 as 20 bits width mask.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
12 months agotree: fix mem leak in nvme_ns_init()
Martin George [Mon, 15 Apr 2024 06:58:43 +0000 (12:28 +0530)]
tree: fix mem leak in nvme_ns_init()

Valgrind revealed a mem leak in nvme_ns_init() invoked by
several nvme commands such as connect-all, list, disconnect-all,
etc. Leak traced to the nvme_ns_id pointer not getting freed
after use. Fix the same.

Signed-off-by: Martin George <marting@netapp.com>
12 months agoRevert "ioctl: return EPROTO when an NVMe status occurred"
Daniel Wagner [Fri, 12 Apr 2024 11:04:05 +0000 (13:04 +0200)]
Revert "ioctl: return EPROTO when an NVMe status occurred"

This reverts commit 3089da58d2c35b3b700c1eb88540f96cfe0e87ad.

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 "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>