Skip to content

Commit 865b674

Browse files
neilbrownchucklever
authored andcommitted
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: NeilBrown <neilb@suse.de> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
1 parent 6a4e252 commit 865b674

1 file changed

Lines changed: 27 additions & 37 deletions

File tree

fs/lockd/svc.c

Lines changed: 27 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -351,14 +351,6 @@ static struct notifier_block lockd_inet6addr_notifier = {
351351
};
352352
#endif
353353

354-
static void lockd_unregister_notifiers(void)
355-
{
356-
unregister_inetaddr_notifier(&lockd_inetaddr_notifier);
357-
#if IS_ENABLED(CONFIG_IPV6)
358-
unregister_inet6addr_notifier(&lockd_inet6addr_notifier);
359-
#endif
360-
}
361-
362354
static int lockd_start_svc(struct svc_serv *serv)
363355
{
364356
int error;
@@ -450,6 +442,27 @@ static int lockd_create_svc(void)
450442
return 0;
451443
}
452444

445+
static void lockd_put(void)
446+
{
447+
if (WARN(nlmsvc_users <= 0, "lockd_down: no users!\n"))
448+
return;
449+
if (--nlmsvc_users)
450+
return;
451+
452+
unregister_inetaddr_notifier(&lockd_inetaddr_notifier);
453+
#if IS_ENABLED(CONFIG_IPV6)
454+
unregister_inet6addr_notifier(&lockd_inet6addr_notifier);
455+
#endif
456+
457+
if (nlmsvc_task) {
458+
kthread_stop(nlmsvc_task);
459+
dprintk("lockd_down: service stopped\n");
460+
nlmsvc_task = NULL;
461+
}
462+
nlmsvc_serv = NULL;
463+
dprintk("lockd_down: service destroyed\n");
464+
}
465+
453466
/*
454467
* Bring up the lockd process if it's not already up.
455468
*/
@@ -461,21 +474,16 @@ int lockd_up(struct net *net, const struct cred *cred)
461474

462475
error = lockd_create_svc();
463476
if (error)
464-
goto err_create;
477+
goto err;
478+
nlmsvc_users++;
465479

466480
error = lockd_up_net(nlmsvc_serv, net, cred);
467481
if (error < 0) {
468-
goto err_put;
482+
lockd_put();
483+
goto err;
469484
}
470485

471-
nlmsvc_users++;
472-
err_put:
473-
if (nlmsvc_users == 0) {
474-
lockd_unregister_notifiers();
475-
kthread_stop(nlmsvc_task);
476-
nlmsvc_serv = NULL;
477-
}
478-
err_create:
486+
err:
479487
mutex_unlock(&nlmsvc_mutex);
480488
return error;
481489
}
@@ -489,25 +497,7 @@ lockd_down(struct net *net)
489497
{
490498
mutex_lock(&nlmsvc_mutex);
491499
lockd_down_net(nlmsvc_serv, net);
492-
if (nlmsvc_users) {
493-
if (--nlmsvc_users)
494-
goto out;
495-
} else {
496-
printk(KERN_ERR "lockd_down: no users! task=%p\n",
497-
nlmsvc_task);
498-
BUG();
499-
}
500-
501-
if (!nlmsvc_task) {
502-
printk(KERN_ERR "lockd_down: no lockd running.\n");
503-
BUG();
504-
}
505-
lockd_unregister_notifiers();
506-
kthread_stop(nlmsvc_task);
507-
dprintk("lockd_down: service destroyed\n");
508-
nlmsvc_serv = NULL;
509-
nlmsvc_task = NULL;
510-
out:
500+
lockd_put();
511501
mutex_unlock(&nlmsvc_mutex);
512502
}
513503
EXPORT_SYMBOL_GPL(lockd_down);

0 commit comments

Comments
 (0)