From f7abdefbdd861ec752cf3df6eda42c26c522cdb9 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Sun, 1 Aug 2010 23:12:24 +0200 Subject: [PATCH] 2010-08-01 Robert Millan Make it even harder to use uninitialized `libzfs_handle' (and make the interface a bit simpler). * include/grub/util/misc.h (grub_util_init_libzfs) (libzfs_handle): Remove. (grub_get_libzfs_handle): New prototype. * util/misc.c [HAVE_LIBZFS] (libzfs_handle): Add `static' attribute. (grub_util_init_libzfs): Remove. (grub_get_libzfs_handle): New function. * kern/emu/getroot.c (find_root_device_from_libzfs): Use grub_get_libzfs_handle() to obtain a libzfs handle instead of accessing `libzfs_handle' directly. --- ChangeLog | 18 ++++++++++++++++++ include/grub/util/misc.h | 3 +-- kern/emu/getroot.c | 4 +--- util/misc.c | 14 +++++++------- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2956129b3..d4a63c4ec 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2010-08-01 Robert Millan + + Make it even harder to use uninitialized `libzfs_handle' (and + make the interface a bit simpler). + + * include/grub/util/misc.h (grub_util_init_libzfs) + (libzfs_handle): Remove. + (grub_get_libzfs_handle): New prototype. + + * util/misc.c [HAVE_LIBZFS] (libzfs_handle): Add `static' + attribute. + (grub_util_init_libzfs): Remove. + (grub_get_libzfs_handle): New function. + + * kern/emu/getroot.c (find_root_device_from_libzfs): Use + grub_get_libzfs_handle() to obtain a libzfs handle instead of + accessing `libzfs_handle' directly. + 2010-08-01 Robert Millan * include/grub/emu/misc.h (grub_find_mount_point_from_dir) diff --git a/include/grub/util/misc.h b/include/grub/util/misc.h index 3614c79c2..7ce3d3291 100644 --- a/include/grub/util/misc.h +++ b/include/grub/util/misc.h @@ -61,7 +61,6 @@ char *canonicalize_file_name (const char *path); void grub_util_init_nls (void); -void grub_util_init_libzfs (void); -extern libzfs_handle_t *libzfs_handle; +libzfs_handle_t *grub_get_libzfs_handle (void); #endif /* ! GRUB_UTIL_MISC_HEADER */ diff --git a/kern/emu/getroot.c b/kern/emu/getroot.c index 32044536d..ee6e1c7ba 100644 --- a/kern/emu/getroot.c +++ b/kern/emu/getroot.c @@ -197,9 +197,7 @@ find_root_device_from_libzfs (const char *dir) nvlist_t **nvlist_array; unsigned int nvlist_count; - grub_util_init_libzfs (); - - zpool = zpool_open (libzfs_handle, poolname); + zpool = zpool_open (grub_get_libzfs_handle (), poolname); nvlist = zpool_get_config (zpool, NULL); if (nvlist_lookup_nvlist (nvlist, "vdev_tree", &nvlist) != 0) diff --git a/util/misc.c b/util/misc.c index 2eff256bf..274c182c2 100644 --- a/util/misc.c +++ b/util/misc.c @@ -296,27 +296,27 @@ grub_util_init_nls (void) } #ifdef HAVE_LIBZFS -libzfs_handle_t *libzfs_handle; +static libzfs_handle_t *libzfs_handle; static void fini_libzfs (void) { libzfs_fini (libzfs_handle); } -#endif -void -grub_util_init_libzfs (void) +libzfs_handle_t * +grub_get_libzfs_handle (void) { -#ifdef HAVE_LIBZFS if (! libzfs_handle) { libzfs_handle = libzfs_init (); atexit (fini_libzfs); } -#endif + + return libzfs_handle; } -#endif +#endif /* HAVE_LIBZFS */ +#endif /* GRUB_UTIL */ int grub_dl_ref (grub_dl_t mod)