From: Dhaval Giani Date: Wed, 26 Jul 2017 17:17:45 +0000 (-0400) Subject: Revert "SUNRPC: Refactor svc_set_num_threads()" X-Git-Tag: v4.1.12-107.0.20170801_2000~18 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=d48afa94fca4563d07f555b2c1fd27f2855c6168;p=users%2Fjedix%2Flinux-maple.git Revert "SUNRPC: Refactor svc_set_num_threads()" This reverts commit 0bc9402329824ae06d8a26a73b60d21cdac3e6f2. Orabug: 26479081 Signed-off-by: Dhaval Giani Reviewed-by: Brian Maly --- diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c index ec97d7985859..7d5530c9102c 100644 --- a/net/sunrpc/svc.c +++ b/net/sunrpc/svc.c @@ -694,32 +694,59 @@ found_pool: return task; } -/* create new threads */ -static int -svc_start_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs) +/* + * Create or destroy enough new threads to make the number + * of threads the given number. If `pool' is non-NULL, applies + * only to threads in that pool, otherwise round-robins between + * all pools. Caller must ensure that mutual exclusion between this and + * server startup or shutdown. + * + * Destroying threads relies on the service threads filling in + * rqstp->rq_task, which only the nfs ones do. Assumes the serv + * has been created using svc_create_pooled(). + * + * Based on code that used to be in nfsd_svc() but tweaked + * to be pool-aware. + */ +int +svc_set_num_threads(struct svc_serv *serv, struct svc_pool *pool, int nrservs) { struct svc_rqst *rqstp; struct task_struct *task; struct svc_pool *chosen_pool; + int error = 0; unsigned int state = serv->sv_nrthreads-1; int node; - do { + if (pool == NULL) { + /* The -1 assumes caller has done a svc_get() */ + nrservs -= (serv->sv_nrthreads-1); + } else { + spin_lock_bh(&pool->sp_lock); + nrservs -= pool->sp_nrthreads; + spin_unlock_bh(&pool->sp_lock); + } + + /* create new threads */ + while (nrservs > 0) { nrservs--; chosen_pool = choose_pool(serv, pool, &state); node = svc_pool_map_get_node(chosen_pool->sp_id); rqstp = svc_prepare_thread(serv, chosen_pool, node); - if (IS_ERR(rqstp)) - return PTR_ERR(rqstp); + if (IS_ERR(rqstp)) { + error = PTR_ERR(rqstp); + break; + } __module_get(serv->sv_module); task = kthread_create_on_node(serv->sv_function, rqstp, node, "%s", serv->sv_name); if (IS_ERR(task)) { + error = PTR_ERR(task); module_put(serv->sv_module); svc_exit_thread(rqstp); - return PTR_ERR(task); + break; } rqstp->rq_task = task; @@ -728,62 +755,15 @@ svc_start_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs) svc_sock_update_bufs(serv); wake_up_process(task); - } while (nrservs > 0); - - return 0; -} - - -/* destroy old threads */ -static int -svc_signal_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs) -{ - struct task_struct *task; - unsigned int state = serv->sv_nrthreads-1; - + } /* destroy old threads */ - do { - task = choose_victim(serv, pool, &state); - if (task == NULL) - break; + while (nrservs < 0 && + (task = choose_victim(serv, pool, &state)) != NULL) { send_sig(SIGINT, task, 1); nrservs++; - } while (nrservs < 0); - - return 0; -} - -/* - * Create or destroy enough new threads to make the number - * of threads the given number. If `pool' is non-NULL, applies - * only to threads in that pool, otherwise round-robins between - * all pools. Caller must ensure that mutual exclusion between this and - * server startup or shutdown. - * - * Destroying threads relies on the service threads filling in - * rqstp->rq_task, which only the nfs ones do. Assumes the serv - * has been created using svc_create_pooled(). - * - * Based on code that used to be in nfsd_svc() but tweaked - * to be pool-aware. - */ -int -svc_set_num_threads(struct svc_serv *serv, struct svc_pool *pool, int nrservs) -{ - if (pool == NULL) { - /* The -1 assumes caller has done a svc_get() */ - nrservs -= (serv->sv_nrthreads-1); - } else { - spin_lock_bh(&pool->sp_lock); - nrservs -= pool->sp_nrthreads; - spin_unlock_bh(&pool->sp_lock); } - if (nrservs > 0) - return svc_start_kthreads(serv, pool, nrservs); - if (nrservs < 0) - return svc_signal_kthreads(serv, pool, nrservs); - return 0; + return error; } EXPORT_SYMBOL_GPL(svc_set_num_threads);