diff options
author | Amir Goldstein <amir73il@gmail.com> | 2018-04-20 19:10:49 -0400 |
---|---|---|
committer | Jan Kara <jack@suse.cz> | 2018-05-18 08:58:22 -0400 |
commit | d6f7b98bc8147abd290ead82922f8d83c525fb42 (patch) | |
tree | ca48d6cfca27bb48e0639fc2674cd35edc4ccc6d /fs/notify | |
parent | 3acf4e395260e3bd30a6fa29ba7eada4bf7566ca (diff) |
fsnotify: use type id to identify connector object type
An fsnotify_mark_connector is referencing a single type of object
(either inode or vfsmount). Instead of storing a type mask in
connector->flags, store a single type id in connector->type to
identify the type of object.
When a connector object is detached from the object, its type is set
to FSNOTIFY_OBJ_TYPE_DETACHED and this object is not going to be
reused.
The function fsnotify_clear_marks_by_group() is the only place where
type mask was used, so use type flags instead of type id to this
function.
This change is going to be more convenient when adding a new object
type (super block).
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Jan Kara <jack@suse.cz>
Diffstat (limited to 'fs/notify')
-rw-r--r-- | fs/notify/fdinfo.c | 6 | ||||
-rw-r--r-- | fs/notify/group.c | 2 | ||||
-rw-r--r-- | fs/notify/mark.c | 29 |
3 files changed, 18 insertions, 19 deletions
diff --git a/fs/notify/fdinfo.c b/fs/notify/fdinfo.c index d478629c728b..10aac1942c9f 100644 --- a/fs/notify/fdinfo.c +++ b/fs/notify/fdinfo.c | |||
@@ -77,7 +77,7 @@ static void inotify_fdinfo(struct seq_file *m, struct fsnotify_mark *mark) | |||
77 | struct inotify_inode_mark *inode_mark; | 77 | struct inotify_inode_mark *inode_mark; |
78 | struct inode *inode; | 78 | struct inode *inode; |
79 | 79 | ||
80 | if (!(mark->connector->flags & FSNOTIFY_OBJ_TYPE_INODE)) | 80 | if (mark->connector->type != FSNOTIFY_OBJ_TYPE_INODE) |
81 | return; | 81 | return; |
82 | 82 | ||
83 | inode_mark = container_of(mark, struct inotify_inode_mark, fsn_mark); | 83 | inode_mark = container_of(mark, struct inotify_inode_mark, fsn_mark); |
@@ -116,7 +116,7 @@ static void fanotify_fdinfo(struct seq_file *m, struct fsnotify_mark *mark) | |||
116 | if (mark->flags & FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY) | 116 | if (mark->flags & FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY) |
117 | mflags |= FAN_MARK_IGNORED_SURV_MODIFY; | 117 | mflags |= FAN_MARK_IGNORED_SURV_MODIFY; |
118 | 118 | ||
119 | if (mark->connector->flags & FSNOTIFY_OBJ_TYPE_INODE) { | 119 | if (mark->connector->type == FSNOTIFY_OBJ_TYPE_INODE) { |
120 | inode = igrab(mark->connector->inode); | 120 | inode = igrab(mark->connector->inode); |
121 | if (!inode) | 121 | if (!inode) |
122 | return; | 122 | return; |
@@ -126,7 +126,7 @@ static void fanotify_fdinfo(struct seq_file *m, struct fsnotify_mark *mark) | |||
126 | show_mark_fhandle(m, inode); | 126 | show_mark_fhandle(m, inode); |
127 | seq_putc(m, '\n'); | 127 | seq_putc(m, '\n'); |
128 | iput(inode); | 128 | iput(inode); |
129 | } else if (mark->connector->flags & FSNOTIFY_OBJ_TYPE_VFSMOUNT) { | 129 | } else if (mark->connector->type == FSNOTIFY_OBJ_TYPE_VFSMOUNT) { |
130 | struct mount *mnt = real_mount(mark->connector->mnt); | 130 | struct mount *mnt = real_mount(mark->connector->mnt); |
131 | 131 | ||
132 | seq_printf(m, "fanotify mnt_id:%x mflags:%x mask:%x ignored_mask:%x\n", | 132 | seq_printf(m, "fanotify mnt_id:%x mflags:%x mask:%x ignored_mask:%x\n", |
diff --git a/fs/notify/group.c b/fs/notify/group.c index b7a4b6a69efa..aa5468f23e45 100644 --- a/fs/notify/group.c +++ b/fs/notify/group.c | |||
@@ -67,7 +67,7 @@ void fsnotify_destroy_group(struct fsnotify_group *group) | |||
67 | fsnotify_group_stop_queueing(group); | 67 | fsnotify_group_stop_queueing(group); |
68 | 68 | ||
69 | /* Clear all marks for this group and queue them for destruction */ | 69 | /* Clear all marks for this group and queue them for destruction */ |
70 | fsnotify_clear_marks_by_group(group, FSNOTIFY_OBJ_ALL_TYPES); | 70 | fsnotify_clear_marks_by_group(group, FSNOTIFY_OBJ_ALL_TYPES_MASK); |
71 | 71 | ||
72 | /* | 72 | /* |
73 | * Some marks can still be pinned when waiting for response from | 73 | * Some marks can still be pinned when waiting for response from |
diff --git a/fs/notify/mark.c b/fs/notify/mark.c index e9191b416434..ef44808b28ca 100644 --- a/fs/notify/mark.c +++ b/fs/notify/mark.c | |||
@@ -119,9 +119,9 @@ static void __fsnotify_recalc_mask(struct fsnotify_mark_connector *conn) | |||
119 | if (mark->flags & FSNOTIFY_MARK_FLAG_ATTACHED) | 119 | if (mark->flags & FSNOTIFY_MARK_FLAG_ATTACHED) |
120 | new_mask |= mark->mask; | 120 | new_mask |= mark->mask; |
121 | } | 121 | } |
122 | if (conn->flags & FSNOTIFY_OBJ_TYPE_INODE) | 122 | if (conn->type == FSNOTIFY_OBJ_TYPE_INODE) |
123 | conn->inode->i_fsnotify_mask = new_mask; | 123 | conn->inode->i_fsnotify_mask = new_mask; |
124 | else if (conn->flags & FSNOTIFY_OBJ_TYPE_VFSMOUNT) | 124 | else if (conn->type == FSNOTIFY_OBJ_TYPE_VFSMOUNT) |
125 | real_mount(conn->mnt)->mnt_fsnotify_mask = new_mask; | 125 | real_mount(conn->mnt)->mnt_fsnotify_mask = new_mask; |
126 | } | 126 | } |
127 | 127 | ||
@@ -139,7 +139,7 @@ void fsnotify_recalc_mask(struct fsnotify_mark_connector *conn) | |||
139 | spin_lock(&conn->lock); | 139 | spin_lock(&conn->lock); |
140 | __fsnotify_recalc_mask(conn); | 140 | __fsnotify_recalc_mask(conn); |
141 | spin_unlock(&conn->lock); | 141 | spin_unlock(&conn->lock); |
142 | if (conn->flags & FSNOTIFY_OBJ_TYPE_INODE) | 142 | if (conn->type == FSNOTIFY_OBJ_TYPE_INODE) |
143 | __fsnotify_update_child_dentry_flags(conn->inode); | 143 | __fsnotify_update_child_dentry_flags(conn->inode); |
144 | } | 144 | } |
145 | 145 | ||
@@ -166,18 +166,18 @@ static struct inode *fsnotify_detach_connector_from_object( | |||
166 | { | 166 | { |
167 | struct inode *inode = NULL; | 167 | struct inode *inode = NULL; |
168 | 168 | ||
169 | if (conn->flags & FSNOTIFY_OBJ_TYPE_INODE) { | 169 | if (conn->type == FSNOTIFY_OBJ_TYPE_INODE) { |
170 | inode = conn->inode; | 170 | inode = conn->inode; |
171 | rcu_assign_pointer(inode->i_fsnotify_marks, NULL); | 171 | rcu_assign_pointer(inode->i_fsnotify_marks, NULL); |
172 | inode->i_fsnotify_mask = 0; | 172 | inode->i_fsnotify_mask = 0; |
173 | conn->inode = NULL; | 173 | conn->inode = NULL; |
174 | conn->flags &= ~FSNOTIFY_OBJ_TYPE_INODE; | 174 | conn->type = FSNOTIFY_OBJ_TYPE_DETACHED; |
175 | } else if (conn->flags & FSNOTIFY_OBJ_TYPE_VFSMOUNT) { | 175 | } else if (conn->type == FSNOTIFY_OBJ_TYPE_VFSMOUNT) { |
176 | rcu_assign_pointer(real_mount(conn->mnt)->mnt_fsnotify_marks, | 176 | rcu_assign_pointer(real_mount(conn->mnt)->mnt_fsnotify_marks, |
177 | NULL); | 177 | NULL); |
178 | real_mount(conn->mnt)->mnt_fsnotify_mask = 0; | 178 | real_mount(conn->mnt)->mnt_fsnotify_mask = 0; |
179 | conn->mnt = NULL; | 179 | conn->mnt = NULL; |
180 | conn->flags &= ~FSNOTIFY_OBJ_TYPE_VFSMOUNT; | 180 | conn->type = FSNOTIFY_OBJ_TYPE_DETACHED; |
181 | } | 181 | } |
182 | 182 | ||
183 | return inode; | 183 | return inode; |
@@ -442,10 +442,10 @@ static int fsnotify_attach_connector_to_object( | |||
442 | spin_lock_init(&conn->lock); | 442 | spin_lock_init(&conn->lock); |
443 | INIT_HLIST_HEAD(&conn->list); | 443 | INIT_HLIST_HEAD(&conn->list); |
444 | if (inode) { | 444 | if (inode) { |
445 | conn->flags = FSNOTIFY_OBJ_TYPE_INODE; | 445 | conn->type = FSNOTIFY_OBJ_TYPE_INODE; |
446 | conn->inode = igrab(inode); | 446 | conn->inode = igrab(inode); |
447 | } else { | 447 | } else { |
448 | conn->flags = FSNOTIFY_OBJ_TYPE_VFSMOUNT; | 448 | conn->type = FSNOTIFY_OBJ_TYPE_VFSMOUNT; |
449 | conn->mnt = mnt; | 449 | conn->mnt = mnt; |
450 | } | 450 | } |
451 | /* | 451 | /* |
@@ -479,8 +479,7 @@ static struct fsnotify_mark_connector *fsnotify_grab_connector( | |||
479 | if (!conn) | 479 | if (!conn) |
480 | goto out; | 480 | goto out; |
481 | spin_lock(&conn->lock); | 481 | spin_lock(&conn->lock); |
482 | if (!(conn->flags & (FSNOTIFY_OBJ_TYPE_INODE | | 482 | if (conn->type == FSNOTIFY_OBJ_TYPE_DETACHED) { |
483 | FSNOTIFY_OBJ_TYPE_VFSMOUNT))) { | ||
484 | spin_unlock(&conn->lock); | 483 | spin_unlock(&conn->lock); |
485 | srcu_read_unlock(&fsnotify_mark_srcu, idx); | 484 | srcu_read_unlock(&fsnotify_mark_srcu, idx); |
486 | return NULL; | 485 | return NULL; |
@@ -646,16 +645,16 @@ struct fsnotify_mark *fsnotify_find_mark( | |||
646 | return NULL; | 645 | return NULL; |
647 | } | 646 | } |
648 | 647 | ||
649 | /* Clear any marks in a group with given type */ | 648 | /* Clear any marks in a group with given type mask */ |
650 | void fsnotify_clear_marks_by_group(struct fsnotify_group *group, | 649 | void fsnotify_clear_marks_by_group(struct fsnotify_group *group, |
651 | unsigned int type) | 650 | unsigned int type_mask) |
652 | { | 651 | { |
653 | struct fsnotify_mark *lmark, *mark; | 652 | struct fsnotify_mark *lmark, *mark; |
654 | LIST_HEAD(to_free); | 653 | LIST_HEAD(to_free); |
655 | struct list_head *head = &to_free; | 654 | struct list_head *head = &to_free; |
656 | 655 | ||
657 | /* Skip selection step if we want to clear all marks. */ | 656 | /* Skip selection step if we want to clear all marks. */ |
658 | if (type == FSNOTIFY_OBJ_ALL_TYPES) { | 657 | if (type_mask == FSNOTIFY_OBJ_ALL_TYPES_MASK) { |
659 | head = &group->marks_list; | 658 | head = &group->marks_list; |
660 | goto clear; | 659 | goto clear; |
661 | } | 660 | } |
@@ -670,7 +669,7 @@ void fsnotify_clear_marks_by_group(struct fsnotify_group *group, | |||
670 | */ | 669 | */ |
671 | mutex_lock_nested(&group->mark_mutex, SINGLE_DEPTH_NESTING); | 670 | mutex_lock_nested(&group->mark_mutex, SINGLE_DEPTH_NESTING); |
672 | list_for_each_entry_safe(mark, lmark, &group->marks_list, g_list) { | 671 | list_for_each_entry_safe(mark, lmark, &group->marks_list, g_list) { |
673 | if (mark->connector->flags & type) | 672 | if ((1U << mark->connector->type) & type_mask) |
674 | list_move(&mark->g_list, &to_free); | 673 | list_move(&mark->g_list, &to_free); |
675 | } | 674 | } |
676 | mutex_unlock(&group->mark_mutex); | 675 | mutex_unlock(&group->mark_mutex); |