Skip to content

Commit 6b044fb

Browse files
neilbrownchucklever
authored andcommitted
lockd: use svc_set_num_threads() for thread start and stop
svc_set_num_threads() does everything that lockd_start_svc() does, except set sv_maxconn. It also (when passed 0) finds the threads and stops them with kthread_stop(). So move the setting for sv_maxconn, and use svc_set_num_thread() We now don't need nlmsvc_task. Now that we use svc_set_num_threads() it makes sense to set svo_module. This request that the thread exists with module_put_and_exit(). Also fix the documentation for svo_module to make this explicit. svc_prepare_thread is now only used where it is defined, so it can be made static. Signed-off-by: NeilBrown <neilb@suse.de> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
1 parent 93aa619 commit 6b044fb

3 files changed

Lines changed: 12 additions & 55 deletions

File tree

fs/lockd/svc.c

Lines changed: 8 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ EXPORT_SYMBOL_GPL(nlmsvc_ops);
5555
static DEFINE_MUTEX(nlmsvc_mutex);
5656
static unsigned int nlmsvc_users;
5757
static struct svc_serv *nlmsvc_serv;
58-
static struct task_struct *nlmsvc_task;
5958
unsigned long nlmsvc_timeout;
6059

6160
unsigned int lockd_net_id;
@@ -186,7 +185,7 @@ lockd(void *vrqstp)
186185

187186
svc_exit_thread(rqstp);
188187

189-
return 0;
188+
module_put_and_exit(0);
190189
}
191190

192191
static int create_lockd_listener(struct svc_serv *serv, const char *name,
@@ -292,8 +291,8 @@ static void lockd_down_net(struct svc_serv *serv, struct net *net)
292291
__func__, net->ns.inum);
293292
}
294293
} else {
295-
pr_err("%s: no users! task=%p, net=%x\n",
296-
__func__, nlmsvc_task, net->ns.inum);
294+
pr_err("%s: no users! net=%x\n",
295+
__func__, net->ns.inum);
297296
BUG();
298297
}
299298
}
@@ -351,49 +350,11 @@ static struct notifier_block lockd_inet6addr_notifier = {
351350
};
352351
#endif
353352

354-
static int lockd_start_svc(struct svc_serv *serv)
355-
{
356-
int error;
357-
struct svc_rqst *rqst;
358-
359-
/*
360-
* Create the kernel thread and wait for it to start.
361-
*/
362-
rqst = svc_prepare_thread(serv, &serv->sv_pools[0], NUMA_NO_NODE);
363-
if (IS_ERR(rqst)) {
364-
error = PTR_ERR(rqst);
365-
printk(KERN_WARNING
366-
"lockd_up: svc_rqst allocation failed, error=%d\n",
367-
error);
368-
goto out_rqst;
369-
}
370-
371-
svc_sock_update_bufs(serv);
372-
serv->sv_maxconn = nlm_max_connections;
373-
374-
nlmsvc_task = kthread_create(lockd, rqst, "%s", serv->sv_name);
375-
if (IS_ERR(nlmsvc_task)) {
376-
error = PTR_ERR(nlmsvc_task);
377-
printk(KERN_WARNING
378-
"lockd_up: kthread_run failed, error=%d\n", error);
379-
goto out_task;
380-
}
381-
rqst->rq_task = nlmsvc_task;
382-
wake_up_process(nlmsvc_task);
383-
384-
dprintk("lockd_up: service started\n");
385-
return 0;
386-
387-
out_task:
388-
svc_exit_thread(rqst);
389-
nlmsvc_task = NULL;
390-
out_rqst:
391-
return error;
392-
}
393-
394353
static const struct svc_serv_ops lockd_sv_ops = {
395354
.svo_shutdown = svc_rpcb_cleanup,
355+
.svo_function = lockd,
396356
.svo_enqueue_xprt = svc_xprt_do_enqueue,
357+
.svo_module = THIS_MODULE,
397358
};
398359

399360
static int lockd_get(void)
@@ -425,7 +386,8 @@ static int lockd_get(void)
425386
return -ENOMEM;
426387
}
427388

428-
error = lockd_start_svc(serv);
389+
serv->sv_maxconn = nlm_max_connections;
390+
error = svc_set_num_threads(serv, NULL, 1);
429391
/* The thread now holds the only reference */
430392
svc_put(serv);
431393
if (error < 0)
@@ -453,11 +415,7 @@ static void lockd_put(void)
453415
unregister_inet6addr_notifier(&lockd_inet6addr_notifier);
454416
#endif
455417

456-
if (nlmsvc_task) {
457-
kthread_stop(nlmsvc_task);
458-
dprintk("lockd_down: service stopped\n");
459-
nlmsvc_task = NULL;
460-
}
418+
svc_set_num_threads(nlmsvc_serv, NULL, 0);
461419
nlmsvc_serv = NULL;
462420
dprintk("lockd_down: service destroyed\n");
463421
}

include/linux/sunrpc/svc.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ struct svc_serv_ops {
6464
/* queue up a transport for servicing */
6565
void (*svo_enqueue_xprt)(struct svc_xprt *);
6666

67-
/* optional module to count when adding threads (pooled svcs only) */
67+
/* optional module to count when adding threads.
68+
* Thread function must call module_put_and_exit() to exit.
69+
*/
6870
struct module *svo_module;
6971
};
7072

@@ -504,8 +506,6 @@ struct svc_serv *svc_create(struct svc_program *, unsigned int,
504506
const struct svc_serv_ops *);
505507
struct svc_rqst *svc_rqst_alloc(struct svc_serv *serv,
506508
struct svc_pool *pool, int node);
507-
struct svc_rqst *svc_prepare_thread(struct svc_serv *serv,
508-
struct svc_pool *pool, int node);
509509
void svc_rqst_replace_page(struct svc_rqst *rqstp,
510510
struct page *page);
511511
void svc_rqst_free(struct svc_rqst *);

net/sunrpc/svc.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ svc_rqst_alloc(struct svc_serv *serv, struct svc_pool *pool, int node)
652652
}
653653
EXPORT_SYMBOL_GPL(svc_rqst_alloc);
654654

655-
struct svc_rqst *
655+
static struct svc_rqst *
656656
svc_prepare_thread(struct svc_serv *serv, struct svc_pool *pool, int node)
657657
{
658658
struct svc_rqst *rqstp;
@@ -672,7 +672,6 @@ svc_prepare_thread(struct svc_serv *serv, struct svc_pool *pool, int node)
672672
spin_unlock_bh(&pool->sp_lock);
673673
return rqstp;
674674
}
675-
EXPORT_SYMBOL_GPL(svc_prepare_thread);
676675

677676
/*
678677
* Choose a pool in which to create a new thread, for svc_set_num_threads

0 commit comments

Comments
 (0)