Skip to content

Commit 8212a60

Browse files
committed
fsnotify: Remove indirection from fsnotify_detach_mark()
fsnotify_detach_mark() calls fsnotify_destroy_inode_mark() or fsnotify_destroy_vfsmount_mark() to remove mark from object list. These two functions are however very similar and differ only in the lock they use to protect the object list of marks. Simplify the code by removing the indirection and removing mark from the object list in a common function. Reviewed-by: Miklos Szeredi <mszeredi@redhat.com> Reviewed-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Jan Kara <jack@suse.cz>
1 parent a03e2e4 commit 8212a60

4 files changed

Lines changed: 26 additions & 49 deletions

File tree

‎fs/notify/fsnotify.h‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ extern struct srcu_struct fsnotify_mark_srcu;
1818
extern int fsnotify_compare_groups(struct fsnotify_group *a,
1919
struct fsnotify_group *b);
2020

21-
/* vfsmount specific destruction of a mark */
22-
extern void fsnotify_destroy_vfsmount_mark(struct fsnotify_mark *mark);
23-
/* inode specific destruction of a mark */
24-
extern struct inode *fsnotify_destroy_inode_mark(struct fsnotify_mark *mark);
2521
/* Find mark belonging to given group in the list of marks */
2622
extern struct fsnotify_mark *fsnotify_find_mark(
2723
struct fsnotify_mark_connector *conn,

‎fs/notify/inode_mark.c‎

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,6 @@ void fsnotify_recalc_inode_mask(struct inode *inode)
3535
fsnotify_recalc_mask(inode->i_fsnotify_marks);
3636
}
3737

38-
struct inode *fsnotify_destroy_inode_mark(struct fsnotify_mark *mark)
39-
{
40-
struct inode *inode = mark->connector->inode;
41-
bool empty;
42-
43-
BUG_ON(!mutex_is_locked(&mark->group->mark_mutex));
44-
assert_spin_locked(&mark->lock);
45-
46-
spin_lock(&inode->i_lock);
47-
48-
hlist_del_init_rcu(&mark->obj_list);
49-
empty = hlist_empty(&mark->connector->list);
50-
mark->connector = NULL;
51-
52-
spin_unlock(&inode->i_lock);
53-
54-
fsnotify_recalc_mask(inode->i_fsnotify_marks);
55-
56-
return empty ? inode : NULL;
57-
}
58-
5938
/*
6039
* Given a group clear all of the inode marks associated with that group.
6140
*/

‎fs/notify/mark.c‎

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,30 @@ void fsnotify_recalc_mask(struct fsnotify_mark_connector *conn)
141141
}
142142
}
143143

144+
static struct inode *fsnotify_detach_from_object(struct fsnotify_mark *mark)
145+
{
146+
struct fsnotify_mark_connector *conn;
147+
struct inode *inode = NULL;
148+
spinlock_t *lock;
149+
150+
conn = mark->connector;
151+
if (conn->flags & FSNOTIFY_OBJ_TYPE_INODE)
152+
lock = &conn->inode->i_lock;
153+
else
154+
lock = &conn->mnt->mnt_root->d_lock;
155+
spin_lock(lock);
156+
hlist_del_init_rcu(&mark->obj_list);
157+
if (hlist_empty(&conn->list)) {
158+
if (conn->flags & FSNOTIFY_OBJ_TYPE_INODE)
159+
inode = conn->inode;
160+
}
161+
mark->connector = NULL;
162+
spin_unlock(lock);
163+
fsnotify_recalc_mask(conn);
164+
165+
return inode;
166+
}
167+
144168
/*
145169
* Remove mark from inode / vfsmount list, group list, drop inode reference
146170
* if we got one.
@@ -164,12 +188,8 @@ void fsnotify_detach_mark(struct fsnotify_mark *mark)
164188

165189
mark->flags &= ~FSNOTIFY_MARK_FLAG_ATTACHED;
166190

167-
if (mark->connector->flags & FSNOTIFY_OBJ_TYPE_INODE)
168-
inode = fsnotify_destroy_inode_mark(mark);
169-
else if (mark->connector->flags & FSNOTIFY_OBJ_TYPE_VFSMOUNT)
170-
fsnotify_destroy_vfsmount_mark(mark);
171-
else
172-
BUG();
191+
inode = fsnotify_detach_from_object(mark);
192+
173193
/*
174194
* Note that we didn't update flags telling whether inode cares about
175195
* what's happening with children. We update these flags from

‎fs/notify/vfsmount_mark.c‎

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,6 @@ void fsnotify_recalc_vfsmount_mask(struct vfsmount *mnt)
3939
fsnotify_recalc_mask(real_mount(mnt)->mnt_fsnotify_marks);
4040
}
4141

42-
void fsnotify_destroy_vfsmount_mark(struct fsnotify_mark *mark)
43-
{
44-
struct vfsmount *mnt = mark->connector->mnt;
45-
struct mount *m = real_mount(mnt);
46-
47-
BUG_ON(!mutex_is_locked(&mark->group->mark_mutex));
48-
assert_spin_locked(&mark->lock);
49-
50-
spin_lock(&mnt->mnt_root->d_lock);
51-
52-
hlist_del_init_rcu(&mark->obj_list);
53-
mark->connector = NULL;
54-
55-
spin_unlock(&mnt->mnt_root->d_lock);
56-
57-
fsnotify_recalc_mask(m->mnt_fsnotify_marks);
58-
}
59-
6042
/*
6143
* given a group and vfsmount, find the mark associated with that combination.
6244
* if found take a reference to that mark and return it, else return NULL

0 commit comments

Comments
 (0)