grace.c 1.6 KB

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