From: NeilBrown <neilb@suse.de>
To: "J. Bruce Fields" <bfields@fieldses.org>,
Chuck Lever <chuck.lever@oracle.com>
Cc: linux-nfs@vger.kernel.org
Subject: [PATCH 19/20] lockd: use svc_set_num_threads() for thread start and stop
Date: Mon, 29 Nov 2021 15:51:25 +1100 [thread overview]
Message-ID: <163816148564.32298.15399372682473640783.stgit@noble.brown> (raw)
In-Reply-To: <163816133466.32298.13831616524908720974.stgit@noble.brown>
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>
---
fs/lockd/svc.c | 58 ++++++--------------------------------------
include/linux/sunrpc/svc.h | 6 ++---
net/sunrpc/svc.c | 3 +-
3 files changed, 12 insertions(+), 55 deletions(-)
diff --git a/fs/lockd/svc.c b/fs/lockd/svc.c
index 1a7c11118b32..4defefd89cbf 100644
--- a/fs/lockd/svc.c
+++ b/fs/lockd/svc.c
@@ -55,7 +55,6 @@ EXPORT_SYMBOL_GPL(nlmsvc_ops);
static DEFINE_MUTEX(nlmsvc_mutex);
static unsigned int nlmsvc_users;
static struct svc_serv *nlmsvc_serv;
-static struct task_struct *nlmsvc_task;
unsigned long nlmsvc_timeout;
unsigned int lockd_net_id;
@@ -186,7 +185,7 @@ lockd(void *vrqstp)
svc_exit_thread(rqstp);
- return 0;
+ module_put_and_exit(0);
}
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)
__func__, net->ns.inum);
}
} else {
- pr_err("%s: no users! task=%p, net=%x\n",
- __func__, nlmsvc_task, net->ns.inum);
+ pr_err("%s: no users! net=%x\n",
+ __func__, net->ns.inum);
BUG();
}
}
@@ -351,49 +350,11 @@ static struct notifier_block lockd_inet6addr_notifier = {
};
#endif
-static int lockd_start_svc(struct svc_serv *serv)
-{
- int error;
- struct svc_rqst *rqst;
-
- /*
- * Create the kernel thread and wait for it to start.
- */
- rqst = svc_prepare_thread(serv, &serv->sv_pools[0], NUMA_NO_NODE);
- if (IS_ERR(rqst)) {
- error = PTR_ERR(rqst);
- printk(KERN_WARNING
- "lockd_up: svc_rqst allocation failed, error=%d\n",
- error);
- goto out_rqst;
- }
-
- svc_sock_update_bufs(serv);
- serv->sv_maxconn = nlm_max_connections;
-
- nlmsvc_task = kthread_create(lockd, rqst, "%s", serv->sv_name);
- if (IS_ERR(nlmsvc_task)) {
- error = PTR_ERR(nlmsvc_task);
- printk(KERN_WARNING
- "lockd_up: kthread_run failed, error=%d\n", error);
- goto out_task;
- }
- rqst->rq_task = nlmsvc_task;
- wake_up_process(nlmsvc_task);
-
- dprintk("lockd_up: service started\n");
- return 0;
-
-out_task:
- svc_exit_thread(rqst);
- nlmsvc_task = NULL;
-out_rqst:
- return error;
-}
-
static const struct svc_serv_ops lockd_sv_ops = {
.svo_shutdown = svc_rpcb_cleanup,
+ .svo_function = lockd,
.svo_enqueue_xprt = svc_xprt_do_enqueue,
+ .svo_module = THIS_MODULE,
};
static int lockd_get(void)
@@ -425,7 +386,8 @@ static int lockd_get(void)
return -ENOMEM;
}
- error = lockd_start_svc(serv);
+ serv->sv_maxconn = nlm_max_connections;
+ error = svc_set_num_threads(serv, NULL, 1);
/* The thread now holds the only reference */
svc_put(serv);
if (error < 0)
@@ -453,11 +415,7 @@ static void lockd_put(void)
unregister_inet6addr_notifier(&lockd_inet6addr_notifier);
#endif
- if (nlmsvc_task) {
- kthread_stop(nlmsvc_task);
- dprintk("lockd_down: service stopped\n");
- nlmsvc_task = NULL;
- }
+ svc_set_num_threads(nlmsvc_serv, NULL, 0);
nlmsvc_serv = NULL;
dprintk("lockd_down: service destroyed\n");
}
diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
index d69e6108cb83..cf175d47c6b7 100644
--- a/include/linux/sunrpc/svc.h
+++ b/include/linux/sunrpc/svc.h
@@ -64,7 +64,9 @@ struct svc_serv_ops {
/* queue up a transport for servicing */
void (*svo_enqueue_xprt)(struct svc_xprt *);
- /* optional module to count when adding threads (pooled svcs only) */
+ /* optional module to count when adding threads.
+ * Thread function must call module_put_and_exit() to exit.
+ */
struct module *svo_module;
};
@@ -504,8 +506,6 @@ struct svc_serv *svc_create(struct svc_program *, unsigned int,
const struct svc_serv_ops *);
struct svc_rqst *svc_rqst_alloc(struct svc_serv *serv,
struct svc_pool *pool, int node);
-struct svc_rqst *svc_prepare_thread(struct svc_serv *serv,
- struct svc_pool *pool, int node);
void svc_rqst_replace_page(struct svc_rqst *rqstp,
struct page *page);
void svc_rqst_free(struct svc_rqst *);
diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
index 5fbe7f55289e..2aabec2b4bec 100644
--- a/net/sunrpc/svc.c
+++ b/net/sunrpc/svc.c
@@ -652,7 +652,7 @@ svc_rqst_alloc(struct svc_serv *serv, struct svc_pool *pool, int node)
}
EXPORT_SYMBOL_GPL(svc_rqst_alloc);
-struct svc_rqst *
+static struct svc_rqst *
svc_prepare_thread(struct svc_serv *serv, struct svc_pool *pool, int node)
{
struct svc_rqst *rqstp;
@@ -672,7 +672,6 @@ svc_prepare_thread(struct svc_serv *serv, struct svc_pool *pool, int node)
spin_unlock_bh(&pool->sp_lock);
return rqstp;
}
-EXPORT_SYMBOL_GPL(svc_prepare_thread);
/*
* Choose a pool in which to create a new thread, for svc_set_num_threads
next prev parent reply other threads:[~2021-11-29 4:56 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-29 4:51 [PATCH 00/20 v3] SUNRPC: clean up server thread management NeilBrown
2021-11-29 4:51 ` [PATCH 14/20] lockd: move svc_exit_thread() into the thread NeilBrown
2021-11-29 4:51 ` [PATCH 07/20] NFSD: narrow nfsd_mutex protection in nfsd thread NeilBrown
2021-11-29 4:51 ` [PATCH 09/20] SUNRPC: discard svo_setup and rename svc_set_num_threads_sync() NeilBrown
2021-11-29 4:51 ` [PATCH 18/20] SUNRPC: always treat sv_nrpools==1 as "not pooled" NeilBrown
2021-11-29 4:51 ` [PATCH 11/20] lockd: introduce nlmsvc_serv NeilBrown
2021-11-29 4:51 ` [PATCH 15/20] lockd: introduce lockd_put() NeilBrown
2021-11-29 4:51 ` [PATCH 04/20] SUNRPC: stop using ->sv_nrthreads as a refcount NeilBrown
2021-11-29 4:51 ` [PATCH 05/20] nfsd: make nfsd_stats.th_cnt atomic_t NeilBrown
2021-11-29 4:51 ` [PATCH 08/20] NFSD: Make it possible to use svc_set_num_threads_sync NeilBrown
2021-11-29 4:51 ` [PATCH 13/20] lockd: move lockd_start_svc() call into lockd_create_svc() NeilBrown
2023-06-02 15:46 ` Ido Schimmel
2023-06-02 21:28 ` NeilBrown
2023-06-03 9:33 ` Ido Schimmel
2023-06-03 14:58 ` Chuck Lever III
2021-11-29 4:51 ` [PATCH 16/20] lockd: rename lockd_create_svc() to lockd_get() NeilBrown
2021-11-29 4:51 ` [PATCH 20/20] NFS: switch the callback service back to non-pooled NeilBrown
2021-11-29 4:51 ` [PATCH 17/20] SUNRPC: move the pool_map definitions (back) into svc.c NeilBrown
2021-11-29 4:51 ` [PATCH 03/20] SUNRPC/NFSD: clean up get/put functions NeilBrown
2021-11-29 4:51 ` [PATCH 02/20] SUNRPC: change svc_get() to return the svc NeilBrown
2021-11-29 4:51 ` NeilBrown [this message]
2021-11-29 4:51 ` [PATCH 10/20] NFSD: simplify locking for network notifier NeilBrown
2021-11-29 4:51 ` [PATCH 01/20] NFSD: handle errors better in write_ports_addfd() NeilBrown
2021-11-29 4:51 ` [PATCH 12/20] lockd: simplify management of network status notifiers NeilBrown
2021-11-29 4:51 ` [PATCH 06/20] SUNRPC: use sv_lock to protect updates to sv_nrthreads NeilBrown
2021-11-29 17:45 ` [PATCH 00/20 v3] SUNRPC: clean up server thread management Chuck Lever III
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=163816148564.32298.15399372682473640783.stgit@noble.brown \
--to=neilb@suse.de \
--cc=bfields@fieldses.org \
--cc=chuck.lever@oracle.com \
--cc=linux-nfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox