summaryrefslogtreecommitdiffstats
path: root/cmd/zpool
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 /cmd/zpool
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 'cmd/zpool')
-rw-r--r--cmd/zpool/Makefile.am7
-rw-r--r--cmd/zpool/zpool_iter.c28
-rw-r--r--cmd/zpool/zpool_main.c11
-rw-r--r--cmd/zpool/zpool_util.c26
-rw-r--r--cmd/zpool/zpool_util.h2
5 files changed, 40 insertions, 34 deletions
diff --git a/cmd/zpool/Makefile.am b/cmd/zpool/Makefile.am
index 6eff1d143..d7e1741c1 100644
--- a/cmd/zpool/Makefile.am
+++ b/cmd/zpool/Makefile.am
@@ -16,10 +16,9 @@ zpool_SOURCES = \
zpool_LDADD = \
$(top_builddir)/lib/libnvpair/libnvpair.la \
$(top_builddir)/lib/libuutil/libuutil.la \
- $(top_builddir)/lib/libzpool/libzpool.la \
- $(top_builddir)/lib/libzfs/libzfs.la \
- $(top_builddir)/lib/libzfs_core/libzfs_core.la \
- -lm $(LIBBLKID)
+ $(top_builddir)/lib/libzfs/libzfs.la
+
+zpool_LDADD += -lm $(LIBBLKID)
zpoolconfdir = $(sysconfdir)/zfs/zpool.d
zpoolexecdir = $(libexecdir)/zfs/zpool.d
diff --git a/cmd/zpool/zpool_iter.c b/cmd/zpool/zpool_iter.c
index e55c2f102..019f0b136 100644
--- a/cmd/zpool/zpool_iter.c
+++ b/cmd/zpool/zpool_iter.c
@@ -33,6 +33,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
+#include <thread_pool.h>
#include <libzfs.h>
#include <sys/zfs_context.h>
@@ -668,34 +669,21 @@ all_pools_for_each_vdev_gather_cb(zpool_handle_t *zhp, void *cb_vcdl)
static void
all_pools_for_each_vdev_run_vcdl(vdev_cmd_data_list_t *vcdl)
{
- taskq_t *t;
- int i;
- /* 5 * boot_ncpus selfishly chosen since it works best on LLNL's HW */
- int max_threads = 5 * boot_ncpus;
-
- /*
- * Under Linux we use a taskq to parallelize running a command
- * on each vdev. It is therefore necessary to initialize this
- * functionality for the duration of the threads.
- */
- thread_init();
+ tpool_t *t;
- t = taskq_create("z_pool_cmd", max_threads, defclsyspri, max_threads,
- INT_MAX, 0);
+ t = tpool_create(1, 5 * sysconf(_SC_NPROCESSORS_ONLN), 0, NULL);
if (t == NULL)
return;
/* Spawn off the command for each vdev */
- for (i = 0; i < vcdl->count; i++) {
- (void) taskq_dispatch(t, vdev_run_cmd_thread,
- (void *) &vcdl->data[i], TQ_SLEEP);
+ for (int i = 0; i < vcdl->count; i++) {
+ (void) tpool_dispatch(t, vdev_run_cmd_thread,
+ (void *) &vcdl->data[i]);
}
/* Wait for threads to finish */
- taskq_wait(t);
- taskq_destroy(t);
- thread_fini();
-
+ tpool_wait(t);
+ tpool_destroy(t);
}
/*
diff --git a/cmd/zpool/zpool_main.c b/cmd/zpool/zpool_main.c
index 338b9952c..60713197d 100644
--- a/cmd/zpool/zpool_main.c
+++ b/cmd/zpool/zpool_main.c
@@ -50,6 +50,7 @@
#include <zfs_prop.h>
#include <sys/fs/zfs.h>
#include <sys/stat.h>
+#include <sys/systeminfo.h>
#include <sys/fm/fs/zfs.h>
#include <sys/fm/util.h>
#include <sys/fm/protocol.h>
@@ -2645,15 +2646,7 @@ zpool_do_import(int argc, char **argv)
idata.cachefile = cachefile;
idata.scan = do_scan;
- /*
- * Under Linux the zpool_find_import_impl() function leverages the
- * taskq implementation to parallelize device scanning. It is
- * therefore necessary to initialize this functionality for the
- * duration of the zpool_search_import() function.
- */
- thread_init();
pools = zpool_search_import(g_zfs, &idata);
- thread_fini();
if (pools != NULL && idata.exists &&
(argc == 1 || strcmp(argv[0], argv[1]) == 0)) {
@@ -7968,8 +7961,6 @@ main(int argc, char **argv)
(void) textdomain(TEXT_DOMAIN);
srand(time(NULL));
- dprintf_setup(&argc, argv);
-
opterr = 0;
/*
diff --git a/cmd/zpool/zpool_util.c b/cmd/zpool/zpool_util.c
index 43abfa23b..c26c0eb39 100644
--- a/cmd/zpool/zpool_util.c
+++ b/cmd/zpool/zpool_util.c
@@ -111,3 +111,29 @@ isnumber(char *str)
return (1);
}
+
+/*
+ * Find highest one bit set.
+ * Returns bit number + 1 of highest bit that is set, otherwise returns 0.
+ */
+int
+highbit64(uint64_t i)
+{
+ if (i == 0)
+ return (0);
+
+ return (NBBY * sizeof (uint64_t) - __builtin_clzll(i));
+}
+
+/*
+ * Find lowest one bit set.
+ * Returns bit number + 1 of lowest bit that is set, otherwise returns 0.
+ */
+int
+lowbit64(uint64_t i)
+{
+ if (i == 0)
+ return (0);
+
+ return (__builtin_ffsll(i));
+}
diff --git a/cmd/zpool/zpool_util.h b/cmd/zpool/zpool_util.h
index aef2cff27..3afc82d54 100644
--- a/cmd/zpool/zpool_util.h
+++ b/cmd/zpool/zpool_util.h
@@ -43,6 +43,8 @@ void zpool_no_memory(void);
uint_t num_logs(nvlist_t *nv);
uint64_t array64_max(uint64_t array[], unsigned int len);
int isnumber(char *str);
+int highbit64(uint64_t i);
+int lowbit64(uint64_t i);
/*
* Misc utility functions