Skip to content

Commit c524df8

Browse files
committed
zfs: replace tpool with taskq
They're basically the same thing; lets just carry one. Sponsored-by: https://despairlabs.com/sponsor/ Signed-off-by: Rob Norris <[email protected]>
1 parent c60cf94 commit c524df8

File tree

16 files changed

+60
-834
lines changed

16 files changed

+60
-834
lines changed

cmd/zed/agents/zfs_mod.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
#include <sys/sunddi.h>
8383
#include <sys/sysevent/eventdefs.h>
8484
#include <sys/sysevent/dev.h>
85-
#include <thread_pool.h>
85+
#include <sys/taskq.h>
8686
#include <pthread.h>
8787
#include <unistd.h>
8888
#include <errno.h>
@@ -98,7 +98,7 @@ typedef void (*zfs_process_func_t)(zpool_handle_t *, nvlist_t *, boolean_t);
9898
libzfs_handle_t *g_zfshdl;
9999
list_t g_pool_list; /* list of unavailable pools at initialization */
100100
list_t g_device_list; /* list of disks with asynchronous label request */
101-
tpool_t *g_tpool;
101+
taskq_t *g_taskq;
102102
boolean_t g_enumeration_done;
103103
pthread_t g_zfs_tid; /* zfs_enum_pools() thread */
104104

@@ -749,8 +749,8 @@ zfs_iter_pool(zpool_handle_t *zhp, void *data)
749749
continue;
750750
if (zfs_toplevel_state(zhp) >= VDEV_STATE_DEGRADED) {
751751
list_remove(&g_pool_list, pool);
752-
(void) tpool_dispatch(g_tpool, zfs_enable_ds,
753-
pool);
752+
(void) taskq_dispatch(g_taskq, zfs_enable_ds,
753+
pool, TQ_SLEEP);
754754
break;
755755
}
756756
}
@@ -1347,9 +1347,9 @@ zfs_slm_fini(void)
13471347
/* wait for zfs_enum_pools thread to complete */
13481348
(void) pthread_join(g_zfs_tid, NULL);
13491349
/* destroy the thread pool */
1350-
if (g_tpool != NULL) {
1351-
tpool_wait(g_tpool);
1352-
tpool_destroy(g_tpool);
1350+
if (g_taskq != NULL) {
1351+
taskq_wait(g_taskq);
1352+
taskq_destroy(g_taskq);
13531353
}
13541354

13551355
while ((pool = list_remove_head(&g_pool_list)) != NULL) {

cmd/zpool/zpool_iter.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#include <stdio.h>
3535
#include <stdlib.h>
3636
#include <string.h>
37-
#include <thread_pool.h>
3837

3938
#include <libzfs.h>
4039
#include <libzutil.h>
@@ -653,21 +652,21 @@ all_pools_for_each_vdev_gather_cb(zpool_handle_t *zhp, void *cb_vcdl)
653652
static void
654653
all_pools_for_each_vdev_run_vcdl(vdev_cmd_data_list_t *vcdl)
655654
{
656-
tpool_t *t;
657-
658-
t = tpool_create(1, 5 * sysconf(_SC_NPROCESSORS_ONLN), 0, NULL);
659-
if (t == NULL)
655+
taskq_t *tq = taskq_create("vdev_run_cmd",
656+
5 * sysconf(_SC_NPROCESSORS_ONLN), minclsyspri, 1, INT_MAX,
657+
TASKQ_DYNAMIC);
658+
if (tq == NULL)
660659
return;
661660

662661
/* Spawn off the command for each vdev */
663662
for (int i = 0; i < vcdl->count; i++) {
664-
(void) tpool_dispatch(t, vdev_run_cmd_thread,
665-
(void *) &vcdl->data[i]);
663+
(void) taskq_dispatch(tq, vdev_run_cmd_thread,
664+
(void *) &vcdl->data[i], TQ_SLEEP);
666665
}
667666

668667
/* Wait for threads to finish */
669-
tpool_wait(t);
670-
tpool_destroy(t);
668+
taskq_wait(tq);
669+
taskq_destroy(tq);
671670
}
672671

673672
/*

cmd/zpool/zpool_main.c

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
#include <stdlib.h>
5353
#include <string.h>
5454
#include <termios.h>
55-
#include <thread_pool.h>
5655
#include <time.h>
5756
#include <unistd.h>
5857
#include <pwd.h>
@@ -2389,7 +2388,7 @@ zpool_do_destroy(int argc, char **argv)
23892388
}
23902389

23912390
typedef struct export_cbdata {
2392-
tpool_t *tpool;
2391+
taskq_t *taskq;
23932392
pthread_mutex_t mnttab_lock;
23942393
boolean_t force;
23952394
boolean_t hardforce;
@@ -2414,12 +2413,12 @@ zpool_export_one(zpool_handle_t *zhp, void *data)
24142413
* zpool_disable_datasets() is not thread-safe for mnttab access.
24152414
* So we serialize access here for 'zpool export -a' parallel case.
24162415
*/
2417-
if (cb->tpool != NULL)
2416+
if (cb->taskq != NULL)
24182417
(void) pthread_mutex_lock(&cb->mnttab_lock);
24192418

24202419
int retval = zpool_disable_datasets(zhp, cb->force);
24212420

2422-
if (cb->tpool != NULL)
2421+
if (cb->taskq != NULL)
24232422
(void) pthread_mutex_unlock(&cb->mnttab_lock);
24242423

24252424
if (retval)
@@ -2463,15 +2462,16 @@ zpool_export_task(void *arg)
24632462
static int
24642463
zpool_export_one_async(zpool_handle_t *zhp, void *data)
24652464
{
2466-
tpool_t *tpool = ((export_cbdata_t *)data)->tpool;
2465+
taskq_t *tq = ((export_cbdata_t *)data)->taskq;
24672466
async_export_args_t *aea = safe_malloc(sizeof (async_export_args_t));
24682467

24692468
/* save pool name since zhp will go out of scope */
24702469
aea->aea_poolname = strdup(zpool_get_name(zhp));
24712470
aea->aea_cbdata = data;
24722471

24732472
/* ship off actual export to another thread */
2474-
if (tpool_dispatch(tpool, zpool_export_task, (void *)aea) != 0)
2473+
if (taskq_dispatch(tq, zpool_export_task, (void *)aea,
2474+
TQ_SLEEP) == TASKQID_INVALID)
24752475
return (errno); /* unlikely */
24762476
else
24772477
return (0);
@@ -2517,7 +2517,7 @@ zpool_do_export(int argc, char **argv)
25172517

25182518
cb.force = force;
25192519
cb.hardforce = hardforce;
2520-
cb.tpool = NULL;
2520+
cb.taskq = NULL;
25212521
cb.retval = 0;
25222522
argc -= optind;
25232523
argv += optind;
@@ -2531,16 +2531,17 @@ zpool_do_export(int argc, char **argv)
25312531
usage(B_FALSE);
25322532
}
25332533

2534-
cb.tpool = tpool_create(1, 5 * sysconf(_SC_NPROCESSORS_ONLN),
2535-
0, NULL);
2534+
cb.taskq = taskq_create("zpool_export",
2535+
5 * sysconf(_SC_NPROCESSORS_ONLN), minclsyspri, 1, INT_MAX,
2536+
TASKQ_DYNAMIC);
25362537
(void) pthread_mutex_init(&cb.mnttab_lock, NULL);
25372538

25382539
/* Asynchronously call zpool_export_one using thread pool */
25392540
ret = for_each_pool(argc, argv, B_TRUE, NULL, ZFS_TYPE_POOL,
25402541
B_FALSE, zpool_export_one_async, &cb);
25412542

2542-
tpool_wait(cb.tpool);
2543-
tpool_destroy(cb.tpool);
2543+
taskq_wait(cb.taskq);
2544+
taskq_destroy(cb.taskq);
25442545
(void) pthread_mutex_destroy(&cb.mnttab_lock);
25452546

25462547
return (ret | cb.retval);
@@ -3945,10 +3946,11 @@ import_pools(nvlist_t *pools, nvlist_t *props, char *mntopts, int flags,
39453946
uint_t npools = 0;
39463947

39473948

3948-
tpool_t *tp = NULL;
3949+
taskq_t *tq = NULL;
39493950
if (import->do_all) {
3950-
tp = tpool_create(1, 5 * sysconf(_SC_NPROCESSORS_ONLN),
3951-
0, NULL);
3951+
tq = taskq_create("zpool_import_all",
3952+
5 * sysconf(_SC_NPROCESSORS_ONLN), minclsyspri, 1, INT_MAX,
3953+
TASKQ_DYNAMIC);
39523954
}
39533955

39543956
/*
@@ -3997,8 +3999,8 @@ import_pools(nvlist_t *pools, nvlist_t *props, char *mntopts, int flags,
39973999
ip->ip_mntthreads = mount_tp_nthr / npools;
39984000
ip->ip_err = &err;
39994001

4000-
(void) tpool_dispatch(tp, do_import_task,
4001-
(void *)ip);
4002+
(void) taskq_dispatch(tq, do_import_task,
4003+
(void *)ip, TQ_SLEEP);
40024004
} else {
40034005
/*
40044006
* If we're importing from cachefile, then
@@ -4047,8 +4049,8 @@ import_pools(nvlist_t *pools, nvlist_t *props, char *mntopts, int flags,
40474049
}
40484050
}
40494051
if (import->do_all) {
4050-
tpool_wait(tp);
4051-
tpool_destroy(tp);
4052+
taskq_wait(tq);
4053+
taskq_destroy(tq);
40524054
}
40534055

40544056
/*

include/Makefile.am

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,7 @@ USER_H = \
189189
libzfs_core.h \
190190
libzfsbootenv.h \
191191
libzpool.h \
192-
libzutil.h \
193-
thread_pool.h
192+
libzutil.h
194193

195194

196195
if CONFIG_USER

include/thread_pool.h

Lines changed: 0 additions & 56 deletions
This file was deleted.

lib/Makefile.am

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
# libunicode --/ \ / \ \-------\ \
2525
# \ / \ \ |
2626
# libzutil libzfs_core* | |
27-
# | | | | \ | | | |
28-
# | | | | | | | | |
29-
# | | | | | | | | |
30-
# libtpool -------------/ | | | \---- libnvpair* | | |
27+
# | | | \ | | | |
28+
# | | | | | | | |
29+
# | | | | | | | |
30+
# | | | \---- libnvpair* | | |
3131
# | | | | | |
3232
# libefi -----------------/ | \------ libavl* --------/ |
3333
# | | |
@@ -58,7 +58,6 @@ include $(srcdir)/%D%/libicp/Makefile.am
5858
include $(srcdir)/%D%/libnvpair/Makefile.am
5959
include $(srcdir)/%D%/libshare/Makefile.am
6060
include $(srcdir)/%D%/libspl/Makefile.am
61-
include $(srcdir)/%D%/libtpool/Makefile.am
6261
include $(srcdir)/%D%/libunicode/Makefile.am
6362
include $(srcdir)/%D%/libzdb/Makefile.am
6463
include $(srcdir)/%D%/libzfs_core/Makefile.am

lib/libspl/include/sys/taskq.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131

3232
#include <pthread.h>
3333
#include <stdint.h>
34+
#include <sys/kmem.h>
35+
#include <sys/thread.h>
3436
#include <sys/mutex.h>
3537
#include <sys/rwlock.h>
3638
#include <sys/condvar.h>

lib/libtpool/Makefile.am

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)