Location 1) is present on all the systems I've tested: SUSE, Red Hat,
Fedora, and Ubuntu. Unfortunately, location 2) does not exist on
Debian-based systems.
Currently, uuid_from_dmi() only reads from location 2), which fails
on Debian.
This patch adds code that reads from location 1) first, and will
only try location 2) if reading from 1) fails.
Signed-off-by: Martin Belanger <martin.belanger@dell.com>
[dwagner: Updated return value from -1 to -ENXIO] Signed-off-by: Daniel Wagner <dwagner@suse.de>
Martin Belanger [Wed, 27 Oct 2021 12:20:10 +0000 (08:20 -0400)]
Add Python tests to meson framework.
Python has this strict directory layout requirement. A Python package is a
directory that must contain a __init__.py file in addition to containing
modules.
To be able to run Python tests and load modules directly from the build
directory, the Python package (libnvme) and module (nvme.py) must be organized
in the build directory the same way they would be in the install directory. And
the PYTHONPATH must be set to point to the build directory. In other words,
like this:
This patch changes the directory layout so that meson will organize the Python
package and module as shown above. The patch also defines Python tests and sets
the PYTHONPATH to allow importing directly from the build directory.
Signed-off-by: Martin Belanger <martin.belanger@dell.com>
Jeremy Kerr [Wed, 20 Oct 2021 03:59:03 +0000 (11:59 +0800)]
types.h: heal -> health
We currently have an abbreviation 'heal' in nvme_mi_ctrl_heal_status;
while the subsystem health status uses the full 'health'. This change
unifies these by using the full term instead of the abbreviation.
Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
Klaus Jensen [Wed, 29 Sep 2021 19:07:41 +0000 (21:07 +0200)]
types: remove endian/mmio helpers
The endian/mmio helpers do not belong in types.h.
Since we are already using ccan and have ccan/endian available, just
include that where needed. The implementation is 100% equivalent, even
with sparse annotations.
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
Klaus Jensen [Wed, 29 Sep 2021 17:44:55 +0000 (19:44 +0200)]
types: move command parameters from ioctl.h
Move spec-defined command parameters out of nvme/ioctl.h and into
nvme/types.h. This allows third-party libraries and applications to use
the type definitions of libnvme without potentially clashing with
various function prototypes that are ioctl specific.
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
Klaus Jensen [Tue, 19 Oct 2021 20:13:53 +0000 (22:13 +0200)]
meson: revert to using the ccan configurator
Something fishy is going on with the -include config.h and #include
"config.h" in the ccan sources. If examples/tests use ccan, they end up
with redefinitions caused by the ccan config defines not being properly set.
Revert to generating a ccan-specific config.h using the configurator (like the
Make-based setup).
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
Klaus Jensen [Tue, 19 Oct 2021 19:34:38 +0000 (21:34 +0200)]
src/Makefile: fix ccan config.h
The ccan/ccan-config.h generated by the ccan configurator is never read
by the ccan sources which expect config.h. Instead, because of -I.. in
src/Makefile, the ccan sources picks up the base config.h (as generated
by configure). All kinds of wrong since config.h should actually have
been config-host.h.
Fix the compiler args to not include the base directory and generate the
ccan config file as ccan/config.h. Rename ./config.h to ./config-host.h.
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
Martin Belanger [Tue, 19 Oct 2021 18:34:03 +0000 (14:34 -0400)]
Make Python Bindings optional
Added a new configuration parameter "python". By default it is set to 'auto',
which means that the Python bindings will be built if all dependencies can be
found on the host. If not, Python bindings won;t be built. The option can
also be set to 'true' or 'false' to force Python bindings to be built or not.
Signed-off-by: Martin Belanger <martin.belanger@dell.com>
Daniel Wagner [Tue, 19 Oct 2021 08:15:32 +0000 (10:15 +0200)]
build: Add fallback dependency for json-c
meson supports embedded library build. This is very handy for system
which ship outdated an really outdated json-c library.
The include path for json.h has to be adapted. The json-c upstream
project is not clear which include prefix should be used ('#include
<json-c/json.h>" vs '#include <json.h>'. In order to support embedded
builds, we need to use the second version of the include. The source
code is added to the build, hence we use the include directory path of
the project layout. And json-c has all include files in the root
directory. This is no problem when using a installed version of json-c
as pkg-config adds '-I/usr/inlude/json-c' to the include paths:
$pkg-config --cflags json-c
-I/usr/include/json-c
So the simplest thing to support both build cased (external/embedded)
just drop the include prefix.
While at it also fix the 'requires' argument which expects strings not
dependencies objects.
Klaus Jensen [Mon, 18 Oct 2021 21:00:10 +0000 (23:00 +0200)]
meson: use library() and rely on user settings
There is no need to have both _static and _shared targets. Just use
library(). Project using libnvme as a subproject can now just set
default_options: ['default_library=static']
in the subproject statement to choose the library version.
For pkgconfig, simplify and let the module figure out Libs and Requires.
This has the effect of removing Requires and making it a
Requires.private so we don't require libnvme consumers to link with
libuuid and json-c (unless they specifically needs to use it like
test/test.c).
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
Daniel Wagner [Mon, 18 Oct 2021 11:58:53 +0000 (13:58 +0200)]
build: Split libtool versioning from project versioning
As described in GNU autotools manuals, libtool versioning is not the
same as the project versioning.
The project versioning string is defined in project_version. meson
uses this string for all operations such a creating the tarball. I
decided against using something fancy as 'git describe' for it,
because meson is not supporting this kind of dynamic project
versioning.
Instead we just need to increment the version after the release and
before the first commit. With this scheme we basically know by looking
at the version string if it is an official released version. If this
is not good enough we can try to adopt the approach other project are
doing such as systemd which introduced an additional package
versioning which depends on 'git describe'.
There is little point in fighting the tool if it can be done quite
easily by the described approach from above.
Daniel Wagner [Mon, 18 Oct 2021 09:24:34 +0000 (11:24 +0200)]
build: Set minimum version for json-c
Set minimum version for json-c to 0.13.
libnvme uses json_util_get_last_err() which got introduced in 0.13,
released in December 2017.
While at it, drop the cc.find_library() lookup logic. First, we don't
do this for libuuid and second, dependency() is using pkg-config to
figure out the dependency, thus we can set the minimum version
number. Instead, cc.find_library() will try to link a test program
with '-libjson-c' and have no way to figure out which version it
actually is. Avoid any confusion and make the meson.build script
simpler.
Daniel Wagner [Tue, 12 Oct 2021 15:18:48 +0000 (17:18 +0200)]
build: Allow subproject meson builds
meson has a very fancy feature called subproject. This allows bundle
third party libraries in a project. In order to be able to use this
for nvme-cli we need to drop all global config settings and declare
all dependencies.
Daniel Wagner [Tue, 12 Oct 2021 12:26:57 +0000 (14:26 +0200)]
fabrics: Remove 'UUID derived from machine-id' feature
Commit 3e0520ecad13 ("Read system UUID from DMI and merge hostnqn
generation functions") in nvme-cli introduced the feature to create
the UUID derived from machine-id using the systemd's
sd_id128_get_machine_app_specific function. This adds many library
dependencies to libnvme.
The feature is not really necessary as we have nvme-gen-hostnqn
already in place. So drop the feature entirely.
If the feature needs to be added back, it's probably better to
reimplement this function (e.g. move the hmac_sha256 function from
nvme-cli and use this to derive the UUID from machine-id).
Jeremy Kerr [Tue, 12 Oct 2021 06:42:28 +0000 (14:42 +0800)]
Unify configuration includes, use meson-generated configuration data
Currently, we have two separate configuration includes: ccan/config.h
and config-host.h. The first is generated by the ccan configurator, the
second by the configuration step (either ./configure, or meson).
This change unifies these into a top-level config.h include.
For the meson case, we can use the meson configuration file to provide
all data. For the configure case, we still use the ccan configurator,
but include the resulting file from the top-level config.h
This allows us to cross-compile with meson.
Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
Daniel Wagner [Mon, 11 Oct 2021 09:57:09 +0000 (11:57 +0200)]
fabrics: Do not overflow when reading systemd_uuid
gcc complains with:
../src/nvme/fabrics.c:774:15: warning: ‘read’ writing 512 bytes into a region of size 37 overflows the destination [-Wstringop-overflow=]
774 | len = read(f, system_uuid, 512);
| ^~~~~~~~~~~~~~~~~~~~~~~~~
../src/nvme/fabrics.c: In function ‘nvmf_hostnqn_generate’:
../src/nvme/fabrics.c:863:14: note: destination object ‘uuid_str’ of size 37
863 | char uuid_str[37]; /* e.g. 1b4e28ba-2fa1-11d2-883f-0016d3cca427 + \0 */
| ^~~~~~~~
Let's limit the read to 37 as we know that's the max size for a UUID.
Hannes Reinecke [Thu, 7 Oct 2021 09:51:36 +0000 (11:51 +0200)]
Add nvme_identify_active_ns_list_csi() and nvme_identify_allocated_ns_list_csi()
Update the command IDs with the values from NVMe base spec v2.0 and
implement the missing nvme_identify_active_ns_list_csi() and
nvme_identify_allocated_ns_list_csi().