util: consolidate call paths to argconfig_parse_type()
argconfig_parse_val() already falls back on argconfig_parse_type()
if no option values match.
So always call argconfig_parse_val() from argconfig_parse()
instead of checking whether any option values are defined.
Assuming constant-length value strings, argconfig_parse_val()'s runtime
is currently quadratic in the number of option values.
For each option value, it computes a minimum prefix length
that distinguishes that option from all others.
It then checks whether the input matches up to that prefix length.
Instead, compare the input directly against each option value.
If exactly one matches, select that option value.
Otherwise, fallback on the default value parser.
util: remove empty default case in argconfig functions
Both argconfig_parse_type() and argconfig_set_opt_val()
switch on the argument value type and have an empty default case.
This is unnecessary and masks errors from unhandled enum values.
So drop the default cases.
util: use cleanup to avoid goto in argconfig_parse()
Use _cleanup_free_ in place of explicit calls to free()
in argconfig_parse(). This simplifies the code
and allows using an early return in place of a goto.
test: add test cases for argconfig comma-separated array parsing
There are no unit tests currently covering
argconfig's comma-separated integer array parsing.
Add test cases to test-argconfig-parse.c
that use argconfig_parse_comma_sep_array_u32(),
verifying its functionality and edge cases.
Daniel Wagner [Fri, 12 Jul 2024 12:51:14 +0000 (14:51 +0200)]
build: fetch complete git history
In order to build a image with which contains the correct git version
SHA we need to fetch the complete git tree. Otherwise 'git describe'
fails and we use the project version string as fallback.
Daniel Wagner [Thu, 11 Jul 2024 08:49:23 +0000 (10:49 +0200)]
fabrics: first read config before topology scanning
The topology scanning will create nodes in the internal libnvme tree. As
we rely on the order of the nodes in the tree, we need to read the
config before we scan. This makes sure the first node is the one we have
defined in the config.json. This is important because the first node
provides default hosnqn configuration in absents of /etc/nvme/hostnqn.
Daniel Wagner [Thu, 11 Jul 2024 11:40:42 +0000 (13:40 +0200)]
fabrics: extend already connected message
The 'already connected' message only contains the traddr as info. Add
the missing information so that it's possible to figure out what
combination is already in use.
Francis Pravin [Fri, 12 Jul 2024 06:18:51 +0000 (11:48 +0530)]
nvme: check MD size with PI size when PRACT set to 1
As per NVM Command Set Specification, Rev 1.0d, Sec-5.2.2 PRACT Bit:
"If PRACT bit is set to 1 and Metadata size equals to the Protection
Information size, the protection information is stripped or inserted
by the controller."
Currently NVMe supports 8 and 16 byte size of Protection Information.
So, use pi_size instead of 8 byte.
Signed-off-by: Francis Pravin <francis.p@samsung.com> Reviewed-by: Steven Seungcheol Lee <sc108.lee@samsung.com>
Nitin Sao [Wed, 26 Jun 2024 03:17:42 +0000 (08:47 +0530)]
nvme-print: add new field added in TP4090
As per TP4090, a new field support is added as NPDGL (Namespace
Preferred Deallocate Granularity Large) and so the bit-field of
NSFEAT, OPTPERF get extended by 1 bit.
Signed-off-by: Nitin Sao <nitin.sao@samsung.com> Reviewed-by: Steven Seungcheol Lee <sc108.lee@samsung.com> Reviewed-by: Mohit Kapoor <mohit.kap@samsung.com>
Martin George [Mon, 8 Jul 2024 16:03:58 +0000 (21:33 +0530)]
nvme: fix verbose logging
The -v verbose option for certain nvme commands like id-ctrl,
id-ns, smart-log, sanitize-log, etc. is practically a no-op since
it only prints latency info in addition to the regular output.
But at the same time, these commands already implement a -H human
readable option which prints additional useful info. So fix the
-v option to make it synonymous with the -H option here. And while
we are at it, move the latency info from current INFO level (i.e.
-v logging) to DEBUG level (i.e. -vv logging) since it is better
suited there.
Daniel Wagner [Mon, 1 Jul 2024 12:46:04 +0000 (14:46 +0200)]
nvme: strip newline when parsing TLS key files
When exporting a TLS keys from the kernel keyring a line might have a
newline. Strip the newline away as the nvme_import_tls_key is not
expecting it and thus fails to load an exported keyfile.
Oliver Upton [Thu, 4 Jul 2024 09:09:40 +0000 (09:09 +0000)]
common.h: Avoid using unsupported load/store instructions in arm64 VMs
Using nvme show-regs within a VM on arm64 can sometimes lead to VM
termination.
To answer why this happens: one of the deficiencies of the Arm
architecture is that there exists a range of load/store instructions
that have insufficient decode information for traps taken to the
hypervisor. KVM, for example, may raise an external abort or outright
terminate the VM depending on the configuration.
This is a known problem on the kernel side, and is fixed by using
assembly MMIO accessors w/ 'safe' load/store instructions. So do
exactly that, providing arm64-specific accessors and falling back to
plain old volatile pointer accesses for other architectures.
Reported-by: William Butler <wab@google.com> Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
This commit will provide the first phase of changes
needed for parsing of OCP 2.5 Telemetry Data Areas
1 and 2. It will decode the prefined classes,
statistics, and events.
Martin George [Sun, 30 Jun 2024 07:39:07 +0000 (13:09 +0530)]
nvme: update parse_args() return value handling
Treat non-zero return values from parse_args() as errors, and not
just negative return values. Also makes this consistent with other
functions in nvme.c where parse_args() is invoked.
Francis Pravin [Wed, 26 Jun 2024 06:35:39 +0000 (12:05 +0530)]
nvme: choose PIF from QPIF if QPIFS supports and PIF is QTYPE
As per TP4141a:
"If the Qualified Protection Information Format Support(QPIFS) bit is
set to 1 and the Protection Information Format(PIF) field is set to 11b
(i.e., Qualified Type), then the pif is as defined in the Qualified
Protection Information Format (QPIF) field."
So, choose PIF from QPIF if QPIFS supports and PIF is QTYPE.
Signed-off-by: Francis Pravin <francis.p@samsung.com> Reviewed-by: Steven Seungcheol Lee <sc108.lee@samsung.com>
nvme ana-log currently uses libnvme's nvme{,_mi_admin}_get_log_ana()
function to fetch the ANA log page.
As described in the commit adding nvme_get_ana_log_atomic() to libnvme,
this has the potential to overread the ANA log page
and may result in a torn result if the log page changes concurrently.
Use nvme{,_mi_admin}_get_ana_log_atomic() to only fetch up to the end
of the ANA log page and protect against concurrent log page changes.
nvme ana-log only includes space for MNAN namespace IDs
in the allocated ANA log page buffer if bit 6 of ANACAP
in the Identify Controller structure isn't set.
But the specification says:
Bit 6 if set to '1', then the ANAGRPID field in the Identify Namespace
data structure (refer to the NVM Command Set Specification)
does not change while the namespace is attached to any controller
There is no suggestion that NSIDs won't be returned in the ANA log page.
However, we can exclude space for NSIDs from the allocated buffer
if the Get Log Page command is going to be sent with the RGO bit set,
i.e. the --groups argument is passed.
Therefore, use the libnvme helper nvme_get_ana_log_len_from_id_ctrl()
to calculate the maximum ANA log page length.
It ignores ANACAP and takes the RGO setting into account.