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().
Daniel Wagner [Tue, 21 Sep 2021 07:03:06 +0000 (09:03 +0200)]
fabrics: Refactor uuid_from_device_tree
The recently added uuid_from_device_tree function can be refactored by
minimizing use of local variables and early returns in error
handling. No functional change.
Hannes Reinecke [Fri, 13 Aug 2021 09:58:08 +0000 (11:58 +0200)]
tree: rework topology for multiple hosts
Our tree structure host->subsys->ctrl doesn't match the underlying
topology; the subsystem actually just a container for controllers,
and the hosts are specified on the controller level, not the subsystem
level.
So to flatten that into our tree structure we need to duplicate the
subsystem objects for each host, and filter out the controllers such
that only the controllers with the correct hostnqn will show up
in our internal tree.
Hannes Reinecke [Thu, 12 Aug 2021 09:29:25 +0000 (11:29 +0200)]
fabrics: add nvme_host_t as argument to build_options()
build_options() can be called when the controller hasn't been
instantiated; in that case the 'subsystem' link in the controller
is empty, and there is no host associated with it.
Rather than selecting the default nvme host (and thereby losing
any different hostnqn settings which might have passed in from
the commandline) we should be passing in the nvme host directly
as argument to build_options().
Jeremy Kerr [Thu, 1 Jul 2021 06:26:57 +0000 (14:26 +0800)]
Separate libs from link flags to fix link-order compile failure
Currently, builds fail for me with a link error:
/usr/bin/ld: ../src//libnvme.a(tree.ol): in function `nvme_ns_get_uuid':
src/nvme/tree.c:1321: undefined reference to `uuid_copy'
/usr/bin/ld: ../src//libnvme.a(json.ol): in function `json_read_config':
src/nvme/json.c:152: undefined reference to `json_object_from_file'
Turns out my linker ("GNU ld (GNU Binutils for Debian) 2.35.2") is
sensitive to object argument order - the dependent libs need to be listed
last.
This change splits the required libraries into a LIBS variable, used
last on the Makefile rules to perform the link.
Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>