Blame SOURCES/0016-vddk-Simplify-detection-of-VDDK-symbols-and-baseline.patch

3beab2
From 984e95fcbdb19c2495851322a4c33f34291ecfab Mon Sep 17 00:00:00 2001
7084e2
From: "Richard W.M. Jones" <rjones@redhat.com>
7084e2
Date: Fri, 29 Oct 2021 21:02:54 +0100
7084e2
Subject: [PATCH] vddk: Simplify detection of VDDK symbols and baseline 6.5
7084e2
7084e2
Make all symbols from VDDK 6.5 into required symbols and use a single
7084e2
error message function if one of these is missing.  The new error is:
7084e2
7084e2
  nbdkit: error: required VDDK symbol "VixDiskLib_Wait" is
7084e2
  missing. VDDK version must be >= 6.5. See nbdkit-vddk-plugin(1) man
7084e2
  page section "SUPPORTED VERSIONS OF VDDK". Original dlopen error:
7084e2
  vmware-vix-disklib-distrib/lib64/libvixDiskLib.so.6: undefined
7084e2
  symbol: VixDiskLib_Wait
7084e2
7084e2
Remove the extra check and assert.
7084e2
7084e2
Be more consistent about #define OPTIONAL_STUB(fn,ret,args) STUB(fn,ret,args)
7084e2
when we want the optional and required stubs to do the same thing.
7084e2
7084e2
(cherry picked from commit ec0d22e61881efa39a69d02ccb9e4ede8bf95e75)
7084e2
---
7084e2
 plugins/vddk/stats.c      |  2 +-
7084e2
 plugins/vddk/vddk-stubs.h | 45 ++++++++++++++++++---------------------
7084e2
 plugins/vddk/vddk.c       | 36 ++++++++++++-------------------
7084e2
 plugins/vddk/vddk.h       |  2 +-
7084e2
 4 files changed, 37 insertions(+), 48 deletions(-)
7084e2
7084e2
diff --git a/plugins/vddk/stats.c b/plugins/vddk/stats.c
7084e2
index 18a42714..76e0c244 100644
7084e2
--- a/plugins/vddk/stats.c
7084e2
+++ b/plugins/vddk/stats.c
7084e2
@@ -89,7 +89,7 @@ display_stats (void)
7084e2
   if (!vddk_debug_stats) return;
7084e2
 
7084e2
 #define STUB(fn,ret,args) statlist_append (&stats, stats_##fn)
7084e2
-#define OPTIONAL_STUB(fn,ret,args) statlist_append (&stats, stats_##fn)
7084e2
+#define OPTIONAL_STUB(fn,ret,args) STUB(fn,ret,args)
7084e2
 #include "vddk-stubs.h"
7084e2
 #undef STUB
7084e2
 #undef OPTIONAL_STUB
7084e2
diff --git a/plugins/vddk/vddk-stubs.h b/plugins/vddk/vddk-stubs.h
7084e2
index 66353691..7d8644c3 100644
7084e2
--- a/plugins/vddk/vddk-stubs.h
7084e2
+++ b/plugins/vddk/vddk-stubs.h
7084e2
@@ -39,10 +39,7 @@
7084e2
  * function name, return value, arguments.
7084e2
  */
7084e2
 
7084e2
-/* Required stubs, present in all versions of VDDK that we support.  I
7084e2
- * have checked that all these exist in at least VDDK 5.5.5 (2015).
7084e2
- */
7084e2
-
7084e2
+/* Required stubs, present in all versions of VDDK since 6.5 (Nov 2016). */
7084e2
 STUB (VixDiskLib_InitEx,
7084e2
       VixError,
7084e2
       (uint32_t major, uint32_t minor,
7084e2
@@ -103,27 +100,27 @@ STUB (VixDiskLib_Write,
7084e2
        uint64_t start_sector, uint64_t nr_sectors,
7084e2
        const unsigned char *buf));
7084e2
 
7084e2
-/* Added in VDDK 6.0, these will be NULL in earlier versions. */
7084e2
-OPTIONAL_STUB (VixDiskLib_Flush,
7084e2
-               VixError,
7084e2
-               (VixDiskLibHandle handle));
7084e2
-OPTIONAL_STUB (VixDiskLib_ReadAsync,
7084e2
-               VixError,
7084e2
-               (VixDiskLibHandle handle,
7084e2
-                uint64_t start_sector, uint64_t nr_sectors,
7084e2
-                unsigned char *buf,
7084e2
-                VixDiskLibCompletionCB callback, void *data));
7084e2
-OPTIONAL_STUB (VixDiskLib_WriteAsync,
7084e2
-               VixError,
7084e2
-               (VixDiskLibHandle handle,
7084e2
-                uint64_t start_sector, uint64_t nr_sectors,
7084e2
-                const unsigned char *buf,
7084e2
-                VixDiskLibCompletionCB callback, void *data));
7084e2
+/* Added in VDDK 6.0. */
7084e2
+STUB (VixDiskLib_Flush,
7084e2
+      VixError,
7084e2
+      (VixDiskLibHandle handle));
7084e2
+STUB (VixDiskLib_ReadAsync,
7084e2
+      VixError,
7084e2
+      (VixDiskLibHandle handle,
7084e2
+       uint64_t start_sector, uint64_t nr_sectors,
7084e2
+       unsigned char *buf,
7084e2
+       VixDiskLibCompletionCB callback, void *data));
7084e2
+STUB (VixDiskLib_WriteAsync,
7084e2
+      VixError,
7084e2
+      (VixDiskLibHandle handle,
7084e2
+       uint64_t start_sector, uint64_t nr_sectors,
7084e2
+       const unsigned char *buf,
7084e2
+       VixDiskLibCompletionCB callback, void *data));
7084e2
 
7084e2
-/* Added in VDDK 6.5, this will be NULL in earlier versions. */
7084e2
-OPTIONAL_STUB (VixDiskLib_Wait,
7084e2
-               VixError,
7084e2
-               (VixDiskLibHandle handle));
7084e2
+/* Added in VDDK 6.5. */
7084e2
+STUB (VixDiskLib_Wait,
7084e2
+      VixError,
7084e2
+      (VixDiskLibHandle handle));
7084e2
 
7084e2
 /* Added in VDDK 6.7, these will be NULL for earlier versions: */
7084e2
 OPTIONAL_STUB (VixDiskLib_QueryAllocatedBlocks,
7084e2
diff --git a/plugins/vddk/vddk.c b/plugins/vddk/vddk.c
7084e2
index f967e2d9..271b5ee0 100644
7084e2
--- a/plugins/vddk/vddk.c
7084e2
+++ b/plugins/vddk/vddk.c
7084e2
@@ -63,7 +63,7 @@ NBDKIT_DLL_PUBLIC int vddk_debug_datapath = 1;
7084e2
  * initialized when the plugin is loaded (by vddk_get_ready).
7084e2
  */
7084e2
 #define STUB(fn,ret,args) ret (*fn) args
7084e2
-#define OPTIONAL_STUB(fn,ret,args) ret (*fn) args
7084e2
+#define OPTIONAL_STUB(fn,ret,args) STUB(fn,ret,args)
7084e2
 #include "vddk-stubs.h"
7084e2
 #undef STUB
7084e2
 #undef OPTIONAL_STUB
7084e2
@@ -282,6 +282,17 @@ vddk_config (const char *key, const char *value)
7084e2
   return 0;
7084e2
 }
7084e2
 
7084e2
+static void
7084e2
+missing_required_symbol (const char *fn)
7084e2
+{
7084e2
+  nbdkit_error ("required VDDK symbol \"%s\" is missing. "
7084e2
+                "VDDK version must be >= 6.5. "
7084e2
+                "See nbdkit-vddk-plugin(1) man page section \"SUPPORTED VERSIONS OF VDDK\". "
7084e2
+                "Original dlopen error: %s\n",
7084e2
+                fn, dlerror ());
7084e2
+  exit (EXIT_FAILURE);
7084e2
+}
7084e2
+
7084e2
 /* Load the VDDK library. */
7084e2
 static void
7084e2
 load_library (bool load_error_is_fatal)
7084e2
@@ -358,32 +369,13 @@ load_library (bool load_error_is_fatal)
7084e2
 #define STUB(fn,ret,args)                                         \
7084e2
   do {                                                            \
7084e2
     fn = dlsym (dl, #fn);                                         \
7084e2
-    if (fn == NULL) {                                             \
7084e2
-      nbdkit_error ("required VDDK symbol \"%s\" is missing: %s", \
7084e2
-                    #fn, dlerror ());                             \
7084e2
-      exit (EXIT_FAILURE);                                        \
7084e2
-    }                                                             \
7084e2
+    if (fn == NULL)                                               \
7084e2
+      missing_required_symbol (#fn);                              \
7084e2
   } while (0)
7084e2
 #define OPTIONAL_STUB(fn,ret,args) fn = dlsym (dl, #fn)
7084e2
 #include "vddk-stubs.h"
7084e2
 #undef STUB
7084e2
 #undef OPTIONAL_STUB
7084e2
-
7084e2
-  /* Additionally, VDDK version must be >= 6.5.  This was the first
7084e2
-   * version which introduced VixDiskLib_Wait symbol so we can check
7084e2
-   * for that.
7084e2
-   */
7084e2
-  if (VixDiskLib_Wait == NULL) {
7084e2
-    nbdkit_error ("VDDK version must be >= 6.5. "
7084e2
-                  "See nbdkit-vddk-plugin(1) man page section \"SUPPORTED VERSIONS OF VDDK\".");
7084e2
-    exit (EXIT_FAILURE);
7084e2
-  }
7084e2
-
7084e2
-  /* Added in VDDK 6.0 so it must always be present.  Since we are
7084e2
-   * going to call this function unconditionally, fail early and hard
7084e2
-   * if for some reason it's not present.
7084e2
-   */
7084e2
-  assert (VixDiskLib_Flush != NULL);
7084e2
 }
7084e2
 
7084e2
 static int
7084e2
diff --git a/plugins/vddk/vddk.h b/plugins/vddk/vddk.h
7084e2
index be0b3492..0e3dd79e 100644
7084e2
--- a/plugins/vddk/vddk.h
7084e2
+++ b/plugins/vddk/vddk.h
7084e2
@@ -76,7 +76,7 @@ extern int vddk_debug_datapath;
7084e2
 extern int vddk_debug_stats;
7084e2
 
7084e2
 #define STUB(fn,ret,args) extern ret (*fn) args
7084e2
-#define OPTIONAL_STUB(fn,ret,args) extern ret (*fn) args
7084e2
+#define OPTIONAL_STUB(fn,ret,args) STUB(fn,ret,args)
7084e2
 #include "vddk-stubs.h"
7084e2
 #undef STUB
7084e2
 #undef OPTIONAL_STUB
7084e2
-- 
7084e2
2.31.1
7084e2