History

Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs

Pull more VFS bits from Al Viro: "Unfortunately, it looks like xattr series will have to wait until the next cycle ;-/ This pile contains 9p cleanups and fixes (races in v9fs_fid_add() etc), fixup for nommu breakage in shmem.c, several cleanups and a bit more file_inode() work" * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: constify path_get/path_put and fs_struct.c stuff fix nommu breakage in shmem.c cache the value of file_inode() in struct file 9p: if v9fs_fid_lookup() gets to asking server, it'd better have hashed dentry 9p: make sure ->lookup() adds fid to the right dentry 9p: untangle ->lookup() a bit 9p: double iput() in ->lookup() if d_materialise_unique() fails 9p: v9fs_fid_add() can't fail now v9fs: get rid of v9fs_dentry 9p: turn fid->dlist into hlist 9p: don't bother with private lock in ->d_fsdata; dentry->d_lock will do just fine more file_inode() open-coded instances selinux: opened file can't have NULL or negative ->f_path.dentry (In the meantime, the hlist traversal macros have changed, so this required a semantic conflict fixup for the newly hlistified fid->dlist)

Linus Torvalds committed 13 years ago

Commit 56a79b72 parents 1c82315 dcf787f26 files · +108 −171Browse files

Unified · Split

26 files
  1. arch/s390/hypfs/inode.c +2 −4
  2. arch/x86/kernel/msr.c +4 −5
  3. drivers/staging/comedi/comedi_fops.c +7 −7
  4. drivers/tty/tty_io.c +6 −10
  5. fs/9p/fid.c +25 −29
  6. fs/9p/fid.h +1 −21
  7. fs/9p/vfs_dentry.c +4 −13
  8. fs/9p/vfs_inode.c +14 −26
  9. fs/9p/vfs_inode_dotl.c +7 −12
  10. fs/ext4/indirect.c +1 −1
  11. fs/f2fs/file.c +3 −3
  12. fs/file_table.c +2 −0
  13. fs/fs_struct.c +3 −3
  14. fs/fuse/dev.c +1 −1
  15. fs/fuse/file.c +12 −12
  16. fs/internal.h +1 −1
  17. fs/namei.c +2 −2
  18. fs/open.c +2 −1
  19. fs/seq_file.c +1 −1
  20. include/linux/fs.h +2 −1
  21. include/linux/fs_struct.h +2 −2
  22. include/linux/path.h +2 −2
  23. include/net/9p/client.h +1 −1
  24. kernel/futex.c +1 −1
  25. mm/shmem.c +2 −3
  26. security/selinux/hooks.c +0 −9
arch/s390/hypfs/inode.c+2−4
@@ -171,12 +171,10 @@ static ssize_t hypfs_aio_write(struct kiocb *iocb, const struct iovec *iov, · 170 unmodified lines
171171 unsigned long nr_segs, loff_t offset)
172172 {
173173 int rc;
174− struct super_block *sb;
175− struct hypfs_sb_info *fs_info;
174+ struct super_block *sb = file_inode(iocb->ki_filp)->i_sb;
175+ struct hypfs_sb_info *fs_info = sb->s_fs_info;
176176 size_t count = iov_length(iov, nr_segs);
177177
178− sb = iocb->ki_filp->f_path.dentry->d_inode->i_sb;
179− fs_info = sb->s_fs_info;
180178 /*
181179 * Currently we only allow one update per second for two reasons:
182180 * 1. diag 204 is VERY expensive
arch/x86/kernel/msr.c+4−5
@@ -71,7 +71,7 @@ static ssize_t msr_read(struct file *file, char __user *buf, · 70 unmodified lines
7171 u32 __user *tmp = (u32 __user *) buf;
7272 u32 data[2];
7373 u32 reg = *ppos;
74− int cpu = iminor(file->f_path.dentry->d_inode);
74+ int cpu = iminor(file_inode(file));
7575 int err = 0;
7676 ssize_t bytes = 0;
7777
@@ -99,7 +99,7 @@ static ssize_t msr_write(struct file *file, const char __user *buf, · 21 unmodified lines
9999 const u32 __user *tmp = (const u32 __user *)buf;
100100 u32 data[2];
101101 u32 reg = *ppos;
102− int cpu = iminor(file->f_path.dentry->d_inode);
102+ int cpu = iminor(file_inode(file));
103103 int err = 0;
104104 ssize_t bytes = 0;
105105
@@ -125,7 +125,7 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg) · 19 unmodified lines
125125 {
126126 u32 __user *uregs = (u32 __user *)arg;
127127 u32 regs[8];
128− int cpu = iminor(file->f_path.dentry->d_inode);
128+ int cpu = iminor(file_inode(file));
129129 int err;
130130
131131 switch (ioc) {
@@ -171,13 +171,12 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg) · 39 unmodified lines
171171
172172 static int msr_open(struct inode *inode, struct file *file)
173173 {
174− unsigned int cpu;
174+ unsigned int cpu = iminor(file_inode(file));
175175 struct cpuinfo_x86 *c;
176176
177177 if (!capable(CAP_SYS_RAWIO))
178178 return -EPERM;
179179
180− cpu = iminor(file->f_path.dentry->d_inode);
181180 if (cpu >= nr_cpu_ids || !cpu_online(cpu))
182181 return -ENXIO; /* No such CPU */
183182
drivers/staging/comedi/comedi_fops.c+7−7
@@ -580,7 +580,7 @@ static int do_devinfo_ioctl(struct comedi_device *dev, · 579 unmodified lines
580580 struct comedi_devinfo __user *arg,
581581 struct file *file)
582582 {
583− const unsigned minor = iminor(file->f_dentry->d_inode);
583+ const unsigned minor = iminor(file_inode(file));
584584 struct comedi_file_info *info = comedi_file_info_from_minor(minor);
585585 struct comedi_subdevice *s;
586586 struct comedi_devinfo devinfo;
@@ -1615,7 +1615,7 @@ static int do_poll_ioctl(struct comedi_device *dev, unsigned int arg, · 1028 unmodified lines
16151615 static long comedi_unlocked_ioctl(struct file *file, unsigned int cmd,
16161616 unsigned long arg)
16171617 {
1618− const unsigned minor = iminor(file->f_dentry->d_inode);
1618+ const unsigned minor = iminor(file_inode(file));
16191619 struct comedi_file_info *info = comedi_file_info_from_minor(minor);
16201620 struct comedi_device *dev = comedi_dev_from_file_info(info);
16211621 int rc;
@@ -1743,7 +1743,7 @@ static struct vm_operations_struct comedi_vm_ops = { · 121 unmodified lines
17431743
17441744 static int comedi_mmap(struct file *file, struct vm_area_struct *vma)
17451745 {
1746− const unsigned minor = iminor(file->f_dentry->d_inode);
1746+ const unsigned minor = iminor(file_inode(file));
17471747 struct comedi_file_info *info = comedi_file_info_from_minor(minor);
17481748 struct comedi_device *dev = comedi_dev_from_file_info(info);
17491749 struct comedi_subdevice *s;
@@ -1823,7 +1823,7 @@ done: · 73 unmodified lines
18231823 static unsigned int comedi_poll(struct file *file, poll_table *wait)
18241824 {
18251825 unsigned int mask = 0;
1826− const unsigned minor = iminor(file->f_dentry->d_inode);
1826+ const unsigned minor = iminor(file_inode(file));
18271827 struct comedi_file_info *info = comedi_file_info_from_minor(minor);
18281828 struct comedi_device *dev = comedi_dev_from_file_info(info);
18291829 struct comedi_subdevice *s;
@@ -1869,7 +1869,7 @@ static ssize_t comedi_write(struct file *file, const char __user *buf, · 39 unmodified lines
18691869 struct comedi_async *async;
18701870 int n, m, count = 0, retval = 0;
18711871 DECLARE_WAITQUEUE(wait, current);
1872− const unsigned minor = iminor(file->f_dentry->d_inode);
1872+ const unsigned minor = iminor(file_inode(file));
18731873 struct comedi_file_info *info = comedi_file_info_from_minor(minor);
18741874 struct comedi_device *dev = comedi_dev_from_file_info(info);
18751875
@@ -1964,7 +1964,7 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes, · 88 unmodified lines
19641964 struct comedi_async *async;
19651965 int n, m, count = 0, retval = 0;
19661966 DECLARE_WAITQUEUE(wait, current);
1967− const unsigned minor = iminor(file->f_dentry->d_inode);
1967+ const unsigned minor = iminor(file_inode(file));
19681968 struct comedi_file_info *info = comedi_file_info_from_minor(minor);
19691969 struct comedi_device *dev = comedi_dev_from_file_info(info);
19701970
@@ -2133,7 +2133,7 @@ ok: · 162 unmodified lines
21332133
21342134 static int comedi_fasync(int fd, struct file *file, int on)
21352135 {
2136− const unsigned minor = iminor(file->f_dentry->d_inode);
2136+ const unsigned minor = iminor(file_inode(file));
21372137 struct comedi_device *dev = comedi_dev_from_minor(minor);
21382138
21392139 if (!dev)
drivers/tty/tty_io.c+6−10
@@ -960,11 +960,10 @@ static ssize_t tty_read(struct file *file, char __user *buf, size_t count, · 959 unmodified lines
960960 loff_t *ppos)
961961 {
962962 int i;
963− struct inode *inode = file->f_path.dentry->d_inode;
964963 struct tty_struct *tty = file_tty(file);
965964 struct tty_ldisc *ld;
966965
967− if (tty_paranoia_check(tty, inode, "tty_read"))
966+ if (tty_paranoia_check(tty, file_inode(file), "tty_read"))
968967 return -EIO;
969968 if (!tty || (test_bit(TTY_IO_ERROR, &tty->flags)))
970969 return -EIO;
@@ -1132,12 +1131,11 @@ void tty_write_message(struct tty_struct *tty, char *msg) · 161 unmodified lines
11321131 static ssize_t tty_write(struct file *file, const char __user *buf,
11331132 size_t count, loff_t *ppos)
11341133 {
1135− struct inode *inode = file->f_path.dentry->d_inode;
11361134 struct tty_struct *tty = file_tty(file);
11371135 struct tty_ldisc *ld;
11381136 ssize_t ret;
11391137
1140− if (tty_paranoia_check(tty, inode, "tty_write"))
1138+ if (tty_paranoia_check(tty, file_inode(file), "tty_write"))
11411139 return -EIO;
11421140 if (!tty || !tty->ops->write ||
11431141 (test_bit(TTY_IO_ERROR, &tty->flags)))
@@ -2047,7 +2045,7 @@ static unsigned int tty_poll(struct file *filp, poll_table *wait) · 903 unmodified lines
20472045 struct tty_ldisc *ld;
20482046 int ret = 0;
20492047
2050− if (tty_paranoia_check(tty, filp->f_path.dentry->d_inode, "tty_poll"))
2048+ if (tty_paranoia_check(tty, file_inode(filp), "tty_poll"))
20512049 return 0;
20522050
20532051 ld = tty_ldisc_ref_wait(tty);
@@ -2063,7 +2061,7 @@ static int __tty_fasync(int fd, struct file *filp, int on) · 9 unmodified lines
20632061 unsigned long flags;
20642062 int retval = 0;
20652063
2066− if (tty_paranoia_check(tty, filp->f_path.dentry->d_inode, "tty_fasync"))
2064+ if (tty_paranoia_check(tty, file_inode(filp), "tty_fasync"))
20672065 goto out;
20682066
20692067 retval = fasync_helper(fd, filp, on, &tty->fasync);
@@ -2637,9 +2635,8 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg) · 567 unmodified lines
26372635 void __user *p = (void __user *)arg;
26382636 int retval;
26392637 struct tty_ldisc *ld;
2640− struct inode *inode = file->f_dentry->d_inode;
26412638
2642− if (tty_paranoia_check(tty, inode, "tty_ioctl"))
2639+ if (tty_paranoia_check(tty, file_inode(file), "tty_ioctl"))
26432640 return -EINVAL;
26442641
26452642 real_tty = tty_pair_get_tty(tty);
@@ -2780,12 +2777,11 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg) · 134 unmodified lines
27802777 static long tty_compat_ioctl(struct file *file, unsigned int cmd,
27812778 unsigned long arg)
27822779 {
2783− struct inode *inode = file->f_dentry->d_inode;
27842780 struct tty_struct *tty = file_tty(file);
27852781 struct tty_ldisc *ld;
27862782 int retval = -ENOIOCTLCMD;
27872783
2788− if (tty_paranoia_check(tty, inode, "tty_ioctl"))
2784+ if (tty_paranoia_check(tty, file_inode(file), "tty_ioctl"))
27892785 return -EINVAL;
27902786
27912787 if (tty->ops->compat_ioctl) {
fs/9p/fid.c+25−29
@@ -41,29 +41,16 @@ · 40 unmodified lines
4141 *
4242 */
4343
44−int v9fs_fid_add(struct dentry *dentry, struct p9_fid *fid)
44+static inline void __add_fid(struct dentry *dentry, struct p9_fid *fid)
4545 {
46− struct v9fs_dentry *dent;
47−
48− p9_debug(P9_DEBUG_VFS, "fid %d dentry %s\n",
49− fid->fid, dentry->d_name.name);
50−
51− dent = dentry->d_fsdata;
52− if (!dent) {
53− dent = kmalloc(sizeof(struct v9fs_dentry), GFP_KERNEL);
54− if (!dent)
55− return -ENOMEM;
56−
57− spin_lock_init(&dent->lock);
58− INIT_LIST_HEAD(&dent->fidlist);
59− dentry->d_fsdata = dent;
60− }
61−
62− spin_lock(&dent->lock);
63− list_add(&fid->dlist, &dent->fidlist);
64− spin_unlock(&dent->lock);
46+ hlist_add_head(&fid->dlist, (struct hlist_head *)&dentry->d_fsdata);
47+}
6548
66− return 0;
49+void v9fs_fid_add(struct dentry *dentry, struct p9_fid *fid)
50+{
51+ spin_lock(&dentry->d_lock);
52+ __add_fid(dentry, fid);
53+ spin_unlock(&dentry->d_lock);
6754 }
6855
6956 /**
@@ -76,23 +63,23 @@ int v9fs_fid_add(struct dentry *dentry, struct p9_fid *fid) · 6 unmodified lines
7663
7764 static struct p9_fid *v9fs_fid_find(struct dentry *dentry, kuid_t uid, int any)
7865 {
79− struct v9fs_dentry *dent;
8066 struct p9_fid *fid, *ret;
8167
8268 p9_debug(P9_DEBUG_VFS, " dentry: %s (%p) uid %d any %d\n",
8369 dentry->d_name.name, dentry, from_kuid(&init_user_ns, uid),
8470 any);
85− dent = (struct v9fs_dentry *) dentry->d_fsdata;
8671 ret = NULL;
87− if (dent) {
88− spin_lock(&dent->lock);
89− list_for_each_entry(fid, &dent->fidlist, dlist) {
72+ /* we'll recheck under lock if there's anything to look in */
73+ if (dentry->d_fsdata) {
74+ struct hlist_head *h = (struct hlist_head *)&dentry->d_fsdata;
75+ spin_lock(&dentry->d_lock);
76+ hlist_for_each_entry(fid, h, dlist) {
9077 if (any || uid_eq(fid->uid, uid)) {
9178 ret = fid;
9279 break;
9380 }
9481 }
95− spin_unlock(&dent->lock);
82+ spin_unlock(&dentry->d_lock);
9683 }
9784
9885 return ret;
@@ -215,8 +202,17 @@ static struct p9_fid *v9fs_fid_lookup_with_uid(struct dentry *dentry, · 116 unmodified lines
215202 }
216203 kfree(wnames);
217204 fid_out:
218− if (!IS_ERR(fid))
219− v9fs_fid_add(dentry, fid);
205+ if (!IS_ERR(fid)) {
206+ spin_lock(&dentry->d_lock);
207+ if (d_unhashed(dentry)) {
208+ spin_unlock(&dentry->d_lock);
209+ p9_client_clunk(fid);
210+ fid = ERR_PTR(-ENOENT);
211+ } else {
212+ __add_fid(dentry, fid);
213+ spin_unlock(&dentry->d_lock);
214+ }
215+ }
220216 err_out:
221217 up_read(&v9ses->rename_sem);
222218 return fid;
fs/9p/fid.h+1−21
@@ -23,28 +23,8 @@ · 22 unmodified lines
2323 #define FS_9P_FID_H
2424 #include <linux/list.h>
2525
26−/**
27− * struct v9fs_dentry - 9p private data stored in dentry d_fsdata
28− * @lock: protects the fidlist
29− * @fidlist: list of FIDs currently associated with this dentry
30− *
31− * This structure defines the 9p private data associated with
32− * a particular dentry. In particular, this private data is used
33− * to lookup which 9P FID handle should be used for a particular VFS
34− * operation. FID handles are associated with dentries instead of
35− * inodes in order to more closely map functionality to the Plan 9
36− * expected behavior for FID reclaimation and tracking.
37− *
38− * See Also: Mapping FIDs to Linux VFS model in
39− * Design and Implementation of the Linux 9P File System documentation
40− */
41−struct v9fs_dentry {
42− spinlock_t lock; /* protect fidlist */
43− struct list_head fidlist;
44−};
45−
4626 struct p9_fid *v9fs_fid_lookup(struct dentry *dentry);
4727 struct p9_fid *v9fs_fid_clone(struct dentry *dentry);
48−int v9fs_fid_add(struct dentry *dentry, struct p9_fid *fid);
28+void v9fs_fid_add(struct dentry *dentry, struct p9_fid *fid);
4929 struct p9_fid *v9fs_writeback_fid(struct dentry *dentry);
5030 #endif
fs/9p/vfs_dentry.c+4−13
@@ -83,21 +83,12 @@ static int v9fs_cached_dentry_delete(const struct dentry *dentry) · 82 unmodified lines
8383
8484 static void v9fs_dentry_release(struct dentry *dentry)
8585 {
86− struct v9fs_dentry *dent;
87− struct p9_fid *temp, *current_fid;
88−
86+ struct hlist_node *p, *n;
8987 p9_debug(P9_DEBUG_VFS, " dentry: %s (%p)\n",
9088 dentry->d_name.name, dentry);
91− dent = dentry->d_fsdata;
92− if (dent) {
93− list_for_each_entry_safe(current_fid, temp, &dent->fidlist,
94− dlist) {
95− p9_client_clunk(current_fid);
96− }
97−
98− kfree(dent);
99− dentry->d_fsdata = NULL;
100− }
89+ hlist_for_each_safe(p, n, (struct hlist_head *)&dentry->d_fsdata)
90+ p9_client_clunk(hlist_entry(p, struct p9_fid, dlist));
91+ dentry->d_fsdata = NULL;
10192 }
10293
10394 static int v9fs_lookup_revalidate(struct dentry *dentry, unsigned int flags)
fs/9p/vfs_inode.c+14−26
@@ -692,9 +692,7 @@ v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir, · 691 unmodified lines
692692 "inode creation failed %d\n", err);
693693 goto error;
694694 }
695− err = v9fs_fid_add(dentry, fid);
696− if (err < 0)
697− goto error;
695+ v9fs_fid_add(dentry, fid);
698696 d_instantiate(dentry, inode);
699697 }
700698 return ofid;
@@ -790,7 +788,6 @@ struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry, · 89 unmodified lines
790788 struct p9_fid *dfid, *fid;
791789 struct inode *inode;
792790 char *name;
793− int result = 0;
794791
795792 p9_debug(P9_DEBUG_VFS, "dir: %p dentry: (%s) %p flags: %x\n",
796793 dir, dentry->d_name.name, dentry, flags);
@@ -808,13 +805,11 @@ struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry, · 11 unmodified lines
808805 name = (char *) dentry->d_name.name;
809806 fid = p9_client_walk(dfid, 1, &name, 1);
810807 if (IS_ERR(fid)) {
811− result = PTR_ERR(fid);
812− if (result == -ENOENT) {
813− inode = NULL;
814− goto inst_out;
808+ if (fid == ERR_PTR(-ENOENT)) {
809+ d_add(dentry, NULL);
810+ return NULL;
815811 }
816−
817− return ERR_PTR(result);
812+ return ERR_CAST(fid);
818813 }
819814 /*
820815 * Make sure we don't use a wrong inode due to parallel
@@ -826,14 +821,9 @@ struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry, · 5 unmodified lines
826821 else
827822 inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
828823 if (IS_ERR(inode)) {
829− result = PTR_ERR(inode);
830− inode = NULL;
831− goto error;
824+ p9_client_clunk(fid);
825+ return ERR_CAST(inode);
832826 }
833− result = v9fs_fid_add(dentry, fid);
834− if (result < 0)
835− goto error_iput;
836−inst_out:
837827 /*
838828 * If we had a rename on the server and a parallel lookup
839829 * for the new name, then make sure we instantiate with
@@ -842,15 +832,13 @@ inst_out: · 2 unmodified lines
842832 * k/b.
843833 */
844834 res = d_materialise_unique(dentry, inode);
845− if (!IS_ERR(res))
846− return res;
847− result = PTR_ERR(res);
848−error_iput:
849− iput(inode);
850−error:
851− p9_client_clunk(fid);
852−
853− return ERR_PTR(result);
835+ if (!res)
836+ v9fs_fid_add(dentry, fid);
837+ else if (!IS_ERR(res))
838+ v9fs_fid_add(res, fid);
839+ else
840+ p9_client_clunk(fid);
841+ return res;
854842 }
855843
856844 static int
fs/9p/vfs_inode_dotl.c+7−12
@@ -333,9 +333,7 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct dentry *dentry, · 332 unmodified lines
333333 /* Now set the ACL based on the default value */
334334 v9fs_set_create_acl(inode, fid, dacl, pacl);
335335
336− err = v9fs_fid_add(dentry, fid);
337− if (err < 0)
338− goto error;
336+ v9fs_fid_add(dentry, fid);
339337 d_instantiate(dentry, inode);
340338
341339 v9inode = V9FS_I(inode);
@@ -453,12 +451,11 @@ static int v9fs_vfs_mkdir_dotl(struct inode *dir, · 111 unmodified lines
453451 err);
454452 goto error;
455453 }
456− err = v9fs_fid_add(dentry, fid);
457− if (err < 0)
458− goto error;
454+ v9fs_fid_add(dentry, fid);
459455 v9fs_set_create_acl(inode, fid, dacl, pacl);
460456 d_instantiate(dentry, inode);
461457 fid = NULL;
458+ err = 0;
462459 } else {
463460 /*
464461 * Not in cached mode. No need to populate
@@ -747,11 +744,10 @@ v9fs_vfs_symlink_dotl(struct inode *dir, struct dentry *dentry, · 282 unmodified lines
747744 err);
748745 goto error;
749746 }
750− err = v9fs_fid_add(dentry, fid);
751− if (err < 0)
752− goto error;
747+ v9fs_fid_add(dentry, fid);
753748 d_instantiate(dentry, inode);
754749 fid = NULL;
750+ err = 0;
755751 } else {
756752 /* Not in cached mode. No need to populate inode with stat */
757753 inode = v9fs_get_inode(dir->i_sb, S_IFLNK, 0);
@@ -900,11 +896,10 @@ v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, umode_t omode, · 142 unmodified lines
900896 goto error;
901897 }
902898 v9fs_set_create_acl(inode, fid, dacl, pacl);
903− err = v9fs_fid_add(dentry, fid);
904− if (err < 0)
905− goto error;
899+ v9fs_fid_add(dentry, fid);
906900 d_instantiate(dentry, inode);
907901 fid = NULL;
902+ err = 0;
908903 } else {
909904 /*
910905 * Not in cached mode. No need to populate inode with stat.
fs/ext4/indirect.c+1−1
@@ -1606,7 +1606,7 @@ err: · 1605 unmodified lines
16061606
16071607 int ext4_ind_punch_hole(struct file *file, loff_t offset, loff_t length)
16081608 {
1609− struct inode *inode = file->f_path.dentry->d_inode;
1609+ struct inode *inode = file_inode(file);
16101610 struct super_block *sb = inode->i_sb;
16111611 ext4_lblk_t first_block, stop_block;
16121612 struct address_space *mapping = inode->i_mapping;
fs/f2fs/file.c+3−3
@@ -29,7 +29,7 @@ static int f2fs_vm_page_mkwrite(struct vm_area_struct *vma, · 28 unmodified lines
2929 struct vm_fault *vmf)
3030 {
3131 struct page *page = vmf->page;
32− struct inode *inode = vma->vm_file->f_path.dentry->d_inode;
32+ struct inode *inode = file_inode(vma->vm_file);
3333 struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
3434 block_t old_blk_addr;
3535 struct dnode_of_data dn;
@@ -544,7 +544,7 @@ static int expand_inode_data(struct inode *inode, loff_t offset, · 508 unmodified lines
544544 static long f2fs_fallocate(struct file *file, int mode,
545545 loff_t offset, loff_t len)
546546 {
547− struct inode *inode = file->f_path.dentry->d_inode;
547+ struct inode *inode = file_inode(file);
548548 long ret;
549549
550550 if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE))
@@ -577,7 +577,7 @@ static inline __u32 f2fs_mask_flags(umode_t mode, __u32 flags) · 26 unmodified lines
577577
578578 long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
579579 {
580− struct inode *inode = filp->f_dentry->d_inode;
580+ struct inode *inode = file_inode(filp);
581581 struct f2fs_inode_info *fi = F2FS_I(inode);
582582 unsigned int flags;
583583 int ret;
fs/file_table.c+2−0
@@ -176,6 +176,7 @@ struct file *alloc_file(struct path *path, fmode_t mode, · 175 unmodified lines
176176 return file;
177177
178178 file->f_path = *path;
179+ file->f_inode = path->dentry->d_inode;
179180 file->f_mapping = path->dentry->d_inode->i_mapping;
180181 file->f_mode = mode;
181182 file->f_op = fop;
@@ -258,6 +259,7 @@ static void __fput(struct file *file) · 76 unmodified lines
258259 drop_file_write_access(file);
259260 file->f_path.dentry = NULL;
260261 file->f_path.mnt = NULL;
262+ file->f_inode = NULL;
261263 file_free(file);
262264 dput(dentry);
263265 mntput(mnt);
fs/fs_struct.c+3−3
@@ -10,7 +10,7 @@ · 9 unmodified lines
1010 * Replace the fs->{rootmnt,root} with {mnt,dentry}. Put the old values.
1111 * It can block.
1212 */
13−void set_fs_root(struct fs_struct *fs, struct path *path)
13+void set_fs_root(struct fs_struct *fs, const struct path *path)
1414 {
1515 struct path old_root;
1616
@@ -29,7 +29,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path) · 12 unmodified lines
2929 * Replace the fs->{pwdmnt,pwd} with {mnt,dentry}. Put the old values.
3030 * It can block.
3131 */
32−void set_fs_pwd(struct fs_struct *fs, struct path *path)
32+void set_fs_pwd(struct fs_struct *fs, const struct path *path)
3333 {
3434 struct path old_pwd;
3535
@@ -53,7 +53,7 @@ static inline int replace_path(struct path *p, const struct path *old, const str · 17 unmodified lines
5353 return 1;
5454 }
5555
56−void chroot_fs_refs(struct path *old_root, struct path *new_root)
56+void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
5757 {
5858 struct task_struct *g, *p;
5959 struct fs_struct *fs;
fs/fuse/dev.c+1−1
@@ -532,7 +532,7 @@ void fuse_request_send_background_locked(struct fuse_conn *fc, · 531 unmodified lines
532532
533533 void fuse_force_forget(struct file *file, u64 nodeid)
534534 {
535− struct inode *inode = file->f_path.dentry->d_inode;
535+ struct inode *inode = file_inode(file);
536536 struct fuse_conn *fc = get_fuse_conn(inode);
537537 struct fuse_req *req;
538538 struct fuse_forget_in inarg;
fs/fuse/file.c+12−12
@@ -355,7 +355,7 @@ static int fuse_wait_on_page_writeback(struct inode *inode, pgoff_t index) · 354 unmodified lines
355355
356356 static int fuse_flush(struct file *file, fl_owner_t id)
357357 {
358− struct inode *inode = file->f_path.dentry->d_inode;
358+ struct inode *inode = file_inode(file);
359359 struct fuse_conn *fc = get_fuse_conn(inode);
360360 struct fuse_file *ff = file->private_data;
361361 struct fuse_req *req;
@@ -1215,7 +1215,7 @@ static ssize_t __fuse_direct_read(struct file *file, const struct iovec *iov, · 853 unmodified lines
12151215 unsigned long nr_segs, loff_t *ppos)
12161216 {
12171217 ssize_t res;
1218− struct inode *inode = file->f_path.dentry->d_inode;
1218+ struct inode *inode = file_inode(file);
12191219
12201220 if (is_bad_inode(inode))
12211221 return -EIO;
@@ -1238,7 +1238,7 @@ static ssize_t fuse_direct_read(struct file *file, char __user *buf, · 16 unmodified lines
12381238 static ssize_t __fuse_direct_write(struct file *file, const struct iovec *iov,
12391239 unsigned long nr_segs, loff_t *ppos)
12401240 {
1241− struct inode *inode = file->f_path.dentry->d_inode;
1241+ struct inode *inode = file_inode(file);
12421242 size_t count = iov_length(iov, nr_segs);
12431243 ssize_t res;
12441244
@@ -1258,7 +1258,7 @@ static ssize_t fuse_direct_write(struct file *file, const char __user *buf, · 13 unmodified lines
12581258 size_t count, loff_t *ppos)
12591259 {
12601260 struct iovec iov = { .iov_base = (void __user *)buf, .iov_len = count };
1261− struct inode *inode = file->f_path.dentry->d_inode;
1261+ struct inode *inode = file_inode(file);
12621262 ssize_t res;
12631263
12641264 if (is_bad_inode(inode))
@@ -1485,7 +1485,7 @@ static const struct vm_operations_struct fuse_file_vm_ops = { · 220 unmodified lines
14851485 static int fuse_file_mmap(struct file *file, struct vm_area_struct *vma)
14861486 {
14871487 if ((vma->vm_flags & VM_SHARED) && (vma->vm_flags & VM_MAYWRITE)) {
1488− struct inode *inode = file->f_dentry->d_inode;
1488+ struct inode *inode = file_inode(file);
14891489 struct fuse_conn *fc = get_fuse_conn(inode);
14901490 struct fuse_inode *fi = get_fuse_inode(inode);
14911491 struct fuse_file *ff = file->private_data;
@@ -1543,7 +1543,7 @@ static void fuse_lk_fill(struct fuse_req *req, struct file *file, · 51 unmodified lines
15431543 const struct file_lock *fl, int opcode, pid_t pid,
15441544 int flock)
15451545 {
1546− struct inode *inode = file->f_path.dentry->d_inode;
1546+ struct inode *inode = file_inode(file);
15471547 struct fuse_conn *fc = get_fuse_conn(inode);
15481548 struct fuse_file *ff = file->private_data;
15491549 struct fuse_lk_in *arg = &req->misc.lk_in;
@@ -1565,7 +1565,7 @@ static void fuse_lk_fill(struct fuse_req *req, struct file *file, · 15 unmodified lines
15651565
15661566 static int fuse_getlk(struct file *file, struct file_lock *fl)
15671567 {
1568− struct inode *inode = file->f_path.dentry->d_inode;
1568+ struct inode *inode = file_inode(file);
15691569 struct fuse_conn *fc = get_fuse_conn(inode);
15701570 struct fuse_req *req;
15711571 struct fuse_lk_out outarg;
@@ -1590,7 +1590,7 @@ static int fuse_getlk(struct file *file, struct file_lock *fl) · 18 unmodified lines
15901590
15911591 static int fuse_setlk(struct file *file, struct file_lock *fl, int flock)
15921592 {
1593− struct inode *inode = file->f_path.dentry->d_inode;
1593+ struct inode *inode = file_inode(file);
15941594 struct fuse_conn *fc = get_fuse_conn(inode);
15951595 struct fuse_req *req;
15961596 int opcode = (fl->fl_flags & FL_SLEEP) ? FUSE_SETLKW : FUSE_SETLK;
@@ -1622,7 +1622,7 @@ static int fuse_setlk(struct file *file, struct file_lock *fl, int flock) · 25 unmodified lines
16221622
16231623 static int fuse_file_lock(struct file *file, int cmd, struct file_lock *fl)
16241624 {
1625− struct inode *inode = file->f_path.dentry->d_inode;
1625+ struct inode *inode = file_inode(file);
16261626 struct fuse_conn *fc = get_fuse_conn(inode);
16271627 int err;
16281628
@@ -1645,7 +1645,7 @@ static int fuse_file_lock(struct file *file, int cmd, struct file_lock *fl) · 16 unmodified lines
16451645
16461646 static int fuse_file_flock(struct file *file, int cmd, struct file_lock *fl)
16471647 {
1648− struct inode *inode = file->f_path.dentry->d_inode;
1648+ struct inode *inode = file_inode(file);
16491649 struct fuse_conn *fc = get_fuse_conn(inode);
16501650 int err;
16511651
@@ -1702,7 +1702,7 @@ static sector_t fuse_bmap(struct address_space *mapping, sector_t block) · 50 unmodified lines
17021702 static loff_t fuse_file_llseek(struct file *file, loff_t offset, int whence)
17031703 {
17041704 loff_t retval;
1705− struct inode *inode = file->f_path.dentry->d_inode;
1705+ struct inode *inode = file_inode(file);
17061706
17071707 /* No i_mutex protection necessary for SEEK_CUR and SEEK_SET */
17081708 if (whence == SEEK_CUR || whence == SEEK_SET)
@@ -2079,7 +2079,7 @@ EXPORT_SYMBOL_GPL(fuse_do_ioctl); · 370 unmodified lines
20792079 long fuse_ioctl_common(struct file *file, unsigned int cmd,
20802080 unsigned long arg, unsigned int flags)
20812081 {
2082− struct inode *inode = file->f_dentry->d_inode;
2082+ struct inode *inode = file_inode(file);
20832083 struct fuse_conn *fc = get_fuse_conn(inode);
20842084
20852085 if (!fuse_allow_current_process(fc))
fs/internal.h+1−1
@@ -69,7 +69,7 @@ extern void __mnt_drop_write_file(struct file *); · 68 unmodified lines
6969 /*
7070 * fs_struct.c
7171 */
72−extern void chroot_fs_refs(struct path *, struct path *);
72+extern void chroot_fs_refs(const struct path *, const struct path *);
7373
7474 /*
7575 * file_table.c
fs/namei.c+2−2
@@ -451,7 +451,7 @@ int inode_permission(struct inode *inode, int mask) · 450 unmodified lines
451451 *
452452 * Given a path increment the reference count to the dentry and the vfsmount.
453453 */
454−void path_get(struct path *path)
454+void path_get(const struct path *path)
455455 {
456456 mntget(path->mnt);
457457 dget(path->dentry);
@@ -464,7 +464,7 @@ EXPORT_SYMBOL(path_get); · 6 unmodified lines
464464 *
465465 * Given a path decrement the reference count to the dentry and the vfsmount.
466466 */
467−void path_put(struct path *path)
467+void path_put(const struct path *path)
468468 {
469469 dput(path->dentry);
470470 mntput(path->mnt);
fs/open.c+2−1
@@ -704,7 +704,7 @@ static int do_dentry_open(struct file *f, · 703 unmodified lines
704704 f->f_mode = FMODE_PATH;
705705
706706 path_get(&f->f_path);
707− inode = file_inode(f);
707+ inode = f->f_inode = f->f_path.dentry->d_inode;
708708 if (f->f_mode & FMODE_WRITE) {
709709 error = __get_file_write_access(inode, f->f_path.mnt);
710710 if (error)
@@ -767,6 +767,7 @@ cleanup_file: · 56 unmodified lines
767767 path_put(&f->f_path);
768768 f->f_path.mnt = NULL;
769769 f->f_path.dentry = NULL;
770+ f->f_inode = NULL;
770771 return error;
771772 }
772773
fs/seq_file.c+1−1
@@ -339,7 +339,7 @@ EXPORT_SYMBOL(seq_lseek); · 338 unmodified lines
339339 /**
340340 * seq_release - free the structures associated with sequential file.
341341 * @file: file in question
342− * @inode: file->f_path.dentry->d_inode
342+ * @inode: its inode
343343 *
344344 * Frees the structures associated with sequential file; can be used
345345 * as ->f_op->release() if you don't have private data to destroy.
include/linux/fs.h+2−1
@@ -769,6 +769,7 @@ struct file { · 768 unmodified lines
769769 } f_u;
770770 struct path f_path;
771771 #define f_dentry f_path.dentry
772+ struct inode *f_inode; /* cached value */
772773 const struct file_operations *f_op;
773774
774775 /*
@@ -2217,7 +2218,7 @@ static inline bool execute_ok(struct inode *inode) · 1442 unmodified lines
22172218
22182219 static inline struct inode *file_inode(struct file *f)
22192220 {
2220− return f->f_path.dentry->d_inode;
2221+ return f->f_inode;
22212222 }
22222223
22232224 /*
include/linux/fs_struct.h+2−2
@@ -17,8 +17,8 @@ struct fs_struct { · 16 unmodified lines
1717 extern struct kmem_cache *fs_cachep;
1818
1919 extern void exit_fs(struct task_struct *);
20−extern void set_fs_root(struct fs_struct *, struct path *);
21−extern void set_fs_pwd(struct fs_struct *, struct path *);
20+extern void set_fs_root(struct fs_struct *, const struct path *);
21+extern void set_fs_pwd(struct fs_struct *, const struct path *);
2222 extern struct fs_struct *copy_fs_struct(struct fs_struct *);
2323 extern void free_fs_struct(struct fs_struct *);
2424 extern int unshare_fs_struct(void);
include/linux/path.h+2−2
@@ -9,8 +9,8 @@ struct path { · 8 unmodified lines
99 struct dentry *dentry;
1010 };
1111
12−extern void path_get(struct path *);
13−extern void path_put(struct path *);
12+extern void path_get(const struct path *);
13+extern void path_put(const struct path *);
1414
1515 static inline int path_equal(const struct path *path1, const struct path *path2)
1616 {
include/net/9p/client.h+1−1
@@ -192,7 +192,7 @@ struct p9_fid { · 191 unmodified lines
192192 void *rdir;
193193
194194 struct list_head flist;
195− struct list_head dlist; /* list of all fids attached to a dentry */
195+ struct hlist_node dlist; /* list of all fids attached to a dentry */
196196 };
197197
198198 /**
kernel/futex.c+1−1
@@ -226,7 +226,7 @@ static void drop_futex_key_refs(union futex_key *key) · 225 unmodified lines
226226 * Returns a negative error code or 0
227227 * The key words are stored in *key on success.
228228 *
229− * For shared mappings, it's (page->index, vma->vm_file->f_path.dentry->d_inode,
229+ * For shared mappings, it's (page->index, file_inode(vma->vm_file),
230230 * offset_within_page). For private mappings, it's (uaddr, current->mm).
231231 * We can usually work out the index without swapping in the page.
232232 *
mm/shmem.c+2−3
@@ -2932,9 +2932,8 @@ struct file *shmem_file_setup(const char *name, loff_t size, unsigned long flags · 2931 unmodified lines
29322932 inode->i_size = size;
29332933 clear_nlink(inode); /* It is unlinked */
29342934 #ifndef CONFIG_MMU
2935− error = ramfs_nommu_expand_for_mapping(inode, size);
2936− res = ERR_PTR(error);
2937− if (error)
2935+ res = ERR_PTR(ramfs_nommu_expand_for_mapping(inode, size));
2936+ if (IS_ERR(res))
29382937 goto put_dentry;
29392938 #endif
29402939
security/selinux/hooks.c+0−9
@@ -3135,11 +3135,6 @@ static int selinux_file_fcntl(struct file *file, unsigned int cmd, · 3134 unmodified lines
31353135
31363136 switch (cmd) {
31373137 case F_SETFL:
3138− if (!file->f_path.dentry || !file->f_path.dentry->d_inode) {
3139− err = -EINVAL;
3140− break;
3141− }
3142−
31433138 if ((file->f_flags & O_APPEND) && !(arg & O_APPEND)) {
31443139 err = file_has_perm(cred, file, FILE__WRITE);
31453140 break;
@@ -3162,10 +3157,6 @@ static int selinux_file_fcntl(struct file *file, unsigned int cmd, · 16 unmodified lines
31623157 case F_SETLK64:
31633158 case F_SETLKW64:
31643159 #endif
3165− if (!file->f_path.dentry || !file->f_path.dentry->d_inode) {
3166− err = -EINVAL;
3167− break;
3168− }
31693160 err = file_has_perm(cred, file, FILE__LOCK);
31703161 break;
31713162 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t