]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
libnvme-wrap: exit on VOID_FN lookup failure
authorCaleb Sander <csander@purestorage.com>
Sun, 5 Nov 2023 16:02:02 +0000 (09:02 -0700)
committerDaniel Wagner <wagi@monom.org>
Tue, 7 Nov 2023 08:08:09 +0000 (09:08 +0100)
libnvme-wrap provides fallbacks for missing libnvme functions.
For functions that return a value, the FN() macro can be used
to define a default return value if the function isn't found.
This isn't possible for functions returning void,
so VOID_FN() currently is a no-op if the function can't be found.
For nvme_init_copy_range_f1(), the only current VOID_FN() user,
this will result in silently sending a Copy command
with a zeroed range, which is not what the user requested.
Instead, exit the process immediately if the function can't be found.

Signed-off-by: Caleb Sander <csander@purestorage.com>
libnvme-wrap.c

index a62d60c0123e33a62006eb053b182a1762d97b01..b5b48383b630bcb200c757ee799853eb2c2a7c2d 100644 (file)
@@ -7,19 +7,24 @@
 
 #include <dlfcn.h>
 #include <errno.h>
+#include <stdlib.h>
 
 #include <libnvme.h>
+#include "nvme-print.h"
 
 #define PROTO(args...) args
 #define ARGS(args...) args
 
-#define VOID_FN(name, proto, args)                             \
-void __attribute__((weak)) name(proto)                         \
-{                                                              \
-       void (*fn)(proto);                                      \
-       fn = dlsym(RTLD_NEXT, #name);                           \
-       if (fn)                                                 \
-               fn(args);                                       \
+#define VOID_FN(name, proto, args)                                     \
+void __attribute__((weak)) name(proto)                                 \
+{                                                                      \
+       void (*fn)(proto);                                              \
+       fn = dlsym(RTLD_NEXT, #name);                                   \
+       if (!fn) {                                                      \
+               nvme_show_error("libnvme function " #name " not found");\
+               exit(EXIT_FAILURE);                                     \
+       }                                                               \
+       fn(args);                                                       \
 }
 
 #define FN(name, rtype, proto, args, defret)                   \