]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
sunrpc: split new thread creation into a separate function
authorJeff Layton <jlayton@kernel.org>
Tue, 6 Jan 2026 18:59:47 +0000 (13:59 -0500)
committerChuck Lever <chuck.lever@oracle.com>
Wed, 28 Jan 2026 15:15:42 +0000 (10:15 -0500)
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>
include/linux/sunrpc/svc.h
net/sunrpc/svc.c

index 8fd511d02f3b36a614db5595c3b88afe9fce92a2..b55ed8404a9e9863cecfe1f29d79fcc426d6f31c 100644 (file)
@@ -442,6 +442,7 @@ struct svc_serv *svc_create(struct svc_program *, unsigned int,
 bool              svc_rqst_replace_page(struct svc_rqst *rqstp,
                                         struct page *page);
 void              svc_rqst_release_pages(struct svc_rqst *rqstp);
+int               svc_new_thread(struct svc_serv *serv, struct svc_pool *pool);
 void              svc_exit_thread(struct svc_rqst *);
 struct svc_serv *  svc_create_pooled(struct svc_program *prog,
                                     unsigned int nprog,
index 92bad06755efdfb83fbac42d35ecb95a917b054e..346ac560dcc2fa7d6d073d202f79b141acf4adc2 100644 (file)
@@ -763,44 +763,61 @@ void svc_pool_wake_idle_thread(struct svc_pool *pool)
 }
 EXPORT_SYMBOL_GPL(svc_pool_wake_idle_thread);
 
-static int
-svc_start_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
+/**
+ * svc_new_thread - spawn a new thread in the given pool
+ * @serv: the serv to which the pool belongs
+ * @pool: pool in which thread should be spawned
+ *
+ * Create a new thread inside @pool, which is a part of @serv.
+ * Caller must hold the service mutex.
+ *
+ * Returns 0 on success, or -errno on failure.
+ */
+int svc_new_thread(struct svc_serv *serv, struct svc_pool *pool)
 {
        struct svc_rqst *rqstp;
        struct task_struct *task;
        int node;
-       int err;
+       int err = 0;
 
-       do {
-               nrservs--;
-               node = svc_pool_map_get_node(pool->sp_id);
-
-               rqstp = svc_prepare_thread(serv, pool, node);
-               if (!rqstp)
-                       return -ENOMEM;
-               task = kthread_create_on_node(serv->sv_threadfn, rqstp,
-                                             node, "%s", serv->sv_name);
-               if (IS_ERR(task)) {
-                       svc_exit_thread(rqstp);
-                       return PTR_ERR(task);
-               }
+       node = svc_pool_map_get_node(pool->sp_id);
 
-               rqstp->rq_task = task;
-               if (serv->sv_nrpools > 1)
-                       svc_pool_map_set_cpumask(task, pool->sp_id);
+       rqstp = svc_prepare_thread(serv, pool, node);
+       if (!rqstp)
+               return -ENOMEM;
+       task = kthread_create_on_node(serv->sv_threadfn, rqstp,
+                                     node, "%s", serv->sv_name);
+       if (IS_ERR(task)) {
+               err = PTR_ERR(task);
+               goto out;
+       }
 
-               svc_sock_update_bufs(serv);
-               wake_up_process(task);
+       rqstp->rq_task = task;
+       if (serv->sv_nrpools > 1)
+               svc_pool_map_set_cpumask(task, pool->sp_id);
 
-               wait_var_event(&rqstp->rq_err, rqstp->rq_err != -EAGAIN);
-               err = rqstp->rq_err;
-               if (err) {
-                       svc_exit_thread(rqstp);
-                       return err;
-               }
-       } while (nrservs > 0);
+       svc_sock_update_bufs(serv);
+       wake_up_process(task);
 
-       return 0;
+       /* Wait for the thread to signal initialization status */
+       wait_var_event(&rqstp->rq_err, rqstp->rq_err != -EAGAIN);
+       err = rqstp->rq_err;
+out:
+       if (err)
+               svc_exit_thread(rqstp);
+       return err;
+}
+EXPORT_SYMBOL_GPL(svc_new_thread);
+
+static int
+svc_start_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
+{
+       int err = 0;
+
+       while (!err && nrservs--)
+               err = svc_new_thread(serv, pool);
+
+       return err;
 }
 
 static int