mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-29 05:44:11 +00:00
file: remove pointless wrapper
Only io_uring uses __close_fd_get_file(). All it does is hide current->files but io_uring accesses files_struct directly right now anyway so it's a bit pointless. Just rename pick_file() to file_close_fd_locked() and let io_uring use it. Add a lockdep assert in there that we expect the caller to hold file_lock while we're at it. Link: https://lore.kernel.org/r/20231130-vfs-files-fixes-v1-2-e73ca6f4ea83@kernel.org Reviewed-by: Jens Axboe <axboe@kernel.dk> Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
parent
a88c955fcf
commit
24fa3ae946
3 changed files with 11 additions and 16 deletions
23
fs/file.c
23
fs/file.c
|
@ -629,19 +629,23 @@ void fd_install(unsigned int fd, struct file *file)
|
||||||
EXPORT_SYMBOL(fd_install);
|
EXPORT_SYMBOL(fd_install);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* pick_file - return file associatd with fd
|
* file_close_fd_locked - return file associated with fd
|
||||||
* @files: file struct to retrieve file from
|
* @files: file struct to retrieve file from
|
||||||
* @fd: file descriptor to retrieve file for
|
* @fd: file descriptor to retrieve file for
|
||||||
*
|
*
|
||||||
|
* Doesn't take a separate reference count.
|
||||||
|
*
|
||||||
* Context: files_lock must be held.
|
* Context: files_lock must be held.
|
||||||
*
|
*
|
||||||
* Returns: The file associated with @fd (NULL if @fd is not open)
|
* Returns: The file associated with @fd (NULL if @fd is not open)
|
||||||
*/
|
*/
|
||||||
static struct file *pick_file(struct files_struct *files, unsigned fd)
|
struct file *file_close_fd_locked(struct files_struct *files, unsigned fd)
|
||||||
{
|
{
|
||||||
struct fdtable *fdt = files_fdtable(files);
|
struct fdtable *fdt = files_fdtable(files);
|
||||||
struct file *file;
|
struct file *file;
|
||||||
|
|
||||||
|
lockdep_assert_held(&files->file_lock);
|
||||||
|
|
||||||
if (fd >= fdt->max_fds)
|
if (fd >= fdt->max_fds)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -660,7 +664,7 @@ int close_fd(unsigned fd)
|
||||||
struct file *file;
|
struct file *file;
|
||||||
|
|
||||||
spin_lock(&files->file_lock);
|
spin_lock(&files->file_lock);
|
||||||
file = pick_file(files, fd);
|
file = file_close_fd_locked(files, fd);
|
||||||
spin_unlock(&files->file_lock);
|
spin_unlock(&files->file_lock);
|
||||||
if (!file)
|
if (!file)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
@ -707,7 +711,7 @@ static inline void __range_close(struct files_struct *files, unsigned int fd,
|
||||||
max_fd = min(max_fd, n);
|
max_fd = min(max_fd, n);
|
||||||
|
|
||||||
for (; fd <= max_fd; fd++) {
|
for (; fd <= max_fd; fd++) {
|
||||||
file = pick_file(files, fd);
|
file = file_close_fd_locked(files, fd);
|
||||||
if (file) {
|
if (file) {
|
||||||
spin_unlock(&files->file_lock);
|
spin_unlock(&files->file_lock);
|
||||||
filp_close(file, files);
|
filp_close(file, files);
|
||||||
|
@ -795,15 +799,6 @@ int __close_range(unsigned fd, unsigned max_fd, unsigned int flags)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* See file_close_fd() below, this variant assumes current->files->file_lock
|
|
||||||
* is held.
|
|
||||||
*/
|
|
||||||
struct file *__close_fd_get_file(unsigned int fd)
|
|
||||||
{
|
|
||||||
return pick_file(current->files, fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* file_close_fd - return file associated with fd
|
* file_close_fd - return file associated with fd
|
||||||
* @fd: file descriptor to retrieve file for
|
* @fd: file descriptor to retrieve file for
|
||||||
|
@ -818,7 +813,7 @@ struct file *file_close_fd(unsigned int fd)
|
||||||
struct file *file;
|
struct file *file;
|
||||||
|
|
||||||
spin_lock(&files->file_lock);
|
spin_lock(&files->file_lock);
|
||||||
file = pick_file(files, fd);
|
file = file_close_fd_locked(files, fd);
|
||||||
spin_unlock(&files->file_lock);
|
spin_unlock(&files->file_lock);
|
||||||
|
|
||||||
return file;
|
return file;
|
||||||
|
|
|
@ -179,7 +179,7 @@ extern struct file *do_file_open_root(const struct path *,
|
||||||
const char *, const struct open_flags *);
|
const char *, const struct open_flags *);
|
||||||
extern struct open_how build_open_how(int flags, umode_t mode);
|
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);
|
extern int build_open_flags(const struct open_how *how, struct open_flags *op);
|
||||||
extern struct file *__close_fd_get_file(unsigned int fd);
|
struct file *file_close_fd_locked(struct files_struct *files, unsigned fd);
|
||||||
|
|
||||||
long do_sys_ftruncate(unsigned int fd, loff_t length, int small);
|
long do_sys_ftruncate(unsigned int fd, loff_t length, int small);
|
||||||
int chmod_common(const struct path *path, umode_t mode);
|
int chmod_common(const struct path *path, umode_t mode);
|
||||||
|
|
|
@ -241,7 +241,7 @@ int io_close(struct io_kiocb *req, unsigned int issue_flags)
|
||||||
return -EAGAIN;
|
return -EAGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
file = __close_fd_get_file(close->fd);
|
file = file_close_fd_locked(files, close->fd);
|
||||||
spin_unlock(&files->file_lock);
|
spin_unlock(&files->file_lock);
|
||||||
if (!file)
|
if (!file)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
Loading…
Reference in a new issue