forked from luck/tmp_suning_uos_patched
get rid of fget_light()
instead of returning the flags by reference, we can just have the low-level primitive return those in lower bits of unsigned long, with struct file * derived from the rest. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
00e188ef6a
commit
bd2a31d522
56
fs/file.c
56
fs/file.c
|
@ -683,35 +683,65 @@ 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 unsigned long __fget_light(unsigned int fd, fmode_t mask)
|
||||
{
|
||||
struct files_struct *files = current->files;
|
||||
struct file *file;
|
||||
|
||||
*fput_needed = 0;
|
||||
if (atomic_read(&files->count) == 1) {
|
||||
file = __fcheck_files(files, fd);
|
||||
if (file && (file->f_mode & mask))
|
||||
file = NULL;
|
||||
if (!file || unlikely(file->f_mode & mask))
|
||||
return 0;
|
||||
return (unsigned long)file;
|
||||
} else {
|
||||
file = __fget(fd, mask);
|
||||
if (file)
|
||||
*fput_needed = 1;
|
||||
if (!file)
|
||||
return 0;
|
||||
return FDPUT_FPUT | (unsigned long)file;
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
struct file *fget_light(unsigned int fd, int *fput_needed)
|
||||
unsigned long __fdget(unsigned int fd)
|
||||
{
|
||||
return __fget_light(fd, FMODE_PATH, fput_needed);
|
||||
return __fget_light(fd, FMODE_PATH);
|
||||
}
|
||||
EXPORT_SYMBOL(fget_light);
|
||||
EXPORT_SYMBOL(__fdget);
|
||||
|
||||
struct file *fget_raw_light(unsigned int fd, int *fput_needed)
|
||||
unsigned long __fdget_raw(unsigned int fd)
|
||||
{
|
||||
return __fget_light(fd, 0, fput_needed);
|
||||
return __fget_light(fd, 0);
|
||||
}
|
||||
|
||||
unsigned long __fdget_pos(unsigned int fd)
|
||||
{
|
||||
struct files_struct *files = current->files;
|
||||
struct file *file;
|
||||
unsigned long v;
|
||||
|
||||
if (atomic_read(&files->count) == 1) {
|
||||
file = __fcheck_files(files, fd);
|
||||
v = 0;
|
||||
} else {
|
||||
file = __fget(fd, 0);
|
||||
v = FDPUT_FPUT;
|
||||
}
|
||||
if (!file)
|
||||
return 0;
|
||||
|
||||
if (file->f_mode & FMODE_ATOMIC_POS) {
|
||||
if (file_count(file) > 1) {
|
||||
v |= FDPUT_POS_UNLOCK;
|
||||
mutex_lock(&file->f_pos_lock);
|
||||
}
|
||||
}
|
||||
return v | (unsigned long)file;
|
||||
}
|
||||
|
||||
/*
|
||||
* We only lock f_pos if we have threads or if the file might be
|
||||
* shared with another process. In both cases we'll have an elevated
|
||||
* file count (done either by fdget() or by fork()).
|
||||
*/
|
||||
|
||||
void set_close_on_exec(unsigned int fd, int flag)
|
||||
{
|
||||
struct files_struct *files = current->files;
|
||||
|
|
|
@ -264,23 +264,9 @@ loff_t vfs_llseek(struct file *file, loff_t offset, int whence)
|
|||
}
|
||||
EXPORT_SYMBOL(vfs_llseek);
|
||||
|
||||
/*
|
||||
* We only lock f_pos if we have threads or if the file might be
|
||||
* shared with another process. In both cases we'll have an elevated
|
||||
* file count (done either by fdget() or by fork()).
|
||||
*/
|
||||
static inline struct fd fdget_pos(int fd)
|
||||
{
|
||||
struct fd f = fdget(fd);
|
||||
struct file *file = f.file;
|
||||
|
||||
if (file && (file->f_mode & FMODE_ATOMIC_POS)) {
|
||||
if (file_count(file) > 1) {
|
||||
f.flags |= FDPUT_POS_UNLOCK;
|
||||
mutex_lock(&file->f_pos_lock);
|
||||
}
|
||||
}
|
||||
return f;
|
||||
return __to_fd(__fdget_pos(fd));
|
||||
}
|
||||
|
||||
static inline void fdput_pos(struct fd f)
|
||||
|
|
|
@ -40,23 +40,24 @@ 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);
|
||||
extern struct file *fget_raw(unsigned int fd);
|
||||
extern unsigned long __fdget(unsigned int fd);
|
||||
extern unsigned long __fdget_raw(unsigned int fd);
|
||||
extern unsigned long __fdget_pos(unsigned int fd);
|
||||
|
||||
static inline struct fd __to_fd(unsigned long v)
|
||||
{
|
||||
return (struct fd){(struct file *)(v & ~3),v & 3};
|
||||
}
|
||||
|
||||
static inline struct fd fdget(unsigned int fd)
|
||||
{
|
||||
int b;
|
||||
struct file *f = fget_light(fd, &b);
|
||||
return (struct fd){f,b};
|
||||
return __to_fd(__fdget(fd));
|
||||
}
|
||||
|
||||
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};
|
||||
return __to_fd(__fdget_raw(fd));
|
||||
}
|
||||
|
||||
extern int f_dupfd(unsigned int from, struct file *file, unsigned flags);
|
||||
|
|
|
@ -812,7 +812,7 @@ struct file {
|
|||
#ifdef CONFIG_DEBUG_WRITECOUNT
|
||||
unsigned long f_mnt_write_state;
|
||||
#endif
|
||||
};
|
||||
} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
|
||||
|
||||
struct file_handle {
|
||||
__u32 handle_bytes;
|
||||
|
|
Loading…
Reference in New Issue
Block a user