Blame SOURCES/0005-vddk-Include-VDDK-major-library-version-in-dump-plug.patch

f19e3f
From 9e20e2696fdb68008c9b4f1c36298f813320e381 Mon Sep 17 00:00:00 2001
f19e3f
From: "Richard W.M. Jones" <rjones@redhat.com>
f19e3f
Date: Sat, 23 Oct 2021 16:16:39 +0100
f19e3f
Subject: [PATCH] vddk: Include VDDK major library version in --dump-plugin
f19e3f
 output
f19e3f
f19e3f
Although it doesn't seem to be possible to get the precise VDDK
f19e3f
version, With a relatively simple change we can at least return the
f19e3f
VDDK major version.  Currently this can be 5, 6 or 7.
f19e3f
f19e3f
(cherry picked from commit 8700649d147948897f3b97810a1dff37924bdd6e)
f19e3f
---
f19e3f
 plugins/vddk/nbdkit-vddk-plugin.pod |  4 ++++
f19e3f
 plugins/vddk/vddk.c                 | 29 +++++++++++++++++++----------
f19e3f
 tests/test-vddk-real-dump-plugin.sh |  2 ++
f19e3f
 3 files changed, 25 insertions(+), 10 deletions(-)
f19e3f
f19e3f
diff --git a/plugins/vddk/nbdkit-vddk-plugin.pod b/plugins/vddk/nbdkit-vddk-plugin.pod
f19e3f
index 8b14eda0..822b96be 100644
f19e3f
--- a/plugins/vddk/nbdkit-vddk-plugin.pod
f19e3f
+++ b/plugins/vddk/nbdkit-vddk-plugin.pod
f19e3f
@@ -417,6 +417,10 @@ at runtime.
f19e3f
 If this is printed then the C<nfchostport=PORT> parameter is supported
f19e3f
 by this build.
f19e3f
 
f19e3f
+=item C<vddk_library_version=...>
f19e3f
+
f19e3f
+The VDDK major library version: 5, 6, 7, ...
f19e3f
+
f19e3f
 =item C<vddk_dll=...>
f19e3f
 
f19e3f
 Prints the full path to the VDDK shared library.  Since this requires
f19e3f
diff --git a/plugins/vddk/vddk.c b/plugins/vddk/vddk.c
f19e3f
index 69193504..291283f4 100644
f19e3f
--- a/plugins/vddk/vddk.c
f19e3f
+++ b/plugins/vddk/vddk.c
f19e3f
@@ -77,6 +77,7 @@ int vddk_debug_datapath = 1;
f19e3f
 static void *dl;                           /* dlopen handle */
f19e3f
 static bool init_called;                   /* was InitEx called */
f19e3f
 static __thread int error_suppression;     /* threadlocal error suppression */
f19e3f
+static int library_version;                /* VDDK major: 5, 6, 7, ... */
f19e3f
 
f19e3f
 static enum { NONE = 0, ZLIB, FASTLZ, SKIPZ } compression; /* compression */
f19e3f
 static char *config;                       /* config */
f19e3f
@@ -297,7 +298,10 @@ vddk_config (const char *key, const char *value)
f19e3f
 static void
f19e3f
 load_library (bool load_error_is_fatal)
f19e3f
 {
f19e3f
-  static const char *sonames[] = {
f19e3f
+  static struct {
f19e3f
+    const char *soname;
f19e3f
+    int library_version;
f19e3f
+  } libs[] = {
f19e3f
     /* Prefer the newest library in case multiple exist.  Check two
f19e3f
      * possible directories: the usual VDDK installation puts .so
f19e3f
      * files in an arch-specific subdirectory of $libdir (our minimum
f19e3f
@@ -305,12 +309,13 @@ load_library (bool load_error_is_fatal)
f19e3f
      * but our testsuite is easier to write if we point libdir
f19e3f
      * directly to a stub .so.
f19e3f
      */
f19e3f
-    "lib64/libvixDiskLib.so.7",
f19e3f
-    "libvixDiskLib.so.7",
f19e3f
-    "lib64/libvixDiskLib.so.6",
f19e3f
-    "libvixDiskLib.so.6",
f19e3f
-    "lib64/libvixDiskLib.so.5",
f19e3f
-    "libvixDiskLib.so.5",
f19e3f
+    { "lib64/libvixDiskLib.so.7", 7 },
f19e3f
+    { "libvixDiskLib.so.7",       7 },
f19e3f
+    { "lib64/libvixDiskLib.so.6", 6 },
f19e3f
+    { "libvixDiskLib.so.6",       6 },
f19e3f
+    { "lib64/libvixDiskLib.so.5", 5 },
f19e3f
+    { "libvixDiskLib.so.5",       5 },
f19e3f
+    { NULL }
f19e3f
   };
f19e3f
   size_t i;
f19e3f
   CLEANUP_FREE char *orig_error = NULL;
f19e3f
@@ -323,19 +328,20 @@ load_library (bool load_error_is_fatal)
f19e3f
     }
f19e3f
   }
f19e3f
 
f19e3f
-  for (i = 0; i < sizeof sonames / sizeof sonames[0]; ++i) {
f19e3f
+  for (i = 0; libs[i].soname != NULL; ++i) {
f19e3f
     CLEANUP_FREE char *path;
f19e3f
 
f19e3f
     /* Set the full path so that dlopen will preferentially load the
f19e3f
      * system libraries from the same directory.
f19e3f
      */
f19e3f
-    if (asprintf (&path, "%s/%s", libdir, sonames[i]) == -1) {
f19e3f
+    if (asprintf (&path, "%s/%s", libdir, libs[i].soname) == -1) {
f19e3f
       nbdkit_error ("asprintf: %m");
f19e3f
       exit (EXIT_FAILURE);
f19e3f
     }
f19e3f
 
f19e3f
     dl = dlopen (path, RTLD_NOW);
f19e3f
     if (dl != NULL) {
f19e3f
+      library_version = libs[i].library_version;
f19e3f
       /* Now that we found the library, ensure that LD_LIBRARY_PATH
f19e3f
        * includes its directory for all future loads.  This may modify
f19e3f
        * path in-place and/or re-exec nbdkit, but that's okay.
f19e3f
@@ -356,10 +362,12 @@ load_library (bool load_error_is_fatal)
f19e3f
                   "If '%s' is located on a non-standard path you may need to\n"
f19e3f
                   "set libdir=/path/to/vmware-vix-disklib-distrib.\n\n"
f19e3f
                   "See nbdkit-vddk-plugin(1) man page section \"LIBRARY LOCATION\" for details.",
f19e3f
-                  orig_error ? : "(unknown error)", sonames[0]);
f19e3f
+                  orig_error ? : "(unknown error)", libs[0].soname);
f19e3f
     exit (EXIT_FAILURE);
f19e3f
   }
f19e3f
 
f19e3f
+  assert (library_version >= 5);
f19e3f
+
f19e3f
   /* Load symbols. */
f19e3f
 #define STUB(fn,ret,args)                                         \
f19e3f
   do {                                                            \
f19e3f
@@ -474,6 +482,7 @@ vddk_dump_plugin (void)
f19e3f
 
f19e3f
   printf ("vddk_default_libdir=%s\n", VDDK_LIBDIR);
f19e3f
   printf ("vddk_has_nfchostport=1\n");
f19e3f
+  printf ("vddk_library_version=%d\n", library_version);
f19e3f
 
f19e3f
 #if defined(HAVE_DLADDR)
f19e3f
   /* It would be nice to print the version of VDDK from the shared
f19e3f
diff --git a/tests/test-vddk-real-dump-plugin.sh b/tests/test-vddk-real-dump-plugin.sh
f19e3f
index 1479e416..59c79693 100755
f19e3f
--- a/tests/test-vddk-real-dump-plugin.sh
f19e3f
+++ b/tests/test-vddk-real-dump-plugin.sh
f19e3f
@@ -51,10 +51,12 @@ rm -f $files
f19e3f
 cleanup_fn rm -f $files
f19e3f
 
f19e3f
 nbdkit -f -v vddk libdir="$vddkdir" --dump-plugin > $out
f19e3f
+cat $out
f19e3f
 
f19e3f
 # Check the vddk_* entries are set.
f19e3f
 grep ^vddk_default_libdir= $out
f19e3f
 grep ^vddk_has_nfchostport= $out
f19e3f
+grep ^vddk_library_version= $out
f19e3f
 grep ^vddk_dll= $out
f19e3f
 
f19e3f
 dll="$(grep ^vddk_dll $out | cut -d= -f2)"
f19e3f
-- 
f19e3f
2.31.1
f19e3f