Skip to content

Commit e2a2994

Browse files
LinoSanfilippo333eparis
authored andcommitted
fsnotify: pass group to fsnotify_destroy_mark()
In fsnotify_destroy_mark() dont get the group from the passed mark anymore, but pass the group itself as an additional parameter to the function. Signed-off-by: Lino Sanfilippo <LinoSanfilippo@gmx.de> Signed-off-by: Eric Paris <eparis@redhat.com>
1 parent 986ab09 commit e2a2994

10 files changed

Lines changed: 38 additions & 34 deletions

File tree

‎fs/notify/dnotify/dnotify.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ void dnotify_flush(struct file *filp, fl_owner_t id)
201201

202202
/* nothing else could have found us thanks to the dnotify_mark_mutex */
203203
if (dn_mark->dn == NULL)
204-
fsnotify_destroy_mark(fsn_mark);
204+
fsnotify_destroy_mark(fsn_mark, dnotify_group);
205205

206206
mutex_unlock(&dnotify_mark_mutex);
207207

@@ -385,7 +385,7 @@ int fcntl_dirnotify(int fd, struct file *filp, unsigned long arg)
385385
spin_unlock(&fsn_mark->lock);
386386

387387
if (destroy)
388-
fsnotify_destroy_mark(fsn_mark);
388+
fsnotify_destroy_mark(fsn_mark, dnotify_group);
389389

390390
mutex_unlock(&dnotify_mark_mutex);
391391
fsnotify_put_mark(fsn_mark);

‎fs/notify/fanotify/fanotify_user.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ static int fanotify_remove_vfsmount_mark(struct fsnotify_group *group,
546546
removed = fanotify_mark_remove_from_mask(fsn_mark, mask, flags,
547547
&destroy_mark);
548548
if (destroy_mark)
549-
fsnotify_destroy_mark(fsn_mark);
549+
fsnotify_destroy_mark(fsn_mark, group);
550550

551551
fsnotify_put_mark(fsn_mark);
552552
if (removed & real_mount(mnt)->mnt_fsnotify_mask)
@@ -570,7 +570,7 @@ static int fanotify_remove_inode_mark(struct fsnotify_group *group,
570570
removed = fanotify_mark_remove_from_mask(fsn_mark, mask, flags,
571571
&destroy_mark);
572572
if (destroy_mark)
573-
fsnotify_destroy_mark(fsn_mark);
573+
fsnotify_destroy_mark(fsn_mark, group);
574574
/* matches the fsnotify_find_inode_mark() */
575575
fsnotify_put_mark(fsn_mark);
576576
if (removed & inode->i_fsnotify_mask)

‎fs/notify/inode_mark.c‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,16 @@ void fsnotify_clear_marks_by_inode(struct inode *inode)
9999
spin_unlock(&inode->i_lock);
100100

101101
list_for_each_entry_safe(mark, lmark, &free_list, i.free_i_list) {
102-
fsnotify_destroy_mark(mark);
102+
struct fsnotify_group *group;
103+
104+
spin_lock(&mark->lock);
105+
fsnotify_get_group(mark->group);
106+
group = mark->group;
107+
spin_unlock(&mark->lock);
108+
109+
fsnotify_destroy_mark(mark, group);
103110
fsnotify_put_mark(mark);
111+
fsnotify_put_group(group);
104112
}
105113
}
106114

‎fs/notify/inotify/inotify_fsnotify.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ static int inotify_handle_event(struct fsnotify_group *group,
132132
}
133133

134134
if (inode_mark->mask & IN_ONESHOT)
135-
fsnotify_destroy_mark(inode_mark);
135+
fsnotify_destroy_mark(inode_mark, group);
136136

137137
return ret;
138138
}

‎fs/notify/inotify/inotify_user.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ SYSCALL_DEFINE2(inotify_rm_watch, int, fd, __s32, wd)
816816

817817
ret = 0;
818818

819-
fsnotify_destroy_mark(&i_mark->fsn_mark);
819+
fsnotify_destroy_mark(&i_mark->fsn_mark, group);
820820

821821
/* match ref taken by inotify_idr_find */
822822
fsnotify_put_mark(&i_mark->fsn_mark);

‎fs/notify/mark.c‎

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -121,29 +121,19 @@ void fsnotify_put_mark(struct fsnotify_mark *mark)
121121
* The caller had better be holding a reference to this mark so we don't actually
122122
* do the final put under the mark->lock
123123
*/
124-
void fsnotify_destroy_mark(struct fsnotify_mark *mark)
124+
void fsnotify_destroy_mark(struct fsnotify_mark *mark,
125+
struct fsnotify_group *group)
125126
{
126-
struct fsnotify_group *group;
127127
struct inode *inode = NULL;
128128

129-
spin_lock(&mark->lock);
130-
/* dont get the group from a mark that is not alive yet */
131-
if (!(mark->flags & FSNOTIFY_MARK_FLAG_ALIVE)) {
132-
spin_unlock(&mark->lock);
133-
return;
134-
}
135-
fsnotify_get_group(mark->group);
136-
group = mark->group;
137-
spin_unlock(&mark->lock);
138-
139129
mutex_lock(&group->mark_mutex);
140130
spin_lock(&mark->lock);
141131

142132
/* something else already called this function on this mark */
143133
if (!(mark->flags & FSNOTIFY_MARK_FLAG_ALIVE)) {
144134
spin_unlock(&mark->lock);
145135
mutex_unlock(&group->mark_mutex);
146-
goto put_group;
136+
return;
147137
}
148138

149139
mark->flags &= ~FSNOTIFY_MARK_FLAG_ALIVE;
@@ -194,9 +184,6 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark)
194184
*/
195185

196186
atomic_dec(&group->num_marks);
197-
198-
put_group:
199-
fsnotify_put_group(group);
200187
}
201188

202189
void fsnotify_set_mark_mask_locked(struct fsnotify_mark *mark, __u32 mask)
@@ -307,7 +294,7 @@ void fsnotify_clear_marks_by_group_flags(struct fsnotify_group *group,
307294
mutex_unlock(&group->mark_mutex);
308295

309296
list_for_each_entry_safe(mark, lmark, &free_list, free_g_list) {
310-
fsnotify_destroy_mark(mark);
297+
fsnotify_destroy_mark(mark, group);
311298
fsnotify_put_mark(mark);
312299
}
313300
}

‎fs/notify/vfsmount_mark.c‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,16 @@ void fsnotify_clear_marks_by_mount(struct vfsmount *mnt)
4646
spin_unlock(&mnt->mnt_root->d_lock);
4747

4848
list_for_each_entry_safe(mark, lmark, &free_list, m.free_m_list) {
49-
fsnotify_destroy_mark(mark);
49+
struct fsnotify_group *group;
50+
51+
spin_lock(&mark->lock);
52+
fsnotify_get_group(mark->group);
53+
group = mark->group;
54+
spin_unlock(&mark->lock);
55+
56+
fsnotify_destroy_mark(mark, group);
5057
fsnotify_put_mark(mark);
58+
fsnotify_put_group(group);
5159
}
5260
}
5361

‎include/linux/fsnotify_backend.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,9 @@ extern void fsnotify_set_mark_mask_locked(struct fsnotify_mark *mark, __u32 mask
408408
/* attach the mark to both the group and the inode */
409409
extern int fsnotify_add_mark(struct fsnotify_mark *mark, struct fsnotify_group *group,
410410
struct inode *inode, struct vfsmount *mnt, int allow_dups);
411-
/* given a mark, flag it to be freed when all references are dropped */
412-
extern void fsnotify_destroy_mark(struct fsnotify_mark *mark);
411+
/* given a group and a mark, flag mark to be freed when all references are dropped */
412+
extern void fsnotify_destroy_mark(struct fsnotify_mark *mark,
413+
struct fsnotify_group *group);
413414
/* run all the marks in a group, and clear all of the vfsmount marks */
414415
extern void fsnotify_clear_vfsmount_marks_by_group(struct fsnotify_group *group);
415416
/* run all the marks in a group, and clear all of the inode marks */

‎kernel/audit_tree.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ static void untag_chunk(struct node *p)
249249
list_del_rcu(&chunk->hash);
250250
spin_unlock(&hash_lock);
251251
spin_unlock(&entry->lock);
252-
fsnotify_destroy_mark(entry);
252+
fsnotify_destroy_mark(entry, audit_tree_group);
253253
goto out;
254254
}
255255

@@ -291,7 +291,7 @@ static void untag_chunk(struct node *p)
291291
owner->root = new;
292292
spin_unlock(&hash_lock);
293293
spin_unlock(&entry->lock);
294-
fsnotify_destroy_mark(entry);
294+
fsnotify_destroy_mark(entry, audit_tree_group);
295295
fsnotify_put_mark(&new->mark); /* drop initial reference */
296296
goto out;
297297

@@ -331,7 +331,7 @@ static int create_chunk(struct inode *inode, struct audit_tree *tree)
331331
spin_unlock(&hash_lock);
332332
chunk->dead = 1;
333333
spin_unlock(&entry->lock);
334-
fsnotify_destroy_mark(entry);
334+
fsnotify_destroy_mark(entry, audit_tree_group);
335335
fsnotify_put_mark(entry);
336336
return 0;
337337
}
@@ -412,7 +412,7 @@ static int tag_chunk(struct inode *inode, struct audit_tree *tree)
412412
spin_unlock(&chunk_entry->lock);
413413
spin_unlock(&old_entry->lock);
414414

415-
fsnotify_destroy_mark(chunk_entry);
415+
fsnotify_destroy_mark(chunk_entry, audit_tree_group);
416416

417417
fsnotify_put_mark(chunk_entry);
418418
fsnotify_put_mark(old_entry);
@@ -443,7 +443,7 @@ static int tag_chunk(struct inode *inode, struct audit_tree *tree)
443443
spin_unlock(&hash_lock);
444444
spin_unlock(&chunk_entry->lock);
445445
spin_unlock(&old_entry->lock);
446-
fsnotify_destroy_mark(old_entry);
446+
fsnotify_destroy_mark(old_entry, audit_tree_group);
447447
fsnotify_put_mark(chunk_entry); /* drop initial reference */
448448
fsnotify_put_mark(old_entry); /* pair to fsnotify_find mark_entry */
449449
return 0;

‎kernel/audit_watch.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ static void audit_remove_parent_watches(struct audit_parent *parent)
349349
}
350350
mutex_unlock(&audit_filter_mutex);
351351

352-
fsnotify_destroy_mark(&parent->mark);
352+
fsnotify_destroy_mark(&parent->mark, audit_watch_group);
353353
}
354354

355355
/* Get path information necessary for adding watches. */
@@ -456,7 +456,7 @@ void audit_remove_watch_rule(struct audit_krule *krule)
456456

457457
if (list_empty(&parent->watches)) {
458458
audit_get_parent(parent);
459-
fsnotify_destroy_mark(&parent->mark);
459+
fsnotify_destroy_mark(&parent->mark, audit_watch_group);
460460
audit_put_parent(parent);
461461
}
462462
}

0 commit comments

Comments
 (0)