Skip to content

Commit 7b8c9d7

Browse files
amir73iljankara
authored andcommitted
fsnotify: move fsnotify_open() hook into do_dentry_open()
fsnotify_open() hook is called only from high level system calls context and not called for the very many helpers to open files. This may makes sense for many of the special file open cases, but it is inconsistent with fsnotify_close() hook that is called for every last fput() of on a file object with FMODE_OPENED. As a result, it is possible to observe ACCESS, MODIFY and CLOSE events without ever observing an OPEN event. Fix this inconsistency by replacing all the fsnotify_open() hooks with a single hook inside do_dentry_open(). If there are special cases that would like to opt-out of the possible overhead of fsnotify() call in fsnotify_open(), they would probably also want to avoid the overhead of fsnotify() call in the rest of the fsnotify hooks, so they should be opening that file with the __FMODE_NONOTIFY flag. However, in the majority of those cases, the s_fsnotify_connectors optimization in fsnotify_parent() would be sufficient to avoid the overhead of fsnotify() call anyway. Signed-off-by: Amir Goldstein <[email protected]> Signed-off-by: Jan Kara <[email protected]> Message-Id: <[email protected]>
1 parent 7cdafe6 commit 7b8c9d7

File tree

4 files changed

+5
-8
lines changed

4 files changed

+5
-8
lines changed

fs/exec.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,6 @@ SYSCALL_DEFINE1(uselib, const char __user *, library)
152152
path_noexec(&file->f_path)))
153153
goto exit;
154154

155-
fsnotify_open(file);
156-
157155
error = -ENOEXEC;
158156

159157
read_lock(&binfmt_lock);
@@ -934,9 +932,6 @@ static struct file *do_open_execat(int fd, struct filename *name, int flags)
934932
if (err)
935933
goto exit;
936934

937-
if (name->name[0] != '\0')
938-
fsnotify_open(file);
939-
940935
out:
941936
return file;
942937

fs/fhandle.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ static long do_handle_open(int mountdirfd, struct file_handle __user *ufh,
242242
retval = PTR_ERR(file);
243243
} else {
244244
retval = fd;
245-
fsnotify_open(file);
246245
fd_install(fd, file);
247246
}
248247
path_put(&path);

fs/open.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,11 @@ static int do_dentry_open(struct file *f,
969969
}
970970
}
971971

972+
/*
973+
* Once we return a file with FMODE_OPENED, __fput() will call
974+
* fsnotify_close(), so we need fsnotify_open() here for symmetry.
975+
*/
976+
fsnotify_open(f);
972977
return 0;
973978

974979
cleanup_all:
@@ -1358,7 +1363,6 @@ static long do_sys_openat2(int dfd, const char __user *filename,
13581363
put_unused_fd(fd);
13591364
fd = PTR_ERR(f);
13601365
} else {
1361-
fsnotify_open(f);
13621366
fd_install(fd, f);
13631367
}
13641368
}

io_uring/openclose.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ int io_openat2(struct io_kiocb *req, unsigned int issue_flags)
150150

151151
if ((issue_flags & IO_URING_F_NONBLOCK) && !nonblock_set)
152152
file->f_flags &= ~O_NONBLOCK;
153-
fsnotify_open(file);
154153

155154
if (!fixed)
156155
fd_install(ret, file);

0 commit comments

Comments
 (0)