From 1fde82bbd3c0973f9c073ee4fb2c42345eff394e Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Wed, 13 Apr 2022 21:31:02 +0200 Subject: [PATCH] nvme: output also libnvme version Print the used libnvme version which the nvme-cli fronent is using. In order to be backward compatible don't expect that the newly introduce function in libnvme to be 1available. This is done by providing a weak symbol which is overwritten when statically build or when libnvme is is used as shared libray the dlsym() call checks if the function is available. $ nvme --version nvme version 2.0 (git 2.0-2-g037372a+) libnvme version 1.0 (git 1.0-2-gfb628fe) Signed-off-by: Daniel Wagner --- meson.build | 2 ++ plugin.c | 5 +++++ wrapper.c | 22 ++++++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 wrapper.c diff --git a/meson.build b/meson.build index c1698f5d..7252b539 100644 --- a/meson.build +++ b/meson.build @@ -243,6 +243,7 @@ sources = [ 'nvme-print.c', 'nvme-rpmb.c', 'plugin.c', + 'wrapper.c', ] subdir('ccan') @@ -256,6 +257,7 @@ executable( sources, dependencies: [ libnvme_dep, libuuid_dep, json_c_dep, libz_dep, libhugetlbfs_dep ], + link_args: '-ldl', include_directories: incdir, install: true, install_dir: sbindir diff --git a/plugin.c b/plugin.c index b27b2cb2..d58cf377 100644 --- a/plugin.c +++ b/plugin.c @@ -6,6 +6,8 @@ #include "plugin.h" #include "util/argconfig.h" +#include + static int version(struct plugin *plugin) { struct program *prog = plugin->parent; @@ -17,6 +19,9 @@ static int version(struct plugin *plugin) printf("%s version %s (git %s)\n", prog->name, prog->version, GIT_VERSION); } + printf("libnvme version %s (git %s)\n", + nvme_get_version(NVME_VERSION_PROJECT), + nvme_get_version(NVME_VERSION_GIT)); return 0; } diff --git a/wrapper.c b/wrapper.c new file mode 100644 index 00000000..73416315 --- /dev/null +++ b/wrapper.c @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * This file is part of nvme-cli + * + * Copyright (c) 2022 Daniel Wagner, SUSE + */ + +#include + +#include + +const char * __attribute__((weak)) nvme_get_version(enum nvme_version type) +{ + const char *(*libnvme_get_version)(enum nvme_version type); + + libnvme_get_version = dlsym(RTLD_NEXT, "nvme_get_version"); + + if (libnvme_get_version) + return libnvme_get_version(type); + + return "n/a"; +} -- 2.50.1