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;
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
}
nfsd4_shutdown_recdir();
- nfs4_init = 0;
}
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 */
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");
nfsd_svc(unsigned short port, int nrservs)
{
int error;
+ bool first_thread;
mutex_lock(&nfsd_mutex);
dprintk("nfsd: creating service\n");
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)
* 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;
}