fixup error handling in taskqueue_start_threads: check for kthread_create
failing, print a message when we fail for some reason as most callers do not check the return value (e.g. 'cuz they're called from SYSINIT) Reviewed by: scottl MFC after: 1 week
This commit is contained in:
parent
017427c851
commit
a2a6bebf93
@ -316,31 +316,40 @@ taskqueue_start_threads(struct taskqueue **tqp, int count, int pri,
|
|||||||
va_list ap;
|
va_list ap;
|
||||||
struct taskqueue *tq;
|
struct taskqueue *tq;
|
||||||
char ktname[MAXCOMLEN];
|
char ktname[MAXCOMLEN];
|
||||||
int i;
|
int i, error;
|
||||||
|
|
||||||
if (count <= 0)
|
if (count <= 0)
|
||||||
return (EINVAL);
|
return (EINVAL);
|
||||||
tq = *tqp;
|
tq = *tqp;
|
||||||
|
|
||||||
if ((tq->tq_pproc = malloc(sizeof(struct proc *) * count, M_TASKQUEUE,
|
|
||||||
M_NOWAIT | M_ZERO)) == NULL)
|
|
||||||
return (ENOMEM);
|
|
||||||
|
|
||||||
va_start(ap, name);
|
va_start(ap, name);
|
||||||
vsnprintf(ktname, MAXCOMLEN, name, ap);
|
vsnprintf(ktname, MAXCOMLEN, name, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
|
tq->tq_pproc = malloc(sizeof(struct proc *) * count, M_TASKQUEUE,
|
||||||
|
M_NOWAIT | M_ZERO);
|
||||||
|
if (tq->tq_pproc == NULL) {
|
||||||
|
printf("%s: no memory for %s threads\n", __func__, ktname);
|
||||||
|
return (ENOMEM);
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
if (count == 1)
|
if (count == 1)
|
||||||
kthread_create(taskqueue_thread_loop, tqp,
|
error = kthread_create(taskqueue_thread_loop, tqp,
|
||||||
&tq->tq_pproc[i], 0, 0, ktname);
|
&tq->tq_pproc[i], 0, 0, ktname);
|
||||||
else
|
else
|
||||||
kthread_create(taskqueue_thread_loop, tqp,
|
error = kthread_create(taskqueue_thread_loop, tqp,
|
||||||
&tq->tq_pproc[i], 0, 0, "%s_%d", ktname, i);
|
&tq->tq_pproc[i], 0, 0, "%s_%d", ktname, i);
|
||||||
mtx_lock_spin(&sched_lock);
|
if (error == 0) {
|
||||||
sched_prio(FIRST_THREAD_IN_PROC(tq->tq_pproc[i]), pri);
|
mtx_lock_spin(&sched_lock);
|
||||||
mtx_unlock_spin(&sched_lock);
|
sched_prio(FIRST_THREAD_IN_PROC(tq->tq_pproc[i]), pri);
|
||||||
tq->tq_pcount++;
|
mtx_unlock_spin(&sched_lock);
|
||||||
|
tq->tq_pcount++;
|
||||||
|
} else {
|
||||||
|
/* should be ok to continue, taskqueue_free will dtrt */
|
||||||
|
printf("%s: kthread_create(%s): error %d",
|
||||||
|
__func__, ktname, error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
|
Loading…
Reference in New Issue
Block a user