Commit a9c5d73a8d8cb37601f8c39b35b9b4128e1a5254

Authored by Stanislav Kinsbursky
Committed by Trond Myklebust
1 parent c228fa2038

Lockd: pernet usage counter introduced

Lockd is going to be shared between network namespaces - i.e. going to be able
to handle lock requests from different network namespaces. This means, that
network namespace related resources have to be allocated not once (like now),
but for every network namespace context, from which service is requested to
operate.
This patch implements Lockd per-net users accounting. New per-net counter is
used to determine, when per-net resources have to be freed.

Signed-off-by: Stanislav Kinsbursky <skinsbursky@parallels.com>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>

Showing 2 changed files with 54 additions and 3 deletions Side-by-side Diff

  1 +#ifndef __LOCKD_NETNS_H__
  2 +#define __LOCKD_NETNS_H__
  3 +
  4 +#include <net/netns/generic.h>
  5 +
  6 +struct lockd_net {
  7 + unsigned int nlmsvc_users;
  8 +};
  9 +
  10 +extern int lockd_net_id;
  11 +
  12 +#endif
... ... @@ -35,6 +35,8 @@
35 35 #include <linux/lockd/lockd.h>
36 36 #include <linux/nfs.h>
37 37  
  38 +#include "netns.h"
  39 +
38 40 #define NLMDBG_FACILITY NLMDBG_SVC
39 41 #define LOCKD_BUFSIZE (1024 + NLMSVC_XDRSIZE)
40 42 #define ALLOWED_SIGS (sigmask(SIGKILL))
... ... @@ -50,6 +52,8 @@
50 52 static struct svc_rqst *nlmsvc_rqst;
51 53 unsigned long nlmsvc_timeout;
52 54  
  55 +int lockd_net_id;
  56 +
53 57 /*
54 58 * These can be set at insmod time (useful for NFS as root filesystem),
55 59 * and also changed through the sysctl interface. -- Jamie Lokier, Aug 2003
56 60  
... ... @@ -316,8 +320,12 @@
316 320 destroy_and_out:
317 321 svc_destroy(serv);
318 322 out:
319   - if (!error)
  323 + if (!error) {
  324 + struct lockd_net *ln = net_generic(net, lockd_net_id);
  325 +
  326 + ln->nlmsvc_users++;
320 327 nlmsvc_users++;
  328 + }
321 329 mutex_unlock(&nlmsvc_mutex);
322 330 return error;
323 331 }
324 332  
325 333  
326 334  
327 335  
328 336  
329 337  
... ... @@ -500,24 +508,55 @@
500 508 module_param(nsm_use_hostnames, bool, 0644);
501 509 module_param(nlm_max_connections, uint, 0644);
502 510  
  511 +static int lockd_init_net(struct net *net)
  512 +{
  513 + return 0;
  514 +}
  515 +
  516 +static void lockd_exit_net(struct net *net)
  517 +{
  518 +}
  519 +
  520 +static struct pernet_operations lockd_net_ops = {
  521 + .init = lockd_init_net,
  522 + .exit = lockd_exit_net,
  523 + .id = &lockd_net_id,
  524 + .size = sizeof(struct lockd_net),
  525 +};
  526 +
  527 +
503 528 /*
504 529 * Initialising and terminating the module.
505 530 */
506 531  
507 532 static int __init init_nlm(void)
508 533 {
  534 + int err;
  535 +
509 536 #ifdef CONFIG_SYSCTL
  537 + err = -ENOMEM;
510 538 nlm_sysctl_table = register_sysctl_table(nlm_sysctl_root);
511   - return nlm_sysctl_table ? 0 : -ENOMEM;
512   -#else
  539 + if (nlm_sysctl_table == NULL)
  540 + goto err_sysctl;
  541 +#endif
  542 + err = register_pernet_subsys(&lockd_net_ops);
  543 + if (err)
  544 + goto err_pernet;
513 545 return 0;
  546 +
  547 +err_pernet:
  548 +#ifdef CONFIG_SYSCTL
  549 + unregister_sysctl_table(nlm_sysctl_table);
514 550 #endif
  551 +err_sysctl:
  552 + return err;
515 553 }
516 554  
517 555 static void __exit exit_nlm(void)
518 556 {
519 557 /* FIXME: delete all NLM clients */
520 558 nlm_shutdown_hosts();
  559 + unregister_pernet_subsys(&lockd_net_ops);
521 560 #ifdef CONFIG_SYSCTL
522 561 unregister_sysctl_table(nlm_sysctl_table);
523 562 #endif