From f55e00e40e6aba3e1e8fc701a7069a0b7a0868b7 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Mon, 3 Mar 2014 14:43:03 -0800 Subject: [PATCH 2/2] vfs: get rid of old legacy "f{get,put}_[raw_]_light()" interfaces Everything but the net/socket.c use has long since been converted to the fdget() model that has a cleaner calling convention, so just get rid of the old interface and teach the socket code to use the new model using a trivial shim layer. Signed-off-by: Linus Torvalds --- fs/file.c | 30 +++++++++++++++--------------- include/linux/file.h | 24 ++---------------------- net/socket.c | 17 ++++++++++++----- 3 files changed, 29 insertions(+), 42 deletions(-) diff --git a/fs/file.c b/fs/file.c index db25c2bdfe46..baaa755f3919 100644 --- a/fs/file.c +++ b/fs/file.c @@ -683,33 +683,33 @@ EXPORT_SYMBOL(fget_raw); * The fput_needed flag returned by fget_light should be passed to the * corresponding fput_light. */ -struct file *__fget_light(unsigned int fd, fmode_t mask, int *fput_needed) +static inline struct fd __fdget(unsigned int fd, fmode_t mask) { struct files_struct *files = current->files; - struct file *file; + struct fd f = { NULL, }; - *fput_needed = 0; if (atomic_read(&files->count) == 1) { - file = __fcheck_files(files, fd); - if (file && (file->f_mode & mask)) - file = NULL; + f.file = __fcheck_files(files, fd); + if (f.file && (f.file->f_mode & mask)) + f.file = NULL; } else { - file = __fget(fd, mask); - if (file) - *fput_needed = 1; + f.file = __fget(fd, mask); + if (f.file) + f.flags = FDPUT_FPUT; } - return file; + return f; } -struct file *fget_light(unsigned int fd, int *fput_needed) + +struct fd fdget(unsigned int fd) { - return __fget_light(fd, FMODE_PATH, fput_needed); + return __fdget(fd, FMODE_PATH); } -EXPORT_SYMBOL(fget_light); +EXPORT_SYMBOL(fdget); -struct file *fget_raw_light(unsigned int fd, int *fput_needed) +struct fd fdget_raw(unsigned int fd) { - return __fget_light(fd, 0, fput_needed); + return __fdget(fd, 0); } void set_close_on_exec(unsigned int fd, int flag) diff --git a/include/linux/file.h b/include/linux/file.h index f2517fa2d610..1f6b39394a9e 100644 --- a/include/linux/file.h +++ b/include/linux/file.h @@ -20,12 +20,6 @@ struct path; extern struct file *alloc_file(struct path *, fmode_t mode, const struct file_operations *fop); -static inline void fput_light(struct file *file, int fput_needed) -{ - if (fput_needed) - fput(file); -} - struct fd { struct file *file; unsigned int flags; @@ -40,24 +34,10 @@ static inline void fdput(struct fd fd) } extern struct file *fget(unsigned int fd); -extern struct file *fget_light(unsigned int fd, int *fput_needed); - -static inline struct fd fdget(unsigned int fd) -{ - int b; - struct file *f = fget_light(fd, &b); - return (struct fd){f,b}; -} - extern struct file *fget_raw(unsigned int fd); -extern struct file *fget_raw_light(unsigned int fd, int *fput_needed); -static inline struct fd fdget_raw(unsigned int fd) -{ - int b; - struct file *f = fget_raw_light(fd, &b); - return (struct fd){f,b}; -} +extern struct fd fdget(unsigned int fd); +extern struct fd fdget_raw(unsigned int fd); extern int f_dupfd(unsigned int from, struct file *file, unsigned flags); extern int replace_fd(unsigned fd, struct file *file, unsigned flags); diff --git a/net/socket.c b/net/socket.c index 879933aaed4c..5ef37af499b3 100644 --- a/net/socket.c +++ b/net/socket.c @@ -448,18 +448,25 @@ struct socket *sockfd_lookup(int fd, int *err) } EXPORT_SYMBOL(sockfd_lookup); +static void fput_light(struct file *file, int flags) +{ + struct fd f = { file, flags }; + fdput(f); +} + static struct socket *sockfd_lookup_light(int fd, int *err, int *fput_needed) { - struct file *file; + struct fd f; struct socket *sock; *err = -EBADF; - file = fget_light(fd, fput_needed); - if (file) { - sock = sock_from_file(file, err); + f = fdget(fd); + *fput_needed = f.flags; + if (f.file) { + sock = sock_from_file(f.file, err); if (sock) return sock; - fput_light(file, *fput_needed); + fdput(f); } return NULL; } -- 1.9.0