]> www.infradead.org Git - users/sagi/libnvme.git/log
users/sagi/libnvme.git
21 months agotest: handle POSIX ioctl prototype
Sam James [Sat, 30 Sep 2023 05:38:53 +0000 (06:38 +0100)]
test: handle POSIX ioctl prototype

glibc has the following prototype for ioctl: int ioctl(int fd, unsigned long request, ...)
POSIX (inc. musl) has the following for ioctl: int ioctl(int fd, int request, ...)

Check which prototype is used in <sys/ioctl.h> to avoid a conflict and conditionally
define the right one for the system.

Bug: https://bugs.gentoo.org/914921
Signed-off-by: Sam James <sam@gentoo.org>
21 months agodoc: Regenerate all docs for v1.6 v1.6
Daniel Wagner [Fri, 29 Sep 2023 06:26:50 +0000 (08:26 +0200)]
doc: Regenerate all docs for v1.6

Signed-off-by: Daniel Wagner <dwagner@suse.de>
21 months agobuild: Update version to v1.6
Daniel Wagner [Fri, 29 Sep 2023 06:26:28 +0000 (08:26 +0200)]
build: Update version to v1.6

Signed-off-by: Daniel Wagner <dwagner@suse.de>
21 months agodocs: Fix Read-the-Docs configuration (deprecated config param)
Martin Belanger [Wed, 27 Sep 2023 15:25:41 +0000 (11:25 -0400)]
docs: Fix Read-the-Docs configuration (deprecated config param)

Signed-off-by: Martin Belanger <martin.belanger@dell.com>
21 months agoREADME: Fix meson/python build badges
Martin Belanger [Wed, 27 Sep 2023 15:22:13 +0000 (11:22 -0400)]
README: Fix meson/python build badges

Signed-off-by: Martin Belanger <martin.belanger@dell.com>
22 months agomi-mctp: Fix free() in error path of mi_open_mctp
Jeremy Kerr [Sat, 23 Sep 2023 16:44:50 +0000 (09:44 -0700)]
mi-mctp: Fix free() in error path of mi_open_mctp

If the malloc of our struct nvme_mi_transport_mctp fails, we'll attempt
to free ->rsp_buf of this (now zero) pointer.

Instead, structure the error path to progressively undo the
initialisation operations. This means we'll need to save the errno at
the site of each possible failure.

In doing this, add a comment to the call to nvme_mi_close(), just to
clarify behaviour with regards to the cleanups through that path.

Reported-by: Barnabás Pőcze <pobrn@protonmail.com>
Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
22 months agotypes: Use NVME_SET for status type mask to get status value
Tokunori Ikegami [Sat, 17 Jun 2023 01:56:26 +0000 (10:56 +0900)]
types: Use NVME_SET for status type mask to get status value

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
22 months agotypes: Define FLBAS MASK and SHIFT to use NVME_GET
Tokunori Ikegami [Sat, 17 Jun 2023 01:24:56 +0000 (10:24 +0900)]
types: Define FLBAS MASK and SHIFT to use NVME_GET

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
22 months agobuild: abort CI builds on first error
Daniel Wagner [Thu, 21 Sep 2023 07:27:35 +0000 (09:27 +0200)]
build: abort CI builds on first error

Do not continue to build and hide any errors.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
22 months agotypes: Support Phy Rx Eye Opening Measurement Log
Brandon Paupore [Tue, 12 Sep 2023 21:45:31 +0000 (16:45 -0500)]
types: Support Phy Rx Eye Opening Measurement Log

This implements support for TP4119a, adding various fields and functions
to enable better handling of the new Physical Receiver Eye Opening
Measurement log page.

Signed-off-by: Brandon Paupore <brandon.paupore@wdc.com>
22 months agolog: Add nvme root global variable to set for default output
Tokunori Ikegami [Mon, 26 Jun 2023 15:06:59 +0000 (00:06 +0900)]
log: Add nvme root global variable to set for default output

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
[dwagner: export new function, update docs, reorder free sequence]
Signed-off-by: Daniel Wagner <dwagner@suse.de>
22 months agotypes: Add support for the OAQD ID controller field
Brandon Paupore [Fri, 8 Sep 2023 20:30:33 +0000 (15:30 -0500)]
types: Add support for the OAQD ID controller field

Signed-off-by: Brandon Paupore <brandon.paupore@wdc.com>
[dwagner: dropped generated documentation change]
Signed-off-by: Daniel Wagner <dwagner@suse.de>
22 months agotest: use non deprecated API
Daniel Wagner [Wed, 20 Sep 2023 08:30:19 +0000 (10:30 +0200)]
test: use non deprecated API

A few of the feature related function have been deprecated. Update the
test to use the new APIs instead of the old one.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
22 months agotest: add tests for Get/Set Features functions
Caleb Sander [Fri, 8 Sep 2023 19:07:36 +0000 (13:07 -0600)]
test: add tests for Get/Set Features functions

Use the mock ioctl() infrastructure to test the functions in ioctl.h
that issue Set Features and Get Features commands.

Signed-off-by: Caleb Sander <csander@purestorage.com>
22 months agoioctl: implement nvme_set_features_lba_range()
Caleb Sander [Fri, 15 Sep 2023 01:22:58 +0000 (19:22 -0600)]
ioctl: implement nvme_set_features_lba_range()

nvme_set_features_lba_range() was missing an implementation,
so add one. Change nr_ranges to a u8 since its maximum value is 64.

Signed-off-by: Caleb Sander <csander@purestorage.com>
22 months agoioctl: pass NSID in Get/Set Features commands that use it
Caleb Sander [Fri, 15 Sep 2023 19:20:19 +0000 (13:20 -0600)]
ioctl: pass NSID in Get/Set Features commands that use it

Several features are configured on a per-namespace basis
by setting the NSID in the Set Features and Get Features commands.
But the corresponding nvme_{g,s}et_features_*() functions
aren't passing the NSID in the commands.
For the functions missing a NSID parameter, define new variants
with the NSID argument added and mark the old functions as deprecated.

Signed-off-by: Caleb Sander <csander@purestorage.com>
22 months agoioctl: fix swapped parameters in nvme_set_features_host_id()
Caleb Sander [Thu, 14 Sep 2023 21:52:17 +0000 (15:52 -0600)]
ioctl: fix swapped parameters in nvme_set_features_host_id()

nvme_set_features_host_id()'s prototype says the parameter EXHID
comes before SAVE, but its definition does the opposite,
causing the parameters to be misinterpreted.
Match the definition to the declaration.

Signed-off-by: Caleb Sander <csander@purestorage.com>
22 months agoioctl: export nvme_{g,s}et_features_iocs_profile()
Caleb Sander [Thu, 14 Sep 2023 21:14:13 +0000 (15:14 -0600)]
ioctl: export nvme_{g,s}et_features_iocs_profile()

nvme_get_features_iocs_profile() and nvme_set_features_iocs_profile()
are defined but not exorted in libnvme.so.
nvme_set_features_iocs_profile()'s prototype was also removed,
so add it back.
IOCSI is a 9-bit value, so fix its bitmask and change its type to u16.

Signed-off-by: Caleb Sander <csander@purestorage.com>
22 months agoioctl: pass ENDGID in nvme_get_features_endurance_event_cfg()
Caleb Sander [Thu, 14 Sep 2023 20:56:31 +0000 (14:56 -0600)]
ioctl: pass ENDGID in nvme_get_features_endurance_event_cfg()

The ENDGID parameter of nvme_get_features_endurance_event_cfg()
is currently unused.
According to the NVMe spec, it should be passed in CDW 11.

Signed-off-by: Caleb Sander <csander@purestorage.com>
22 months agoioctl: don't set SAVE bit on unsaveable features
Caleb Sander [Thu, 14 Sep 2023 20:23:39 +0000 (14:23 -0600)]
ioctl: don't set SAVE bit on unsaveable features

According to the NVMe spec, the Host Behavior
and Write Protection features are not saveable.
Setting the SAVE bit may cause the Set Features command to be rejected,
so don't set it for these features.

Signed-off-by: Caleb Sander <csander@purestorage.com>
22 months agoioctl: avoid sending uninitialized timestamp
Caleb Sander [Fri, 8 Sep 2023 19:47:16 +0000 (13:47 -0600)]
ioctl: avoid sending uninitialized timestamp

The last 2 bytes of the struct nvme_timestamp data
are not initialized in nvme_set_features_timestamp().
Add an initializer to avoid sending uninitialized stack memory
to the controller.

Signed-off-by: Caleb Sander <csander@purestorage.com>
22 months agoioctl: pass data for Get/Set Features commands
Caleb Sander [Fri, 8 Sep 2023 18:10:08 +0000 (12:10 -0600)]
ioctl: pass data for Get/Set Features commands

Several nvme_{g,s}et_features_*() functions take a data buffer
but don't provide it to the Get/Set Features commands.
Fix them to pass the data buffer to nvme_{g,s}et_features().

Getting the Host Memory Buffer feature also returns
a struct nvme_host_mem_buf_attrs data structure,
so make a nvme_get_features_host_mem_buf2() function
that takes in a data buffer to receive it.

Signed-off-by: Caleb Sander <csander@purestorage.com>
22 months agoioctl: set correct bits in Set Features commands
Caleb Sander [Fri, 8 Sep 2023 16:51:19 +0000 (10:51 -0600)]
ioctl: set correct bits in Set Features commands

A few nvme_set_features_*() functions are setting the wrong bits in
CDW11 based on their inputs. Correct the fields passed to NVME_SET().

Signed-off-by: Caleb Sander <csander@purestorage.com>
22 months agoioctl: correct feature IDs in Get/Set Features commands
Caleb Sander [Fri, 8 Sep 2023 18:21:04 +0000 (12:21 -0600)]
ioctl: correct feature IDs in Get/Set Features commands

Several nvme_{g,s}et_features_*() functions use the wrong feature ID.
Correct them so the intended feature is requested.

Signed-off-by: Caleb Sander <csander@purestorage.com>
22 months agotree: Add 2 new public functions to lookup existing controllers
Martin Belanger [Tue, 12 Sep 2023 19:55:55 +0000 (15:55 -0400)]
tree: Add 2 new public functions to lookup existing controllers

There is duplicate code between libnvme and nvme-cli. When trying
to instantiate a controller, both libnvme and nvme-cli scan the
sysfs looking for an existing controller that can be reused.

This patch adds nvme_ctrl_find() and nvme_ctrl_config_match().
These functions can be used by nvme-cli to lookup existing
controllers. This will allow removing the duplicate code in
nvme-cli (separate commit to follow on the nvme-cli GitHub repo).

Signed-off-by: Martin Belanger <martin.belanger@dell.com>
22 months agoioctl: Add debugging feature to show command outputs
Tokunori Ikegami [Tue, 12 Sep 2023 14:42:32 +0000 (23:42 +0900)]
ioctl: Add debugging feature to show command outputs

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
22 months agoFix incorrect article 'an' as 'a' to use for a description
Tokunori Ikegami [Mon, 15 May 2023 15:48:18 +0000 (00:48 +0900)]
Fix incorrect article 'an' as 'a' to use for a description

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
22 months agolinux: Added functions to enable faster telemetry data retrieval.
da Cunha, Leonardo [Wed, 23 Aug 2023 18:26:39 +0000 (11:26 -0700)]
linux: Added functions to enable faster telemetry data retrieval.
Moved telemetry data area support detection into separate function.
Added possibility to modify data transfer chunk size.
Enable telemetry extraction up to specified data area.
Removed some printf() and perror().

Signed-off-by: leonardo.da.cunha <leonardo.da.cunha@solidigm.com>
22 months agobuild(deps): bump actions/checkout from 3 to 4
dependabot[bot] [Mon, 11 Sep 2023 02:39:36 +0000 (02:39 +0000)]
build(deps): bump actions/checkout from 3 to 4

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

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
22 months agotest: account for discovery log page entry stripping
Caleb Sander [Wed, 30 Aug 2023 16:45:57 +0000 (10:45 -0600)]
test: account for discovery log page entry stripping

The discovery log page tests incorrectly assumed the log page
nvmf_get_discovery_log() returns exactly matches what was fetched.
This failed to account for the trailing space trimming
of the TRSVCID and TRADDR fields.
If the arbitrary entries happened to contain trailing spaces
for these fields, the test cases would fail.
Generate arbitrary entries with space-padded strings for the log page
and corresponding expected entries with NUL-padded strings.

Signed-off-by: Caleb Sander <csander@purestorage.com>
22 months agofabrics: unconditionally strip discovery entry strings
Caleb Sander [Wed, 30 Aug 2023 15:53:19 +0000 (09:53 -0600)]
fabrics: unconditionally strip discovery entry strings

The NVMe base specification defines fields TRSVCID and TRADDR
as "ASCII strings", meaning they are space-padded.
Therefore, whether spaces need to be stripped from them
doesn't depend on the transport or address family.
Some combinations already appear to be missing,
such as RDMA using IB addresses.
And if new transports are added in the future,
sanitize_discovery_log_entry() would need to be updated.

So strip spaces from these fields regardless of the entry's
transport type or address family.

Signed-off-by: Caleb Sander <csander@purestorage.com>
22 months agofabrics: only look for spaces in strchomp()
Caleb Sander [Wed, 30 Aug 2023 15:44:48 +0000 (09:44 -0600)]
fabrics: only look for spaces in strchomp()

strchomp() is only needed to strip trailing spaces from a string.
There is no need to replace NUL characters with NUL characters.
So simplify the check for "NUL or space" to just "space".
Update the function description as well,
as it doesn't strip all whitespace, just spaces.

Signed-off-by: Caleb Sander <csander@purestorage.com>
22 months agotree: Use early return instead of else statements
Martin Belanger [Thu, 31 Aug 2023 15:01:51 +0000 (11:01 -0400)]
tree: Use early return instead of else statements

The code could be simplified and made more readable by using
early returns instead of else statements.

Signed-off-by: Martin Belanger <martin.belanger@dell.com>
22 months agobuild: use latest container instead fixed version master
Daniel Wagner [Thu, 31 Aug 2023 14:19:50 +0000 (16:19 +0200)]
build: use latest container instead fixed version

We control the build containers so there is little risk
that these randomly break. So let's go with the latest
version and avoid updating the build files all the time.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
22 months agobuild: run tests before coverage tool
Daniel Wagner [Thu, 31 Aug 2023 12:12:12 +0000 (14:12 +0200)]
build: run tests before coverage tool

Obviously, we need to run the tests before the coverage tool.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
22 months agobuild: fix coverage report build
Daniel Wagner [Thu, 31 Aug 2023 12:03:34 +0000 (14:03 +0200)]
build: fix coverage report build

We need to run the build first, before we can run the coverage tool.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
22 months agobuild: checkout repo in coverage build
Daniel Wagner [Thu, 31 Aug 2023 09:45:47 +0000 (11:45 +0200)]
build: checkout repo in coverage build

The previous commit removed accidentally the checkout step.
Add it back.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
22 months agobuild: use container for coverage build
Daniel Wagner [Thu, 31 Aug 2023 09:40:17 +0000 (11:40 +0200)]
build: use container for coverage build

The coverage build also fails due missing dependency in
install step. Let's use a prebuild container here as well.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
22 months agobuild: use debian container for release-python build
Daniel Wagner [Thu, 31 Aug 2023 07:37:19 +0000 (09:37 +0200)]
build: use debian container for release-python build

The build keeps failing because the dependencies can't be installed.
Let's use the prebuild container for this as well.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
22 months agobuild: use prebuild container images for cross builds
Daniel Wagner [Wed, 30 Aug 2023 17:31:11 +0000 (19:31 +0200)]
build: use prebuild container images for cross builds

The cross tool installation is breaking very often. Let's use a prebuild
container for this.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
22 months agotest: fix lookup test case
Daniel Wagner [Wed, 30 Aug 2023 14:38:42 +0000 (16:38 +0200)]
test: fix lookup test case

The tcp lookup test is not correct. The trsvcid is mandatory and thus we
have only to try to lookup all combination of host_traddr and host_iface.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
22 months agotest: make all function static
Daniel Wagner [Wed, 30 Aug 2023 12:54:51 +0000 (14:54 +0200)]
test: make all function static

No need to export local functions.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
22 months agotest: add tests for new tcp controller matching algorithm
Martin Belanger [Fri, 18 Aug 2023 01:36:01 +0000 (21:36 -0400)]
test: add tests for new tcp controller matching algorithm

Signed-off-by: Martin Belanger <martin.belanger@dell.com>
22 months agotree: Improve TCP controller matching algorithm
Martin Belanger [Fri, 18 Aug 2023 01:35:34 +0000 (21:35 -0400)]
tree: Improve TCP controller matching algorithm

The configuration parameters used to connect to a TCP controller are:

1. transport - "tcp"
2. traddr - Destination address (controller's IP address)
3. trsvcid - Service ID (controller's port - typically 8009 or 4420)
4. host-traddr - Source address (host's IP address)
5. host-iface - Physical/Logical interface where the connection will be made

For TCP, transport, traddr, and trsvcid are mandatory, while the
host-traddr and host-iface are optional. The host-traddr and host-iface
can be used as "overrides" to select a different source address and
interface than those that the kernel would choose by default.

When an application using libnvme to connect to a controller does
not specify the host-traddr or host-iface, the kernel will have to
determine the best interface and source address by itself. It does that
by looking up the destination address (traddr) in the routing table to
determine the best interface for the connection. The kernel then
retrieves the primary IP address assigned to that interface and uses that
as the connection's source address. By default, the kernel always uses
the interface's primary address as the connection's source address
unless host-traddr is used to override it.

Prior to version 6.1, the kernel did not reveal the source address or
interface it selected. Therefore, it was impossible for user-space apps
to tell exactly where connections were made. With kernel 6.1 (and later),
the sysfs now exposes the source address as "src_addr=" in the nvme
"address" attribute. The src_addr not only provides us with the
connection's source address, but by scanning the interface map one can
find out which interface owns that source address and precisely determine
on which interface each connection is made.

With TP8010 and the introduction of the Centralized Discovery Controller
(CDC), it is very important for hosts to connect to CDCs with a consistent
source address. That's because of the way the CDC keeps track of all the
hosts that connect to it. In addition to the host NQN, the CDC also checks
the host IP address (the connection's source address) to uniquely identify
a host. This unique identifier is then used for fabric zoning.

With fabric zoning, administrators configure the list of I/O controllers
that a host is allowed to connect to. The CDC sends the list of I/O
controllers to the host in response to a Get Discovery Log Page (DLP)
command from the host. If a host does not connect to the CDC with the
right source address, it will receive invalid DLP entries (wrong zone).
This will cause the host to connect to the wrong I/O controllers.

libnvme tries to avoid making duplicate connections to the same
controller. This avoids consuming precious kernel resources. When an
application requests libnvme to connect to a controller (the candidate
controller), libnvme scans the sysfs to see if an existing connection
matches the candidate. If a matching connection is found, libnvme just
reuses it instead of creating a new one.

Matching the 3 mandatory parameters (transport, traddr, trsvcid) between
existing connections and a candidate connection is easy because they can
never be NULL and can therefore be compared. It is not the case for the
host-traddr and host-iface. These optional parameters can be NULL. A NULL
host-traddr or host-iface means that we have left it to the kernel to
determine the interface and source address to use for the connection.
Therefore, if we want to compare a non-NULL candidate host-traddr to
an existing connection with a NULL host-traddr, we cannot just compare the
two. They will obviously be different. Instead, we need to check the
src_addr of the existing connection to see if it matches the candidate's
host-traddr.

Prior to this patch, libnvme performed a simple string comparison
between the candidate's host-traddr (or host-iface) and the existing
connection's host-traddr (or host-iface). A match would be declared if
both were the same (including both NULL). Also, a match would even be
declared if the existing connection's host-traddr (or host-iface) was
NULL while the candidate's host-traddr (or host-iface) was non-NULL.
This is wrong and can lead to the wrong connections being reused and
the wrong DLP entries returned by the CDC.

With this patch, when a candidate wants a specific source address
(host-traddr != NULL) or interface (host-iface != NULL), libnvme will
now check the src_addr of each existing connection to ensure a 100%
match. If the src_addr is not available (kernel older than 6.1), then we
can still infer the real interface and source address of an existing
connection, if the existing connection has either its host-traddr or
host-iface defined (check code to see how it's done).

It's only when an exsiting connection's src_addr, host-iface, and
host-traddr are all NULL that we cannot clearly match to a candidate.
When that happens, libnvme will take an optimistic approach and
declare a match even though it doesn't have enough info to do so.
This "optimistic match" follows what libnvme was doing prior to this
patch.

Signed-off-by: Martin Belanger <martin.belanger@dell.com>
22 months agoutil: Add functions to parse the system's interfaces
Martin Belanger [Fri, 18 Aug 2023 01:28:57 +0000 (21:28 -0400)]
util: Add functions to parse the system's interfaces

1) nvme_iface_matching_addr() identifies which interface owns a
specific IP address.

2) nvme_iface_primary_addr_matches() checks that the primary IP
address of a given interface matches a specific IP address.

Signed-off-by: Martin Belanger <martin.belanger@dell.com>
23 months agotypes: Add support for EGFEAT, Domain Identifier, TEGCAP and UEGCAP
Tokunori Ikegami [Fri, 18 Aug 2023 20:08:15 +0000 (05:08 +0900)]
types: Add support for EGFEAT, Domain Identifier, TEGCAP and UEGCAP

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
23 months agomi: remove nsid from nvme_mi_admin_identify_secondary_ctrl_list()
Daniel Wagner [Sat, 19 Aug 2023 10:44:07 +0000 (12:44 +0200)]
mi: remove nsid from nvme_mi_admin_identify_secondary_ctrl_list()

According to the NVMe specification, Identify CNS value 15h
("Secondary Controller list of controllers associated with the primary
controller processing the command") does not use the NSID field. So
remove the "nsid" argument from
nvme_mi_admin_identify_secondary_ctrl_list().

Fixes: 07b63103878 ("ioctl: remove nsid from nvme_identify_secondary_ctrl_list()")
Signed-off-by: Daniel Wagner <dwagner@suse.de>
23 months agotest: add tests for nvme_ctrl_get_src_addr()
Martin Belanger [Thu, 17 Aug 2023 11:57:50 +0000 (07:57 -0400)]
test: add tests for nvme_ctrl_get_src_addr()

Signed-off-by: Martin Belanger <martin.belanger@dell.com>
23 months agotree: Add nvme_ctrl_get_src_addr() to get the controller's src_addr
Martin Belanger [Thu, 17 Aug 2023 10:46:26 +0000 (06:46 -0400)]
tree: Add nvme_ctrl_get_src_addr() to get the controller's src_addr

Signed-off-by: Martin Belanger <martin.belanger@dell.com>
23 months agoutil: Split _nvme_ipaddrs_eq() from nvme_ipaddrs_eq()
Martin Belanger [Thu, 17 Aug 2023 10:44:45 +0000 (06:44 -0400)]
util: Split _nvme_ipaddrs_eq() from nvme_ipaddrs_eq()

Extract the core algorithm from nvme_ipaddrs_eq() and create
a reusable function _nvme_ipaddrs_eq().

Signed-off-by: Martin Belanger <martin.belanger@dell.com>
23 months agotest: add tests for Identify functions
Caleb Sander [Sat, 12 Aug 2023 20:50:47 +0000 (14:50 -0600)]
test: add tests for Identify functions

Use the mock ioctl() infrastructure to test  the functions in ioctl.h
that issue Identify commands.
nvme_identify_ns_csi_user_data_format() and
nvme_identify_iocs_ns_csi_user_data_format() are omitted
since they're not defined in the NVMe specification yet
Functions tested indirectly from other functions are also omitted.

Signed-off-by: Caleb Sander <csander@purestorage.com>
23 months agoioctl: use available Identify helper functions
Caleb Sander [Sat, 12 Aug 2023 20:50:03 +0000 (14:50 -0600)]
ioctl: use available Identify helper functions

nvme_identify_independent_identify_ns() only specifies a CNS and a NSID,
so have it just call nvme_identify_cns_nsid()
instead of duplicating most of its implementation.
Similarly, nvme_zns_identify_ns() is just nvme_identify_ns_csi()
with the CSI set to ZNS and no UUID index.

Signed-off-by: Caleb Sander <csander@purestorage.com>
23 months agotest: pass a large enough buffer to nvme_identify_ns_descs()
Caleb Sander [Sat, 12 Aug 2023 19:55:12 +0000 (13:55 -0600)]
test: pass a large enough buffer to nvme_identify_ns_descs()

nvme_identify_ns_descs() takes a struct nvme_ns_id_desc * parameter,
but passes it as the data to nvme_identify(), which sets data_len = 4K.
But struct nvme_ns_id_desc only represents the start of a single
Namespace Identification Descriptor, so it is less than 4 KB.
So it needs to be explicitly allocated with at least 4 KB.
Allocate a 4 KB buffer in test.c to avoid a stack buffer overflow.

Signed-off-by: Caleb Sander <csander@purestorage.com>
23 months agoioctl: remove nsid from nvme_identify_secondary_ctrl_list()
Caleb Sander [Sat, 12 Aug 2023 19:51:18 +0000 (13:51 -0600)]
ioctl: remove nsid from nvme_identify_secondary_ctrl_list()

According to the NVMe specification, Identify CNS value 15h
("Secondary Controller list of controllers associated with
the primary controller processing the command")
does not use the NSID field.
So remove the "nsid" argument from nvme_identify_secondary_ctrl_list().

Signed-off-by: Caleb Sander <csander@purestorage.com>
23 months agobuild: clean up version script
Caleb Sander [Wed, 16 Aug 2023 21:20:27 +0000 (15:20 -0600)]
build: clean up version script

Remove symbols from libnvme.map that don't exist in libnvme.so.
These are a mix of static inline functions,
static (unexported) functions, nonexistent functions, and types.
Also remove a couple of duplicate symbols.

Bash script to find unexported symbols:
for symbol in `grep -o nvm[ef]_[a-z0-9_]* src/libnvme.map`
do
    if nm -D .build/src/libnvme.so | grep $symbol$ > /dev/null
    then
        true
    else
        echo $symbol
    fi
done

Bash command to find duplicated symbols:
grep nvm src/libnvme.map | uniq -c | grep -v '^\s*1 '

Signed-off-by: Caleb Sander <csander@purestorage.com>
23 months agomeson: Don't hard-code path to "internal/config.h"
Martin Belanger [Tue, 15 Aug 2023 19:16:24 +0000 (15:16 -0400)]
meson: Don't hard-code path to "internal/config.h"

When building libnvme as a subproject of another project
(e.g. nvme-stas), the hard-coded absolute path to config.h, i.e.
"-include internal/config.h" does not resolve properly and fails
to build. Instead, use the real path calculated by meson and
saved to variable "config_h".

Signed-off-by: Martin Belanger <martin.belanger@dell.com>
23 months agofabrics: Do not pass disable_sqflow if not supported
Daniel Wagner [Tue, 8 Aug 2023 06:34:05 +0000 (08:34 +0200)]
fabrics: Do not pass disable_sqflow if not supported

Do not try to use disable_sqflow if the kernel actually supports this
option.

Reported-by: Sagi Grimberg <sagi@grimberg.me>
Signed-off-by: Daniel Wagner <dwagner@suse.de>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
23 months agofabrics: Read the supported options lazy
Daniel Wagner [Tue, 8 Aug 2023 06:37:19 +0000 (08:37 +0200)]
fabrics: Read the supported options lazy

Read the options in when we need the for the first time.

Reported-by: Sagi Grimberg <sagi@grimberg.me>
Signed-off-by: Daniel Wagner <dwagner@suse.de>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
23 months agotest: add discovery log page tests
Caleb Sander [Mon, 31 Jul 2023 18:22:18 +0000 (12:22 -0600)]
test: add discovery log page tests

Add unit tests for nvmf_get_discovery_log().
They provide coverage of the logic in nvme_discovery_log(),
nvme_get_log_page(), and nvme_get_log() too.
The tests use the mock ioctl() infra to validate the Get Log Page
commands issued and inject responses triggering different code paths.

Signed-off-by: Caleb Sander <csander@purestorage.com>
23 months agotest: add infra for mocking passthru ioctls
Caleb Sander [Sun, 30 Jul 2023 23:08:59 +0000 (17:08 -0600)]
test: add infra for mocking passthru ioctls

Functions issuing admin/IO passthru ioctls sorely lack unit tests.
It would be great for unit tests not to need a real NVMe controller.
It's also useful to be able to test responses to commands
that might be impossible to trigger with real controllers.

To that end, implement infrastructure for mocking ioctl(),
allowing tests to set expectations for the NVMe passthru ioctls
that will be issued and control the corresponding responses.

The mock library can be used with LD_PRELOAD so that libnvme's ioctl()
calls are redirected from libc. No changes in libnvme itself are needed.

Signed-off-by: Caleb Sander <csander@purestorage.com>
23 months agotree: fix segfault in nvme_scan_subsystem()
Martin George [Tue, 8 Aug 2023 16:30:25 +0000 (22:00 +0530)]
tree: fix segfault in nvme_scan_subsystem()

The wrong nvme_subsystem struct was being passed to
__nvme_subsystem_scan() which caused it to segfault.
Fix it.

Fixes: d08fd10 ("make __nvme_scan_subsystem() returning bool")
Signed-off-by: Martin George <marting@netapp.com>
23 months agosrc/nvme/tree.c: make __nvme_scan_subsystem() returning bool
Hannes Reinecke [Tue, 8 Aug 2023 11:32:53 +0000 (13:32 +0200)]
src/nvme/tree.c: make __nvme_scan_subsystem() returning bool

__nvme_scan_subsystem() will free the 's' argument when the filter
triggers, so it needs a return value to inform the caller that the
argument has been freed.

Signed-off-by: Hannes Reinecke <hare@suse.de>
23 months agodoc: fix minor mistake in README.md about dependencies
Christophe Vu-Brugier [Sun, 30 Jul 2023 09:46:28 +0000 (11:46 +0200)]
doc: fix minor mistake in README.md about dependencies

OpenSSL is used for TLS over TCP whereas Keyutils is used for
authentication.

Also fix spelling mistake: dependend -> dependent.

Signed-off-by: Christophe Vu-Brugier <cvubrugier@fastmail.fm>
2 years agonvme-tree: avoid warning in 'list-subsys'
Martin George [Wed, 26 Jul 2023 13:31:29 +0000 (19:01 +0530)]
nvme-tree: avoid warning in 'list-subsys'

With the recent change to scan all subsystems, 'nvme list-subsys
/dev/nvmeXnY' now displays an annoying warning for the NQN mismatch
for all other subsystems that don't match during the subsystem
scan. For e.g.

NQN mismatch for subsystem 'nvme-subsys1'
NQN mismatch for subsystem 'nvme-subsys4'
nvme-subsys3 - NQN=nqn.1992-08.com.netapp:sn.48391d66c0a611ecaaa5d039ea165514:subsystem.subsys_CLIENT116_1
               hostnqn=nqn.2014-08.org.nvmexpress:uuid:e6550026-173e-4959-ba74-be367844bd8a
\
 +- nvme3 tcp traddr=192.168.1.116,trsvcid=4420,host_traddr=192.168.1.16,host_iface=eth5 live optimized
 +- nvme7 tcp traddr=192.168.2.116,trsvcid=4420,host_traddr=192.168.2.16 live optimized
 +- nvme8 tcp traddr=192.168.1.116,trsvcid=4420,host_traddr=192.168.2.16 live optimized

Avoid this warning by displaying it only under debug level.

Fixes: fbd45f1 ("tree: Scan all subsystems")
Signed-off-by: Martin George <marting@netapp.com>
2 years agotree: Add getter for subsystem iopolicy
Daniel Wagner [Wed, 26 Jul 2023 13:33:39 +0000 (15:33 +0200)]
tree: Add getter for subsystem iopolicy

Allow to retrieve the iopolicy settings for the subsystem.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
2 years agofabrics: Consider also all hosts settings for context match
Daniel Wagner [Mon, 3 Jul 2023 09:17:48 +0000 (11:17 +0200)]
fabrics: Consider also all hosts settings for context match

It's not enough to iterate over all subsystem of one host. We need to
iterate over all hosts as well to find a match.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
2 years agotree: Scan all subsystems
Daniel Wagner [Mon, 17 Jul 2023 11:54:30 +0000 (13:54 +0200)]
tree: Scan all subsystems

We need to scan all subsystems because a subsystem might show up on
different hosts, e.g 'nvme connect' with different hostnqn and the
target reports the same namespace.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
2 years agodoc: Fixing compile instruction in README
Brando [Tue, 18 Jul 2023 16:57:56 +0000 (09:57 -0700)]
doc: Fixing compile instruction in README

Update the instruction how to build with meson.

2 years agomi: allow non-4-byte-aligned responses
Jeremy Kerr [Mon, 3 Jul 2023 08:14:47 +0000 (16:14 +0800)]
mi: allow non-4-byte-aligned responses

We currently assume that a MI response will be a multiple of four bytes
in length. However, this may not be the case: for example, a Read MI
Data (Controller List) with an even number of controllers, and with an
unpadded response, may only be aligned on a two-byte boundary.

The NVMe-MI spec states, for the MIC field:

    This field is byte aligned.

So, relax the requirement for alignment on the response sizes, and the
expected response size values. We only do this for the mi commands; the
Admin commands still require an aligned value for DLEN.

In doing so, drop the explicit alignment tests, and add a couple that
check that the Controller List example above will work.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
Reported-by: Klaus Jensen <its@irrelevant.dk>
2 years agomi-mctp: use a linear response buffer
Jeremy Kerr [Mon, 3 Jul 2023 08:06:34 +0000 (16:06 +0800)]
mi-mctp: use a linear response buffer

Currently, we're passing a 3-entry iovec to the MCTP resvmsg()
interface:

 - header
 - payload
 - MIC

This is fine if the response comes back eaxctly the size we expect, but
causes complexity if we get a smaller response (for example, as an error
or a More Processing Required response), as we need to extract the MIC
from somewhere in those buffers.

At the moment, since we're enforcing 4-byte alignment, that isn't too
complex - we know the MIC will be entirely in one of the buffers. The
MPR code is a bit awkward, but still manageable.

However: we now want to allow unaligned responses from MI messages,
which is about to make that a lot more complex; in the worst case, the
MIC could be split over all three buffers!

This change uses a fixed linear buffer for the MCTP response instead. We
allocate 4k for this by default, but expand if necessary. We use this as
the sendmsg() buffer, so get a linear message back from the MCTP
endpoint. Once we have verified the format (and extracted the MIC), we
copy this into the actual response header/payload buffers as required.

This makes the response handing code simpler, at the cost of one extra
response buffer per endpoint.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
2 years agomi: implement length and offset alignment checks in admin_xfer()
Jeremy Kerr [Mon, 3 Jul 2023 07:55:04 +0000 (15:55 +0800)]
mi: implement length and offset alignment checks in admin_xfer()

We're about to relax some alignment requirements in the generic
(internal) nvme_mi_submit function. To ensure that the raw admin
interface continues to enfore the required alignment on DOFST and DLEN
fields, implement checks in the Admin command interface.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
2 years agotree: Don't open nvme devices until it's absolutely required
Martin Belanger [Mon, 3 Jul 2023 18:41:14 +0000 (14:41 -0400)]
tree: Don't open nvme devices until it's absolutely required

Don't open nvme devices while scanning the tree. Only open devices
when we actually need to write commands to them.

This patch also provides functions to close fds when a user no
longer needs them to be open.

Signed-off-by: Martin Belanger <martin.belanger@dell.com>
2 years agotree: missing closedir() causes fd leak for "/sys/bus/pci/slots"
Martin Belanger [Wed, 5 Jul 2023 14:59:25 +0000 (10:59 -0400)]
tree: missing closedir() causes fd leak for "/sys/bus/pci/slots"

In nvme_ctrl_lookup_phy_slot(), we are missing a closedir(), which
causes file descriptors to leak. Also, there was a missing free()
when the function returns with ENOMEM.

Signed-off-by: Martin Belanger <martin.belanger@dell.com>
2 years agomi: don't return from mi_mctp_submit with a tag held
Jeremy Kerr [Wed, 24 May 2023 09:29:33 +0000 (17:29 +0800)]
mi: don't return from mi_mctp_submit with a tag held

If the poll() times-out or fails, we'll exit early from
nvme_mi_mctp_submit still holding the tag reservation. When using an i2c
transport, this may mean we hold a lock on the i2c bus with no way to
release.

Instead, always drop the tag on function exit.

Fixes: 6a08780 ("mi-mctp: Add timeout support to MCTP transport")
Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
2 years agodoc: Regenerate all docs for v1.5 v1.5
Daniel Wagner [Fri, 30 Jun 2023 13:17:07 +0000 (15:17 +0200)]
doc: Regenerate all docs for v1.5

Signed-off-by: Daniel Wagner <dwagner@suse.de>
2 years agobuild: Update version to v1.5
Daniel Wagner [Fri, 30 Jun 2023 13:16:30 +0000 (15:16 +0200)]
build: Update version to v1.5

Signed-off-by: Daniel Wagner <dwagner@suse.de>
2 years agobuild: Update cross instruction and drop verbose test flag
Daniel Wagner [Fri, 30 Jun 2023 13:08:52 +0000 (15:08 +0200)]
build: Update cross instruction and drop verbose test flag

Signed-off-by: Daniel Wagner <dwagner@suse.de>
2 years agobuild: Use containers with matrix build
Daniel Wagner [Mon, 26 Jun 2023 11:44:21 +0000 (13:44 +0200)]
build: Use containers with matrix build

Use a matrix build approach and a base container which already contains
all the libraries installed.

2 years agoutil: Provide empty nvme_ipaddrs_eq for static builds
Daniel Wagner [Mon, 26 Jun 2023 11:40:28 +0000 (13:40 +0200)]
util: Provide empty nvme_ipaddrs_eq for static builds

Static builds can't use netdb functions, they are only available when
linking dynamically against glibc.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
2 years agoscripts: Use spaces instead of tabs
Daniel Wagner [Fri, 23 Jun 2023 14:22:50 +0000 (16:22 +0200)]
scripts: Use spaces instead of tabs

The build.sh file contains a mix of tabs and spaces, just use spaces
consistently.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
2 years agobuild: Move CI build steps into a scripts
Daniel Wagner [Fri, 23 Jun 2023 13:29:15 +0000 (15:29 +0200)]
build: Move CI build steps into a scripts

Move the build instruction into a script. This allows to run these steps
also locally.

Also disable the fallback static library build as it is clearly not
working because in the dependencies rely to link against a dynamic
glibc. Instead just add a minimal static build without fallbacks.

While we are at it, also add a debug clang build.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
2 years agoscripts: Sync release script
Daniel Wagner [Fri, 23 Jun 2023 08:55:08 +0000 (10:55 +0200)]
scripts: Sync release script

Sync with the nvme-cli release script.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
2 years agoscripts: Call update doc script from top level dir
Daniel Wagner [Fri, 23 Jun 2023 08:52:44 +0000 (10:52 +0200)]
scripts: Call update doc script from top level dir

Make sure that the script runs from the lop level dir.

While at it also properly quote variables to make shellcheck happy.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
2 years agoscripts: Move helper scripts to a central place
Daniel Wagner [Fri, 23 Jun 2023 08:02:02 +0000 (10:02 +0200)]
scripts: Move helper scripts to a central place

The helper scripts for maintaining are distributed over several
directories. Let's move them to the scripts directory.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
2 years agofabrics: Relax match on well known disc ctrl lookup
Daniel Wagner [Thu, 22 Jun 2023 12:13:13 +0000 (14:13 +0200)]
fabrics: Relax match on well known disc ctrl lookup

In case nvmf_add_ctrl() is called to add a well known discovery
controller we also need to verify if we should ignore it (see --context
command line argument of nvme-cli). Though we have to be careful not to
overmatch on the lookup.

That means the host_traddr and host_iface might be different for the
discovery controller than the normal controllers. For example this can
happen when the discovery controller is reached via different interface
than the data controllers.

Thus only consider the transport type, target address and trsvcid only
when looking up well known discovery controllers.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
2 years agotree: Ignore NULL address pointer for phy slot lookup
Daniel Wagner [Thu, 22 Jun 2023 12:09:50 +0000 (14:09 +0200)]
tree: Ignore NULL address pointer for phy slot lookup

The PCI physical slot lookup works obviously only for physical cards.
Thus do not try to dereference the address pointer if it is a NULL
pointer.

Fixes: 42ac45359635 ("tree: Add PCI physical slot number for controller")
Signed-off-by: Daniel Wagner <dwagner@suse.de>
2 years agofabrics: Filter discovery ctrls out during application context check
Daniel Wagner [Wed, 14 Jun 2023 12:19:10 +0000 (14:19 +0200)]
fabrics: Filter discovery ctrls out during application context check

We also need to filter out the well known discovery controllers when
using the execution context filtering. Obviously, we can't use the
subsystem name, thus match on the host and target address instead.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
2 years agoutil: Add ignored error code
Daniel Wagner [Wed, 14 Jun 2023 12:17:41 +0000 (14:17 +0200)]
util: Add ignored error code

When libnvme ignores a connection attempt via the 'application' context
tracking return an unique error code to allow proper filtering on the
caller side.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
2 years agojson: Use memory block allocated by realloc() instead printbuf
Tokunori Ikegami [Sat, 17 Jun 2023 15:06:26 +0000 (00:06 +0900)]
json: Use memory block allocated by realloc() instead printbuf

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
2 years agoutil: Use HAVE_NETDB instead of HAVE_LIBNSS
Tokunori Ikegami [Thu, 15 Jun 2023 15:16:50 +0000 (00:16 +0900)]
util: Use HAVE_NETDB instead of HAVE_LIBNSS

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
2 years agotree: Add PCI physical slot number for controller
Umer Saleem [Mon, 12 Jun 2023 14:45:49 +0000 (19:45 +0500)]
tree: Add PCI physical slot number for controller

This commit introduces a physical slot field for controller, that
contains the PCI physcial slot number for controller device.

In case, there are multiple NVME drives present on the platform,
it's hard to identify which NVME drive is present in which slot.
The slot number is usually helpful in determining the location.
It is cross reference-able from lspci, but it would be nice to
have a direct option.

Signed-off-by: Umer Saleem <usaleem@ixsystems.com>
2 years agotree: Use nvme_ipaddrs_eq() to compare IP addresses
Martin Belanger [Mon, 12 Jun 2023 14:40:42 +0000 (10:40 -0400)]
tree: Use nvme_ipaddrs_eq() to compare IP addresses

Signed-off-by: Martin Belanger <martin.belanger@dell.com>
2 years agofabrics: Add EADDRNOTAVAIL error mapping
Tokunori Ikegami [Tue, 13 Jun 2023 15:13:14 +0000 (00:13 +0900)]
fabrics: Add EADDRNOTAVAIL error mapping

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
2 years agofabrics: filter out subsystems with non-matching application string
Hannes Reinecke [Thu, 20 Apr 2023 10:38:10 +0000 (12:38 +0200)]
fabrics: filter out subsystems with non-matching application string

If the nvme root has an application string set any subsystem lookup
should ignore subsystems which either have no application string set
or which have a non-matching application string.

Signed-off-by: Hannes Reinecke <hare@suse.de>
2 years agolibnvme: add 'application' setting to nvme_root
Hannes Reinecke [Thu, 20 Apr 2023 10:10:17 +0000 (12:10 +0200)]
libnvme: add 'application' setting to nvme_root

Add an 'application' string to the tree root to indicate which
application manages this configuration.

Signed-off-by: Hannes Reinecke <hare@suse.de>
2 years agolibnvme: add 'application' setting to the subsystem
Hannes Reinecke [Thu, 20 Apr 2023 10:10:17 +0000 (12:10 +0200)]
libnvme: add 'application' setting to the subsystem

Add an 'application' string to the subsystem to indicate which
application should manage this particular subsystem.

Signed-off-by: Hannes Reinecke <hare@suse.de>
2 years agotest: Add more code coverage for nvme_ipaddrs_eq()
Martin Belanger [Fri, 2 Jun 2023 12:55:24 +0000 (08:55 -0400)]
test: Add more code coverage for nvme_ipaddrs_eq()

Signed-off-by: Martin Belanger <martin.belanger@dell.com>
2 years agoutil: rename ipaddrs_eq() to nvme_ipaddrs_eq() and make public.
Martin Belanger [Fri, 2 Jun 2023 12:35:51 +0000 (08:35 -0400)]
util: rename ipaddrs_eq() to nvme_ipaddrs_eq() and make public.

Signed-off-by: Martin Belanger <martin.belanger@dell.com>
2 years agoutil: Add ipaddrs_eq() to check whether two IP addresses are equal
Martin Belanger [Fri, 19 May 2023 17:40:45 +0000 (13:40 -0400)]
util: Add ipaddrs_eq() to check whether two IP addresses are equal

Signed-off-by: Martin Belanger <martin.belanger@dell.com>
2 years agoexamples: Fix wrong indentation in discover-loop.py
Benjamin Drung [Tue, 23 May 2023 10:30:16 +0000 (12:30 +0200)]
examples: Fix wrong indentation in discover-loop.py

Running `examples/discover-loop.py` fails:

```
  File "examples/discover-loop.py", line 59
    c.disconnect()
    ^
IndentationError: expected an indented block after 'try' statement on line 58
```

Signed-off-by: Benjamin Drung <benjamin.drung@canonical.com>