diff options
author | Brian Behlendorf <[email protected]> | 2017-08-09 15:31:08 -0700 |
---|---|---|
committer | GitHub <[email protected]> | 2017-08-09 15:31:08 -0700 |
commit | 46364cb2f35545a7fc915df9593b719a94c43a83 (patch) | |
tree | 0fb11534892c2aaaa1c1bda3c10914e718827eb0 /lib/libzfs/libzfs_import.c | |
parent | 5146d802b4e371cab1d6db79bea482c056be7bf2 (diff) |
Add libtpool (thread pools)
OpenZFS provides a library called tpool which implements thread
pools for user space applications. Porting this library means
the zpool utility no longer needs to borrow the kernel mutex and
taskq interfaces from libzpool. This code was updated to use
the tpool library which behaves in a very similar fashion.
Porting libtpool was relatively straight forward and minimal
modifications were needed. The core changes were:
* Fully convert the library to use pthreads.
* Updated signal handling.
* lmalloc/lfree converted to calloc/free
* Implemented portable pthread_attr_clone() function.
Finally, update the build system such that libzpool.so is no
longer linked in to zfs(8), zpool(8), etc. All that is required
is libzfs to which the zcommon soures were added (which is the way
it always should have been). Removing the libzpool dependency
resulted in several build issues which needed to be resolved.
* Moved zfeature support to module/zcommon/zfeature_common.c
* Moved ratelimiting to to module/zfs/zfs_ratelimit.c
* Moved get_system_hostid() to lib/libspl/gethostid.c
* Removed use of cmn_err() in zcommon source
* Removed dprintf_setup() call from zpool_main.c and zfs_main.c
* Removed highbit() and lowbit()
* Removed unnecessary library dependencies from Makefiles
* Removed fletcher-4 kstat in user space
* Added sha2 support explicitly to libzfs
* Added highbit64() and lowbit64() to zpool_util.c
Reviewed-by: Tony Hutter <[email protected]>
Signed-off-by: Brian Behlendorf <[email protected]>
Closes #6442
Diffstat (limited to 'lib/libzfs/libzfs_import.c')
-rw-r--r-- | lib/libzfs/libzfs_import.c | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/lib/libzfs/libzfs_import.c b/lib/libzfs/libzfs_import.c index f371d925b..833568356 100644 --- a/lib/libzfs/libzfs_import.c +++ b/lib/libzfs/libzfs_import.c @@ -60,6 +60,7 @@ #include <sys/vtoc.h> #include <sys/dktp/fdisk.h> #include <sys/efi_partition.h> +#include <thread_pool.h> #include <sys/vdev_impl.h> #include <blkid/blkid.h> #include "libzfs.h" @@ -1388,7 +1389,7 @@ typedef struct rdsk_node { nvlist_t *rn_config; /* Label config */ avl_tree_t *rn_avl; avl_node_t rn_node; - kmutex_t *rn_lock; + pthread_mutex_t *rn_lock; boolean_t rn_labelpaths; } rdsk_node_t; @@ -1603,14 +1604,14 @@ zpool_open_func(void *arg) slice->rn_hdl = hdl; slice->rn_order = IMPORT_ORDER_PREFERRED_1; slice->rn_labelpaths = B_FALSE; - mutex_enter(rn->rn_lock); + pthread_mutex_lock(rn->rn_lock); if (avl_find(rn->rn_avl, slice, &where)) { - mutex_exit(rn->rn_lock); + pthread_mutex_unlock(rn->rn_lock); free(slice->rn_name); free(slice); } else { avl_insert(rn->rn_avl, slice, where); - mutex_exit(rn->rn_lock); + pthread_mutex_unlock(rn->rn_lock); zpool_open_func(slice); } } @@ -1629,14 +1630,14 @@ zpool_open_func(void *arg) slice->rn_hdl = hdl; slice->rn_order = IMPORT_ORDER_PREFERRED_2; slice->rn_labelpaths = B_FALSE; - mutex_enter(rn->rn_lock); + pthread_mutex_lock(rn->rn_lock); if (avl_find(rn->rn_avl, slice, &where)) { - mutex_exit(rn->rn_lock); + pthread_mutex_unlock(rn->rn_lock); free(slice->rn_name); free(slice); } else { avl_insert(rn->rn_avl, slice, where); - mutex_exit(rn->rn_lock); + pthread_mutex_unlock(rn->rn_lock); zpool_open_func(slice); } } @@ -1679,7 +1680,7 @@ zpool_clear_label(int fd) * Scan a list of directories for zfs devices. */ static int -zpool_find_import_scan(libzfs_handle_t *hdl, kmutex_t *lock, +zpool_find_import_scan(libzfs_handle_t *hdl, pthread_mutex_t *lock, avl_tree_t **slice_cache, char **dir, int dirs) { avl_tree_t *cache; @@ -1735,9 +1736,9 @@ zpool_find_import_scan(libzfs_handle_t *hdl, kmutex_t *lock, slice->rn_hdl = hdl; slice->rn_order = i + IMPORT_ORDER_SCAN_OFFSET; slice->rn_labelpaths = B_FALSE; - mutex_enter(lock); + pthread_mutex_lock(lock); avl_add(cache, slice); - mutex_exit(lock); + pthread_mutex_unlock(lock); } (void) closedir(dirp); @@ -1761,7 +1762,7 @@ error: * Use libblkid to quickly enumerate all known zfs devices. */ static int -zpool_find_import_blkid(libzfs_handle_t *hdl, kmutex_t *lock, +zpool_find_import_blkid(libzfs_handle_t *hdl, pthread_mutex_t *lock, avl_tree_t **slice_cache) { rdsk_node_t *slice; @@ -1815,14 +1816,14 @@ zpool_find_import_blkid(libzfs_handle_t *hdl, kmutex_t *lock, else slice->rn_order = IMPORT_ORDER_DEFAULT; - mutex_enter(lock); + pthread_mutex_lock(lock); if (avl_find(*slice_cache, slice, &where)) { free(slice->rn_name); free(slice); } else { avl_insert(*slice_cache, slice, where); } - mutex_exit(lock); + pthread_mutex_unlock(lock); } blkid_dev_iterate_end(iter); @@ -1860,14 +1861,14 @@ zpool_find_import_impl(libzfs_handle_t *hdl, importargs_t *iarg) vdev_entry_t *ve, *venext; config_entry_t *ce, *cenext; name_entry_t *ne, *nenext; - kmutex_t lock; + pthread_mutex_t lock; avl_tree_t *cache; rdsk_node_t *slice; void *cookie; - taskq_t *t; + tpool_t *t; verify(iarg->poolname == NULL || iarg->guid == 0); - mutex_init(&lock, NULL, MUTEX_DEFAULT, NULL); + pthread_mutex_init(&lock, NULL); /* * Locate pool member vdevs using libblkid or by directory scanning. @@ -1896,15 +1897,13 @@ zpool_find_import_impl(libzfs_handle_t *hdl, importargs_t *iarg) * validating labels, a large number of threads can be used due to * minimal contention. */ - t = taskq_create("z_import", 2 * boot_ncpus, defclsyspri, - 2 * boot_ncpus, INT_MAX, TASKQ_PREPOPULATE); - + t = tpool_create(1, 2 * sysconf(_SC_NPROCESSORS_ONLN), 0, NULL); for (slice = avl_first(cache); slice; (slice = avl_walk(cache, slice, AVL_AFTER))) - (void) taskq_dispatch(t, zpool_open_func, slice, TQ_SLEEP); + (void) tpool_dispatch(t, zpool_open_func, slice); - taskq_wait(t); - taskq_destroy(t); + tpool_wait(t); + tpool_destroy(t); /* * Process the cache filtering out any entries which are not @@ -1974,7 +1973,7 @@ zpool_find_import_impl(libzfs_handle_t *hdl, importargs_t *iarg) } avl_destroy(cache); free(cache); - mutex_destroy(&lock); + pthread_mutex_destroy(&lock); ret = get_configs(hdl, &pools, iarg->can_be_active); |