libnvpair: Support prefixed nvlist symbol names as found on NetBSD

NetBSD uses slightly different function names for the same functions.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
This commit is contained in:
Vladimir Serbinenko 2023-08-25 00:01:25 +02:00 committed by Daniel Kiper
parent a13df3d15a
commit f20123072a
3 changed files with 26 additions and 9 deletions

View File

@ -2005,8 +2005,19 @@ fi
if test x"$libzfs_excuse" = x ; then if test x"$libzfs_excuse" = x ; then
AC_CHECK_LIB([nvpair], [nvlist_lookup_string], AC_CHECK_LIB([nvpair], [nvlist_lookup_string],
[], [have_normal_nvpair=yes],
[libzfs_excuse="need nvpair library"]) [have_normal_nvpair=no])
if test x"$have_normal_nvpair" = xno ; then
AC_CHECK_LIB([nvpair], [opensolaris_nvlist_lookup_string],
[have_prefixed_nvpair=yes],
[have_prefixed_nvpair=no])
if test x"$have_prefixed_nvpair" = xyes ; then
AC_DEFINE([GRUB_UTIL_NVPAIR_IS_PREFIXED], [1],
[Define to 1 if libnvpair symbols are prefixed with opensolaris_.])
else
libzfs_excuse="need nvpair library"
fi
fi
fi fi
if test x"$enable_libzfs" = xyes && test x"$libzfs_excuse" != x ; then if test x"$enable_libzfs" = xyes && test x"$libzfs_excuse" != x ; then

View File

@ -174,20 +174,20 @@ grub_util_find_root_devices_from_poolname (char *poolname)
zpool = zpool_open (libzfs, poolname); zpool = zpool_open (libzfs, poolname);
config = zpool_get_config (zpool, NULL); config = zpool_get_config (zpool, NULL);
if (nvlist_lookup_nvlist (config, "vdev_tree", &vdev_tree) != 0) if (NVLIST(lookup_nvlist) (config, "vdev_tree", &vdev_tree) != 0)
error (1, errno, "nvlist_lookup_nvlist (\"vdev_tree\")"); error (1, errno, "nvlist_lookup_nvlist (\"vdev_tree\")");
if (nvlist_lookup_nvlist_array (vdev_tree, "children", &children, &nvlist_count) != 0) if (NVLIST(lookup_nvlist_array) (vdev_tree, "children", &children, &nvlist_count) != 0)
error (1, errno, "nvlist_lookup_nvlist_array (\"children\")"); error (1, errno, "nvlist_lookup_nvlist_array (\"children\")");
assert (nvlist_count > 0); assert (nvlist_count > 0);
while (nvlist_lookup_nvlist_array (children[0], "children", while (NVLIST(lookup_nvlist_array) (children[0], "children",
&children, &nvlist_count) == 0) &children, &nvlist_count) == 0)
assert (nvlist_count > 0); assert (nvlist_count > 0);
for (i = 0; i < nvlist_count; i++) for (i = 0; i < nvlist_count; i++)
{ {
if (nvlist_lookup_string (children[i], "path", &device) != 0) if (NVLIST(lookup_string) (children[i], "path", &device) != 0)
error (1, errno, "nvlist_lookup_string (\"path\")"); error (1, errno, "nvlist_lookup_string (\"path\")");
struct stat st; struct stat st;

View File

@ -29,9 +29,15 @@
typedef void nvlist_t; typedef void nvlist_t;
int nvlist_lookup_string (nvlist_t *, const char *, char **); #ifdef GRUB_UTIL_NVPAIR_IS_PREFIXED
int nvlist_lookup_nvlist (nvlist_t *, const char *, nvlist_t **); #define NVLIST(x) opensolaris_nvlist_ ## x
int nvlist_lookup_nvlist_array (nvlist_t *, const char *, nvlist_t ***, unsigned int *); #else
#define NVLIST(x) nvlist_ ## x
#endif
int NVLIST(lookup_string) (nvlist_t *, const char *, char **);
int NVLIST(lookup_nvlist) (nvlist_t *, const char *, nvlist_t **);
int NVLIST(lookup_nvlist_array) (nvlist_t *, const char *, nvlist_t ***, unsigned int *);
#endif /* ! HAVE_LIBNVPAIR_H */ #endif /* ! HAVE_LIBNVPAIR_H */