Support post-3.13 kthread_create() semantics.

Provide spl_kthread_create() as a wrapper to the kernel's kthread_create()
to provide pre-3.13 semantics.  Re-try if the call is interrupted or if it
would have returned -ENOMEM.  Otherwise return NULL.

Signed-off-by: Chunwei Chen <tuxoko@gmail.com>
Signed-off-by: Tim Chase <tim@chase2k.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #339
This commit is contained in:
Tim Chase
2014-03-26 08:29:24 -05:00
committed by Brian Behlendorf
parent e19101e08f
commit 17a527cb0f
6 changed files with 38 additions and 9 deletions
+28
View File
@@ -60,4 +60,32 @@ extern kthread_t *__thread_create(caddr_t stk, size_t stksize,
int state, pri_t pri);
extern void __thread_exit(void);
/*
* spl_kthread_create - Wrapper providing pre-3.13 semantics for
* kthread_create() in which it is not killable and less likely
* to return -ENOMEM.
*/
static inline struct task_struct *
spl_kthread_create(int (*func)(void *), void *data, const char namefmt[], ...)
{
struct task_struct *tsk;
va_list args;
va_start(args, namefmt);
do {
tsk = kthread_create_on_node(func, data,
-1, namefmt, args);
if (IS_ERR(tsk)) {
if (signal_pending(current)) {
clear_thread_flag(TIF_SIGPENDING);
continue;
}
if (PTR_ERR(tsk) == -ENOMEM)
continue;
return (NULL);
} else
return (tsk);
} while (1);
}
#endif /* _SPL_THREAD_H */