grace.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Common code for control of lockd and nfsv4 grace periods.
  3. */
  4. #include <linux/module.h>
  5. #include <linux/lockd/bind.h>
  6. #include <net/net_namespace.h>
  7. #include "netns.h"
  8. static DEFINE_SPINLOCK(grace_lock);
  9. /**
  10. * locks_start_grace
  11. * @lm: who this grace period is for
  12. *
  13. * A grace period is a period during which locks should not be given
  14. * out. Currently grace periods are only enforced by the two lock
  15. * managers (lockd and nfsd), using the locks_in_grace() function to
  16. * check when they are in a grace period.
  17. *
  18. * This function is called to start a grace period.
  19. */
  20. void locks_start_grace(struct net *net, struct lock_manager *lm)
  21. {
  22. struct lockd_net *ln = net_generic(net, lockd_net_id);
  23. spin_lock(&grace_lock);
  24. list_add(&lm->list, &ln->grace_list);
  25. spin_unlock(&grace_lock);
  26. }
  27. EXPORT_SYMBOL_GPL(locks_start_grace);
  28. /**
  29. * locks_end_grace
  30. * @lm: who this grace period is for
  31. *
  32. * Call this function to state that the given lock manager is ready to
  33. * resume regular locking. The grace period will not end until all lock
  34. * managers that called locks_start_grace() also call locks_end_grace().
  35. * Note that callers count on it being safe to call this more than once,
  36. * and the second call should be a no-op.
  37. */
  38. void locks_end_grace(struct lock_manager *lm)
  39. {
  40. spin_lock(&grace_lock);
  41. list_del_init(&lm->list);
  42. spin_unlock(&grace_lock);
  43. }
  44. EXPORT_SYMBOL_GPL(locks_end_grace);
  45. /**
  46. * locks_in_grace
  47. *
  48. * Lock managers call this function to determine when it is OK for them
  49. * to answer ordinary lock requests, and when they should accept only
  50. * lock reclaims.
  51. */
  52. int locks_in_grace(struct net *net)
  53. {
  54. struct lockd_net *ln = net_generic(net, lockd_net_id);
  55. return !list_empty(&ln->grace_list);
  56. }
  57. EXPORT_SYMBOL_GPL(locks_in_grace);