diff --git a/fs/file_table.c b/fs/file_table.c index aa07d3684a2e8e13bdf4ae36eb5dc0ba98641223..cd4d87a82951f6169cd4f5fd8e24a61c45c16b8d 100644 --- a/fs/file_table.c +++ b/fs/file_table.c @@ -176,6 +176,7 @@ struct file *alloc_file(struct path *path, fmode_t mode, return file; file->f_path = *path; + file->f_inode = path->dentry->d_inode; file->f_mapping = path->dentry->d_inode->i_mapping; file->f_mode = mode; file->f_op = fop; @@ -258,6 +259,7 @@ static void __fput(struct file *file) drop_file_write_access(file); file->f_path.dentry = NULL; file->f_path.mnt = NULL; + file->f_inode = NULL; file_free(file); dput(dentry); mntput(mnt); diff --git a/fs/open.c b/fs/open.c index 62f907e3bc36aab08513270e6e9d636da96b9664..806d4589559f6739126b16c5bac1d3746609daa3 100644 --- a/fs/open.c +++ b/fs/open.c @@ -689,7 +689,7 @@ static int do_dentry_open(struct file *f, f->f_mode = FMODE_PATH; path_get(&f->f_path); - inode = file_inode(f); + inode = f->f_inode = f->f_path.dentry->d_inode; if (f->f_mode & FMODE_WRITE) { error = __get_file_write_access(inode, f->f_path.mnt); if (error) @@ -752,6 +752,7 @@ static int do_dentry_open(struct file *f, path_put(&f->f_path); f->f_path.mnt = NULL; f->f_path.dentry = NULL; + f->f_inode = NULL; return error; } diff --git a/include/linux/fs.h b/include/linux/fs.h index 4e686a099465ea5279d329938bb406d6c45aa1b9..74a907b8b950c5c7d8e2e736003258429f01abf0 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -769,6 +769,7 @@ struct file { } f_u; struct path f_path; #define f_dentry f_path.dentry + struct inode *f_inode; /* cached value */ const struct file_operations *f_op; /* @@ -2217,7 +2218,7 @@ static inline bool execute_ok(struct inode *inode) static inline struct inode *file_inode(struct file *f) { - return f->f_path.dentry->d_inode; + return f->f_inode; } /*