From b1b9ae5efcc9da70c03ccc7354a416a6d7cd74f9 Mon Sep 17 00:00:00 2001 From: Faruk Kasumovic Date: Tue, 10 Apr 2018 13:45:02 +0200 Subject: [PATCH] - Fix PoolImportSearch not listing pools that are not explicitly exported --- zpool.c | 10 ++++++++++ zpool.go | 5 +---- zpool.h | 2 ++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/zpool.c b/zpool.c index 6cd0d49..a6c982b 100644 --- a/zpool.c +++ b/zpool.c @@ -486,4 +486,14 @@ nvlist_ptr get_zpool_vdev_tree(nvlist_ptr nv) { return NULL; } return vdev_tree; +} + + +nvlist_ptr go_zpool_search_import(libzfs_handle_ptr zfsh, int paths, char **path, boolean_t do_scan) { + importargs_t idata = { 0 }; + idata.path = path; + idata.paths = paths; + // idata.scan = 0; + + return zpool_search_import(zfsh, &idata); } \ No newline at end of file diff --git a/zpool.go b/zpool.go index 7a3f547..0cc47a0 100644 --- a/zpool.go +++ b/zpool.go @@ -307,7 +307,7 @@ func PoolImportSearch(searchpaths []string) (epools []ExportedPool, err error) { C.strings_setat(cpaths, C.int(i), csPath) } - pools := C.zpool_find_import(C.libzfsHandle, C.int(numofp), cpaths) + pools := C.go_zpool_search_import(C.libzfsHandle, C.int(numofp), cpaths, C.B_FALSE) defer C.nvlist_free(pools) elem = C.nvlist_next_nvpair(pools, elem) epools = make([]ExportedPool, 0, 1) @@ -319,9 +319,6 @@ func PoolImportSearch(searchpaths []string) (epools []ExportedPool, err error) { } ep.State = PoolState(C.get_zpool_state(config)) - if ep.State != PoolStateExported { - continue - } if cname = C.get_zpool_name(config); cname == nil { err = fmt.Errorf("Failed to fetch %s", C.ZPOOL_CONFIG_POOL_NAME) diff --git a/zpool.h b/zpool.h index 0961a36..cdb5892 100644 --- a/zpool.h +++ b/zpool.h @@ -68,6 +68,8 @@ const char *get_zpool_comment(nvlist_ptr nv); nvlist_ptr get_zpool_vdev_tree(nvlist_ptr nv); +nvlist_ptr go_zpool_search_import(libzfs_handle_ptr zfsh, int paths, char **path, boolean_t do_scan); + extern char *sZPOOL_CONFIG_VERSION; extern char *sZPOOL_CONFIG_POOL_NAME;