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>
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;
| ^~~
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.
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.
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>
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.
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
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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>
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.
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>
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;
| ^~~~~~~~
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.
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.
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.
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.
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.