From: Kinglong Mee <kinglongmee@gmail.com>
To: Trond Myklebust <trond.myklebust@primarydata.com>,
linux-nfs@vger.kernel.org
Cc: "J. Bruce Fields" <bfields@redhat.com>,
Kinglong Mee <kinglongmee@gmail.com>
Subject: Re: [PATCH 2/2] NFSv4: Fix callback server shutdown
Date: Thu, 27 Apr 2017 11:06:39 +0800 [thread overview]
Message-ID: <1692a8de-1d22-dfdd-d36f-e2b040160e26@gmail.com> (raw)
In-Reply-To: <20170426155527.92213-3-trond.myklebust@primarydata.com>
On 4/26/2017 23:55, Trond Myklebust wrote:
> We want to use kthread_stop() in order to ensure the threads are
> shut down before we tear down the nfs_callback_info in nfs_callback_down.
>
> Reported-by: Kinglong Mee <kinglongmee@gmail.com>
> Fixes: bb6aeba736ba9 ("NFSv4.x: Switch to using svc_set_num_threads()...")
> Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
> Cc: J. Bruce Fields <bfields@redhat.com>
> ---
> fs/nfs/callback.c | 24 ++++++++++++++++--------
> include/linux/sunrpc/svc.h | 1 +
> net/sunrpc/svc.c | 38 ++++++++++++++++++++++++++++++++++++++
> 3 files changed, 55 insertions(+), 8 deletions(-)
>
> diff --git a/fs/nfs/callback.c b/fs/nfs/callback.c
> index 773774531aff..8cabae9b140e 100644
> --- a/fs/nfs/callback.c
> +++ b/fs/nfs/callback.c
> @@ -76,7 +76,10 @@ nfs4_callback_svc(void *vrqstp)
>
> set_freezable();
>
> - while (!kthread_should_stop()) {
> + while (!kthread_freezable_should_stop(NULL)) {
> +
> + if (signal_pending(current))
> + flush_signals(current);
> /*
> * Listen for a request on the socket
> */
> @@ -85,6 +88,8 @@ nfs4_callback_svc(void *vrqstp)
> continue;
> svc_process(rqstp);
> }
> + svc_exit_thread(rqstp);
> + module_put_and_exit(0);
> return 0;
> }
>
> @@ -103,9 +108,10 @@ nfs41_callback_svc(void *vrqstp)
>
> set_freezable();
>
> - while (!kthread_should_stop()) {
> - if (try_to_freeze())
> - continue;
> + while (!kthread_freezable_should_stop(NULL)) {
> +
> + if (signal_pending(current))
> + flush_signals(current);
>
> prepare_to_wait(&serv->sv_cb_waitq, &wq, TASK_INTERRUPTIBLE);
> spin_lock_bh(&serv->sv_cb_lock);
> @@ -121,11 +127,13 @@ nfs41_callback_svc(void *vrqstp)
> error);
> } else {
> spin_unlock_bh(&serv->sv_cb_lock);
> - schedule();
> + if (!kthread_should_stop())
> + schedule();
> finish_wait(&serv->sv_cb_waitq, &wq);
> }
> - flush_signals(current);
> }
> + svc_exit_thread(rqstp);
> + module_put_and_exit(0);
> return 0;
> }
>
> @@ -221,14 +229,14 @@ static int nfs_callback_up_net(int minorversion, struct svc_serv *serv,
> static struct svc_serv_ops nfs40_cb_sv_ops = {
> .svo_function = nfs4_callback_svc,
> .svo_enqueue_xprt = svc_xprt_do_enqueue,
> - .svo_setup = svc_set_num_threads,
> + .svo_setup = svc_set_num_threads_sync,
> .svo_module = THIS_MODULE,
> };
> #if defined(CONFIG_NFS_V4_1)
> static struct svc_serv_ops nfs41_cb_sv_ops = {
> .svo_function = nfs41_callback_svc,
> .svo_enqueue_xprt = svc_xprt_do_enqueue,
> - .svo_setup = svc_set_num_threads,
> + .svo_setup = svc_set_num_threads_sync,
> .svo_module = THIS_MODULE,
> };
>
> diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
> index e770abeed32d..11cef5a7bc87 100644
> --- a/include/linux/sunrpc/svc.h
> +++ b/include/linux/sunrpc/svc.h
> @@ -474,6 +474,7 @@ void svc_pool_map_put(void);
> struct svc_serv * svc_create_pooled(struct svc_program *, unsigned int,
> struct svc_serv_ops *);
> int svc_set_num_threads(struct svc_serv *, struct svc_pool *, int);
> +int svc_set_num_threads_sync(struct svc_serv *, struct svc_pool *, int);
> int svc_pool_stats_open(struct svc_serv *serv, struct file *file);
> void svc_destroy(struct svc_serv *);
> void svc_shutdown_net(struct svc_serv *, struct net *);
> diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
> index 98dc33ae738b..bc0f5a0ecbdc 100644
> --- a/net/sunrpc/svc.c
> +++ b/net/sunrpc/svc.c
> @@ -795,6 +795,44 @@ svc_set_num_threads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
> }
> EXPORT_SYMBOL_GPL(svc_set_num_threads);
>
> +/* destroy old threads */
> +static int
> +svc_stop_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;
> + kthread_stop(task);
> + nrservs++;
> + } while (nrservs < 0);
> + return 0;
> +}
> +
> +int
> +svc_set_num_threads_sync(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_stop_kthreads(serv, pool, nrservs);
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(svc_set_num_threads_sync);
There is only one use of svc_set_num_threads that by nfsd,
I'd like to change svc_set_num_threads and update nfsd than add a new function.
Ps,
"NFSv4.x/callback: Create the callback service through svc_create_pooled"
must be include before the fix. I will resend it later.
thanks,
Kinglong Mee
next prev parent reply other threads:[~2017-04-27 3:06 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-26 15:55 [PATCH 0/2] Fix the NFSv4 client callback channel shutdown Trond Myklebust
2017-04-26 15:55 ` [PATCH 1/2] SUNRPC: Refactor svc_set_num_threads() Trond Myklebust
2017-04-26 15:55 ` [PATCH 2/2] NFSv4: Fix callback server shutdown Trond Myklebust
2017-04-26 20:29 ` J. Bruce Fields
2017-04-27 3:06 ` Kinglong Mee [this message]
2017-04-27 3:13 ` [PATCH resend] NFSv4.x/callback: Create the callback service through svc_create_pooled Kinglong Mee
2017-04-27 3:24 ` [PATCH 2/2] NFSv4: Fix callback server shutdown Trond Myklebust
2017-04-27 3:54 ` Kinglong Mee
2017-04-27 22:03 ` J. Bruce Fields
2017-04-27 22:07 ` Trond Myklebust
2017-05-03 20:21 ` J. Bruce Fields
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=1692a8de-1d22-dfdd-d36f-e2b040160e26@gmail.com \
--to=kinglongmee@gmail.com \
--cc=bfields@redhat.com \
--cc=linux-nfs@vger.kernel.org \
--cc=trond.myklebust@primarydata.com \
/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;
as well as URLs for NNTP newsgroup(s).