From 186cb47e71ae9d14699c54f93b61ce5d749e8fa8 Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko <phco...@gmail.com>
Date: Fri, 25 Aug 2023 00:01:25 +0200
Subject: [PATCH 11/13] Support prefixed nvlist symbol names as found on NetBSD

---
 configure.ac                   | 15 +++++++++++++--
 grub-core/osdep/unix/getroot.c |  8 ++++----
 include/grub/util/libnvpair.h  | 12 +++++++++---
 3 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/configure.ac b/configure.ac
index 2902f9533..9fa0931b3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1983,8 +1983,19 @@ fi
 
 if test x"$libzfs_excuse" = x ; then
   AC_CHECK_LIB([nvpair], [nvlist_lookup_string],
-               [],
-               [libzfs_excuse="need nvpair library"])
+               [have_normal_nvpair=yes],
+               [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
 
 if test x"$enable_libzfs" = xyes && test x"$libzfs_excuse" != x ; then
diff --git a/grub-core/osdep/unix/getroot.c b/grub-core/osdep/unix/getroot.c
index 71cdf2e86..ee11b02fb 100644
--- a/grub-core/osdep/unix/getroot.c
+++ b/grub-core/osdep/unix/getroot.c
@@ -174,20 +174,20 @@ grub_util_find_root_devices_from_poolname (char *poolname)
   zpool = zpool_open (libzfs, poolname);
   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\")");
 
-  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\")");
   assert (nvlist_count > 0);
 
-  while (nvlist_lookup_nvlist_array (children[0], "children",
+  while (NVLIST(lookup_nvlist_array) (children[0], "children",
 				     &children, &nvlist_count) == 0)
     assert (nvlist_count > 0);
 
   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\")");
 
       struct stat st;
diff --git a/include/grub/util/libnvpair.h b/include/grub/util/libnvpair.h
index 573c7ea81..a3acffb88 100644
--- a/include/grub/util/libnvpair.h
+++ b/include/grub/util/libnvpair.h
@@ -29,9 +29,15 @@
 
 typedef void nvlist_t;
 
-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 *);
+#ifdef GRUB_UTIL_NVPAIR_IS_PREFIXED
+#define NVLIST(x) opensolaris_nvlist_ ## x
+#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 */
 
-- 
2.42.0

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to