]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme: output also libnvme version
authorDaniel Wagner <dwagner@suse.de>
Wed, 13 Apr 2022 19:31:02 +0000 (21:31 +0200)
committerDaniel Wagner <dwagner@suse.de>
Thu, 14 Apr 2022 08:58:32 +0000 (10:58 +0200)
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 <dwagner@suse.de>
meson.build
plugin.c
wrapper.c [new file with mode: 0644]

index c1698f5d4eb8c6956efd2eb06c5d355962c1d504..7252b539ca42b3097710c878882a511d611ab551 100644 (file)
@@ -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
index b27b2cb2c90b11635943ac9dfc964e08b4968350..d58cf37788757d68363e77be3ad74e695a812d47 100644 (file)
--- a/plugin.c
+++ b/plugin.c
@@ -6,6 +6,8 @@
 #include "plugin.h"
 #include "util/argconfig.h"
 
+#include <libnvme.h>
+
 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 (file)
index 0000000..7341631
--- /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 <dlfcn.h>
+
+#include <libnvme.h>
+
+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";
+}