Skip to content

Commit 3dcd25f

Browse files
Jan BlunckLinus Torvalds
authored andcommitted
d_path: Make proc_get_link() use a struct path argument
proc_get_link() is always called with a dentry and a vfsmount from a struct path. Make proc_get_link() take it directly as an argument. Signed-off-by: Jan Blunck <jblunck@suse.de> Acked-by: Christoph Hellwig <hch@infradead.org> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: "J. Bruce Fields" <bfields@fieldses.org> Cc: Neil Brown <neilb@suse.de> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 44707fd commit 3dcd25f

5 files changed

Lines changed: 34 additions & 42 deletions

File tree

‎fs/proc/base.c‎

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ static int get_nr_threads(struct task_struct *tsk)
153153
return count;
154154
}
155155

156-
static int proc_cwd_link(struct inode *inode, struct dentry **dentry, struct vfsmount **mnt)
156+
static int proc_cwd_link(struct inode *inode, struct path *path)
157157
{
158158
struct task_struct *task = get_proc_task(inode);
159159
struct fs_struct *fs = NULL;
@@ -165,16 +165,16 @@ static int proc_cwd_link(struct inode *inode, struct dentry **dentry, struct vfs
165165
}
166166
if (fs) {
167167
read_lock(&fs->lock);
168-
*mnt = mntget(fs->pwd.mnt);
169-
*dentry = dget(fs->pwd.dentry);
168+
*path = fs->pwd;
169+
path_get(&fs->pwd);
170170
read_unlock(&fs->lock);
171171
result = 0;
172172
put_fs_struct(fs);
173173
}
174174
return result;
175175
}
176176

177-
static int proc_root_link(struct inode *inode, struct dentry **dentry, struct vfsmount **mnt)
177+
static int proc_root_link(struct inode *inode, struct path *path)
178178
{
179179
struct task_struct *task = get_proc_task(inode);
180180
struct fs_struct *fs = NULL;
@@ -186,8 +186,8 @@ static int proc_root_link(struct inode *inode, struct dentry **dentry, struct vf
186186
}
187187
if (fs) {
188188
read_lock(&fs->lock);
189-
*mnt = mntget(fs->root.mnt);
190-
*dentry = dget(fs->root.dentry);
189+
*path = fs->root;
190+
path_get(&fs->root);
191191
read_unlock(&fs->lock);
192192
result = 0;
193193
put_fs_struct(fs);
@@ -1170,34 +1170,30 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
11701170
if (!proc_fd_access_allowed(inode))
11711171
goto out;
11721172

1173-
error = PROC_I(inode)->op.proc_get_link(inode, &nd->path.dentry,
1174-
&nd->path.mnt);
1173+
error = PROC_I(inode)->op.proc_get_link(inode, &nd->path);
11751174
nd->last_type = LAST_BIND;
11761175
out:
11771176
return ERR_PTR(error);
11781177
}
11791178

1180-
static int do_proc_readlink(struct dentry *dentry, struct vfsmount *mnt,
1181-
char __user *buffer, int buflen)
1179+
static int do_proc_readlink(struct path *path, char __user *buffer, int buflen)
11821180
{
1183-
struct inode * inode;
11841181
char *tmp = (char*)__get_free_page(GFP_TEMPORARY);
1185-
char *path;
1182+
char *pathname;
11861183
int len;
11871184

11881185
if (!tmp)
11891186
return -ENOMEM;
11901187

1191-
inode = dentry->d_inode;
1192-
path = d_path(dentry, mnt, tmp, PAGE_SIZE);
1193-
len = PTR_ERR(path);
1194-
if (IS_ERR(path))
1188+
pathname = d_path(path->dentry, path->mnt, tmp, PAGE_SIZE);
1189+
len = PTR_ERR(pathname);
1190+
if (IS_ERR(pathname))
11951191
goto out;
1196-
len = tmp + PAGE_SIZE - 1 - path;
1192+
len = tmp + PAGE_SIZE - 1 - pathname;
11971193

11981194
if (len > buflen)
11991195
len = buflen;
1200-
if (copy_to_user(buffer, path, len))
1196+
if (copy_to_user(buffer, pathname, len))
12011197
len = -EFAULT;
12021198
out:
12031199
free_page((unsigned long)tmp);
@@ -1208,20 +1204,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
12081204
{
12091205
int error = -EACCES;
12101206
struct inode *inode = dentry->d_inode;
1211-
struct dentry *de;
1212-
struct vfsmount *mnt = NULL;
1207+
struct path path;
12131208

12141209
/* Are we allowed to snoop on the tasks file descriptors? */
12151210
if (!proc_fd_access_allowed(inode))
12161211
goto out;
12171212

1218-
error = PROC_I(inode)->op.proc_get_link(inode, &de, &mnt);
1213+
error = PROC_I(inode)->op.proc_get_link(inode, &path);
12191214
if (error)
12201215
goto out;
12211216

1222-
error = do_proc_readlink(de, mnt, buffer, buflen);
1223-
dput(de);
1224-
mntput(mnt);
1217+
error = do_proc_readlink(&path, buffer, buflen);
1218+
path_put(&path);
12251219
out:
12261220
return error;
12271221
}
@@ -1448,8 +1442,7 @@ static unsigned name_to_int(struct dentry *dentry)
14481442

14491443
#define PROC_FDINFO_MAX 64
14501444

1451-
static int proc_fd_info(struct inode *inode, struct dentry **dentry,
1452-
struct vfsmount **mnt, char *info)
1445+
static int proc_fd_info(struct inode *inode, struct path *path, char *info)
14531446
{
14541447
struct task_struct *task = get_proc_task(inode);
14551448
struct files_struct *files = NULL;
@@ -1468,10 +1461,10 @@ static int proc_fd_info(struct inode *inode, struct dentry **dentry,
14681461
spin_lock(&files->file_lock);
14691462
file = fcheck_files(files, fd);
14701463
if (file) {
1471-
if (mnt)
1472-
*mnt = mntget(file->f_path.mnt);
1473-
if (dentry)
1474-
*dentry = dget(file->f_path.dentry);
1464+
if (path) {
1465+
*path = file->f_path;
1466+
path_get(&file->f_path);
1467+
}
14751468
if (info)
14761469
snprintf(info, PROC_FDINFO_MAX,
14771470
"pos:\t%lli\n"
@@ -1488,10 +1481,9 @@ static int proc_fd_info(struct inode *inode, struct dentry **dentry,
14881481
return -ENOENT;
14891482
}
14901483

1491-
static int proc_fd_link(struct inode *inode, struct dentry **dentry,
1492-
struct vfsmount **mnt)
1484+
static int proc_fd_link(struct inode *inode, struct path *path)
14931485
{
1494-
return proc_fd_info(inode, dentry, mnt, NULL);
1486+
return proc_fd_info(inode, path, NULL);
14951487
}
14961488

14971489
static int tid_fd_revalidate(struct dentry *dentry, struct nameidata *nd)
@@ -1685,7 +1677,7 @@ static ssize_t proc_fdinfo_read(struct file *file, char __user *buf,
16851677
size_t len, loff_t *ppos)
16861678
{
16871679
char tmp[PROC_FDINFO_MAX];
1688-
int err = proc_fd_info(file->f_path.dentry->d_inode, NULL, NULL, tmp);
1680+
int err = proc_fd_info(file->f_path.dentry->d_inode, NULL, tmp);
16891681
if (!err)
16901682
err = simple_read_from_buffer(buf, len, ppos, tmp, strlen(tmp));
16911683
return err;

‎fs/proc/internal.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ extern int maps_protect;
4848

4949
extern void create_seq_entry(char *name, mode_t mode,
5050
const struct file_operations *f);
51-
extern int proc_exe_link(struct inode *, struct dentry **, struct vfsmount **);
51+
extern int proc_exe_link(struct inode *, struct path *);
5252
extern int proc_tid_stat(struct seq_file *m, struct pid_namespace *ns,
5353
struct pid *pid, struct task_struct *task);
5454
extern int proc_tgid_stat(struct seq_file *m, struct pid_namespace *ns,

‎fs/proc/task_mmu.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ int task_statm(struct mm_struct *mm, int *shared, int *text,
7575
return mm->total_vm;
7676
}
7777

78-
int proc_exe_link(struct inode *inode, struct dentry **dentry, struct vfsmount **mnt)
78+
int proc_exe_link(struct inode *inode, struct path *path)
7979
{
8080
struct vm_area_struct * vma;
8181
int result = -ENOENT;
@@ -98,8 +98,8 @@ int proc_exe_link(struct inode *inode, struct dentry **dentry, struct vfsmount *
9898
}
9999

100100
if (vma) {
101-
*mnt = mntget(vma->vm_file->f_path.mnt);
102-
*dentry = dget(vma->vm_file->f_path.dentry);
101+
*path = vma->vm_file->f_path;
102+
path_get(&vma->vm_file->f_path);
103103
result = 0;
104104
}
105105

‎fs/proc/task_nommu.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ int task_statm(struct mm_struct *mm, int *shared, int *text,
103103
return size;
104104
}
105105

106-
int proc_exe_link(struct inode *inode, struct dentry **dentry, struct vfsmount **mnt)
106+
int proc_exe_link(struct inode *inode, struct path *path)
107107
{
108108
struct vm_list_struct *vml;
109109
struct vm_area_struct *vma;
@@ -126,8 +126,8 @@ int proc_exe_link(struct inode *inode, struct dentry **dentry, struct vfsmount *
126126
}
127127

128128
if (vma) {
129-
*mnt = mntget(vma->vm_file->f_path.mnt);
130-
*dentry = dget(vma->vm_file->f_path.dentry);
129+
*path = vma->vm_file->f_path;
130+
path_get(&vma->vm_file->f_path);
131131
result = 0;
132132
}
133133

‎include/linux/proc_fs.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ extern void kclist_add(struct kcore_list *, void *, size_t);
269269
#endif
270270

271271
union proc_op {
272-
int (*proc_get_link)(struct inode *, struct dentry **, struct vfsmount **);
272+
int (*proc_get_link)(struct inode *, struct path *);
273273
int (*proc_read)(struct task_struct *task, char *page);
274274
int (*proc_show)(struct seq_file *m,
275275
struct pid_namespace *ns, struct pid *pid,

0 commit comments

Comments
 (0)