Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Jeff Layton and committed by
Chuck Lever
7f221b34 7ffc7ade

+46 -28
+1
include/linux/sunrpc/svc.h
··· 442 442 bool svc_rqst_replace_page(struct svc_rqst *rqstp, 443 443 struct page *page); 444 444 void svc_rqst_release_pages(struct svc_rqst *rqstp); 445 + int svc_new_thread(struct svc_serv *serv, struct svc_pool *pool); 445 446 void svc_exit_thread(struct svc_rqst *); 446 447 struct svc_serv * svc_create_pooled(struct svc_program *prog, 447 448 unsigned int nprog,
+45 -28
net/sunrpc/svc.c
··· 763 763 } 764 764 EXPORT_SYMBOL_GPL(svc_pool_wake_idle_thread); 765 765 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) 768 777 { 769 778 struct svc_rqst *rqstp; 770 779 struct task_struct *task; 771 780 int node; 772 - int err; 781 + int err = 0; 773 782 774 - do { 775 - nrservs--; 776 - node = svc_pool_map_get_node(pool->sp_id); 783 + node = svc_pool_map_get_node(pool->sp_id); 777 784 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 - } 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 + } 787 794 788 - rqstp->rq_task = task; 789 - if (serv->sv_nrpools > 1) 790 - svc_pool_map_set_cpumask(task, pool->sp_id); 795 + rqstp->rq_task = task; 796 + if (serv->sv_nrpools > 1) 797 + svc_pool_map_set_cpumask(task, pool->sp_id); 791 798 792 - svc_sock_update_bufs(serv); 793 - wake_up_process(task); 799 + svc_sock_update_bufs(serv); 800 + wake_up_process(task); 794 801 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); 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); 802 811 803 - return 0; 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; 804 821 } 805 822 806 823 static int