fs_pin.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #include <linux/fs.h>
  2. #include <linux/slab.h>
  3. #include <linux/fs_pin.h>
  4. #include "internal.h"
  5. #include "mount.h"
  6. static void pin_free_rcu(struct rcu_head *head)
  7. {
  8. kfree(container_of(head, struct fs_pin, rcu));
  9. }
  10. static DEFINE_SPINLOCK(pin_lock);
  11. void pin_put(struct fs_pin *p)
  12. {
  13. if (atomic_long_dec_and_test(&p->count))
  14. call_rcu(&p->rcu, pin_free_rcu);
  15. }
  16. void pin_remove(struct fs_pin *pin)
  17. {
  18. spin_lock(&pin_lock);
  19. hlist_del(&pin->m_list);
  20. hlist_del(&pin->s_list);
  21. spin_unlock(&pin_lock);
  22. }
  23. void pin_insert(struct fs_pin *pin, struct vfsmount *m)
  24. {
  25. spin_lock(&pin_lock);
  26. hlist_add_head(&pin->s_list, &m->mnt_sb->s_pins);
  27. hlist_add_head(&pin->m_list, &real_mount(m)->mnt_pins);
  28. spin_unlock(&pin_lock);
  29. }
  30. void mnt_pin_kill(struct mount *m)
  31. {
  32. while (1) {
  33. struct hlist_node *p;
  34. struct fs_pin *pin;
  35. rcu_read_lock();
  36. p = ACCESS_ONCE(m->mnt_pins.first);
  37. if (!p) {
  38. rcu_read_unlock();
  39. break;
  40. }
  41. pin = hlist_entry(p, struct fs_pin, m_list);
  42. if (!atomic_long_inc_not_zero(&pin->count)) {
  43. rcu_read_unlock();
  44. cpu_relax();
  45. continue;
  46. }
  47. rcu_read_unlock();
  48. pin->kill(pin);
  49. }
  50. }
  51. void sb_pin_kill(struct super_block *sb)
  52. {
  53. while (1) {
  54. struct hlist_node *p;
  55. struct fs_pin *pin;
  56. rcu_read_lock();
  57. p = ACCESS_ONCE(sb->s_pins.first);
  58. if (!p) {
  59. rcu_read_unlock();
  60. break;
  61. }
  62. pin = hlist_entry(p, struct fs_pin, s_list);
  63. if (!atomic_long_inc_not_zero(&pin->count)) {
  64. rcu_read_unlock();
  65. cpu_relax();
  66. continue;
  67. }
  68. rcu_read_unlock();
  69. pin->kill(pin);
  70. }
  71. }