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.
Jeremy Kerr [Thu, 26 Jan 2023 02:28:49 +0000 (10:28 +0800)]
test: mi: Provide a full request buffer for invalid admin req tests
We're issuing an admin command with up to four bytes of data in the
request. Although these will all fail due to invalid args, we still want
to provide enough data to simulate the full request.
Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
Jeremy Kerr [Thu, 26 Jan 2023 02:24:54 +0000 (10:24 +0800)]
test: mi: Explicitly zero args for test API invocations
We have a few places where we're passing an uninitialised pointer
argument to the libnvme API in the MI tests. Add an explicit zero init
for these.
Fixes: https://github.com/linux-nvme/libnvme/issues/563 Reported-by: Daniel Wagner <dwagner@suse.de> Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
Daniel Wagner [Tue, 24 Jan 2023 10:50:01 +0000 (11:50 +0100)]
fabrics: Always sanitize discovery log entries
Do not just sanitize the traddr and trsvcid when unsing the auto
discovery/connect path, instead also do it for all users of
nvmf_get_discovery_log{_args}() per default.
Daniel Wagner [Fri, 20 Jan 2023 09:39:19 +0000 (10:39 +0100)]
gitignore: Ignore clang build artifacts
When using language server support from clang, the .cache directory is
added. Also for getting lsp working properly the compile_commands.json
file has to present (which is just a link to Meson generared json file).
Daniel Wagner [Mon, 16 Jan 2023 13:54:34 +0000 (14:54 +0100)]
build: Set projects default to debug and prefix /usr/local
Do not install to /usr per default and accidently overwrite the
distributions version of the package. And also debugging symbols per
default to make development setup as we don't install it anyway to /usr
anyway.
Hao Jiang [Tue, 10 Jan 2023 19:04:41 +0000 (11:04 -0800)]
mi: add timeout functions to .map
Need to export nvme_mi_ep_set_timeout and nvme_mi_ep_get_timeout. These
two functions were defined but left over in .map file.
Signed-off-by: Hao Jiang <jianghao@google.com>
[dwagner: moved the function to the LIBNVME_MI_1_3 section] Signed-off-by: Daniel Wagner <dwagner@suse.de>
Klaus Jensen [Thu, 15 Sep 2022 20:54:37 +0000 (22:54 +0200)]
types: add fdp data structures and helpers
Add required data structures and helper functions for TP4146 ("Flexible
Data Placement").
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
[dwagner: - drop packed attribute
- reorder struct args members
- move new functions to next version linker section] Signed-off-by: Daniel Wagner <dwagner@suse.de>
Jinliang Wang [Thu, 1 Dec 2022 07:25:05 +0000 (23:25 -0800)]
mi: use lpo and numd to chunk big get log page command
1) Change log page offset inside `__nvme_mi_admin_get_log`
We use LPO and NUMD to chunk get log page request whose length
is greater than 4KB. This method works better for some of current
devices.
2) Update `test_admin_get_log_split_cb`.
Signed-off-by: Jinliang Wang <jinliangw@google.com>
Tomas Bzatek [Wed, 30 Nov 2022 13:51:09 +0000 (14:51 +0100)]
tree: Fix leaking struct nvme_ns.generic_name
==306445== 96 bytes in 16 blocks are definitely lost in loss record 3,171 of 3,553
==306445== at 0x484386F: malloc (vg_replace_malloc.c:393)
==306445== by 0x4FA2F6D: strdup (strdup.c:42)
==306445== by 0x7B9C477: nvme_ns_set_generic_name (tree.c:1802)
==306445== by 0x7B9C51B: nvme_ns_open (tree.c:1820)
==306445== by 0x7B9C606: __nvme_scan_namespace (tree.c:1853)
==306445== by 0x7B9CA0C: nvme_subsystem_scan_namespace (tree.c:1931)
==306445== by 0x7B98C81: nvme_subsystem_scan_namespaces (tree.c:496)
==306445== by 0x7B991BC: nvme_scan_subsystem (tree.c:597)
==306445== by 0x7B97DA1: nvme_scan_topology (tree.c:118)
==306445== by 0x7B97FA9: nvme_scan (tree.c:177)
Valgrind complaining about accessing uninitialized memory:
==159962== Conditional jump or move depends on uninitialised value(s)
==159962== at 0x484BCF6: rawmemchr (vg_replace_strmem.c:1564)
==159962== by 0x4F52B15: _IO_str_init_static_internal (strops.c:41)
==159962== by 0x4F1DAB1: UnknownInlinedFun (strfile.h:95)
==159962== by 0x4F1DAB1: __isoc99_sscanf (isoc99_sscanf.c:28)
==159962== by 0x7B77C97: uuid_from_dmi_entries (fabrics.c:969)
==159962== by 0x7B84192: UnknownInlinedFun (fabrics.c:1059)
==159962== by 0x7B84192: nvmf_hostnqn_generate (fabrics.c:1070)
rename the `tmp` variable into `xfered_size`.
It is hard to figure out a name which can imply that this variable
is used as both input and output parameter, so I choose `xfered_size`
to emphasize the output functionality.
Signed-off-by: Jinliang Wang <jinliangw@google.com>
Jeremy Kerr [Mon, 21 Nov 2022 08:35:38 +0000 (16:35 +0800)]
MI: switch from libsdbus to libdbus
libsystemd is not generally available as a static library, and we would
like to produce a static nvme-cli. This change switches to libdbus
instead.
This requires slightly more boilerplate code for the dbus
marshalling/unmarshalling as part of the MCTP endpoint scan, but means
we have a simpler upstream lib dependency.
Fixes: https://github.com/linux-nvme/nvme-cli/issues/1734 Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
Martin Belanger [Fri, 18 Nov 2022 15:41:32 +0000 (10:41 -0500)]
fabrics: Fix bad UUID size introduced in recent UUID changes
71c25d1cf741 ("util: Add simple UUID type") introduced a regression in
nvmf_get_tel(). nvmf_get_tel() returns the lenght of the binary
representation. Hence use NVME_UUID_LEN instead.
Signed-off-by: Martin Belanger <martin.belanger@dell.com>
[dwagner: massaged commit message] Signed-off-by: Daniel Wagner <dwagner@suse.de>
Daniel Wagner [Mon, 21 Nov 2022 08:19:57 +0000 (09:19 +0100)]
build: Drop --werror for fallback builds
The fallback builds will build also the OpenSSL library which triggers a
few compiler warnings. As we already build with the project with
--werror in other configuration there is no loss in coverage dropping
it here.
Daniel Wagner [Wed, 16 Nov 2022 13:17:15 +0000 (14:17 +0100)]
build: Allow static linking
To allow static linking, we have to make the libnss dependency
optional. This means the hostname IP resolution feature is not
available in this configuration.
Also the libystemd dependency check doesn't take into account that we
want to link statically. Lukily we just need this for an example.
Currently, the OpenSSL library build will fail in the example
(dependency on libnss) but the library is available to link.
nick black [Sun, 13 Nov 2022 21:27:28 +0000 (16:27 -0500)]
build: require meson 0.50.0+
The Meson buildspec uses features ('plain strings for
include_directories') introduced in Meson 0.50.0, but only specifies
0.48.0. Eliminates a Meson warning.
Signed-off-by: nick black <dankamongmen@gmail.com>
Jeremy Kerr [Thu, 10 Nov 2022 04:20:37 +0000 (12:20 +0800)]
mi: endian fixes
We have a couple of endian issues in the mi code: one where we're not
converting cdw0 for MI commands, and one where we're using the wrong
byte length for an existing conversion. There is also an error in the
test suite, where we should be converting the nsze field of a
nvme_id_ns.
This change fixes those, so that the test suite passes on a BE platform
(ppc64 in my case).
Fixes: https://github.com/linux-nvme/libnvme/issues/524 Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
Jinliang Wang [Fri, 28 Oct 2022 15:42:10 +0000 (08:42 -0700)]
mi: add nvme_mi_admin_admin_passthru
Similar to nvme_admin_passthru, send a customized NVMe Admin command
request message and get the corresponding response message.
Currently, it only supports data xfer size <= 4096.
Signed-off-by: Jinliang Wang <jinliangw@google.com>
[dwagner: refactored has_*_data checks] Signed-off-by: Daniel Wagner <dwagner@suse.de>