]> www.infradead.org Git - users/sagi/libnvme.git/log
users/sagi/libnvme.git
15 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>
15 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>
15 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>
15 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>
15 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>
16 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>
16 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>
16 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>
16 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>
16 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>
16 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.
16 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>
16 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>
16 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>
16 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>
16 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>
16 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>
16 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>
16 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>
16 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>
16 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>
16 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>
16 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>
16 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>
16 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>
16 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>
16 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>
16 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>
16 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>
16 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>
16 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>
16 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>
16 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>
16 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>
16 months agolinux: add nvme_read_key()
Hannes Reinecke [Wed, 21 Feb 2024 06:32:16 +0000 (07:32 +0100)]
linux: add nvme_read_key()

Add a function to return the payload of a key.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

The changes for PEL rci port identifier type print function.

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

The changes for persistent event log rci print function.

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

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

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

gcc complains about potentially uninitialized variables.

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

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

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

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

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

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

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

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

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

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

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

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

Described by the NVM express base specification revision 2.0c.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

This provides just the basic building blocks.

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

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

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

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

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

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

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

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

This allows to write the output to a file.

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

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

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

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

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

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

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

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

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

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

Update the JSON schema with the keyring and tls_key details.

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

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

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

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

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

Segmentation fault (core dumped)

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

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

meson.build: fixup 'join' syntax

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

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

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

gcc complains about potentially uninitialized variables.

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

gcc complains about potentially uninitialized variables.

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

gcc complains about potentially uninitialized variables.

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

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

E.g.

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

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

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

Signed-off-by: Leonardo da Cunha <leonardo.da.cunha@solidigm.com>
19 months agobuild: fix release python tag match
Daniel Wagner [Wed, 20 Dec 2023 10:04:24 +0000 (11:04 +0100)]
build: fix release python tag match

The version match should also accept patch level strings.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
19 months agodoc: Regenerate all docs for v1.7.1 v1.7.1
Daniel Wagner [Wed, 20 Dec 2023 09:51:58 +0000 (10:51 +0100)]
doc: Regenerate all docs for v1.7.1

Signed-off-by: Daniel Wagner <dwagner@suse.de>
19 months agobuild: Update version to v1.7.1
Daniel Wagner [Wed, 20 Dec 2023 09:51:34 +0000 (10:51 +0100)]
build: Update version to v1.7.1

Signed-off-by: Daniel Wagner <dwagner@suse.de>
19 months agobuild: handle patch level versioning
Daniel Wagner [Wed, 20 Dec 2023 09:48:31 +0000 (10:48 +0100)]
build: handle patch level versioning

Use the patch level identifier from the version string when it is
provided instead blindly extending the version string with '.0'. This
prevents patch level releases.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
19 months agotree: do no free ns on error in nvme_ns_init
Daniel Wagner [Wed, 20 Dec 2023 07:26:16 +0000 (08:26 +0100)]
tree: do no free ns on error in nvme_ns_init

The ns pointer is owned by the caller not by nvme_ns_init, thus we can't
just free it on error.

Fixes: 7959f52960fd ("tree: read all attributes from sysfs when available")
Reported-by: Tomasz Kłoczko <kloczek@fedoraproject.org>
Signed-off-by: Daniel Wagner <dwagner@suse.de>
19 months agobuild: use build container with python support
Daniel Wagner [Tue, 19 Dec 2023 21:19:24 +0000 (22:19 +0100)]
build: use build container with python support

We should also build the Python binding, thus use the Debian container
with all Python dependencies installed.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
19 months agobuild: use single string to name tests
Daniel Wagner [Tue, 19 Dec 2023 21:11:53 +0000 (22:11 +0100)]
build: use single string to name tests

In order to be able to select to run a given test by name, use a single
string which makes it way simpler to execute, e.g.

  meson test -C .build --gdb python-import-libnvme

Signed-off-by: Daniel Wagner <dwagner@suse.de>
19 months agodoc: Regenerate all docs for v1.7 v1.7
Daniel Wagner [Tue, 19 Dec 2023 10:33:19 +0000 (11:33 +0100)]
doc: Regenerate all docs for v1.7

Signed-off-by: Daniel Wagner <dwagner@suse.de>
19 months agobuild: Update version to v1.7
Daniel Wagner [Tue, 19 Dec 2023 10:32:57 +0000 (11:32 +0100)]
build: Update version to v1.7

Signed-off-by: Daniel Wagner <dwagner@suse.de>
19 months agobuild: update json-c and openssl wrap
Daniel Wagner [Tue, 19 Dec 2023 10:12:43 +0000 (11:12 +0100)]
build: update json-c and openssl wrap

Update the two dependency to the latest upstream released one.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
19 months agobuild: construct path to config.h manually
Daniel Wagner [Tue, 19 Dec 2023 09:40:21 +0000 (10:40 +0100)]
build: construct path to config.h manually

meson reports:

  internal/meson.build:25: DEPRECATION: Project uses feature that was
  always broken, and is now deprecated since '1.3.0': str.format: Value
  other than strings, integers, bools, options, dictionaries and lists
  thereof.

Thus just hardcode the config file path by using current_build_dir. Note
this changes the path from a relative one to an absolute one.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
19 months agotree: do not open blk device on default
Daniel Wagner [Thu, 7 Dec 2023 12:52:59 +0000 (13:52 +0100)]
tree: do not open blk device on default

The fd is not needed anymore if the kernel exposes all necessary sysfs
entries to fully scan the nvme subsystem. Thus do not alwyas open the
blk device and do it only when necessary.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
19 months agotree: read all attributes from sysfs when available
Daniel Wagner [Fri, 1 Dec 2023 09:23:29 +0000 (10:23 +0100)]
tree: read all attributes from sysfs when available

The kernel already exposes parts or all attributes we are looking up
with the ns id command. By reading these from the sysfs we can remove
the last command we are issuing during the topology scan.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
19 months agobuild(deps): bump actions/download-artifact from 3 to 4
dependabot[bot] [Mon, 18 Dec 2023 02:32:10 +0000 (02:32 +0000)]
build(deps): bump actions/download-artifact from 3 to 4

Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 3 to 4.
- [Release notes](https://github.com/actions/download-artifact/releases)
- [Commits](https://github.com/actions/download-artifact/compare/v3...v4)

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

Signed-off-by: dependabot[bot] <support@github.com>
19 months agobuild(deps): bump actions/upload-artifact from 3 to 4
dependabot[bot] [Mon, 18 Dec 2023 02:32:06 +0000 (02:32 +0000)]
build(deps): bump actions/upload-artifact from 3 to 4

Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 3 to 4.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v3...v4)

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

Signed-off-by: dependabot[bot] <support@github.com>
19 months agobuild: add codecov configuration
Daniel Wagner [Wed, 13 Dec 2023 08:29:40 +0000 (09:29 +0100)]
build: add codecov configuration

Unfortunatly, the codecov configuration wants to have it's own
configurtion file on top level of the project.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
19 months agobuild: ignore external code for code coverage check
Daniel Wagner [Wed, 13 Dec 2023 08:08:40 +0000 (09:08 +0100)]
build: ignore external code for code coverage check

Signed-off-by: Daniel Wagner <dwagner@suse.de>
19 months agoioctl: set data length when retrieving LBA status
Nate Thornton [Thu, 7 Dec 2023 22:02:16 +0000 (16:02 -0600)]
ioctl: set data length when retrieving LBA status

Current nvme_get_lba_status() function does specify any data_len in the
admin command, resulting in zero data being returned.

This is the least intrusive change as it requires no update to nvme-cli.

Signed-off-by: Nate Thornton <n.thornton@samsung.com>
19 months agobuild: add CFLAGS back when building with muon
Daniel Wagner [Thu, 16 Nov 2023 16:04:56 +0000 (17:04 +0100)]
build: add CFLAGS back when building with muon

Previous commit dropped the CLFAGS from the muon
configuration step. Add it back.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
19 months agotypes: fix regression for vendor-specific field in nvme_id_ns
Chris Patterson [Fri, 1 Dec 2023 06:21:15 +0000 (22:21 -0800)]
types: fix regression for vendor-specific field in nvme_id_ns

Recent versions of nvme-cli have started reading vs from offset
392 instead of 384. Previous PRs coupled the use of nvme_id_ns
for use in namespace management (create_ns).  However, the NVMe
spec has a different structure for namespace management, with
only a subset of the fields allowed/shared and some additional
fields.

To fix this, remove lbstm and restore the proper length for vs
from nvme_id_ns.

I expect that create_ns() should fully switch over to the
nvme_ns_mgmt_host_sw_specified struct which seems aligned with
the spec (though has some newer fields than what is available in
the latest NVMe Command Set Specification Revision 1.0c). This
will have to be addressed separately in nvme-cli.

https://github.com/linux-nvme/libnvme/pull/307
https://github.com/linux-nvme/nvme-cli/pull/1452

Signed-off-by: Chris Patterson <cpatterson@microsoft.com>
19 months agoutil: use cleanup functions
Caleb Sander [Wed, 29 Nov 2023 02:15:34 +0000 (19:15 -0700)]
util: use cleanup functions

Use cleanup attributes from cleanup.h to avoid boilerplate cleanup code.

Signed-off-by: Caleb Sander <csander@purestorage.com>
19 months agolinux: use cleanup functions
Caleb Sander [Wed, 29 Nov 2023 02:13:42 +0000 (19:13 -0700)]
linux: use cleanup functions

Use cleanup attributes from cleanup.h to avoid boilerplate cleanup code.

Signed-off-by: Caleb Sander <csander@purestorage.com>
19 months agojson: use cleanup functions
Caleb Sander [Wed, 29 Nov 2023 01:33:43 +0000 (18:33 -0700)]
json: use cleanup functions

Use cleanup attributes from cleanup.h to avoid boilerplate cleanup code.
Introduce _cleanup_tokener_ to call json_tokener_free() on cleanup.

Signed-off-by: Caleb Sander <csander@purestorage.com>
19 months agofabrics: use cleanup functions
Caleb Sander [Wed, 29 Nov 2023 01:21:29 +0000 (18:21 -0700)]
fabrics: use cleanup functions

Use cleanup attributes from cleanup.h to avoid boilerplate cleanup code.

Signed-off-by: Caleb Sander <csander@purestorage.com>
19 months agotree: use cleanup functions
Caleb Sander [Tue, 28 Nov 2023 21:32:21 +0000 (14:32 -0700)]
tree: use cleanup functions

Use cleanup attributes from cleanup.h to avoid boilerplate cleanup code.
Introduce struct dirents and the corresponding _cleanup_dirents_
to clean up arrays of directory entries.

Signed-off-by: Caleb Sander <csander@purestorage.com>
19 months agocleanup: add cleanup functions
Caleb Sander [Tue, 28 Nov 2023 20:35:01 +0000 (13:35 -0700)]
cleanup: add cleanup functions

Introduce _cleanup_free_ from nvme-cli to call free() on cleanup,
_cleanup_file_ to call fclose(), _cleanup_dir_ to call closedir(),
and _cleanup_fd_ to call close().

_cleanup_free_ generalizes __cleanup__(cleanup_charp),
so remove it along with cleanup.c.

Signed-off-by: Caleb Sander <csander@purestorage.com>