aboutsummaryrefslogtreecommitdiffstats
path: root/lib/libzfs
diff options
context:
space:
mode:
authorBrian Behlendorf <[email protected]>2017-08-09 15:31:08 -0700
committerGitHub <[email protected]>2017-08-09 15:31:08 -0700
commit46364cb2f35545a7fc915df9593b719a94c43a83 (patch)
tree0fb11534892c2aaaa1c1bda3c10914e718827eb0 /lib/libzfs
parent5146d802b4e371cab1d6db79bea482c056be7bf2 (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')
-rw-r--r--lib/libzfs/Makefile.am32
-rw-r--r--lib/libzfs/libzfs_import.c45
-rw-r--r--lib/libzfs/libzfs_pool.c1
-rw-r--r--lib/libzfs/libzfs_status.c1
4 files changed, 52 insertions, 27 deletions
diff --git a/lib/libzfs/Makefile.am b/lib/libzfs/Makefile.am
index f1260ea71..7ab8658e4 100644
--- a/lib/libzfs/Makefile.am
+++ b/lib/libzfs/Makefile.am
@@ -1,10 +1,16 @@
include $(top_srcdir)/config/Rules.am
+VPATH = \
+ $(top_srcdir)/module/icp \
+ $(top_srcdir)/module/zcommon \
+ $(top_srcdir)/lib/libzfs
+
libzfs_pcdir = $(datarootdir)/pkgconfig
libzfs_pc_DATA = libzfs.pc libzfs_core.pc
DEFAULT_INCLUDES += \
-I$(top_srcdir)/include \
+ -I$(top_srcdir)/module/icp/include \
-I$(top_srcdir)/lib/libspl/include
lib_LTLIBRARIES = libzfs.la
@@ -23,17 +29,35 @@ USER_C = \
libzfs_status.c \
libzfs_util.c
-KERNEL_C =
+KERNEL_C = \
+ algs/sha2/sha2.c \
+ zfeature_common.c \
+ zfs_comutil.c \
+ zfs_deleg.c \
+ zfs_fletcher.c \
+ zfs_fletcher_aarch64_neon.c \
+ zfs_fletcher_avx512.c \
+ zfs_fletcher_intel.c \
+ zfs_fletcher_sse.c \
+ zfs_fletcher_superscalar.c \
+ zfs_fletcher_superscalar4.c \
+ zfs_namecheck.c \
+ zfs_prop.c \
+ zfs_uio.c \
+ zpool_prop.c \
+ zprop_common.c
nodist_libzfs_la_SOURCES = \
$(USER_C) \
$(KERNEL_C)
libzfs_la_LIBADD = \
- $(top_builddir)/lib/libzfs_core/libzfs_core.la \
- $(top_builddir)/lib/libshare/libshare.la \
+ $(top_builddir)/lib/libefi/libefi.la \
$(top_builddir)/lib/libnvpair/libnvpair.la \
- $(top_builddir)/lib/libzpool/libzpool.la
+ $(top_builddir)/lib/libshare/libshare.la \
+ $(top_builddir)/lib/libtpool/libtpool.la \
+ $(top_builddir)/lib/libuutil/libuutil.la \
+ $(top_builddir)/lib/libzfs_core/libzfs_core.la
libzfs_la_LIBADD += -lm $(LIBBLKID) $(LIBUDEV)
libzfs_la_LDFLAGS = -version-info 2:0:0
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);
diff --git a/lib/libzfs/libzfs_pool.c b/lib/libzfs/libzfs_pool.c
index 73af75f9d..d3363809d 100644
--- a/lib/libzfs/libzfs_pool.c
+++ b/lib/libzfs/libzfs_pool.c
@@ -40,6 +40,7 @@
#include <zone.h>
#include <sys/stat.h>
#include <sys/efi_partition.h>
+#include <sys/systeminfo.h>
#include <sys/vtoc.h>
#include <sys/zfs_ioctl.h>
#include <dlfcn.h>
diff --git a/lib/libzfs/libzfs_status.c b/lib/libzfs/libzfs_status.c
index 05a9afce8..ccc472153 100644
--- a/lib/libzfs/libzfs_status.c
+++ b/lib/libzfs/libzfs_status.c
@@ -44,6 +44,7 @@
#include <libzfs.h>
#include <string.h>
#include <unistd.h>
+#include <sys/systeminfo.h>
#include "libzfs_impl.h"
#include "zfeature_common.h"