From: "J. Bruce Fields" <bfields@fieldses.org>
To: Jeff Layton <jlayton@redhat.com>
Cc: trond.myklebust@fys.uio.no, linux-nfs@vger.kernel.org,
nfsv4@linux-nfs.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/3] lockd: close potential race with rapid lockd_up/lockd_down cycle
Date: Fri, 13 Jun 2008 13:53:16 -0400 [thread overview]
Message-ID: <20080613175316.GB8501@fieldses.org> (raw)
In-Reply-To: <1213192992-7635-4-git-send-email-jlayton@redhat.com>
On Wed, Jun 11, 2008 at 10:03:12AM -0400, Jeff Layton wrote:
> If lockd_down is called very rapidly after lockd_up returns, then
> there is a slim chance that lockd() will never be called. kthread()
> will return before calling the function, so we'll end up never
> actually calling the cleanup functions for the thread.
Looks OK to me, thanks. Applied (for 2.6.27, unless someone wants to
argue it's more urgent.)
--b.
>
> Signed-off-by: Jeff Layton <jlayton@redhat.com>
> ---
> fs/lockd/svc.c | 33 +++++++++++++--------------------
> 1 files changed, 13 insertions(+), 20 deletions(-)
>
> diff --git a/fs/lockd/svc.c b/fs/lockd/svc.c
> index 2169af4..5bd9bf0 100644
> --- a/fs/lockd/svc.c
> +++ b/fs/lockd/svc.c
> @@ -50,7 +50,7 @@ EXPORT_SYMBOL(nlmsvc_ops);
> static DEFINE_MUTEX(nlmsvc_mutex);
> static unsigned int nlmsvc_users;
> static struct task_struct *nlmsvc_task;
> -static struct svc_serv *nlmsvc_serv;
> +static struct svc_rqst *nlmsvc_rqst;
> int nlmsvc_grace_period;
> unsigned long nlmsvc_timeout;
>
> @@ -194,20 +194,11 @@ lockd(void *vrqstp)
>
> svc_process(rqstp);
> }
> -
> flush_signals(current);
> if (nlmsvc_ops)
> nlmsvc_invalidate_all();
> nlm_shutdown_hosts();
> -
> unlock_kernel();
> -
> - nlmsvc_task = NULL;
> - nlmsvc_serv = NULL;
> -
> - /* Exit the RPC thread */
> - svc_exit_thread(rqstp);
> -
> return 0;
> }
>
> @@ -254,16 +245,15 @@ int
> lockd_up(int proto) /* Maybe add a 'family' option when IPv6 is supported ?? */
> {
> struct svc_serv *serv;
> - struct svc_rqst *rqstp;
> int error = 0;
>
> mutex_lock(&nlmsvc_mutex);
> /*
> * Check whether we're already up and running.
> */
> - if (nlmsvc_serv) {
> + if (nlmsvc_rqst) {
> if (proto)
> - error = make_socks(nlmsvc_serv, proto);
> + error = make_socks(nlmsvc_rqst->rq_server, proto);
> goto out;
> }
>
> @@ -288,9 +278,10 @@ lockd_up(int proto) /* Maybe add a 'family' option when IPv6 is supported ?? */
> /*
> * Create the kernel thread and wait for it to start.
> */
> - rqstp = svc_prepare_thread(serv, &serv->sv_pools[0]);
> - if (IS_ERR(rqstp)) {
> - error = PTR_ERR(rqstp);
> + nlmsvc_rqst = svc_prepare_thread(serv, &serv->sv_pools[0]);
> + if (IS_ERR(nlmsvc_rqst)) {
> + error = PTR_ERR(nlmsvc_rqst);
> + nlmsvc_rqst = NULL;
> printk(KERN_WARNING
> "lockd_up: svc_rqst allocation failed, error=%d\n",
> error);
> @@ -298,16 +289,15 @@ lockd_up(int proto) /* Maybe add a 'family' option when IPv6 is supported ?? */
> }
>
> svc_sock_update_bufs(serv);
> - nlmsvc_serv = rqstp->rq_server;
>
> - nlmsvc_task = kthread_run(lockd, rqstp, serv->sv_name);
> + nlmsvc_task = kthread_run(lockd, nlmsvc_rqst, serv->sv_name);
> if (IS_ERR(nlmsvc_task)) {
> error = PTR_ERR(nlmsvc_task);
> + svc_exit_thread(nlmsvc_rqst);
> nlmsvc_task = NULL;
> - nlmsvc_serv = NULL;
> + nlmsvc_rqst = NULL;
> printk(KERN_WARNING
> "lockd_up: kthread_run failed, error=%d\n", error);
> - svc_exit_thread(rqstp);
> goto destroy_and_out;
> }
>
> @@ -346,6 +336,9 @@ lockd_down(void)
> BUG();
> }
> kthread_stop(nlmsvc_task);
> + svc_exit_thread(nlmsvc_rqst);
> + nlmsvc_task = NULL;
> + nlmsvc_rqst = NULL;
> out:
> mutex_unlock(&nlmsvc_mutex);
> }
> --
> 1.5.3.6
>
prev parent reply other threads:[~2008-06-13 17:53 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-11 14:03 [PATCH 0/3] fix potential races in lockd and nfs4-callback startup/shutdown Jeff Layton
2008-06-11 14:03 ` [PATCH 1/3] nfs4: remove BKL from nfs_callback_up and nfs_callback_down Jeff Layton
2008-06-11 14:03 ` [PATCH 2/3] nfs4: fix potential race with rapid nfs_callback_up/down cycle Jeff Layton
2008-06-11 14:03 ` [PATCH 3/3] lockd: close potential race with rapid lockd_up/lockd_down cycle Jeff Layton
2008-06-13 17:53 ` J. Bruce Fields [this message]
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=20080613175316.GB8501@fieldses.org \
--to=bfields@fieldses.org \
--cc=jlayton@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=nfsv4@linux-nfs.org \
--cc=trond.myklebust@fys.uio.no \
/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
all inboxes | Powered by JetHome®