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.
Caleb Sander [Fri, 12 May 2023 15:43:22 +0000 (09:43 -0600)]
ioctl: fix RAE bit on last Get Log Page command
If nvme_get_log_page() requires multiple Get Log Page commands
because the total log length exceeds the transfer length,
args->rae is overwritten, causing the RAE bit to be set in all commands.
Retrieve the value of args->rae before overwriting it
so the RAE bit is set as requested in the last command.
Fixes: c23dbd4 ("linux: Change nvme_get_log_page to use nvme_get_log_args parm") Signed-off-by: Caleb Sander <csander@purestorage.com>
Caleb Sander [Fri, 12 May 2023 16:49:46 +0000 (10:49 -0600)]
fabrics: check genctr after getting discovery entries
From the NVMe base spec (version 2.0c, section 5.16.1.23):
If the host reads the Discovery Log Page using multiple Get Log Page
commands the host should ensure that there has not been a change in the
contents of the data. The host should read the Discovery Log Page
contents in order (i.e., with increasing Log Page Offset values) and
then re-read the Generation Counter after the entire log page is
transferred. If the Generation Counter does not match the original value
read, the host should discard the log page read as the entries may be
inconsistent.
nvme_get_log_page() will issue multiple Get Log Page commands
to fetch the discovery log page if it exceeds 4 KB.
Since GENCTR is at the start of the log page, this ordering is possible:
- GENCTR is read by a Get Log Page command for the first 4 KB
- The log page is modified, changing GENCTR
- Other Get Log Page commands read the remainder of the log page
So the check that GENCTR hasn't changed will incorrectly pass,
despite the log page having been modified.
This can lead to inconsistent, missing, or duplicate log page entries.
Ensure a GENCTR update is not missed
by fetching log page header again after all entries.
Also use NVME_LOG_PAGE_PDU_SIZE to match other nvme_get_log_page() calls
instead of hard-coding the 4 KB max transfer length.
And ensure LPO is correctly reset if the log page is read again.
Caleb Sander [Fri, 12 May 2023 00:40:26 +0000 (18:40 -0600)]
fabrics: handle /dev/nvme-fabrics read failure
The ability to read from /dev/nvme-fabrics to find supported options
is a newer Linux kernel feature added in f18ee3d988157 (5.17-rc1).
On earlier kernels, this read returns EINVAL,
preventing the controller from being added:
$ nvme discover --transport tcp --traddr 192.168.1.62
Failed to read from /dev/nvme-fabrics: Invalid argument
failed to add controller, error Invalid argument
So don't treat EINVAL as a fatal error, and instead fall back
to a default set of supported options.
With this change, controllers can be created successfully:
$ nvme discover --transport tcp --traddr 192.168.1.62
Discovery Log Number of Records 4, Generation counter 125
...
Fixes: d123131f2e ("fabrics: Do not pass unsupported options to kernel") Signed-off-by: Caleb Sander <csander@purestorage.com>
Maurizio Lombardi [Mon, 8 May 2023 15:47:00 +0000 (17:47 +0200)]
fabrics: fix potential invalid memory access in __nvmf_supported_option()
In __nvmf_supported_option(), len is declared as size_t (unsigned)
"len = read()" may return a negative number;
the check "if (len < 0)" will always be false and therefore
"buf[len]" will dereference an invalid memory address.
len should be declared as a signed size_t (ssize_t)
Prevent Garbage Collector (GC) from deleting host and root objects
before all controller objects under that root/host have been GCed.
This time, it's the init() method that needed the fix. Previously
we had only fixed the connect() method.
Signed-off-by: Martin Belanger <martin.belanger@dell.com>
To suppress the warnings generated by swig when parsing anonymous
struct/union, we simply wrap the offending struct/union in a
"#ifndef SWIG" statement. This is an acceptable workaround because
we don't need to generate Python bindings for these structs. In
fact, we specifically tell swig to not generate wrappers for all
structs in types.h. Although swig does not generate wrappers for
those structs, it still warns when a struct doesn't have a name
and therefore we need to use this workaround.
Signed-off-by: Martin Belanger <martin.belanger@dell.com>
examples: fix incorrect controller status in MI info output
In the mi-mctp example, we're incorrectly reporting the percent drive
life used as the controller status. Fix the controller status output
to use the correct (ccs) field.
Signed-off-by: Lior Weintraub <liorw@pliops.com> Reviewed-by: Jeremy Kerr <jk@codeconstruct.com.au>
Martin Belanger [Tue, 18 Apr 2023 13:19:32 +0000 (09:19 -0400)]
Python: make NBFT data more pythonic
I made the nfollowing changes so that the data is more Pythonic.
1) For boolean values, set them to True/False instead of 1/0.
2) NBFT data contains ordered lists. In the raw NBFT data the
position of each element in the list is indicated by a 1-based
index. When converting to Python lists, make sure that each
element is inserted in the list at the right position. This is
done by converting the 1-based index to a 0-based index.
3) For objects that contain index variables that refer to items in
a list, make sure to convert the 1-based index to 0-based so that
it can be used directly to access the python lists (e.g. list[index]).
4) Since Python lists are ordered (per 2 above), there is no
need to keep an explicit 1-based index in each of the list items.
Therefore those 1-based indexes were removed.
5) No need to keep explicit variables representing the length of
a list. In Python one need only use len(list) to get the length.
Signed-off-by: Martin Belanger <martin.belanger@dell.com>
Daniel Wagner [Mon, 17 Apr 2023 08:25:55 +0000 (10:25 +0200)]
python: Update test data
Since commit 1617d1a3f42a ("nbft: Parse the {HOSTID,HOSTNQN}_CONFIGURED
flags") host_id_configured and host_nqn_configured are parsed. Thus we
need to update the test case accordingly.
Tomas Bzatek [Tue, 11 Apr 2023 16:04:55 +0000 (18:04 +0200)]
nbft: Add a simple unit test
A simple table dump utility, a set of real ACPI NBFT table files
and corresponding set of reference dumps, compared against each
other as part of the meson test run.
Daniel Wagner [Thu, 13 Apr 2023 10:41:31 +0000 (12:41 +0200)]
build: Disable fallback on default
meson's default setting for wrap mode is to attempt to download missing
dependencies. Disable this feature as the community is unhappy with
this default behavior.
Daniel Wagner [Wed, 12 Apr 2023 13:43:18 +0000 (15:43 +0200)]
tree: Fix offset argument check in nvme_bytes_to_lba
Also offset modulo blocksize needs to be 0. Commit 01c6055e5602 ("tree:
Fix argument check in nvme_bytes_to_lba") missed to update this, thus do
it now.
Stuart Hayes [Thu, 31 Mar 2022 18:47:11 +0000 (13:47 -0500)]
nbft: add NBFT v1.0 table support
Added support for parsing and printing the contents
of the NBFT table (per NVMe-oF boot specification v1.0).
Signed-off-by: Stuart Hayes <stuart_hayes@dell.com> Signed-off-by: Martin Belanger <martin.belanger@dell.com> Signed-off-by: Martin Wilck <mwilck@suse.com> Signed-off-by: Tomas Bzatek <tbzatek@redhat.com> Signed-off-by: John Meneghini <jmeneghi@redhat.com>
Daniel Wagner [Wed, 5 Apr 2023 06:37:38 +0000 (08:37 +0200)]
tree: Fix argument check in nvme_bytes_to_lba
nvme_bytes_to_lba() argument checker is ensuring that all passed in
values are valid. That means we have at least one block to write, the
offset is aligned to a block starting address and the number of blocks
is a multiple of the block size
Hannes Reinecke [Tue, 28 Mar 2023 10:28:21 +0000 (12:28 +0200)]
Print out correct TREQ strings for discovery
The TREQ field in the discover log page is actually a bit field,
so we need to update the string mapping to print out all possible
combinations correctly.
Minwoo Im [Wed, 22 Mar 2023 22:59:03 +0000 (07:59 +0900)]
tree: fix generic device open failure
If scan_namespace is called with a generic device (e.g., /dev/ng0n1)
given, it fails to scan a namespace based on the generic device because
there's no entry point in /sys/block/ for the generic device.
This patch provides two helpers to change the given generic device name
to a block device name based on the instances:
ng0n1 -> nvme0n1
This patch fixes command failure:
root@vm:~/work/nvme-cli.git# nvme show-regs /dev/ng0n1
Unable to find ng0n1
get-property: Invalid argument
Signed-off-by: Minwoo Im <minwoo.im@samsung.com>
[dwagner: also catch blkdev allocation failures] Signed-off-by: Daniel Wagner <dwagner@suse.de>
Hannes Reinecke [Thu, 23 Mar 2023 09:44:02 +0000 (10:44 +0100)]
fabrics: add configuration option 'tls_key'
Add a fabrics configuration option to specify the TLS PSK for a
connection. The PSK is referenced by its serial number, but stored
with its description in the JSON configuration file.
Hannes Reinecke [Thu, 23 Mar 2023 09:14:03 +0000 (10:14 +0100)]
fabrics: add configuration option 'keyring'
Add a fabrics configuation option 'keyring' to set the keyring
for storing and looking up keys.
As the keyring serial number is ephemeral we cannot store it
in the JSON configuration file, so store the keyring description
instead.
Hannes Reinecke [Thu, 23 Mar 2023 13:46:13 +0000 (14:46 +0100)]
linux: add key helper functions
Add helper functions for key handling.
Signed-off-by: Hannes Reinecke <hare@suse.de>
[dwagner:
- set errno on failure and updated documentation accordingly
- fix return check of nvme_lookup_key in nvme_insert_tls_key] Signed-off-by: Daniel Wagner <dwagner@suse.de>
Hannes Reinecke [Thu, 23 Mar 2023 13:18:44 +0000 (14:18 +0100)]
linux: add nvme_lookup_keyring()
Add a function to lookup a keyring by its description.
Signed-off-by: Hannes Reinecke <hare@suse.de>
[dwagner:
- pass in command line option to dependency requirement argument
- drop log message, find_key_by_type_and_desc sets errno] Signed-off-by: Daniel Wagner <dwagner@suse.de>
Daniel Wagner [Fri, 24 Mar 2023 15:50:48 +0000 (16:50 +0100)]
build: Update OpenSSL wrap
Update to OpenSSL 3.0.7.
When the fallback was using v1 we never went into the v3 testing. With
updating to v3 we are going to figure out if we have LibreSSL spin of
the API. But cc.has_header_symbol() and cc.has_header() only work on
external library and not on fallbacks.
Thus if we use the fallback (internal) we just know it is API version 3
and don't do any crazy testing.
Martin Belanger [Fri, 17 Mar 2023 15:56:26 +0000 (11:56 -0400)]
python: Add setter property for controller DHCHAP Key
Similar to the way we allow setting/getting the Host DHCHAP key,
we need to allow setting/getting the Controller DHCHAP Key.
There was already a "getter" property, but the "setter" property
was missing.
Signed-off-by: Martin Belanger <martin.belanger@dell.com>
Martin Belanger [Fri, 17 Mar 2023 12:12:07 +0000 (08:12 -0400)]
python: Remove redundant host.set_key() method
I just found out that the DHCHAP Key can be set as a property
(e.g. host.dhchap_key = "THE-KEY"). So, we can remove the set_key()
method that was added a few days ago.
Signed-off-by: Martin Belanger <martin.belanger@dell.com>
Steven Seungcheol Lee [Mon, 6 Mar 2023 06:37:10 +0000 (15:37 +0900)]
doc: fix kernel-doc-check warning
src/nvme/api-types.h:815: warning: Function parameter or member 'mos' not described in 'nvme_io_mgmt_recv_args'
src/nvme/api-types.h:815: warning: Function parameter or member 'mo' not described in 'nvme_io_mgmt_recv_args'
src/nvme/api-types.h:837: warning: Function parameter or member 'mos' not described in 'nvme_io_mgmt_send_args'
src/nvme/api-types.h:837: warning: Function parameter or member 'mo' not described in 'nvme_io_mgmt_send_args'
Signed-off-by: Steven Seungcheol Lee <sc108.lee@samsung.com>
Martin Belanger [Wed, 1 Mar 2023 19:21:03 +0000 (14:21 -0500)]
python, meson: Assert that deps are present for -Dpython=true
The -Dpython option takes 3 values: auto, true, or false. For
"auto", the Python bindings will be built if all the dependencies
are met and will be skipped in not. For "true", the Python bindings
MUST be built and therefore missing dependencies need to be treated
as an error. For "false", the Python bindings won't be built whether
the dependencies are met or not.
Currently, with -Dpython=true, if a dependency required to build the
Python bindings is missing, meson silently skips it (i.e. it behaves
like "-Dpython=auto").
Signed-off-by: Martin Belanger <martin.belanger@dell.com>
Martin Belanger [Tue, 28 Feb 2023 18:56:36 +0000 (13:56 -0500)]
python: Reformat SWIG input file
The SWIG file contains a lot of C code that was not following the
standard formatting (e.g. indent with tabs). I ran a code
beautifier to bring this code in compliance and make it easier to
read.
P.S. I verified that the code generated has not changed and tested
that eveyrhing still works as usual.
Signed-off-by: Martin Belanger <martin.belanger@dell.com>
Martin Belanger [Mon, 27 Feb 2023 18:37:20 +0000 (13:37 -0500)]
python: Fix segmentation fault during garbage collection
With SWIG we create proxy classes to wrap the C structures (struct).
These classes are used to create Python objects matching the C
structures such as:
`nvme.root` is used to wrap `struct nvme_root`
`nvme.host` is used to wrap `struct nvme_host`
`nvme.ctrl` is used to wrap `struct nvme_ctrl`
etc...
One thing that SWIG cannot do is figure out the dependencies
between the different objects. For example, it cannot tell that
when deleting a host object that all the subsystems, controllers,
namespaces under that host need to be deleted as well. That's an
implicit property of the libnvme driver and users need to know to
stop using objects after their parent has been deleted.
Unfotunately, with Python the Gargage Collector (GC) decides which
objects to delete and it can delete obects in any order it sees fit.
This can result in objects being deleted in the wrong order. For
example, the GC may delete a host object (`nvme_free_host`) before
deleting any of the controller objects under that host. And when the
GC finally deletes a controller by calling `nvme_free_ctrl()`, the
memory for that controller has already been freed and a segmentation
fault will result.
To enforce that objects get deleted in the right order, we need to
set dependencies between objects at the Python level. This can be
achived by having children objects maintain a reference to their
parents. This way a parent cannot be deleted before all its children
have been deleted.
Signed-off-by: Martin Belanger <martin.belanger@dell.com>
Daniel Wagner [Wed, 15 Feb 2023 11:18:07 +0000 (12:18 +0100)]
mi: Add nvme_mi_admin_get_log_page
The non MI API has an nvme_get_log_page() function which accepts the
transfer length. In order to be able to use the nvme_get_log_page()
function ins nvme-cli, the MI API needs to provide the same API so that
the transport abstraction wrappers work.
Daniel Wagner [Wed, 15 Feb 2023 11:16:03 +0000 (12:16 +0100)]
ioctl: Set file descriptor in nvme_get_log_page()
We explicitly ask for a file descriptor in the API so use it. The caller
might not have set it in args.
For example, in nvme-cli when the libnvme wrappers are used to hide the
transport details from the nvme-cli core, the macros only pass the file
descriptor via the function arguments but don't set it in the arg
structs.
Keith Busch [Thu, 9 Feb 2023 18:47:19 +0000 (10:47 -0800)]
fix endians
All the nvme defined payloads are in little endian. All the known users
are alrady using the appropriate le*_to_cpu() accessors, so just fix the
type annotations.
Cc: Klaus Jensen <its@irrelevant.dk> Signed-off-by: Keith Busch <kbusch@kernel.org>
Daniel Wagner [Fri, 10 Feb 2023 13:56:20 +0000 (14:56 +0100)]
build: Set defaults for libdbus to disabled
People are unhappy with the defaults of libdbus being auto. It pulls in
the extra dependency for little gain. So let's set it to disabled which
is for most developers the right choice anyway.
Daniel Wagner [Mon, 6 Feb 2023 13:48:43 +0000 (14:48 +0100)]
build: Use prefixdir directly on sysconfdir
The sysconfdir is an explicit path '/etc' and the muon implementation of
join_paths is dropping the prefixdir, thus we need to string concanate
the syscondfir path instead of using the join_paths function.