Skip to content

Commit 2e37c6c

Browse files
committed
fsnotify: Remove fsnotify_detach_group_marks()
The function is already mostly contained in what fsnotify_clear_marks_by_group() does. Just update that function to not select marks when all of them should be destroyed and remove fsnotify_detach_group_marks(). Reviewed-by: Miklos Szeredi <mszeredi@redhat.com> Reviewed-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Jan Kara <jack@suse.cz>
1 parent 18f2e0d commit 2e37c6c

4 files changed

Lines changed: 20 additions & 38 deletions

File tree

‎fs/notify/fsnotify.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ static inline void fsnotify_clear_marks_by_mount(struct vfsmount *mnt)
4040
{
4141
fsnotify_destroy_marks(&real_mount(mnt)->mnt_fsnotify_marks);
4242
}
43-
/* prepare for freeing all marks associated with given group */
44-
extern void fsnotify_detach_group_marks(struct fsnotify_group *group);
4543
/* Wait until all marks queued for destruction are destroyed */
4644
extern void fsnotify_wait_marks_destroyed(void);
4745

‎fs/notify/group.c‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,14 @@ void fsnotify_destroy_group(struct fsnotify_group *group)
6767
fsnotify_group_stop_queueing(group);
6868

6969
/* Clear all marks for this group and queue them for destruction */
70-
fsnotify_detach_group_marks(group);
70+
fsnotify_clear_marks_by_group(group, FSNOTIFY_OBJ_ALL_TYPES);
71+
72+
/*
73+
* Some marks can still be pinned when waiting for response from
74+
* userspace. Wait for those now. fsnotify_prepare_user_wait() will
75+
* not succeed now so this wait is race-free.
76+
*/
77+
wait_event(group->notification_waitq, !atomic_read(&group->user_waits));
7178

7279
/*
7380
* Wait until all marks get really destroyed. We could actually destroy

‎fs/notify/mark.c‎

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
* - The fs the inode is on is unmounted. (fsnotify_inode_delete/fsnotify_unmount_inodes)
6868
* - Something explicitly requests that it be removed. (fsnotify_destroy_mark)
6969
* - The fsnotify_group associated with the mark is going away and all such marks
70-
* need to be cleaned up. (fsnotify_detach_group_marks)
70+
* need to be cleaned up. (fsnotify_clear_marks_by_group)
7171
*
7272
* This has the very interesting property of being able to run concurrently with
7373
* any (or all) other directions.
@@ -651,7 +651,13 @@ void fsnotify_clear_marks_by_group(struct fsnotify_group *group,
651651
{
652652
struct fsnotify_mark *lmark, *mark;
653653
LIST_HEAD(to_free);
654+
struct list_head *head = &to_free;
654655

656+
/* Skip selection step if we want to clear all marks. */
657+
if (type == FSNOTIFY_OBJ_ALL_TYPES) {
658+
head = &group->marks_list;
659+
goto clear;
660+
}
655661
/*
656662
* We have to be really careful here. Anytime we drop mark_mutex, e.g.
657663
* fsnotify_clear_marks_by_inode() can come and free marks. Even in our
@@ -668,13 +674,14 @@ void fsnotify_clear_marks_by_group(struct fsnotify_group *group,
668674
}
669675
mutex_unlock(&group->mark_mutex);
670676

677+
clear:
671678
while (1) {
672679
mutex_lock_nested(&group->mark_mutex, SINGLE_DEPTH_NESTING);
673-
if (list_empty(&to_free)) {
680+
if (list_empty(head)) {
674681
mutex_unlock(&group->mark_mutex);
675682
break;
676683
}
677-
mark = list_first_entry(&to_free, struct fsnotify_mark, g_list);
684+
mark = list_first_entry(head, struct fsnotify_mark, g_list);
678685
fsnotify_get_mark(mark);
679686
fsnotify_detach_mark(mark);
680687
mutex_unlock(&group->mark_mutex);
@@ -683,38 +690,6 @@ void fsnotify_clear_marks_by_group(struct fsnotify_group *group,
683690
}
684691
}
685692

686-
/*
687-
* Given a group, prepare for freeing all the marks associated with that group.
688-
* The marks are attached to the list of marks prepared for destruction, the
689-
* caller is responsible for freeing marks in that list after SRCU period has
690-
* ended.
691-
*/
692-
void fsnotify_detach_group_marks(struct fsnotify_group *group)
693-
{
694-
struct fsnotify_mark *mark;
695-
696-
while (1) {
697-
mutex_lock_nested(&group->mark_mutex, SINGLE_DEPTH_NESTING);
698-
if (list_empty(&group->marks_list)) {
699-
mutex_unlock(&group->mark_mutex);
700-
break;
701-
}
702-
mark = list_first_entry(&group->marks_list,
703-
struct fsnotify_mark, g_list);
704-
fsnotify_get_mark(mark);
705-
fsnotify_detach_mark(mark);
706-
mutex_unlock(&group->mark_mutex);
707-
fsnotify_free_mark(mark);
708-
fsnotify_put_mark(mark);
709-
}
710-
/*
711-
* Some marks can still be pinned when waiting for response from
712-
* userspace. Wait for those now. fsnotify_prepare_user_wait() will
713-
* not succeed now so this wait is race-free.
714-
*/
715-
wait_event(group->notification_waitq, !atomic_read(&group->user_waits));
716-
}
717-
718693
/* Destroy all marks attached to inode / vfsmount */
719694
void fsnotify_destroy_marks(struct fsnotify_mark_connector __rcu **connp)
720695
{

‎include/linux/fsnotify_backend.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ struct fsnotify_mark_connector {
208208
spinlock_t lock;
209209
#define FSNOTIFY_OBJ_TYPE_INODE 0x01
210210
#define FSNOTIFY_OBJ_TYPE_VFSMOUNT 0x02
211+
#define FSNOTIFY_OBJ_ALL_TYPES (FSNOTIFY_OBJ_TYPE_INODE | \
212+
FSNOTIFY_OBJ_TYPE_VFSMOUNT)
211213
unsigned int flags; /* Type of object [lock] */
212214
union { /* Object pointer [lock] */
213215
struct inode *inode;

0 commit comments

Comments
 (0)