Commit 865b6740 authored by NeilBrown's avatar NeilBrown Committed by Chuck Lever

lockd: introduce lockd_put()

There is some cleanup that is duplicated in lockd_down() and the failure
path of lockd_up().
Factor these out into a new lockd_put() and call it from both places.

lockd_put() does *not* take the mutex - that must be held by the caller.
It decrements nlmsvc_users and if that reaches zero, it cleans up.
Signed-off-by: default avatarNeilBrown <neilb@suse.de>
Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
parent 6a4e2527
...@@ -351,14 +351,6 @@ static struct notifier_block lockd_inet6addr_notifier = { ...@@ -351,14 +351,6 @@ static struct notifier_block lockd_inet6addr_notifier = {
}; };
#endif #endif
static void lockd_unregister_notifiers(void)
{
unregister_inetaddr_notifier(&lockd_inetaddr_notifier);
#if IS_ENABLED(CONFIG_IPV6)
unregister_inet6addr_notifier(&lockd_inet6addr_notifier);
#endif
}
static int lockd_start_svc(struct svc_serv *serv) static int lockd_start_svc(struct svc_serv *serv)
{ {
int error; int error;
...@@ -450,6 +442,27 @@ static int lockd_create_svc(void) ...@@ -450,6 +442,27 @@ static int lockd_create_svc(void)
return 0; return 0;
} }
static void lockd_put(void)
{
if (WARN(nlmsvc_users <= 0, "lockd_down: no users!\n"))
return;
if (--nlmsvc_users)
return;
unregister_inetaddr_notifier(&lockd_inetaddr_notifier);
#if IS_ENABLED(CONFIG_IPV6)
unregister_inet6addr_notifier(&lockd_inet6addr_notifier);
#endif
if (nlmsvc_task) {
kthread_stop(nlmsvc_task);
dprintk("lockd_down: service stopped\n");
nlmsvc_task = NULL;
}
nlmsvc_serv = NULL;
dprintk("lockd_down: service destroyed\n");
}
/* /*
* Bring up the lockd process if it's not already up. * Bring up the lockd process if it's not already up.
*/ */
...@@ -461,21 +474,16 @@ int lockd_up(struct net *net, const struct cred *cred) ...@@ -461,21 +474,16 @@ int lockd_up(struct net *net, const struct cred *cred)
error = lockd_create_svc(); error = lockd_create_svc();
if (error) if (error)
goto err_create; goto err;
nlmsvc_users++;
error = lockd_up_net(nlmsvc_serv, net, cred); error = lockd_up_net(nlmsvc_serv, net, cred);
if (error < 0) { if (error < 0) {
goto err_put; lockd_put();
goto err;
} }
nlmsvc_users++; err:
err_put:
if (nlmsvc_users == 0) {
lockd_unregister_notifiers();
kthread_stop(nlmsvc_task);
nlmsvc_serv = NULL;
}
err_create:
mutex_unlock(&nlmsvc_mutex); mutex_unlock(&nlmsvc_mutex);
return error; return error;
} }
...@@ -489,25 +497,7 @@ lockd_down(struct net *net) ...@@ -489,25 +497,7 @@ lockd_down(struct net *net)
{ {
mutex_lock(&nlmsvc_mutex); mutex_lock(&nlmsvc_mutex);
lockd_down_net(nlmsvc_serv, net); lockd_down_net(nlmsvc_serv, net);
if (nlmsvc_users) { lockd_put();
if (--nlmsvc_users)
goto out;
} else {
printk(KERN_ERR "lockd_down: no users! task=%p\n",
nlmsvc_task);
BUG();
}
if (!nlmsvc_task) {
printk(KERN_ERR "lockd_down: no lockd running.\n");
BUG();
}
lockd_unregister_notifiers();
kthread_stop(nlmsvc_task);
dprintk("lockd_down: service destroyed\n");
nlmsvc_serv = NULL;
nlmsvc_task = NULL;
out:
mutex_unlock(&nlmsvc_mutex); mutex_unlock(&nlmsvc_mutex);
} }
EXPORT_SYMBOL_GPL(lockd_down); EXPORT_SYMBOL_GPL(lockd_down);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment