From: "J. Bruce Fields" <bfields@redhat.com>
To: Jeff Layton <jlayton@redhat.com>
Cc: linux-nfs@vger.kernel.org, Jeff Layton <jlayton@redhat.com>,
"J. Bruce Fields" <bfields@redhat.com>
Subject: [PATCH 1/7] nfsd4: fix v4 state shutdown error paths
Date: Wed, 21 Jul 2010 19:26:45 -0400 [thread overview]
Message-ID: <1279754811-8328-1-git-send-email-bfields@redhat.com> (raw)
In-Reply-To: <20100721232432.GA6689@fieldses.org>
From: Jeff Layton <jlayton@redhat.com>
If someone tries to shut down the laundry_wq while it isn't up it'll
cause an oops.
This can happen because write_ports can create a nfsd_svc before we
really start the nfs server, and we may fail before the server is ever
started.
Also make sure state is shutdown on error paths in nfsd_svc().
Use a common global nfsd_up flag instead of nfs4_init, and create common
helper functions for nfsd start/shutdown, as there will be other work
that we want done only when we the number of nfsd threads transitions
between zero and nonzero.
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
---
fs/nfsd/nfs4state.c | 12 +-----------
fs/nfsd/nfssvc.c | 51 ++++++++++++++++++++++++++++++++++++++++++---------
2 files changed, 43 insertions(+), 20 deletions(-)
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 182448f..9cc3b78 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -51,7 +51,6 @@ static time_t boot_time;
static u32 current_ownerid = 1;
static u32 current_fileid = 1;
static u32 current_delegid = 1;
-static u32 nfs4_init;
static stateid_t zerostateid; /* bits all 0 */
static stateid_t onestateid; /* bits all 1 */
static u64 current_sessionid = 1;
@@ -4071,16 +4070,8 @@ out_free_laundry:
int
nfs4_state_start(void)
{
- int ret;
-
- if (nfs4_init)
- return 0;
nfsd4_load_reboot_recovery_data();
- ret = __nfs4_state_start();
- if (ret)
- return ret;
- nfs4_init = 1;
- return 0;
+ return __nfs4_state_start();
}
static void
@@ -4115,7 +4106,6 @@ __nfs4_state_shutdown(void)
}
nfsd4_shutdown_recdir();
- nfs4_init = 0;
}
void
diff --git a/fs/nfsd/nfssvc.c b/fs/nfsd/nfssvc.c
index 06b2a26..d7a4d7b 100644
--- a/fs/nfsd/nfssvc.c
+++ b/fs/nfsd/nfssvc.c
@@ -180,6 +180,31 @@ int nfsd_nrthreads(void)
return rv;
}
+static bool nfsd_up = false;
+
+static int nfsd_startup(unsigned short port, int nrservs)
+{
+ int ret;
+
+ ret = nfs4_state_start();
+ nfsd_up = true;
+ return ret;
+}
+
+static void nfsd_shutdown(void)
+{
+ /*
+ * write_ports can create the server without actually starting
+ * any threads--if we get shut down before any threads are
+ * started, then nfsd_last_thread will be run before any of this
+ * other initialization has been done.
+ */
+ if (!nfsd_up)
+ return;
+ nfs4_state_shutdown();
+ nfsd_up = false;
+}
+
static void nfsd_last_thread(struct svc_serv *serv)
{
/* When last nfsd thread exits we need to do some clean-up */
@@ -188,7 +213,7 @@ static void nfsd_last_thread(struct svc_serv *serv)
lockd_down();
nfsd_serv = NULL;
nfsd_racache_shutdown();
- nfs4_state_shutdown();
+ nfsd_shutdown();
printk(KERN_WARNING "nfsd: last server has exited, flushing export "
"cache\n");
@@ -380,6 +405,7 @@ int
nfsd_svc(unsigned short port, int nrservs)
{
int error;
+ bool first_thread;
mutex_lock(&nfsd_mutex);
dprintk("nfsd: creating service\n");
@@ -395,19 +421,23 @@ nfsd_svc(unsigned short port, int nrservs)
error = nfsd_racache_init(2*nrservs);
if (error<0)
goto out;
- error = nfs4_state_start();
- if (error)
- goto out;
+
+ first_thread = (nfsd_serv->sv_nrthreads == 0) && (nrservs != 0);
+
+ if (first_thread) {
+ error = nfsd_startup(port, nrservs);
+ if (error)
+ goto out;
+ }
nfsd_reset_versions();
error = nfsd_create_serv();
-
if (error)
- goto out;
+ goto out_shutdown;
error = nfsd_init_socks(port);
if (error)
- goto failure;
+ goto out_destroy;
error = svc_set_num_threads(nfsd_serv, NULL, nrservs);
if (error == 0)
@@ -416,9 +446,12 @@ nfsd_svc(unsigned short port, int nrservs)
* so subtract 1
*/
error = nfsd_serv->sv_nrthreads - 1;
- failure:
+out_destroy:
svc_destroy(nfsd_serv); /* Release server */
- out:
+out_shutdown:
+ if (error < 0 && first_thread)
+ nfsd_shutdown();
+out:
mutex_unlock(&nfsd_mutex);
return error;
}
--
1.7.0.4
next prev parent reply other threads:[~2010-07-21 23:27 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-21 13:21 [PATCH 5/5] nfsd: just keep single lockd reference for nfsd (try #4) Jeff Layton
2010-07-21 20:14 ` J. Bruce Fields
2010-07-21 23:24 ` J. Bruce Fields
2010-07-21 23:26 ` J. Bruce Fields [this message]
2010-07-21 23:26 ` [PATCH 2/7] nfsd: fix error handling when starting nfsd with rpcbind down J. Bruce Fields
2010-07-21 23:26 ` [PATCH 3/7] nfsd: fix error handling in __write_ports_addxprt J. Bruce Fields
2010-07-21 23:26 ` [PATCH 4/7] nfsd: clean up nfsd_create_serv error handling J. Bruce Fields
2010-07-21 23:26 ` [PATCH 5/7] nfsd: just keep single lockd reference for nfsd J. Bruce Fields
2010-07-21 23:26 ` [PATCH 6/7] nfsd: move more into nfsd_startup() J. Bruce Fields
2010-07-21 23:26 ` [PATCH 7/7] nfsd: minor nfsd_svc() cleanup J. Bruce Fields
2010-07-22 17:40 ` [PATCH 5/5] nfsd: just keep single lockd reference for nfsd (try #4) Jeff Layton
[not found] ` <20100722134026.62091dc2-xSBYVWDuneFaJnirhKH9O4GKTjYczspe@public.gmane.org>
2010-07-23 12:55 ` J. Bruce Fields
2010-07-22 11:59 ` Staubach_Peter
2010-07-22 12:26 ` J. Bruce Fields
2010-07-22 12:36 ` Jeff Layton
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=1279754811-8328-1-git-send-email-bfields@redhat.com \
--to=bfields@redhat.com \
--cc=jlayton@redhat.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;
as well as URLs for NNTP newsgroup(s).