mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
fs: add filp_close_sync()
Currently close() already does a synchronous release of the last reference since the task is about to return to userspace and the deferral through task work buys nothing. Add a filp_close_sync() helper. We'll use that in the next patches. No functional changes. Link: https://patch.msgid.link/20260910-work-coredump-unlock-self-v4-5-a5c1800dc930@kernel.org Reviewed-by: NeilBrown <neil@brown.name> Reviewed-by: Oleg Nesterov <oleg@redhat.com> Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
This commit is contained in:
parent
5fe5e24a8f
commit
2b256ebe82
|
|
@ -198,6 +198,7 @@ extern struct file *do_file_open_root(const struct path *,
|
|||
extern struct open_how build_open_how(int flags, umode_t mode);
|
||||
extern int build_open_flags(const struct open_how *how, struct open_flags *op);
|
||||
struct file *file_close_fd_locked(struct files_struct *files, unsigned fd);
|
||||
int filp_close_sync(struct file *filp, fl_owner_t id);
|
||||
|
||||
int do_ftruncate(struct file *file, loff_t length, unsigned int flags);
|
||||
int chmod_common(const struct path *path, umode_t mode);
|
||||
|
|
|
|||
17
fs/open.c
17
fs/open.c
|
|
@ -1537,6 +1537,19 @@ int filp_close(struct file *filp, fl_owner_t id)
|
|||
}
|
||||
EXPORT_SYMBOL(filp_close);
|
||||
|
||||
/* Like filp_close() but the last reference is put right here. */
|
||||
int filp_close_sync(struct file *filp, fl_owner_t id)
|
||||
{
|
||||
int retval;
|
||||
|
||||
/* Kernel threads must never put their final reference here. */
|
||||
VFS_WARN_ON_ONCE(current->flags & PF_KTHREAD);
|
||||
retval = filp_flush(filp, id);
|
||||
fput_close_sync(filp);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*
|
||||
* Careful here! We test whether the file pointer is NULL before
|
||||
* releasing the fd. This ensures that one clone task can't release
|
||||
|
|
@ -1551,13 +1564,11 @@ SYSCALL_DEFINE1(close, unsigned int, fd)
|
|||
if (!file)
|
||||
return -EBADF;
|
||||
|
||||
retval = filp_flush(file, current->files);
|
||||
|
||||
/*
|
||||
* We're returning to user space. Don't bother
|
||||
* with any delayed fput() cases.
|
||||
*/
|
||||
fput_close_sync(file);
|
||||
retval = filp_close_sync(file, current->files);
|
||||
|
||||
if (likely(retval == 0))
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user