Skip to content

Commit 40554c3

Browse files
committed
fsnotify: allow addition of duplicate fsnotify marks
This patch allows a task to add a second fsnotify mark to an inode for the same group. This mark will be added to the end of the inode's list and this will never be found by the stand fsnotify_find_mark() function. This is useful if a user wants to add a new mark before removing the old one. Signed-off-by: Eric Paris <eparis@redhat.com>
1 parent 9e1c743 commit 40554c3

5 files changed

Lines changed: 9 additions & 7 deletions

File tree

‎fs/notify/dnotify/dnotify.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ int fcntl_dirnotify(int fd, struct file *filp, unsigned long arg)
362362
dnentry = container_of(entry, struct dnotify_mark_entry, fsn_entry);
363363
spin_lock(&entry->lock);
364364
} else {
365-
fsnotify_add_mark(new_entry, dnotify_group, inode);
365+
fsnotify_add_mark(new_entry, dnotify_group, inode, 0);
366366
spin_lock(&new_entry->lock);
367367
entry = new_entry;
368368
dnentry = new_dnentry;

‎fs/notify/inode_mark.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,10 @@ void fsnotify_init_mark(struct fsnotify_mark_entry *entry,
312312
* event types should be delivered to which group and for which inodes.
313313
*/
314314
int fsnotify_add_mark(struct fsnotify_mark_entry *entry,
315-
struct fsnotify_group *group, struct inode *inode)
315+
struct fsnotify_group *group, struct inode *inode,
316+
int allow_dups)
316317
{
317-
struct fsnotify_mark_entry *lentry;
318+
struct fsnotify_mark_entry *lentry = NULL;
318319
int ret = 0;
319320

320321
inode = igrab(inode);
@@ -331,7 +332,8 @@ int fsnotify_add_mark(struct fsnotify_mark_entry *entry,
331332
spin_lock(&group->mark_lock);
332333
spin_lock(&inode->i_lock);
333334

334-
lentry = fsnotify_find_mark_entry(group, inode);
335+
if (!allow_dups)
336+
lentry = fsnotify_find_mark_entry(group, inode);
335337
if (!lentry) {
336338
entry->group = group;
337339
entry->inode = inode;

‎fs/notify/inotify/inotify_user.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ static int inotify_new_watch(struct fsnotify_group *group,
651651
goto out_err;
652652

653653
/* we are on the idr, now get on the inode */
654-
ret = fsnotify_add_mark(&tmp_ientry->fsn_entry, group, inode);
654+
ret = fsnotify_add_mark(&tmp_ientry->fsn_entry, group, inode, 0);
655655
if (ret) {
656656
/* we failed to get on the inode, get off the idr */
657657
inotify_remove_from_idr(group, tmp_ientry);

‎include/linux/fsnotify_backend.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ extern struct fsnotify_mark_entry *fsnotify_find_mark_entry(struct fsnotify_grou
345345
/* copy the values from old into new */
346346
extern void fsnotify_duplicate_mark(struct fsnotify_mark_entry *new, struct fsnotify_mark_entry *old);
347347
/* attach the mark to both the group and the inode */
348-
extern int fsnotify_add_mark(struct fsnotify_mark_entry *entry, struct fsnotify_group *group, struct inode *inode);
348+
extern int fsnotify_add_mark(struct fsnotify_mark_entry *entry, struct fsnotify_group *group, struct inode *inode, int allow_dups);
349349
/* given a mark, flag it to be freed when all references are dropped */
350350
extern void fsnotify_destroy_mark_by_entry(struct fsnotify_mark_entry *entry);
351351
/* run all the marks in a group, and flag them to be freed */

‎kernel/audit_watch.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ static struct audit_parent *audit_init_parent(struct nameidata *ndp)
161161

162162
fsnotify_init_mark(&parent->mark, audit_watch_free_mark);
163163
parent->mark.mask = AUDIT_FS_WATCH;
164-
ret = fsnotify_add_mark(&parent->mark, audit_watch_group, inode);
164+
ret = fsnotify_add_mark(&parent->mark, audit_watch_group, inode, 0);
165165
if (ret < 0) {
166166
audit_free_parent(parent);
167167
return ERR_PTR(ret);

0 commit comments

Comments
 (0)