]> git.proxmox.com Git - mirror_spl-debian.git/blame - modules/spl/spl-taskq.c
- Remapped ldi_handle_t to struct block_device * which is much more useful
[mirror_spl-debian.git] / modules / spl / spl-taskq.c
CommitLineData
f4b37741 1#include <sys/taskq.h>
f1ca4da6 2
3/*
4 * Task queue interface
5 *
6 * The taskq_work_wrapper functions are used to manage the work_structs
7 * which must be submitted to linux. The shim layer allocates a wrapper
8 * structure for all items which contains a pointer to itself as well as
9 * the real work to be performed. When the work item run the generic
10 * handle is called which calls the real work function and then using
11 * the self pointer frees the work_struct.
12 */
13typedef struct taskq_work_wrapper {
14 struct work_struct tww_work;
15 task_func_t tww_func;
16 void * tww_priv;
17} taskq_work_wrapper_t;
18
19static void
20taskq_work_handler(void *priv)
21{
22 taskq_work_wrapper_t *tww = priv;
23
24 BUG_ON(tww == NULL);
25 BUG_ON(tww->tww_func == NULL);
26
27 /* Call the real function and free the wrapper */
28 tww->tww_func(tww->tww_priv);
29 kfree(tww);
30}
31
32/* XXX - All flags currently ignored */
33taskqid_t
34__taskq_dispatch(taskq_t *tq, task_func_t func, void *priv, uint_t flags)
35{
36 struct workqueue_struct *wq = tq;
37 taskq_work_wrapper_t *tww;
38 int rc;
39
f1ca4da6 40 BUG_ON(tq == NULL);
41 BUG_ON(func == NULL);
42
0a6fd143 43 /* Use GFP_ATOMIC since this may be called in interrupt context */
44 tww = (taskq_work_wrapper_t *)kmalloc(sizeof(*tww), GFP_ATOMIC);
f1ca4da6 45 if (!tww)
46 return (taskqid_t)0;
47
48 INIT_WORK(&(tww->tww_work), taskq_work_handler, tww);
49 tww->tww_func = func;
50 tww->tww_priv = priv;
51
52 rc = queue_work(wq, &(tww->tww_work));
53 if (!rc) {
54 kfree(tww);
55 return (taskqid_t)0;
56 }
57
58 return (taskqid_t)wq;
59}
f1b59d26 60EXPORT_SYMBOL(__taskq_dispatch);
f1ca4da6 61
62/* XXX - Most args ignored until we decide if it's worth the effort
63 * to emulate the solaris notion of dynamic thread pools. For
64 * now we simply serialize everything through one thread which
65 * may come back to bite us as a performance issue.
66 * pri - Ignore priority
67 * min - Ignored until this is a dynamic thread pool
68 * max - Ignored until this is a dynamic thread pool
69 * flags - Ignored until this is a dynamic thread_pool
70 */
71taskq_t *
72__taskq_create(const char *name, int nthreads, pri_t pri,
73 int minalloc, int maxalloc, uint_t flags)
74{
f1b59d26 75 /* NOTE: Linux workqueue names are limited to 10 chars */
f1ca4da6 76
77 return create_singlethread_workqueue(name);
78}
f1b59d26 79EXPORT_SYMBOL(__taskq_create);
b123971f 80
81void
82__taskq_destroy(taskq_t *tq)
83{
84 destroy_workqueue(tq);
85}
86EXPORT_SYMBOL(__taskq_destroy);
87
88void
89__taskq_wait(taskq_t *tq)
90{
91 flush_workqueue(tq);
92}
93EXPORT_SYMBOL(__taskq_wait);