Skip to content

Commit 7f221b3

Browse files
jtlaytonchucklever
authored andcommitted
sunrpc: split new thread creation into a separate function
Break out the part of svc_start_kthreads() that creates a thread into svc_new_thread(), as a new exported helper function. Signed-off-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
1 parent 7ffc7ad commit 7f221b3

2 files changed

Lines changed: 47 additions & 29 deletions

File tree

include/linux/sunrpc/svc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ struct svc_serv *svc_create(struct svc_program *, unsigned int,
442442
bool svc_rqst_replace_page(struct svc_rqst *rqstp,
443443
struct page *page);
444444
void svc_rqst_release_pages(struct svc_rqst *rqstp);
445+
int svc_new_thread(struct svc_serv *serv, struct svc_pool *pool);
445446
void svc_exit_thread(struct svc_rqst *);
446447
struct svc_serv * svc_create_pooled(struct svc_program *prog,
447448
unsigned int nprog,

net/sunrpc/svc.c

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -763,44 +763,61 @@ void svc_pool_wake_idle_thread(struct svc_pool *pool)
763763
}
764764
EXPORT_SYMBOL_GPL(svc_pool_wake_idle_thread);
765765

766-
static int
767-
svc_start_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
766+
/**
767+
* svc_new_thread - spawn a new thread in the given pool
768+
* @serv: the serv to which the pool belongs
769+
* @pool: pool in which thread should be spawned
770+
*
771+
* Create a new thread inside @pool, which is a part of @serv.
772+
* Caller must hold the service mutex.
773+
*
774+
* Returns 0 on success, or -errno on failure.
775+
*/
776+
int svc_new_thread(struct svc_serv *serv, struct svc_pool *pool)
768777
{
769778
struct svc_rqst *rqstp;
770779
struct task_struct *task;
771780
int node;
772-
int err;
781+
int err = 0;
773782

774-
do {
775-
nrservs--;
776-
node = svc_pool_map_get_node(pool->sp_id);
777-
778-
rqstp = svc_prepare_thread(serv, pool, node);
779-
if (!rqstp)
780-
return -ENOMEM;
781-
task = kthread_create_on_node(serv->sv_threadfn, rqstp,
782-
node, "%s", serv->sv_name);
783-
if (IS_ERR(task)) {
784-
svc_exit_thread(rqstp);
785-
return PTR_ERR(task);
786-
}
783+
node = svc_pool_map_get_node(pool->sp_id);
787784

788-
rqstp->rq_task = task;
789-
if (serv->sv_nrpools > 1)
790-
svc_pool_map_set_cpumask(task, pool->sp_id);
785+
rqstp = svc_prepare_thread(serv, pool, node);
786+
if (!rqstp)
787+
return -ENOMEM;
788+
task = kthread_create_on_node(serv->sv_threadfn, rqstp,
789+
node, "%s", serv->sv_name);
790+
if (IS_ERR(task)) {
791+
err = PTR_ERR(task);
792+
goto out;
793+
}
791794

792-
svc_sock_update_bufs(serv);
793-
wake_up_process(task);
795+
rqstp->rq_task = task;
796+
if (serv->sv_nrpools > 1)
797+
svc_pool_map_set_cpumask(task, pool->sp_id);
794798

795-
wait_var_event(&rqstp->rq_err, rqstp->rq_err != -EAGAIN);
796-
err = rqstp->rq_err;
797-
if (err) {
798-
svc_exit_thread(rqstp);
799-
return err;
800-
}
801-
} while (nrservs > 0);
799+
svc_sock_update_bufs(serv);
800+
wake_up_process(task);
802801

803-
return 0;
802+
/* Wait for the thread to signal initialization status */
803+
wait_var_event(&rqstp->rq_err, rqstp->rq_err != -EAGAIN);
804+
err = rqstp->rq_err;
805+
out:
806+
if (err)
807+
svc_exit_thread(rqstp);
808+
return err;
809+
}
810+
EXPORT_SYMBOL_GPL(svc_new_thread);
811+
812+
static int
813+
svc_start_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
814+
{
815+
int err = 0;
816+
817+
while (!err && nrservs--)
818+
err = svc_new_thread(serv, pool);
819+
820+
return err;
804821
}
805822

806823
static int

0 commit comments

Comments
 (0)