vfsmount_mark.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Copyright (C) 2008 Red Hat, Inc., Eric Paris <eparis@redhat.com>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2, or (at your option)
  7. * any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; see the file COPYING. If not, write to
  16. * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. #include <linux/fs.h>
  19. #include <linux/init.h>
  20. #include <linux/kernel.h>
  21. #include <linux/module.h>
  22. #include <linux/mount.h>
  23. #include <linux/mutex.h>
  24. #include <linux/spinlock.h>
  25. #include <linux/atomic.h>
  26. #include <linux/fsnotify_backend.h>
  27. #include "fsnotify.h"
  28. void fsnotify_clear_vfsmount_marks_by_group(struct fsnotify_group *group)
  29. {
  30. fsnotify_clear_marks_by_group_flags(group, FSNOTIFY_MARK_FLAG_VFSMOUNT);
  31. }
  32. /*
  33. * Recalculate the mnt->mnt_fsnotify_mask, or the mask of all FS_* event types
  34. * any notifier is interested in hearing for this mount point
  35. */
  36. void fsnotify_recalc_vfsmount_mask(struct vfsmount *mnt)
  37. {
  38. struct mount *m = real_mount(mnt);
  39. spin_lock(&mnt->mnt_root->d_lock);
  40. m->mnt_fsnotify_mask = fsnotify_recalc_mask(&m->mnt_fsnotify_marks);
  41. spin_unlock(&mnt->mnt_root->d_lock);
  42. }
  43. void fsnotify_destroy_vfsmount_mark(struct fsnotify_mark *mark)
  44. {
  45. struct vfsmount *mnt = mark->mnt;
  46. struct mount *m = real_mount(mnt);
  47. BUG_ON(!mutex_is_locked(&mark->group->mark_mutex));
  48. assert_spin_locked(&mark->lock);
  49. spin_lock(&mnt->mnt_root->d_lock);
  50. hlist_del_init_rcu(&mark->obj_list);
  51. mark->mnt = NULL;
  52. m->mnt_fsnotify_mask = fsnotify_recalc_mask(&m->mnt_fsnotify_marks);
  53. spin_unlock(&mnt->mnt_root->d_lock);
  54. }
  55. /*
  56. * given a group and vfsmount, find the mark associated with that combination.
  57. * if found take a reference to that mark and return it, else return NULL
  58. */
  59. struct fsnotify_mark *fsnotify_find_vfsmount_mark(struct fsnotify_group *group,
  60. struct vfsmount *mnt)
  61. {
  62. struct mount *m = real_mount(mnt);
  63. struct fsnotify_mark *mark;
  64. spin_lock(&mnt->mnt_root->d_lock);
  65. mark = fsnotify_find_mark(&m->mnt_fsnotify_marks, group);
  66. spin_unlock(&mnt->mnt_root->d_lock);
  67. return mark;
  68. }
  69. /*
  70. * Attach an initialized mark to a given group and vfsmount.
  71. * These marks may be used for the fsnotify backend to determine which
  72. * event types should be delivered to which groups.
  73. */
  74. int fsnotify_add_vfsmount_mark(struct fsnotify_mark *mark,
  75. struct fsnotify_group *group, struct vfsmount *mnt,
  76. int allow_dups)
  77. {
  78. struct mount *m = real_mount(mnt);
  79. int ret;
  80. mark->flags |= FSNOTIFY_MARK_FLAG_VFSMOUNT;
  81. BUG_ON(!mutex_is_locked(&group->mark_mutex));
  82. assert_spin_locked(&mark->lock);
  83. spin_lock(&mnt->mnt_root->d_lock);
  84. mark->mnt = mnt;
  85. ret = fsnotify_add_mark_list(&m->mnt_fsnotify_marks, mark, allow_dups);
  86. m->mnt_fsnotify_mask = fsnotify_recalc_mask(&m->mnt_fsnotify_marks);
  87. spin_unlock(&mnt->mnt_root->d_lock);
  88. return ret;
  89. }